Form_Home.cs 707 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using Microsoft.Win32;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using HslCommunication.LogNet;
  13. using MainForm.FaForm;
  14. using Sunny.UI;
  15. using MainForm.ClassFile.XiaomiAPI;
  16. using System.Diagnostics;
  17. using MainForm.Models;
  18. using SqlSugar;
  19. using EasyModbus;
  20. using ModBusClientSimple.Util;
  21. using csharp_networkprotocol_hpsocket;
  22. using MqttnetServerWin;
  23. using Sunny.UI.Win32;
  24. using MainForm.ClassFile.XiaomiAPI_AGV;
  25. using MainForm.ClassFile.XiaomiAPI_RouteCom;
  26. using HslCommunication.Controls;
  27. using EIP_Protocol;
  28. using MainForm.ClassFile.XiaomiAPI_MES;
  29. using NPOI.Util;
  30. using static MainForm.SQLHelper;
  31. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
  32. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
  33. using MainForm.ClassFile.ProjectClass;
  34. using CommonLib;
  35. using Org.BouncyCastle.Asn1.IsisMtt;
  36. using System.Web.Services.Description;
  37. using System.Numerics;
  38. using MathNet.Numerics.RootFinding;
  39. using HslCommunication.Enthernet;
  40. using BZFAStandardLib;
  41. using MainForm.ClassFile;
  42. using NPOI.SS.Formula.Functions;
  43. using static MainForm.ClassFile.XiaomiAPI.XiaomiMqttClient_Extend;
  44. using System.Net.Http;
  45. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_UpLoadFile;
  46. using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
  47. using System.Reflection;
  48. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
  49. using FaFrameUI;
  50. using System.Security.Policy;
  51. /*
  52. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  53. */
  54. namespace MainForm
  55. {
  56. /// <summary>
  57. /// 记录日志的委托
  58. /// </summary>
  59. /// <param name="logType">日志类型</param>
  60. /// <param name="message">日志信息</param>
  61. public delegate void HomeMessageHandler(LogType logType, string message);
  62. /// <summary>
  63. /// 主页窗体
  64. /// </summary>
  65. public partial class Form_Home : Form
  66. {
  67. #region 常量
  68. //文本常量
  69. private const string Head = "开始采集";
  70. private const string Tail = "采集完成";
  71. private const string Body = "工位出站数据";
  72. private const string BodyCheck = "工位点检数据";
  73. private const string BodyRun = "整线运行数据";
  74. private const string BodyAlarm = "整线报警数据";
  75. #endregion 常量
  76. #region 变量
  77. /// <summary>
  78. /// 委托-记录日志的方法
  79. /// </summary>
  80. public event HomeMessageHandler MessageEvent;
  81. /// <summary>
  82. /// 日志接口
  83. /// </summary>
  84. ILogNet _PLCLogNet;
  85. /// <summary>
  86. /// 用于记录IOT MQTT日志
  87. /// </summary>
  88. ILogNet _IOTMqttLogNet;
  89. /// <summary>
  90. /// 用于记录AGV MQTT日志
  91. /// </summary>
  92. ILogNet _AGVMqttLogNet;
  93. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  94. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  95. // 间隔时间
  96. private int IntervalReadPLC = 300; //ms 读PLC
  97. private int IntervalMonitorMES = 1000; //ms MES心跳
  98. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  99. /// <summary>
  100. /// 设备报警数据
  101. /// </summary>
  102. uint[] _FaultDatas = { };
  103. uint[] _FaultDatas_Old = { };
  104. // 软件状态
  105. private bool IsRun = true;
  106. #region PLC 与 TCP对象
  107. // 定义一个字典,存plc对象(通讯)
  108. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  109. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  110. // 定义TCPClient对象列表
  111. Dictionary<int, HPSocket_TcpClientHelper>
  112. _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  113. // 定义MQTTHelper对象
  114. MQTTHelper _MQTTHelper = new MQTTHelper();
  115. #endregion PLC 与 TCP对象
  116. /// <summary>
  117. /// 上次的设备运行信息
  118. /// </summary>
  119. private string lineWorkingData1_OldStr = string.Empty;
  120. /// <summary>
  121. /// 设备报警字典-当前结果
  122. /// Dictionary<工位代码,List<报警信息>>
  123. /// </summary>
  124. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  125. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  126. /// <summary>
  127. /// 单机用-设备状态
  128. /// </summary>
  129. //XiaomiDeviceState xmDeviceState = XiaomiDeviceState.Uninitialized;
  130. XiaomiDeviceStateData xmDeviceStateData = new XiaomiDeviceStateData();
  131. #endregion 变量
  132. #region 窗体基础事件
  133. /// <summary>
  134. /// 初始化
  135. /// </summary>
  136. public Form_Home()
  137. {
  138. InitializeComponent();
  139. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  140. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  141. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  142. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  143. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  144. }
  145. /// <summary>
  146. /// 窗体加载事件
  147. /// </summary>
  148. private void Form_Home_Load(object sender, EventArgs e)
  149. {
  150. try
  151. {
  152. AddMessage(LogType.Info, "开始初始化程序");
  153. //组建plc对象字典
  154. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  155. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  156. if (GlobalContext.IsUsePLC1)
  157. {
  158. GlobalContext.IsUsePLCNow = 1;
  159. GlobalContext.IsUseStationName = "[OP10]壳体清洁上料";
  160. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  161. }
  162. if (GlobalContext.IsUsePLC2)
  163. {
  164. GlobalContext.IsUsePLCNow = 2;
  165. GlobalContext.IsUseStationName = "[OP20]上盖板上料装备";
  166. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  167. }
  168. if (GlobalContext.IsUsePLC3)
  169. {
  170. GlobalContext.IsUsePLCNow = 3;
  171. GlobalContext.IsUseStationName = "[OP30]点散热胶装备";
  172. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  173. }
  174. if (GlobalContext.IsUsePLC4)
  175. {
  176. GlobalContext.IsUsePLCNow = 4;
  177. GlobalContext.IsUseStationName = "[OP40]胶线检测";
  178. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  179. }
  180. if (GlobalContext.IsUsePLC5)
  181. {
  182. GlobalContext.IsUsePLCNow = 5;
  183. GlobalContext.IsUseStationName = "[OP50]ADD板上料组装装备";
  184. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  185. }
  186. if (GlobalContext.IsUsePLC6)
  187. {
  188. GlobalContext.IsUsePLCNow = 6;
  189. GlobalContext.IsUseStationName = "[OP60]组上盖板";
  190. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  191. }
  192. if (GlobalContext.IsUsePLC7)
  193. {
  194. GlobalContext.IsUsePLCNow = 7;
  195. GlobalContext.IsUseStationName = "[OP70]上盖板锁螺丝";
  196. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  197. }
  198. if (GlobalContext.IsUsePLC8)
  199. {
  200. GlobalContext.IsUsePLCNow = 8;
  201. GlobalContext.IsUseStationName = "[OP80]NG下料";
  202. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC8Address, GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  203. }
  204. if (GlobalContext.IsUsePLC9)
  205. {
  206. GlobalContext.IsUsePLCNow = 9;
  207. GlobalContext.IsUseStationName = "[OP90]半成品下料";
  208. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  209. }
  210. (bool,string)DicResult=InitalDicAlarm(); // 实例化报警字典
  211. AddMessage(LogType.Info, DicResult.Item2);
  212. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  213. {
  214. if (plcEIP != null)
  215. {
  216. try
  217. {
  218. (int, string) result = plcEIP.Connect();
  219. }
  220. catch (Exception ex)
  221. {
  222. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  223. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
  224. MessageBoxOptions.ServiceNotification);
  225. }
  226. }
  227. }
  228. /*
  229. //plc1Alarm.Connect();
  230. foreach (ModbusClientHelper modbusClient in Funs.Values)
  231. {
  232. if (modbusClient != null)
  233. {
  234. try
  235. {
  236. modbusClient.Connect();
  237. }
  238. catch (Exception ex)
  239. {
  240. MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
  241. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  242. }
  243. }
  244. }
  245. */
  246. // 采集任务
  247. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  248. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  249. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  250. if (GlobalContext.IsUsePLC1)
  251. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  252. if (GlobalContext.IsUsePLC2)
  253. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  254. if (GlobalContext.IsUsePLC3)
  255. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  256. if (GlobalContext.IsUsePLC4)
  257. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  258. if (GlobalContext.IsUsePLC5)
  259. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  260. if (GlobalContext.IsUsePLC6)
  261. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  262. if (GlobalContext.IsUsePLC7)
  263. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  264. if (GlobalContext.IsUsePLC8)
  265. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  266. if (GlobalContext.IsUsePLC9)
  267. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  268. #region 初始化
  269. try
  270. {
  271. // 开启边线MES(绑定/查询数据)
  272. //int mesRoute = XiaomiMES_RouteCommunication.Init();
  273. //if (mesRoute == 0)
  274. //{
  275. // //picMESStatus.Image = imageListState.Images[1];
  276. // //GlobalContext.MESIsConnect = true;
  277. // AddMessage(LogType.Info, "小米MES边线初始连接成功!");
  278. //}
  279. //else
  280. //{
  281. // //picMESStatus.Image = imageListState.Images[0];
  282. // //GlobalContext.MESIsConnect = false;
  283. // AddMessage(LogType.Info, $"小米MES边线初始连接失败!");
  284. //}
  285. // 开启MES(Http)
  286. if (GlobalContext.IsUseMES)
  287. {
  288. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  289. if (mesret)
  290. {
  291. picMESStatus.Image = imageListState.Images[1];
  292. GlobalContext.MESIsConnect = true;
  293. AddMessage(LogType.Info, "小米MES初始连接成功!");
  294. }
  295. else
  296. {
  297. picMESStatus.Image = imageListState.Images[0];
  298. GlobalContext.MESIsConnect = false;
  299. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  300. }
  301. }
  302. // 开启IOT(MQTT)
  303. if (GlobalContext.IsUseIot)
  304. {
  305. string addr = GlobalContext.MQTTServerHost;
  306. int port = GlobalContext.MQTTServerPort;
  307. //生产环境需要修改
  308. (int, string) qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666, GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  309. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult.Item1;
  310. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  311. {
  312. picIot.Image = imageListState.Images[1];
  313. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  314. // 设置回调函数
  315. //XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  316. // 配置参数
  317. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  318. // fds
  319. param.parameter.fds.address = "http://file-cm.be.mi.com/file/x5/file/upload/mqtt";
  320. param.parameter.fds.appId = "Auto-Soft";
  321. param.parameter.fds.appKey = "d11ec2b9-0e7a-4086-a80c-a1ec716e0896";
  322. // mes
  323. param.parameter.mes.address = GlobalContext.ServerIp;
  324. param.parameter.mes.appId = GlobalContext.MESAppId;
  325. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  326. // mqtt
  327. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  328. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  329. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  330. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  331. // 设备配置
  332. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  333. if (GlobalContext.IsUsePLC1)
  334. {
  335. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  336. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  337. }
  338. if (GlobalContext.IsUsePLC2)
  339. {
  340. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  341. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  342. }
  343. if (GlobalContext.IsUsePLC3)
  344. {
  345. param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
  346. //param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
  347. }
  348. if (GlobalContext.IsUsePLC4)
  349. {
  350. param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
  351. param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
  352. }
  353. if (GlobalContext.IsUsePLC5)
  354. {
  355. param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
  356. param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
  357. }
  358. if (GlobalContext.IsUsePLC6)
  359. {
  360. param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
  361. param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
  362. }
  363. if (GlobalContext.IsUsePLC7)
  364. {
  365. param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  366. //param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  367. }
  368. if (GlobalContext.IsUsePLC8)
  369. {
  370. param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
  371. param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
  372. }
  373. if (GlobalContext.IsUsePLC9)
  374. {
  375. param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
  376. param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
  377. }
  378. param.parameter.equipment.project = GlobalContext.Project_Code;
  379. param.parameter.equipment.productMode = "debug";
  380. param.parameter.other.logLevel = 0;
  381. param.parameter.other.LogPath = GlobalContext.MqttLogDir;
  382. //测试
  383. //param.parameter.fds.address = "http://file-cm.be.mi.com/file/x5/file/upload/mqtt";
  384. //param.parameter.fds.appId = "Auto-Soft";
  385. //param.parameter.fds.appKey = "d11ec2b9-0e7a-4086-a80c-a1ec716e0896";
  386. //param.parameter.mes.address = "cm.pre.mi.com";
  387. //param.parameter.mes.appId = "MIUAT";
  388. //param.parameter.mes.appKey = "6B3D57E2-F062-471F-932B-76C8A79E0D66";
  389. //param.parameter.mqtt.address = "staging-cnbj2-rmq-mqtt.api.xiaomi.com";
  390. //param.parameter.mqtt.port = 80;
  391. //param.parameter.mqtt.username = "AKPKTSQAS46NKE4NHY";
  392. //param.parameter.mqtt.password = "Vfr/yyxVSkCVkHFjvD2rwb3ZOoUh+75KwnfWZX3N";
  393. //param.parameter.equipment.factoryCode = "1";
  394. //param.parameter.equipment.deviceCode = "C-MBA-ADDCU-A-BZJG-0001";
  395. //param.parameter.equipment.stationCode = "Y46-ADDCU-11";
  396. //param.parameter.equipment.project = "801";
  397. //param.parameter.equipment.productMode = "debug";
  398. //param.parameter.other.logLevel = 0;
  399. //param.parameter.other.runMode = "online";
  400. //param.parameter.other.uploadDigitalTwinData = "true";
  401. //param.parameter.other.LogPath = "D:/XiaomiMqttLog";
  402. //param.parameter.other.mqttEnableService = "true";
  403. XiaomiMqttClient_Extend.ParameterConfig(param);
  404. }
  405. else
  406. {
  407. picIot.Image = imageListState.Images[0];
  408. AddMessage(LogType.Info,
  409. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  410. }
  411. }
  412. // 开启AGV(Http与MQTT)
  413. if (GlobalContext.IsUseAGV)
  414. {
  415. // AGV HTTP
  416. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  417. if (mesret1)
  418. {
  419. picAgvHttp.Image = imageListState.Images[1];
  420. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  421. }
  422. else
  423. {
  424. picAgvHttp.Image = imageListState.Images[0];
  425. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  426. }
  427. string agvMqttIp = GlobalContext.MQTTServerHost;
  428. int agvMqttPort = GlobalContext.MQTTServerPort;
  429. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  430. ResultData_MQTT result_MQTT = _MQTTHelper
  431. .CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  432. // AGV MQTT
  433. if (result_MQTT.ResultCode == 1)
  434. {
  435. picAgvMqtt.Image = imageListState.Images[1];
  436. GlobalContext.AGVMQTTIsConnect = true;
  437. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  438. ResultData_MQTT result =
  439. XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  440. AddMessage(LogType.Info,
  441. $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  442. }
  443. else
  444. {
  445. picAgvMqtt.Image = imageListState.Images[0];
  446. GlobalContext.AGVMQTTIsConnect = false;
  447. AddMessage(LogType.Info,
  448. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  449. }
  450. }
  451. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  452. Task.Run(MonitorMESConnect);
  453. // 查询PLC连接状态
  454. foreach (int plcNo in FunsEip.Keys)
  455. {
  456. bool connected = FunsEip[plcNo].IsConnected;
  457. if (connected)
  458. {
  459. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  460. AddMessage(LogType.Info, msg);
  461. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  462. }
  463. else
  464. {
  465. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  466. AddMessage(LogType.Info, msg);
  467. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  468. }
  469. }
  470. // PLC4时 初始化扫码器TCP
  471. //if (GlobalContext.IsUsePLC4)
  472. // HpTCPClientInit();
  473. // 开启PLC的业务处理线程-监听PLC点位+状态
  474. foreach (Task task in TaskReadProcess)
  475. {
  476. if (task != null)
  477. task.Start();
  478. }
  479. //// 开启iot的线程
  480. TaskReadAlarm.Start();
  481. ////下传MES信息给1工位(先判断下plc对象数量)
  482. //if (Funs.Count > 1)
  483. // DownLoadProductInfo(1);
  484. if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  485. {
  486. state_l.Text = "设备状态(左):";
  487. state_r.Text = "设备状态(右):";
  488. state_r.Visible = true;
  489. lblDeviceStates2.Visible = true;
  490. }
  491. AddMessage(LogType.Info, "程序初始化完成");
  492. }
  493. catch (Exception ex)
  494. {
  495. string str = ex.StackTrace;
  496. this.BeginInvoke(new Action(() =>
  497. {
  498. AddMessage(LogType.Error,
  499. "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  500. str.Length - str.LastIndexOf("\\") - 1));
  501. }));
  502. }
  503. #endregion
  504. }
  505. catch (Exception ex)
  506. {
  507. string str = ex.StackTrace;
  508. OnMessage(LogType.Info,
  509. "主窗体的首页初始化出错!异常位置:" +
  510. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" +
  511. ex.Message.ToString());
  512. if (ex.Message != null && ex.Message.Contains("timed out"))
  513. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  514. else
  515. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  516. }
  517. }
  518. /// <summary>
  519. /// 窗体关闭事件
  520. /// </summary>
  521. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  522. {
  523. Closed2();
  524. }
  525. public void Closed2()
  526. {
  527. try
  528. {
  529. IsRun = false;
  530. Thread.Sleep(IntervalReadPLC);
  531. // 断开TCP
  532. int count = _HPSocket_TcpClients.Count();
  533. for (int i = 0; i < count; i++)
  534. {
  535. try
  536. {
  537. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  538. {
  539. _HPSocket_TcpClients[i].Stop();
  540. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  541. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  542. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  543. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  544. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  545. }
  546. }
  547. catch
  548. {
  549. }
  550. }
  551. // 关闭Iot
  552. try
  553. {
  554. XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath,
  555. GlobalContext.MqttServerName);
  556. }
  557. catch
  558. {
  559. }
  560. // 关闭AGV Mqtt
  561. try
  562. {
  563. _MQTTHelper.DisconnectAsync_Client().Wait();
  564. }
  565. catch
  566. {
  567. }
  568. }
  569. catch
  570. {
  571. }
  572. }
  573. #endregion 窗体基础事件
  574. #region 监控MES状态
  575. /// <summary>
  576. /// 监控MES连接状态
  577. /// </summary>
  578. private void MonitorMESConnect()
  579. {
  580. while (IsRun) // 运行被控线程
  581. {
  582. try
  583. {
  584. // 开启MES(Http)
  585. if (GlobalContext.IsUseMES)
  586. {
  587. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  588. if (mesret)
  589. {
  590. picMESStatus.Image = imageListState.Images[1];
  591. GlobalContext.MESIsConnect = true;
  592. }
  593. else
  594. {
  595. picMESStatus.Image = imageListState.Images[0];
  596. GlobalContext.MESIsConnect = false;
  597. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  598. }
  599. }
  600. // 开启IOT(MQTT)
  601. if (GlobalContext.IsUseIot)
  602. {
  603. bool iIot = XiaomiMqttClient.IsOpen;
  604. if (iIot)
  605. picIot.Image = imageListState.Images[1];
  606. else
  607. {
  608. picIot.Image = imageListState.Images[0];
  609. OnMessage(LogType.Info,
  610. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  611. }
  612. }
  613. // 开启AGV(Http与MQTT)
  614. if (GlobalContext.IsUseAGV)
  615. {
  616. // AGV Http
  617. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  618. if (mesret1)
  619. picAgvHttp.Image = imageListState.Images[1];
  620. else
  621. {
  622. picAgvHttp.Image = imageListState.Images[0];
  623. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  624. }
  625. // AGV MQTT
  626. if (GlobalContext.AGVMQTTIsConnect)
  627. picAgvMqtt.Image = imageListState.Images[1];
  628. else
  629. {
  630. picAgvMqtt.Image = imageListState.Images[0];
  631. OnMessage(LogType.Info,
  632. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  633. }
  634. }
  635. }
  636. catch (Exception ex)
  637. {
  638. string str = ex.StackTrace;
  639. AddMessage(LogType.Error,
  640. "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  641. str.Length - str.LastIndexOf("\\") - 1));
  642. }
  643. Thread.Sleep(IntervalMonitorMES);
  644. }
  645. }
  646. #endregion 监控MES连接状态
  647. #region 采集设备状态、运行数据、报警数据
  648. /// <summary>
  649. /// 请求设备状态 5000
  650. /// </summary>
  651. /// <param name="no">1</param>
  652. /// <param name="stationNameStr"></param>
  653. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  654. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  655. {
  656. try
  657. {
  658. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  659. {
  660. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  661. return result;
  662. }
  663. else
  664. {
  665. return 0;
  666. }
  667. }
  668. catch (Exception ex)
  669. {
  670. string str = ex.StackTrace;
  671. AddMessage_Station(stationNameStr, LogType.Error,
  672. "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  673. str.Length - str.LastIndexOf("\\") - 1));
  674. return 0;
  675. }
  676. }
  677. /// <summary>
  678. /// 检查是否可采集点检数据 - 不取新值
  679. /// 5000不为1时可点检
  680. /// </summary>
  681. /// <returns></returns>
  682. public bool CheckCanSpotcheck1(int deviceState)
  683. {
  684. //return true;
  685. //D5000 = 1,代表设备控制状态处于运行状态
  686. //D5000 = 2, 代表设备控制状态处于故障状态
  687. //D5000 = 3,代表设备控制状态处于缺料状态
  688. //D5000 = 4, 代表设备控制状态处于待机状态
  689. //D5000 = 5,代表设备控制状态处于维修状态
  690. return deviceState != 1;
  691. }
  692. /// <summary>
  693. /// 检查是否可采集产品数据 - 不取新值
  694. /// </summary>
  695. /// <returns></returns>
  696. public bool CheckCanCollData(int deviceState)
  697. {
  698. return deviceState == 0; // 点检时该值不为0
  699. }
  700. /// <summary>
  701. /// 采集到的设备状态
  702. /// </summary>
  703. private string _DeviceStates = "未知状态";
  704. private string _DeviceStates_Old = "未知状态";
  705. private string _DeviceStates2 = "未知状态";
  706. private string _DeviceStates_Old2 = "未知状态";
  707. /// <summary>
  708. /// 获取设备报警数据与获取设备运行信息
  709. /// </summary>
  710. private async void ReadAlarmAllPLC()
  711. {
  712. /// 获取设备报警数据与状态信息
  713. string stationNameStr = "获取设备报警数据与状态信息";
  714. // 已连接到PLC
  715. while (IsRun)
  716. {
  717. try
  718. {
  719. #region 报警数据
  720. try
  721. {
  722. //_FaultDatas = new uint[] { 4, 0, 30, 10 };
  723. if (_FaultDatas.Length>0)
  724. {
  725. ReadPLCAlarmToIot(_FaultDatas, stationNameStr);
  726. }
  727. else
  728. {
  729. AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!" );
  730. }
  731. }
  732. catch (Exception ex)
  733. {
  734. string str = ex.StackTrace;
  735. AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  736. }
  737. #endregion 报警数据
  738. #region 设备状态
  739. //if (!GlobalContext._IsCon_plc1Alarm)
  740. //{
  741. // UpdatePLCMonitor(1, -2, 0);
  742. // continue;
  743. //}
  744. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  745. {
  746. if (plcEIP != null)
  747. {
  748. if (plcEIP.IsConnected)
  749. {
  750. #region 主页展示设备运行状态并上传到IOT中,有双工位left就是左工位,没有双工位left就是单工位
  751. switch (xmDeviceStateData.left)
  752. {
  753. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  754. _DeviceStates = "未初始化状态";
  755. lblDeviceStates.Text = _DeviceStates;
  756. break;
  757. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  758. _DeviceStates = "初始化状态";
  759. lblDeviceStates.Text = _DeviceStates;
  760. break;
  761. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  762. _DeviceStates = "初始化完成状态";
  763. lblDeviceStates.Text = _DeviceStates;
  764. break;
  765. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  766. _DeviceStates = "运行状态";
  767. lblDeviceStates.Text = _DeviceStates;
  768. break;
  769. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  770. _DeviceStates = "暂停状态";
  771. lblDeviceStates.Text = _DeviceStates;
  772. break;
  773. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  774. _DeviceStates = "故障状态";
  775. lblDeviceStates.Text = _DeviceStates;
  776. break;
  777. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  778. _DeviceStates = "警报状态";
  779. lblDeviceStates.Text = _DeviceStates;
  780. break;
  781. }
  782. if (!_DeviceStates.Equals(_DeviceStates_Old))
  783. {
  784. var iotResult =
  785. SaveDeviceStateData(stationNameStr, xmDeviceStateData.left, "left"); // 上传+保存
  786. if (iotResult.Item1 == 1)
  787. {
  788. _DeviceStates_Old = _DeviceStates;
  789. AddMessage_Station(stationNameStr, LogType.Info,
  790. "【设备状态】" + stationNameStr + $"_上传设备状态到Iot成功!");
  791. }
  792. else
  793. AddMessage_Station(stationNameStr, LogType.Info,
  794. "【设备状态】"+stationNameStr +
  795. $"_上传设备状态到Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  796. }
  797. #endregion 主页展示设备运行状态并上传到IOT中
  798. #region 右工位
  799. if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  800. {
  801. switch (xmDeviceStateData.right)
  802. {
  803. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  804. _DeviceStates2 = "未初始化状态";
  805. lblDeviceStates.Text = _DeviceStates2;
  806. break;
  807. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  808. _DeviceStates2 = "初始化状态";
  809. lblDeviceStates.Text = _DeviceStates2;
  810. break;
  811. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  812. _DeviceStates2 = "初始化完成状态";
  813. lblDeviceStates.Text = _DeviceStates2;
  814. break;
  815. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  816. _DeviceStates2 = "运行状态";
  817. lblDeviceStates.Text = _DeviceStates2;
  818. break;
  819. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  820. _DeviceStates2 = "暂停状态";
  821. lblDeviceStates.Text = _DeviceStates2;
  822. break;
  823. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  824. _DeviceStates2 = "故障状态";
  825. lblDeviceStates.Text = _DeviceStates2;
  826. break;
  827. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  828. _DeviceStates2 = "警报状态";
  829. lblDeviceStates.Text = _DeviceStates2;
  830. break;
  831. }
  832. if (!_DeviceStates2.Equals(_DeviceStates_Old2))
  833. {
  834. var iotResult = SaveDeviceStateData(stationNameStr, xmDeviceStateData.left,
  835. "right"); // 上传+保存
  836. if (iotResult.Item1 == 1)
  837. {
  838. _DeviceStates_Old2 = _DeviceStates2;
  839. AddMessage_Station(stationNameStr, LogType.Info,
  840. "【设备状态】" + stationNameStr + $"_上传Iot成功!");
  841. }
  842. else
  843. AddMessage_Station(stationNameStr, LogType.Info,
  844. "【设备状态】" + stationNameStr +
  845. $"_上传Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  846. }
  847. }
  848. #endregion 右工位
  849. }
  850. }
  851. }
  852. #endregion
  853. //if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  854. //{
  855. // DateTime dtNow = DateTime.Now;
  856. // //#region 获取设备运行信息
  857. // //try
  858. // //{
  859. // // LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  860. // // lineWorkingData1.GUID = Guid.NewGuid().ToString();
  861. // // lineWorkingData1.LineName = GlobalContext.LineCode;
  862. // // //
  863. // // lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  864. // // lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  865. // // lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  866. // // lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  867. // // lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  868. // // lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  869. // // lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  870. // // lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  871. // // lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  872. // // lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  873. // // lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  874. // // lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  875. // // lineWorkingData1.CreateTime = DateTime.Now;
  876. // // string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  877. // // // UI展示-展示到设备状态页
  878. // // if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  879. // // {
  880. // // // 查询数据库最新一条数据,确定是不是更新
  881. // // string qSql = @"SELECT top(1) [GUID]
  882. // // ,[LineName]
  883. // // ,[BootTimeLong]
  884. // // ,[NormalTimeLong]
  885. // // ,[StandbyTimeLong]
  886. // // ,[FaultTimeLong]
  887. // // ,[MaterialShortageTimeLong]
  888. // // ,[MaintenanceTimeLong]
  889. // // ,[FaultNumber]
  890. // // ,[OutputNumber]
  891. // // ,[QualifiedNumber]
  892. // // ,[QualifiedRate]
  893. // // ,[DesignRhythm]
  894. // // ,[RealityRhythm]
  895. // // ,[CreateTime]
  896. // // FROM [LineWorkingData]
  897. // // where [CreateTime] > '{0}'
  898. // // and [LineName]='{1}'
  899. // // order by [CreateTime] desc
  900. // // ";
  901. // // qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  902. // // var ds = SQLHelper_New.Query(qSql, null);
  903. // // if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  904. // // {
  905. // // var dataDBlast = new LineWorkingData_ThisTime();
  906. // // dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  907. // // dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  908. // // dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  909. // // dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  910. // // if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  911. // // {
  912. // // dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  913. // // dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  914. // // dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  915. // // dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  916. // // dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  917. // // dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  918. // // dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  919. // // dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  920. // // dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  921. // // dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  922. // // dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  923. // // dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  924. // // string usql = dataDBlast.ToStringUpdate();
  925. // // SQLHelper_New.ExecuteSQL(usql, null);
  926. // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  927. // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  928. // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  929. // // }
  930. // // }
  931. // // else
  932. // // {
  933. // // // 插入
  934. // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  935. // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  936. // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  937. // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  938. // // }
  939. // // }
  940. // // else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  941. // // {
  942. // // LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  943. // // //// 本次开机设备运行情况
  944. // // //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  945. // // //Task.Run(() =>
  946. // // //{
  947. // // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  948. // // // {
  949. // // // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  950. // // // }
  951. // // //});
  952. // // // 本日设备运行情况
  953. // // // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  954. // // if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  955. // // {
  956. // // // 更新
  957. // // lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  958. // // lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  959. // // lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  960. // // lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  961. // // lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  962. // // lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  963. // // lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  964. // // lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  965. // // lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  966. // // lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  967. // // lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  968. // // lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  969. // // SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  970. // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  971. // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  972. // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  973. // // }
  974. // // else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  975. // // {
  976. // // // 插入
  977. // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  978. // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  979. // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  980. // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  981. // // }
  982. // // await Task.Run(() =>
  983. // // {
  984. // // try
  985. // // {
  986. // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  987. // // {
  988. // // Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  989. // // }
  990. // // }
  991. // // catch { }
  992. // // });
  993. // // }
  994. // //}
  995. // //catch (Exception ex)
  996. // //{
  997. // // string str = ex.StackTrace;
  998. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  999. // //}
  1000. // //#endregion 获取设备运行信息
  1001. // #region 报警数据
  1002. // try
  1003. // {
  1004. // List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  1005. // bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  1006. // // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  1007. // var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  1008. // for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  1009. // {
  1010. // short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  1011. // dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  1012. // if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  1013. // {
  1014. // isNeedUpdUI = true; // 需要更新历史报警UI信息
  1015. // // 记录
  1016. // dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  1017. // switch (dicAlarms_Cur_PLC1[i].是否报警)
  1018. // {
  1019. // case true: // 报警
  1020. // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  1021. // {
  1022. // GUID = Guid.NewGuid().ToString(),
  1023. // LineName = GlobalContext.LineCode, // 线体
  1024. // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  1025. // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  1026. // StartTime = dtNow // 开始时间
  1027. // };
  1028. // // 传输到页面
  1029. // deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  1030. // {
  1031. // 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  1032. // 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  1033. // 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  1034. // 开始时间 = dtNow
  1035. // });
  1036. // // 新增到数据库
  1037. // var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  1038. // SaveAlarmDataByDB(stationNameStr, data1, false);
  1039. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  1040. // break;
  1041. // case false: // 消除报警
  1042. // if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  1043. // {
  1044. // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  1045. // {
  1046. // GUID = Guid.NewGuid().ToString(),
  1047. // LineName = GlobalContext.LineCode, // 线体
  1048. // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  1049. // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  1050. // StartTime = dtNow, // 开始时间
  1051. // EndTime = dtNow, // 开始时间
  1052. // PersistTime = 1, // 耗时1s
  1053. // };
  1054. // // 新增
  1055. // var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  1056. // SaveAlarmDataByDB(stationNameStr, data2, false);
  1057. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  1058. // }
  1059. // else
  1060. // {
  1061. // dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  1062. // dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  1063. // - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  1064. // // 修改
  1065. // var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  1066. // SaveAlarmDataByDB(stationNameStr, data3, true);
  1067. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  1068. // }
  1069. // break;
  1070. // default:
  1071. // break;
  1072. // }
  1073. // }
  1074. // }
  1075. // DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  1076. // // 有新报警则更新
  1077. // if (isNeedUpdUI)
  1078. // {
  1079. // // UI展示 - 展示到设备状态页
  1080. // await Task.Run(() =>
  1081. // {
  1082. // try
  1083. // {
  1084. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  1085. // {
  1086. // Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  1087. // if (Form_Main.formDevAlarm.Visible)
  1088. // {
  1089. // Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  1090. // }
  1091. // }
  1092. // }
  1093. // catch { }
  1094. // });
  1095. // }
  1096. // }
  1097. // catch (Exception ex)
  1098. // {
  1099. // string str = ex.StackTrace;
  1100. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1101. // }
  1102. // #endregion 报警数据
  1103. // UpdatePLCMonitor(1, -2, 1);
  1104. //}
  1105. //else
  1106. //{
  1107. // UpdatePLCMonitor(1, -2, 0);
  1108. //}
  1109. }
  1110. catch (Exception ex)
  1111. {
  1112. //AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1113. AddMessage_Station(stationNameStr, LogType.Error,
  1114. $"PLC1_{stationNameStr}_采集运行数据与报警数据出错!错误信息:" + ex.Message.ToString());
  1115. }
  1116. Thread.Sleep(IntervalAlarm);
  1117. }
  1118. }
  1119. #endregion 轮询PLC
  1120. #region 下发订单信息
  1121. ///// <summary>
  1122. ///// 壳体上料(下发工单)的交互逻辑
  1123. ///// </summary>
  1124. ///// <param name="no"></param>
  1125. ///// <exception cref="NotImplementedException"></exception>
  1126. //private void ReadStation_DownOrderInfo(int plcNo)
  1127. //{
  1128. // // [S1] Tray盘上料装备(板测)
  1129. // // [S2] FCT(板测)
  1130. // // [S3] 值板机
  1131. // // [S4] 取放桁架
  1132. // // [S5] Tray盘下料装备
  1133. // /// 上位机心跳
  1134. // /// 获取设备报警数据与状态信息
  1135. // string stationNameStr = "[S0]壳体上料";
  1136. // while (IsRun)
  1137. // {
  1138. // try
  1139. // {
  1140. // if (!GlobalContext._IsCon_Funs1)
  1141. // {
  1142. // UpdatePLCMonitor(plcNo, 0);
  1143. // continue;
  1144. // }
  1145. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  1146. // {
  1147. // #region 壳体上料(下发工单)
  1148. // try
  1149. // {
  1150. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  1151. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  1152. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  1153. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  1154. // // 重置数据和信号
  1155. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  1156. // {
  1157. // // 清空写给PLC的数据
  1158. // int[] i497 = new int[1] { 0 };
  1159. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  1160. // // MES_Flag重置为0
  1161. // int[] i500 = new int[1] { 0 };
  1162. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  1163. // }
  1164. // }
  1165. // catch (Exception ex)
  1166. // {
  1167. // string str = ex.StackTrace;
  1168. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1169. // }
  1170. // #endregion 壳体上料(下发工单)
  1171. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1172. // }
  1173. // else
  1174. // {
  1175. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  1176. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1177. //
  1178. // Funs[plcNo].Connect();
  1179. // }
  1180. // }
  1181. // catch (Exception ex)
  1182. // {
  1183. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  1184. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1185. //
  1186. // Funs[plcNo].ReConnect();
  1187. // }
  1188. // Thread.Sleep(IntervalReadPLC);
  1189. // }
  1190. //}
  1191. ///// <summary>
  1192. ///// 下发订单信息到PLC
  1193. ///// </summary>
  1194. ///// <param name="no">PLC编号</param>
  1195. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  1196. //{
  1197. // try
  1198. // {
  1199. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  1200. // {
  1201. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  1202. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  1203. // }
  1204. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  1205. // }
  1206. // catch (Exception ex)
  1207. // {
  1208. // string str = ex.StackTrace;
  1209. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1210. // }
  1211. //}
  1212. /// <summary>
  1213. /// 下发清料信号
  1214. /// </summary>
  1215. /// <param name="no">PLC编号</param>
  1216. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  1217. {
  1218. try
  1219. {
  1220. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  1221. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  1222. return true;
  1223. }
  1224. catch (Exception ex)
  1225. {
  1226. string str = ex.StackTrace;
  1227. AddMessage_Station(stationNameStr, LogType.Error,
  1228. "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  1229. str.Length - str.LastIndexOf("\\") - 1));
  1230. return false;
  1231. }
  1232. }
  1233. #endregion 下发订单信息
  1234. #region Xiaomi 贲流
  1235. #region 公共方法
  1236. private static bool ProgressState = false;
  1237. private static readonly object lockObj = new object(); // 锁对象
  1238. private static bool isCollectingFlagLeft;
  1239. private static bool isCollectingFlagRight;
  1240. private bool OpenDailogFalg = true;//是否开启扫码弹窗标识
  1241. /// <summary>
  1242. /// float[]转为string
  1243. /// </summary>
  1244. public string FloatArrayToString(float[] nScrewResults)
  1245. {
  1246. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  1247. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  1248. }
  1249. /// <summary>
  1250. /// short[]转为string
  1251. /// </summary>
  1252. public string ShortArrayToString(short[] nScrewResults)
  1253. {
  1254. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  1255. return string.Join(",", nScrewResults);
  1256. }
  1257. /// <summary>
  1258. /// 写入PLC重复三次
  1259. /// </summary>
  1260. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount,
  1261. T inObj)
  1262. {
  1263. int i = 0;
  1264. int nRet = 0;
  1265. string strRet = "";
  1266. try
  1267. {
  1268. while (i < 3) // 最多上传三次
  1269. {
  1270. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  1271. if (nRet == 0) //成功
  1272. {
  1273. break;
  1274. }
  1275. else
  1276. {
  1277. AddMessage_Station(stationNameStr, LogType.Error,
  1278. $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1279. i++;
  1280. }
  1281. }
  1282. return (nRet, strRet);
  1283. }
  1284. catch (Exception ex)
  1285. {
  1286. return (1, ex.Message);
  1287. }
  1288. }
  1289. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes,
  1290. short[] nScrewOrders, short[] nScrewResults)
  1291. {
  1292. try
  1293. {
  1294. // 获取当前日期
  1295. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1296. // 构建保存路径
  1297. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  1298. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction, "螺丝Mes数据");
  1299. // 确保目录存在
  1300. Directory.CreateDirectory(savePath);
  1301. // 文件名
  1302. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  1303. string filePath = Path.Combine(savePath, fileName);
  1304. // 确保不会超出数组长度,只取前14个或数组的实际长度
  1305. int count = Math.Min(14, fScrewTimes.Length);
  1306. using (StreamWriter sw = new StreamWriter(filePath))
  1307. {
  1308. for (int i = 0; i < count; i++)
  1309. {
  1310. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  1311. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  1312. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  1313. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  1314. sw.WriteLine(); // 空行分隔不同螺丝的信息
  1315. }
  1316. }
  1317. return (0, "");
  1318. }
  1319. catch (Exception ex)
  1320. {
  1321. return (1, ex.Message);
  1322. }
  1323. }
  1324. public Dictionary<string, string> GetLastLineCompensation(string path, string direction, string sn)
  1325. {
  1326. // 创建字典存储补偿点及其对应的值
  1327. Dictionary<string, string> compensationDict = new Dictionary<string, string>();
  1328. try
  1329. {
  1330. //string path = GlobalContext.MESLaserRPath;
  1331. // 获取当前日期并格式化为 "yyyy-MM-dd" 格式
  1332. string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
  1333. string filename = $"Laser-{currentDate}-W0.txt";
  1334. // 拼接完整路径
  1335. string fullPath = Path.Combine(path, filename);
  1336. string lastNonEmptyLine = "";
  1337. // 判断文件是否存在
  1338. if (File.Exists(fullPath))
  1339. {
  1340. //读取文件内容
  1341. string[] lines = File.ReadAllLines(fullPath);
  1342. // 获取最后一行数据(忽略标题行)
  1343. if (lines.Length > 1)
  1344. {
  1345. string lastLine = "";
  1346. for (int i = lines.Length - 1; i > 0; i--)
  1347. {
  1348. if (!string.IsNullOrEmpty(lines[i]))
  1349. {
  1350. lastLine = lines[i];
  1351. break;
  1352. }
  1353. }
  1354. // 将最后一行按逗号分隔
  1355. string[] values = lastLine.Split(',');
  1356. values[1] = sn;
  1357. string key = "三点激光_" + direction; // 构造键名
  1358. string value = string.Join(",", values); // 获取值并去除多余空格
  1359. compensationDict[key] = value;
  1360. //// 提取“1点补偿”到“6点补偿”的值
  1361. //for (int i = 2; i <= 7 && i < values.Length; i++) // 从索引2开始,最多提取6个值
  1362. //{
  1363. // string key = $"{i - 1}点补偿"; // 构造键名
  1364. // string value = values[i].Trim(); // 获取值并去除多余空格
  1365. // compensationDict[key] = value;
  1366. //}
  1367. }
  1368. }
  1369. else
  1370. {
  1371. Console.WriteLine($"文件不存在: {fullPath}");
  1372. }
  1373. }
  1374. catch (Exception ex)
  1375. {
  1376. // 捕获异常并输出错误信息
  1377. Console.WriteLine($"发生错误: {ex.Message}");
  1378. }
  1379. return compensationDict;
  1380. }
  1381. /// <summary>
  1382. /// 调用进站接口并保存进站数据
  1383. /// </summary>
  1384. /// <param name="stationNameStr">工站信息</param>
  1385. /// <param name="workorder_code">工单号</param>
  1386. /// <param name="mtltmrk">型号(物料号)</param>
  1387. /// <param name="sn">产品SN</param>
  1388. /// <param name="items">进站数据</param>
  1389. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1390. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn,
  1391. List<TestItem> items, string MachineId, string StationId)
  1392. {
  1393. int result = 0;
  1394. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1395. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1396. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1397. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1398. inRequest_Body.clientTime =
  1399. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1400. inRequest_Body.unitSn = sn; // 产品SN
  1401. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1402. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1403. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1404. StationIn stationIn = new StationIn()
  1405. {
  1406. Workorder_code = workorder_code, // 车间订单号
  1407. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1408. Sn = sn, // SN
  1409. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1410. Parameter_values = items, // 进站数据
  1411. Write_user = inRequest_Body.userId, // 员工Id
  1412. Test_time = inRequest_Body.clientTime // 进站时间
  1413. };
  1414. // 本地数据
  1415. string sql = stationIn.ToStringInsert(0);
  1416. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1417. result = ret == "成功" ? 1 : 6;
  1418. //await Task.Delay(200);
  1419. // 上传MES
  1420. if (GlobalContext.IsSendStationIn)
  1421. {
  1422. try
  1423. {
  1424. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1425. string resultJson = "";
  1426. string mesRet = string.Empty;
  1427. int i = 0;
  1428. while (i < 2) // 1009会多次尝试上传
  1429. {
  1430. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1431. resultJson = JsonConvert.SerializeObject(response);
  1432. if (response != null && response.header.code == "200")
  1433. break;
  1434. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1435. i++;
  1436. i++;
  1437. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1438. // 记录失败原因
  1439. OnMessage(LogType.Error, $"上传出站数据到MES服务器---失败!正在重新上传!请求参数:{json_Body},接口报错信息:" + mesRet);
  1440. }
  1441. if (response?.header?.code == "200")
  1442. {
  1443. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1444. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1445. result = ret_Upd == "成功" ? 1 : 6;
  1446. AddMessage( LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功,请求参数:{json_Body},返回参数:{resultJson}");
  1447. }
  1448. else
  1449. {
  1450. result = 5;
  1451. AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!请求参数:{json_Body},接口报错信息:" + mesRet);
  1452. }
  1453. string sql_response =
  1454. stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1455. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1456. }
  1457. catch (Exception ex)
  1458. {
  1459. result = 6;
  1460. string str = ex.StackTrace;
  1461. AddMessage_Station(stationNameStr, LogType.Error,
  1462. $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1463. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1464. }
  1465. }
  1466. return result;
  1467. }
  1468. /// <summary>
  1469. /// 选择如何记录出站数据
  1470. /// </summary>
  1471. /// <param name="items">出站数据</param>
  1472. /// <param name="equipmentCode">设备编号</param>
  1473. /// <param name="processItem">测试项目</param>
  1474. /// <param name="workorder_code">车间订单号</param>
  1475. /// <param name="batch_num">批次号</param>
  1476. /// <param name="mtltmrk">型号</param>
  1477. /// <param name="proDate">日期</param>
  1478. /// <param name="supplierCode">供应商代码</param>
  1479. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1480. /// <returns>上传成功时返回1;失败返回0</returns>
  1481. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode,
  1482. string processItem,
  1483. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1484. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode,string jsonParm, string direction="")
  1485. {
  1486. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
  1487. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode, jsonParm, direction);
  1488. }
  1489. /// <summary>
  1490. /// 添加出站数据(提交到MES+本地保存到数据库)
  1491. /// </summary>
  1492. /// <param name="items">出站数据</param>
  1493. /// <param name="equipmentCode">设备编号</param>
  1494. /// <param name="processItem">测试项目</param>
  1495. /// <param name="workorder_code">车间订单号</param>
  1496. /// <param name="batch_num">批次号</param>
  1497. /// <param name="mtltmrk">型号</param>
  1498. /// <param name="proDate">日期</param>
  1499. /// <param name="supplierCode">供应商代码</param>
  1500. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1501. /// <returns>上传成功时返回1;失败返回0</returns>
  1502. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1503. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1504. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode,string jsonParm,string direction="")
  1505. {
  1506. int upload = 0;
  1507. int result = 0;
  1508. ProcessData processData = new ProcessData()
  1509. {
  1510. Equipment_code = equipmentCode,
  1511. Workorder_code = workorder_code,
  1512. Batch_number = batch_num,
  1513. Sn = sn, // SN
  1514. Testitem = processItem,
  1515. Parameter_values = items,
  1516. Write_user = GlobalContext.CurrentUser,
  1517. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1518. };
  1519. // 本地数据
  1520. string sql = processData.ToStringInsert(upload);
  1521. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1522. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1523. string uuid = "";
  1524. // 上传MES
  1525. if (GlobalContext.IsSendProcessData)
  1526. {
  1527. try
  1528. {
  1529. string id = processData.ID.Copy();
  1530. uuid = Guid.NewGuid().ToString();
  1531. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1532. outRequest_Body.uuidInspection = uuid;
  1533. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1534. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1535. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1536. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1537. outRequest_Body.unitSn = sn; // 产品SN
  1538. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1539. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1540. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1541. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1542. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1543. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1544. if (!string.IsNullOrEmpty(partBarcode))
  1545. {
  1546. outRequest_Body.unitData.keyMaterial.Add(
  1547. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1548. {
  1549. bindSort = 1,
  1550. materialSn = partBarcode
  1551. }); // 设备数据 - 部件码
  1552. }
  1553. //OP30站读txt数据
  1554. if (stationNameStr.Contains("CPAPHD"))
  1555. {
  1556. string path = "";
  1557. if (direction == "Left")
  1558. path = GlobalContext.MESLaserLPath;
  1559. else
  1560. path = GlobalContext.MESLaserRPath;
  1561. //字典存储数据
  1562. Dictionary<string, string> compensationDict = GetLastLineCompensation(path, direction, sn);
  1563. foreach (var kvp in compensationDict)
  1564. {
  1565. outRequest_Body.unitData.processData.Add(
  1566. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1567. {
  1568. dataName = kvp.Key.ToString(),
  1569. dataValue = kvp.Value.ToString()
  1570. });
  1571. }
  1572. }
  1573. //过站明细
  1574. if (GlobalContext.IsSendProcessDetail)
  1575. {
  1576. if (jsonParm.Length > 0)
  1577. {
  1578. // 解析JSON字符串为字典
  1579. var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonParm);
  1580. foreach (var kvp in dictionary)
  1581. {
  1582. outRequest_Body.unitData.processData.Add(
  1583. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1584. {
  1585. dataName = kvp.Key.ToString(),
  1586. dataValue = kvp.Value.ToString()
  1587. });
  1588. }
  1589. }
  1590. }
  1591. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1592. if (GlobalContext.IsSendProcessData)
  1593. {
  1594. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1595. string mesRet = string.Empty;
  1596. int i = 0;
  1597. while (i < 2) // 1009会多次尝试上传
  1598. {
  1599. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1600. if (response != null && response.header.code == "200")
  1601. {
  1602. OnMessage(LogType.Error,
  1603. "上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" +
  1604. JsonConvert.SerializeObject(response.body));
  1605. break;
  1606. }
  1607. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1608. i++;
  1609. i++;
  1610. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1611. // 记录失败原因
  1612. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1613. }
  1614. if (response?.header?.code == "200")
  1615. {
  1616. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1617. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1618. result = 1;
  1619. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1620. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1621. }
  1622. else
  1623. {
  1624. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1625. }
  1626. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(
  1627. JsonConvert.SerializeObject(outRequest_Body),
  1628. JsonConvert.SerializeObject(response), id);
  1629. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1630. }
  1631. }
  1632. catch (Exception ex)
  1633. {
  1634. string str = ex.StackTrace;
  1635. AddMessage_Station(stationNameStr, LogType.Error,
  1636. $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1637. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1638. }
  1639. }
  1640. if (GlobalContext.IsMqttSendProcessData)
  1641. {
  1642. PassStationDetailRequest request = new PassStationDetailRequest();
  1643. request.pass_station_id = uuid;
  1644. request.sn = sn; // 产品SN
  1645. request.slot = ""; // 槽位编码
  1646. request.test_item_num = "1";
  1647. request.function_name = "Machine_加⼯模块";
  1648. request.status = "PASS";
  1649. (int, string) iotResult = (0, "");
  1650. if (jsonParm.Length > 0)
  1651. {
  1652. // 解析JSON字符串为字典
  1653. var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonParm);
  1654. foreach (var kvp in dictionary)
  1655. {
  1656. request.test_item= kvp.Key.ToString();
  1657. request.result_val = kvp.Value.ToString();
  1658. request.description = request.test_item;
  1659. // 上传过站结果
  1660. iotResult = XiaomiMqttClient_Extend.Write_PassStationDetail(request);
  1661. if (iotResult.Item1 != 0)
  1662. {
  1663. OnMessage(LogType.Info, $"【IOT过站明细】上传失败!错误原因:{iotResult.Item2},过站明细;产品码[{sn}] 测试项目[{request.test_item}] 测试值[{request.result_val}]");
  1664. }
  1665. }
  1666. }
  1667. }
  1668. return result;
  1669. }
  1670. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1671. //{
  1672. // Stopwatch stopwatch = new Stopwatch();
  1673. // stopwatch.Start();
  1674. // try
  1675. // {
  1676. // // 初始化 AtlasScrew 实例
  1677. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1678. // atlasScrew1.Initial();
  1679. // // 存储结果的列表
  1680. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1681. // // 存储角度和扭力的字符串列表
  1682. // List<string> angleStrs = new List<string>();
  1683. // List<string> torqueStrs = new List<string>();
  1684. // // 上一次获取的数据
  1685. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1686. // while (isExitAtlasLeft) // 检查是否收集数据
  1687. // {
  1688. // // 获取当前数据
  1689. // var currentResult = atlasScrew1.GetResults();
  1690. // // 判断是否为新数据
  1691. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1692. // {
  1693. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1694. // // 更新角度和扭力的字符串列表
  1695. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1696. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1697. // // 计算角度、扭力、起始扭力和最大扭力
  1698. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1699. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1700. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1701. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1702. // // 将新数据添加到结果列表
  1703. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1704. // // 更新上一次获取的数据
  1705. // lastResult = currentResult;
  1706. // }
  1707. // // 等待一段时间后再次检查
  1708. // Thread.Sleep(20); // 轮询间隔时间
  1709. // // 如果触发了出站,则退出循环
  1710. // if (!isExitAtlasLeft)
  1711. // {
  1712. // break;
  1713. // }
  1714. // }
  1715. // // 生成文件名
  1716. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1717. // // 写入数据到文件
  1718. // using (StreamWriter writer = new StreamWriter(fileName))
  1719. // {
  1720. // // 写入标题行
  1721. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1722. // // 写入每一行数据
  1723. // foreach (var result in results)
  1724. // {
  1725. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1726. // }
  1727. // }
  1728. // stopwatch.Stop();
  1729. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1730. // }
  1731. // catch (Exception ex)
  1732. // {
  1733. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1734. // }
  1735. // finally
  1736. // {
  1737. // // 重置标志变量
  1738. // isExitAtlasLeft = false;
  1739. // }
  1740. //}
  1741. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1742. //{
  1743. // Stopwatch stopwatch = new Stopwatch();
  1744. // stopwatch.Start();
  1745. // try
  1746. // {
  1747. // // 初始化 AtlasScrew 实例
  1748. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1749. // atlasScrew2.Initial();
  1750. // // 存储结果的列表
  1751. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1752. // // 上一次获取的数据
  1753. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1754. // while (isExitAtlasRight) // 检查是否收集数据
  1755. // {
  1756. // // 获取当前数据
  1757. // var currentResult = atlasScrew2.GetResults();
  1758. // // 判断是否为新数据
  1759. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1760. // {
  1761. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1762. // // 将新数据写入PLC
  1763. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1764. // // 将新数据添加到结果列表
  1765. // results.Add(currentResult);
  1766. // // 更新上一次获取的数据
  1767. // lastResult = currentResult;
  1768. // }
  1769. // // 等待一段时间后再次检查
  1770. // Thread.Sleep(20); // 轮询间隔时间
  1771. // // 如果触发了出站,则退出循环
  1772. // if (!isExitAtlasRight)
  1773. // {
  1774. // break;
  1775. // }
  1776. // }
  1777. // // 将所有数据写入文件
  1778. // //WriteDataToFile(sn, direction, results);
  1779. // stopwatch.Stop();
  1780. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1781. // }
  1782. // catch (Exception ex)
  1783. // {
  1784. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1785. // }
  1786. // finally
  1787. // {
  1788. // // 重置标志变量
  1789. // isExitAtlasRight = false;
  1790. // }
  1791. //}
  1792. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1793. {
  1794. Stopwatch stopwatch = new Stopwatch();
  1795. stopwatch.Start();
  1796. int nRet = 0;
  1797. string strRet = "";
  1798. try
  1799. {
  1800. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1801. while (isCollectingFlagLeft)
  1802. {
  1803. // 从缓存中获取所有未处理的数据
  1804. var cachedData = atlasScrew.GetCachedDataLeft();
  1805. foreach (var currentResult in cachedData)
  1806. {
  1807. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1808. {
  1809. continue; // 跳过无效数据
  1810. }
  1811. OnMessage(LogType.Info,
  1812. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1813. // 写入PLC
  1814. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1815. {
  1816. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1817. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1818. };
  1819. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1820. if (nRet != 0)
  1821. {
  1822. OnMessage(LogType.Info,
  1823. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1824. }
  1825. else
  1826. {
  1827. OnMessage(LogType.Info,
  1828. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1829. }
  1830. // 构建保存路径
  1831. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1832. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1833. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1834. Directory.CreateDirectory(savePath); // 确保目录存在
  1835. // 构建文件名(以 SN + 序号命名)
  1836. string fileName = $"{sn}_{fileCounter}.txt";
  1837. string filePath = Path.Combine(savePath, fileName);
  1838. // 写入文件
  1839. using (StreamWriter writer = new StreamWriter(filePath))
  1840. {
  1841. writer.WriteLine("精度, 扭力");
  1842. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1843. for (int i = 0;
  1844. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  1845. i++)
  1846. {
  1847. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1848. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1849. writer.WriteLine($"{precision}, {torque}");
  1850. }
  1851. }
  1852. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1853. // 增加文件计数器
  1854. fileCounter++;
  1855. }
  1856. // 如果没有更多数据,则短暂休眠以节省资源
  1857. if (!cachedData.Any())
  1858. {
  1859. Thread.Sleep(10); // 根据需要调整休眠时间
  1860. }
  1861. // 如果触发了出站,则退出循环
  1862. if (!isCollectingFlagLeft)
  1863. {
  1864. break;
  1865. }
  1866. }
  1867. stopwatch.Stop();
  1868. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1869. }
  1870. catch (Exception ex)
  1871. {
  1872. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1873. }
  1874. finally
  1875. {
  1876. isCollectingFlagLeft = false;
  1877. }
  1878. }
  1879. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1880. {
  1881. Stopwatch stopwatch = new Stopwatch();
  1882. stopwatch.Start();
  1883. int nRet = 0;
  1884. string strRet = "";
  1885. try
  1886. {
  1887. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1888. while (isCollectingFlagRight)
  1889. {
  1890. // 从缓存中获取所有未处理的数据
  1891. var cachedData = atlasScrew.GetCachedDataLeft();
  1892. foreach (var currentResult in cachedData)
  1893. {
  1894. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1895. {
  1896. continue; // 跳过无效数据
  1897. }
  1898. OnMessage(LogType.Info,
  1899. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1900. // 写入PLC
  1901. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1902. {
  1903. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1904. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1905. };
  1906. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1907. if (nRet != 0)
  1908. {
  1909. OnMessage(LogType.Info,
  1910. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1911. }
  1912. else
  1913. {
  1914. OnMessage(LogType.Info,
  1915. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1916. }
  1917. // 构建保存路径
  1918. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1919. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1920. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1921. Directory.CreateDirectory(savePath); // 确保目录存在
  1922. // 构建文件名(以 SN + 序号命名)
  1923. string fileName = $"{sn}_{fileCounter}.txt";
  1924. string filePath = Path.Combine(savePath, fileName);
  1925. // 写入文件
  1926. using (StreamWriter writer = new StreamWriter(filePath))
  1927. {
  1928. writer.WriteLine("精度, 扭力");
  1929. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1930. for (int i = 0;
  1931. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  1932. i++)
  1933. {
  1934. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1935. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1936. writer.WriteLine($"{precision}, {torque}");
  1937. }
  1938. }
  1939. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1940. // 增加文件计数器
  1941. fileCounter++;
  1942. }
  1943. // 如果没有更多数据,则短暂休眠以节省资源
  1944. if (!cachedData.Any())
  1945. {
  1946. Thread.Sleep(10); // 根据需要调整休眠时间
  1947. }
  1948. // 如果触发了出站,则退出循环
  1949. if (!isCollectingFlagRight)
  1950. {
  1951. break;
  1952. }
  1953. }
  1954. stopwatch.Stop();
  1955. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1956. }
  1957. catch (Exception ex)
  1958. {
  1959. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1960. }
  1961. finally
  1962. {
  1963. isCollectingFlagRight = false;
  1964. }
  1965. }
  1966. /// <summary>
  1967. /// 上传文件
  1968. /// </summary>
  1969. /// <param name="BarcodeSet_t">条码集合</param>
  1970. /// <param name="stationCode">工站编号</param>
  1971. /// <param name="stationName">工站名称</param>
  1972. /// <param name="path">文件路径</param>
  1973. public async Task<(int, string)> SaveDBbyFileInfo(BarcodeSet_t BarcodeSet, string stationCode, string stationName,string path)
  1974. {
  1975. string sql, filename = "";
  1976. Guid guid;
  1977. int result = 0;
  1978. var formData = new MultipartFormDataContent();
  1979. // 获取所有图片文件
  1980. List<string> imageFiles = GetAllImageFiles(path);
  1981. try
  1982. {
  1983. if (imageFiles.Count>0)
  1984. {
  1985. foreach (string imageFile in imageFiles)
  1986. {
  1987. guid = Guid.NewGuid();
  1988. filename = Path.GetFileName(imageFile);
  1989. sql = string.Format("INSERT INTO [dbo].[DataFiles](stationCode,stationName,CarrierBarcode,ProductBarcode,bucket,fileName,fileContext,uuid,fileUrl,status,submitTime,createTime) " +
  1990. "VALUES('{0}','{1}','{2}' ,'{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')"
  1991. , stationCode
  1992. , stationName
  1993. , BarcodeSet.strCarrierBarcode
  1994. , BarcodeSet.strProductBarcode
  1995. , "/mesCommToPC/pic/left"
  1996. , filename
  1997. , ""
  1998. , guid.ToString()
  1999. , ""
  2000. , 0
  2001. , ""
  2002. , DateTime.Now
  2003. );
  2004. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  2005. FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
  2006. string bucket = string.Empty;
  2007. //bucket = "IMAGE/IMAGE/N3/debug/online/PASS/M0002PA-0001/P320N000006B/382f55e9-c2bb";
  2008. bucket = "/mesCommToPC/pic/left";
  2009. fileUpload_X5.bucket = bucket;
  2010. fileUpload_X5.name = filename;
  2011. fileUpload_X5.uuid = guid.ToString();
  2012. ///需要上传文件
  2013. FileInfo file = new FileInfo(imageFile);
  2014. string fileMd5Hex = GetMD5Hex(file);
  2015. fileUpload_X5.md5 = fileMd5Hex;
  2016. fileUpload_X5.uploadCloud = true;
  2017. fileUpload_X5.informMqtt = true;
  2018. FileMqttPayload fileMqttPayload = new FileMqttPayload();
  2019. //fileMqttPayload.factory = "";
  2020. //fileMqttPayload.project_name = "";
  2021. //fileMqttPayload.product_mode = "";
  2022. //fileMqttPayload.line_no = "";
  2023. //fileMqttPayload.work_station_no = "";
  2024. //fileMqttPayload.equipment_no = "";
  2025. //fileMqttPayload.station_no = "";
  2026. //fileMqttPayload.file_id = "";
  2027. //fileMqttPayload.file_name = "";
  2028. //fileMqttPayload.sn = "";
  2029. //fileMqttPayload.opt_time = "";
  2030. //fileMqttPayload.file_type = "";
  2031. //fileMqttPayload.file_category = "";
  2032. //fileMqttPayload.tag = "";
  2033. //fileMqttPayload.pass_station_id = "";
  2034. //FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
  2035. //FileMqttPayload fileMqttPayload = new FileMqttPayload();
  2036. //fileUpload_X5.bucket = "IMAGE/IMAGE/N3/debug/online/PASS/M0002PA-0001/P320N000006B/382f55e9-c2bb";
  2037. //fileUpload_X5.name = "test";
  2038. //fileUpload_X5.md5 = "";
  2039. //fileUpload_X5.uploadCloud = true;
  2040. //fileUpload_X5.informMqtt = true;
  2041. var fileresult = XiaomiMESHttp_UpLoadFile.FileUoladToMes(imageFile, fileUpload_X5, fileMqttPayload);
  2042. if (fileresult.Result.Item1 == 0)
  2043. {
  2044. return (1, fileresult.Result.Item2);
  2045. }
  2046. sql = string.Format("UPDATE [dbo].[DataFiles] SET status='{0}' WHERE uuid='{1}'", 1, guid);
  2047. string retnew = SQLHelper_New.ExecuteNonQuery(sql, null);
  2048. return fileresult.Result;
  2049. }
  2050. return (1, "程序错误!");
  2051. }
  2052. else
  2053. {
  2054. return (1,"文件不存在!");
  2055. }
  2056. }
  2057. catch (Exception e)
  2058. {
  2059. return (1, filename + $"图片保存失败!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode},错误原因:" + e.Message);
  2060. //AddMessage_Station(stationName, LogType.Error, filename + $"图片保存失败!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode}");
  2061. }
  2062. }
  2063. /// <summary>
  2064. /// 获取路径下的所有图片
  2065. /// </summary>
  2066. /// <param name="directoryPath"></param>
  2067. /// <returns></returns>
  2068. public List<string> GetAllImageFiles(string directoryPath)
  2069. {
  2070. var imageExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { ".jpg", ".jpeg", ".png", ".bmp", ".gif", ".tiff" };
  2071. var imageFiles = new List<string>();
  2072. try
  2073. {
  2074. // 遍历目录及子目录中的所有文件
  2075. foreach (string file in Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories))
  2076. {
  2077. // 获取文件扩展名并检查是否为图片格式
  2078. string extension = Path.GetExtension(file);
  2079. if (imageExtensions.Contains(extension))
  2080. {
  2081. imageFiles.Add(file);
  2082. }
  2083. }
  2084. }
  2085. catch (Exception ex)
  2086. {
  2087. OnMessage(LogType.Error, $"图片查询发生错误: {ex.Message}");
  2088. }
  2089. return imageFiles;
  2090. }
  2091. /// <summary>
  2092. /// 实例化报警字典
  2093. /// </summary>
  2094. private (bool, string) InitalDicAlarm()
  2095. {
  2096. #region 加载报警表
  2097. string excelPath = "";
  2098. switch (GlobalContext.IsUsePLCNow)
  2099. {
  2100. case 1:
  2101. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_10_壳体清洁上料.xlsx";
  2102. break;
  2103. case 2:
  2104. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_20_上盖板上料装备.xlsx";
  2105. break;
  2106. case 3:
  2107. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_30_点散热胶装备.xlsx";
  2108. break;
  2109. case 4:
  2110. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_40_胶线检测.xlsx";
  2111. break;
  2112. case 5:
  2113. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_50_ADD板上料组装装备.xlsx";
  2114. break;
  2115. case 6:
  2116. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_60_组上盖板.xlsx";
  2117. break;
  2118. case 7:
  2119. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_70_上盖板锁螺丝.xlsx";
  2120. break;
  2121. case 8:
  2122. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_80_NG下料.xlsx";
  2123. break;
  2124. case 9:
  2125. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_90_半成品下料.xlsx";
  2126. break;
  2127. default:
  2128. return (false, $"不支持当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请在设置页切换到正确的plc后重启该软件!");
  2129. }
  2130. if (!File.Exists(excelPath))
  2131. return (false, $"未找到当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请检查文件路径:'{excelPath}'。");
  2132. DataTable DtModel = NPOIHelper.ReadExcel(excelPath);
  2133. if (DtModel == null || DtModel.Rows.Count < 1)
  2134. return (false, $"报警点位表未包含任何报警数据!请检查‘{excelPath}’文件!");
  2135. // 检查列名
  2136. List<string> isNeedParms = new List<string>() {"设备分类名称","设备分类编码","分类层级1","分类层级2","分类层级3" ,"分类层级4","事件名称"
  2137. ,"事件ID","描述","标签","PLC地址","工位"}; // 必须要有的列
  2138. // 指定列名 + 检查列是否完整
  2139. DataRow dtRowName = DtModel.Rows[0];
  2140. int count = DtModel.Columns.Count;
  2141. for (int i = 0; i < count; i++)
  2142. {
  2143. string columeName = dtRowName[i]?.ToString();
  2144. if (!string.IsNullOrEmpty(columeName))
  2145. DtModel.Columns[i].ColumnName = columeName;
  2146. if ((!string.IsNullOrEmpty(columeName)) && isNeedParms.Count > 0 && isNeedParms.Contains(columeName))
  2147. isNeedParms.Remove(columeName);
  2148. }
  2149. DtModel.Rows.RemoveAt(0);
  2150. if (isNeedParms.Count > 0)
  2151. {
  2152. string msg1 = string.Join(",", isNeedParms);
  2153. return (false, $"报警点位表未包含列:{msg1}!请检查‘{excelPath}’文件!");
  2154. }
  2155. #endregion 加载报警表
  2156. List<Alarm> keyValues1 = new List<Alarm>();
  2157. for (int i = 0; i < DtModel.Rows.Count; i++)
  2158. {
  2159. Alarm alarm = new Alarm();
  2160. alarm.plcName = DtModel.Rows[i]["设备分类名称"]?.ToString(); // 设备名;
  2161. string type1Str = DtModel.Rows[i]["分类层级1"]?.ToString(); // 分类层级1;
  2162. alarm.type1CH = type1Str; // 分类层级1 中文
  2163. alarm.type1 = type1Str; // 分类层级1
  2164. if (!string.IsNullOrEmpty(type1Str) && type1Str.Contains("\n"))
  2165. {
  2166. string[] type1Strs = type1Str.Split('\n');
  2167. if (type1Strs.Length >= 2)
  2168. {
  2169. alarm.type1CH = type1Strs[0].Trim(); // 分类层级1 中文
  2170. alarm.type1 = type1Strs[1].Trim(); // 分类层级1
  2171. if (string.IsNullOrEmpty(alarm.type1))
  2172. alarm.type1 = alarm.type1CH;
  2173. }
  2174. }
  2175. string type2Str = DtModel.Rows[i]["分类层级2"]?.ToString(); // 分类层级2;电气控制 electric_control
  2176. alarm.type2CH = type2Str; // 分类层级2 中文
  2177. alarm.type2 = type2Str; // 分类层级2
  2178. if (!string.IsNullOrEmpty(type2Str) && type2Str.Contains("\n"))
  2179. {
  2180. string[] type2Strs = type2Str.Split('\n');
  2181. if (type2Strs.Length >= 2)
  2182. {
  2183. alarm.type2CH = type2Strs[0].Trim(); // 分类层级2 中文
  2184. alarm.type2 = type2Strs[1].Trim(); // 分类层级2
  2185. if (string.IsNullOrEmpty(alarm.type2))
  2186. alarm.type2 = alarm.type2CH;
  2187. }
  2188. }
  2189. string type3Str = DtModel.Rows[i]["分类层级3"]?.ToString(); // 分类层级3;故障 Fault
  2190. alarm.type3CH = type3Str; // 分类层级3 中文
  2191. alarm.type3 = type3Str; // 分类层级3
  2192. if (!string.IsNullOrEmpty(type3Str) && type3Str.Contains("\n"))
  2193. {
  2194. string[] type3Strs = type3Str.Split('\n');
  2195. if (type3Strs.Length >= 2)
  2196. {
  2197. alarm.type3CH = type3Strs[0].Trim(); // 分类层级3 中文
  2198. alarm.type3 = type3Strs[1].Trim(); // 分类层级3
  2199. if (string.IsNullOrEmpty(alarm.type3))
  2200. alarm.type3 = alarm.type3CH;
  2201. }
  2202. }
  2203. string faultStr = DtModel.Rows[i]["分类层级4"]?.ToString(); // 故障部件;overall_module
  2204. alarm.type4 = faultStr; // 分类层级4 中文
  2205. alarm.type4CH = faultStr; // 分类层级4
  2206. if (!string.IsNullOrEmpty(faultStr) && faultStr.Contains("\n"))
  2207. {
  2208. string[] faultStrs = faultStr.Split('\n');
  2209. if (faultStrs.Length >= 2)
  2210. {
  2211. alarm.type4CH = faultStrs[0].Trim(); // 故障部件;overall_module
  2212. alarm.type4 = faultStrs[1].Trim(); // 故障部件
  2213. if (string.IsNullOrEmpty(alarm.type4))
  2214. alarm.type4 = alarm.type4CH;
  2215. }
  2216. }
  2217. alarm.fault_code = DtModel.Rows[i]["事件ID"]?.ToString(); // 故障编码;A40001
  2218. alarm.fault_name = DtModel.Rows[i]["事件名称"]?.ToString(); // 故障名称;AL[1000]_系统_HMI急停故障
  2219. alarm.fault_desc = alarm.fault_name; // 故障描述;AL[1000]_系统_HMI急停故障
  2220. string plcAdress = DtModel.Rows[i]["PLC地址"]?.ToString();
  2221. alarm.PLC地址 = plcAdress;
  2222. plcAdress = plcAdress.Replace("fault_codes[", "");
  2223. plcAdress = plcAdress.Replace("]", "");
  2224. alarm.group_index = Convert.ToInt32(plcAdress.Split(".")[0]);
  2225. keyValues1.Add(alarm);
  2226. }
  2227. DicAlarms_Cur.Add(GlobalContext.IsUseStationName, keyValues1); // 这里使用线体代替工位
  2228. return (true, "报警字典表初始化成功!");
  2229. }
  2230. private async void ReadPLCAlarmToIot(uint[] FaultData,string stationNameStr)
  2231. {
  2232. DateTime dtNow = DateTime.Now;
  2233. try
  2234. {
  2235. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  2236. List<(int, int)> AlarmIndexList = new List<(int, int)>();//收集所有报警信息的位置
  2237. AlarmData alarmData = new AlarmData();
  2238. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  2239. bool isNoAlarm = false;//是否有报警
  2240. string binaryString = "";
  2241. bool isNoNewAlarm = false;//是否有新的报警
  2242. if (FaultData.Length > 0)
  2243. {
  2244. }
  2245. foreach (var item in FaultData)
  2246. {
  2247. isNoAlarm = item > 0 ? true : false;
  2248. }
  2249. if (!FaultData.SequenceEqual(_FaultDatas_Old))
  2250. {
  2251. isNoNewAlarm = true;
  2252. isNeedUpdUI = true;
  2253. }
  2254. if (FaultData.Length > 0 && isNoAlarm && isNoNewAlarm)
  2255. {
  2256. //解析报警信息,分析当前报警在字典中的定位
  2257. for (int i = 0; i <= FaultData.Length - 1; i++)
  2258. {
  2259. var num = 0;
  2260. if (FaultData[i] > 0)
  2261. {
  2262. //转换二进制
  2263. binaryString = Convert.ToString(FaultData[i], 2);
  2264. for (int j = binaryString.Length - 1; j >= 0; j--)
  2265. {
  2266. num++;
  2267. char s = binaryString[j];
  2268. if (binaryString[j] == '1')
  2269. {
  2270. //记录1的位置
  2271. AlarmIndexList.Add((i, num - 1));
  2272. }
  2273. }
  2274. }
  2275. }
  2276. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  2277. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.IsUseStationName];
  2278. foreach ((int index, int row) in AlarmIndexList)
  2279. {
  2280. var tempDic = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList();
  2281. for (int i = 0; i < tempDic.Count - 1; i++) // 读取
  2282. {
  2283. //若报警字典第[group_index]个数据,第[i]行与AlarmIndexList中的定位匹配,则添加进对应行的报警数据
  2284. if (tempDic[i].group_index == index && i == row)
  2285. {
  2286. dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据 = new AlarmData()
  2287. {
  2288. GUID = Guid.NewGuid().ToString(),
  2289. LineName = GlobalContext.IsUseStationName, // 工站
  2290. PlcStation = tempDic[i].plcName, // 工站全称;[S1]
  2291. Type1 = tempDic[i].type1, // 故障层级1
  2292. Type2 = tempDic[i].type2, // 故障层级2
  2293. Type3 = tempDic[i].type3, // 故障层级3
  2294. Type4 = tempDic[i].type4, // 故障层级4
  2295. AlarmType = tempDic[i].fault_code, // 报警类型
  2296. AlarmDesc = tempDic[i].fault_name, // 报警内容
  2297. StartTime = dtNow // 开始时间
  2298. };
  2299. // 传输到页面
  2300. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  2301. {
  2302. 线体名称 = tempDic[i].plcName,
  2303. 报警类型 = tempDic[i].fault_code,
  2304. 报警内容 = tempDic[i].fault_name,
  2305. 开始时间 = dtNow
  2306. });
  2307. // 新增到数据库
  2308. //var data1 = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据;
  2309. //SaveAlarmDataByDB(stationNameStr, data1, false);
  2310. //OnMessage(LogType.Info, $"更新{BodyAlarm}完毕!");
  2311. }
  2312. }
  2313. }
  2314. //筛选含报警数据的字典
  2315. var dicAlarms_Cur = dicAlarms_Cur_PLC1.Where(x => x.报警数据 != null).ToList();
  2316. if (dicAlarms_Cur.Count > 0)
  2317. {
  2318. foreach (var item in dicAlarms_Cur)
  2319. {
  2320. //上传
  2321. SaveAlarmDataByDB(GlobalContext.IsUseStationName, item.报警数据, false);
  2322. }
  2323. }
  2324. // 有新报警则更新
  2325. if (isNeedUpdUI)
  2326. // UI展示 - 展示到设备状态页
  2327. await Task.Run(() =>
  2328. {
  2329. try
  2330. {
  2331. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  2332. {
  2333. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  2334. if (Form_Main.formDevAlarm.Visible)
  2335. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  2336. }
  2337. }
  2338. catch { }
  2339. });
  2340. _FaultDatas_Old = FaultData.ToArray();
  2341. }
  2342. //FaultLogRequest request = new FaultLogRequest();
  2343. //request.station = mesStation; // 工位
  2344. //request.fault_name = xmFaultName; // 故障名称(同数据字典中的事件名称)
  2345. //request.fault_code = xmFaultCode2; // 故障编码(A,B,C,D,E)
  2346. //request.fault_cmpnt = xmFaultCmpnt; // 故障部件
  2347. //request.fault_desc = xmFaultDesc; // 故障描述
  2348. //request.fault_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 故障发生时间 2022-06-01 14:27:57.283
  2349. // // 上传
  2350. //(int, string) iotResult = XiaomiMqttClient_Extend.Write_FaultLog(request, type1, type2, type3, request.fault_cmpnt, deciveCode);
  2351. }
  2352. catch (Exception ex)
  2353. {
  2354. string str = ex.StackTrace;
  2355. AddMessage_Station(stationNameStr, LogType.Error, $"{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2356. }
  2357. }
  2358. #endregion
  2359. #region S1
  2360. /// <summary>
  2361. /// [S1] 壳体清洁上料装备
  2362. /// </summary>
  2363. /// <param name="plcNo">PLC编号</param>
  2364. private void ReadStation_S1(int plcNo)
  2365. {
  2366. string stationCode = "[OP10]";
  2367. string stationName = "壳体清洁上料";
  2368. string stationNameStr = stationCode + stationName;
  2369. string tagBaseName = "g_OP10_MES"; //标签变量名称
  2370. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2371. string tagAgvCommName = "agvCommFrmPC";
  2372. string tagBarsetName = "BarcodeSet";
  2373. // 触发信号字典
  2374. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2375. s1PLCSignal_Old.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2376. // PLC数据字典 赋值
  2377. s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2378. s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  2379. s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  2380. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  2381. (int, string) result;
  2382. while (true)
  2383. {
  2384. try
  2385. {
  2386. if (!GlobalContext._IsCon_Funs1)
  2387. {
  2388. UpdatePLCMonitor(1, plcNo, 0);
  2389. continue;
  2390. }
  2391. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2392. {
  2393. Stopwatch stopwatch1 = new Stopwatch();
  2394. Stopwatch stopwatch2 = new Stopwatch();
  2395. stopwatch1.Start();
  2396. stopwatch2.Start();
  2397. #region 一次性读取所有数据
  2398. // 一次性读取所有数据
  2399. result = FunsEip[plcNo]
  2400. .Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2401. if (result.Item1 != 0)
  2402. {
  2403. //richTextBox1.AppendText("\n" + strRet);
  2404. }
  2405. else
  2406. {
  2407. //richTextBox1.AppendText("\n" + "读取成功");
  2408. //设备状态
  2409. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  2410. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  2411. ? XiaomiDeviceState.Unknown
  2412. : (XiaomiDeviceState)xmDeviceStateInt;
  2413. // 物料码(物料码还未绑定载具SN时必填)
  2414. s1PLCData["a1OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode;
  2415. // 载具SN
  2416. s1PLCData["a1OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode;
  2417. // 节拍
  2418. s1PLCData["a1OEEType"] = stPLC_MesData.iotData.BeatAction;
  2419. //报警信息
  2420. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  2421. }
  2422. #endregion 一次性读取所有数据
  2423. stopwatch2.Stop();
  2424. #region 进站
  2425. try
  2426. {
  2427. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2428. {
  2429. lock (lockObj)
  2430. {
  2431. if (!ProgressState)
  2432. {
  2433. ProgressState = true;
  2434. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData,
  2435. tagBaseName + "." + tagMesCommName, out ProgressState));
  2436. }
  2437. }
  2438. }
  2439. }
  2440. catch (Exception ex)
  2441. {
  2442. ProgressState = false;
  2443. string str = ex.StackTrace;
  2444. AddMessage_Station(stationNameStr, LogType.Error,
  2445. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2446. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2447. }
  2448. #endregion 进站
  2449. #region 出站
  2450. try
  2451. {
  2452. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2453. {
  2454. lock (lockObj)
  2455. {
  2456. if (!ProgressState)
  2457. {
  2458. ProgressState = true;
  2459. stPLC_MesData.mesData.nThrowCount = 1;
  2460. stPLC_MesData.mesData.fCleanAirPress = 4;
  2461. stPLC_MesData.mesData.fCleanSpeed = 2;
  2462. stPLC_MesData.mesData.fWindBladeHeight = 5;
  2463. stPLC_MesData.mesData.fCleanTime = 2;
  2464. stPLC_MesData.mesData.nCleanCount = 7;
  2465. stPLC_MesData.mesData.nRemainCount = 1;
  2466. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData,
  2467. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  2468. out ProgressState));
  2469. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  2470. }
  2471. }
  2472. }
  2473. }
  2474. catch (Exception ex)
  2475. {
  2476. ProgressState = false;
  2477. string str = ex.StackTrace;
  2478. AddMessage_Station(stationNameStr, LogType.Error,
  2479. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2480. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2481. }
  2482. #endregion 出站
  2483. #region 节拍接口
  2484. try
  2485. {
  2486. int a10EEType = (int)s1PLCData["a10EEType"];
  2487. int a10EETypeGOld = (int)s1PLCSignal_Old["a10EEType"];
  2488. //若设备紧急复原后节拍重置
  2489. if (a10EEType == 1)
  2490. {
  2491. a10EETypeGOld = 0;
  2492. }
  2493. if (a10EEType != a10EETypeGOld)
  2494. {
  2495. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  2496. if ((a10EETypeGOld == 1 && a10EEType != 2) || (a10EETypeGOld == 3 && a10EEType != 4) ||
  2497. (a10EETypeGOld == 5 && a10EEType != 6))
  2498. {
  2499. //写入PLC
  2500. stPLC_MesData.iotData.beatReturn = 2; //NG
  2501. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  2502. AddMessage(LogType.Info,
  2503. stationNameStr +
  2504. $"_节拍接口-- 设备本次上传节拍[{a10EEType}],未上传节拍[{a10EETypeGOld}]的结束信号,请检查;总用时" +
  2505. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  2506. "ms");
  2507. return;
  2508. }
  2509. else
  2510. {
  2511. Task.Run(() =>
  2512. S1节拍接口(plcNo, stationNameStr, tagBaseName,
  2513. stPLC_MesData.iotData)); // MreTasks[4].Set();
  2514. }
  2515. s1PLCSignal_Old["a10EEType"] = s1PLCData["a10EEType"];
  2516. }
  2517. }
  2518. catch (Exception ex)
  2519. {
  2520. string str = ex.StackTrace;
  2521. AddMessage_Station(stationNameStr, LogType.Error,
  2522. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  2523. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2524. }
  2525. #endregion
  2526. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2527. stopwatch1.Stop();
  2528. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2529. }
  2530. else
  2531. {
  2532. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2533. AddMessage_Station(stationNameStr, LogType.Info,
  2534. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2535. FunsEip[plcNo].Connect(); // 重连
  2536. }
  2537. }
  2538. catch (Exception ex)
  2539. {
  2540. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2541. AddMessage_Station(stationNameStr, LogType.Error,
  2542. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2543. }
  2544. Thread.Sleep(IntervalReadPLC);
  2545. }
  2546. }
  2547. /// <summary>
  2548. /// [S1] 壳体清洁上料 - 进站
  2549. /// </summary>
  2550. /// <param name="plcNo">PLC编号</param>
  2551. /// <param name="stationNameStr">工站全称</param>
  2552. /// <param name="stPLC_MesData"></param>
  2553. /// <param name="tagMesCommName"></param>
  2554. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  2555. out bool ProgressState)
  2556. {
  2557. Stopwatch stopwatch1 = new Stopwatch();
  2558. Stopwatch stopwatch2 = new Stopwatch();
  2559. try
  2560. {
  2561. stopwatch1.Start();
  2562. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2563. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  2564. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2565. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  2566. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  2567. if (string.IsNullOrEmpty(sn))
  2568. {
  2569. ProgressState = false;
  2570. return;
  2571. }
  2572. //正式生产就用PLC中取的
  2573. //sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;
  2574. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  2575. sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2576. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2577. //绑定载具和产品
  2578. ResponseMessage message = new ResponseMessage();
  2579. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  2580. if (message.result == false)
  2581. {
  2582. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  2583. }
  2584. // 产品SN进站
  2585. List<TestItem> item = new List<TestItem>();
  2586. stopwatch2.Start();
  2587. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  2588. item, MachineId, StationId);
  2589. stopwatch2.Stop();
  2590. //指令执行结果 1:OK 110:失败
  2591. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2592. //进站结果写入PLC
  2593. CommandFromPLC resultToPlC = new CommandFromPLC();
  2594. resultToPlC.cmd = 0;
  2595. resultToPlC.cmdParam = 0;
  2596. resultToPlC.cmdResult = mesResultFrmWeb;
  2597. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2598. }
  2599. catch (Exception ex)
  2600. {
  2601. string str = ex.StackTrace;
  2602. AddMessage(LogType.Error,
  2603. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  2604. str.Length - str.LastIndexOf("\\") - 1));
  2605. CommandFromPLC resultToPlC = new CommandFromPLC();
  2606. resultToPlC.cmd = 0;
  2607. resultToPlC.cmdParam = 0; //指令参数
  2608. resultToPlC.cmdResult = 110;
  2609. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2610. }
  2611. stopwatch1.Stop();
  2612. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2613. AddMessage(LogType.Info,
  2614. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  2615. stopwatch2.ElapsedMilliseconds + "ms");
  2616. ProgressState = false;
  2617. }
  2618. /// <summary>
  2619. /// [S1] 壳体清洁上料 - 出站接口
  2620. /// </summary>
  2621. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  2622. string stationCode, string stationName, out bool ProgressState)
  2623. {
  2624. Stopwatch stopwatch1 = new Stopwatch();
  2625. Stopwatch stopwatch2 = new Stopwatch();
  2626. try
  2627. {
  2628. stopwatch1.Start();
  2629. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2630. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2631. string processItem = stationName; // 项目
  2632. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2633. string supplierCode = ""; // 供应商代码
  2634. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  2635. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  2636. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  2637. string sn = string.Empty;
  2638. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2639. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  2640. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  2641. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2642. //a1Result = 1;
  2643. bool pass = a1Result == 1;
  2644. //根据载具码获取产品码
  2645. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2646. if (string.IsNullOrEmpty(strProductBarcode))
  2647. {
  2648. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2649. }
  2650. sn = strProductBarcode;
  2651. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2652. List<TestItem> items = new List<TestItem>();
  2653. items.Add(new TestItem()
  2654. {
  2655. Parameter_name = "载具码",
  2656. Parameter_value = CarrierBarcode,
  2657. Parameter_unit = ""
  2658. });
  2659. items.Add(new TestItem()
  2660. {
  2661. Parameter_name = "产品码",
  2662. Parameter_value = sn,
  2663. Parameter_unit = ""
  2664. });
  2665. #region 转换过站明细字符串
  2666. //创建字典
  2667. var dic = new Dictionary<string, string>();
  2668. // 获取结构体类型
  2669. FieldInfo[] fields = typeof(OP10_DataSet_t).GetFields();
  2670. // 遍历变量名转换成字典描述
  2671. foreach (FieldInfo field in fields)
  2672. {
  2673. //获取枚举描述
  2674. string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name, typeof(XiaomiMESEnum_ProcessData.Enum_10_ProcessData));
  2675. //获取过站明细的值
  2676. object valueObj = field.GetValue(stPLC_MesData.mesData);
  2677. dic.Add(name, valueObj.ToString());
  2678. }
  2679. string paramJson = JsonConvert.SerializeObject(dic);
  2680. #endregion
  2681. //出站接口
  2682. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2683. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  2684. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2685. stopwatch2.Start();
  2686. //进站结果写入PLC
  2687. CommandFromPLC resultToPlC = new CommandFromPLC();
  2688. resultToPlC.cmd = 0;
  2689. resultToPlC.cmdParam = 0; //指令参数
  2690. resultToPlC.cmdResult = mesResultFrmWeb;
  2691. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2692. stopwatch2.Stop();
  2693. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2694. //保存PLC返回MES数据到本地
  2695. ResponseMessage message = new ResponseMessage();
  2696. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  2697. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress,
  2698. stPLC_MesData.mesData.fCleanSpeed,
  2699. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime,
  2700. stPLC_MesData.mesData.nCleanCount,
  2701. stPLC_MesData.mesData.nRemainCount);
  2702. if (message.result == false)
  2703. {
  2704. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2705. }
  2706. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  2707. }
  2708. catch (Exception ex)
  2709. {
  2710. stopwatch2.Start();
  2711. CommandFromPLC resultToPlC = new CommandFromPLC();
  2712. resultToPlC.cmd = 0;
  2713. resultToPlC.cmdParam = 0; //指令参数
  2714. resultToPlC.cmdResult = 110;
  2715. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2716. stopwatch2.Stop();
  2717. string str = ex.StackTrace;
  2718. AddMessage(LogType.Error,
  2719. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  2720. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2721. }
  2722. stopwatch1.Stop();
  2723. AddMessage(LogType.Info,
  2724. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  2725. stopwatch2.ElapsedMilliseconds + "ms");
  2726. ProgressState = false;
  2727. }
  2728. #endregion
  2729. #region S2
  2730. /// <summary>
  2731. /// [S2] 上盖板上料装备
  2732. /// </summary>
  2733. /// <param name="plcNo">PLC编号</param>
  2734. private void ReadStation_S2(int plcNo)
  2735. {
  2736. string stationCode = "[OP20]";
  2737. string stationName = "上盖板上料装备";
  2738. string stationNameStr = stationCode + stationName;
  2739. string tagBaseName = "g_OP20_MES"; //标签变量名称
  2740. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2741. string tagAgvCommName = "agvCommFrmPC";
  2742. string tagBarsetName = "BarcodeSet";
  2743. // 触发信号字典
  2744. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2745. s2PLCSignal_Old.Add("a2OEEType", 0); // 节拍类型(plc写入)
  2746. // PLC数据字典 赋值
  2747. s2PLCData.Add("a2OEEType", 0); // 节拍类型(plc写入)
  2748. s2PLCData.Add("a2OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  2749. s2PLCData.Add("a2OEEVehicleCode", ""); // 载具SN
  2750. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  2751. IoT_DataSet_t iot_data;
  2752. (int, string) result;
  2753. while (true)
  2754. {
  2755. try
  2756. {
  2757. if (!GlobalContext._IsCon_Funs2)
  2758. {
  2759. UpdatePLCMonitor(1, plcNo, 0);
  2760. continue;
  2761. }
  2762. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2763. {
  2764. Stopwatch stopwatch1 = new Stopwatch();
  2765. Stopwatch stopwatch2 = new Stopwatch();
  2766. stopwatch1.Start();
  2767. stopwatch2.Start();
  2768. #region 一次性读取所有数据
  2769. // 一次性读取所有数据
  2770. result = FunsEip[plcNo]
  2771. .Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2772. if (result.Item1 != 0)
  2773. {
  2774. //richTextBox1.AppendText("\n" + strRet);
  2775. }
  2776. else
  2777. {
  2778. //richTextBox1.AppendText("\n" + "读取成功");
  2779. //设备状态
  2780. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  2781. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  2782. ? XiaomiDeviceState.Unknown
  2783. : (XiaomiDeviceState)xmDeviceStateInt;
  2784. s2PLCData["a2OEEPartNo"] =
  2785. stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  2786. s2PLCData["a2OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  2787. s2PLCData["a2OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  2788. }
  2789. #endregion 一次性读取所有数据
  2790. stopwatch2.Stop();
  2791. #region 进站
  2792. try
  2793. {
  2794. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2795. {
  2796. lock (lockObj)
  2797. {
  2798. if (!ProgressState)
  2799. {
  2800. ProgressState = true;
  2801. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData,
  2802. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  2803. out ProgressState));
  2804. }
  2805. }
  2806. }
  2807. }
  2808. catch (Exception ex)
  2809. {
  2810. ProgressState = false;
  2811. string str = ex.StackTrace;
  2812. AddMessage_Station(stationNameStr, LogType.Error,
  2813. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2814. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2815. }
  2816. #endregion 进站
  2817. #region 出站
  2818. try
  2819. {
  2820. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2821. {
  2822. lock (lockObj)
  2823. {
  2824. if (!ProgressState)
  2825. {
  2826. ProgressState = true;
  2827. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData,
  2828. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  2829. out ProgressState));
  2830. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  2831. }
  2832. }
  2833. }
  2834. }
  2835. catch (Exception ex)
  2836. {
  2837. ProgressState = false;
  2838. string str = ex.StackTrace;
  2839. AddMessage_Station(stationNameStr, LogType.Error,
  2840. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2841. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2842. }
  2843. #endregion 出站
  2844. #region 节拍接口
  2845. try
  2846. {
  2847. int a20EEType = (int)s2PLCData["a20EEType"];
  2848. int a20EETypeGOld = (int)s2PLCSignal_Old["a20EEType"];
  2849. //若设备紧急复原后节拍重置
  2850. if (a20EEType == 1)
  2851. {
  2852. a20EETypeGOld = 0;
  2853. }
  2854. if (a20EEType != a20EETypeGOld)
  2855. {
  2856. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  2857. if ((a20EETypeGOld == 1 && a20EEType != 2) || (a20EETypeGOld == 3 && a20EEType != 4) ||
  2858. (a20EETypeGOld == 5 && a20EEType != 6))
  2859. {
  2860. //写入PLC
  2861. stPLC_MesData.iotData.beatReturn = 2; //NG
  2862. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  2863. AddMessage(LogType.Info,
  2864. stationNameStr +
  2865. $"_节拍接口-- 设备本次上传节拍[{a20EEType}],未上传节拍[{a20EETypeGOld}]的结束信号,请检查;总用时" +
  2866. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  2867. "ms");
  2868. return;
  2869. }
  2870. else
  2871. {
  2872. Task.Run(() =>
  2873. S2节拍接口(plcNo, stationNameStr, tagBaseName,
  2874. stPLC_MesData.iotData)); // MreTasks[4].Set();
  2875. }
  2876. s2PLCSignal_Old["a20EEType"] = s2PLCData["a20EEType"];
  2877. }
  2878. }
  2879. catch (Exception ex)
  2880. {
  2881. string str = ex.StackTrace;
  2882. AddMessage_Station(stationNameStr, LogType.Error,
  2883. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  2884. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2885. }
  2886. #endregion
  2887. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2888. stopwatch1.Stop();
  2889. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2890. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2891. }
  2892. else
  2893. {
  2894. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2895. AddMessage_Station(stationNameStr, LogType.Info,
  2896. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2897. FunsEip[plcNo].Connect();
  2898. }
  2899. }
  2900. catch (Exception ex)
  2901. {
  2902. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2903. AddMessage_Station(stationNameStr, LogType.Error,
  2904. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2905. //Funs[plcNo].ReConnect();
  2906. }
  2907. Thread.Sleep(IntervalReadPLC);
  2908. }
  2909. }
  2910. /// <summary>
  2911. /// [S2] 上盖板上料装备
  2912. /// </summary>
  2913. /// <param name="plcNo">PLC编号</param>
  2914. /// <param name="stationNameStr">工站全称</param>
  2915. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  2916. string tagBarsetName, out bool ProgressState)
  2917. {
  2918. Stopwatch stopwatch1 = new Stopwatch();
  2919. Stopwatch stopwatch2 = new Stopwatch();
  2920. try
  2921. {
  2922. stopwatch1.Start();
  2923. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2924. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  2925. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2926. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  2927. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  2928. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2929. //根据载具码获取产品码
  2930. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2931. if (string.IsNullOrEmpty(strProductBarcode))
  2932. {
  2933. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2934. }
  2935. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  2936. //if (sn != strProductBarcode)
  2937. //{
  2938. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  2939. //}
  2940. sn = strProductBarcode;
  2941. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2942. // 产品SN(物料码)校验
  2943. List<TestItem> item = new List<TestItem>();
  2944. stopwatch2.Start();
  2945. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  2946. item, MachineId, StationId);
  2947. stopwatch2.Stop();
  2948. //指令执行结果 1:OK 110:失败
  2949. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2950. //进站结果写入PLC
  2951. CommandFromPLC resultToPlC = new CommandFromPLC();
  2952. resultToPlC.cmd = 0;
  2953. resultToPlC.cmdParam = 0; //指令参数
  2954. resultToPlC.cmdResult = mesResultFrmWeb;
  2955. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2956. }
  2957. catch (Exception ex)
  2958. {
  2959. string str = ex.StackTrace;
  2960. AddMessage(LogType.Error,
  2961. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  2962. str.Length - str.LastIndexOf("\\") - 1));
  2963. CommandFromPLC resultToPlC = new CommandFromPLC();
  2964. resultToPlC.cmd = 0;
  2965. resultToPlC.cmdParam = 0; //指令参数
  2966. resultToPlC.cmdResult = 110;
  2967. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2968. }
  2969. stopwatch1.Stop();
  2970. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2971. AddMessage(LogType.Info,
  2972. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  2973. stopwatch2.ElapsedMilliseconds + "ms");
  2974. ProgressState = false;
  2975. }
  2976. /// <summary>
  2977. /// [S2] 上盖板上料装备 - 出站接口
  2978. /// </summary>
  2979. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  2980. string stationCode, string stationName, out bool ProgressState)
  2981. {
  2982. Stopwatch stopwatch1 = new Stopwatch();
  2983. Stopwatch stopwatch2 = new Stopwatch();
  2984. try
  2985. {
  2986. stopwatch1.Start();
  2987. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2988. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2989. string processItem = stationName; // 测试项目
  2990. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2991. string supplierCode = ""; // 供应商代码
  2992. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2993. string batch_num = GlobalContext.BatchNumber; // 批次号
  2994. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2995. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2996. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2997. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  2998. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  2999. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  3000. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3001. bool pass = a1Result == 1;
  3002. //根据载具码获取产品码
  3003. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3004. if (string.IsNullOrEmpty(strProductBarcode))
  3005. {
  3006. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3007. }
  3008. sn = strProductBarcode;
  3009. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3010. List<TestItem> items = new List<TestItem>();
  3011. items.Add(new TestItem()
  3012. {
  3013. Parameter_name = "载具码",
  3014. Parameter_value = CarrierBarcode,
  3015. Parameter_unit = ""
  3016. });
  3017. items.Add(new TestItem()
  3018. {
  3019. Parameter_name = "产品码",
  3020. Parameter_value = sn,
  3021. Parameter_unit = ""
  3022. });
  3023. items.Add(new TestItem()
  3024. {
  3025. Parameter_name = "部件码",
  3026. Parameter_value = PartBarcode,
  3027. Parameter_unit = ""
  3028. });
  3029. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3030. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3031. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode, paramJson);
  3032. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3033. stopwatch2.Start();
  3034. //进站结果写入PLC
  3035. CommandFromPLC resultToPlC = new CommandFromPLC();
  3036. resultToPlC.cmd = 0;
  3037. resultToPlC.cmdParam = 0; //指令参数
  3038. resultToPlC.cmdResult = mesResultFrmWeb;
  3039. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3040. stopwatch2.Stop();
  3041. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3042. //保存PLC返回MES数据到本地
  3043. ResponseMessage message = new ResponseMessage();
  3044. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  3045. stPLC_MesData.mesData.nRemainCount);
  3046. if (message.result == false)
  3047. {
  3048. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3049. }
  3050. if (!string.IsNullOrEmpty(PartBarcode))
  3051. {
  3052. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  3053. if (message.result == false)
  3054. {
  3055. AddMessage(LogType.Error, message.text);
  3056. }
  3057. }
  3058. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3059. }
  3060. catch (Exception ex)
  3061. {
  3062. stopwatch2.Start();
  3063. CommandFromPLC resultToPlC = new CommandFromPLC();
  3064. resultToPlC.cmd = 0;
  3065. resultToPlC.cmdParam = 0; //指令参数
  3066. resultToPlC.cmdResult = 110;
  3067. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3068. stopwatch2.Stop();
  3069. string str = ex.StackTrace;
  3070. AddMessage(LogType.Error,
  3071. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3072. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3073. }
  3074. stopwatch1.Stop();
  3075. AddMessage(LogType.Info,
  3076. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3077. stopwatch2.ElapsedMilliseconds + "ms");
  3078. ProgressState = false;
  3079. }
  3080. #endregion
  3081. #region S3
  3082. /// <summary>
  3083. /// [S3] 点散热胶装备
  3084. /// </summary>
  3085. /// <param name="plcNo">PLC编号</param>
  3086. private void ReadStation_S3(int plcNo)
  3087. {
  3088. string stationCode = "[OP30]";
  3089. string stationName = "点散热胶装备";
  3090. string stationNameStr = stationCode + stationName;
  3091. string tagBaseName = "g_OP30_MES"; //标签变量名称
  3092. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3093. string tagAgvCommName = "agvCommFrmPC";
  3094. string tagBarsetName = "BarcodeSet";
  3095. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  3096. s3PLCSignal_Old.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
  3097. s3PLCSignal_Old.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
  3098. // PLC数据字典 赋值
  3099. s3PLCData.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
  3100. s3PLCData.Add("a3OEEPartNo_left", ""); // 物料码(物料码还未绑定载具SN时必填)
  3101. s3PLCData.Add("a3OEEVehicleCode_left", ""); // 载具SN
  3102. s3PLCData.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
  3103. s3PLCData.Add("a3OEEPartNo_right", ""); // 物料码(物料码还未绑定载具SN时必填)
  3104. s3PLCData.Add("a3OEEVehicleCode_right", ""); // 载具SN
  3105. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  3106. (int, string) result;
  3107. while (true)
  3108. {
  3109. try
  3110. {
  3111. if (!GlobalContext._IsCon_Funs2)
  3112. {
  3113. UpdatePLCMonitor(1, plcNo, 0);
  3114. continue;
  3115. }
  3116. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3117. {
  3118. Stopwatch stopwatch1 = new Stopwatch();
  3119. Stopwatch stopwatch2 = new Stopwatch();
  3120. stopwatch1.Start();
  3121. stopwatch2.Start();
  3122. #region 一次性读取所有数据
  3123. // 一次性读取所有数据
  3124. result = FunsEip[plcNo]
  3125. .Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3126. if (result.Item1 != 0)
  3127. {
  3128. //richTextBox1.AppendText("\n" + strRet);
  3129. }
  3130. else
  3131. {
  3132. //richTextBox1.AppendText("\n" + "读取成功");
  3133. int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  3134. int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  3135. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  3136. ? XiaomiDeviceState.Unknown
  3137. : (XiaomiDeviceState)xmDeviceStateInt_L;
  3138. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  3139. ? XiaomiDeviceState.Unknown
  3140. : (XiaomiDeviceState)xmDeviceStateInt_R;
  3141. s1PLCData["a1OEEPartNo"] =stPLC_MesData.Left.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  3142. s1PLCData["a1OEEVehicleCode"] = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode; // 载具SN
  3143. s1PLCData["a1OEEType"] = stPLC_MesData.Left.iotData.BeatAction; // 节拍
  3144. s1PLCData["a1OEEVehicleCode_right"] = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode; // 载具SN
  3145. s1PLCData["a1OEEType_right"] = stPLC_MesData.Right.iotData.BeatAction; // 节拍
  3146. }
  3147. #endregion 一次性读取所有数据
  3148. stopwatch2.Stop();
  3149. #region 左边进站
  3150. try
  3151. {
  3152. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3153. {
  3154. lock (lockObj)
  3155. {
  3156. if (!ProgressState)
  3157. {
  3158. ProgressState = true;
  3159. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left,
  3160. tagBaseName + ".Left." + tagMesCommName,
  3161. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  3162. }
  3163. }
  3164. }
  3165. }
  3166. catch (Exception ex)
  3167. {
  3168. ProgressState = false;
  3169. string str = ex.StackTrace;
  3170. AddMessage_Station(stationNameStr, LogType.Error,
  3171. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3172. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3173. }
  3174. #endregion 左边进站
  3175. #region 左边出站
  3176. try
  3177. {
  3178. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3179. {
  3180. lock (lockObj)
  3181. {
  3182. if (!ProgressState)
  3183. {
  3184. ProgressState = true;
  3185. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left,
  3186. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  3187. out ProgressState));
  3188. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  3189. }
  3190. }
  3191. }
  3192. }
  3193. catch (Exception ex)
  3194. {
  3195. ProgressState = false;
  3196. string str = ex.StackTrace;
  3197. AddMessage_Station(stationNameStr, LogType.Error,
  3198. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3199. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3200. }
  3201. #endregion 左边出站
  3202. #region 右边进站
  3203. try
  3204. {
  3205. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3206. {
  3207. lock (lockObj)
  3208. {
  3209. if (!ProgressState)
  3210. {
  3211. ProgressState = true;
  3212. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right,
  3213. tagBaseName + ".Right." + tagMesCommName,
  3214. tagBaseName + ".Right." + tagBarsetName, "Right", out ProgressState));
  3215. }
  3216. }
  3217. }
  3218. }
  3219. catch (Exception ex)
  3220. {
  3221. ProgressState = false;
  3222. string str = ex.StackTrace;
  3223. AddMessage_Station(stationNameStr, LogType.Error,
  3224. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3225. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3226. }
  3227. #endregion 右边进站
  3228. #region 右边出站
  3229. try
  3230. {
  3231. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3232. {
  3233. lock (lockObj)
  3234. {
  3235. if (!ProgressState)
  3236. {
  3237. ProgressState = true;
  3238. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right,
  3239. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  3240. out ProgressState));
  3241. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  3242. }
  3243. }
  3244. }
  3245. }
  3246. catch (Exception ex)
  3247. {
  3248. string str = ex.StackTrace;
  3249. AddMessage_Station(stationNameStr, LogType.Error,
  3250. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3251. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3252. }
  3253. #endregion 右边出站
  3254. #region 节拍接口
  3255. try
  3256. {
  3257. #region 左工位 节拍
  3258. int a30EEType_left = (int)s3PLCData["a30EEType_left"];
  3259. int a30EETypeGOld_left = (int)s3PLCSignal_Old["a30EEType_left"];
  3260. //若设备紧急复原后节拍重置
  3261. if (a30EEType_left == 1)
  3262. {
  3263. a30EETypeGOld_left = 0;
  3264. }
  3265. if (a30EEType_left != a30EETypeGOld_left)
  3266. {
  3267. stationNameStr = stationNameStr + "_Left";
  3268. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  3269. if ((a30EETypeGOld_left == 1 && a30EEType_left != 2) || (a30EETypeGOld_left == 3 && a30EEType_left != 4) ||
  3270. (a30EETypeGOld_left == 5 && a30EEType_left != 6))
  3271. {
  3272. //写入PLC
  3273. stPLC_MesData.Left.iotData.beatReturn = 2; //NG
  3274. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName, 1, stPLC_MesData.Left.iotData);
  3275. AddMessage(LogType.Info,
  3276. stationNameStr +
  3277. $"_节拍接口-- 设备本次上传节拍[{a30EEType_left}],未上传节拍[{a30EETypeGOld_left}]的结束信号,请检查;总用时" +
  3278. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  3279. "ms");
  3280. return;
  3281. }
  3282. else
  3283. {
  3284. Task.Run(() =>
  3285. S3节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName,
  3286. stPLC_MesData.Left.iotData)); // MreTasks[4].Set();
  3287. }
  3288. s3PLCSignal_Old["a30EEType_left"] = s3PLCData["a30EEType_left"];
  3289. }
  3290. #endregion 左工位 节拍
  3291. #region 右工位 节拍
  3292. int a30EEType_right = (int)s3PLCData["a30EEType_right"];
  3293. int a30EETypeGOld_right = (int)s3PLCSignal_Old["a30EEType_right"];
  3294. //若设备紧急复原后节拍重置
  3295. if (a30EEType_right == 1)
  3296. {
  3297. a30EETypeGOld_right = 0;
  3298. }
  3299. if (a30EEType_right != a30EETypeGOld_right)
  3300. {
  3301. stationNameStr = stationNameStr + "_Right";
  3302. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  3303. if ((a30EETypeGOld_right == 1 && a30EEType_right != 2) || (a30EETypeGOld_right == 3 && a30EEType_right != 4) ||
  3304. (a30EETypeGOld_right == 5 && a30EEType_right != 6))
  3305. {
  3306. //写入PLC
  3307. stPLC_MesData.Right.iotData.beatReturn = 2; //NG
  3308. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName, 1, stPLC_MesData.Left.iotData);
  3309. AddMessage(LogType.Info,
  3310. stationNameStr +
  3311. $"_节拍接口-- 设备本次上传节拍[{a30EEType_right}],未上传节拍[{a30EETypeGOld_right}]的结束信号,请检查;总用时" +
  3312. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  3313. "ms");
  3314. return;
  3315. }
  3316. else
  3317. {
  3318. Task.Run(() =>
  3319. S3节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName,
  3320. stPLC_MesData.Left.iotData)); // MreTasks[4].Set();
  3321. }
  3322. s3PLCSignal_Old["a30EEType_right"] = s3PLCData["a30EEType_right"];
  3323. }
  3324. #endregion 右工位 节拍
  3325. }
  3326. catch (Exception ex)
  3327. {
  3328. string str = ex.StackTrace;
  3329. AddMessage_Station(stationNameStr, LogType.Error,
  3330. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3331. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3332. }
  3333. #endregion
  3334. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3335. stopwatch1.Stop();
  3336. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  3337. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3338. }
  3339. else
  3340. {
  3341. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3342. AddMessage_Station(stationNameStr, LogType.Info,
  3343. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3344. FunsEip[plcNo].Connect();
  3345. }
  3346. }
  3347. catch (Exception ex)
  3348. {
  3349. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3350. AddMessage_Station(stationNameStr, LogType.Error,
  3351. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3352. //Funs[plcNo].ReConnect();
  3353. }
  3354. Thread.Sleep(IntervalReadPLC);
  3355. }
  3356. }
  3357. /// <summary>
  3358. /// [S3] 点散热胶装备 - 进站
  3359. /// </summary>
  3360. /// <param name="plcNo">PLC编号</param>
  3361. /// <param name="stationNameStr">工站全称</param>
  3362. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  3363. string tagBarsetName, string direction, out bool ProgressState)
  3364. {
  3365. Stopwatch stopwatch1 = new Stopwatch();
  3366. Stopwatch stopwatch2 = new Stopwatch();
  3367. try
  3368. {
  3369. stopwatch1.Start();
  3370. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  3371. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3372. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  3373. string StationId = string.Empty;
  3374. if (direction == "Left")
  3375. {
  3376. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  3377. }
  3378. if (direction == "Right")
  3379. {
  3380. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  3381. }
  3382. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3383. //载具码验证产品码
  3384. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3385. if (string.IsNullOrEmpty(strProductBarcode))
  3386. {
  3387. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3388. }
  3389. sn = strProductBarcode;
  3390. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  3391. // 产品SN(物料码)校验
  3392. List<TestItem> item = new List<TestItem>();
  3393. stopwatch2.Start();
  3394. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3395. item, MachineId, StationId);
  3396. stopwatch2.Stop();
  3397. //指令执行结果 1:OK 110:失败
  3398. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3399. //进站结果写入PLC
  3400. CommandFromPLC resultToPlC = new CommandFromPLC();
  3401. resultToPlC.cmd = 0;
  3402. resultToPlC.cmdParam = 0; //指令参数
  3403. resultToPlC.cmdResult = mesResultFrmWeb;
  3404. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3405. }
  3406. catch (Exception ex)
  3407. {
  3408. string str = ex.StackTrace;
  3409. AddMessage(LogType.Error,
  3410. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3411. str.Length - str.LastIndexOf("\\") - 1));
  3412. CommandFromPLC resultToPlC = new CommandFromPLC();
  3413. resultToPlC.cmd = 0;
  3414. resultToPlC.cmdParam = 0; //指令参数
  3415. resultToPlC.cmdResult = 110;
  3416. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3417. }
  3418. stopwatch1.Stop();
  3419. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3420. AddMessage(LogType.Info,
  3421. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3422. stopwatch2.ElapsedMilliseconds + "ms");
  3423. ProgressState = false;
  3424. }
  3425. /// <summary>
  3426. /// [S3] 点散热胶装备 - 出站
  3427. /// </summary>
  3428. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  3429. string stationCode, string stationName, string direction, out bool ProgressState)
  3430. {
  3431. Stopwatch stopwatch1 = new Stopwatch();
  3432. Stopwatch stopwatch2 = new Stopwatch();
  3433. try
  3434. {
  3435. stopwatch1.Start();
  3436. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  3437. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3438. string processItem = stationName; // 测试项目
  3439. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3440. string supplierCode = ""; // 供应商代码
  3441. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3442. string batch_num = GlobalContext.BatchNumber; // 批次号
  3443. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3444. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3445. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3446. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  3447. string StationId = string.Empty;
  3448. if (direction == "Left")
  3449. {
  3450. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  3451. }
  3452. if (direction == "Right")
  3453. {
  3454. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  3455. }
  3456. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3457. bool pass = a1Result == 1;
  3458. //根据载具码获取产品码
  3459. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3460. if (string.IsNullOrEmpty(strProductBarcode))
  3461. {
  3462. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3463. }
  3464. sn = strProductBarcode;
  3465. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3466. List<TestItem> items = new List<TestItem>();
  3467. items.Add(new TestItem()
  3468. {
  3469. Parameter_name = "载具码",
  3470. Parameter_value = CarrierBarcode,
  3471. Parameter_unit = ""
  3472. });
  3473. items.Add(new TestItem()
  3474. {
  3475. Parameter_name = "产品码",
  3476. Parameter_value = sn,
  3477. Parameter_unit = ""
  3478. });
  3479. int result1 = 1;
  3480. //if (direction == "Right")
  3481. //{
  3482. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3483. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3484. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson, direction);
  3485. //}
  3486. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3487. stopwatch2.Start();
  3488. //进站结果写入PLC
  3489. CommandFromPLC resultToPlC = new CommandFromPLC();
  3490. resultToPlC.cmd = 0;
  3491. resultToPlC.cmdParam = 0; //指令参数
  3492. resultToPlC.cmdResult = mesResultFrmWeb;
  3493. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3494. stopwatch2.Stop();
  3495. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  3496. //保存PLC返回MES数据到本地
  3497. ResponseMessage message = new ResponseMessage();
  3498. if (direction == "Left")
  3499. {
  3500. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  3501. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  3502. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  3503. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  3504. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  3505. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  3506. if (message.result == false)
  3507. {
  3508. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3509. }
  3510. }
  3511. if (direction == "Right")
  3512. {
  3513. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  3514. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  3515. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  3516. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  3517. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  3518. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  3519. if (message.result == false)
  3520. {
  3521. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3522. }
  3523. }
  3524. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3525. }
  3526. catch (Exception ex)
  3527. {
  3528. stopwatch2.Start();
  3529. CommandFromPLC resultToPlC = new CommandFromPLC();
  3530. resultToPlC.cmd = 0;
  3531. resultToPlC.cmdParam = 0; //指令参数
  3532. resultToPlC.cmdResult = 110;
  3533. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3534. stopwatch2.Stop();
  3535. string str = ex.StackTrace;
  3536. AddMessage(LogType.Error,
  3537. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3538. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3539. }
  3540. stopwatch1.Stop();
  3541. AddMessage(LogType.Info,
  3542. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3543. stopwatch2.ElapsedMilliseconds + "ms");
  3544. ProgressState = false;
  3545. }
  3546. #endregion S3
  3547. #region S4
  3548. /// <summary>
  3549. /// [S4] 点胶检测设备
  3550. /// </summary>
  3551. /// <param name="plcNo">PLC编号</param>
  3552. private void ReadStation_S4(int plcNo)
  3553. {
  3554. string stationCode = "[OP40]";
  3555. string stationName = "胶线检测";
  3556. string stationNameStr = stationCode + stationName;
  3557. string tagBaseName = "g_OP40_MES"; //标签变量名称
  3558. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3559. string tagAgvCommName = "agvCommFrmPC";
  3560. string tagBarsetName = "BarcodeSet";
  3561. // 触发信号字典
  3562. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  3563. s4PLCSignal_Old.Add("a4OEEType", 0); // 节拍类型(plc写入)
  3564. // PLC数据字典 赋值
  3565. s4PLCData.Add("a4OEEType", 0); // 节拍类型(plc写入)
  3566. s4PLCData.Add("a4OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  3567. s4PLCData.Add("a4OEEVehicleCode", ""); // 载具SN
  3568. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  3569. (int, string) result;
  3570. while (true)
  3571. {
  3572. try
  3573. {
  3574. if (!GlobalContext._IsCon_Funs1)
  3575. {
  3576. UpdatePLCMonitor(1, plcNo, 0);
  3577. continue;
  3578. }
  3579. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3580. {
  3581. Stopwatch stopwatch1 = new Stopwatch();
  3582. Stopwatch stopwatch2 = new Stopwatch();
  3583. stopwatch1.Start();
  3584. stopwatch2.Start();
  3585. #region 一次性读取所有数据
  3586. // 一次性读取所有数据
  3587. result = FunsEip[plcNo]
  3588. .Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3589. if (result.Item1 != 0)
  3590. {
  3591. //richTextBox1.AppendText("\n" + strRet);
  3592. }
  3593. else
  3594. {
  3595. //richTextBox1.AppendText("\n" + "读取成功");
  3596. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  3597. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  3598. ? XiaomiDeviceState.Unknown
  3599. : (XiaomiDeviceState)xmDeviceStateInt;
  3600. s4PLCData["a4OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  3601. s4PLCData["a4OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  3602. s4PLCData["a4OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  3603. }
  3604. #endregion 一次性读取所有数据
  3605. stopwatch2.Stop();
  3606. #region 进站
  3607. try
  3608. {
  3609. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3610. {
  3611. lock (lockObj)
  3612. {
  3613. if (!ProgressState)
  3614. {
  3615. ProgressState = true;
  3616. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData,
  3617. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  3618. out ProgressState));
  3619. }
  3620. }
  3621. }
  3622. }
  3623. catch (Exception ex)
  3624. {
  3625. ProgressState = false;
  3626. string str = ex.StackTrace;
  3627. AddMessage_Station(stationNameStr, LogType.Error,
  3628. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3629. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3630. }
  3631. #endregion 进站
  3632. #region 出站
  3633. try
  3634. {
  3635. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3636. {
  3637. lock (lockObj)
  3638. {
  3639. if (!ProgressState)
  3640. {
  3641. ProgressState = true;
  3642. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData,
  3643. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  3644. out ProgressState));
  3645. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3646. }
  3647. }
  3648. }
  3649. }
  3650. catch (Exception ex)
  3651. {
  3652. string str = ex.StackTrace;
  3653. AddMessage_Station(stationNameStr, LogType.Error,
  3654. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3655. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3656. }
  3657. #endregion 出站
  3658. #region 节拍接口
  3659. try
  3660. {
  3661. int a40EEType = (int)s4PLCData["a40EEType"];
  3662. int a40EETypeGOld = (int)s4PLCSignal_Old["a40EEType"];
  3663. //若设备紧急复原后节拍重置
  3664. if (a40EEType == 1)
  3665. {
  3666. a40EETypeGOld = 0;
  3667. }
  3668. if (a40EEType != a40EETypeGOld)
  3669. {
  3670. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  3671. if ((a40EETypeGOld == 1 && a40EEType != 2) || (a40EETypeGOld == 3 && a40EEType != 4) ||
  3672. (a40EETypeGOld == 5 && a40EEType != 6))
  3673. {
  3674. //写入PLC
  3675. stPLC_MesData.iotData.beatReturn = 2; //NG
  3676. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  3677. AddMessage(LogType.Info,
  3678. stationNameStr +
  3679. $"_节拍接口-- 设备本次上传节拍[{a40EEType}],未上传节拍[{a40EETypeGOld}]的结束信号,请检查;总用时" +
  3680. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  3681. "ms");
  3682. return;
  3683. }
  3684. else
  3685. {
  3686. Task.Run(() =>
  3687. S4节拍接口(plcNo, stationNameStr, tagBaseName,
  3688. stPLC_MesData.iotData)); // MreTasks[4].Set();
  3689. }
  3690. s4PLCSignal_Old["a40EEType"] = s4PLCData["a40EEType"];
  3691. }
  3692. }
  3693. catch (Exception ex)
  3694. {
  3695. string str = ex.StackTrace;
  3696. AddMessage_Station(stationNameStr, LogType.Error,
  3697. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3698. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3699. }
  3700. #endregion
  3701. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3702. stopwatch1.Stop();
  3703. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3704. }
  3705. else
  3706. {
  3707. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3708. AddMessage_Station(stationNameStr, LogType.Info,
  3709. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3710. FunsEip[plcNo].Connect(); // 重连
  3711. }
  3712. }
  3713. catch (Exception ex)
  3714. {
  3715. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3716. AddMessage_Station(stationNameStr, LogType.Error,
  3717. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3718. }
  3719. Thread.Sleep(IntervalReadPLC);
  3720. }
  3721. }
  3722. /// <summary>
  3723. /// [S4] 点胶检测设备 - 进站
  3724. /// </summary>
  3725. /// <param name="plcNo">PLC编号</param>
  3726. /// <param name="stationNameStr">工站全称</param>
  3727. /// <param name="stPLC_MesData"></param>
  3728. /// <param name="tagMesCommName"></param>
  3729. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  3730. string tagBarsetName, out bool ProgressState)
  3731. {
  3732. Stopwatch stopwatch1 = new Stopwatch();
  3733. Stopwatch stopwatch2 = new Stopwatch();
  3734. try
  3735. {
  3736. stopwatch1.Start();
  3737. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3738. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3739. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  3740. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  3741. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3742. //载具码验证产品码
  3743. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3744. if (string.IsNullOrEmpty(strProductBarcode))
  3745. {
  3746. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3747. }
  3748. sn = strProductBarcode;
  3749. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3750. // 产品SN(物料码)校验
  3751. List<TestItem> item = new List<TestItem>();
  3752. stopwatch2.Start();
  3753. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3754. item, MachineId, StationId);
  3755. stopwatch2.Stop();
  3756. //指令执行结果 1:OK 110:失败
  3757. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3758. //进站结果写入PLC
  3759. CommandFromPLC resultToPlC = new CommandFromPLC();
  3760. resultToPlC.cmd = 0;
  3761. resultToPlC.cmdParam = 0; //指令参数
  3762. resultToPlC.cmdResult = mesResultFrmWeb;
  3763. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3764. }
  3765. catch (Exception ex)
  3766. {
  3767. string str = ex.StackTrace;
  3768. AddMessage(LogType.Error,
  3769. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3770. str.Length - str.LastIndexOf("\\") - 1));
  3771. CommandFromPLC resultToPlC = new CommandFromPLC();
  3772. resultToPlC.cmd = 0;
  3773. resultToPlC.cmdParam = 0; //指令参数
  3774. resultToPlC.cmdResult = 110;
  3775. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3776. }
  3777. stopwatch1.Stop();
  3778. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3779. AddMessage(LogType.Info,
  3780. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3781. stopwatch2.ElapsedMilliseconds + "ms");
  3782. ProgressState = false;
  3783. }
  3784. /// <summary>
  3785. /// [S4] 点胶检测设备 - 出站接口
  3786. /// </summary>
  3787. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  3788. string stationCode, string stationName, out bool ProgressState)
  3789. {
  3790. Stopwatch stopwatch1 = new Stopwatch();
  3791. Stopwatch stopwatch2 = new Stopwatch();
  3792. try
  3793. {
  3794. stopwatch1.Start();
  3795. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3796. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3797. string processItem = stationName; // 测试项目
  3798. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3799. string supplierCode = ""; // 供应商代码
  3800. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3801. string batch_num = GlobalContext.BatchNumber; // 批次号
  3802. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3803. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3804. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3805. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  3806. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  3807. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3808. bool pass = a1Result == 1;
  3809. //根据载具码获取产品码
  3810. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3811. if (string.IsNullOrEmpty(strProductBarcode))
  3812. {
  3813. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3814. }
  3815. sn = strProductBarcode;
  3816. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3817. List<TestItem> items = new List<TestItem>();
  3818. items.Add(new TestItem()
  3819. {
  3820. Parameter_name = "载具码",
  3821. Parameter_value = CarrierBarcode,
  3822. Parameter_unit = ""
  3823. });
  3824. items.Add(new TestItem()
  3825. {
  3826. Parameter_name = "产品码",
  3827. Parameter_value = sn,
  3828. Parameter_unit = ""
  3829. });
  3830. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3831. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3832. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  3833. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3834. stopwatch2.Start();
  3835. //进站结果写入PLC
  3836. CommandFromPLC resultToPlC = new CommandFromPLC();
  3837. resultToPlC.cmd = 0;
  3838. resultToPlC.cmdParam = 0; //指令参数
  3839. resultToPlC.cmdResult = mesResultFrmWeb;
  3840. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3841. stopwatch2.Stop();
  3842. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3843. //保存PLC返回MES数据到本地
  3844. ResponseMessage message = new ResponseMessage();
  3845. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  3846. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  3847. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  3848. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  3849. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  3850. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  3851. if (message.result == false)
  3852. {
  3853. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3854. }
  3855. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3856. }
  3857. catch (Exception ex)
  3858. {
  3859. stopwatch2.Start();
  3860. CommandFromPLC resultToPlC = new CommandFromPLC();
  3861. resultToPlC.cmd = 0;
  3862. resultToPlC.cmdParam = 0; //指令参数
  3863. resultToPlC.cmdResult = 110;
  3864. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3865. stopwatch2.Stop();
  3866. string str = ex.StackTrace;
  3867. AddMessage(LogType.Error,
  3868. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3869. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3870. }
  3871. stopwatch1.Stop();
  3872. AddMessage(LogType.Info,
  3873. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3874. stopwatch2.ElapsedMilliseconds + "ms");
  3875. ProgressState = false;
  3876. }
  3877. private void S4节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  3878. {
  3879. Stopwatch stopwatch1 = new Stopwatch();
  3880. Stopwatch stopwatch2 = new Stopwatch();
  3881. string resultStr = string.Empty;
  3882. try
  3883. {
  3884. stopwatch1.Start();
  3885. string oEEType = ((int)s1PLCData["a4OEEType"]).ToString(); // 节拍类型(plc写入)
  3886. string a40EEPartNo = (string)s1PLCData["a40EEPartNo"]; // 物料码
  3887. a40EEPartNo = a40EEPartNo.Replace("\0", "");
  3888. string a50EEVehicleCode = (string)s1PLCData["a50EEVehicleCode"]; // 载具SN
  3889. a50EEVehicleCode = a50EEVehicleCode.Replace("\0", "");
  3890. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  3891. if (!actionBool)
  3892. {
  3893. stopwatch2.Start();
  3894. //写入PLC
  3895. iot_data.beatReturn = 2; //NG
  3896. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3897. stopwatch2.Stop();
  3898. AddMessage(LogType.Info,
  3899. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  3900. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3901. return;
  3902. }
  3903. //作业开始后要有物料和载具信息
  3904. if (string.IsNullOrEmpty(a40EEPartNo) && string.IsNullOrEmpty(a50EEVehicleCode) &&
  3905. Convert.ToInt32(oEEType) > 2)
  3906. {
  3907. stopwatch2.Start();
  3908. //写入PLC
  3909. iot_data.beatReturn = 2; //NG
  3910. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3911. stopwatch2.Stop();
  3912. AddMessage_Station(stationNameStr, LogType.Info,
  3913. stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  3914. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3915. return;
  3916. }
  3917. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a40EEPartNo))
  3918. {
  3919. stopwatch2.Start();
  3920. //写入PLC
  3921. iot_data.beatReturn = 2; //NG
  3922. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3923. stopwatch2.Stop();
  3924. AddMessage_Station(stationNameStr, LogType.Info,
  3925. stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  3926. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3927. return;
  3928. }
  3929. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a50EEVehicleCode))
  3930. {
  3931. stopwatch2.Start();
  3932. //写入PLC
  3933. iot_data.beatReturn = 2; //NG
  3934. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3935. stopwatch2.Stop();
  3936. AddMessage_Station(stationNameStr, LogType.Info,
  3937. stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  3938. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3939. return;
  3940. }
  3941. short _result = 0;
  3942. // 上传OEE
  3943. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a40EEPartNo, a50EEVehicleCode);
  3944. _result = result.Item1;
  3945. resultStr = result.Item2;
  3946. if (_result == 1)
  3947. {
  3948. stopwatch2.Start();
  3949. //写入PLC
  3950. iot_data.beatReturn = 1; //OK
  3951. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3952. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  3953. stopwatch2.Stop();
  3954. }
  3955. else
  3956. {
  3957. stopwatch2.Start();
  3958. //写入PLC
  3959. iot_data.beatReturn = 2; //NG
  3960. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3961. stopwatch2.Stop();
  3962. AddMessage_Station(stationNameStr, LogType.Error,
  3963. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  3964. }
  3965. }
  3966. catch (Exception ex)
  3967. {
  3968. string str = ex.StackTrace;
  3969. AddMessage_Station(stationNameStr, LogType.Error,
  3970. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  3971. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3972. // MES_Flag
  3973. stopwatch2.Start();
  3974. //写入PLC
  3975. iot_data.beatReturn = 2; //NG
  3976. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3977. stopwatch2.Stop();
  3978. }
  3979. stopwatch1.Stop();
  3980. AddMessage(LogType.Info,
  3981. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3982. stopwatch2.ElapsedMilliseconds + "ms");
  3983. }
  3984. #endregion
  3985. #region S5
  3986. /// <summary>
  3987. /// [S5] 点胶检测设备
  3988. /// </summary>
  3989. /// <param name="plcNo">PLC编号</param>
  3990. private void ReadStation_S5(int plcNo)
  3991. {
  3992. string stationCode = "[OP50]";
  3993. string stationName = "ADD板上料组装装备";
  3994. string stationNameStr = stationCode + stationName;
  3995. string tagBaseName = "g_OP50_MES"; //标签变量名称
  3996. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3997. string tagAgvCommName = "agvCommFrmPC";
  3998. string tagBarsetName = "BarcodeSet";
  3999. // 触发信号字典
  4000. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4001. s5PLCSignal_Old.Add("a5OEEType", 0); // 节拍类型(plc写入)
  4002. // PLC数据字典 赋值
  4003. s5PLCData.Add("a5OEEType", 0); // 节拍类型(plc写入)
  4004. s5PLCData.Add("a5OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4005. s5PLCData.Add("a5OEEVehicleCode", ""); // 载具SN
  4006. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  4007. (int, string) result;
  4008. while (true)
  4009. {
  4010. try
  4011. {
  4012. if (!GlobalContext._IsCon_Funs1)
  4013. {
  4014. UpdatePLCMonitor(1, plcNo, 0);
  4015. continue;
  4016. }
  4017. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4018. {
  4019. Stopwatch stopwatch1 = new Stopwatch();
  4020. Stopwatch stopwatch2 = new Stopwatch();
  4021. stopwatch1.Start();
  4022. stopwatch2.Start();
  4023. #region 一次性读取所有数据
  4024. // 一次性读取所有数据
  4025. result = FunsEip[plcNo]
  4026. .Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4027. if (result.Item1 != 0)
  4028. {
  4029. //richTextBox1.AppendText("\n" + strRet);
  4030. }
  4031. else
  4032. {
  4033. //richTextBox1.AppendText("\n" + "读取成功");
  4034. //richTextBox1.AppendText("\n" + "读取成功");
  4035. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  4036. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  4037. ? XiaomiDeviceState.Unknown
  4038. : (XiaomiDeviceState)xmDeviceStateInt;
  4039. s5PLCData["a5OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  4040. s5PLCData["a5OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  4041. s5PLCData["a5OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  4042. }
  4043. #endregion 一次性读取所有数据
  4044. stopwatch2.Stop();
  4045. #region 进站
  4046. try
  4047. {
  4048. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4049. {
  4050. lock (lockObj)
  4051. {
  4052. if (!ProgressState)
  4053. {
  4054. ProgressState = true;
  4055. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData,
  4056. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  4057. out ProgressState));
  4058. }
  4059. }
  4060. }
  4061. }
  4062. catch (Exception ex)
  4063. {
  4064. ProgressState = false;
  4065. string str = ex.StackTrace;
  4066. AddMessage_Station(stationNameStr, LogType.Error,
  4067. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4068. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4069. }
  4070. #endregion 进站
  4071. #region 出站
  4072. try
  4073. {
  4074. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4075. {
  4076. lock (lockObj)
  4077. {
  4078. if (!ProgressState)
  4079. {
  4080. ProgressState = true;
  4081. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData,
  4082. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4083. out ProgressState));
  4084. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4085. }
  4086. }
  4087. }
  4088. }
  4089. catch (Exception ex)
  4090. {
  4091. ProgressState = false;
  4092. string str = ex.StackTrace;
  4093. AddMessage_Station(stationNameStr, LogType.Error,
  4094. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4095. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4096. }
  4097. #endregion 出站
  4098. #region 节拍接口
  4099. try
  4100. {
  4101. int a50EEType = (int)s5PLCData["a50EEType"];
  4102. int a50EETypeGOld = (int)s5PLCSignal_Old["a50EEType"];
  4103. //若设备紧急复原后节拍重置
  4104. if (a50EEType == 1)
  4105. {
  4106. a50EETypeGOld = 0;
  4107. }
  4108. if (a50EEType != a50EETypeGOld)
  4109. {
  4110. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  4111. if ((a50EETypeGOld == 1 && a50EEType != 2) || (a50EETypeGOld == 3 && a50EEType != 4) ||
  4112. (a50EETypeGOld == 5 && a50EEType != 6))
  4113. {
  4114. //写入PLC
  4115. stPLC_MesData.iotData.beatReturn = 2; //NG
  4116. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  4117. AddMessage(LogType.Info,
  4118. stationNameStr +
  4119. $"_节拍接口-- 设备本次上传节拍[{a50EEType}],未上传节拍[{a50EETypeGOld}]的结束信号,请检查;总用时" +
  4120. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  4121. "ms");
  4122. return;
  4123. }
  4124. else
  4125. {
  4126. Task.Run(() =>
  4127. S5节拍接口(plcNo, stationNameStr, tagBaseName,
  4128. stPLC_MesData.iotData)); // MreTasks[4].Set();
  4129. }
  4130. s5PLCSignal_Old["a50EEType"] = s5PLCData["a50EEType"];
  4131. }
  4132. }
  4133. catch (Exception ex)
  4134. {
  4135. string str = ex.StackTrace;
  4136. AddMessage_Station(stationNameStr, LogType.Error,
  4137. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4138. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4139. }
  4140. #endregion
  4141. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4142. stopwatch1.Stop();
  4143. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4144. }
  4145. else
  4146. {
  4147. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4148. AddMessage_Station(stationNameStr, LogType.Info,
  4149. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4150. FunsEip[plcNo].Connect(); // 重连
  4151. }
  4152. }
  4153. catch (Exception ex)
  4154. {
  4155. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4156. AddMessage_Station(stationNameStr, LogType.Error,
  4157. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4158. }
  4159. Thread.Sleep(IntervalReadPLC);
  4160. }
  4161. }
  4162. /// <summary>
  4163. /// [S5] 点胶检测设备 - 进站
  4164. /// </summary>
  4165. /// <param name="plcNo">PLC编号</param>
  4166. /// <param name="stationNameStr">工站全称</param>
  4167. /// <param name="stPLC_MesData"></param>
  4168. /// <param name="tagMesCommName"></param>
  4169. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  4170. string tagBarsetName, out bool ProgressState)
  4171. {
  4172. Stopwatch stopwatch1 = new Stopwatch();
  4173. Stopwatch stopwatch2 = new Stopwatch();
  4174. try
  4175. {
  4176. stopwatch1.Start();
  4177. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4178. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4179. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  4180. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  4181. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  4182. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码
  4183. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  4184. //绑定载具和产品
  4185. ResponseMessage message = new ResponseMessage();
  4186. message = SQLHelper.PCBCarrierBind(strCarrierBarcode, pcbBarcode);
  4187. if (message.result == false)
  4188. {
  4189. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  4190. }
  4191. //载具码验证产品码 //载具码验证产品码
  4192. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4193. if (string.IsNullOrEmpty(strProductBarcode))
  4194. {
  4195. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4196. }
  4197. sn = strProductBarcode;
  4198. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn};PCB码:{pcbBarcode}");
  4199. // 产品SN(物料码)校验
  4200. List<TestItem> item = new List<TestItem>();
  4201. stopwatch2.Start();
  4202. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  4203. item, MachineId, StationId);
  4204. stopwatch2.Stop();
  4205. //指令执行结果 1:OK 110:失败
  4206. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4207. //进站结果写入PLC
  4208. CommandFromPLC resultToPlC = new CommandFromPLC();
  4209. resultToPlC.cmd = 0;
  4210. resultToPlC.cmdParam = 0; //指令参数
  4211. resultToPlC.cmdResult = mesResultFrmWeb;
  4212. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4213. }
  4214. catch (Exception ex)
  4215. {
  4216. string str = ex.StackTrace;
  4217. AddMessage(LogType.Error,
  4218. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4219. str.Length - str.LastIndexOf("\\") - 1));
  4220. CommandFromPLC resultToPlC = new CommandFromPLC();
  4221. resultToPlC.cmd = 0;
  4222. resultToPlC.cmdParam = 0; //指令参数
  4223. resultToPlC.cmdResult = 110;
  4224. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4225. }
  4226. stopwatch1.Stop();
  4227. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4228. AddMessage(LogType.Info,
  4229. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4230. stopwatch2.ElapsedMilliseconds + "ms");
  4231. ProgressState = false;
  4232. }
  4233. /// <summary>
  4234. /// [S5] 点胶检测设备 - 出站接口
  4235. /// </summary>
  4236. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  4237. string stationCode, string stationName, out bool ProgressState)
  4238. {
  4239. Stopwatch stopwatch1 = new Stopwatch();
  4240. Stopwatch stopwatch2 = new Stopwatch();
  4241. try
  4242. {
  4243. stopwatch1.Start();
  4244. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4245. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4246. string processItem = stationName; // 测试项目
  4247. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4248. string supplierCode = ""; // 供应商代码
  4249. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4250. string batch_num = GlobalContext.BatchNumber; // 批次号
  4251. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4252. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4253. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
  4254. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4255. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  4256. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  4257. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4258. bool pass = a1Result == 1;
  4259. //根据载具码获取产品码
  4260. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4261. if (string.IsNullOrEmpty(strProductBarcode))
  4262. {
  4263. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4264. }
  4265. sn = strProductBarcode;
  4266. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4267. List<TestItem> items = new List<TestItem>();
  4268. items.Add(new TestItem()
  4269. {
  4270. Parameter_name = "载具码",
  4271. Parameter_value = CarrierBarcode,
  4272. Parameter_unit = ""
  4273. });
  4274. items.Add(new TestItem()
  4275. {
  4276. Parameter_name = "产品码",
  4277. Parameter_value = sn,
  4278. Parameter_unit = ""
  4279. });
  4280. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4281. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4282. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode, paramJson);
  4283. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4284. stopwatch2.Start();
  4285. //进站结果写入PLC
  4286. CommandFromPLC resultToPlC = new CommandFromPLC();
  4287. resultToPlC.cmd = 0;
  4288. resultToPlC.cmdParam = 0; //指令参数
  4289. resultToPlC.cmdResult = mesResultFrmWeb;
  4290. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4291. stopwatch2.Stop();
  4292. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4293. //保存PLC返回MES数据到本地
  4294. ResponseMessage message = new ResponseMessage();
  4295. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  4296. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB,
  4297. stPLC_MesData.mesData.nRemainCount, "");
  4298. if (message.result == false)
  4299. {
  4300. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4301. }
  4302. //保存部件码信息
  4303. if (!string.IsNullOrEmpty(PartBarcode))
  4304. {
  4305. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  4306. if (message.result == false)
  4307. {
  4308. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  4309. }
  4310. }
  4311. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4312. }
  4313. catch (Exception ex)
  4314. {
  4315. stopwatch2.Start();
  4316. CommandFromPLC resultToPlC = new CommandFromPLC();
  4317. resultToPlC.cmd = 0;
  4318. resultToPlC.cmdParam = 0; //指令参数
  4319. resultToPlC.cmdResult = 110;
  4320. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4321. stopwatch2.Stop();
  4322. string str = ex.StackTrace;
  4323. AddMessage(LogType.Error,
  4324. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4325. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4326. }
  4327. stopwatch1.Stop();
  4328. AddMessage(LogType.Info,
  4329. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4330. stopwatch2.ElapsedMilliseconds + "ms");
  4331. ProgressState = false;
  4332. }
  4333. private void S5节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  4334. {
  4335. Stopwatch stopwatch1 = new Stopwatch();
  4336. Stopwatch stopwatch2 = new Stopwatch();
  4337. string resultStr = string.Empty;
  4338. try
  4339. {
  4340. stopwatch1.Start();
  4341. string oEEType = ((int)s1PLCData["a5OEEType"]).ToString(); // 节拍类型(plc写入)
  4342. string a50EEPartNo = (string)s1PLCData["a50EEPartNo"]; // 物料码
  4343. a50EEPartNo = a50EEPartNo.Replace("\0", "");
  4344. string a40EEVehicleCode = (string)s1PLCData["a40EEVehicleCode"]; // 载具SN
  4345. a40EEVehicleCode = a40EEVehicleCode.Replace("\0", "");
  4346. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4347. if (!actionBool)
  4348. {
  4349. stopwatch2.Start();
  4350. //写入PLC
  4351. iot_data.beatReturn = 2; //NG
  4352. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4353. stopwatch2.Stop();
  4354. AddMessage(LogType.Info,
  4355. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  4356. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4357. return;
  4358. }
  4359. //作业开始后要有物料和载具信息
  4360. if (string.IsNullOrEmpty(a50EEPartNo) && string.IsNullOrEmpty(a40EEVehicleCode) &&
  4361. Convert.ToInt32(oEEType) > 2)
  4362. {
  4363. stopwatch2.Start();
  4364. //写入PLC
  4365. iot_data.beatReturn = 2; //NG
  4366. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4367. stopwatch2.Stop();
  4368. AddMessage_Station(stationNameStr, LogType.Info,
  4369. stationNameStr + $"_[{a40EEVehicleCode}][{a50EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  4370. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4371. return;
  4372. }
  4373. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a50EEPartNo))
  4374. {
  4375. stopwatch2.Start();
  4376. //写入PLC
  4377. iot_data.beatReturn = 2; //NG
  4378. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4379. stopwatch2.Stop();
  4380. AddMessage_Station(stationNameStr, LogType.Info,
  4381. stationNameStr + $"_[{a40EEVehicleCode}][{a50EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  4382. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4383. return;
  4384. }
  4385. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a40EEVehicleCode))
  4386. {
  4387. stopwatch2.Start();
  4388. //写入PLC
  4389. iot_data.beatReturn = 2; //NG
  4390. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4391. stopwatch2.Stop();
  4392. AddMessage_Station(stationNameStr, LogType.Info,
  4393. stationNameStr + $"_[{a40EEVehicleCode}][{a50EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  4394. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4395. return;
  4396. }
  4397. short _result = 0;
  4398. // 上传OEE
  4399. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a50EEPartNo, a40EEVehicleCode);
  4400. _result = result.Item1;
  4401. resultStr = result.Item2;
  4402. if (_result == 1)
  4403. {
  4404. stopwatch2.Start();
  4405. //写入PLC
  4406. iot_data.beatReturn = 1; //OK
  4407. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4408. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  4409. stopwatch2.Stop();
  4410. }
  4411. else
  4412. {
  4413. stopwatch2.Start();
  4414. //写入PLC
  4415. iot_data.beatReturn = 2; //NG
  4416. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4417. stopwatch2.Stop();
  4418. AddMessage_Station(stationNameStr, LogType.Error,
  4419. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  4420. }
  4421. }
  4422. catch (Exception ex)
  4423. {
  4424. string str = ex.StackTrace;
  4425. AddMessage_Station(stationNameStr, LogType.Error,
  4426. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  4427. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4428. // MES_Flag
  4429. stopwatch2.Start();
  4430. //写入PLC
  4431. iot_data.beatReturn = 2; //NG
  4432. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4433. stopwatch2.Stop();
  4434. }
  4435. stopwatch1.Stop();
  4436. AddMessage(LogType.Info,
  4437. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4438. stopwatch2.ElapsedMilliseconds + "ms");
  4439. }
  4440. #endregion
  4441. #region S6
  4442. private Dictionary<string, object> s6PLCData = new Dictionary<string, object>();
  4443. private Dictionary<string, object> s6PLCSignal_Old = new Dictionary<string, object>();
  4444. /// <summary>
  4445. /// [S6] 顶盖装配设备
  4446. /// </summary>
  4447. /// <param name="plcNo">PLC编号</param>
  4448. private void ReadStation_S6(int plcNo)
  4449. {
  4450. string stationCode = "[OP60]";
  4451. string stationName = "组上盖板";
  4452. string stationNameStr = stationCode + stationName;
  4453. string tagBaseName = "g_OP60_MES"; //标签变量名称
  4454. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4455. string tagAgvCommName = "agvCommFrmPC";
  4456. string tagBarsetName = "BarcodeSet";
  4457. // 触发信号字典
  4458. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4459. s6PLCSignal_Old.Add("a6OEEType", 0); // 节拍类型(plc写入)
  4460. // PLC数据字典 赋值
  4461. s6PLCData.Add("a6OEEType", 0); // 节拍类型(plc写入)
  4462. s6PLCData.Add("a6OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4463. s6PLCData.Add("a6OEEVehicleCode", ""); // 载具SN
  4464. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  4465. (int, string) result;
  4466. while (true)
  4467. {
  4468. try
  4469. {
  4470. if (!GlobalContext._IsCon_Funs1)
  4471. {
  4472. UpdatePLCMonitor(1, plcNo, 0);
  4473. continue;
  4474. }
  4475. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4476. {
  4477. Stopwatch stopwatch1 = new Stopwatch();
  4478. Stopwatch stopwatch2 = new Stopwatch();
  4479. stopwatch1.Start();
  4480. stopwatch2.Start();
  4481. #region 一次性读取所有数据
  4482. // 一次性读取所有数据
  4483. result = FunsEip[plcNo]
  4484. .Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4485. if (result.Item1 != 0)
  4486. {
  4487. //richTextBox1.AppendText("\n" + strRet);
  4488. }
  4489. else
  4490. {
  4491. //richTextBox1.AppendText("\n" + "读取成功");
  4492. //richTextBox1.AppendText("\n" + "读取成功");
  4493. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  4494. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  4495. ? XiaomiDeviceState.Unknown
  4496. : (XiaomiDeviceState)xmDeviceStateInt;
  4497. s6PLCData["a6OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  4498. s6PLCData["a6OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  4499. s6PLCData["a6OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  4500. }
  4501. #endregion 一次性读取所有数据
  4502. stopwatch2.Stop();
  4503. #region 进站
  4504. try
  4505. {
  4506. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4507. {
  4508. lock (lockObj)
  4509. {
  4510. if (!ProgressState)
  4511. {
  4512. ProgressState = true;
  4513. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData,
  4514. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  4515. out ProgressState));
  4516. }
  4517. }
  4518. }
  4519. }
  4520. catch (Exception ex)
  4521. {
  4522. ProgressState = false;
  4523. string str = ex.StackTrace;
  4524. AddMessage_Station(stationNameStr, LogType.Error,
  4525. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4526. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4527. }
  4528. #endregion 进站
  4529. #region 出站
  4530. try
  4531. {
  4532. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4533. {
  4534. lock (lockObj)
  4535. {
  4536. if (!ProgressState)
  4537. {
  4538. ProgressState = true;
  4539. ;
  4540. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData,
  4541. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4542. out ProgressState));
  4543. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4544. }
  4545. }
  4546. }
  4547. }
  4548. catch (Exception ex)
  4549. {
  4550. ProgressState = false;
  4551. string str = ex.StackTrace;
  4552. AddMessage_Station(stationNameStr, LogType.Error,
  4553. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4554. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4555. }
  4556. #endregion 出站
  4557. #region 节拍接口
  4558. try
  4559. {
  4560. int a60EEType = (int)s6PLCData["a60EEType"];
  4561. int a60EETypeGOld = (int)s6PLCSignal_Old["a60EEType"];
  4562. //若设备紧急复原后节拍重置
  4563. if (a60EEType == 1)
  4564. {
  4565. a60EETypeGOld = 0;
  4566. }
  4567. if (a60EEType != a60EETypeGOld)
  4568. {
  4569. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  4570. if ((a60EETypeGOld == 1 && a60EEType != 2) || (a60EETypeGOld == 3 && a60EEType != 4) ||
  4571. (a60EETypeGOld == 5 && a60EEType != 6))
  4572. {
  4573. //写入PLC
  4574. stPLC_MesData.iotData.beatReturn = 2; //NG
  4575. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  4576. AddMessage(LogType.Info,
  4577. stationNameStr +
  4578. $"_节拍接口-- 设备本次上传节拍[{a60EEType}],未上传节拍[{a60EETypeGOld}]的结束信号,请检查;总用时" +
  4579. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  4580. "ms");
  4581. return;
  4582. }
  4583. else
  4584. {
  4585. Task.Run(() =>
  4586. S6节拍接口(plcNo, stationNameStr, tagBaseName,
  4587. stPLC_MesData.iotData)); // MreTasks[4].Set();
  4588. }
  4589. s6PLCSignal_Old["a60EEType"] = s6PLCData["a60EEType"];
  4590. }
  4591. }
  4592. catch (Exception ex)
  4593. {
  4594. string str = ex.StackTrace;
  4595. AddMessage_Station(stationNameStr, LogType.Error,
  4596. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4597. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4598. }
  4599. #endregion
  4600. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4601. stopwatch1.Stop();
  4602. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4603. }
  4604. else
  4605. {
  4606. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4607. AddMessage_Station(stationNameStr, LogType.Info,
  4608. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4609. FunsEip[plcNo].Connect(); // 重连
  4610. }
  4611. }
  4612. catch (Exception ex)
  4613. {
  4614. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4615. AddMessage_Station(stationNameStr, LogType.Error,
  4616. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4617. }
  4618. Thread.Sleep(IntervalReadPLC);
  4619. }
  4620. }
  4621. /// <summary>
  4622. /// [S6] 顶盖装配设备 - 进站
  4623. /// </summary>
  4624. /// <param name="plcNo">PLC编号</param>
  4625. /// <param name="stationNameStr">工站全称</param>
  4626. /// <param name="stPLC_MesData"></param>
  4627. /// <param name="tagMesCommName"></param>
  4628. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  4629. string tagBarsetName, out bool ProgressState)
  4630. {
  4631. Stopwatch stopwatch1 = new Stopwatch();
  4632. Stopwatch stopwatch2 = new Stopwatch();
  4633. try
  4634. {
  4635. stopwatch1.Start();
  4636. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4637. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4638. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  4639. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  4640. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4641. //strCarrierBarcode = "N801A-003";
  4642. //载具码验证产品码
  4643. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4644. if (string.IsNullOrEmpty(strProductBarcode))
  4645. {
  4646. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4647. }
  4648. sn = strProductBarcode;
  4649. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4650. if (OpenDailogFalg)
  4651. {
  4652. using (var dialog = new BandBarodeDialog())
  4653. {
  4654. dialog._CarrierBarcode = strCarrierBarcode;
  4655. dialog._ProductBarcode = sn;
  4656. var rs = dialog.ShowDialog();
  4657. if (rs == DialogResult.OK)
  4658. {
  4659. AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  4660. OpenDailogFalg = false;//关闭扫码
  4661. }
  4662. else {
  4663. ProgressState = false;
  4664. return;
  4665. }
  4666. }
  4667. }
  4668. // 产品SN(物料码)校验
  4669. List<TestItem> item = new List<TestItem>();
  4670. stopwatch2.Start();
  4671. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  4672. item, MachineId, StationId);
  4673. stopwatch2.Stop();
  4674. //指令执行结果 1:OK 110:失败
  4675. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4676. //进站结果写入PLC
  4677. CommandFromPLC resultToPlC = new CommandFromPLC();
  4678. resultToPlC.cmd = 0;
  4679. resultToPlC.cmdParam = 0; //指令参数
  4680. resultToPlC.cmdResult = mesResultFrmWeb;
  4681. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4682. }
  4683. catch (Exception ex)
  4684. {
  4685. string str = ex.StackTrace;
  4686. AddMessage(LogType.Error,
  4687. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4688. str.Length - str.LastIndexOf("\\") - 1));
  4689. CommandFromPLC resultToPlC = new CommandFromPLC();
  4690. resultToPlC.cmd = 0;
  4691. resultToPlC.cmdParam = 0; //指令参数
  4692. resultToPlC.cmdResult = 110;
  4693. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4694. }
  4695. stopwatch1.Stop();
  4696. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4697. AddMessage(LogType.Info,
  4698. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4699. stopwatch2.ElapsedMilliseconds + "ms");
  4700. ProgressState = false;
  4701. OpenDailogFalg = true; //开启下一个物料的扫码
  4702. }
  4703. /// <summary>
  4704. /// [S6] 顶盖装配设备 - 出站接口
  4705. /// </summary>
  4706. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  4707. string stationCode, string stationName, out bool ProgressState)
  4708. {
  4709. Stopwatch stopwatch1 = new Stopwatch();
  4710. Stopwatch stopwatch2 = new Stopwatch();
  4711. try
  4712. {
  4713. stopwatch1.Start();
  4714. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4715. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4716. string processItem = stationName; // 测试项目
  4717. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4718. string supplierCode = ""; // 供应商代码
  4719. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4720. string batch_num = GlobalContext.BatchNumber; // 批次号
  4721. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4722. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4723. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4724. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  4725. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  4726. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4727. bool pass = a1Result == 1;
  4728. //根据载具码获取产品码
  4729. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4730. if (string.IsNullOrEmpty(strProductBarcode))
  4731. {
  4732. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4733. }
  4734. sn = strProductBarcode;
  4735. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4736. List<TestItem> items = new List<TestItem>();
  4737. items.Add(new TestItem()
  4738. {
  4739. Parameter_name = "载具码",
  4740. Parameter_value = CarrierBarcode,
  4741. Parameter_unit = ""
  4742. });
  4743. items.Add(new TestItem()
  4744. {
  4745. Parameter_name = "产品码",
  4746. Parameter_value = sn,
  4747. Parameter_unit = ""
  4748. });
  4749. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4750. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4751. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  4752. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4753. stopwatch2.Start();
  4754. //进站结果写入PLC
  4755. CommandFromPLC resultToPlC = new CommandFromPLC();
  4756. resultToPlC.cmd = 0;
  4757. resultToPlC.cmdParam = 0; //指令参数
  4758. resultToPlC.cmdResult = mesResultFrmWeb;
  4759. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4760. stopwatch2.Stop();
  4761. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4762. //保存PLC返回MES数据到本地
  4763. ResponseMessage message = new ResponseMessage();
  4764. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  4765. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  4766. if (message.result == false)
  4767. {
  4768. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4769. }
  4770. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4771. }
  4772. catch (Exception ex)
  4773. {
  4774. stopwatch2.Start();
  4775. CommandFromPLC resultToPlC = new CommandFromPLC();
  4776. resultToPlC.cmd = 0;
  4777. resultToPlC.cmdParam = 0; //指令参数
  4778. resultToPlC.cmdResult = 110;
  4779. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4780. stopwatch2.Stop();
  4781. string str = ex.StackTrace;
  4782. AddMessage(LogType.Error,
  4783. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4784. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4785. }
  4786. stopwatch1.Stop();
  4787. AddMessage(LogType.Info,
  4788. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4789. stopwatch2.ElapsedMilliseconds + "ms");
  4790. ProgressState = false;
  4791. }
  4792. private void S6节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  4793. {
  4794. Stopwatch stopwatch1 = new Stopwatch();
  4795. Stopwatch stopwatch2 = new Stopwatch();
  4796. string resultStr = string.Empty;
  4797. try
  4798. {
  4799. stopwatch1.Start();
  4800. string oEEType = ((int)s1PLCData["a6OEEType"]).ToString(); // 节拍类型(plc写入)
  4801. string a60EEPartNo = (string)s1PLCData["a60EEPartNo"]; // 物料码
  4802. a60EEPartNo = a60EEPartNo.Replace("\0", "");
  4803. string a60EEVehicleCode = (string)s1PLCData["a60EEVehicleCode"]; // 载具SN
  4804. a60EEVehicleCode = a60EEVehicleCode.Replace("\0", "");
  4805. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4806. if (!actionBool)
  4807. {
  4808. stopwatch2.Start();
  4809. //写入PLC
  4810. iot_data.beatReturn = 2; //NG
  4811. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4812. stopwatch2.Stop();
  4813. AddMessage(LogType.Info,
  4814. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  4815. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4816. return;
  4817. }
  4818. //作业开始后要有物料和载具信息
  4819. if (string.IsNullOrEmpty(a60EEPartNo) && string.IsNullOrEmpty(a60EEVehicleCode) &&
  4820. Convert.ToInt32(oEEType) > 2)
  4821. {
  4822. stopwatch2.Start();
  4823. //写入PLC
  4824. iot_data.beatReturn = 2; //NG
  4825. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4826. stopwatch2.Stop();
  4827. AddMessage_Station(stationNameStr, LogType.Info,
  4828. stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  4829. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4830. return;
  4831. }
  4832. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a60EEPartNo))
  4833. {
  4834. stopwatch2.Start();
  4835. //写入PLC
  4836. iot_data.beatReturn = 2; //NG
  4837. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4838. stopwatch2.Stop();
  4839. AddMessage_Station(stationNameStr, LogType.Info,
  4840. stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  4841. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4842. return;
  4843. }
  4844. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a60EEVehicleCode))
  4845. {
  4846. stopwatch2.Start();
  4847. //写入PLC
  4848. iot_data.beatReturn = 2; //NG
  4849. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4850. stopwatch2.Stop();
  4851. AddMessage_Station(stationNameStr, LogType.Info,
  4852. stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  4853. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4854. return;
  4855. }
  4856. short _result = 0;
  4857. // 上传OEE
  4858. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a60EEPartNo, a60EEVehicleCode);
  4859. _result = result.Item1;
  4860. resultStr = result.Item2;
  4861. if (_result == 1)
  4862. {
  4863. stopwatch2.Start();
  4864. //写入PLC
  4865. iot_data.beatReturn = 1; //OK
  4866. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4867. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  4868. stopwatch2.Stop();
  4869. }
  4870. else
  4871. {
  4872. stopwatch2.Start();
  4873. //写入PLC
  4874. iot_data.beatReturn = 2; //NG
  4875. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4876. stopwatch2.Stop();
  4877. AddMessage_Station(stationNameStr, LogType.Error,
  4878. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  4879. }
  4880. }
  4881. catch (Exception ex)
  4882. {
  4883. string str = ex.StackTrace;
  4884. AddMessage_Station(stationNameStr, LogType.Error,
  4885. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  4886. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4887. // MES_Flag
  4888. stopwatch2.Start();
  4889. //写入PLC
  4890. iot_data.beatReturn = 2; //NG
  4891. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4892. stopwatch2.Stop();
  4893. }
  4894. stopwatch1.Stop();
  4895. AddMessage(LogType.Info,
  4896. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4897. stopwatch2.ElapsedMilliseconds + "ms");
  4898. }
  4899. #endregion
  4900. #region S7
  4901. private Dictionary<string, object> s7PLCSignal_Old = new Dictionary<string, object>();
  4902. private Dictionary<string, object> s7PLCData = new Dictionary<string, object>();
  4903. /// <summary>
  4904. /// [S7] 锁螺丝设备
  4905. /// </summary>
  4906. /// <param name="plcNo">PLC编号</param>
  4907. private void ReadStation_S7(int plcNo)
  4908. {
  4909. string stationCode = "[OP70]";
  4910. string stationName = "上盖板锁螺丝";
  4911. string stationNameStr = stationCode + stationName;
  4912. string tagBaseName = "g_OP70_MES"; //标签变量名称
  4913. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4914. string tagAgvCommName = "agvCommFrmPC";
  4915. string tagBarsetName = "BarcodeSet";
  4916. string tagScrewDataset = "screwDataset";
  4917. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4918. s7PLCSignal_Old.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
  4919. s7PLCSignal_Old.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
  4920. // PLC数据字典 赋值
  4921. s7PLCData.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
  4922. s7PLCData.Add("a7OEEPartNo_left", ""); // 物料码(物料码还未绑定载具SN时必填)
  4923. s7PLCData.Add("a7OEEVehicleCode_left", ""); // 载具SN
  4924. s7PLCData.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
  4925. s7PLCData.Add("a7OEEPartNo_right", ""); // 物料码(物料码还未绑定载具SN时必填)
  4926. s7PLCData.Add("a7OEEVehicleCode_right", ""); // 载具SN
  4927. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  4928. (int, string) result;
  4929. AtlasScrew atlasScrewLeft = new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort,
  4930. 3000, 3000, "Left");
  4931. atlasScrewLeft.Initial();
  4932. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort,
  4933. 3000, 3000, "Right");
  4934. atlasScrewRight.Initial();
  4935. while (true)
  4936. {
  4937. try
  4938. {
  4939. if (!GlobalContext._IsCon_Funs1)
  4940. {
  4941. UpdatePLCMonitor(1, plcNo, 0);
  4942. continue;
  4943. }
  4944. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4945. {
  4946. Stopwatch stopwatch1 = new Stopwatch();
  4947. Stopwatch stopwatch2 = new Stopwatch();
  4948. stopwatch1.Start();
  4949. stopwatch2.Start();
  4950. #region 一次性读取所有数据
  4951. // 一次性读取所有数据
  4952. result = FunsEip[plcNo]
  4953. .Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4954. if (result.Item1 != 0)
  4955. {
  4956. //richTextBox1.AppendText("\n" + strRet);
  4957. }
  4958. else
  4959. {
  4960. //richTextBox1.AppendText("\n" + "读取成功");
  4961. int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  4962. int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  4963. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  4964. ? XiaomiDeviceState.Unknown
  4965. : (XiaomiDeviceState)xmDeviceStateInt_L;
  4966. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  4967. ? XiaomiDeviceState.Unknown
  4968. : (XiaomiDeviceState)xmDeviceStateInt_R;
  4969. s7PLCData["a7OEEPartNo"] =stPLC_MesData.Left.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  4970. s7PLCData["a7OEEVehicleCode"] = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode; // 载具SN
  4971. s7PLCData["a7OEEType"] = stPLC_MesData.Left.iotData.BeatAction; // 节拍
  4972. s7PLCData["a7OEEVehicleCode_right"] = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode; // 载具SN
  4973. s7PLCData["a7OEEType_right"] = stPLC_MesData.Right.iotData.BeatAction; // 节拍
  4974. }
  4975. #endregion 一次性读取所有数据
  4976. stopwatch2.Stop();
  4977. #region 左边进站
  4978. try
  4979. {
  4980. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4981. {
  4982. lock (lockObj)
  4983. {
  4984. if (!ProgressState)
  4985. {
  4986. ProgressState = true;
  4987. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left,
  4988. tagBaseName + ".Left." + tagMesCommName,
  4989. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState,
  4990. atlasScrewLeft));
  4991. }
  4992. }
  4993. }
  4994. }
  4995. catch (Exception ex)
  4996. {
  4997. ProgressState = false;
  4998. string str = ex.StackTrace;
  4999. AddMessage_Station(stationNameStr, LogType.Error,
  5000. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5001. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5002. }
  5003. #endregion 左边进站
  5004. #region 左边出站
  5005. try
  5006. {
  5007. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5008. {
  5009. lock (lockObj)
  5010. {
  5011. if (!ProgressState)
  5012. {
  5013. ProgressState = true;
  5014. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left,
  5015. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  5016. out ProgressState));
  5017. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  5018. }
  5019. }
  5020. }
  5021. }
  5022. catch (Exception ex)
  5023. {
  5024. ProgressState = false;
  5025. string str = ex.StackTrace;
  5026. AddMessage_Station(stationNameStr, LogType.Error,
  5027. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5028. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5029. }
  5030. #endregion 左边出站
  5031. #region 右边进站
  5032. try
  5033. {
  5034. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5035. {
  5036. lock (lockObj)
  5037. {
  5038. if (!ProgressState)
  5039. {
  5040. ProgressState = true;
  5041. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right,
  5042. tagBaseName + ".Right." + tagMesCommName,
  5043. tagBaseName + ".Right" + tagBarsetName, "Right", out ProgressState,
  5044. atlasScrewRight));
  5045. }
  5046. }
  5047. }
  5048. }
  5049. catch (Exception ex)
  5050. {
  5051. ProgressState = false;
  5052. string str = ex.StackTrace;
  5053. AddMessage_Station(stationNameStr, LogType.Error,
  5054. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5055. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5056. }
  5057. #endregion 右边进站
  5058. #region 右边出站
  5059. try
  5060. {
  5061. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5062. {
  5063. lock (lockObj)
  5064. {
  5065. if (!ProgressState)
  5066. {
  5067. ProgressState = true;
  5068. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right,
  5069. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  5070. out ProgressState));
  5071. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  5072. }
  5073. }
  5074. }
  5075. }
  5076. catch (Exception ex)
  5077. {
  5078. ProgressState = false;
  5079. string str = ex.StackTrace;
  5080. AddMessage_Station(stationNameStr, LogType.Error,
  5081. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5082. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5083. }
  5084. #endregion 右边出站
  5085. #region 节拍接口
  5086. try
  5087. {
  5088. #region 左工位 节拍
  5089. int a70EEType_left = (int)s7PLCData["a70EEType_left"];
  5090. int a70EETypeGOld_left = (int)s7PLCSignal_Old["a70EEType_left"];
  5091. //若设备紧急复原后节拍重置
  5092. if (a70EEType_left == 1)
  5093. {
  5094. a70EETypeGOld_left = 0;
  5095. }
  5096. if (a70EEType_left != a70EETypeGOld_left)
  5097. {
  5098. stationNameStr = stationNameStr + "_Left";
  5099. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  5100. if ((a70EETypeGOld_left == 1 && a70EEType_left != 2) || (a70EETypeGOld_left == 3 && a70EEType_left != 4) ||
  5101. (a70EETypeGOld_left == 5 && a70EEType_left != 6))
  5102. {
  5103. //写入PLC
  5104. stPLC_MesData.Left.iotData.beatReturn = 2; //NG
  5105. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName, 1, stPLC_MesData.Left.iotData);
  5106. AddMessage(LogType.Info,
  5107. stationNameStr +
  5108. $"_节拍接口-- 设备本次上传节拍[{a70EEType_left}],未上传节拍[{a70EETypeGOld_left}]的结束信号,请检查;总用时" +
  5109. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  5110. "ms");
  5111. return;
  5112. }
  5113. else
  5114. {
  5115. Task.Run(() =>
  5116. S3节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName,
  5117. stPLC_MesData.Left.iotData)); // MreTasks[4].Set();
  5118. }
  5119. s7PLCSignal_Old["a70EEType_left"] = s7PLCData["a70EEType_left"];
  5120. }
  5121. #endregion 左工位 节拍
  5122. #region 右工位 节拍
  5123. int a70EEType_right = (int)s7PLCData["a70EEType_right"];
  5124. int a70EETypeGOld_right = (int)s7PLCSignal_Old["a70EEType_right"];
  5125. //若设备紧急复原后节拍重置
  5126. if (a70EEType_right == 1)
  5127. {
  5128. a70EETypeGOld_right = 0;
  5129. }
  5130. if (a70EEType_right != a70EETypeGOld_right)
  5131. {
  5132. stationNameStr = stationNameStr + "_Right";
  5133. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  5134. if ((a70EETypeGOld_right == 1 && a70EEType_right != 2) || (a70EETypeGOld_right == 3 && a70EEType_right != 4) ||
  5135. (a70EETypeGOld_right == 5 && a70EEType_right != 6))
  5136. {
  5137. //写入PLC
  5138. stPLC_MesData.Right.iotData.beatReturn = 2; //NG
  5139. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName, 1, stPLC_MesData.Left.iotData);
  5140. AddMessage(LogType.Info,
  5141. stationNameStr +
  5142. $"_节拍接口-- 设备本次上传节拍[{a70EEType_right}],未上传节拍[{a70EETypeGOld_right}]的结束信号,请检查;总用时" +
  5143. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  5144. "ms");
  5145. return;
  5146. }
  5147. else
  5148. {
  5149. Task.Run(() =>
  5150. S3节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName,
  5151. stPLC_MesData.Left.iotData)); // MreTasks[4].Set();
  5152. }
  5153. s7PLCSignal_Old["a70EEType_right"] = s7PLCData["a70EEType_right"];
  5154. }
  5155. #endregion 右工位 节拍
  5156. }
  5157. catch (Exception ex)
  5158. {
  5159. string str = ex.StackTrace;
  5160. AddMessage_Station(stationNameStr, LogType.Error,
  5161. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  5162. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5163. }
  5164. #endregion
  5165. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5166. stopwatch1.Stop();
  5167. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5168. }
  5169. else
  5170. {
  5171. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5172. AddMessage_Station(stationNameStr, LogType.Info,
  5173. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5174. FunsEip[plcNo].Connect(); // 重连
  5175. }
  5176. }
  5177. catch (Exception ex)
  5178. {
  5179. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5180. AddMessage_Station(stationNameStr, LogType.Error,
  5181. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5182. }
  5183. Thread.Sleep(IntervalReadPLC);
  5184. }
  5185. }
  5186. /// <summary>
  5187. /// [S7] 锁螺丝设备 - 进站
  5188. /// </summary>
  5189. /// <param name="plcNo">PLC编号</param>
  5190. /// <param name="stationNameStr">工站全称</param>
  5191. /// <param name="stPLC_MesData"></param>
  5192. /// <param name="tagMesCommName"></param>
  5193. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  5194. string tagBarsetName, string direction, out bool ProgressState, AtlasScrew atlasScrew)
  5195. {
  5196. Stopwatch stopwatch1 = new Stopwatch();
  5197. Stopwatch stopwatch2 = new Stopwatch();
  5198. string atlasSn = string.Empty;
  5199. try
  5200. {
  5201. stopwatch1.Start();
  5202. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  5203. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5204. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  5205. string StationId = string.Empty; // 工位ID(可配置)
  5206. if (direction == "Left")
  5207. {
  5208. StationId = GlobalContext.S7_StationId_1;
  5209. }
  5210. if (direction == "Right")
  5211. {
  5212. StationId = GlobalContext.S7_StationId_2;
  5213. }
  5214. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  5215. //载具码验证产品码
  5216. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  5217. if (string.IsNullOrEmpty(strProductBarcode))
  5218. {
  5219. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  5220. }
  5221. sn = strProductBarcode;
  5222. atlasSn = strProductBarcode;
  5223. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5224. if (direction == "Left")
  5225. {
  5226. isCollectingFlagLeft = false; //采集螺丝数据结束
  5227. }
  5228. if (direction == "Right")
  5229. {
  5230. isCollectingFlagRight = false; //采集螺丝数据结束
  5231. }
  5232. // 产品SN(物料码)校验
  5233. List<TestItem> item = new List<TestItem>();
  5234. stopwatch2.Start();
  5235. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  5236. item, MachineId, StationId);
  5237. stopwatch2.Stop();
  5238. //指令执行结果 1:OK 110:失败
  5239. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5240. //进站结果写入PLC
  5241. CommandFromPLC resultToPlC = new CommandFromPLC();
  5242. resultToPlC.cmd = 0;
  5243. resultToPlC.cmdParam = 0; //指令参数
  5244. resultToPlC.cmdResult = mesResultFrmWeb;
  5245. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5246. }
  5247. catch (Exception ex)
  5248. {
  5249. string str = ex.StackTrace;
  5250. AddMessage(LogType.Error,
  5251. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  5252. str.Length - str.LastIndexOf("\\") - 1));
  5253. CommandFromPLC resultToPlC = new CommandFromPLC();
  5254. resultToPlC.cmd = 0;
  5255. resultToPlC.cmdParam = 0; //指令参数
  5256. resultToPlC.cmdResult = 110;
  5257. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5258. }
  5259. stopwatch1.Stop();
  5260. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  5261. AddMessage(LogType.Info,
  5262. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5263. stopwatch2.ElapsedMilliseconds + "ms");
  5264. ProgressState = false;
  5265. //开始采集螺丝数据
  5266. if (direction == "Left")
  5267. {
  5268. isCollectingFlagLeft = true;
  5269. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  5270. }
  5271. if (direction == "Right")
  5272. {
  5273. isCollectingFlagRight = true;
  5274. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  5275. }
  5276. }
  5277. /// <summary>
  5278. /// [S7] 锁螺丝设备 - 出站
  5279. /// </summary>
  5280. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  5281. string stationCode, string stationName, string direction, out bool ProgressState)
  5282. {
  5283. Stopwatch stopwatch1 = new Stopwatch();
  5284. Stopwatch stopwatch2 = new Stopwatch();
  5285. try
  5286. {
  5287. stopwatch1.Start();
  5288. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  5289. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5290. string processItem = stationName; // 测试项目
  5291. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5292. string supplierCode = ""; // 供应商代码
  5293. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5294. string batch_num = GlobalContext.BatchNumber; // 批次号
  5295. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5296. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5297. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5298. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  5299. string StationId = string.Empty; // 工位ID(可配置)
  5300. if (direction == "Left")
  5301. {
  5302. StationId = GlobalContext.S7_StationId_1;
  5303. }
  5304. if (direction == "Right")
  5305. {
  5306. StationId = GlobalContext.S7_StationId_2;
  5307. }
  5308. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5309. a1Result = 1;
  5310. bool pass = a1Result == 1;
  5311. //根据载具码获取产品码
  5312. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5313. if (string.IsNullOrEmpty(strProductBarcode))
  5314. {
  5315. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  5316. }
  5317. sn = strProductBarcode;
  5318. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  5319. List<TestItem> items = new List<TestItem>();
  5320. items.Add(new TestItem()
  5321. {
  5322. Parameter_name = "载具码",
  5323. Parameter_value = CarrierBarcode,
  5324. Parameter_unit = ""
  5325. });
  5326. items.Add(new TestItem()
  5327. {
  5328. Parameter_name = "产品码",
  5329. Parameter_value = sn,
  5330. Parameter_unit = ""
  5331. });
  5332. int result1 = 1;
  5333. //if (direction == "Right")
  5334. //{
  5335. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  5336. SwitctProcessData(stationNameStr, items, equipmentCode, processItem , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode
  5337. , sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  5338. //}
  5339. //if (direction == "Left")
  5340. //{
  5341. // isCollectingFlagLeft = false;//采集螺丝数据结束
  5342. //}
  5343. //if (direction == "Right")
  5344. //{
  5345. // isCollectingFlagRight = false;//采集螺丝数据结束
  5346. //}
  5347. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5348. stopwatch2.Start();
  5349. //进站结果写入PLC
  5350. CommandFromPLC resultToPlC = new CommandFromPLC();
  5351. resultToPlC.cmd = 0;
  5352. resultToPlC.cmdParam = 0; //指令参数
  5353. resultToPlC.cmdResult = mesResultFrmWeb;
  5354. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5355. stopwatch2.Stop();
  5356. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  5357. //保存PLC返回MES数据到本地
  5358. ResponseMessage message = new ResponseMessage();
  5359. if (direction == "Left")
  5360. {
  5361. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  5362. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  5363. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  5364. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  5365. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  5366. if (message.result == false)
  5367. {
  5368. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  5369. }
  5370. }
  5371. if (direction == "Right")
  5372. {
  5373. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  5374. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  5375. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  5376. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  5377. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  5378. if (message.result == false)
  5379. {
  5380. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  5381. }
  5382. }
  5383. //保存螺丝数据到txt
  5384. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes,
  5385. stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  5386. if (result.Item1 != 0)
  5387. {
  5388. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  5389. }
  5390. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_保存加工数据到本地成功");
  5391. }
  5392. catch (Exception ex)
  5393. {
  5394. stopwatch2.Start();
  5395. CommandFromPLC resultToPlC = new CommandFromPLC();
  5396. resultToPlC.cmd = 0;
  5397. resultToPlC.cmdParam = 0; //指令参数
  5398. resultToPlC.cmdResult = 110;
  5399. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5400. stopwatch2.Stop();
  5401. string str = ex.StackTrace;
  5402. AddMessage(LogType.Error,
  5403. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5404. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5405. }
  5406. stopwatch1.Stop();
  5407. AddMessage(LogType.Info,
  5408. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5409. stopwatch2.ElapsedMilliseconds + "ms");
  5410. ProgressState = false;
  5411. }
  5412. private void S7节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  5413. {
  5414. Stopwatch stopwatch1 = new Stopwatch();
  5415. Stopwatch stopwatch2 = new Stopwatch();
  5416. string resultStr = string.Empty;
  5417. try
  5418. {
  5419. stopwatch1.Start();
  5420. string oEEType = ((int)s1PLCData["a7OEEType"]).ToString(); // 节拍类型(plc写入)
  5421. string a7OEEPartNo = (string)s1PLCData["a7OEEPartNo"]; // 物料码
  5422. a7OEEPartNo = a7OEEPartNo.Replace("\0", "");
  5423. string a7OEEVehicleCode = (string)s1PLCData["a7OEEVehicleCode"]; // 载具SN
  5424. a7OEEVehicleCode = a7OEEVehicleCode.Replace("\0", "");
  5425. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5426. if (!actionBool)
  5427. {
  5428. stopwatch2.Start();
  5429. //写入PLC
  5430. iot_data.beatReturn = 2; //NG
  5431. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5432. stopwatch2.Stop();
  5433. AddMessage(LogType.Info,
  5434. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  5435. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5436. return;
  5437. }
  5438. //作业开始后要有物料和载具信息
  5439. if (string.IsNullOrEmpty(a7OEEPartNo) && string.IsNullOrEmpty(a7OEEVehicleCode) &&
  5440. Convert.ToInt32(oEEType) > 2)
  5441. {
  5442. stopwatch2.Start();
  5443. //写入PLC
  5444. iot_data.beatReturn = 2; //NG
  5445. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5446. stopwatch2.Stop();
  5447. AddMessage_Station(stationNameStr, LogType.Info,
  5448. stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  5449. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5450. return;
  5451. }
  5452. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a7OEEPartNo))
  5453. {
  5454. stopwatch2.Start();
  5455. //写入PLC
  5456. iot_data.beatReturn = 2; //NG
  5457. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5458. stopwatch2.Stop();
  5459. AddMessage_Station(stationNameStr, LogType.Info,
  5460. stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  5461. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5462. return;
  5463. }
  5464. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a7OEEVehicleCode))
  5465. {
  5466. stopwatch2.Start();
  5467. //写入PLC
  5468. iot_data.beatReturn = 2; //NG
  5469. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5470. stopwatch2.Stop();
  5471. AddMessage_Station(stationNameStr, LogType.Info,
  5472. stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  5473. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5474. return;
  5475. }
  5476. short _result = 0;
  5477. // 上传OEE
  5478. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a7OEEPartNo, a7OEEVehicleCode);
  5479. _result = result.Item1;
  5480. resultStr = result.Item2;
  5481. if (_result == 1)
  5482. {
  5483. stopwatch2.Start();
  5484. //写入PLC
  5485. iot_data.beatReturn = 1; //OK
  5486. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5487. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  5488. stopwatch2.Stop();
  5489. }
  5490. else
  5491. {
  5492. stopwatch2.Start();
  5493. //写入PLC
  5494. iot_data.beatReturn = 2; //NG
  5495. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5496. stopwatch2.Stop();
  5497. AddMessage_Station(stationNameStr, LogType.Error,
  5498. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  5499. }
  5500. }
  5501. catch (Exception ex)
  5502. {
  5503. string str = ex.StackTrace;
  5504. AddMessage_Station(stationNameStr, LogType.Error,
  5505. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  5506. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5507. // MES_Flag
  5508. stopwatch2.Start();
  5509. //写入PLC
  5510. iot_data.beatReturn = 2; //NG
  5511. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5512. stopwatch2.Stop();
  5513. }
  5514. stopwatch1.Stop();
  5515. AddMessage(LogType.Info,
  5516. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5517. stopwatch2.ElapsedMilliseconds + "ms");
  5518. }
  5519. #endregion
  5520. #region S8
  5521. private Dictionary<string, object> s8PLCData = new Dictionary<string, object>();
  5522. private Dictionary<string, object> s8PLCSignal_Old = new Dictionary<string, object>();
  5523. /// <summary>
  5524. /// [S8] 3D螺丝高度检测设备
  5525. /// </summary>
  5526. /// <param name="plcNo">PLC编号</param>
  5527. private void ReadStation_S8(int plcNo)
  5528. {
  5529. string stationCode = "[OP80]";
  5530. string stationName = "NG下料";
  5531. string stationNameStr = stationCode + stationName;
  5532. string tagBaseName = "g_OP80_MES"; //标签变量名称
  5533. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5534. string tagAgvCommName = "agvCommFrmPC";
  5535. string tagBarsetName = "BarcodeSet";
  5536. // 触发信号字典
  5537. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5538. s8PLCSignal_Old.Add("a8OEEType", 0); // 节拍类型(plc写入)
  5539. // PLC数据字典 赋值
  5540. s8PLCData.Add("a8OEEType", 0); // 节拍类型(plc写入)
  5541. s8PLCData.Add("a8OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  5542. s8PLCData.Add("a8OEEVehicleCode", ""); // 载具SN
  5543. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  5544. (int, string) result;
  5545. while (true)
  5546. {
  5547. try
  5548. {
  5549. if (!GlobalContext._IsCon_Funs1)
  5550. {
  5551. UpdatePLCMonitor(1, plcNo, 0);
  5552. continue;
  5553. }
  5554. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5555. {
  5556. Stopwatch stopwatch1 = new Stopwatch();
  5557. Stopwatch stopwatch2 = new Stopwatch();
  5558. stopwatch1.Start();
  5559. stopwatch2.Start();
  5560. #region 一次性读取所有数据
  5561. // 一次性读取所有数据
  5562. result = FunsEip[plcNo]
  5563. .Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  5564. if (result.Item1 != 0)
  5565. {
  5566. //richTextBox1.AppendText("\n" + strRet);
  5567. }
  5568. else
  5569. {
  5570. //richTextBox1.AppendText("\n" + "读取成功");
  5571. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  5572. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  5573. ? XiaomiDeviceState.Unknown
  5574. : (XiaomiDeviceState)xmDeviceStateInt;
  5575. s8PLCData["a8OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  5576. s8PLCData["a8OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  5577. s8PLCData["a8OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  5578. }
  5579. #endregion 一次性读取所有数据
  5580. stopwatch2.Stop();
  5581. #region 进站
  5582. try
  5583. {
  5584. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5585. {
  5586. lock (lockObj)
  5587. {
  5588. if (!ProgressState)
  5589. {
  5590. ProgressState = true;
  5591. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData,
  5592. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  5593. out ProgressState));
  5594. }
  5595. }
  5596. }
  5597. }
  5598. catch (Exception ex)
  5599. {
  5600. ProgressState = false;
  5601. string str = ex.StackTrace;
  5602. AddMessage_Station(stationNameStr, LogType.Error,
  5603. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5604. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5605. }
  5606. #endregion 进站
  5607. #region 出站
  5608. try
  5609. {
  5610. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5611. {
  5612. lock (lockObj)
  5613. {
  5614. if (!ProgressState)
  5615. {
  5616. ProgressState = true;
  5617. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData,
  5618. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  5619. out ProgressState));
  5620. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  5621. }
  5622. }
  5623. }
  5624. }
  5625. catch (Exception ex)
  5626. {
  5627. ProgressState = false;
  5628. string str = ex.StackTrace;
  5629. AddMessage_Station(stationNameStr, LogType.Error,
  5630. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5631. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5632. }
  5633. #endregion 出站
  5634. #region 节拍接口
  5635. try
  5636. {
  5637. int a80EEType = (int)s9PLCData["a80EEType"];
  5638. int a80EETypeGOld = (int)s9PLCSignal_Old["a80EEType"];
  5639. //若设备紧急复原后节拍重置
  5640. if (a80EEType == 1)
  5641. {
  5642. a80EETypeGOld = 0;
  5643. }
  5644. if (a80EEType != a80EETypeGOld)
  5645. {
  5646. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  5647. if ((a80EETypeGOld == 1 && a80EEType != 2) || (a80EETypeGOld == 3 && a80EEType != 4) ||
  5648. (a80EETypeGOld == 5 && a80EEType != 6))
  5649. {
  5650. //写入PLC
  5651. stPLC_MesData.iotData.beatReturn = 2; //NG
  5652. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  5653. AddMessage(LogType.Info,
  5654. stationNameStr +
  5655. $"_节拍接口-- 设备本次上传节拍[{a80EEType}],未上传节拍[{a80EETypeGOld}]的结束信号,请检查;总用时" +
  5656. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  5657. "ms");
  5658. return;
  5659. }
  5660. else
  5661. {
  5662. Task.Run(() =>
  5663. S8节拍接口(plcNo, stationNameStr, tagBaseName,
  5664. stPLC_MesData.iotData)); // MreTasks[4].Set();
  5665. }
  5666. s8PLCSignal_Old["a80EEType"] = s8PLCData["a80EEType"];
  5667. }
  5668. }
  5669. catch (Exception ex)
  5670. {
  5671. string str = ex.StackTrace;
  5672. AddMessage_Station(stationNameStr, LogType.Error,
  5673. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  5674. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5675. }
  5676. #endregion
  5677. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5678. stopwatch1.Stop();
  5679. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5680. }
  5681. else
  5682. {
  5683. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5684. AddMessage_Station(stationNameStr, LogType.Info,
  5685. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5686. FunsEip[plcNo].Connect(); // 重连
  5687. }
  5688. }
  5689. catch (Exception ex)
  5690. {
  5691. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5692. AddMessage_Station(stationNameStr, LogType.Error,
  5693. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5694. }
  5695. Thread.Sleep(IntervalReadPLC);
  5696. }
  5697. }
  5698. /// <summary>
  5699. /// [S8] 3D螺丝高度检测设备 - 进站
  5700. /// </summary>
  5701. /// <param name="plcNo">PLC编号</param>
  5702. /// <param name="stationNameStr">工站全称</param>
  5703. /// <param name="stPLC_MesData"></param>
  5704. /// <param name="tagMesCommName"></param>
  5705. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  5706. string tagBarsetName, out bool ProgressState)
  5707. {
  5708. Stopwatch stopwatch1 = new Stopwatch();
  5709. Stopwatch stopwatch2 = new Stopwatch();
  5710. try
  5711. {
  5712. stopwatch1.Start();
  5713. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  5714. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5715. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  5716. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  5717. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  5718. //载具码验证产品码
  5719. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  5720. if (string.IsNullOrEmpty(strProductBarcode))
  5721. {
  5722. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  5723. }
  5724. sn = strProductBarcode;
  5725. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5726. // 产品SN(物料码)校验
  5727. List<TestItem> item = new List<TestItem>();
  5728. stopwatch2.Start();
  5729. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  5730. item, MachineId, StationId);
  5731. stopwatch2.Stop();
  5732. //指令执行结果 1:OK 110:失败
  5733. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5734. //进站结果写入PLC
  5735. CommandFromPLC resultToPlC = new CommandFromPLC();
  5736. resultToPlC.cmd = 0;
  5737. resultToPlC.cmdParam = 0; //指令参数
  5738. resultToPlC.cmdResult = mesResultFrmWeb;
  5739. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5740. }
  5741. catch (Exception ex)
  5742. {
  5743. string str = ex.StackTrace;
  5744. AddMessage(LogType.Error,
  5745. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  5746. str.Length - str.LastIndexOf("\\") - 1));
  5747. CommandFromPLC resultToPlC = new CommandFromPLC();
  5748. resultToPlC.cmd = 0;
  5749. resultToPlC.cmdParam = 0; //指令参数
  5750. resultToPlC.cmdResult = 110;
  5751. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5752. }
  5753. stopwatch1.Stop();
  5754. AddMessage(LogType.Info,
  5755. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5756. stopwatch2.ElapsedMilliseconds + "ms");
  5757. ProgressState = false;
  5758. }
  5759. /// <summary>
  5760. /// [S8] 3D螺丝高度检测设备 - 出站接口
  5761. /// </summary>
  5762. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  5763. string stationCode, string stationName, out bool ProgressState)
  5764. {
  5765. Stopwatch stopwatch1 = new Stopwatch();
  5766. Stopwatch stopwatch2 = new Stopwatch();
  5767. try
  5768. {
  5769. stopwatch1.Start();
  5770. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  5771. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5772. string processItem = stationName; // 测试项目
  5773. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5774. string supplierCode = ""; // 供应商代码
  5775. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5776. string batch_num = GlobalContext.BatchNumber; // 批次号
  5777. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5778. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5779. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5780. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  5781. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  5782. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5783. bool pass = a1Result == 1;
  5784. //根据载具码获取产品码
  5785. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5786. if (string.IsNullOrEmpty(strProductBarcode))
  5787. {
  5788. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  5789. }
  5790. sn = strProductBarcode;
  5791. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  5792. List<TestItem> items = new List<TestItem>();
  5793. items.Add(new TestItem()
  5794. {
  5795. Parameter_name = "载具码",
  5796. Parameter_value = CarrierBarcode,
  5797. Parameter_unit = ""
  5798. });
  5799. items.Add(new TestItem()
  5800. {
  5801. Parameter_name = "产品码",
  5802. Parameter_value = sn,
  5803. Parameter_unit = ""
  5804. });
  5805. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  5806. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  5807. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  5808. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5809. stopwatch2.Start();
  5810. //进站结果写入PLC
  5811. CommandFromPLC resultToPlC = new CommandFromPLC();
  5812. resultToPlC.cmd = 0;
  5813. resultToPlC.cmdParam = 0; //指令参数
  5814. resultToPlC.cmdResult = mesResultFrmWeb;
  5815. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5816. stopwatch2.Stop();
  5817. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  5818. //保存PLC返回MES数据到本地
  5819. ResponseMessage message = new ResponseMessage();
  5820. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  5821. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  5822. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  5823. if (message.result == false)
  5824. {
  5825. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  5826. }
  5827. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  5828. }
  5829. catch (Exception ex)
  5830. {
  5831. stopwatch2.Start();
  5832. CommandFromPLC resultToPlC = new CommandFromPLC();
  5833. resultToPlC.cmd = 0;
  5834. resultToPlC.cmdParam = 0; //指令参数
  5835. resultToPlC.cmdResult = 110;
  5836. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5837. stopwatch2.Stop();
  5838. string str = ex.StackTrace;
  5839. AddMessage(LogType.Error,
  5840. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5841. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5842. }
  5843. stopwatch1.Stop();
  5844. AddMessage(LogType.Info,
  5845. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5846. stopwatch2.ElapsedMilliseconds + "ms");
  5847. ProgressState = false;
  5848. }
  5849. private void S8节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  5850. {
  5851. Stopwatch stopwatch1 = new Stopwatch();
  5852. Stopwatch stopwatch2 = new Stopwatch();
  5853. string resultStr = string.Empty;
  5854. try
  5855. {
  5856. stopwatch1.Start();
  5857. string oEEType = ((int)s1PLCData["a8OEEType"]).ToString(); // 节拍类型(plc写入)
  5858. string a80EEPartNo = (string)s1PLCData["a80EEPartNo"]; // 物料码
  5859. a80EEPartNo = a80EEPartNo.Replace("\0", "");
  5860. string a80EEVehicleCode = (string)s1PLCData["a80EEVehicleCode"]; // 载具SN
  5861. a80EEVehicleCode = a80EEVehicleCode.Replace("\0", "");
  5862. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5863. if (!actionBool)
  5864. {
  5865. stopwatch2.Start();
  5866. //写入PLC
  5867. iot_data.beatReturn = 2; //NG
  5868. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5869. stopwatch2.Stop();
  5870. AddMessage(LogType.Info,
  5871. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  5872. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5873. return;
  5874. }
  5875. //作业开始后要有物料和载具信息
  5876. if (string.IsNullOrEmpty(a80EEPartNo) && string.IsNullOrEmpty(a80EEVehicleCode) &&
  5877. Convert.ToInt32(oEEType) > 2)
  5878. {
  5879. stopwatch2.Start();
  5880. //写入PLC
  5881. iot_data.beatReturn = 2; //NG
  5882. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5883. stopwatch2.Stop();
  5884. AddMessage_Station(stationNameStr, LogType.Info,
  5885. stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  5886. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5887. return;
  5888. }
  5889. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a80EEPartNo))
  5890. {
  5891. stopwatch2.Start();
  5892. //写入PLC
  5893. iot_data.beatReturn = 2; //NG
  5894. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5895. stopwatch2.Stop();
  5896. AddMessage_Station(stationNameStr, LogType.Info,
  5897. stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  5898. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5899. return;
  5900. }
  5901. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a80EEVehicleCode))
  5902. {
  5903. stopwatch2.Start();
  5904. //写入PLC
  5905. iot_data.beatReturn = 2; //NG
  5906. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5907. stopwatch2.Stop();
  5908. AddMessage_Station(stationNameStr, LogType.Info,
  5909. stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  5910. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5911. return;
  5912. }
  5913. short _result = 0;
  5914. // 上传OEE
  5915. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a80EEPartNo, a80EEVehicleCode);
  5916. _result = result.Item1;
  5917. resultStr = result.Item2;
  5918. if (_result == 1)
  5919. {
  5920. stopwatch2.Start();
  5921. //写入PLC
  5922. iot_data.beatReturn = 1; //OK
  5923. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5924. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  5925. stopwatch2.Stop();
  5926. }
  5927. else
  5928. {
  5929. stopwatch2.Start();
  5930. //写入PLC
  5931. iot_data.beatReturn = 2; //NG
  5932. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5933. stopwatch2.Stop();
  5934. AddMessage_Station(stationNameStr, LogType.Error,
  5935. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  5936. }
  5937. }
  5938. catch (Exception ex)
  5939. {
  5940. string str = ex.StackTrace;
  5941. AddMessage_Station(stationNameStr, LogType.Error,
  5942. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  5943. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5944. // MES_Flag
  5945. stopwatch2.Start();
  5946. //写入PLC
  5947. iot_data.beatReturn = 2; //NG
  5948. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5949. stopwatch2.Stop();
  5950. }
  5951. stopwatch1.Stop();
  5952. AddMessage(LogType.Info,
  5953. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5954. stopwatch2.ElapsedMilliseconds + "ms");
  5955. }
  5956. #endregion
  5957. #region S9
  5958. private Dictionary<string, object> s9PLCData = new Dictionary<string, object>();
  5959. private Dictionary<string, object> s9PLCSignal_Old = new Dictionary<string, object>();
  5960. /// <summary>
  5961. /// [S9] 下料设备
  5962. /// </summary>
  5963. /// <param name="plcNo">PLC编号</param>
  5964. private void ReadStation_S9(int plcNo)
  5965. {
  5966. string stationCode = "[OP90]";
  5967. string stationName = "半成品下料";
  5968. string stationNameStr = stationCode + stationName;
  5969. string tagBaseName = "g_OP90_MES"; //标签变量名称
  5970. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5971. string tagAgvCommName = "agvCommFrmPC";
  5972. string tagBarsetName = "BarcodeSet";
  5973. // 触发信号字典
  5974. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5975. s9PLCSignal_Old.Add("a9OEEType", 0); // 节拍类型(plc写入)
  5976. // PLC数据字典 赋值
  5977. s9PLCData.Add("a9OEEType", 0); // 节拍类型(plc写入)
  5978. s9PLCData.Add("a9OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  5979. s9PLCData.Add("a9OEEVehicleCode", ""); // 载具SN
  5980. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  5981. (int, string) result;
  5982. while (true)
  5983. {
  5984. try
  5985. {
  5986. if (!GlobalContext._IsCon_Funs1)
  5987. {
  5988. UpdatePLCMonitor(1, plcNo, 0);
  5989. continue;
  5990. }
  5991. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5992. {
  5993. Stopwatch stopwatch1 = new Stopwatch();
  5994. Stopwatch stopwatch2 = new Stopwatch();
  5995. stopwatch1.Start();
  5996. stopwatch2.Start();
  5997. #region 一次性读取所有数据
  5998. // 一次性读取所有数据
  5999. result = FunsEip[plcNo]
  6000. .Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  6001. if (result.Item1 != 0)
  6002. {
  6003. //richTextBox1.AppendText("\n" + strRet);
  6004. }
  6005. else
  6006. {
  6007. //richTextBox1.AppendText("\n" + "读取成功");
  6008. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  6009. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  6010. ? XiaomiDeviceState.Unknown
  6011. : (XiaomiDeviceState)xmDeviceStateInt;
  6012. s9PLCData["a9OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  6013. s9PLCData["a9OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  6014. s9PLCData["a9OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  6015. }
  6016. #endregion 一次性读取所有数据
  6017. stopwatch2.Stop();
  6018. #region 进站
  6019. try
  6020. {
  6021. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  6022. {
  6023. lock (lockObj)
  6024. {
  6025. if (!ProgressState)
  6026. {
  6027. ProgressState = true;
  6028. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData,
  6029. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  6030. out ProgressState));
  6031. }
  6032. }
  6033. }
  6034. }
  6035. catch (Exception ex)
  6036. {
  6037. ProgressState = false;
  6038. string str = ex.StackTrace;
  6039. AddMessage_Station(stationNameStr, LogType.Error,
  6040. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6041. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6042. }
  6043. #endregion 进站
  6044. #region 出站
  6045. try
  6046. {
  6047. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  6048. {
  6049. lock (lockObj)
  6050. {
  6051. if (!ProgressState)
  6052. {
  6053. ProgressState = true;
  6054. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData,
  6055. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  6056. out ProgressState));
  6057. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  6058. }
  6059. }
  6060. }
  6061. }
  6062. catch (Exception ex)
  6063. {
  6064. ProgressState = false;
  6065. string str = ex.StackTrace;
  6066. AddMessage_Station(stationNameStr, LogType.Error,
  6067. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6068. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6069. }
  6070. #endregion 出站
  6071. #region 节拍接口
  6072. try
  6073. {
  6074. int a90EEType = (int)s9PLCData["a90EEType"];
  6075. int a90EETypeGOld = (int)s9PLCSignal_Old["a90EEType"];
  6076. //若设备紧急复原后节拍重置
  6077. if (a90EEType == 1)
  6078. {
  6079. a90EETypeGOld = 0;
  6080. }
  6081. if (a90EEType != a90EETypeGOld)
  6082. {
  6083. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  6084. if ((a90EETypeGOld == 1 && a90EEType != 2) || (a90EETypeGOld == 3 && a90EEType != 4) ||
  6085. (a90EETypeGOld == 5 && a90EEType != 6))
  6086. {
  6087. //写入PLC
  6088. stPLC_MesData.iotData.beatReturn = 2; //NG
  6089. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  6090. AddMessage(LogType.Info,
  6091. stationNameStr +
  6092. $"_节拍接口-- 设备本次上传节拍[{a90EEType}],未上传节拍[{a90EETypeGOld}]的结束信号,请检查;总用时" +
  6093. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  6094. "ms");
  6095. return;
  6096. }
  6097. else
  6098. {
  6099. Task.Run(() =>
  6100. S9节拍接口(plcNo, stationNameStr, tagBaseName,
  6101. stPLC_MesData.iotData)); // MreTasks[4].Set();
  6102. }
  6103. s9PLCSignal_Old["a90EEType"] = s9PLCData["a90EEType"];
  6104. }
  6105. }
  6106. catch (Exception ex)
  6107. {
  6108. string str = ex.StackTrace;
  6109. AddMessage_Station(stationNameStr, LogType.Error,
  6110. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  6111. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6112. }
  6113. #endregion
  6114. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6115. stopwatch1.Stop();
  6116. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6117. }
  6118. else
  6119. {
  6120. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6121. AddMessage_Station(stationNameStr, LogType.Info,
  6122. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6123. FunsEip[plcNo].Connect(); // 重连
  6124. }
  6125. }
  6126. catch (Exception ex)
  6127. {
  6128. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6129. AddMessage_Station(stationNameStr, LogType.Error,
  6130. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6131. }
  6132. Thread.Sleep(IntervalReadPLC);
  6133. }
  6134. }
  6135. /// <summary>
  6136. /// [S9] 下料设备 - 进站
  6137. /// </summary>
  6138. /// <param name="plcNo">PLC编号</param>
  6139. /// <param name="stationNameStr">工站全称</param>
  6140. /// <param name="stPLC_MesData"></param>
  6141. /// <param name="tagMesCommName"></param>
  6142. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  6143. string tagBarsetName, out bool ProgressState)
  6144. {
  6145. Stopwatch stopwatch1 = new Stopwatch();
  6146. Stopwatch stopwatch2 = new Stopwatch();
  6147. try
  6148. {
  6149. stopwatch1.Start();
  6150. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  6151. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  6152. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  6153. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  6154. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  6155. //载具码验证产品码
  6156. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  6157. if (string.IsNullOrEmpty(strProductBarcode))
  6158. {
  6159. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  6160. }
  6161. sn = strProductBarcode;
  6162. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  6163. // 产品SN(物料码)校验
  6164. List<TestItem> item = new List<TestItem>();
  6165. stopwatch2.Start();
  6166. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  6167. item, MachineId, StationId);
  6168. stopwatch2.Stop();
  6169. //指令执行结果 1:OK 110:失败
  6170. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  6171. //进站结果写入PLC
  6172. CommandFromPLC resultToPlC = new CommandFromPLC();
  6173. resultToPlC.cmd = 0;
  6174. resultToPlC.cmdParam = 0; //指令参数
  6175. resultToPlC.cmdResult = mesResultFrmWeb;
  6176. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6177. }
  6178. catch (Exception ex)
  6179. {
  6180. string str = ex.StackTrace;
  6181. AddMessage(LogType.Error,
  6182. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  6183. str.Length - str.LastIndexOf("\\") - 1));
  6184. CommandFromPLC resultToPlC = new CommandFromPLC();
  6185. resultToPlC.cmd = 0;
  6186. resultToPlC.cmdParam = 0; //指令参数
  6187. resultToPlC.cmdResult = 110;
  6188. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6189. }
  6190. stopwatch1.Stop();
  6191. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  6192. AddMessage(LogType.Info,
  6193. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  6194. stopwatch2.ElapsedMilliseconds + "ms");
  6195. ProgressState = false;
  6196. }
  6197. /// <summary>
  6198. /// [S9] 下料设备 - 出站接口
  6199. /// </summary>
  6200. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  6201. string stationCode, string stationName, out bool ProgressState)
  6202. {
  6203. Stopwatch stopwatch1 = new Stopwatch();
  6204. Stopwatch stopwatch2 = new Stopwatch();
  6205. try
  6206. {
  6207. stopwatch1.Start();
  6208. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  6209. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6210. string processItem = stationName; // 测试项目
  6211. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6212. string supplierCode = ""; // 供应商代码
  6213. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6214. string batch_num = GlobalContext.BatchNumber; // 批次号
  6215. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6216. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  6217. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  6218. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  6219. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  6220. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6221. bool pass = a1Result == 1;
  6222. //根据载具码获取产品码
  6223. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  6224. if (string.IsNullOrEmpty(strProductBarcode))
  6225. {
  6226. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  6227. }
  6228. sn = strProductBarcode;
  6229. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  6230. List<TestItem> items = new List<TestItem>();
  6231. items.Add(new TestItem()
  6232. {
  6233. Parameter_name = "载具码",
  6234. Parameter_value = CarrierBarcode,
  6235. Parameter_unit = ""
  6236. });
  6237. items.Add(new TestItem()
  6238. {
  6239. Parameter_name = "产品码",
  6240. Parameter_value = sn,
  6241. Parameter_unit = ""
  6242. });
  6243. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  6244. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6245. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  6246. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  6247. stopwatch2.Start();
  6248. //进站结果写入PLC
  6249. CommandFromPLC resultToPlC = new CommandFromPLC();
  6250. resultToPlC.cmd = 0;
  6251. resultToPlC.cmdParam = 0; //指令参数
  6252. resultToPlC.cmdResult = mesResultFrmWeb;
  6253. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6254. stopwatch2.Stop();
  6255. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  6256. //保存PLC返回MES数据到本地
  6257. ResponseMessage message = new ResponseMessage();
  6258. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  6259. stPLC_MesData.mesData.nRemainCount);
  6260. if (message.result == false)
  6261. {
  6262. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  6263. }
  6264. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  6265. if (result1 == 1)
  6266. {
  6267. //载具码解除绑定
  6268. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  6269. if (message.result == false)
  6270. {
  6271. AddMessage(LogType.Error, message.text);
  6272. }
  6273. }
  6274. }
  6275. catch (Exception ex)
  6276. {
  6277. stopwatch2.Start();
  6278. CommandFromPLC resultToPlC = new CommandFromPLC();
  6279. resultToPlC.cmd = 0;
  6280. resultToPlC.cmdParam = 0; //指令参数
  6281. resultToPlC.cmdResult = 110;
  6282. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6283. stopwatch2.Stop();
  6284. string str = ex.StackTrace;
  6285. AddMessage(LogType.Error,
  6286. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  6287. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6288. }
  6289. stopwatch1.Stop();
  6290. AddMessage(LogType.Info,
  6291. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6292. stopwatch2.ElapsedMilliseconds + "ms");
  6293. ProgressState = false;
  6294. }
  6295. private void S9节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  6296. {
  6297. Stopwatch stopwatch1 = new Stopwatch();
  6298. Stopwatch stopwatch2 = new Stopwatch();
  6299. string resultStr = string.Empty;
  6300. try
  6301. {
  6302. stopwatch1.Start();
  6303. string oEEType = ((int)s1PLCData["a9OEEType"]).ToString(); // 节拍类型(plc写入)
  6304. string a90EEPartNo = (string)s1PLCData["a90EEPartNo"]; // 物料码
  6305. a90EEPartNo = a90EEPartNo.Replace("\0", "");
  6306. string a90EEVehicleCode = (string)s1PLCData["a90EEVehicleCode"]; // 载具SN
  6307. a90EEVehicleCode = a90EEVehicleCode.Replace("\0", "");
  6308. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6309. if (!actionBool)
  6310. {
  6311. stopwatch2.Start();
  6312. //写入PLC
  6313. iot_data.beatReturn = 2; //NG
  6314. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6315. stopwatch2.Stop();
  6316. AddMessage(LogType.Info,
  6317. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  6318. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6319. return;
  6320. }
  6321. //作业开始后要有物料和载具信息
  6322. if (string.IsNullOrEmpty(a90EEPartNo) && string.IsNullOrEmpty(a90EEVehicleCode) &&
  6323. Convert.ToInt32(oEEType) > 2)
  6324. {
  6325. stopwatch2.Start();
  6326. //写入PLC
  6327. iot_data.beatReturn = 2; //NG
  6328. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6329. stopwatch2.Stop();
  6330. AddMessage_Station(stationNameStr, LogType.Info,
  6331. stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  6332. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6333. return;
  6334. }
  6335. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a90EEPartNo))
  6336. {
  6337. stopwatch2.Start();
  6338. //写入PLC
  6339. iot_data.beatReturn = 2; //NG
  6340. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6341. stopwatch2.Stop();
  6342. AddMessage_Station(stationNameStr, LogType.Info,
  6343. stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  6344. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6345. return;
  6346. }
  6347. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a90EEVehicleCode))
  6348. {
  6349. stopwatch2.Start();
  6350. //写入PLC
  6351. iot_data.beatReturn = 2; //NG
  6352. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6353. stopwatch2.Stop();
  6354. AddMessage_Station(stationNameStr, LogType.Info,
  6355. stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  6356. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6357. return;
  6358. }
  6359. short _result = 0;
  6360. // 上传OEE
  6361. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a90EEPartNo, a90EEVehicleCode);
  6362. _result = result.Item1;
  6363. resultStr = result.Item2;
  6364. if (_result == 1)
  6365. {
  6366. stopwatch2.Start();
  6367. //写入PLC
  6368. iot_data.beatReturn = 1; //OK
  6369. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6370. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  6371. stopwatch2.Stop();
  6372. }
  6373. else
  6374. {
  6375. stopwatch2.Start();
  6376. //写入PLC
  6377. iot_data.beatReturn = 2; //NG
  6378. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6379. stopwatch2.Stop();
  6380. AddMessage_Station(stationNameStr, LogType.Error,
  6381. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  6382. }
  6383. }
  6384. catch (Exception ex)
  6385. {
  6386. string str = ex.StackTrace;
  6387. AddMessage_Station(stationNameStr, LogType.Error,
  6388. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  6389. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6390. // MES_Flag
  6391. stopwatch2.Start();
  6392. //写入PLC
  6393. iot_data.beatReturn = 2; //NG
  6394. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6395. stopwatch2.Stop();
  6396. }
  6397. stopwatch1.Stop();
  6398. AddMessage(LogType.Info,
  6399. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6400. stopwatch2.ElapsedMilliseconds + "ms");
  6401. }
  6402. #endregion
  6403. #endregion Xiaomi
  6404. #region PLC1 张超凡
  6405. #region [S1] Tray盘上料装备(板测)
  6406. /// <summary>
  6407. /// S1工位的数据- 触发信号上次的值
  6408. /// </summary>
  6409. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  6410. /// <summary>
  6411. /// S1工位的数据(含触发信号)
  6412. /// </summary>
  6413. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  6414. /// <summary>
  6415. /// S1工位的数据- 回写点位
  6416. /// </summary>
  6417. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6418. ///// <summary>
  6419. ///// 触发信号
  6420. ///// </summary>
  6421. //private ManualResetEvent[] MreTasks;
  6422. /// <summary>
  6423. /// [S1] Tray盘上料装备(板测)
  6424. /// </summary>
  6425. /// <param name="plcNo">PLC编号</param>
  6426. //private void ReadStation_S1(int plcNo)
  6427. //{
  6428. // // [S1] Tray盘上料装备
  6429. // // [S2] FCT
  6430. // // [S3] 值板机
  6431. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6432. // // [S5] Tray盘下料装备
  6433. // string stationCode = "[S1]";
  6434. // string stationName = "Tray盘上料装备";
  6435. // string stationNameStr = stationCode + stationName;
  6436. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6437. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6438. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  6439. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  6440. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6441. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  6442. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6443. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  6444. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  6445. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  6446. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  6447. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6448. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  6449. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  6450. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  6451. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  6452. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  6453. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  6454. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6455. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  6456. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  6457. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  6458. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  6459. // s1PLCData.Add("a1Result", 0); // 产品结果
  6460. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  6461. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  6462. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  6463. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  6464. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  6465. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6466. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  6467. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  6468. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  6469. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  6470. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  6471. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  6472. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  6473. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  6474. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  6475. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  6476. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  6477. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6478. // while (IsRun)
  6479. // {
  6480. // try
  6481. // {
  6482. // if (!GlobalContext._IsCon_Funs1)
  6483. // {
  6484. // UpdatePLCMonitor(1, plcNo, 0);
  6485. // continue;
  6486. // }
  6487. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6488. // {
  6489. // Stopwatch stopwatch1 = new Stopwatch();
  6490. // Stopwatch stopwatch2 = new Stopwatch();
  6491. // stopwatch1.Start();
  6492. // stopwatch2.Start();
  6493. // #region 一次性读取所有数据
  6494. // // 一次性读取所有数据
  6495. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6496. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6497. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6498. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  6499. // int[] datas = data1.Concat(data2).ToArray();
  6500. // datas = datas.Concat(data3).ToArray();
  6501. // datas = datas.Concat(data4).ToArray();
  6502. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  6503. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  6504. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  6505. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  6506. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  6507. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  6508. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  6509. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  6510. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  6511. // s1PLCData["a1MES_FLAG"] = datas[109];
  6512. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  6513. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  6514. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  6515. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  6516. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  6517. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  6518. // s1PLCData["a1Result"] = datas[170];
  6519. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  6520. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  6521. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  6522. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  6523. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  6524. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  6525. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  6526. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  6527. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  6528. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  6529. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  6530. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  6531. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  6532. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  6533. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  6534. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  6535. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  6536. // s1PLCData["a1AGVUpStart"] = datas[308];
  6537. // s1PLCData["a1AGVUpEnd"] = datas[309];
  6538. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  6539. // s1PLCData["a1AGVDownStart"] = datas[321];
  6540. // s1PLCData["a1AGVDownEnd"] = datas[322];
  6541. // #endregion 一次性读取所有数据
  6542. // stopwatch2.Stop();
  6543. // #region 回写操作,写后清空flag
  6544. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  6545. // #endregion 回写操作,写后清空flag
  6546. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  6547. // try
  6548. // {
  6549. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  6550. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  6551. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  6552. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  6553. // {
  6554. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  6555. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  6556. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  6557. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  6558. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  6559. // }
  6560. // }
  6561. // catch (Exception ex)
  6562. // {
  6563. // // 6代表上位机报警
  6564. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  6565. // string str = ex.StackTrace;
  6566. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6567. // }
  6568. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  6569. // #region 上料进站校验
  6570. // try
  6571. // {
  6572. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  6573. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  6574. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  6575. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  6576. // {
  6577. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  6578. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  6579. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  6580. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  6581. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  6582. // }
  6583. // }
  6584. // catch (Exception ex)
  6585. // {
  6586. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  6587. // string str = ex.StackTrace;
  6588. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6589. // }
  6590. // #endregion 上料进站校验
  6591. // #region Tray盘上料装备-出站接口
  6592. // try
  6593. // {
  6594. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  6595. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  6596. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  6597. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  6598. // {
  6599. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  6600. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6601. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  6602. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  6603. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  6604. // }
  6605. // }
  6606. // catch (Exception ex)
  6607. // {
  6608. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  6609. // string str = ex.StackTrace;
  6610. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6611. // }
  6612. // #endregion Tray盘上料装备-出站接口
  6613. // #region Tray盘上料装备-将SN发给ICT标机
  6614. // try
  6615. // {
  6616. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  6617. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  6618. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  6619. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  6620. // {
  6621. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  6622. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  6623. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  6624. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  6625. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  6626. // }
  6627. // }
  6628. // catch (Exception ex)
  6629. // {
  6630. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  6631. // string str = ex.StackTrace;
  6632. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6633. // }
  6634. // #endregion Tray盘上料装备-将SN发给ICT标机
  6635. // #region Tray盘上料装备-点检数据
  6636. // //try
  6637. // //{
  6638. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  6639. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  6640. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  6641. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  6642. // // if (pLC_Flag && !mES_Flag) // 1 0
  6643. // // {
  6644. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  6645. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  6646. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  6647. // // }
  6648. // // else if (!pLC_Flag && mES_Flag) // 0 1
  6649. // // {
  6650. // // // 清空写给PLC的数据
  6651. // // // MES_Flag重置为0
  6652. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  6653. // // }
  6654. // //}
  6655. // //catch (Exception ex)
  6656. // //{
  6657. // // // MES_Flag 为2上位机报错
  6658. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  6659. // // string str = ex.StackTrace;
  6660. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6661. // //}
  6662. // #endregion Tray盘上料装备-点检数据
  6663. // #region 节拍接口
  6664. // try
  6665. // {
  6666. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  6667. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  6668. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  6669. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  6670. // {
  6671. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  6672. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6673. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  6674. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  6675. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  6676. // }
  6677. // }
  6678. // catch (Exception ex)
  6679. // {
  6680. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  6681. // string str = ex.StackTrace;
  6682. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6683. // }
  6684. // #endregion 节拍接口
  6685. // #region AGV上料
  6686. // // AGV上料叫AGV信号
  6687. // try
  6688. // {
  6689. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  6690. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  6691. // if (a1AGVUpCall != a1AGVUpCallOld)
  6692. // {
  6693. // if (a1AGVUpCall == 1) // 0->1
  6694. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  6695. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  6696. // }
  6697. // }
  6698. // catch (Exception ex)
  6699. // {
  6700. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  6701. // string str = ex.StackTrace;
  6702. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6703. // }
  6704. // // AGV上料完成信号
  6705. // try
  6706. // {
  6707. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  6708. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  6709. // if (a1AGVUpEnd != a1AGVUpEndOld)
  6710. // {
  6711. // if (a1AGVUpEnd == 1) // 0->1
  6712. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  6713. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  6714. // }
  6715. // }
  6716. // catch (Exception ex)
  6717. // {
  6718. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  6719. // string str = ex.StackTrace;
  6720. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6721. // }
  6722. // #endregion AGV上料
  6723. // #region AGV下料
  6724. // // AGV下料叫agv信号
  6725. // try
  6726. // {
  6727. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  6728. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  6729. // if (a1AGVDownCall != a1AGVDownCallOld)
  6730. // {
  6731. // if (a1AGVDownCall == 1) // 0->1
  6732. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  6733. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  6734. // }
  6735. // }
  6736. // catch (Exception ex)
  6737. // {
  6738. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  6739. // string str = ex.StackTrace;
  6740. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6741. // }
  6742. // // AGV下料完成信号
  6743. // try
  6744. // {
  6745. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  6746. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  6747. // if (a1AGVDownEnd != a1AGVDownEndOld)
  6748. // {
  6749. // if (a1AGVDownEnd == 1) // 0->1
  6750. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  6751. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  6752. // }
  6753. // }
  6754. // catch (Exception ex)
  6755. // {
  6756. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  6757. // string str = ex.StackTrace;
  6758. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6759. // }
  6760. // #endregion AGV下料
  6761. // #region 心跳
  6762. // try
  6763. // {
  6764. // short states = 0;
  6765. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  6766. // }
  6767. // catch (Exception ex)
  6768. // {
  6769. // string str = ex.StackTrace;
  6770. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6771. // }
  6772. // #endregion 心跳
  6773. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6774. // stopwatch1.Stop();
  6775. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  6776. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6777. // }
  6778. // else
  6779. // {
  6780. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6781. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6782. // Funs[plcNo].Connect(); // 重连
  6783. // }
  6784. // }
  6785. // catch (Exception ex)
  6786. // {
  6787. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6788. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6789. // Funs[plcNo].ReConnect();
  6790. // }
  6791. // Thread.Sleep(IntervalReadPLC);
  6792. // }
  6793. //}
  6794. /// <summary>
  6795. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  6796. /// </summary>
  6797. /// <param name="plcNo">PLC编号</param>
  6798. /// <param name="stationNameStr">工站全称</param>
  6799. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  6800. {
  6801. Stopwatch stopwatch1 = new Stopwatch();
  6802. Stopwatch stopwatch2 = new Stopwatch();
  6803. try
  6804. {
  6805. stopwatch1.Start();
  6806. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  6807. sn = sn.Replace("\0", "");
  6808. #region 查询载具上的产品信息
  6809. string cavityData = string.Empty;
  6810. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6811. if (string.IsNullOrEmpty(cavityData))
  6812. cavityData = "";
  6813. if (snResult != 0)
  6814. {
  6815. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6816. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  6817. writeToPLC_Flag1.Adress = 2003;
  6818. writeToPLC_Flag1.Value = (short)6;
  6819. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  6820. stopwatch1.Stop();
  6821. AddMessage(LogType.Info,
  6822. stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  6823. "ms");
  6824. return;
  6825. }
  6826. #endregion 查询载具上的产品信息
  6827. string[] cavitySNs = cavityData.Split('.');
  6828. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  6829. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  6830. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  6831. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  6832. if (cavitySNs != null && cavitySNs.Length >= 2)
  6833. {
  6834. a1CavitySN1_VehicleStates = cavitySNs[0];
  6835. a1CavitySN2_VehicleStates = cavitySNs[1];
  6836. a1CavityResult1_VehicleStates = 2;
  6837. a1CavityResult2_VehicleStates = 2;
  6838. }
  6839. if (a1CavitySN1_VehicleStates == "假产品")
  6840. a1CavityResult1_VehicleStates = 3;
  6841. if (a1CavitySN2_VehicleStates == "假产品")
  6842. a1CavityResult2_VehicleStates = 3;
  6843. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6844. // 回写
  6845. stopwatch2.Start();
  6846. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  6847. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  6848. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  6849. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  6850. //// MES_Flag
  6851. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  6852. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6853. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  6854. writeToPLC_Flag.Adress = 2003;
  6855. writeToPLC_Flag.Value = mES_Flag;
  6856. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  6857. {
  6858. Name = "a1CavitySN1_VehicleStates",
  6859. Adress = 2024,
  6860. ValueType = PLCValueType.String,
  6861. ValueTypeStrLength = 20,
  6862. Value = a1CavitySN1_VehicleStates
  6863. });
  6864. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  6865. {
  6866. Name = "a1CavitySN2_VehicleStates",
  6867. Adress = 2044,
  6868. ValueType = PLCValueType.String,
  6869. ValueTypeStrLength = 20,
  6870. Value = a1CavitySN2_VehicleStates
  6871. });
  6872. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  6873. {
  6874. Name = "a1CavityResult1_VehicleStates",
  6875. Adress = 2064,
  6876. ValueType = PLCValueType.Short,
  6877. Value = a1CavityResult1_VehicleStates
  6878. });
  6879. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  6880. {
  6881. Name = "a1CavityResult2_VehicleStates",
  6882. Adress = 2065,
  6883. ValueType = PLCValueType.Short,
  6884. Value = a1CavityResult2_VehicleStates
  6885. });
  6886. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  6887. stopwatch2.Stop();
  6888. }
  6889. catch (Exception ex)
  6890. {
  6891. string str = ex.StackTrace;
  6892. AddMessage_Station(stationNameStr, LogType.Error,
  6893. $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" +
  6894. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6895. // MES_Flag
  6896. stopwatch2.Start();
  6897. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6898. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6899. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  6900. writeToPLC_Flag.Adress = 2003;
  6901. writeToPLC_Flag.Value = (short)6;
  6902. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  6903. stopwatch2.Stop();
  6904. }
  6905. stopwatch1.Stop();
  6906. AddMessage(LogType.Info,
  6907. stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6908. stopwatch2.ElapsedMilliseconds + "ms");
  6909. }
  6910. /// <summary>
  6911. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  6912. /// </summary>
  6913. /// <param name="plcNo">PLC编号</param>
  6914. /// <param name="stationNameStr">工站全称</param>
  6915. private void S1上料进站校验(int plcNo, string stationNameStr)
  6916. {
  6917. Stopwatch stopwatch1 = new Stopwatch();
  6918. Stopwatch stopwatch2 = new Stopwatch();
  6919. try
  6920. {
  6921. stopwatch1.Start();
  6922. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  6923. sn = sn.Replace("\0", "");
  6924. // 保存进站数据+调用进站MES接口
  6925. List<TestItem> item = new List<TestItem>();
  6926. stopwatch2.Start();
  6927. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  6928. item, out string errorMsg);
  6929. stopwatch2.Stop();
  6930. short a1MES_FLAG_Check = (short)result;
  6931. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6932. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6933. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  6934. writeToPLC_Flag.Adress = 2077;
  6935. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  6936. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  6937. }
  6938. catch (Exception ex)
  6939. {
  6940. string str = ex.StackTrace;
  6941. AddMessage_Station(stationNameStr, LogType.Error,
  6942. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  6943. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6944. // MES_Flag
  6945. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  6946. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6947. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  6948. writeToPLC_Flag.Adress = 2077;
  6949. writeToPLC_Flag.Value = (short)6;
  6950. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  6951. }
  6952. stopwatch1.Stop();
  6953. AddMessage(LogType.Info,
  6954. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  6955. stopwatch2.ElapsedMilliseconds + "ms");
  6956. }
  6957. /// <summary>
  6958. /// [S1] Tray盘上料装备(板测)- 出站接口
  6959. /// </summary>
  6960. /// <param name="plcNo"></param>
  6961. /// <param name="stationCode"></param>
  6962. /// <param name="stationName"></param>
  6963. private void S1出站接口(int plcNo, string stationCode, string stationName)
  6964. {
  6965. Stopwatch stopwatch1 = new Stopwatch();
  6966. Stopwatch stopwatch2 = new Stopwatch();
  6967. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6968. string stationNameStr = stationCode + stationName;
  6969. string processItem = stationName; // 测试项目
  6970. try
  6971. {
  6972. stopwatch1.Start();
  6973. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6974. //string batch_num = GlobalContext.BatchNumber; // 批次号
  6975. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6976. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6977. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  6978. sn = sn.Replace("\0", "");
  6979. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  6980. partNo1 = partNo1.Replace("\0", "");
  6981. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  6982. partNo2 = partNo2.Replace("\0", "");
  6983. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  6984. bool pass = a1Result == 1;
  6985. stopwatch2.Start();
  6986. // 产品1
  6987. List<TestItem> items = new List<TestItem>();
  6988. items.Add(new TestItem()
  6989. {
  6990. Parameter_name = "载具码",
  6991. Parameter_value = sn,
  6992. Parameter_unit = ""
  6993. });
  6994. items.Add(new TestItem()
  6995. {
  6996. Parameter_name = "载具穴号",
  6997. Parameter_value = "1",
  6998. Parameter_unit = ""
  6999. });
  7000. items.Add(new TestItem()
  7001. {
  7002. Parameter_name = "产品结果",
  7003. Parameter_value = a1Result == 1 ? "OK" : "NG",
  7004. Parameter_unit = ""
  7005. });
  7006. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  7007. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  7008. // 产品2
  7009. items = new List<TestItem>();
  7010. items.Add(new TestItem()
  7011. {
  7012. Parameter_name = "载具码",
  7013. Parameter_value = sn,
  7014. Parameter_unit = ""
  7015. });
  7016. items.Add(new TestItem()
  7017. {
  7018. Parameter_name = "载具穴号",
  7019. Parameter_value = "2",
  7020. Parameter_unit = ""
  7021. });
  7022. items.Add(new TestItem()
  7023. {
  7024. Parameter_name = "产品结果",
  7025. Parameter_value = a1Result == 1 ? "OK" : "NG",
  7026. Parameter_unit = ""
  7027. });
  7028. int result2 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  7029. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  7030. short result = 0;
  7031. List<int> results = new List<int>() { result1, result2 };
  7032. if (result1 == 1 && result2 == 1)
  7033. result = 1;
  7034. else if (results.Contains(3))
  7035. result = 3;
  7036. else if (results.Contains(2))
  7037. result = 2;
  7038. else if (results.Contains(4))
  7039. result = 4;
  7040. else
  7041. result = 4;
  7042. stopwatch2.Stop();
  7043. #region 存储绑定数据到 边线MES系统中
  7044. if (result == 1)
  7045. {
  7046. string data = string.Concat(partNo1, ".", partNo2);
  7047. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7048. if (resultMesR != 0)
  7049. {
  7050. result = 4;
  7051. AddMessage_Station(stationNameStr, LogType.Error,
  7052. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  7053. }
  7054. }
  7055. #endregion 存储绑定数据到 边线MES系统中
  7056. // MES_Flag 为MES报错
  7057. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7058. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  7059. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7060. writeToPLC_Flag.Name = "a1MES_FLAG";
  7061. writeToPLC_Flag.Adress = 2109;
  7062. writeToPLC_Flag.Value = result;
  7063. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  7064. OnMessage(LogType.Debug,
  7065. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7066. }
  7067. catch (Exception ex)
  7068. {
  7069. stopwatch2.Restart();
  7070. // MES_Flag 为4上位机报错
  7071. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  7072. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7073. writeToPLC_Flag.Name = "a1MES_FLAG";
  7074. writeToPLC_Flag.Adress = 2109;
  7075. writeToPLC_Flag.Value = (short)4;
  7076. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  7077. stopwatch2.Stop();
  7078. string str = ex.StackTrace;
  7079. AddMessage_Station(stationNameStr, LogType.Error,
  7080. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  7081. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7082. }
  7083. stopwatch1.Stop();
  7084. AddMessage(LogType.Info,
  7085. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  7086. stopwatch2.ElapsedMilliseconds + "ms");
  7087. }
  7088. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  7089. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  7090. //{
  7091. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7092. // string stationNameStr = stationCode + stationName;
  7093. // string processItem = stationName; // 测试项目
  7094. // try
  7095. // {
  7096. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7097. // string accno = "1"; // 工序编号
  7098. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  7099. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  7100. // List<OneCheckItem> items = new List<OneCheckItem>()
  7101. // {
  7102. // new OneCheckItem()
  7103. // {
  7104. // Onecheck_name="胶圈装配行程设定上限",
  7105. // Onecheck_content="上限值",
  7106. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  7107. // },
  7108. // };
  7109. // OneCheckData oneCheckData = new OneCheckData()
  7110. // {
  7111. // Line_code = GlobalContext.LineCode,
  7112. // Line_name = GlobalContext.LineName,
  7113. // Equipment_code = equipmentCode,
  7114. // Equipment_name = equipmentCode,
  7115. // Workorder_code = workorder_code,
  7116. // Procedure_code = accno,
  7117. // Procedure_name = processItem,
  7118. // Oneckeck_values = items,
  7119. // Onecheck_empcode = "",
  7120. // Onecheck_empname = "",
  7121. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  7122. // };
  7123. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  7124. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  7125. // short result = result1 == 1 ? (short)1 : (short)2;
  7126. // // MES_Flag 为4MES报错
  7127. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  7128. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7129. // }
  7130. // catch (Exception ex)
  7131. // {
  7132. // // MES_Flag 为2上位机报错
  7133. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  7134. // string str = ex.StackTrace;
  7135. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7136. // }
  7137. //}
  7138. // ReadStation_S1_2 节拍接口+AGV
  7139. /// <summary>
  7140. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  7141. /// </summary>
  7142. /// <param name="plcNo">PLC编号</param>
  7143. /// <param name="stationNameStr">工站全称</param>
  7144. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  7145. {
  7146. Stopwatch stopwatch1 = new Stopwatch();
  7147. Stopwatch stopwatch2 = new Stopwatch();
  7148. try
  7149. {
  7150. stopwatch1.Start();
  7151. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  7152. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  7153. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  7154. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  7155. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  7156. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  7157. // ZS 将SN发给ICT标机(串口)
  7158. short a1MES_FLAG_ICT = 1;
  7159. stopwatch2.Start();
  7160. // MES_Flag
  7161. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  7162. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7163. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  7164. writeToPLC_Flag.Adress = 2182;
  7165. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  7166. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  7167. stopwatch2.Stop();
  7168. }
  7169. catch (Exception ex)
  7170. {
  7171. string str = ex.StackTrace;
  7172. AddMessage_Station(stationNameStr, LogType.Error,
  7173. $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" +
  7174. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7175. stopwatch2.Start();
  7176. // MES_Flag
  7177. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  7178. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7179. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  7180. writeToPLC_Flag.Adress = 2182;
  7181. writeToPLC_Flag.Value = (short)4;
  7182. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  7183. stopwatch2.Stop();
  7184. }
  7185. stopwatch1.Stop();
  7186. AddMessage(LogType.Info,
  7187. stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7188. stopwatch2.ElapsedMilliseconds + "ms");
  7189. }
  7190. /// <summary>
  7191. /// [S1] Tray盘上料装备(板测)- 节拍接口
  7192. /// </summary>
  7193. /// <param name="plcNo">PLC编号</param>
  7194. /// <param name="stationNameStr">工站全称</param>
  7195. private void S1节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  7196. {
  7197. Stopwatch stopwatch1 = new Stopwatch();
  7198. Stopwatch stopwatch2 = new Stopwatch();
  7199. string resultStr = string.Empty;
  7200. try
  7201. {
  7202. stopwatch1.Start();
  7203. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  7204. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  7205. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  7206. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  7207. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  7208. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7209. if (!actionBool)
  7210. {
  7211. stopwatch2.Start();
  7212. //写入PLC
  7213. iot_data.beatReturn = 2; //NG
  7214. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7215. stopwatch2.Stop();
  7216. AddMessage(LogType.Info,
  7217. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  7218. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7219. return;
  7220. }
  7221. //作业开始后要有物料和载具信息
  7222. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode) &&
  7223. Convert.ToInt32(oEEType) > 2)
  7224. {
  7225. stopwatch2.Start();
  7226. //写入PLC
  7227. iot_data.beatReturn = 2; //NG
  7228. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7229. stopwatch2.Stop();
  7230. AddMessage_Station(stationNameStr, LogType.Info,
  7231. stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  7232. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7233. return;
  7234. }
  7235. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a1OEEPartNo))
  7236. {
  7237. stopwatch2.Start();
  7238. //写入PLC
  7239. iot_data.beatReturn = 2; //NG
  7240. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7241. stopwatch2.Stop();
  7242. AddMessage_Station(stationNameStr, LogType.Info,
  7243. stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  7244. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7245. return;
  7246. }
  7247. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a1OEEVehicleCode))
  7248. {
  7249. stopwatch2.Start();
  7250. //写入PLC
  7251. iot_data.beatReturn = 2; //NG
  7252. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7253. stopwatch2.Stop();
  7254. AddMessage_Station(stationNameStr, LogType.Info,
  7255. stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  7256. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7257. return;
  7258. }
  7259. short _result = 0;
  7260. // 上传OEE
  7261. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  7262. _result = result.Item1;
  7263. resultStr = result.Item2;
  7264. if (_result == 1)
  7265. {
  7266. stopwatch2.Start();
  7267. //写入PLC
  7268. iot_data.beatReturn = 1; //OK
  7269. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7270. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  7271. stopwatch2.Stop();
  7272. }
  7273. else {
  7274. stopwatch2.Start();
  7275. //写入PLC
  7276. iot_data.beatReturn = 2; //NG
  7277. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7278. stopwatch2.Stop();
  7279. AddMessage_Station(stationNameStr, LogType.Error,
  7280. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr );
  7281. }
  7282. }
  7283. catch (Exception ex)
  7284. {
  7285. string str = ex.StackTrace;
  7286. AddMessage_Station(stationNameStr, LogType.Error,
  7287. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  7288. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7289. // MES_Flag
  7290. stopwatch2.Start();
  7291. //写入PLC
  7292. iot_data.beatReturn = 2; //NG
  7293. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7294. stopwatch2.Stop();
  7295. }
  7296. stopwatch1.Stop();
  7297. AddMessage(LogType.Info,
  7298. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7299. stopwatch2.ElapsedMilliseconds + "ms");
  7300. }
  7301. /// <summary>
  7302. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  7303. /// </summary>
  7304. /// <param name="plcNo">PLC编号</param>
  7305. /// <param name="stationNameStr">工站全称</param>
  7306. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  7307. {
  7308. Stopwatch stopwatch1 = new Stopwatch();
  7309. Stopwatch stopwatch2 = new Stopwatch();
  7310. try
  7311. {
  7312. stopwatch1.Start();
  7313. // ZS 呼叫AGV
  7314. short a1AGVUpCall = 2;
  7315. stopwatch2.Start();
  7316. // a1AGVUpCall
  7317. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7318. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7319. writeToPLC_Flag.Name = "a1AGVUpCall";
  7320. writeToPLC_Flag.Adress = 2307;
  7321. writeToPLC_Flag.Value = a1AGVUpCall;
  7322. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  7323. stopwatch2.Stop();
  7324. }
  7325. catch (Exception ex)
  7326. {
  7327. string str = ex.StackTrace;
  7328. AddMessage_Station(stationNameStr, LogType.Error,
  7329. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  7330. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7331. // a1AGVUpCall
  7332. stopwatch2.Start();
  7333. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  7334. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7335. writeToPLC_Flag.Name = "a1AGVUpCall";
  7336. writeToPLC_Flag.Adress = 2307;
  7337. writeToPLC_Flag.Value = (short)4;
  7338. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  7339. stopwatch2.Stop();
  7340. }
  7341. stopwatch1.Stop();
  7342. AddMessage(LogType.Info,
  7343. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7344. stopwatch2.ElapsedMilliseconds + "ms");
  7345. }
  7346. /// <summary>
  7347. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  7348. /// </summary>
  7349. /// <param name="plcNo">PLC编号</param>
  7350. /// <param name="stationNameStr">工站全称</param>
  7351. private void S1AGV上料完成(int plcNo, string stationNameStr)
  7352. {
  7353. Stopwatch stopwatch1 = new Stopwatch();
  7354. Stopwatch stopwatch2 = new Stopwatch();
  7355. try
  7356. {
  7357. stopwatch1.Start();
  7358. // ZS AGV上料完成,让小车离开
  7359. short a1AGVUpEnd = 2;
  7360. stopwatch2.Start();
  7361. // a1AGVUpEnd
  7362. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7363. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7364. writeToPLC_Flag.Name = "a1AGVUpEnd";
  7365. writeToPLC_Flag.Adress = 2309;
  7366. writeToPLC_Flag.Value = a1AGVUpEnd;
  7367. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  7368. stopwatch2.Stop();
  7369. }
  7370. catch (Exception ex)
  7371. {
  7372. string str = ex.StackTrace;
  7373. AddMessage_Station(stationNameStr, LogType.Error,
  7374. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  7375. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7376. // a1AGVUpEnd
  7377. stopwatch2.Start();
  7378. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  7379. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7380. writeToPLC_Flag.Name = "a1AGVUpEnd";
  7381. writeToPLC_Flag.Adress = 2309;
  7382. writeToPLC_Flag.Value = (short)4;
  7383. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  7384. stopwatch2.Stop();
  7385. }
  7386. stopwatch1.Stop();
  7387. AddMessage(LogType.Info,
  7388. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7389. stopwatch2.ElapsedMilliseconds + "ms");
  7390. }
  7391. /// <summary>
  7392. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  7393. /// </summary>
  7394. /// <param name="plcNo">PLC编号</param>
  7395. /// <param name="stationNameStr">工站全称</param>
  7396. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  7397. {
  7398. Stopwatch stopwatch1 = new Stopwatch();
  7399. Stopwatch stopwatch2 = new Stopwatch();
  7400. try
  7401. {
  7402. stopwatch1.Start();
  7403. // ZS 呼叫AGV
  7404. short a1AGVDownCall = 2;
  7405. stopwatch2.Start();
  7406. // a1AGVDownCall
  7407. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7408. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7409. writeToPLC_Flag.Name = "a1AGVDownCall";
  7410. writeToPLC_Flag.Adress = 2320;
  7411. writeToPLC_Flag.Value = a1AGVDownCall;
  7412. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  7413. stopwatch2.Stop();
  7414. }
  7415. catch (Exception ex)
  7416. {
  7417. string str = ex.StackTrace;
  7418. AddMessage_Station(stationNameStr, LogType.Error,
  7419. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  7420. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7421. // a1AGVDownCall
  7422. stopwatch2.Start();
  7423. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  7424. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7425. writeToPLC_Flag.Name = "a1AGVDownCall";
  7426. writeToPLC_Flag.Adress = 2320;
  7427. writeToPLC_Flag.Value = (short)4;
  7428. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  7429. stopwatch2.Stop();
  7430. }
  7431. stopwatch1.Stop();
  7432. AddMessage(LogType.Info,
  7433. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7434. stopwatch2.ElapsedMilliseconds + "ms");
  7435. }
  7436. /// <summary>
  7437. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  7438. /// </summary>
  7439. /// <param name="plcNo">PLC编号</param>
  7440. /// <param name="stationNameStr">工站全称</param>
  7441. private void S1AGV下料完成(int plcNo, string stationNameStr)
  7442. {
  7443. Stopwatch stopwatch1 = new Stopwatch();
  7444. Stopwatch stopwatch2 = new Stopwatch();
  7445. try
  7446. {
  7447. stopwatch1.Start();
  7448. // ZS AGV上料完成,让小车离开
  7449. short a1AGVDownEnd = 2;
  7450. stopwatch2.Start();
  7451. // a1AGVDownEnd
  7452. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7453. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7454. writeToPLC_Flag.Name = "a1AGVDownEnd";
  7455. writeToPLC_Flag.Adress = 2322;
  7456. writeToPLC_Flag.Value = a1AGVDownEnd;
  7457. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  7458. stopwatch2.Stop();
  7459. }
  7460. catch (Exception ex)
  7461. {
  7462. string str = ex.StackTrace;
  7463. AddMessage_Station(stationNameStr, LogType.Error,
  7464. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  7465. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7466. // a1AGVDownEnd
  7467. stopwatch2.Start();
  7468. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  7469. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7470. writeToPLC_Flag.Name = "a1AGVDownEnd";
  7471. writeToPLC_Flag.Adress = 2322;
  7472. writeToPLC_Flag.Value = (short)4;
  7473. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  7474. stopwatch2.Stop();
  7475. }
  7476. stopwatch1.Stop();
  7477. AddMessage(LogType.Info,
  7478. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7479. stopwatch2.ElapsedMilliseconds + "ms");
  7480. }
  7481. #endregion [S1] Tray盘上料装备(板测)
  7482. #endregion PLC1 张超凡
  7483. #region PLC2 李晓奇
  7484. #region [S2] FCT(板测)
  7485. /// <summary>
  7486. /// S2工位的数据- 触发信号上次的值
  7487. /// </summary>
  7488. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  7489. /// <summary>
  7490. /// S2工位的数据(含触发信号)
  7491. /// </summary>
  7492. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  7493. /// <summary>
  7494. /// S2工位的数据- 回写点位
  7495. /// </summary>
  7496. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  7497. /// <summary>
  7498. /// [S2] FCT(板测)
  7499. /// </summary>
  7500. /// <param name="plcNo">PLC编号</param>
  7501. //private void ReadStation_S2(int plcNo)
  7502. //{
  7503. // // [S1] Tray盘上料装备
  7504. // // [S2] FCT
  7505. // // [S3] 值板机
  7506. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  7507. // // [S5] Tray盘下料装备
  7508. // /// 上位机心跳
  7509. // /// 获取设备报警数据与状态信息
  7510. // string stationCode = "[S2]";
  7511. // string stationName = "FCT";
  7512. // string stationNameStr = stationCode + stationName;
  7513. // #region 创建字典
  7514. // // 触发信号字典 赋值
  7515. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  7516. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  7517. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  7518. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  7519. // // PLC数据字典 赋值
  7520. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  7521. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  7522. // s2PLCData.Add("b1ProductSN_Check", 0);
  7523. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  7524. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  7525. // s2PLCData.Add("b1ProductSN_Unbind", "");
  7526. // s2PLCData.Add("b1ProductSN_Bind", "");
  7527. // s2PLCData.Add("b1Part1SN_Bind", "");
  7528. // s2PLCData.Add("b1Part2SN_Bind", "");
  7529. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  7530. // s2PLCData.Add("b1MES_FLAG", 0);
  7531. // s2PLCData.Add("b1ProductSN", 0);
  7532. // s2PLCData.Add("b1Part1Result", 0);
  7533. // s2PLCData.Add("b1Part2Result", 0);
  7534. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  7535. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  7536. // s2PLCData.Add("b1OEEProductSN", "");
  7537. // s2PLCData.Add("b1OEEType", 0);
  7538. // #endregion 创建字典
  7539. // while (IsRun)
  7540. // {
  7541. // try
  7542. // {
  7543. // if (!GlobalContext._IsCon_Funs2)
  7544. // {
  7545. // UpdatePLCMonitor(1, plcNo, 0);
  7546. // continue;
  7547. // }
  7548. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  7549. // {
  7550. // Stopwatch stopwatch1 = new Stopwatch();
  7551. // Stopwatch stopwatch2 = new Stopwatch();
  7552. // stopwatch1.Start();
  7553. // stopwatch2.Start();
  7554. // #region 一次性读取所有数据
  7555. // // 一次性读取所有数据
  7556. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  7557. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  7558. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  7559. // int[] datas = data1.Concat(data2).ToArray();
  7560. // datas = datas.Concat(data3).ToArray();
  7561. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  7562. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  7563. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  7564. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  7565. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  7566. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  7567. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  7568. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  7569. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  7570. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  7571. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  7572. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  7573. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  7574. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  7575. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  7576. // s2PLCData["b1MES_FLAG"] = datas[169];
  7577. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  7578. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  7579. // s2PLCData["b1Part1Result"] = datas[190];
  7580. // s2PLCData["b1Part2Result"] = datas[191];
  7581. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  7582. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  7583. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  7584. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  7585. // s2PLCData["b1OEEType"] = datas[224];
  7586. // #endregion 一次性读取所有数据
  7587. // stopwatch2.Stop();
  7588. // #region 回写操作,写后清空flag
  7589. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  7590. // #endregion 回写操作,写后清空flag
  7591. // #region 进站校验
  7592. // try
  7593. // {
  7594. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  7595. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  7596. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  7597. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  7598. // {
  7599. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  7600. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  7601. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  7602. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  7603. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  7604. // }
  7605. // }
  7606. // catch (Exception ex)
  7607. // {
  7608. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7609. // string str = ex.StackTrace;
  7610. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7611. // }
  7612. // #endregion 进站校验
  7613. // #region 二穴载具解绑/绑定(产品换载具)
  7614. // try
  7615. // {
  7616. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  7617. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  7618. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  7619. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  7620. // {
  7621. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  7622. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  7623. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  7624. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  7625. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  7626. // }
  7627. // }
  7628. // catch (Exception ex)
  7629. // {
  7630. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7631. // string str = ex.StackTrace;
  7632. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7633. // }
  7634. // #endregion 二穴载具解绑/绑定(产品换载具)
  7635. // #region FCT-出站接口
  7636. // try
  7637. // {
  7638. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  7639. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  7640. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  7641. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  7642. // {
  7643. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  7644. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  7645. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  7646. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  7647. // }
  7648. // }
  7649. // catch (Exception ex)
  7650. // {
  7651. // // MES_Flag 为6上位机报错
  7652. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  7653. // string str = ex.StackTrace;
  7654. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7655. // }
  7656. // #endregion FCT-出站接口
  7657. // #region 节拍接口
  7658. // try
  7659. // {
  7660. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  7661. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  7662. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  7663. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  7664. // {
  7665. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  7666. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7667. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  7668. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  7669. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  7670. // }
  7671. // }
  7672. // catch (Exception ex)
  7673. // {
  7674. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  7675. // string str = ex.StackTrace;
  7676. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7677. // }
  7678. // #endregion 节拍接口
  7679. // #region 心跳
  7680. // try
  7681. // {
  7682. // short states = 0;
  7683. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7684. // }
  7685. // catch (Exception ex)
  7686. // {
  7687. // string str = ex.StackTrace;
  7688. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7689. // }
  7690. // #endregion 心跳
  7691. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7692. // stopwatch1.Stop();
  7693. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7694. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7695. // }
  7696. // else
  7697. // {
  7698. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7699. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  7700. // Funs[plcNo].Connect();
  7701. // }
  7702. // }
  7703. // catch (Exception ex)
  7704. // {
  7705. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7706. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  7707. // Funs[plcNo].ReConnect();
  7708. // }
  7709. // Thread.Sleep(IntervalReadPLC);
  7710. // }
  7711. //}
  7712. /// <summary>
  7713. /// [S2] FCT(板测)- 进站校验
  7714. /// </summary>
  7715. /// <param name="plcNo">PLC编号</param>
  7716. /// <param name="stationNameStr">工站全称</param>
  7717. private void S2进站校验(int plcNo, string stationNameStr)
  7718. {
  7719. Stopwatch stopwatch1 = new Stopwatch();
  7720. Stopwatch stopwatch2 = new Stopwatch();
  7721. try
  7722. {
  7723. stopwatch1.Start();
  7724. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  7725. sn = sn.Replace("\0", "");
  7726. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  7727. // 查询物料码By载具码 并判断是不是假产品
  7728. string cavityData = string.Empty;
  7729. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  7730. if (string.IsNullOrEmpty(cavityData))
  7731. cavityData = "";
  7732. if (snResult != 0)
  7733. {
  7734. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7735. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  7736. writeToPLC_Flag1.Adress = 2003;
  7737. writeToPLC_Flag1.Value = (short)6;
  7738. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  7739. stopwatch1.Stop();
  7740. AddMessage(LogType.Info,
  7741. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7742. return;
  7743. }
  7744. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  7745. string[] cavitySNs = cavityData.Split('.');
  7746. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  7747. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  7748. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  7749. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  7750. if (cavitySNs != null && cavitySNs.Length >= 2)
  7751. {
  7752. b1Part1SN_Check = cavitySNs[0];
  7753. b1Part2SN_Check = cavitySNs[1];
  7754. b1Part1Result_Check = 2;
  7755. b1Part2Result_Check = 2;
  7756. }
  7757. if (b1Part1SN_Check == "假产品")
  7758. b1Part1Result_Check = 3;
  7759. if (b1Part2SN_Check == "假产品")
  7760. b1Part2Result_Check = 3;
  7761. // 调用MES进站
  7762. stopwatch2.Start();
  7763. // 调用MES进站 - 产品1
  7764. List<TestItem> item;
  7765. int result1 = b1Part1Result_Check;
  7766. if (result1 != 3)
  7767. {
  7768. item = new List<TestItem>();
  7769. item.Add(new TestItem()
  7770. {
  7771. Parameter_name = "载具码",
  7772. Parameter_value = sn,
  7773. });
  7774. item.Add(new TestItem()
  7775. {
  7776. Parameter_name = "载具穴号",
  7777. Parameter_value = "1",
  7778. });
  7779. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  7780. b1Part1SN_Check, item, out string errorMsg);
  7781. }
  7782. // 调用MES进站 - 产品2
  7783. int result2 = b1Part2Result_Check;
  7784. if (result2 != 3)
  7785. {
  7786. item = new List<TestItem>();
  7787. item.Add(new TestItem()
  7788. {
  7789. Parameter_name = "载具码",
  7790. Parameter_value = sn,
  7791. });
  7792. item.Add(new TestItem()
  7793. {
  7794. Parameter_name = "载具穴号",
  7795. Parameter_value = "2",
  7796. });
  7797. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  7798. b1Part2SN_Check, item, out string errorMsg);
  7799. }
  7800. stopwatch2.Stop();
  7801. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  7802. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  7803. int result = result1;
  7804. if (result == 1)
  7805. result = result2;
  7806. short b1MES_FLAG_Check = (short)result;
  7807. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  7808. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  7809. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  7810. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  7811. //// MES_Flag
  7812. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7813. WriteToPLC_Flag
  7814. writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7815. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  7816. writeToPLC_Flag.Adress = 2003;
  7817. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  7818. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7819. {
  7820. Name = "b1Part1SN_Check",
  7821. Adress = 2024,
  7822. ValueType = PLCValueType.String,
  7823. ValueTypeStrLength = 20,
  7824. Value = b1Part1SN_Check
  7825. });
  7826. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7827. {
  7828. Name = "b1Part2SN_Check",
  7829. Adress = 2044,
  7830. ValueType = PLCValueType.String,
  7831. ValueTypeStrLength = 20,
  7832. Value = b1Part2SN_Check
  7833. });
  7834. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7835. {
  7836. Name = "b1Part1Result_Check",
  7837. Adress = 2064,
  7838. ValueType = PLCValueType.Short,
  7839. Value = b1Part1Result_Check
  7840. });
  7841. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7842. {
  7843. Name = "b1Part2Result_Check",
  7844. Adress = 2065,
  7845. ValueType = PLCValueType.Short,
  7846. Value = b1Part2Result_Check
  7847. });
  7848. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  7849. }
  7850. catch (Exception ex)
  7851. {
  7852. string str = ex.StackTrace;
  7853. AddMessage_Station(stationNameStr, LogType.Error,
  7854. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  7855. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7856. // MES_Flag
  7857. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7858. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7859. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  7860. writeToPLC_Flag.Adress = 2003;
  7861. writeToPLC_Flag.Value = (short)6;
  7862. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  7863. }
  7864. stopwatch1.Stop();
  7865. AddMessage(LogType.Info,
  7866. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  7867. stopwatch2.ElapsedMilliseconds + "ms");
  7868. }
  7869. /// <summary>
  7870. /// [S2] FCT(板测)- 二穴载具解绑绑定
  7871. /// </summary>
  7872. /// <param name="plcNo">PLC编号</param>
  7873. /// <param name="stationNameStr">工站全称</param>
  7874. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  7875. {
  7876. Stopwatch stopwatch1 = new Stopwatch();
  7877. Stopwatch stopwatch2 = new Stopwatch();
  7878. try
  7879. {
  7880. stopwatch1.Start();
  7881. // 产品换载具
  7882. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  7883. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  7884. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  7885. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  7886. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  7887. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  7888. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  7889. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  7890. stopwatch2.Start();
  7891. #region 查询载具上的产品信息
  7892. //string cavityData = string.Empty;
  7893. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  7894. //if (string.IsNullOrEmpty(cavityData))
  7895. // cavityData = "";
  7896. //if (snResult != 0)
  7897. //{
  7898. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7899. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  7900. // writeToPLC_Flag.Adress = 2077;
  7901. // writeToPLC_Flag.Value = (short)6;
  7902. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  7903. // stopwatch1.Stop();
  7904. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7905. // return;
  7906. //}
  7907. #endregion 查询载具上的产品信息
  7908. #region 解绑(边线MES系统)
  7909. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  7910. if (snResult != 0)
  7911. {
  7912. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7913. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  7914. writeToPLC_Flag1.Adress = 2077;
  7915. writeToPLC_Flag1.Value = (short)6;
  7916. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  7917. stopwatch1.Stop();
  7918. AddMessage(LogType.Info,
  7919. stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" +
  7920. stopwatch1.ElapsedMilliseconds + "ms");
  7921. return;
  7922. }
  7923. #endregion 解绑(边线MES系统)
  7924. #region 存储绑定数据到 边线MES系统中
  7925. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  7926. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  7927. if (snResult != 0)
  7928. {
  7929. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7930. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  7931. writeToPLC_Flag1.Adress = 2077;
  7932. writeToPLC_Flag1.Value = (short)6;
  7933. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  7934. stopwatch1.Stop();
  7935. AddMessage(LogType.Info,
  7936. stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" +
  7937. stopwatch1.ElapsedMilliseconds + "ms");
  7938. return;
  7939. }
  7940. #endregion 存储绑定数据到 边线MES系统中
  7941. stopwatch2.Stop();
  7942. short b1MES_FLAG_Unbind = 1;
  7943. // MES_Flag
  7944. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7945. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7946. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  7947. writeToPLC_Flag.Adress = 2077;
  7948. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  7949. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  7950. }
  7951. catch (Exception ex)
  7952. {
  7953. string str = ex.StackTrace;
  7954. AddMessage_Station(stationNameStr, LogType.Error,
  7955. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" +
  7956. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7957. // MES_Flag
  7958. stopwatch2.Start();
  7959. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7960. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7961. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  7962. writeToPLC_Flag.Adress = 2077;
  7963. writeToPLC_Flag.Value = (short)6;
  7964. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  7965. stopwatch2.Stop();
  7966. }
  7967. stopwatch1.Stop();
  7968. AddMessage(LogType.Info,
  7969. stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7970. stopwatch2.ElapsedMilliseconds + "ms");
  7971. }
  7972. //// 上次采集到的SN
  7973. //private string sn_FCT = string.Empty;
  7974. /// <summary>
  7975. /// [S2] FCT(板测)- 出站数据
  7976. /// </summary>
  7977. private void S2出站接口(int plcNo, string stationCode, string stationName)
  7978. {
  7979. Stopwatch stopwatch1 = new Stopwatch();
  7980. Stopwatch stopwatch2 = new Stopwatch();
  7981. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7982. string stationNameStr = stationCode + stationName;
  7983. string processItem = stationName; // 测试项目
  7984. try
  7985. {
  7986. stopwatch1.Start();
  7987. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7988. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7989. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7990. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7991. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  7992. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  7993. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  7994. bool pass1 = b1Part1Result == 1;
  7995. bool pass2 = b1Part2Result == 1;
  7996. #region 根据 载具SN 查 物料SN
  7997. string cavityData = string.Empty;
  7998. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  7999. if (string.IsNullOrEmpty(cavityData))
  8000. cavityData = "";
  8001. if (snResult != 0)
  8002. {
  8003. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8004. writeToPLC_Flag1.Name = "b1MES_FLAG";
  8005. writeToPLC_Flag1.Adress = 2169;
  8006. writeToPLC_Flag1.Value = (short)4;
  8007. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  8008. stopwatch1.Stop();
  8009. AddMessage(LogType.Info,
  8010. stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8011. "ms");
  8012. return;
  8013. }
  8014. #endregion 根据 载具SN 查 物料SN
  8015. string[] cavitySNs = cavityData.Split('.');
  8016. string b1ProductSN1 = string.Empty;
  8017. string b1ProductSN2 = string.Empty;
  8018. if (cavitySNs != null && cavitySNs.Length >= 2)
  8019. {
  8020. b1ProductSN1 = cavitySNs[0];
  8021. b1ProductSN2 = cavitySNs[1];
  8022. }
  8023. stopwatch2.Start();
  8024. // 产品1
  8025. int result1 = 0;
  8026. if (b1ProductSN1 == "假产品")
  8027. result1 = 1;
  8028. else
  8029. {
  8030. List<TestItem> items1 = new List<TestItem>();
  8031. items1.Add(new TestItem()
  8032. {
  8033. Parameter_name = "载具码",
  8034. Parameter_value = b1ProductSN.ToString(),
  8035. Parameter_unit = ""
  8036. });
  8037. items1.Add(new TestItem()
  8038. {
  8039. Parameter_name = "载具穴号",
  8040. Parameter_value = "1",
  8041. Parameter_unit = ""
  8042. });
  8043. items1.Add(new TestItem()
  8044. {
  8045. Parameter_name = "产品结果",
  8046. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  8047. Parameter_unit = ""
  8048. });
  8049. result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  8050. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  8051. }
  8052. // 产品2
  8053. int result2 = 0;
  8054. if (b1ProductSN1 == "假产品")
  8055. result2 = 1;
  8056. else
  8057. {
  8058. List<TestItem> items2 = new List<TestItem>();
  8059. items2.Add(new TestItem()
  8060. {
  8061. Parameter_name = "载具码",
  8062. Parameter_value = b1ProductSN.ToString(),
  8063. Parameter_unit = ""
  8064. });
  8065. items2.Add(new TestItem()
  8066. {
  8067. Parameter_name = "载具穴号",
  8068. Parameter_value = "2",
  8069. Parameter_unit = ""
  8070. });
  8071. items2.Add(new TestItem()
  8072. {
  8073. Parameter_name = "产品结果",
  8074. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  8075. Parameter_unit = ""
  8076. });
  8077. result2 = SwitctProcessData_old(stationNameStr, items2, equipmentCode, processItem
  8078. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  8079. }
  8080. short result = 0;
  8081. List<int> results = new List<int>() { result1, result2 };
  8082. if (result1 == 1 && result2 == 1)
  8083. result = 1;
  8084. else if (results.Contains(3))
  8085. result = 3;
  8086. else if (results.Contains(2))
  8087. result = 2;
  8088. else if (results.Contains(4))
  8089. result = 4;
  8090. else
  8091. result = 4;
  8092. stopwatch2.Stop();
  8093. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8094. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8095. writeToPLC_Flag.Name = "b1MES_FLAG";
  8096. writeToPLC_Flag.Adress = 2169;
  8097. writeToPLC_Flag.Value = result;
  8098. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  8099. OnMessage(LogType.Debug,
  8100. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8101. }
  8102. catch (Exception ex)
  8103. {
  8104. stopwatch2.Restart();
  8105. // MES_Flag 为4上位机报错
  8106. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  8107. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8108. writeToPLC_Flag.Name = "b1MES_FLAG";
  8109. writeToPLC_Flag.Adress = 2169;
  8110. writeToPLC_Flag.Value = (short)4;
  8111. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  8112. stopwatch2.Stop();
  8113. string str = ex.StackTrace;
  8114. AddMessage_Station(stationNameStr, LogType.Error,
  8115. $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  8116. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8117. }
  8118. stopwatch1.Stop();
  8119. AddMessage(LogType.Info,
  8120. stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  8121. stopwatch2.ElapsedMilliseconds + "ms");
  8122. }
  8123. /// <summary>
  8124. /// [S2] FCT(板测)- 节拍接口
  8125. /// </summary>
  8126. /// <param name="plcNo">PLC编号</param>
  8127. /// <param name="stationNameStr">工站全称</param>
  8128. private void S2节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  8129. {
  8130. Stopwatch stopwatch1 = new Stopwatch();
  8131. Stopwatch stopwatch2 = new Stopwatch();
  8132. string resultStr = string.Empty;
  8133. try
  8134. {
  8135. stopwatch1.Start();
  8136. string oEEType = ((int)s1PLCData["a2OEEType"]).ToString(); // 节拍类型(plc写入)
  8137. string a2OEEPartNo = (string)s1PLCData["a2OEEPartNo"]; // 物料码
  8138. a2OEEPartNo = a2OEEPartNo.Replace("\0", "");
  8139. string a20EEVehicleCode = (string)s1PLCData["a20EEVehicleCode"]; // 载具SN
  8140. a20EEVehicleCode = a20EEVehicleCode.Replace("\0", "");
  8141. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8142. if (!actionBool)
  8143. {
  8144. stopwatch2.Start();
  8145. //写入PLC
  8146. iot_data.beatReturn = 2; //NG
  8147. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8148. stopwatch2.Stop();
  8149. AddMessage(LogType.Info,
  8150. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  8151. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8152. return;
  8153. }
  8154. //作业开始后要有物料和载具信息
  8155. if (string.IsNullOrEmpty(a2OEEPartNo) && string.IsNullOrEmpty(a20EEVehicleCode) &&
  8156. Convert.ToInt32(oEEType) > 2)
  8157. {
  8158. stopwatch2.Start();
  8159. //写入PLC
  8160. iot_data.beatReturn = 2; //NG
  8161. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8162. stopwatch2.Stop();
  8163. AddMessage_Station(stationNameStr, LogType.Info,
  8164. stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  8165. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8166. return;
  8167. }
  8168. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a2OEEPartNo))
  8169. {
  8170. stopwatch2.Start();
  8171. //写入PLC
  8172. iot_data.beatReturn = 2; //NG
  8173. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8174. stopwatch2.Stop();
  8175. AddMessage_Station(stationNameStr, LogType.Info,
  8176. stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  8177. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8178. return;
  8179. }
  8180. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a20EEVehicleCode))
  8181. {
  8182. stopwatch2.Start();
  8183. //写入PLC
  8184. iot_data.beatReturn = 2; //NG
  8185. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8186. stopwatch2.Stop();
  8187. AddMessage_Station(stationNameStr, LogType.Info,
  8188. stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  8189. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8190. return;
  8191. }
  8192. short _result = 0;
  8193. // 上传OEE
  8194. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a2OEEPartNo, a20EEVehicleCode);
  8195. _result = result.Item1;
  8196. resultStr = result.Item2;
  8197. if (_result == 1)
  8198. {
  8199. stopwatch2.Start();
  8200. //写入PLC
  8201. iot_data.beatReturn = 1; //OK
  8202. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8203. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  8204. stopwatch2.Stop();
  8205. }
  8206. else
  8207. {
  8208. stopwatch2.Start();
  8209. //写入PLC
  8210. iot_data.beatReturn = 2; //NG
  8211. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8212. stopwatch2.Stop();
  8213. AddMessage_Station(stationNameStr, LogType.Error,
  8214. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  8215. }
  8216. }
  8217. catch (Exception ex)
  8218. {
  8219. string str = ex.StackTrace;
  8220. AddMessage_Station(stationNameStr, LogType.Error,
  8221. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  8222. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8223. // MES_Flag
  8224. stopwatch2.Start();
  8225. //写入PLC
  8226. iot_data.beatReturn = 2; //NG
  8227. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8228. stopwatch2.Stop();
  8229. }
  8230. stopwatch1.Stop();
  8231. AddMessage(LogType.Info,
  8232. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8233. stopwatch2.ElapsedMilliseconds + "ms");
  8234. }
  8235. #endregion [S2] FCT(板测)
  8236. #endregion PLC2 李晓奇
  8237. #region PLC3 刘永村
  8238. #region [S3] 值板机
  8239. /// <summary>
  8240. /// S3工位的数据- 触发信号上次的值
  8241. /// </summary>
  8242. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  8243. /// <summary>
  8244. /// S3工位的数据(含触发信号)
  8245. /// </summary>
  8246. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  8247. /// <summary>
  8248. /// S3工位的数据- 回写点位
  8249. /// </summary>
  8250. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8251. /// <summary>
  8252. /// [S3] 值板机
  8253. /// </summary>
  8254. /// <param name="plcNo">PLC编号</param>
  8255. //private void ReadStation_S3(int plcNo)
  8256. //{
  8257. // // [S1] Tray盘上料装备
  8258. // // [S2] FCT
  8259. // // [S3] 值板机
  8260. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8261. // // [S5] Tray盘下料装备
  8262. // /// 上位机心跳
  8263. // /// 获取设备报警数据与状态信息
  8264. // string stationCode = "[S3]";
  8265. // string stationName = "值板机";
  8266. // string stationNameStr = stationCode + stationName;
  8267. // #region 创建字典
  8268. // // 触发信号字典 赋值
  8269. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8270. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  8271. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  8272. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8273. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8274. // // PLC数据字典 赋值
  8275. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8276. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  8277. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8278. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  8279. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  8280. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8281. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8282. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  8283. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  8284. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8285. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  8286. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  8287. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8288. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8289. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  8290. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  8291. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  8292. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8293. // s3PLCData.Add("c1Result", 0); // 产品结果
  8294. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8295. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  8296. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  8297. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  8298. // #endregion 创建字典
  8299. // while (IsRun)
  8300. // {
  8301. // try
  8302. // {
  8303. // if (!GlobalContext._IsCon_Funs3)
  8304. // {
  8305. // UpdatePLCMonitor(1, plcNo, 0);
  8306. // continue;
  8307. // }
  8308. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8309. // {
  8310. // Stopwatch stopwatch1 = new Stopwatch();
  8311. // Stopwatch stopwatch2 = new Stopwatch();
  8312. // stopwatch1.Start();
  8313. // stopwatch2.Start();
  8314. // #region 一次性读取所有数据
  8315. // // 一次性读取所有数据
  8316. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  8317. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8318. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  8319. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  8320. // int[] datas = data1.Concat(data2).ToArray();
  8321. // datas = datas.Concat(data3).ToArray();
  8322. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  8323. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  8324. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8325. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  8326. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  8327. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  8328. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8329. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  8330. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  8331. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  8332. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  8333. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8334. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  8335. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  8336. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  8337. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  8338. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8339. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  8340. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  8341. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  8342. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  8343. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  8344. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  8345. // #endregion 一次性读取所有数据
  8346. // stopwatch2.Stop();
  8347. // #region 回写操作,写后清空flag
  8348. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  8349. // #endregion 回写操作,写后清空flag
  8350. // #region S3进站校验
  8351. // try
  8352. // {
  8353. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  8354. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  8355. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  8356. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  8357. // {
  8358. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  8359. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8360. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  8361. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8362. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  8363. // }
  8364. // }
  8365. // catch (Exception ex)
  8366. // {
  8367. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8368. // string str = ex.StackTrace;
  8369. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8370. // }
  8371. // #endregion S3进站校验
  8372. // #region S3二穴载具解绑
  8373. // try
  8374. // {
  8375. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  8376. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  8377. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  8378. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  8379. // {
  8380. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  8381. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  8382. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  8383. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  8384. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  8385. // }
  8386. // }
  8387. // catch (Exception ex)
  8388. // {
  8389. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  8390. // string str = ex.StackTrace;
  8391. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8392. // }
  8393. // #endregion S3二穴载具解绑
  8394. // #region S3二穴载具绑定
  8395. // try
  8396. // {
  8397. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  8398. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  8399. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  8400. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  8401. // {
  8402. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  8403. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  8404. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  8405. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  8406. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  8407. // }
  8408. // }
  8409. // catch (Exception ex)
  8410. // {
  8411. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  8412. // string str = ex.StackTrace;
  8413. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8414. // }
  8415. // #endregion S3二穴载具绑定
  8416. // #region S3出站接口(+一穴载具绑定)
  8417. // try
  8418. // {
  8419. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  8420. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  8421. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  8422. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  8423. // {
  8424. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  8425. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8426. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  8427. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  8428. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  8429. // }
  8430. // }
  8431. // catch (Exception ex)
  8432. // {
  8433. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  8434. // string str = ex.StackTrace;
  8435. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8436. // }
  8437. // #endregion S3出站接口(+一穴载具绑定)
  8438. // #region S3节拍接口
  8439. // try
  8440. // {
  8441. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  8442. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  8443. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  8444. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  8445. // {
  8446. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  8447. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8448. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  8449. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  8450. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  8451. // }
  8452. // }
  8453. // catch (Exception ex)
  8454. // {
  8455. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  8456. // string str = ex.StackTrace;
  8457. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8458. // }
  8459. // #endregion S3节拍接口
  8460. // #region 心跳
  8461. // try
  8462. // {
  8463. // short states = 0;
  8464. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  8465. // }
  8466. // catch (Exception ex)
  8467. // {
  8468. // string str = ex.StackTrace;
  8469. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8470. // }
  8471. // #endregion 心跳
  8472. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  8473. // stopwatch1.Stop();
  8474. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  8475. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  8476. // }
  8477. // else
  8478. // {
  8479. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8480. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  8481. // Funs[plcNo].Connect();
  8482. // }
  8483. // }
  8484. // catch (Exception ex)
  8485. // {
  8486. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8487. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  8488. // Funs[plcNo].ReConnect();
  8489. // }
  8490. // Thread.Sleep(IntervalReadPLC);
  8491. // }
  8492. //}
  8493. /// <summary>
  8494. /// [S3] 值板机- 进站校验
  8495. /// </summary>
  8496. /// <param name="plcNo">PLC编号</param>
  8497. /// <param name="stationNameStr">工站全称</param>
  8498. private void S3进站校验(int plcNo, string stationNameStr)
  8499. {
  8500. Stopwatch stopwatch1 = new Stopwatch();
  8501. Stopwatch stopwatch2 = new Stopwatch();
  8502. try
  8503. {
  8504. stopwatch1.Start();
  8505. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  8506. sn = sn.Replace("\0", "");
  8507. #region 查询载具上的产品信息
  8508. string cavityData = string.Empty;
  8509. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  8510. if (string.IsNullOrEmpty(cavityData))
  8511. cavityData = "";
  8512. if (snResult != 0)
  8513. {
  8514. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8515. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  8516. writeToPLC_Flag1.Adress = 2003;
  8517. writeToPLC_Flag1.Value = (short)6;
  8518. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  8519. stopwatch1.Stop();
  8520. AddMessage(LogType.Info,
  8521. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8522. return;
  8523. }
  8524. #endregion 查询载具上的产品信息
  8525. string[] cavitySNs = cavityData.Split('.');
  8526. string part1Str = ""; // 产品1的SN码
  8527. string part2Str = ""; // 产品2的SN码
  8528. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  8529. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  8530. if (cavitySNs != null && cavitySNs.Length >= 2)
  8531. {
  8532. part1Str = cavitySNs[0];
  8533. part2Str = cavitySNs[1];
  8534. c1Part1Result_Check = 2;
  8535. c1Part2Result_Check = 2;
  8536. }
  8537. if (part1Str == "假产品")
  8538. c1Part1Result_Check = 3;
  8539. if (part2Str == "假产品")
  8540. c1Part2Result_Check = 3;
  8541. // 调用MES进站
  8542. stopwatch2.Start();
  8543. // 调用MES进站 - 产品1
  8544. List<TestItem> item;
  8545. int result1 = c1Part1Result_Check;
  8546. if (result1 != 3)
  8547. {
  8548. item = new List<TestItem>();
  8549. item.Add(new TestItem()
  8550. {
  8551. Parameter_name = "载具码",
  8552. Parameter_value = sn,
  8553. });
  8554. item.Add(new TestItem()
  8555. {
  8556. Parameter_name = "载具穴号",
  8557. Parameter_value = "1",
  8558. });
  8559. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8560. part1Str, item, out string errorMsg);
  8561. }
  8562. // 调用MES进站 - 产品2
  8563. int result2 = c1Part2Result_Check;
  8564. if (result2 != 3)
  8565. {
  8566. item = new List<TestItem>();
  8567. item.Add(new TestItem()
  8568. {
  8569. Parameter_name = "载具码",
  8570. Parameter_value = sn,
  8571. });
  8572. item.Add(new TestItem()
  8573. {
  8574. Parameter_name = "载具穴号",
  8575. Parameter_value = "2",
  8576. });
  8577. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8578. part2Str, item, out string errorMsg);
  8579. }
  8580. stopwatch2.Stop();
  8581. if (result1 == 2)
  8582. c1Part1Result_Check = 2;
  8583. if (result2 == 2)
  8584. c1Part2Result_Check = 2;
  8585. int result = result1;
  8586. if (result == 1)
  8587. result = result2;
  8588. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  8589. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  8590. short c1MES_FLAG_Check = (short)result;
  8591. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  8592. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  8593. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  8594. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  8595. //// MES_Flag
  8596. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8597. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8598. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  8599. writeToPLC_Flag.Adress = 2003;
  8600. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  8601. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8602. {
  8603. Name = "c1Part1Result_Check",
  8604. Adress = 2024,
  8605. ValueType = PLCValueType.Short,
  8606. Value = c1Part1Result_Check
  8607. });
  8608. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8609. {
  8610. Name = "c1Part2Result_Check",
  8611. Adress = 2025,
  8612. ValueType = PLCValueType.Short,
  8613. Value = c1Part2Result_Check
  8614. });
  8615. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8616. {
  8617. Name = "c1Part1Num_Check",
  8618. Adress = 2026,
  8619. ValueType = PLCValueType.Short,
  8620. Value = c1Part1Num_Check
  8621. });
  8622. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8623. {
  8624. Name = "c1Part2Num_Check",
  8625. Adress = 2027,
  8626. ValueType = PLCValueType.Short,
  8627. Value = c1Part2Num_Check
  8628. });
  8629. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  8630. }
  8631. catch (Exception ex)
  8632. {
  8633. string str = ex.StackTrace;
  8634. AddMessage_Station(stationNameStr, LogType.Error,
  8635. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  8636. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8637. // MES_Flag
  8638. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8639. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8640. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  8641. writeToPLC_Flag.Adress = 2003;
  8642. writeToPLC_Flag.Value = (short)6;
  8643. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  8644. }
  8645. stopwatch1.Stop();
  8646. AddMessage(LogType.Info,
  8647. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  8648. stopwatch2.ElapsedMilliseconds + "ms");
  8649. }
  8650. /// <summary>
  8651. /// [S3] 值板机 - 二穴载具解绑
  8652. /// </summary>
  8653. /// <param name="plcNo">PLC编号</param>
  8654. /// <param name="stationNameStr">工站全称</param>
  8655. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  8656. {
  8657. Stopwatch stopwatch1 = new Stopwatch();
  8658. Stopwatch stopwatch2 = new Stopwatch();
  8659. try
  8660. {
  8661. stopwatch1.Start();
  8662. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  8663. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8664. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8665. // 解绑
  8666. #region 查询载具上的产品信息
  8667. string cavityData = string.Empty;
  8668. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8669. if (string.IsNullOrEmpty(cavityData))
  8670. cavityData = "";
  8671. if (snResult != 0)
  8672. {
  8673. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8674. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  8675. writeToPLC_Flag1.Adress = 2082;
  8676. writeToPLC_Flag1.Value = (short)6;
  8677. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  8678. stopwatch1.Stop();
  8679. AddMessage(LogType.Info,
  8680. stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8681. "ms");
  8682. return;
  8683. }
  8684. #endregion 查询载具上的产品信息
  8685. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  8686. #region 解绑
  8687. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  8688. {
  8689. // 删除
  8690. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8691. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  8692. }
  8693. else
  8694. {
  8695. string data_new = string.Join(".", cavitySNs);
  8696. // 删除再插入
  8697. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8698. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  8699. OnMessage(LogType.Debug,
  8700. $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  8701. }
  8702. #endregion 解绑
  8703. short c1MES_FLAG_Unbind = 1;
  8704. stopwatch2.Start();
  8705. // MES_Flag
  8706. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8707. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8708. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  8709. writeToPLC_Flag.Adress = 2082;
  8710. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  8711. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  8712. stopwatch2.Stop();
  8713. }
  8714. catch (Exception ex)
  8715. {
  8716. string str = ex.StackTrace;
  8717. AddMessage_Station(stationNameStr, LogType.Error,
  8718. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" +
  8719. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8720. // MES_Flag
  8721. stopwatch2.Start();
  8722. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  8723. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8724. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  8725. writeToPLC_Flag.Adress = 2082;
  8726. writeToPLC_Flag.Value = (short)6;
  8727. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  8728. stopwatch2.Stop();
  8729. }
  8730. stopwatch1.Stop();
  8731. AddMessage(LogType.Info,
  8732. stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8733. stopwatch2.ElapsedMilliseconds + "ms");
  8734. }
  8735. /// <summary>
  8736. /// [S3] 值板机 - 二穴载具绑定
  8737. /// </summary>
  8738. /// <param name="plcNo">PLC编号</param>
  8739. /// <param name="stationNameStr">工站全称</param>
  8740. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  8741. {
  8742. Stopwatch stopwatch1 = new Stopwatch();
  8743. Stopwatch stopwatch2 = new Stopwatch();
  8744. try
  8745. {
  8746. stopwatch1.Start();
  8747. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  8748. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8749. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  8750. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  8751. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8752. stopwatch2.Start();
  8753. #region 查询载具上的产品信息
  8754. string cavityData = string.Empty;
  8755. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8756. if (string.IsNullOrEmpty(cavityData))
  8757. cavityData = "";
  8758. if (snResult != 0)
  8759. {
  8760. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8761. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  8762. writeToPLC_Flag1.Adress = 2115;
  8763. writeToPLC_Flag1.Value = (short)6;
  8764. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  8765. stopwatch1.Stop();
  8766. AddMessage(LogType.Info,
  8767. stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8768. "ms");
  8769. return;
  8770. }
  8771. #endregion 查询载具上的产品信息
  8772. // 产品换载具
  8773. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  8774. string partSn1 = "";
  8775. string partSn2 = "";
  8776. if (cavitySNs != null && cavitySNs.Length >= 2)
  8777. {
  8778. partSn1 = cavitySNs[0];
  8779. partSn2 = cavitySNs[1];
  8780. }
  8781. string data_new = string.Empty;
  8782. // 是否是两个穴位交换
  8783. if (c1CavityReverse_Bind == 1)
  8784. {
  8785. // 交换
  8786. data_new = string.Concat(partSn2, ".", partSn1);
  8787. }
  8788. else
  8789. {
  8790. // 不交换
  8791. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  8792. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  8793. cavitySNs[c1VehicleCavityFr_Bind] = "";
  8794. data_new = string.Join(".", cavitySNs);
  8795. }
  8796. // 删除再插入
  8797. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8798. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  8799. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  8800. stopwatch2.Stop();
  8801. short c1MES_FLAG_Bind = 1;
  8802. // MES_Flag
  8803. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8804. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8805. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  8806. writeToPLC_Flag.Adress = 2115;
  8807. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  8808. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  8809. }
  8810. catch (Exception ex)
  8811. {
  8812. string str = ex.StackTrace;
  8813. AddMessage_Station(stationNameStr, LogType.Error,
  8814. $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" +
  8815. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8816. // MES_Flag
  8817. stopwatch2.Start();
  8818. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  8819. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8820. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  8821. writeToPLC_Flag.Adress = 2115;
  8822. writeToPLC_Flag.Value = (short)6;
  8823. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  8824. stopwatch2.Stop();
  8825. }
  8826. stopwatch1.Stop();
  8827. AddMessage(LogType.Info,
  8828. stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8829. stopwatch2.ElapsedMilliseconds + "ms");
  8830. }
  8831. //// 上次采集到的SN
  8832. //private string sn_值板机 = string.Empty;
  8833. /// <summary>
  8834. /// [S3] 值板机 - 出站接口
  8835. /// </summary>
  8836. /// <param name="plcNo">PLC编号</param>
  8837. private void S3出站接口(int plcNo, string stationCode, string stationName)
  8838. {
  8839. Stopwatch stopwatch1 = new Stopwatch();
  8840. Stopwatch stopwatch2 = new Stopwatch();
  8841. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8842. string stationNameStr = stationCode + stationName;
  8843. string processItem = stationName; // 测试项目
  8844. try
  8845. {
  8846. stopwatch1.Start();
  8847. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8848. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8849. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8850. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8851. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  8852. sn = sn.Replace("\0", "");
  8853. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  8854. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8855. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8856. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  8857. bool pass = c1Result == 1;
  8858. // 查sn
  8859. #region 查询载具上的产品信息
  8860. string cavityData = string.Empty;
  8861. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8862. if (string.IsNullOrEmpty(cavityData))
  8863. cavityData = "";
  8864. if (snResult != 0)
  8865. {
  8866. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8867. writeToPLC_Flag1.Name = "c1MES_FLAG";
  8868. writeToPLC_Flag1.Adress = 2150;
  8869. writeToPLC_Flag1.Value = (short)4;
  8870. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  8871. stopwatch1.Stop();
  8872. AddMessage(LogType.Info,
  8873. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8874. return;
  8875. }
  8876. #endregion 查询载具上的产品信息
  8877. string[] cavitySNs = cavityData.Split('.');
  8878. string productSN = "";
  8879. if (cavitySNs != null && cavitySNs.Length >= 2)
  8880. {
  8881. productSN = cavitySNs[c1VehicleCavity];
  8882. cavitySNs[c1VehicleCavity] = "";
  8883. }
  8884. stopwatch2.Start();
  8885. List<TestItem> items = new List<TestItem>();
  8886. items.Add(new TestItem()
  8887. {
  8888. Parameter_name = "二穴载具码",
  8889. Parameter_value = c1ProductSN_Check,
  8890. Parameter_unit = ""
  8891. });
  8892. items.Add(new TestItem()
  8893. {
  8894. Parameter_name = "二穴载具穴号",
  8895. Parameter_value = c1VehicleCavity.ToString(),
  8896. Parameter_unit = ""
  8897. });
  8898. items.Add(new TestItem()
  8899. {
  8900. Parameter_name = "一穴载具码",
  8901. Parameter_value = sn,
  8902. Parameter_unit = ""
  8903. });
  8904. items.Add(new TestItem()
  8905. {
  8906. Parameter_name = "一穴载具穴号",
  8907. Parameter_value = "1",
  8908. Parameter_unit = ""
  8909. });
  8910. items.Add(new TestItem()
  8911. {
  8912. Parameter_name = "产品结果",
  8913. Parameter_value = c1Result == 1 ? "OK" : "NG",
  8914. Parameter_unit = ""
  8915. });
  8916. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  8917. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  8918. short result = (short)result1;
  8919. stopwatch2.Stop();
  8920. #region 存储绑定数据到 边线MES系统中
  8921. if (result == 1)
  8922. {
  8923. string data = string.Concat(productSN);
  8924. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  8925. if (resultMesR != 0)
  8926. {
  8927. result = 4;
  8928. AddMessage_Station(stationNameStr, LogType.Error,
  8929. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  8930. }
  8931. }
  8932. #endregion 存储绑定数据到 边线MES系统中
  8933. #region 产品从 来源载具(二穴载具)中删除
  8934. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  8935. {
  8936. // 删除
  8937. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8938. OnMessage(LogType.Debug,
  8939. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  8940. }
  8941. else
  8942. {
  8943. string data_new = string.Join(".", cavitySNs);
  8944. // 删除再插入
  8945. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8946. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  8947. OnMessage(LogType.Debug,
  8948. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  8949. }
  8950. #endregion 产品从 来源载具(二穴载具)中删除
  8951. // MES_Flag 为MES报错
  8952. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8953. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  8954. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8955. writeToPLC_Flag.Name = "c1MES_FLAG";
  8956. writeToPLC_Flag.Adress = 2150;
  8957. writeToPLC_Flag.Value = result;
  8958. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  8959. OnMessage(LogType.Debug,
  8960. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8961. }
  8962. catch (Exception ex)
  8963. {
  8964. stopwatch2.Restart();
  8965. // MES_Flag 为4上位机报错
  8966. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  8967. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8968. writeToPLC_Flag.Name = "c1MES_FLAG";
  8969. writeToPLC_Flag.Adress = 2150;
  8970. writeToPLC_Flag.Value = (short)4;
  8971. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  8972. stopwatch2.Stop();
  8973. string str = ex.StackTrace;
  8974. AddMessage_Station(stationNameStr, LogType.Error,
  8975. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  8976. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8977. }
  8978. stopwatch1.Stop();
  8979. AddMessage(LogType.Info,
  8980. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  8981. stopwatch2.ElapsedMilliseconds + "ms");
  8982. }
  8983. /// <summary>
  8984. /// [S3] 值板机- 节拍接口
  8985. /// </summary>
  8986. /// <param name="plcNo">PLC编号</param>
  8987. /// <param name="stationNameStr">工站全称</param>
  8988. private void S3节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  8989. {
  8990. Stopwatch stopwatch1 = new Stopwatch();
  8991. Stopwatch stopwatch2 = new Stopwatch();
  8992. string resultStr = string.Empty;
  8993. try
  8994. {
  8995. stopwatch1.Start();
  8996. string oEEType = ((int)s1PLCData["a3OEEType"]).ToString(); // 节拍类型(plc写入)
  8997. string a3OEEPartNo = (string)s1PLCData["a3OEEPartNo"]; // 物料码
  8998. a3OEEPartNo = a3OEEPartNo.Replace("\0", "");
  8999. string a3OEEVehicleCode = (string)s1PLCData["a3OEEVehicleCode"]; // 载具SN
  9000. a3OEEVehicleCode = a3OEEVehicleCode.Replace("\0", "");
  9001. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9002. if (!actionBool)
  9003. {
  9004. stopwatch2.Start();
  9005. //写入PLC
  9006. iot_data.beatReturn = 2; //NG
  9007. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9008. stopwatch2.Stop();
  9009. AddMessage(LogType.Info,
  9010. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  9011. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9012. return;
  9013. }
  9014. //作业开始后要有物料和载具信息
  9015. if (string.IsNullOrEmpty(a3OEEPartNo) && string.IsNullOrEmpty(a3OEEVehicleCode) &&
  9016. Convert.ToInt32(oEEType) > 2)
  9017. {
  9018. stopwatch2.Start();
  9019. //写入PLC
  9020. iot_data.beatReturn = 2; //NG
  9021. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9022. stopwatch2.Stop();
  9023. AddMessage_Station(stationNameStr, LogType.Info,
  9024. stationNameStr + $"_[{a3OEEVehicleCode}][{a3OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  9025. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9026. return;
  9027. }
  9028. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a3OEEPartNo))
  9029. {
  9030. stopwatch2.Start();
  9031. //写入PLC
  9032. iot_data.beatReturn = 2; //NG
  9033. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9034. stopwatch2.Stop();
  9035. AddMessage_Station(stationNameStr, LogType.Info,
  9036. stationNameStr + $"_[{a3OEEVehicleCode}][{a3OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  9037. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9038. return;
  9039. }
  9040. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a3OEEVehicleCode))
  9041. {
  9042. stopwatch2.Start();
  9043. //写入PLC
  9044. iot_data.beatReturn = 2; //NG
  9045. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9046. stopwatch2.Stop();
  9047. AddMessage_Station(stationNameStr, LogType.Info,
  9048. stationNameStr + $"_[{a3OEEVehicleCode}][{a3OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  9049. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9050. return;
  9051. }
  9052. short _result = 0;
  9053. // 上传OEE
  9054. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a3OEEPartNo, a3OEEVehicleCode);
  9055. _result = result.Item1;
  9056. resultStr = result.Item2;
  9057. if (_result == 1)
  9058. {
  9059. stopwatch2.Start();
  9060. //写入PLC
  9061. iot_data.beatReturn = 1; //OK
  9062. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9063. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  9064. stopwatch2.Stop();
  9065. }
  9066. else
  9067. {
  9068. stopwatch2.Start();
  9069. //写入PLC
  9070. iot_data.beatReturn = 2; //NG
  9071. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9072. stopwatch2.Stop();
  9073. AddMessage_Station(stationNameStr, LogType.Error,
  9074. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  9075. }
  9076. }
  9077. catch (Exception ex)
  9078. {
  9079. string str = ex.StackTrace;
  9080. AddMessage_Station(stationNameStr, LogType.Error,
  9081. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  9082. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9083. // MES_Flag
  9084. stopwatch2.Start();
  9085. //写入PLC
  9086. iot_data.beatReturn = 2; //NG
  9087. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9088. stopwatch2.Stop();
  9089. }
  9090. stopwatch1.Stop();
  9091. AddMessage(LogType.Info,
  9092. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9093. stopwatch2.ElapsedMilliseconds + "ms");
  9094. }
  9095. #endregion [S3] 值板机
  9096. #endregion PLC3 刘永村
  9097. #region PLC4 刘果段
  9098. #region [S4] 取放桁架
  9099. /// <summary>
  9100. /// S4工位的数据- 触发信号上次的值
  9101. /// </summary>
  9102. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  9103. /// <summary>
  9104. /// S4工位的数据(含触发信号)
  9105. /// </summary>
  9106. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  9107. /// <summary>
  9108. /// S4工位的数据- 回写点位
  9109. /// </summary>
  9110. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  9111. /// <summary>
  9112. /// [S4] 取放桁架
  9113. /// </summary>
  9114. /// <param name="plcNo">PLC编号</param>
  9115. //private void ReadStation_S4(int plcNo)
  9116. //{
  9117. // // [S1] Tray盘上料装备
  9118. // // [S2] FCT
  9119. // // [S3] 值板机
  9120. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  9121. // // [S5] Tray盘下料装备
  9122. // /// 上位机心跳
  9123. // /// 获取设备报警数据与状态信息
  9124. // string stationCode = "[S4_1]";
  9125. // string stationName = "载具下线装备";
  9126. // string stationNameStr = stationCode + stationName;
  9127. // string stationCode2 = "[S4_2]";
  9128. // string stationName2 = "桁架";
  9129. // string stationNameStr2 = stationCode2 + stationName2;
  9130. // string stationCode3 = "[S4_3]";
  9131. // string stationName3 = "提升机1";
  9132. // string stationNameStr3 = stationCode3 + stationName3;
  9133. // string stationCode4 = "[S4_4]";
  9134. // string stationName4 = "提升机2";
  9135. // string stationNameStr4 = stationCode4 + stationName4;
  9136. // string stationCode5 = "[S4_5]";
  9137. // string stationName5 = "载具上线装备";
  9138. // string stationNameStr5 = stationCode5 + stationName5;
  9139. // #region 创建字典
  9140. // // 触发信号字典 赋值
  9141. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9142. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  9143. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  9144. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9145. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  9146. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  9147. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  9148. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9149. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  9150. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  9151. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9152. // // PLC数据字典 赋值
  9153. // // 载具下线装备(弹夹上线)
  9154. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9155. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  9156. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  9157. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  9158. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  9159. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  9160. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  9161. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  9162. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  9163. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  9164. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  9165. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  9166. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  9167. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  9168. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  9169. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  9170. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  9171. // s4PLCData.Add("d1Result", 0); // 产品结果
  9172. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9173. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  9174. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  9175. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  9176. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  9177. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  9178. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  9179. // // 真空标机(提升机)
  9180. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  9181. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  9182. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  9183. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  9184. // s4PLCData.Add("d3Result", 0); // 产品结果
  9185. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  9186. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  9187. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  9188. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  9189. // s4PLCData.Add("d4Result", 0); // 产品结果
  9190. // // 载具上线装备(弹夹下线)
  9191. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9192. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  9193. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  9194. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  9195. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  9196. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  9197. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  9198. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  9199. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  9200. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  9201. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  9202. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  9203. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  9204. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  9205. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  9206. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  9207. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  9208. // s4PLCData.Add("d5Result", 0); // 产品结果
  9209. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9210. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  9211. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  9212. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  9213. // #endregion 创建字典
  9214. // while (IsRun)
  9215. // {
  9216. // try
  9217. // {
  9218. // if (!GlobalContext._IsCon_Funs4)
  9219. // {
  9220. // UpdatePLCMonitor(1, plcNo, 0);
  9221. // continue;
  9222. // }
  9223. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  9224. // {
  9225. // Stopwatch stopwatch1 = new Stopwatch();
  9226. // Stopwatch stopwatch2 = new Stopwatch();
  9227. // stopwatch1.Start();
  9228. // stopwatch2.Start();
  9229. // #region 一次性读取所有数据
  9230. // // 载具下线装备(弹夹上线)
  9231. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  9232. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  9233. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  9234. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  9235. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  9236. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  9237. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  9238. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  9239. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  9240. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  9241. // int[] datas = data1.Concat(data2).ToArray();
  9242. // datas = datas.Concat(data3).ToArray();
  9243. // datas = datas.Concat(data4).ToArray();
  9244. // datas = datas.Concat(data5).ToArray();
  9245. // datas = datas.Concat(data6).ToArray();
  9246. // datas = datas.Concat(data7).ToArray();
  9247. // datas = datas.Concat(data8).ToArray();
  9248. // datas = datas.Concat(data9).ToArray();
  9249. // datas = datas.Concat(data10).ToArray();
  9250. // // 载具下线装备(弹夹上线)
  9251. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  9252. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  9253. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  9254. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  9255. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  9256. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  9257. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  9258. // s4PLCData["d1MES_FLAG"] = datas[65];
  9259. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  9260. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  9261. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  9262. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  9263. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  9264. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  9265. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  9266. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  9267. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  9268. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  9269. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  9270. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  9271. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  9272. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  9273. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  9274. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  9275. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  9276. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  9277. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  9278. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  9279. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  9280. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  9281. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  9282. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  9283. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  9284. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  9285. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  9286. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  9287. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  9288. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  9289. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  9290. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  9291. // s4PLCData["d1Result"] = datas[386];
  9292. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  9293. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  9294. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  9295. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  9296. // s4PLCData["d1OEEType"] = datas[419];
  9297. // // 桁架(查询标机中弹夹的状态)
  9298. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  9299. // s4PLCData["d2BulletclipStates"] = datas[431];
  9300. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  9301. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  9302. // // 真空标机
  9303. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  9304. // s4PLCData["d3MES_FLAG"] = datas[463];
  9305. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  9306. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  9307. // s4PLCData["d3Result"] = datas[484];
  9308. // s4PLCData["d3Type"] = datas[485];
  9309. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  9310. // s4PLCData["d4MES_FLAG"] = datas[496];
  9311. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  9312. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  9313. // s4PLCData["d4Result"] = datas[517];
  9314. // s4PLCData["d4Type"] = datas[518];
  9315. // // 载具上线装备(弹夹下线)
  9316. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  9317. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  9318. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  9319. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  9320. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  9321. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  9322. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  9323. // s4PLCData["d5MES_FLAG"] = datas[591];
  9324. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  9325. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  9326. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  9327. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  9328. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  9329. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  9330. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  9331. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  9332. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  9333. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  9334. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  9335. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  9336. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  9337. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  9338. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  9339. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  9340. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  9341. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  9342. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  9343. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  9344. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  9345. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  9346. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  9347. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  9348. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  9349. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  9350. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  9351. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  9352. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  9353. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  9354. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  9355. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  9356. // s4PLCData["d5Result"] = datas[912];
  9357. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  9358. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  9359. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  9360. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  9361. // s4PLCData["d5OEEType"] = datas[945];
  9362. // #endregion 一次性读取所有数据
  9363. // stopwatch2.Stop();
  9364. // #region 回写操作,写后清空flag
  9365. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  9366. // #endregion 回写操作,写后清空flag
  9367. // // N801A-S4_1 弹夹扫码
  9368. // #region N801A-S4_1 弹夹扫码
  9369. // try
  9370. // {
  9371. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  9372. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  9373. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  9374. // {
  9375. // if (d1BulletclipScanCode == 1) // 0->1
  9376. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  9377. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  9378. // }
  9379. // }
  9380. // catch (Exception ex)
  9381. // {
  9382. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  9383. // string str = ex.StackTrace;
  9384. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9385. // }
  9386. // #endregion N801A-S4_1 弹夹扫码
  9387. // // N801A-S4_1 载具扫码
  9388. // #region N801A-S4_1 载具扫码
  9389. // try
  9390. // {
  9391. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  9392. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  9393. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  9394. // {
  9395. // if (d1VehicleScanCode == 1) // 0->1
  9396. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  9397. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  9398. // }
  9399. // }
  9400. // catch (Exception ex)
  9401. // {
  9402. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  9403. // string str = ex.StackTrace;
  9404. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9405. // }
  9406. // #endregion N801A-S4_1 载具扫码
  9407. // // N801A-S4_1 出站接口
  9408. // #region N801A-S4_1 出站接口
  9409. // try
  9410. // {
  9411. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  9412. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  9413. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  9414. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  9415. // {
  9416. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  9417. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  9418. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  9419. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  9420. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  9421. // }
  9422. // }
  9423. // catch (Exception ex)
  9424. // {
  9425. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  9426. // string str = ex.StackTrace;
  9427. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9428. // }
  9429. // #endregion N801A-S4_1 出站接口
  9430. // // N801A-S4_1 节拍接口
  9431. // #region N801A-S4_1 节拍接口
  9432. // try
  9433. // {
  9434. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  9435. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  9436. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  9437. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  9438. // {
  9439. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  9440. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  9441. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  9442. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  9443. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  9444. // }
  9445. // }
  9446. // catch (Exception ex)
  9447. // {
  9448. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  9449. // string str = ex.StackTrace;
  9450. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9451. // }
  9452. // #endregion N801A-S4_1 节拍接口
  9453. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  9454. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  9455. // try
  9456. // {
  9457. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  9458. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  9459. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  9460. // {
  9461. // if (d2BulletclipScanCode == 1) // 0->1
  9462. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  9463. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  9464. // }
  9465. // }
  9466. // catch (Exception ex)
  9467. // {
  9468. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  9469. // string str = ex.StackTrace;
  9470. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9471. // }
  9472. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  9473. // // N801A-S4_3 真空标机1 数据
  9474. // #region N801A-S4_3 真空标机1
  9475. // try
  9476. // {
  9477. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  9478. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  9479. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  9480. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  9481. // {
  9482. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  9483. // {
  9484. // int stationType = (int)s4PLCData["d3Type"];
  9485. // if (stationType == 1)
  9486. // {
  9487. // // S4_3进站接口
  9488. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  9489. // }
  9490. // else if (stationType == 2)
  9491. // {
  9492. // // S4_3出站接口
  9493. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  9494. // }
  9495. // }
  9496. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  9497. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  9498. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  9499. // }
  9500. // }
  9501. // catch (Exception ex)
  9502. // {
  9503. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  9504. // string str = ex.StackTrace;
  9505. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9506. // }
  9507. // #endregion N801A-S4_3 真空标机1
  9508. // // N801A-S4_4 真空标机2 数据
  9509. // #region N801A-S4_4 真空标机2
  9510. // try
  9511. // {
  9512. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  9513. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  9514. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  9515. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  9516. // {
  9517. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  9518. // {
  9519. // int stationType = (int)s4PLCData["d4Type"];
  9520. // if (stationType == 1)
  9521. // {
  9522. // // S4_4进站接口
  9523. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  9524. // }
  9525. // else if (stationType == 2)
  9526. // {
  9527. // // S4_4出站接口
  9528. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  9529. // }
  9530. // }
  9531. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  9532. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  9533. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  9534. // }
  9535. // }
  9536. // catch (Exception ex)
  9537. // {
  9538. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  9539. // string str = ex.StackTrace;
  9540. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9541. // }
  9542. // #endregion N801A-S4_4 真空标机2
  9543. // // N801A-S4_5 弹夹扫码 数据
  9544. // #region N801A-S4_5 弹夹扫码
  9545. // try
  9546. // {
  9547. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  9548. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  9549. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  9550. // {
  9551. // if (d5BulletclipScanCode == 1) // 0->1
  9552. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  9553. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  9554. // }
  9555. // }
  9556. // catch (Exception ex)
  9557. // {
  9558. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  9559. // string str = ex.StackTrace;
  9560. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9561. // }
  9562. // #endregion N801A-S4_5 弹夹扫码
  9563. // // N801A-S4_5 载具扫码 数据
  9564. // #region N801A-S4_5 载具扫码
  9565. // try
  9566. // {
  9567. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  9568. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  9569. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  9570. // {
  9571. // if (d5VehicleScanCode == 1) // 0->1
  9572. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  9573. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  9574. // }
  9575. // }
  9576. // catch (Exception ex)
  9577. // {
  9578. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  9579. // string str = ex.StackTrace;
  9580. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9581. // }
  9582. // #endregion N801A-S4_5 载具扫码
  9583. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  9584. // #region N801A-S4_5 出站接口
  9585. // try
  9586. // {
  9587. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  9588. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  9589. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  9590. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  9591. // {
  9592. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  9593. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  9594. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  9595. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  9596. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  9597. // }
  9598. // }
  9599. // catch (Exception ex)
  9600. // {
  9601. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  9602. // string str = ex.StackTrace;
  9603. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9604. // }
  9605. // #endregion N801A-S4_5 出站接口
  9606. // // N801A-S4_5 节拍接口 数据
  9607. // #region N801A-S4_5 节拍接口
  9608. // try
  9609. // {
  9610. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  9611. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  9612. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  9613. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  9614. // {
  9615. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  9616. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  9617. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  9618. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  9619. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  9620. // }
  9621. // }
  9622. // catch (Exception ex)
  9623. // {
  9624. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  9625. // string str = ex.StackTrace;
  9626. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9627. // }
  9628. // #endregion N801A-S4_5 节拍接口
  9629. // #region 心跳
  9630. // try
  9631. // {
  9632. // short states = 0;
  9633. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  9634. // }
  9635. // catch (Exception ex)
  9636. // {
  9637. // string str = ex.StackTrace;
  9638. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9639. // }
  9640. // #endregion 心跳
  9641. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  9642. // stopwatch1.Stop();
  9643. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  9644. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  9645. // }
  9646. // else
  9647. // {
  9648. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9649. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  9650. // Funs[plcNo].Connect();
  9651. // }
  9652. // }
  9653. // catch (Exception ex)
  9654. // {
  9655. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9656. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  9657. // Funs[plcNo].ReConnect();
  9658. // }
  9659. // Thread.Sleep(IntervalReadPLC);
  9660. // }
  9661. //}
  9662. /// <summary>
  9663. /// [S4] 取放桁架 - S4_1弹夹扫码
  9664. /// </summary>
  9665. /// <param name="plcNo">PLC编号</param>
  9666. /// <param name="stationNameStr">工站全称</param>
  9667. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  9668. {
  9669. Stopwatch stopwatch1 = new Stopwatch();
  9670. Stopwatch stopwatch2 = new Stopwatch();
  9671. try
  9672. {
  9673. stopwatch1.Start();
  9674. // ZS 弹夹扫码
  9675. string d1BulletclipCode = " "; // 扫到的码
  9676. short d1BulletclipScanCode = 2;
  9677. stopwatch2.Start();
  9678. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  9679. //// MES_Flag
  9680. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  9681. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9682. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  9683. writeToPLC_Flag.Adress = 2002;
  9684. writeToPLC_Flag.Value = d1BulletclipScanCode;
  9685. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  9686. {
  9687. Name = "d1BulletclipCode",
  9688. Adress = 2003,
  9689. ValueType = PLCValueType.String,
  9690. ValueTypeStrLength = 20,
  9691. Value = d1BulletclipCode
  9692. });
  9693. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  9694. stopwatch2.Stop();
  9695. }
  9696. catch (Exception ex)
  9697. {
  9698. string str = ex.StackTrace;
  9699. AddMessage_Station(stationNameStr, LogType.Error,
  9700. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  9701. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9702. stopwatch2.Start();
  9703. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  9704. //// MES_Flag
  9705. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  9706. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9707. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  9708. writeToPLC_Flag.Adress = 2002;
  9709. writeToPLC_Flag.Value = (short)6;
  9710. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  9711. {
  9712. Name = "d1BulletclipCode",
  9713. Adress = 2003,
  9714. ValueType = PLCValueType.String,
  9715. ValueTypeStrLength = 20,
  9716. Value = " "
  9717. });
  9718. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  9719. stopwatch2.Stop();
  9720. }
  9721. stopwatch1.Stop();
  9722. AddMessage(LogType.Info,
  9723. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9724. stopwatch2.ElapsedMilliseconds + "ms");
  9725. }
  9726. /// <summary>
  9727. /// [S4] 取放桁架 - S4_1载具扫码
  9728. /// </summary>
  9729. /// <param name="plcNo">PLC编号</param>
  9730. /// <param name="stationNameStr">工站全称</param>
  9731. private void S4_1载具扫码(int plcNo, string stationNameStr)
  9732. {
  9733. Stopwatch stopwatch1 = new Stopwatch();
  9734. Stopwatch stopwatch2 = new Stopwatch();
  9735. try
  9736. {
  9737. stopwatch1.Start();
  9738. // ZS 载具扫码
  9739. string d1VehicleCode = ""; // 扫到的码
  9740. short d1VehicleScanCode = 2;
  9741. #region 进站
  9742. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  9743. {
  9744. #region 查询载具上的产品信息
  9745. string cavityData = string.Empty;
  9746. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  9747. if (string.IsNullOrEmpty(cavityData))
  9748. cavityData = "";
  9749. if (snResult != 0)
  9750. {
  9751. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9752. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  9753. writeToPLC_Flag1.Adress = 2033;
  9754. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  9755. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9756. {
  9757. Name = "d1VehicleCode",
  9758. Adress = 2034,
  9759. ValueType = PLCValueType.String,
  9760. ValueTypeStrLength = 20,
  9761. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  9762. });
  9763. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  9764. stopwatch1.Stop();
  9765. AddMessage(LogType.Info,
  9766. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9767. "ms");
  9768. return;
  9769. }
  9770. string[] cavitySNs = cavityData.Split('.');
  9771. string partNo = "";
  9772. if (cavitySNs != null && cavitySNs.Length >= 1)
  9773. {
  9774. partNo = cavitySNs[0];
  9775. }
  9776. #endregion 查询载具上的产品信息
  9777. List<TestItem> item = new List<TestItem>();
  9778. item.Add(new TestItem()
  9779. {
  9780. Parameter_name = "载具码",
  9781. Parameter_value = d1VehicleCode,
  9782. });
  9783. item.Add(new TestItem()
  9784. {
  9785. Parameter_name = "载具穴号",
  9786. Parameter_value = "1",
  9787. });
  9788. stopwatch2.Start();
  9789. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  9790. partNo, item, out string errorMsg);
  9791. stopwatch2.Stop();
  9792. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  9793. }
  9794. #endregion 进站
  9795. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  9796. //// MES_Flag
  9797. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  9798. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9799. writeToPLC_Flag.Name = "d1VehicleScanCode";
  9800. writeToPLC_Flag.Adress = 2033;
  9801. writeToPLC_Flag.Value = d1VehicleScanCode;
  9802. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9803. {
  9804. Name = "d1VehicleCode",
  9805. Adress = 2034,
  9806. ValueType = PLCValueType.String,
  9807. ValueTypeStrLength = 20,
  9808. Value = d1VehicleCode
  9809. });
  9810. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  9811. }
  9812. catch (Exception ex)
  9813. {
  9814. string str = ex.StackTrace;
  9815. AddMessage_Station(stationNameStr, LogType.Error,
  9816. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  9817. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9818. stopwatch2.Start();
  9819. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  9820. //// MES_Flag
  9821. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  9822. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9823. writeToPLC_Flag.Name = "d1VehicleScanCode";
  9824. writeToPLC_Flag.Adress = 2033;
  9825. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  9826. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9827. {
  9828. Name = "d1VehicleCode",
  9829. Adress = 2034,
  9830. ValueType = PLCValueType.String,
  9831. ValueTypeStrLength = 20,
  9832. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  9833. });
  9834. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  9835. stopwatch2.Stop();
  9836. }
  9837. stopwatch1.Stop();
  9838. AddMessage(LogType.Info,
  9839. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9840. stopwatch2.ElapsedMilliseconds + "ms");
  9841. }
  9842. // 上次采集到的SN
  9843. //private string sn_S4_1出站接口 = string.Empty;
  9844. /// <summary>
  9845. /// [S4] 取放桁架 - S4_1出站接口
  9846. /// </summary>
  9847. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  9848. {
  9849. Stopwatch stopwatch1 = new Stopwatch();
  9850. Stopwatch stopwatch2 = new Stopwatch();
  9851. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9852. string stationNameStr = stationCode + stationName;
  9853. string processItem = stationName; // 测试项目
  9854. try
  9855. {
  9856. stopwatch1.Start();
  9857. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9858. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9859. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9860. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9861. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  9862. sn = sn.Replace("\0", "");
  9863. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  9864. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  9865. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  9866. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  9867. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  9868. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  9869. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  9870. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  9871. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  9872. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  9873. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  9874. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  9875. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  9876. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  9877. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  9878. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  9879. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  9880. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  9881. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  9882. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  9883. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  9884. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  9885. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  9886. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  9887. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  9888. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  9889. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  9890. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  9891. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  9892. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  9893. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  9894. bool pass = d1Result == 1;
  9895. // 存 载具SN列表
  9896. List<string> vehicleCodes = new List<string>()
  9897. {
  9898. d1VehicleCode1, d1VehicleCode2, d1VehicleCode3, d1VehicleCode4, d1VehicleCode5,
  9899. d1VehicleCode6, d1VehicleCode7, d1VehicleCode8, d1VehicleCode9, d1VehicleCode10,
  9900. d1VehicleCode11, d1VehicleCode12, d1VehicleCode13, d1VehicleCode14, d1VehicleCode15
  9901. };
  9902. // 统一查 产品SN列表
  9903. List<string> partNos = new List<string>();
  9904. foreach (string vehicleCode in vehicleCodes)
  9905. {
  9906. if (string.IsNullOrEmpty(vehicleCode))
  9907. partNos.Add("");
  9908. else
  9909. {
  9910. string partNo = "";
  9911. #region 查询载具上的产品信息
  9912. string cavityData = string.Empty;
  9913. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  9914. if (string.IsNullOrEmpty(cavityData))
  9915. cavityData = "";
  9916. if (snResult != 0)
  9917. {
  9918. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9919. writeToPLC_Flag1.Name = "d1MES_FLAG";
  9920. writeToPLC_Flag1.Adress = 2065;
  9921. writeToPLC_Flag1.Value = (short)4;
  9922. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  9923. stopwatch1.Stop();
  9924. AddMessage(LogType.Info,
  9925. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9926. "ms");
  9927. return;
  9928. }
  9929. string[] cavitySNs = cavityData.Split('.');
  9930. if (cavitySNs != null && cavitySNs.Length >= 1)
  9931. partNo = cavitySNs[0];
  9932. #endregion 查询载具上的产品信息
  9933. partNos.Add(partNo);
  9934. }
  9935. }
  9936. // 统一上传
  9937. stopwatch2.Start();
  9938. List<int> results = new List<int>();
  9939. for (int i = 0; i < partNos.Count; i++)
  9940. {
  9941. string index = (i + 1).ToString(); // 弹夹穴号
  9942. if (string.IsNullOrEmpty(partNos[i]))
  9943. results.Add(1);
  9944. else
  9945. {
  9946. List<TestItem> items1 = new List<TestItem>();
  9947. items1.Add(new TestItem()
  9948. {
  9949. Parameter_name = "弹夹码",
  9950. Parameter_value = sn,
  9951. Parameter_unit = ""
  9952. });
  9953. items1.Add(new TestItem()
  9954. {
  9955. Parameter_name = "弹夹穴号",
  9956. Parameter_value = index,
  9957. Parameter_unit = ""
  9958. });
  9959. items1.Add(new TestItem()
  9960. {
  9961. Parameter_name = "载具码",
  9962. Parameter_value = vehicleCodes[i],
  9963. Parameter_unit = ""
  9964. });
  9965. items1.Add(new TestItem()
  9966. {
  9967. Parameter_name = "载具穴号",
  9968. Parameter_value = "1",
  9969. Parameter_unit = ""
  9970. });
  9971. items1.Add(new TestItem()
  9972. {
  9973. Parameter_name = "产品结果",
  9974. Parameter_value = d1Result == 1 ? "OK" : "NG",
  9975. Parameter_unit = ""
  9976. });
  9977. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  9978. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  9979. results.Add(result1);
  9980. }
  9981. }
  9982. short result = 0;
  9983. if (results.All(a => a == 1))
  9984. result = 1;
  9985. else if (results.Contains(3))
  9986. result = 3;
  9987. else if (results.Contains(2))
  9988. result = 2;
  9989. else if (results.Contains(4))
  9990. result = 4;
  9991. else
  9992. result = 4;
  9993. stopwatch2.Stop();
  9994. #region 存储绑定数据到 边线MES系统中
  9995. if (result == 1)
  9996. {
  9997. string data = string.Join(".", vehicleCodes);
  9998. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  9999. if (resultMesR != 0)
  10000. {
  10001. result = 4;
  10002. AddMessage_Station(stationNameStr, LogType.Error,
  10003. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  10004. }
  10005. }
  10006. #endregion 存储绑定数据到 边线MES系统中
  10007. // MES_Flag 为4MES报错
  10008. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10009. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10010. writeToPLC_Flag.Name = "d1MES_FLAG";
  10011. writeToPLC_Flag.Adress = 2065;
  10012. writeToPLC_Flag.Value = result;
  10013. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  10014. OnMessage(LogType.Debug,
  10015. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  10016. }
  10017. catch (Exception ex)
  10018. {
  10019. stopwatch2.Restart();
  10020. // MES_Flag 为4上位机报错
  10021. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  10022. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10023. writeToPLC_Flag.Name = "d1MES_FLAG";
  10024. writeToPLC_Flag.Adress = 2065;
  10025. writeToPLC_Flag.Value = (short)4;
  10026. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  10027. stopwatch2.Stop();
  10028. string str = ex.StackTrace;
  10029. AddMessage_Station(stationNameStr, LogType.Error,
  10030. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10031. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10032. }
  10033. stopwatch1.Stop();
  10034. AddMessage(LogType.Info,
  10035. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10036. stopwatch2.ElapsedMilliseconds + "ms");
  10037. }
  10038. /// <summary>
  10039. /// [S4] 取放桁架 - S4_1节拍接口
  10040. /// </summary>
  10041. /// <param name="plcNo">PLC编号</param>
  10042. /// <param name="stationNameStr">工站全称</param>
  10043. private void S4_1节拍接口(int plcNo, string stationNameStr)
  10044. {
  10045. Stopwatch stopwatch1 = new Stopwatch();
  10046. Stopwatch stopwatch2 = new Stopwatch();
  10047. string resultStr = string.Empty;
  10048. try
  10049. {
  10050. stopwatch1.Start();
  10051. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  10052. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  10053. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  10054. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  10055. if (!actionBool)
  10056. {
  10057. stopwatch2.Start();
  10058. // MES_Flag
  10059. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10060. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10061. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  10062. writeToPLC_Flag1.Adress = 2398;
  10063. writeToPLC_Flag1.Value = (short)4;
  10064. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  10065. stopwatch2.Stop();
  10066. AddMessage(LogType.Info,
  10067. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  10068. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  10069. return;
  10070. }
  10071. string d1OEEPartNo = string.Empty; // 物料码
  10072. if (string.IsNullOrEmpty(d1OEEProductSN))
  10073. {
  10074. stopwatch2.Start();
  10075. // MES_Flag
  10076. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10077. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10078. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  10079. writeToPLC_Flag1.Adress = 2398;
  10080. writeToPLC_Flag1.Value = (short)1;
  10081. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  10082. stopwatch2.Stop();
  10083. AddMessage(LogType.Info,
  10084. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10085. stopwatch2.ElapsedMilliseconds + "ms");
  10086. return;
  10087. }
  10088. else
  10089. {
  10090. // 查产品SN ZS
  10091. d1OEEPartNo = "Test";
  10092. }
  10093. short d1OEEMES_FLAG = 0;
  10094. // 上传OEE
  10095. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  10096. d1OEEMES_FLAG = result.Item1;
  10097. resultStr = result.Item2;
  10098. stopwatch2.Start();
  10099. // MES_Flag
  10100. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10101. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10102. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  10103. writeToPLC_Flag.Adress = 2398;
  10104. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  10105. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  10106. stopwatch2.Stop();
  10107. }
  10108. catch (Exception ex)
  10109. {
  10110. string str = ex.StackTrace;
  10111. AddMessage_Station(stationNameStr, LogType.Error,
  10112. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  10113. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10114. // MES_Flag
  10115. stopwatch2.Start();
  10116. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  10117. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10118. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  10119. writeToPLC_Flag.Adress = 2398;
  10120. writeToPLC_Flag.Value = (short)4;
  10121. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  10122. stopwatch2.Stop();
  10123. }
  10124. stopwatch1.Stop();
  10125. AddMessage(LogType.Info,
  10126. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10127. stopwatch2.ElapsedMilliseconds + "ms");
  10128. }
  10129. /// <summary>
  10130. /// [S4] 取放桁架 - S4_2桁架
  10131. /// </summary>
  10132. /// <param name="plcNo">PLC编号</param>
  10133. /// <param name="stationNameStr">工站全称</param>
  10134. private void S4_2桁架(int plcNo, string stationNameStr)
  10135. {
  10136. Stopwatch stopwatch1 = new Stopwatch();
  10137. Stopwatch stopwatch2 = new Stopwatch();
  10138. try
  10139. {
  10140. stopwatch1.Start();
  10141. // ZS 弹夹扫码
  10142. string d2BulletclipCode = " "; // 扫到的码
  10143. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  10144. short d2BulletclipScanCode = 2;
  10145. stopwatch2.Start();
  10146. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  10147. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  10148. //// MES_Flag
  10149. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10150. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10151. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  10152. writeToPLC_Flag.Adress = 2430;
  10153. writeToPLC_Flag.Value = d2BulletclipScanCode;
  10154. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10155. {
  10156. Name = "d2BulletclipCode",
  10157. Adress = 2432,
  10158. ValueType = PLCValueType.String,
  10159. ValueTypeStrLength = 20,
  10160. Value = d2BulletclipCode
  10161. });
  10162. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10163. {
  10164. Name = "d2BulletclipStates",
  10165. Adress = 2431,
  10166. ValueType = PLCValueType.Short,
  10167. Value = d2BulletclipStates
  10168. });
  10169. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  10170. stopwatch2.Stop();
  10171. }
  10172. catch (Exception ex)
  10173. {
  10174. string str = ex.StackTrace;
  10175. AddMessage_Station(stationNameStr, LogType.Error,
  10176. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10177. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10178. stopwatch2.Start();
  10179. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  10180. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  10181. // MES_Flag
  10182. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  10183. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10184. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  10185. writeToPLC_Flag.Adress = 2430;
  10186. writeToPLC_Flag.Value = (short)6;
  10187. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10188. {
  10189. Name = "d2BulletclipCode",
  10190. Adress = 2432,
  10191. ValueType = PLCValueType.String,
  10192. ValueTypeStrLength = 20,
  10193. Value = " "
  10194. });
  10195. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10196. {
  10197. Name = "d2BulletclipStates",
  10198. Adress = 2431,
  10199. ValueType = PLCValueType.Short,
  10200. Value = (short)0
  10201. });
  10202. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  10203. stopwatch2.Stop();
  10204. }
  10205. stopwatch1.Stop();
  10206. AddMessage(LogType.Info,
  10207. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10208. stopwatch2.ElapsedMilliseconds + "ms");
  10209. }
  10210. // 上次采集到的SN
  10211. //private string sn_S4_3进站接口 = string.Empty;
  10212. /// <summary>
  10213. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  10214. /// </summary>
  10215. private void S4_3进站接口(int plcNo, string stationNameStr)
  10216. {
  10217. Stopwatch stopwatch1 = new Stopwatch();
  10218. Stopwatch stopwatch2 = new Stopwatch();
  10219. try
  10220. {
  10221. stopwatch1.Start();
  10222. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  10223. sn = sn.Replace("\0", "");
  10224. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  10225. #region 查询15个载具码
  10226. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10227. string vehicleData = string.Empty;
  10228. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10229. if (string.IsNullOrEmpty(vehicleData))
  10230. vehicleData = "";
  10231. if (snResult != 0)
  10232. {
  10233. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10234. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10235. writeToPLC_Flag1.Adress = 2463;
  10236. writeToPLC_Flag1.Value = (short)4;
  10237. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10238. stopwatch1.Stop();
  10239. AddMessage(LogType.Info,
  10240. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10241. return;
  10242. }
  10243. string[] cavitySNs = vehicleData.Split('.');
  10244. if (cavitySNs != null && cavitySNs.Length > 0)
  10245. {
  10246. for (int i = 0; i < cavitySNs.Length; i++)
  10247. {
  10248. if (string.IsNullOrEmpty(cavitySNs[i]))
  10249. vehicleCodes.Add("");
  10250. else
  10251. vehicleCodes.Add(cavitySNs[i]);
  10252. }
  10253. }
  10254. #endregion 查询15个载具码
  10255. #region 查询15个产品SN
  10256. List<string> portNos = new List<string>(); // 15个产品SN
  10257. foreach (string vehicleCode in vehicleCodes)
  10258. {
  10259. if (string.IsNullOrEmpty(vehicleCode))
  10260. portNos.Add("");
  10261. else
  10262. {
  10263. // 查询
  10264. string cavityData = string.Empty;
  10265. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10266. if (string.IsNullOrEmpty(cavityData))
  10267. cavityData = "";
  10268. if (snResult1 != 0)
  10269. {
  10270. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10271. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10272. writeToPLC_Flag1.Adress = 2463;
  10273. writeToPLC_Flag1.Value = (short)4;
  10274. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10275. stopwatch1.Stop();
  10276. AddMessage(LogType.Info,
  10277. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  10278. stopwatch1.ElapsedMilliseconds + "ms");
  10279. return;
  10280. }
  10281. string[] partSNs = cavityData.Split('.');
  10282. if (partSNs != null && partSNs.Length >= 1)
  10283. portNos.Add(partSNs[0]);
  10284. else
  10285. portNos.Add("");
  10286. }
  10287. }
  10288. #endregion 查询15个产品SN
  10289. // 调用MES进站(最多15个)
  10290. stopwatch2.Start();
  10291. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  10292. for (int i = 0; i < vehicleCodes.Count; i++)
  10293. {
  10294. // 循环进站
  10295. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  10296. {
  10297. // 产品SN(物料码)校验
  10298. string portNo = portNos[i];
  10299. List<TestItem> item = new List<TestItem>();
  10300. item.Add(new TestItem()
  10301. {
  10302. Parameter_name = "弹夹码",
  10303. Parameter_value = sn,
  10304. });
  10305. item.Add(new TestItem()
  10306. {
  10307. Parameter_name = "弹夹穴位",
  10308. Parameter_value = (i + 1).ToString(),
  10309. });
  10310. item.Add(new TestItem()
  10311. {
  10312. Parameter_name = "载具码",
  10313. Parameter_value = vehicleCodes[i],
  10314. });
  10315. item.Add(new TestItem()
  10316. {
  10317. Parameter_name = "载具穴号",
  10318. Parameter_value = "1",
  10319. });
  10320. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  10321. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  10322. }
  10323. }
  10324. stopwatch2.Stop();
  10325. short result = 0;
  10326. bool haveMesWarn = results.Contains(5);
  10327. bool havePCWarn = results.Contains(6);
  10328. if (haveMesWarn)
  10329. result = 2; // 5->2
  10330. else if (havePCWarn)
  10331. result = 6; // 6->4
  10332. else
  10333. result = 1;
  10334. // MES_Flag 为4MES报错
  10335. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10336. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10337. writeToPLC_Flag.Name = "d3MES_FLAG";
  10338. writeToPLC_Flag.Adress = 2463;
  10339. writeToPLC_Flag.Value = result;
  10340. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10341. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10342. }
  10343. catch (Exception ex)
  10344. {
  10345. stopwatch2.Stop();
  10346. // MES_Flag 为4上位机报错
  10347. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  10348. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10349. writeToPLC_Flag.Name = "d3MES_FLAG";
  10350. writeToPLC_Flag.Adress = 2463;
  10351. writeToPLC_Flag.Value = (short)4;
  10352. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10353. string str = ex.StackTrace;
  10354. AddMessage_Station(stationNameStr, LogType.Error,
  10355. $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10356. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10357. }
  10358. stopwatch1.Stop();
  10359. AddMessage(LogType.Info,
  10360. stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  10361. stopwatch2.ElapsedMilliseconds + "ms");
  10362. }
  10363. // 上次采集到的SN
  10364. //private string sn_S4_3出站接口 = string.Empty;
  10365. /// <summary>
  10366. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  10367. /// </summary>
  10368. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  10369. {
  10370. Stopwatch stopwatch1 = new Stopwatch();
  10371. Stopwatch stopwatch2 = new Stopwatch();
  10372. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10373. string stationNameStr = stationCode + stationName;
  10374. string processItem = stationName; // 测试项目
  10375. try
  10376. {
  10377. stopwatch1.Start();
  10378. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10379. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10380. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10381. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10382. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  10383. sn = sn.Replace("\0", "");
  10384. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  10385. bool isPass = d3Result == 1; // 产品结果 bool
  10386. #region 查询15个载具码
  10387. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10388. string vehicleData = string.Empty;
  10389. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10390. if (string.IsNullOrEmpty(vehicleData))
  10391. vehicleData = "";
  10392. if (snResult1 != 0)
  10393. {
  10394. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10395. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10396. writeToPLC_Flag1.Adress = 2463;
  10397. writeToPLC_Flag1.Value = (short)4;
  10398. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10399. stopwatch1.Stop();
  10400. AddMessage(LogType.Info,
  10401. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10402. return;
  10403. }
  10404. string[] cavitySNs = vehicleData.Split('.');
  10405. if (cavitySNs != null && cavitySNs.Length > 0)
  10406. {
  10407. for (int i = 0; i < cavitySNs.Length; i++)
  10408. {
  10409. if (string.IsNullOrEmpty(cavitySNs[i]))
  10410. vehicleCodes.Add("");
  10411. else
  10412. vehicleCodes.Add(cavitySNs[i]);
  10413. }
  10414. }
  10415. #endregion 查询15个载具码
  10416. // 统一查 产品SN列表
  10417. List<string> partNos = new List<string>();
  10418. foreach (string vehicleCode in vehicleCodes)
  10419. {
  10420. if (string.IsNullOrEmpty(vehicleCode))
  10421. partNos.Add("");
  10422. else
  10423. {
  10424. string partNo = "";
  10425. #region 查询载具上的产品信息
  10426. string cavityData = string.Empty;
  10427. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10428. if (string.IsNullOrEmpty(cavityData))
  10429. cavityData = "";
  10430. if (snResult != 0)
  10431. {
  10432. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10433. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10434. writeToPLC_Flag1.Adress = 2463;
  10435. writeToPLC_Flag1.Value = (short)4;
  10436. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10437. stopwatch1.Stop();
  10438. AddMessage(LogType.Info,
  10439. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10440. "ms");
  10441. return;
  10442. }
  10443. string[] partSNs = cavityData.Split('.');
  10444. if (partSNs != null && partSNs.Length >= 1)
  10445. partNo = partSNs[0];
  10446. #endregion 查询载具上的产品信息
  10447. partNos.Add(partNo);
  10448. }
  10449. }
  10450. // 统一上传 - 调用MES出站
  10451. stopwatch2.Start();
  10452. List<int> results = new List<int>();
  10453. for (int i = 0; i < partNos.Count; i++)
  10454. {
  10455. string index = (i + 1).ToString(); // 弹夹穴号
  10456. if (string.IsNullOrEmpty(partNos[i]))
  10457. results.Add(1);
  10458. else
  10459. {
  10460. List<TestItem> items1 = new List<TestItem>();
  10461. items1.Add(new TestItem()
  10462. {
  10463. Parameter_name = "弹夹码",
  10464. Parameter_value = sn,
  10465. Parameter_unit = ""
  10466. });
  10467. items1.Add(new TestItem()
  10468. {
  10469. Parameter_name = "弹夹穴号",
  10470. Parameter_value = index,
  10471. Parameter_unit = ""
  10472. });
  10473. items1.Add(new TestItem()
  10474. {
  10475. Parameter_name = "载具码",
  10476. Parameter_value = vehicleCodes[i],
  10477. Parameter_unit = ""
  10478. });
  10479. items1.Add(new TestItem()
  10480. {
  10481. Parameter_name = "载具穴号",
  10482. Parameter_value = "1",
  10483. Parameter_unit = ""
  10484. });
  10485. items1.Add(new TestItem()
  10486. {
  10487. Parameter_name = "产品结果",
  10488. Parameter_value = d3Result == 1 ? "OK" : "NG",
  10489. Parameter_unit = ""
  10490. });
  10491. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  10492. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  10493. results.Add(result1);
  10494. }
  10495. }
  10496. short result = 0;
  10497. if (results.All(a => a == 1))
  10498. result = 1;
  10499. else if (results.Contains(3))
  10500. result = 3;
  10501. else if (results.Contains(2))
  10502. result = 2;
  10503. else if (results.Contains(4))
  10504. result = 4;
  10505. else
  10506. result = 4;
  10507. stopwatch2.Stop();
  10508. // MES_Flag 为4MES报错
  10509. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10510. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10511. writeToPLC_Flag.Name = "d3MES_FLAG";
  10512. writeToPLC_Flag.Adress = 2463;
  10513. writeToPLC_Flag.Value = result;
  10514. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10515. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10516. }
  10517. catch (Exception ex)
  10518. {
  10519. stopwatch2.Restart();
  10520. // MES_Flag 为4上位机报错
  10521. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  10522. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10523. writeToPLC_Flag.Name = "d3MES_FLAG";
  10524. writeToPLC_Flag.Adress = 2463;
  10525. writeToPLC_Flag.Value = (short)4;
  10526. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10527. string str = ex.StackTrace;
  10528. AddMessage_Station(stationNameStr, LogType.Error,
  10529. $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10530. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10531. stopwatch2.Stop();
  10532. }
  10533. stopwatch1.Stop();
  10534. AddMessage(LogType.Info,
  10535. stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10536. stopwatch2.ElapsedMilliseconds + "ms");
  10537. }
  10538. // 上次采集到的SN
  10539. //private string sn_S4_4进站接口 = string.Empty;
  10540. /// <summary>
  10541. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  10542. /// </summary>
  10543. private void S4_4进站接口(int plcNo, string stationNameStr)
  10544. {
  10545. Stopwatch stopwatch1 = new Stopwatch();
  10546. Stopwatch stopwatch2 = new Stopwatch();
  10547. try
  10548. {
  10549. stopwatch1.Start();
  10550. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  10551. sn = sn.Replace("\0", "");
  10552. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  10553. #region 查询15个载具码
  10554. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10555. string vehicleData = string.Empty;
  10556. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10557. if (string.IsNullOrEmpty(vehicleData))
  10558. vehicleData = "";
  10559. if (snResult != 0)
  10560. {
  10561. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10562. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10563. writeToPLC_Flag1.Adress = 2463;
  10564. writeToPLC_Flag1.Value = (short)4;
  10565. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10566. stopwatch1.Stop();
  10567. AddMessage(LogType.Info,
  10568. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10569. return;
  10570. }
  10571. string[] cavitySNs = vehicleData.Split('.');
  10572. if (cavitySNs != null && cavitySNs.Length > 0)
  10573. {
  10574. for (int i = 0; i < cavitySNs.Length; i++)
  10575. {
  10576. if (string.IsNullOrEmpty(cavitySNs[i]))
  10577. vehicleCodes.Add("");
  10578. else
  10579. vehicleCodes.Add(cavitySNs[i]);
  10580. }
  10581. }
  10582. #endregion 查询15个载具码
  10583. #region 查询15个产品SN
  10584. List<string> portNos = new List<string>(); // 15个产品SN
  10585. foreach (string vehicleCode in vehicleCodes)
  10586. {
  10587. if (string.IsNullOrEmpty(vehicleCode))
  10588. portNos.Add("");
  10589. else
  10590. {
  10591. // 查询
  10592. string cavityData = string.Empty;
  10593. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10594. if (string.IsNullOrEmpty(cavityData))
  10595. cavityData = "";
  10596. if (snResult1 != 0)
  10597. {
  10598. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10599. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10600. writeToPLC_Flag1.Adress = 2463;
  10601. writeToPLC_Flag1.Value = (short)4;
  10602. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10603. stopwatch1.Stop();
  10604. AddMessage(LogType.Info,
  10605. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  10606. stopwatch1.ElapsedMilliseconds + "ms");
  10607. return;
  10608. }
  10609. string[] partSNs = cavityData.Split('.');
  10610. if (partSNs != null && partSNs.Length >= 1)
  10611. portNos.Add(partSNs[0]);
  10612. else
  10613. portNos.Add("");
  10614. }
  10615. }
  10616. #endregion 查询15个产品SN
  10617. // 调用MES进站(最多15个)
  10618. stopwatch2.Start();
  10619. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  10620. for (int i = 0; i < vehicleCodes.Count; i++)
  10621. {
  10622. // 循环进站
  10623. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  10624. {
  10625. // 产品SN(物料码)校验
  10626. string portNo = portNos[i];
  10627. List<TestItem> item = new List<TestItem>();
  10628. item.Add(new TestItem()
  10629. {
  10630. Parameter_name = "弹夹码",
  10631. Parameter_value = sn,
  10632. });
  10633. item.Add(new TestItem()
  10634. {
  10635. Parameter_name = "弹夹穴位",
  10636. Parameter_value = (i + 1).ToString(),
  10637. });
  10638. item.Add(new TestItem()
  10639. {
  10640. Parameter_name = "载具码",
  10641. Parameter_value = vehicleCodes[i],
  10642. });
  10643. item.Add(new TestItem()
  10644. {
  10645. Parameter_name = "载具穴号",
  10646. Parameter_value = "1",
  10647. });
  10648. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  10649. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  10650. }
  10651. }
  10652. stopwatch2.Stop();
  10653. short result = 0;
  10654. bool haveMesWarn = results.Contains(5);
  10655. bool havePCWarn = results.Contains(6);
  10656. if (haveMesWarn)
  10657. result = 2; // 5->2
  10658. else if (havePCWarn)
  10659. result = 6; // 6->4
  10660. else
  10661. result = 1;
  10662. // MES_Flag 为4MES报错
  10663. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10664. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10665. writeToPLC_Flag.Name = "d4MES_FLAG";
  10666. writeToPLC_Flag.Adress = 2496;
  10667. writeToPLC_Flag.Value = result;
  10668. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10669. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10670. }
  10671. catch (Exception ex)
  10672. {
  10673. stopwatch2.Stop();
  10674. // MES_Flag 为4上位机报错
  10675. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  10676. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10677. writeToPLC_Flag.Name = "d4MES_FLAG";
  10678. writeToPLC_Flag.Adress = 2496;
  10679. writeToPLC_Flag.Value = (short)4;
  10680. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10681. string str = ex.StackTrace;
  10682. AddMessage_Station(stationNameStr, LogType.Error,
  10683. $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10684. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10685. }
  10686. stopwatch1.Stop();
  10687. AddMessage(LogType.Info,
  10688. stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  10689. stopwatch2.ElapsedMilliseconds + "ms");
  10690. }
  10691. // 上次采集到的SN
  10692. //private string sn_S4_4出站接口 = string.Empty;
  10693. /// <summary>
  10694. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  10695. /// </summary>
  10696. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  10697. {
  10698. Stopwatch stopwatch1 = new Stopwatch();
  10699. Stopwatch stopwatch2 = new Stopwatch();
  10700. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10701. string stationNameStr = stationCode + stationName;
  10702. string processItem = stationName; // 测试项目
  10703. try
  10704. {
  10705. stopwatch1.Start();
  10706. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10707. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10708. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10709. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10710. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  10711. sn = sn.Replace("\0", "");
  10712. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  10713. bool isPass = d4Result == 1; // 产品结果 bool
  10714. #region 查询15个载具码
  10715. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10716. string vehicleData = string.Empty;
  10717. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10718. if (string.IsNullOrEmpty(vehicleData))
  10719. vehicleData = "";
  10720. if (snResult1 != 0)
  10721. {
  10722. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10723. writeToPLC_Flag1.Name = "d4MES_FLAG";
  10724. writeToPLC_Flag1.Adress = 2496;
  10725. writeToPLC_Flag1.Value = (short)4;
  10726. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  10727. stopwatch1.Stop();
  10728. AddMessage(LogType.Info,
  10729. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10730. return;
  10731. }
  10732. string[] cavitySNs = vehicleData.Split('.');
  10733. if (cavitySNs != null && cavitySNs.Length > 0)
  10734. {
  10735. for (int i = 0; i < cavitySNs.Length; i++)
  10736. {
  10737. if (string.IsNullOrEmpty(cavitySNs[i]))
  10738. vehicleCodes.Add("");
  10739. else
  10740. vehicleCodes.Add(cavitySNs[i]);
  10741. }
  10742. }
  10743. #endregion 查询15个载具码
  10744. // 统一查 产品SN列表
  10745. List<string> partNos = new List<string>();
  10746. foreach (string vehicleCode in vehicleCodes)
  10747. {
  10748. if (string.IsNullOrEmpty(vehicleCode))
  10749. partNos.Add("");
  10750. else
  10751. {
  10752. string partNo = "";
  10753. #region 查询载具上的产品信息
  10754. string cavityData = string.Empty;
  10755. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10756. if (string.IsNullOrEmpty(cavityData))
  10757. cavityData = "";
  10758. if (snResult != 0)
  10759. {
  10760. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10761. writeToPLC_Flag1.Name = "d4MES_FLAG";
  10762. writeToPLC_Flag1.Adress = 2496;
  10763. writeToPLC_Flag1.Value = (short)4;
  10764. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  10765. stopwatch1.Stop();
  10766. AddMessage(LogType.Info,
  10767. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10768. "ms");
  10769. return;
  10770. }
  10771. string[] partSNs = cavityData.Split('.');
  10772. if (partSNs != null && partSNs.Length >= 1)
  10773. partNo = partSNs[0];
  10774. #endregion 查询载具上的产品信息
  10775. partNos.Add(partNo);
  10776. }
  10777. }
  10778. // 调用MES出站
  10779. stopwatch2.Start();
  10780. // 统一上传
  10781. List<int> results = new List<int>();
  10782. for (int i = 0; i < partNos.Count; i++)
  10783. {
  10784. string index = (i + 1).ToString(); // 弹夹穴号
  10785. if (string.IsNullOrEmpty(partNos[i]))
  10786. results.Add(1);
  10787. else
  10788. {
  10789. List<TestItem> items1 = new List<TestItem>();
  10790. items1.Add(new TestItem()
  10791. {
  10792. Parameter_name = "弹夹码",
  10793. Parameter_value = sn,
  10794. Parameter_unit = ""
  10795. });
  10796. items1.Add(new TestItem()
  10797. {
  10798. Parameter_name = "弹夹穴号",
  10799. Parameter_value = index,
  10800. Parameter_unit = ""
  10801. });
  10802. items1.Add(new TestItem()
  10803. {
  10804. Parameter_name = "载具码",
  10805. Parameter_value = vehicleCodes[i],
  10806. Parameter_unit = ""
  10807. });
  10808. items1.Add(new TestItem()
  10809. {
  10810. Parameter_name = "载具穴号",
  10811. Parameter_value = "1",
  10812. Parameter_unit = ""
  10813. });
  10814. items1.Add(new TestItem()
  10815. {
  10816. Parameter_name = "产品结果",
  10817. Parameter_value = d4Result == 1 ? "OK" : "NG",
  10818. Parameter_unit = ""
  10819. });
  10820. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  10821. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  10822. results.Add(result1);
  10823. }
  10824. }
  10825. short result = 0;
  10826. if (results.All(a => a == 1))
  10827. result = 1;
  10828. else if (results.Contains(3))
  10829. result = 3;
  10830. else if (results.Contains(2))
  10831. result = 2;
  10832. else if (results.Contains(4))
  10833. result = 4;
  10834. else
  10835. result = 4;
  10836. stopwatch2.Stop();
  10837. // MES_Flag 为4MES报错
  10838. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10839. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10840. writeToPLC_Flag.Name = "d4MES_FLAG";
  10841. writeToPLC_Flag.Adress = 2496;
  10842. writeToPLC_Flag.Value = result;
  10843. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10844. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10845. }
  10846. catch (Exception ex)
  10847. {
  10848. stopwatch2.Restart();
  10849. // MES_Flag 为4上位机报错
  10850. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  10851. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10852. writeToPLC_Flag.Name = "d4MES_FLAG";
  10853. writeToPLC_Flag.Adress = 2496;
  10854. writeToPLC_Flag.Value = (short)4;
  10855. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10856. string str = ex.StackTrace;
  10857. AddMessage_Station(stationNameStr, LogType.Error,
  10858. $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10859. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10860. stopwatch2.Stop();
  10861. }
  10862. stopwatch1.Stop();
  10863. AddMessage(LogType.Info,
  10864. stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10865. stopwatch2.ElapsedMilliseconds + "ms");
  10866. }
  10867. /// <summary>
  10868. /// [S4] 取放桁架 - S4_5弹夹扫码
  10869. /// </summary>
  10870. /// <param name="plcNo">PLC编号</param>
  10871. /// <param name="stationNameStr">工站全称</param>
  10872. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  10873. {
  10874. Stopwatch stopwatch1 = new Stopwatch();
  10875. Stopwatch stopwatch2 = new Stopwatch();
  10876. try
  10877. {
  10878. stopwatch1.Start();
  10879. // ZS 弹夹扫码
  10880. string d5BulletclipCode = " "; // 扫到的码
  10881. short d5BulletclipScanCode = 2;
  10882. stopwatch2.Start();
  10883. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  10884. //// MES_Flag
  10885. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10886. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10887. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  10888. writeToPLC_Flag.Adress = 2528;
  10889. writeToPLC_Flag.Value = d5BulletclipScanCode;
  10890. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10891. {
  10892. Name = "d5BulletclipCode",
  10893. Adress = 2529,
  10894. ValueType = PLCValueType.String,
  10895. ValueTypeStrLength = 20,
  10896. Value = d5BulletclipCode
  10897. });
  10898. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  10899. stopwatch2.Stop();
  10900. }
  10901. catch (Exception ex)
  10902. {
  10903. string str = ex.StackTrace;
  10904. AddMessage_Station(stationNameStr, LogType.Error,
  10905. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10906. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10907. stopwatch2.Start();
  10908. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  10909. //// MES_Flag
  10910. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  10911. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10912. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  10913. writeToPLC_Flag.Adress = 2528;
  10914. writeToPLC_Flag.Value = (short)6;
  10915. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10916. {
  10917. Name = "d5BulletclipCode",
  10918. Adress = 2529,
  10919. ValueType = PLCValueType.String,
  10920. ValueTypeStrLength = 20,
  10921. Value = " "
  10922. });
  10923. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  10924. stopwatch2.Stop();
  10925. }
  10926. stopwatch1.Stop();
  10927. AddMessage(LogType.Info,
  10928. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10929. stopwatch2.ElapsedMilliseconds + "ms");
  10930. }
  10931. /// <summary>
  10932. /// [S4] 取放桁架 - S4_5载具扫码
  10933. /// </summary>
  10934. /// <param name="plcNo">PLC编号</param>
  10935. /// <param name="stationNameStr">工站全称</param>
  10936. private void S4_5载具扫码(int plcNo, string stationNameStr)
  10937. {
  10938. Stopwatch stopwatch1 = new Stopwatch();
  10939. Stopwatch stopwatch2 = new Stopwatch();
  10940. try
  10941. {
  10942. stopwatch1.Start();
  10943. // ZS 载具扫码
  10944. string d5VehicleCode = " "; // 扫到的码
  10945. short d5VehicleScanCode = 2;
  10946. #region 进站
  10947. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  10948. {
  10949. // 查产品SN
  10950. #region 查询载具上的产品信息
  10951. string cavityData = string.Empty;
  10952. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  10953. if (string.IsNullOrEmpty(cavityData))
  10954. cavityData = "";
  10955. if (snResult != 0)
  10956. {
  10957. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10958. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  10959. writeToPLC_Flag1.Adress = 2559;
  10960. writeToPLC_Flag1.Value = (short)6;
  10961. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10962. {
  10963. Name = "d5VehicleCode",
  10964. Adress = 2560,
  10965. ValueType = PLCValueType.String,
  10966. ValueTypeStrLength = 20,
  10967. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  10968. });
  10969. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  10970. stopwatch1.Stop();
  10971. AddMessage(LogType.Info,
  10972. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10973. "ms");
  10974. return;
  10975. }
  10976. string[] cavitySNs = cavityData.Split('.');
  10977. string partNo = "";
  10978. if (cavitySNs != null && cavitySNs.Length >= 1)
  10979. {
  10980. partNo = cavitySNs[0];
  10981. }
  10982. #endregion 查询载具上的产品信息
  10983. List<TestItem> item = new List<TestItem>();
  10984. item.Add(new TestItem()
  10985. {
  10986. Parameter_name = "载具码",
  10987. Parameter_value = d5VehicleCode,
  10988. });
  10989. item.Add(new TestItem()
  10990. {
  10991. Parameter_name = "载具穴号",
  10992. Parameter_value = "1",
  10993. });
  10994. stopwatch2.Start();
  10995. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  10996. partNo, item, out string errorMsg);
  10997. stopwatch2.Stop();
  10998. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  10999. }
  11000. #endregion 进站
  11001. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  11002. //// MES_Flag
  11003. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  11004. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11005. writeToPLC_Flag.Name = "d5VehicleScanCode";
  11006. writeToPLC_Flag.Adress = 2559;
  11007. writeToPLC_Flag.Value = d5VehicleScanCode;
  11008. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  11009. {
  11010. Name = "d5VehicleCode",
  11011. Adress = 2560,
  11012. ValueType = PLCValueType.String,
  11013. ValueTypeStrLength = 20,
  11014. Value = d5VehicleCode
  11015. });
  11016. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  11017. }
  11018. catch (Exception ex)
  11019. {
  11020. string str = ex.StackTrace;
  11021. AddMessage_Station(stationNameStr, LogType.Error,
  11022. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  11023. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11024. stopwatch2.Start();
  11025. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  11026. //// MES_Flag
  11027. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  11028. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11029. writeToPLC_Flag.Name = "d5VehicleScanCode";
  11030. writeToPLC_Flag.Adress = 2559;
  11031. writeToPLC_Flag.Value = (short)6;
  11032. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  11033. {
  11034. Name = "d5VehicleCode",
  11035. Adress = 2560,
  11036. ValueType = PLCValueType.String,
  11037. ValueTypeStrLength = 20,
  11038. Value = " "
  11039. });
  11040. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  11041. stopwatch2.Stop();
  11042. }
  11043. stopwatch1.Stop();
  11044. AddMessage(LogType.Info,
  11045. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11046. stopwatch2.ElapsedMilliseconds + "ms");
  11047. }
  11048. // 上次采集到的SN
  11049. //private string sn_S4_5出站接口 = string.Empty;
  11050. /// <summary>
  11051. /// [S4] 取放桁架 - S4_5出站接口
  11052. /// </summary>
  11053. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  11054. {
  11055. Stopwatch stopwatch1 = new Stopwatch();
  11056. Stopwatch stopwatch2 = new Stopwatch();
  11057. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  11058. string stationNameStr = stationCode + stationName;
  11059. string processItem = stationName; // 测试项目
  11060. try
  11061. {
  11062. stopwatch1.Start();
  11063. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  11064. //string batch_num = GlobalContext.BatchNumber; // 批次号
  11065. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  11066. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  11067. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  11068. sn = sn.Replace("\0", "");
  11069. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  11070. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  11071. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  11072. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  11073. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  11074. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  11075. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  11076. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  11077. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  11078. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  11079. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  11080. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  11081. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  11082. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  11083. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  11084. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  11085. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  11086. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  11087. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  11088. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  11089. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  11090. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  11091. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  11092. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  11093. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  11094. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  11095. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  11096. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  11097. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  11098. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  11099. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  11100. bool pass = d5Result == 1;
  11101. // 存 载具SN列表
  11102. List<string> vehicleCodes = new List<string>()
  11103. {
  11104. d5VehicleCode1, d5VehicleCode2, d5VehicleCode3, d5VehicleCode4, d5VehicleCode5,
  11105. d5VehicleCode6, d5VehicleCode7, d5VehicleCode8, d5VehicleCode9, d5VehicleCode10,
  11106. d5VehicleCode11, d5VehicleCode12, d5VehicleCode13, d5VehicleCode14, d5VehicleCode15
  11107. };
  11108. // 统一查 产品SN列表
  11109. List<string> partNos = new List<string>();
  11110. foreach (string vehicleCode in vehicleCodes)
  11111. {
  11112. if (string.IsNullOrEmpty(vehicleCode))
  11113. partNos.Add("");
  11114. else
  11115. {
  11116. string partNo = "";
  11117. #region 查询载具上的产品信息
  11118. string cavityData = string.Empty;
  11119. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  11120. if (string.IsNullOrEmpty(cavityData))
  11121. cavityData = "";
  11122. if (snResult != 0)
  11123. {
  11124. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11125. writeToPLC_Flag1.Name = "d5MES_FLAG";
  11126. writeToPLC_Flag1.Adress = 2591;
  11127. writeToPLC_Flag1.Value = (short)4;
  11128. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  11129. stopwatch1.Stop();
  11130. AddMessage(LogType.Info,
  11131. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  11132. "ms");
  11133. return;
  11134. }
  11135. string[] cavitySNs = cavityData.Split('.');
  11136. if (cavitySNs != null && cavitySNs.Length >= 1)
  11137. partNo = cavitySNs[0];
  11138. #endregion 查询载具上的产品信息
  11139. partNos.Add(partNo);
  11140. }
  11141. }
  11142. // 统一上传
  11143. stopwatch2.Start();
  11144. List<int> results = new List<int>();
  11145. for (int i = 0; i < partNos.Count; i++)
  11146. {
  11147. string index = (i + 1).ToString(); // 弹夹穴号
  11148. if (string.IsNullOrEmpty(partNos[i]))
  11149. results.Add(1);
  11150. else
  11151. {
  11152. List<TestItem> items1 = new List<TestItem>();
  11153. items1.Add(new TestItem()
  11154. {
  11155. Parameter_name = "弹夹码",
  11156. Parameter_value = sn,
  11157. Parameter_unit = ""
  11158. });
  11159. items1.Add(new TestItem()
  11160. {
  11161. Parameter_name = "弹夹穴号",
  11162. Parameter_value = index,
  11163. Parameter_unit = ""
  11164. });
  11165. items1.Add(new TestItem()
  11166. {
  11167. Parameter_name = "载具码",
  11168. Parameter_value = vehicleCodes[i],
  11169. Parameter_unit = ""
  11170. });
  11171. items1.Add(new TestItem()
  11172. {
  11173. Parameter_name = "载具穴号",
  11174. Parameter_value = "1",
  11175. Parameter_unit = ""
  11176. });
  11177. items1.Add(new TestItem()
  11178. {
  11179. Parameter_name = "产品结果",
  11180. Parameter_value = d5Result == 1 ? "OK" : "NG",
  11181. Parameter_unit = ""
  11182. });
  11183. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  11184. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  11185. results.Add(result1);
  11186. }
  11187. }
  11188. short result = 0;
  11189. if (results.All(a => a == 1))
  11190. result = 1;
  11191. else if (results.Contains(3))
  11192. result = 3;
  11193. else if (results.Contains(2))
  11194. result = 2;
  11195. else if (results.Contains(4))
  11196. result = 4;
  11197. else
  11198. result = 4;
  11199. stopwatch2.Stop();
  11200. #region 存储绑定数据到 边线MES系统中
  11201. if (result == 1)
  11202. {
  11203. // 删除绑定信息
  11204. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  11205. if (resultMesR != 0)
  11206. {
  11207. result = 4;
  11208. AddMessage_Station(stationNameStr, LogType.Error,
  11209. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  11210. }
  11211. }
  11212. #endregion 存储绑定数据到 边线MES系统中
  11213. // MES_Flag 为4MES报错
  11214. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11215. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11216. writeToPLC_Flag.Name = "d5MES_FLAG";
  11217. writeToPLC_Flag.Adress = 2591;
  11218. writeToPLC_Flag.Value = result;
  11219. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  11220. OnMessage(LogType.Debug,
  11221. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  11222. }
  11223. catch (Exception ex)
  11224. {
  11225. stopwatch2.Restart();
  11226. // MES_Flag 为4上位机报错
  11227. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  11228. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11229. writeToPLC_Flag.Name = "d5MES_FLAG";
  11230. writeToPLC_Flag.Adress = 2591;
  11231. writeToPLC_Flag.Value = (short)4;
  11232. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  11233. stopwatch2.Stop();
  11234. string str = ex.StackTrace;
  11235. AddMessage_Station(stationNameStr, LogType.Error,
  11236. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11237. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11238. }
  11239. stopwatch1.Stop();
  11240. AddMessage(LogType.Info,
  11241. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11242. stopwatch2.ElapsedMilliseconds + "ms");
  11243. }
  11244. /// <summary>
  11245. /// [S4] 取放桁架 - S4_5节拍接口
  11246. /// </summary>
  11247. /// <param name="plcNo">PLC编号</param>
  11248. /// <param name="stationNameStr">工站全称</param>
  11249. private void S4_5节拍接口(int plcNo, string stationNameStr)
  11250. {
  11251. Stopwatch stopwatch1 = new Stopwatch();
  11252. Stopwatch stopwatch2 = new Stopwatch();
  11253. string resultStr = string.Empty;
  11254. try
  11255. {
  11256. stopwatch1.Start();
  11257. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  11258. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  11259. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  11260. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  11261. if (!actionBool)
  11262. {
  11263. stopwatch2.Start();
  11264. // MES_Flag
  11265. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  11266. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11267. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  11268. writeToPLC_Flag1.Adress = 2924;
  11269. writeToPLC_Flag1.Value = (short)4;
  11270. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  11271. stopwatch2.Stop();
  11272. AddMessage(LogType.Info,
  11273. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  11274. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  11275. return;
  11276. }
  11277. string d5OEEPartNo = string.Empty; // 物料码
  11278. if (string.IsNullOrEmpty(d5OEEProductSN))
  11279. {
  11280. stopwatch2.Start();
  11281. // MES_Flag
  11282. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11283. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11284. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  11285. writeToPLC_Flag1.Adress = 2924;
  11286. writeToPLC_Flag1.Value = (short)1;
  11287. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  11288. stopwatch2.Stop();
  11289. AddMessage(LogType.Info,
  11290. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11291. stopwatch2.ElapsedMilliseconds + "ms");
  11292. return;
  11293. }
  11294. else
  11295. {
  11296. // 查产品SN
  11297. d5OEEPartNo = "Test"; // ZS
  11298. }
  11299. short d5OEEMES_FLAG = 0;
  11300. // 上传OEE
  11301. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  11302. d5OEEMES_FLAG = result.Item1;
  11303. resultStr = result.Item2;
  11304. stopwatch2.Start();
  11305. // MES_Flag
  11306. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11307. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11308. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  11309. writeToPLC_Flag.Adress = 2924;
  11310. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  11311. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  11312. stopwatch2.Stop();
  11313. }
  11314. catch (Exception ex)
  11315. {
  11316. string str = ex.StackTrace;
  11317. AddMessage_Station(stationNameStr, LogType.Error,
  11318. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  11319. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11320. // MES_Flag
  11321. stopwatch2.Start();
  11322. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  11323. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11324. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  11325. writeToPLC_Flag.Adress = 2924;
  11326. writeToPLC_Flag.Value = (short)4;
  11327. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  11328. stopwatch2.Stop();
  11329. }
  11330. stopwatch1.Stop();
  11331. AddMessage(LogType.Info,
  11332. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11333. stopwatch2.ElapsedMilliseconds + "ms");
  11334. }
  11335. #endregion [S4] 取放桁架
  11336. #endregion PLC4 刘果段
  11337. #region PLC5 张超凡
  11338. #region [S5] Tray盘下料装备
  11339. /// <summary>
  11340. /// S5工位的数据- 触发信号上次的值
  11341. /// </summary>
  11342. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  11343. /// <summary>
  11344. /// S5工位的数据(含触发信号)
  11345. /// </summary>
  11346. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  11347. /// <summary>
  11348. /// S5工位的数据- 回写点位
  11349. /// </summary>
  11350. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  11351. /// <summary>
  11352. /// [S5] Tray盘下料装备
  11353. /// </summary>
  11354. /// <param name="plcNo">PLC编号</param>
  11355. //private void ReadStation_S5(int plcNo)
  11356. //{
  11357. // // [S1] Tray盘上料装备
  11358. // // [S2] FCT
  11359. // // [S3] 值板机
  11360. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  11361. // // [S5] Tray盘下料装备
  11362. // /// 上位机心跳
  11363. // /// 获取设备报警数据与状态信息
  11364. // string stationCode = "[S5]";
  11365. // string stationName = "Tray盘下料装备";
  11366. // string stationNameStr = stationCode + stationName;
  11367. // #region 创建字典
  11368. // // 触发信号字典 赋值
  11369. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  11370. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  11371. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  11372. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  11373. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  11374. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  11375. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  11376. // // PLC数据字典 赋值
  11377. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  11378. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  11379. // s5PLCData.Add("e1ProductSN_Check", ""); //
  11380. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  11381. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  11382. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  11383. // s5PLCData.Add("e1PartNo", ""); // 物料码
  11384. // s5PLCData.Add("e1Result", 0); // 产品结果
  11385. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  11386. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  11387. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  11388. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  11389. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  11390. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  11391. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  11392. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  11393. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  11394. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  11395. // #endregion 创建字典
  11396. // while (IsRun)
  11397. // {
  11398. // try
  11399. // {
  11400. // if (!GlobalContext._IsCon_Funs5)
  11401. // {
  11402. // UpdatePLCMonitor(1, plcNo, 0);
  11403. // continue;
  11404. // }
  11405. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  11406. // {
  11407. // Stopwatch stopwatch1 = new Stopwatch();
  11408. // Stopwatch stopwatch2 = new Stopwatch();
  11409. // stopwatch1.Start();
  11410. // stopwatch2.Start();
  11411. // #region 一次性读取所有数据
  11412. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  11413. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  11414. // int[] datas = data1.Concat(data2).ToArray();
  11415. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  11416. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  11417. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  11418. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  11419. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  11420. // s5PLCData["e1MES_FLAG"] = datas[35];
  11421. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  11422. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  11423. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  11424. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  11425. // s5PLCData["e1Result"] = datas[76];
  11426. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  11427. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  11428. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  11429. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  11430. // s5PLCData["e1OEEType"] = datas[109];
  11431. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  11432. // s5PLCData["e1AGVUpStart"] = datas[121];
  11433. // s5PLCData["e1AGVUpEnd"] = datas[122];
  11434. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  11435. // s5PLCData["e1AGVDownStart"] = datas[134];
  11436. // s5PLCData["e1AGVDownEnd"] = datas[135];
  11437. // #endregion 一次性读取所有数据
  11438. // stopwatch2.Stop();
  11439. // #region 回写操作,写后清空flag
  11440. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  11441. // #endregion 回写操作,写后清空flag
  11442. // #region 进站校验
  11443. // try
  11444. // {
  11445. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  11446. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  11447. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  11448. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  11449. // {
  11450. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  11451. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  11452. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  11453. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  11454. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  11455. // }
  11456. // }
  11457. // catch (Exception ex)
  11458. // {
  11459. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  11460. // string str = ex.StackTrace;
  11461. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11462. // }
  11463. // #endregion 进站校验
  11464. // #region 出站接口
  11465. // try
  11466. // {
  11467. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  11468. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  11469. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  11470. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  11471. // {
  11472. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  11473. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  11474. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  11475. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  11476. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  11477. // }
  11478. // }
  11479. // catch (Exception ex)
  11480. // {
  11481. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  11482. // string str = ex.StackTrace;
  11483. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11484. // }
  11485. // #endregion 出站接口
  11486. // #region 节拍接口
  11487. // try
  11488. // {
  11489. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  11490. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  11491. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  11492. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  11493. // {
  11494. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  11495. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  11496. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  11497. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  11498. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  11499. // }
  11500. // }
  11501. // catch (Exception ex)
  11502. // {
  11503. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  11504. // string str = ex.StackTrace;
  11505. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11506. // }
  11507. // #endregion 节拍接口
  11508. // #region AGV上料
  11509. // // AGV上料叫AGV信号
  11510. // try
  11511. // {
  11512. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  11513. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  11514. // if (e1AGVUpCall != e1AGVUpCallOld)
  11515. // {
  11516. // if (e1AGVUpCall == 1) // 0->1
  11517. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  11518. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  11519. // }
  11520. // }
  11521. // catch (Exception ex)
  11522. // {
  11523. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  11524. // string str = ex.StackTrace;
  11525. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11526. // }
  11527. // // AGV上料完成信号
  11528. // try
  11529. // {
  11530. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  11531. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  11532. // if (e1AGVUpEnd != e1AGVUpEndOld)
  11533. // {
  11534. // if (e1AGVUpEnd == 1) // 0->1
  11535. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  11536. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  11537. // }
  11538. // }
  11539. // catch (Exception ex)
  11540. // {
  11541. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  11542. // string str = ex.StackTrace;
  11543. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11544. // }
  11545. // #endregion AGV上料
  11546. // #region AGV下料
  11547. // // AGV下料叫agv信号
  11548. // try
  11549. // {
  11550. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  11551. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  11552. // if (e1AGVDownCall != e1AGVDownCallOld)
  11553. // {
  11554. // if (e1AGVDownCall == 1) // 0->1
  11555. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  11556. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  11557. // }
  11558. // }
  11559. // catch (Exception ex)
  11560. // {
  11561. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  11562. // string str = ex.StackTrace;
  11563. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11564. // }
  11565. // // AGV下料完成信号
  11566. // try
  11567. // {
  11568. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  11569. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  11570. // if (e1AGVDownEnd != e1AGVDownEndOld)
  11571. // {
  11572. // if (e1AGVDownEnd == 1) // 0->1
  11573. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  11574. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  11575. // }
  11576. // }
  11577. // catch (Exception ex)
  11578. // {
  11579. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  11580. // string str = ex.StackTrace;
  11581. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11582. // }
  11583. // #endregion AGV下料
  11584. // #region 心跳
  11585. // try
  11586. // {
  11587. // short states = 0;
  11588. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  11589. // }
  11590. // catch (Exception ex)
  11591. // {
  11592. // string str = ex.StackTrace;
  11593. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11594. // }
  11595. // #endregion 心跳
  11596. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  11597. // stopwatch1.Stop();
  11598. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  11599. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  11600. // }
  11601. // else
  11602. // {
  11603. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  11604. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  11605. // Funs[plcNo].Connect();
  11606. // }
  11607. // }
  11608. // catch (Exception ex)
  11609. // {
  11610. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  11611. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  11612. // Funs[plcNo].ReConnect();
  11613. // }
  11614. // Thread.Sleep(IntervalReadPLC);
  11615. // }
  11616. //}
  11617. /// <summary>
  11618. /// [S5] Tray盘下料装备 - 进站校验
  11619. /// </summary>
  11620. /// <param name="plcNo">PLC编号</param>
  11621. /// <param name="stationNameStr">工站全称</param>
  11622. private void S5进站校验(int plcNo, string stationNameStr)
  11623. {
  11624. Stopwatch stopwatch1 = new Stopwatch();
  11625. Stopwatch stopwatch2 = new Stopwatch();
  11626. try
  11627. {
  11628. stopwatch1.Start();
  11629. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  11630. sn = sn.Replace("\0", "");
  11631. // 获取产品SN By 载具码
  11632. #region 查询载具上的产品信息
  11633. string cavityData = string.Empty;
  11634. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  11635. if (string.IsNullOrEmpty(cavityData))
  11636. cavityData = "";
  11637. if (snResult != 0)
  11638. {
  11639. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11640. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  11641. writeToPLC_Flag1.Adress = 2003;
  11642. writeToPLC_Flag1.Value = (short)6;
  11643. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  11644. stopwatch1.Stop();
  11645. AddMessage(LogType.Info,
  11646. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11647. return;
  11648. }
  11649. string[] cavitySNs = cavityData.Split('.');
  11650. string partNo = string.Empty;
  11651. if (cavitySNs != null && cavitySNs.Length >= 1)
  11652. partNo = cavitySNs[0];
  11653. #endregion 查询载具上的产品信息
  11654. // 产品SN(物料码)校验
  11655. List<TestItem> item = new List<TestItem>();
  11656. item.Add(new TestItem()
  11657. {
  11658. Parameter_name = "载具码",
  11659. Parameter_value = sn,
  11660. });
  11661. item.Add(new TestItem()
  11662. {
  11663. Parameter_name = "载具穴号",
  11664. Parameter_value = "1",
  11665. });
  11666. stopwatch2.Start();
  11667. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  11668. partNo, item, out string errorMsg);
  11669. stopwatch2.Stop();
  11670. short e1MES_FLAG_Check = (short)result;
  11671. // MES_Flag
  11672. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  11673. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11674. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  11675. writeToPLC_Flag.Adress = 2003;
  11676. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  11677. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  11678. }
  11679. catch (Exception ex)
  11680. {
  11681. string str = ex.StackTrace;
  11682. AddMessage_Station(stationNameStr, LogType.Error,
  11683. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  11684. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11685. // MES_Flag
  11686. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  11687. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11688. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  11689. writeToPLC_Flag.Adress = 2003;
  11690. writeToPLC_Flag.Value = (short)6;
  11691. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  11692. }
  11693. stopwatch1.Stop();
  11694. AddMessage(LogType.Info,
  11695. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  11696. stopwatch2.ElapsedMilliseconds + "ms");
  11697. }
  11698. /// <summary>
  11699. /// [S5] Tray盘下料装备 - 出站接口
  11700. /// </summary>
  11701. /// <param name="plcNo"></param>
  11702. /// <param name="stationCode"></param>
  11703. /// <param name="stationName"></param>
  11704. private void S5出站接口(int plcNo, string stationCode, string stationName)
  11705. {
  11706. Stopwatch stopwatch1 = new Stopwatch();
  11707. Stopwatch stopwatch2 = new Stopwatch();
  11708. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  11709. string stationNameStr = stationCode + stationName;
  11710. string processItem = stationName; // 测试项目
  11711. try
  11712. {
  11713. stopwatch1.Start();
  11714. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  11715. //string batch_num = GlobalContext.BatchNumber; // 批次号
  11716. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  11717. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  11718. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  11719. sn = sn.Replace("\0", "");
  11720. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  11721. //partNo = partNo.Replace("\0", "");
  11722. #region 查询载具上的产品信息
  11723. string cavityData = string.Empty;
  11724. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  11725. if (string.IsNullOrEmpty(cavityData))
  11726. cavityData = "";
  11727. if (snResult != 0)
  11728. {
  11729. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11730. writeToPLC_Flag1.Name = "e1MES_FLAG";
  11731. writeToPLC_Flag1.Adress = 2035;
  11732. writeToPLC_Flag1.Value = (short)4;
  11733. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  11734. stopwatch1.Stop();
  11735. AddMessage(LogType.Info,
  11736. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11737. return;
  11738. }
  11739. string[] cavitySNs = cavityData.Split('.');
  11740. string partNo = string.Empty;
  11741. if (cavitySNs != null && cavitySNs.Length >= 1)
  11742. partNo = cavitySNs[0];
  11743. #endregion 查询载具上的产品信息
  11744. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  11745. bool pass = e1Result == 1;
  11746. stopwatch2.Start();
  11747. // 上传MES
  11748. List<TestItem> items = new List<TestItem>();
  11749. items.Add(new TestItem()
  11750. {
  11751. Parameter_name = "载具码",
  11752. Parameter_value = sn,
  11753. Parameter_unit = ""
  11754. });
  11755. items.Add(new TestItem()
  11756. {
  11757. Parameter_name = "载具穴号",
  11758. Parameter_value = "1",
  11759. Parameter_unit = ""
  11760. });
  11761. items.Add(new TestItem()
  11762. {
  11763. Parameter_name = "产品结果",
  11764. Parameter_value = e1Result == 1 ? "OK" : "NG",
  11765. Parameter_unit = ""
  11766. });
  11767. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  11768. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  11769. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  11770. short result = result1 == 1 ? (short)1 : (short)3;
  11771. stopwatch2.Stop();
  11772. #region 存储绑定数据到 边线MES系统中
  11773. if (result == 1)
  11774. {
  11775. // 删除绑定信息
  11776. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  11777. if (resultMesR != 0)
  11778. {
  11779. result = 4;
  11780. AddMessage_Station(stationNameStr, LogType.Error,
  11781. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  11782. }
  11783. }
  11784. #endregion 存储绑定数据到 边线MES系统中
  11785. // MES_Flag 为MES报错
  11786. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11787. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  11788. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11789. writeToPLC_Flag.Name = "e1MES_FLAG";
  11790. writeToPLC_Flag.Adress = 2035;
  11791. writeToPLC_Flag.Value = result;
  11792. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  11793. OnMessage(LogType.Debug,
  11794. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  11795. }
  11796. catch (Exception ex)
  11797. {
  11798. stopwatch2.Restart();
  11799. // MES_Flag 为4上位机报错
  11800. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  11801. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11802. writeToPLC_Flag.Name = "e1MES_FLAG";
  11803. writeToPLC_Flag.Adress = 2035;
  11804. writeToPLC_Flag.Value = (short)4;
  11805. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  11806. stopwatch2.Stop();
  11807. string str = ex.StackTrace;
  11808. AddMessage_Station(stationNameStr, LogType.Error,
  11809. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11810. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11811. }
  11812. stopwatch1.Stop();
  11813. AddMessage(LogType.Info,
  11814. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11815. stopwatch2.ElapsedMilliseconds + "ms");
  11816. }
  11817. /// <summary>
  11818. /// [S5] Tray盘下料装备 - 节拍接口
  11819. /// </summary>
  11820. /// <param name="plcNo">PLC编号</param>
  11821. /// <param name="stationNameStr">工站全称</param>
  11822. //private void S5节拍接口(int plcNo, string stationNameStr)
  11823. //{
  11824. // Stopwatch stopwatch1 = new Stopwatch();
  11825. // Stopwatch stopwatch2 = new Stopwatch();
  11826. // string resultStr = string.Empty;
  11827. // try
  11828. // {
  11829. // stopwatch1.Start();
  11830. // string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  11831. // string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  11832. // e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  11833. // bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  11834. // if (!actionBool)
  11835. // {
  11836. // stopwatch2.Start();
  11837. // // MES_Flag
  11838. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11839. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11840. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  11841. // writeToPLC_Flag1.Adress = 2088;
  11842. // writeToPLC_Flag1.Value = (short)4;
  11843. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  11844. // stopwatch2.Stop();
  11845. // AddMessage(LogType.Info,
  11846. // stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  11847. // "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  11848. // return;
  11849. // }
  11850. // string e1OEEPartNo = string.Empty; // 物料码
  11851. // if (string.IsNullOrEmpty(e1OEEProductSN))
  11852. // {
  11853. // stopwatch2.Start();
  11854. // // MES_Flag
  11855. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11856. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11857. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  11858. // writeToPLC_Flag1.Adress = 2088;
  11859. // writeToPLC_Flag1.Value = (short)1;
  11860. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  11861. // stopwatch2.Stop();
  11862. // AddMessage(LogType.Info,
  11863. // stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11864. // stopwatch2.ElapsedMilliseconds + "ms");
  11865. // return;
  11866. // }
  11867. // else
  11868. // {
  11869. // // 查产品SN
  11870. // e1OEEPartNo = "Test"; // ZS
  11871. // }
  11872. // short e1OEEMES_FLAG = 0;
  11873. // // 上传OEE
  11874. // (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  11875. // e1OEEMES_FLAG = result.Item1;
  11876. // resultStr = result.Item2;
  11877. // stopwatch2.Start();
  11878. // // MES_Flag
  11879. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11880. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11881. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  11882. // writeToPLC_Flag.Adress = 2088;
  11883. // writeToPLC_Flag.Value = e1OEEMES_FLAG;
  11884. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  11885. // stopwatch2.Stop();
  11886. // }
  11887. // catch (Exception ex)
  11888. // {
  11889. // string str = ex.StackTrace;
  11890. // AddMessage_Station(stationNameStr, LogType.Error,
  11891. // $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  11892. // str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11893. // // MES_Flag
  11894. // stopwatch2.Start();
  11895. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  11896. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11897. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  11898. // writeToPLC_Flag.Adress = 2088;
  11899. // writeToPLC_Flag.Value = (short)4;
  11900. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  11901. // stopwatch2.Stop();
  11902. // }
  11903. // stopwatch1.Stop();
  11904. // AddMessage(LogType.Info,
  11905. // stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11906. // stopwatch2.ElapsedMilliseconds + "ms");
  11907. //}
  11908. /// <summary>
  11909. /// [S5] Tray盘下料装备 - AGV上料叫agv
  11910. /// </summary>
  11911. /// <param name="plcNo">PLC编号</param>
  11912. /// <param name="stationNameStr">工站全称</param>
  11913. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  11914. {
  11915. Stopwatch stopwatch1 = new Stopwatch();
  11916. Stopwatch stopwatch2 = new Stopwatch();
  11917. try
  11918. {
  11919. stopwatch1.Start();
  11920. // ZS 呼叫AGV
  11921. short e1AGVUpCall = 2;
  11922. stopwatch2.Start();
  11923. // e1AGVUpCall
  11924. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11925. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11926. writeToPLC_Flag.Name = "e1AGVUpCall";
  11927. writeToPLC_Flag.Adress = 2120;
  11928. writeToPLC_Flag.Value = e1AGVUpCall;
  11929. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  11930. stopwatch2.Stop();
  11931. }
  11932. catch (Exception ex)
  11933. {
  11934. string str = ex.StackTrace;
  11935. AddMessage_Station(stationNameStr, LogType.Error,
  11936. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  11937. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11938. // e1AGVUpCall
  11939. stopwatch2.Start();
  11940. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  11941. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11942. writeToPLC_Flag.Name = "e1AGVUpCall";
  11943. writeToPLC_Flag.Adress = 2120;
  11944. writeToPLC_Flag.Value = (short)4;
  11945. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  11946. stopwatch2.Stop();
  11947. }
  11948. stopwatch1.Stop();
  11949. AddMessage(LogType.Info,
  11950. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11951. stopwatch2.ElapsedMilliseconds + "ms");
  11952. }
  11953. /// <summary>
  11954. /// [S5] Tray盘下料装备 - AGV上料完成
  11955. /// </summary>
  11956. /// <param name="plcNo">PLC编号</param>
  11957. /// <param name="stationNameStr">工站全称</param>
  11958. private void S5AGV上料完成(int plcNo, string stationNameStr)
  11959. {
  11960. Stopwatch stopwatch1 = new Stopwatch();
  11961. Stopwatch stopwatch2 = new Stopwatch();
  11962. try
  11963. {
  11964. stopwatch1.Start();
  11965. // ZS AGV上料完成,让小车离开
  11966. short e1AGVUpEnd = 2;
  11967. stopwatch2.Start();
  11968. // e1AGVUpEnd
  11969. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11970. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11971. writeToPLC_Flag.Name = "e1AGVUpEnd";
  11972. writeToPLC_Flag.Adress = 2122;
  11973. writeToPLC_Flag.Value = e1AGVUpEnd;
  11974. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  11975. stopwatch2.Stop();
  11976. }
  11977. catch (Exception ex)
  11978. {
  11979. string str = ex.StackTrace;
  11980. AddMessage_Station(stationNameStr, LogType.Error,
  11981. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  11982. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11983. // e1AGVUpEnd
  11984. stopwatch2.Start();
  11985. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  11986. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11987. writeToPLC_Flag.Name = "e1AGVUpEnd";
  11988. writeToPLC_Flag.Adress = 2122;
  11989. writeToPLC_Flag.Value = (short)4;
  11990. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  11991. stopwatch2.Stop();
  11992. }
  11993. stopwatch1.Stop();
  11994. AddMessage(LogType.Info,
  11995. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11996. stopwatch2.ElapsedMilliseconds + "ms");
  11997. }
  11998. /// <summary>
  11999. /// [S5] Tray盘下料装备 - AGV下料叫agv
  12000. /// </summary>
  12001. /// <param name="plcNo">PLC编号</param>
  12002. /// <param name="stationNameStr">工站全称</param>
  12003. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  12004. {
  12005. Stopwatch stopwatch1 = new Stopwatch();
  12006. Stopwatch stopwatch2 = new Stopwatch();
  12007. try
  12008. {
  12009. stopwatch1.Start();
  12010. // ZS 呼叫AGV
  12011. short e1AGVDownCall = 2;
  12012. stopwatch2.Start();
  12013. // e1AGVDownCall
  12014. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  12015. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12016. writeToPLC_Flag.Name = "e1AGVDownCall";
  12017. writeToPLC_Flag.Adress = 2133;
  12018. writeToPLC_Flag.Value = e1AGVDownCall;
  12019. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  12020. stopwatch2.Stop();
  12021. }
  12022. catch (Exception ex)
  12023. {
  12024. string str = ex.StackTrace;
  12025. AddMessage_Station(stationNameStr, LogType.Error,
  12026. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  12027. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12028. // e1AGVDownCall
  12029. stopwatch2.Start();
  12030. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  12031. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12032. writeToPLC_Flag.Name = "e1AGVDownCall";
  12033. writeToPLC_Flag.Adress = 2133;
  12034. writeToPLC_Flag.Value = (short)4;
  12035. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  12036. stopwatch2.Stop();
  12037. }
  12038. stopwatch1.Stop();
  12039. AddMessage(LogType.Info,
  12040. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12041. stopwatch2.ElapsedMilliseconds + "ms");
  12042. }
  12043. /// <summary>
  12044. /// [S5] Tray盘下料装备 - AGV下料完成
  12045. /// </summary>
  12046. /// <param name="plcNo">PLC编号</param>
  12047. /// <param name="stationNameStr">工站全称</param>
  12048. private void S5AGV下料完成(int plcNo, string stationNameStr)
  12049. {
  12050. Stopwatch stopwatch1 = new Stopwatch();
  12051. Stopwatch stopwatch2 = new Stopwatch();
  12052. try
  12053. {
  12054. stopwatch1.Start();
  12055. // ZS AGV上料完成,让小车离开
  12056. short e1AGVDownEnd = 2;
  12057. stopwatch2.Start();
  12058. // e1AGVDownEnd
  12059. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  12060. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12061. writeToPLC_Flag.Name = "e1AGVDownEnd";
  12062. writeToPLC_Flag.Adress = 2135;
  12063. writeToPLC_Flag.Value = e1AGVDownEnd;
  12064. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  12065. stopwatch2.Stop();
  12066. }
  12067. catch (Exception ex)
  12068. {
  12069. string str = ex.StackTrace;
  12070. AddMessage_Station(stationNameStr, LogType.Error,
  12071. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  12072. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12073. // e1AGVDownEnd
  12074. stopwatch2.Start();
  12075. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  12076. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12077. writeToPLC_Flag.Name = "e1AGVDownEnd";
  12078. writeToPLC_Flag.Adress = 2135;
  12079. writeToPLC_Flag.Value = (short)4;
  12080. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  12081. stopwatch2.Stop();
  12082. }
  12083. stopwatch1.Stop();
  12084. AddMessage(LogType.Info,
  12085. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12086. stopwatch2.ElapsedMilliseconds + "ms");
  12087. }
  12088. #endregion [S5] Tray盘下料装备
  12089. #endregion PLC5 张超凡
  12090. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  12091. /// <summary>
  12092. /// PLC读取到的数据 -添加数据
  12093. /// </summary>
  12094. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  12095. {
  12096. if (sxPlcData.ContainsKey(newKey))
  12097. sxPlcData[newKey] = newValue;
  12098. else
  12099. sxPlcData.Add(newKey, newValue);
  12100. }
  12101. /// <summary>
  12102. /// PLC需要写入的数据 -添加数据
  12103. /// </summary>
  12104. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey,
  12105. WriteToPLC_Flag newValue)
  12106. {
  12107. if (sxPLCWriteData.ContainsKey(newKey))
  12108. sxPLCWriteData[newKey] = newValue;
  12109. else
  12110. sxPLCWriteData.Add(newKey, newValue);
  12111. }
  12112. /// <summary>
  12113. /// PLC回写操作,写后清空flag
  12114. /// </summary>
  12115. /// <param name="modbusClient">modbus对象</param>
  12116. /// <param name="pLCReadDatas">读取到的数据字典</param>
  12117. /// <param name="pLCWriteDatas">需要写入的数据</param>
  12118. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas,
  12119. ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  12120. {
  12121. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  12122. {
  12123. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  12124. for (int i = 0; i < pLCWriteDatas.Count; i++)
  12125. {
  12126. string mesFlagName = pLCWriteDatas[i].Name;
  12127. int mesFlagAdress = pLCWriteDatas[i].Adress;
  12128. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  12129. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  12130. {
  12131. // 先回写数据
  12132. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  12133. for (int j = 0; j < writeToPLCDatas.Count; j++)
  12134. {
  12135. int mesDataAdress = writeToPLCDatas[j].Adress;
  12136. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  12137. switch (mesDataType)
  12138. {
  12139. case PLCValueType.Short:
  12140. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  12141. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  12142. break;
  12143. case PLCValueType.String:
  12144. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  12145. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  12146. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr,
  12147. mesDataValueStrLength);
  12148. break;
  12149. }
  12150. }
  12151. // 再回写信号
  12152. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  12153. // 存储读取数据的字典
  12154. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  12155. // 存储写入数据的字典 - 清空写入值
  12156. pLCWriteDatas[i].Value = (short)0;
  12157. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  12158. }
  12159. }
  12160. }
  12161. }
  12162. /// <summary>
  12163. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  12164. /// </summary>
  12165. /// <param name="no">3</param>
  12166. /// <param name="stationCode">设备编号</param>
  12167. /// <param name="stationNameStr">设备名称</param>
  12168. /// <param name="plcOrder">车间订单号</param>
  12169. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  12170. {
  12171. try
  12172. {
  12173. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  12174. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  12175. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  12176. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  12177. int result1 = 0;
  12178. switch (stationCode)
  12179. {
  12180. case 2:
  12181. case 3:
  12182. case 4:
  12183. case 6:
  12184. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  12185. break;
  12186. case 102:
  12187. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  12188. break;
  12189. case 103:
  12190. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  12191. break;
  12192. case 104:
  12193. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  12194. break;
  12195. case 106:
  12196. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  12197. break;
  12198. default:
  12199. // MES_Flag 为“6未找到正确设备编号”
  12200. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  12201. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  12202. return;
  12203. }
  12204. short result = result1 == 1 ? (short)1 : (short)2;
  12205. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  12206. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  12207. }
  12208. catch (Exception ex)
  12209. {
  12210. // MES_Flag 为2上位机报错
  12211. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  12212. string str = ex.StackTrace;
  12213. AddMessage_Station(stationNameStr, LogType.Error,
  12214. $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  12215. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12216. }
  12217. }
  12218. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  12219. #region UI刷新
  12220. /// <summary>
  12221. /// 更新商品信息的UI + 下发产品信息(SN)
  12222. /// </summary>
  12223. private void UpdateProductInfo()
  12224. {
  12225. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  12226. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  12227. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  12228. //txt_CurSupplierCode.Text = ""; // 供应商代号
  12229. }
  12230. /// <summary>
  12231. /// 更新PLC连接状态的UI
  12232. /// </summary>
  12233. /// <param name="no">PLC编号</param>
  12234. /// <param name="status">状态</param>
  12235. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  12236. {
  12237. if (this != null && !this.IsDisposed)
  12238. {
  12239. switch (imgNo)
  12240. {
  12241. case 1:
  12242. this.BeginInvoke(new Action(() => { picPLC.Image = imageListState.Images[status]; }));
  12243. break;
  12244. case 2:
  12245. this.BeginInvoke(new Action(() => { pictureBox2.Image = imageListState.Images[status]; }));
  12246. break;
  12247. case 3:
  12248. this.BeginInvoke(new Action(() => { pictureBox3.Image = imageListState.Images[status]; }));
  12249. break;
  12250. case 4:
  12251. this.BeginInvoke(new Action(() => { pictureBox4.Image = imageListState.Images[status]; }));
  12252. break;
  12253. case 5:
  12254. this.BeginInvoke(new Action(() => { pictureBox5.Image = imageListState.Images[status]; }));
  12255. break;
  12256. case 6:
  12257. this.BeginInvoke(new Action(() => { pictureBox6.Image = imageListState.Images[status]; }));
  12258. break;
  12259. case 7:
  12260. this.BeginInvoke(new Action(() => { pictureBox7.Image = imageListState.Images[status]; }));
  12261. break;
  12262. case 8:
  12263. this.BeginInvoke(new Action(() => { pictureBox8.Image = imageListState.Images[status]; }));
  12264. break;
  12265. default:
  12266. break;
  12267. }
  12268. }
  12269. Task.Run(() => // 更新PLC交互页的指示灯
  12270. {
  12271. try
  12272. {
  12273. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  12274. {
  12275. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  12276. }
  12277. }
  12278. catch
  12279. {
  12280. }
  12281. });
  12282. }
  12283. #endregion UI刷新
  12284. #region 日志
  12285. /// <summary>
  12286. /// 添加各工位运行日志(同步至PLC交互页面)
  12287. /// </summary>
  12288. /// <param name="stationNameStr">工站名称</param>
  12289. /// <param name="logType">日志类型</param>
  12290. /// <param name="message">日志内容</param>
  12291. /// <param name="snNumber">产品数字SN</param>
  12292. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  12293. {
  12294. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")))
  12295. {
  12296. AddMessage(logType, message); // 首页展示+日志记录
  12297. }
  12298. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  12299. {
  12300. StationName = stationNameStr,
  12301. SnNumber = snNumber,
  12302. Message = message,
  12303. CreateTime = DateTime.Now
  12304. };
  12305. // PLC交互页展示
  12306. Task.Run(() =>
  12307. {
  12308. try
  12309. {
  12310. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  12311. {
  12312. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  12313. }
  12314. }
  12315. catch
  12316. {
  12317. }
  12318. });
  12319. }
  12320. /// <summary>
  12321. /// 添加运行日志
  12322. /// </summary>
  12323. /// <param name="logType">日志类型</param>
  12324. /// <param name="message">日志内容</param>
  12325. public void AddMessage(LogType logType, string message)
  12326. {
  12327. OnMessage(logType, message);
  12328. string date = DateTime.Now.ToString("yyyy/MM/dd");
  12329. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  12330. string msgShow = time + "--> " + message + "\r\n";
  12331. this.BeginInvoke(new Action(() =>
  12332. {
  12333. systemLog.Rows.Insert(0, date, time, message);
  12334. if (systemLog.Rows.Count >= 100)
  12335. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  12336. }));
  12337. }
  12338. /// <summary>
  12339. /// 添加运行日志-保存
  12340. /// </summary>
  12341. /// <param name="logType">日志类型</param>
  12342. /// <param name="message">日志内容</param>
  12343. private void OnMessage(LogType logType, string msg)
  12344. {
  12345. MessageEvent?.Invoke(logType, msg);
  12346. }
  12347. /// <summary>
  12348. /// 保存PLC写入日志
  12349. /// </summary>
  12350. /// <param name="logType"></param>
  12351. /// <param name="logValue"></param>
  12352. private void WritePLCLog(LogType logType, string logValue)
  12353. {
  12354. switch ((int)logType)
  12355. {
  12356. case 0:
  12357. _PLCLogNet.WriteDebug(logValue);
  12358. break;
  12359. case 1:
  12360. _PLCLogNet.WriteInfo(logValue);
  12361. break;
  12362. case 2:
  12363. _PLCLogNet.WriteWarn(logValue);
  12364. break;
  12365. case 3:
  12366. _PLCLogNet.WriteError(logValue);
  12367. break;
  12368. default:
  12369. _PLCLogNet.WriteFatal(logValue);
  12370. break;
  12371. }
  12372. }
  12373. /// <summary>
  12374. /// IOT Mqtt回调方法- With DataId
  12375. /// </summary>
  12376. /// <param name="id"></param>
  12377. /// <param name="v"></param>
  12378. /// <param name="dataId"></param>
  12379. public void CallbackWithDataId(string id, string msg, string dataId)
  12380. {
  12381. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  12382. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  12383. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  12384. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  12385. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  12386. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  12387. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  12388. }
  12389. /// <summary>
  12390. /// AGV Mqtt回调方法- 记录Log并处理数据
  12391. /// </summary>
  12392. /// <param name="obj"></param>
  12393. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  12394. {
  12395. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  12396. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  12397. // 接收到的信息
  12398. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  12399. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  12400. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  12401. {
  12402. }
  12403. }
  12404. #endregion 日志
  12405. //private void button1_Click(object sender, EventArgs e)
  12406. //{
  12407. // OpenDailogFalg=true;
  12408. // if (OpenDailogFalg)
  12409. // {
  12410. // using (var dialog = new BandBarodeDialog())
  12411. // {
  12412. // string strCarrierBarcode = "N801A-003";
  12413. // dialog._CarrierBarcode = strCarrierBarcode;
  12414. // string sn = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  12415. // dialog._ProductBarcode = sn;
  12416. // var rs = dialog.ShowDialog();
  12417. // if (rs == DialogResult.OK)
  12418. // {
  12419. // AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  12420. // OpenDailogFalg = false;//关闭扫码
  12421. // }
  12422. // }
  12423. // }
  12424. //}
  12425. }
  12426. }