Form_Home.cs 723 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660
  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. using static MainForm.ClassFile.XiaomiClass.MesHelper;
  52. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
  53. using System.Drawing.Imaging;
  54. using System.Drawing;
  55. using ICSharpCode.SharpZipLib.Zip;
  56. using System.Text.RegularExpressions;
  57. using System.Text;
  58. using SixLabors.ImageSharp;
  59. /*
  60. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  61. */
  62. namespace MainForm
  63. {
  64. /// <summary>
  65. /// 记录日志的委托
  66. /// </summary>
  67. /// <param name="logType">日志类型</param>
  68. /// <param name="message">日志信息</param>
  69. public delegate void HomeMessageHandler(LogType logType, string message);
  70. /// <summary>
  71. /// 主页窗体
  72. /// </summary>
  73. public partial class Form_Home : Form
  74. {
  75. #region 常量
  76. //文本常量
  77. private const string Head = "开始采集";
  78. private const string Tail = "采集完成";
  79. private const string Body = "工位出站数据";
  80. private const string BodyCheck = "工位点检数据";
  81. private const string BodyRun = "整线运行数据";
  82. private const string BodyAlarm = "整线报警数据";
  83. #endregion 常量
  84. #region 变量
  85. /// <summary>
  86. /// 委托-记录日志的方法
  87. /// </summary>
  88. public event HomeMessageHandler MessageEvent;
  89. /// <summary>
  90. /// 日志接口
  91. /// </summary>
  92. ILogNet _PLCLogNet;
  93. /// <summary>
  94. /// 用于记录IOT MQTT日志
  95. /// </summary>
  96. ILogNet _IOTMqttLogNet;
  97. /// <summary>
  98. /// 用于记录AGV MQTT日志
  99. /// </summary>
  100. ILogNet _AGVMqttLogNet;
  101. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  102. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  103. // 间隔时间
  104. private int IntervalReadPLC = 300; //ms 读PLC
  105. private int IntervalMonitorMES = 1000; //ms MES心跳
  106. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  107. /// <summary>
  108. /// 设备报警数据
  109. /// </summary>
  110. uint[] _FaultDatas = { };
  111. uint[] _FaultDatas_Old = { };
  112. uint[] _FaultDatas2 = { };
  113. uint[] _FaultDatas_Old2 = { };
  114. // 软件状态
  115. private bool IsRun = true;
  116. #region PLC 与 TCP对象
  117. // 定义一个字典,存plc对象(通讯)
  118. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  119. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  120. // 定义TCPClient对象列表
  121. Dictionary<int, HPSocket_TcpClientHelper>
  122. _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  123. // 定义MQTTHelper对象
  124. MQTTHelper _MQTTHelper = new MQTTHelper();
  125. #endregion PLC 与 TCP对象
  126. /// <summary>
  127. /// 上次的设备运行信息
  128. /// </summary>
  129. private string lineWorkingData1_OldStr = string.Empty;
  130. /// <summary>
  131. /// 设备报警字典-当前结果
  132. /// Dictionary<工位代码,List<报警信息>>
  133. /// </summary>
  134. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  135. public Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  136. /// <summary>
  137. /// 单机用-设备状态
  138. /// </summary>
  139. //XiaomiDeviceState xmDeviceState = XiaomiDeviceState.Uninitialized;
  140. XiaomiDeviceStateData xmDeviceStateData = new XiaomiDeviceStateData();
  141. private int test_item_num = 0; //iot 过站数据序号
  142. public static string uuid = ""; //单工位或左工位
  143. public static string uuid2 = ""; //右工位
  144. private bool inpass = false; //保存进站测试状态
  145. public static XiaoMiParm xiaomiParm = new XiaoMiParm();
  146. //记录上传附件的信息
  147. public static FileUpload_FileData fileUploadData = new FileUpload_FileData();
  148. #endregion 变量
  149. #region 窗体基础事件
  150. /// <summary>
  151. /// 初始化
  152. /// </summary>
  153. public Form_Home()
  154. {
  155. InitializeComponent();
  156. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  157. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  158. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  159. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  160. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  161. }
  162. /// <summary>
  163. /// 窗体加载事件
  164. /// </summary>
  165. public void Form_Home_Load(object sender, EventArgs e)
  166. {
  167. try
  168. {
  169. AddMessage(LogType.Info, "开始初始化程序");
  170. //组建plc对象字典
  171. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  172. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  173. if (GlobalContext.IsUsePLC1)
  174. {
  175. GlobalContext.IsUsePLCNow = 1;
  176. GlobalContext.IsUseStationName = "[OP10]壳体清洁上料";
  177. FunsEip.Add(GlobalContext.IsUsePLCNow,
  178. new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  179. }
  180. if (GlobalContext.IsUsePLC2)
  181. {
  182. GlobalContext.IsUsePLCNow = 2;
  183. GlobalContext.IsUseStationName = "[OP20]上盖板上料装备";
  184. FunsEip.Add(GlobalContext.IsUsePLCNow,
  185. new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  186. }
  187. if (GlobalContext.IsUsePLC3)
  188. {
  189. GlobalContext.IsUsePLCNow = 3;
  190. GlobalContext.IsUseStationName = "[OP30]点散热胶装备";
  191. FunsEip.Add(GlobalContext.IsUsePLCNow,
  192. new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  193. }
  194. if (GlobalContext.IsUsePLC4)
  195. {
  196. GlobalContext.IsUsePLCNow = 4;
  197. GlobalContext.IsUseStationName = "[OP40]胶线检测";
  198. FunsEip.Add(GlobalContext.IsUsePLCNow,
  199. new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  200. }
  201. if (GlobalContext.IsUsePLC5)
  202. {
  203. GlobalContext.IsUsePLCNow = 5;
  204. GlobalContext.IsUseStationName = "[OP50]ADD板上料组装装备";
  205. FunsEip.Add(GlobalContext.IsUsePLCNow,
  206. new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  207. }
  208. if (GlobalContext.IsUsePLC6)
  209. {
  210. GlobalContext.IsUsePLCNow = 6;
  211. GlobalContext.IsUseStationName = "[OP70]组上盖板";
  212. FunsEip.Add(GlobalContext.IsUsePLCNow,
  213. new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  214. }
  215. if (GlobalContext.IsUsePLC7)
  216. {
  217. GlobalContext.IsUsePLCNow = 7;
  218. GlobalContext.IsUseStationName = "[OP80]上盖板锁螺丝";
  219. FunsEip.Add(GlobalContext.IsUsePLCNow,
  220. new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  221. }
  222. if (GlobalContext.IsUsePLC8)
  223. {
  224. GlobalContext.IsUsePLCNow = 8;
  225. GlobalContext.IsUseStationName = "[OP90]NG下料";
  226. FunsEip.Add(GlobalContext.IsUsePLCNow,
  227. new Inovance_EIP(GlobalContext.PC8Address,
  228. GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  229. }
  230. if (GlobalContext.IsUsePLC9)
  231. {
  232. GlobalContext.IsUsePLCNow = 9;
  233. GlobalContext.IsUseStationName = "[OP100]半成品下料";
  234. FunsEip.Add(GlobalContext.IsUsePLCNow,
  235. new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  236. }
  237. (bool, string) DicResult = InitalDicAlarm(); // 实例化报警字典
  238. AddMessage(LogType.Info, DicResult.Item2);
  239. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  240. {
  241. if (plcEIP != null)
  242. {
  243. try
  244. {
  245. (int, string) result = plcEIP.Connect();
  246. }
  247. catch (Exception ex)
  248. {
  249. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  250. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
  251. MessageBoxOptions.ServiceNotification);
  252. }
  253. }
  254. }
  255. // 采集任务
  256. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  257. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  258. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  259. if (GlobalContext.IsUsePLC1)
  260. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  261. if (GlobalContext.IsUsePLC2)
  262. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  263. if (GlobalContext.IsUsePLC3)
  264. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  265. if (GlobalContext.IsUsePLC4)
  266. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  267. if (GlobalContext.IsUsePLC5)
  268. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  269. if (GlobalContext.IsUsePLC6)
  270. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  271. if (GlobalContext.IsUsePLC7)
  272. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  273. if (GlobalContext.IsUsePLC8)
  274. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  275. if (GlobalContext.IsUsePLC9)
  276. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  277. #region 初始化
  278. try
  279. {
  280. // 开启MES(Http)
  281. if (GlobalContext.IsUseMES)
  282. {
  283. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  284. if (mesret)
  285. {
  286. picMESStatus.Image = imageListState.Images[1];
  287. GlobalContext.MESIsConnect = true;
  288. AddMessage(LogType.Info, "小米MES初始连接成功!");
  289. }
  290. else
  291. {
  292. picMESStatus.Image = imageListState.Images[0];
  293. GlobalContext.MESIsConnect = false;
  294. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  295. }
  296. }
  297. // 开启IOT(MQTT)
  298. if (GlobalContext.IsUseIot)
  299. {
  300. string addr = GlobalContext.MQTTServerHost;
  301. int port = GlobalContext.MQTTServerPort;
  302. //生产环境需要修改
  303. (int, string) qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666,
  304. GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  305. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult.Item1;
  306. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  307. {
  308. picIot.Image = imageListState.Images[1];
  309. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  310. // 设置回调函数
  311. //XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  312. // 配置参数
  313. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  314. // fds
  315. param.parameter.fds.address = GlobalContext.address;
  316. param.parameter.fds.appId = GlobalContext.appId;
  317. param.parameter.fds.appKey = GlobalContext.appKey;
  318. // mes
  319. param.parameter.mes.address = GlobalContext.ServerIp;
  320. param.parameter.mes.appId = GlobalContext.MESAppId;
  321. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  322. // mqtt
  323. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  324. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  325. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  326. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  327. // 设备配置
  328. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  329. if (GlobalContext.IsUsePLC1)
  330. {
  331. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  332. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  333. xiaomiParm.workstation = GlobalContext.S1_work_station; //工站
  334. }
  335. if (GlobalContext.IsUsePLC2)
  336. {
  337. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  338. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  339. xiaomiParm.workstation = GlobalContext.S2_work_station; //工站
  340. }
  341. if (GlobalContext.IsUsePLC3)
  342. {
  343. param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
  344. //param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
  345. }
  346. if (GlobalContext.IsUsePLC4)
  347. {
  348. param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
  349. param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
  350. xiaomiParm.workstation = GlobalContext.s4_work_station; //工站
  351. }
  352. if (GlobalContext.IsUsePLC5)
  353. {
  354. param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
  355. param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
  356. xiaomiParm.workstation = GlobalContext.s5_work_station; //工站
  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. xiaomiParm.workstation = GlobalContext.s6_work_station; //工站
  363. }
  364. if (GlobalContext.IsUsePLC7)
  365. {
  366. param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  367. //param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  368. xiaomiParm.stationCode = GlobalContext.s7_1_station;
  369. }
  370. if (GlobalContext.IsUsePLC8)
  371. {
  372. param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
  373. param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
  374. xiaomiParm.workstation = GlobalContext.s8_work_station; //工站
  375. }
  376. if (GlobalContext.IsUsePLC9)
  377. {
  378. param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
  379. param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
  380. xiaomiParm.workstation = GlobalContext.s9_work_station; //工站
  381. }
  382. param.parameter.equipment.project = GlobalContext.Project_Code;
  383. param.parameter.equipment.productMode = "debug";
  384. param.parameter.other.logLevel = 0;
  385. param.parameter.other.LogPath = GlobalContext.MqttLogDir;
  386. XiaomiMqttClient_Extend.ParameterConfig(param);
  387. //保存全局变量
  388. xiaomiParm.stationCode = param.parameter.equipment.stationCode;
  389. xiaomiParm.deviceCode = param.parameter.equipment.deviceCode;
  390. }
  391. else
  392. {
  393. picIot.Image = imageListState.Images[0];
  394. AddMessage(LogType.Info,
  395. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  396. }
  397. }
  398. // 开启AGV(Http与MQTT)
  399. if (GlobalContext.IsUseAGV)
  400. {
  401. // AGV HTTP
  402. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  403. if (mesret1)
  404. {
  405. picAgvHttp.Image = imageListState.Images[1];
  406. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  407. }
  408. else
  409. {
  410. picAgvHttp.Image = imageListState.Images[0];
  411. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  412. }
  413. string agvMqttIp = GlobalContext.MQTTServerHost;
  414. int agvMqttPort = GlobalContext.MQTTServerPort;
  415. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  416. ResultData_MQTT result_MQTT = _MQTTHelper
  417. .CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  418. // AGV MQTT
  419. if (result_MQTT.ResultCode == 1)
  420. {
  421. picAgvMqtt.Image = imageListState.Images[1];
  422. GlobalContext.AGVMQTTIsConnect = true;
  423. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  424. ResultData_MQTT result =
  425. XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  426. AddMessage(LogType.Info,
  427. $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  428. }
  429. else
  430. {
  431. picAgvMqtt.Image = imageListState.Images[0];
  432. GlobalContext.AGVMQTTIsConnect = false;
  433. AddMessage(LogType.Info,
  434. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  435. }
  436. }
  437. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  438. Task.Run(MonitorMESConnect);
  439. // 查询PLC连接状态
  440. foreach (int plcNo in FunsEip.Keys)
  441. {
  442. bool connected = FunsEip[plcNo].IsConnected;
  443. if (connected)
  444. {
  445. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  446. AddMessage(LogType.Info, msg);
  447. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  448. }
  449. else
  450. {
  451. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  452. AddMessage(LogType.Info, msg);
  453. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  454. }
  455. }
  456. // PLC4时 初始化扫码器TCP
  457. //if (GlobalContext.IsUsePLC4)
  458. // HpTCPClientInit();
  459. // 开启PLC的业务处理线程-监听PLC点位+状态
  460. foreach (Task task in TaskReadProcess)
  461. {
  462. if (task != null)
  463. task.Start();
  464. }
  465. //// 开启iot的线程
  466. TaskReadAlarm.Start();
  467. ////下传MES信息给1工位(先判断下plc对象数量)
  468. //if (Funs.Count > 1)
  469. // DownLoadProductInfo(1);
  470. if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  471. {
  472. //state_l.Text = "设备状态(左):";
  473. //state_r.Text = "设备状态(右):";
  474. //state_r.Visible = true;
  475. //lblDeviceStates2.Visible = true;
  476. }
  477. //上传操作记录
  478. operateToIot("startup", "开启");
  479. //上传装备配置
  480. deviceConfigToIot("project_name", GlobalContext.Project_Code);
  481. AddMessage(LogType.Info, "程序初始化完成");
  482. }
  483. catch (Exception ex)
  484. {
  485. string str = ex.StackTrace;
  486. this.BeginInvoke(new Action(() =>
  487. {
  488. AddMessage(LogType.Error,
  489. "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  490. str.Length - str.LastIndexOf("\\") - 1));
  491. }));
  492. }
  493. #endregion
  494. }
  495. catch (Exception ex)
  496. {
  497. string str = ex.StackTrace;
  498. OnMessage(LogType.Info,
  499. "主窗体的首页初始化出错!异常位置:" +
  500. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" +
  501. ex.Message.ToString());
  502. if (ex.Message != null && ex.Message.Contains("timed out"))
  503. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  504. else
  505. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  506. }
  507. }
  508. /// <summary>
  509. /// 窗体关闭事件
  510. /// </summary>
  511. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  512. {
  513. Closed2();
  514. }
  515. public void Closed2()
  516. {
  517. try
  518. {
  519. IsRun = false;
  520. Thread.Sleep(IntervalReadPLC);
  521. // 断开TCP
  522. int count = _HPSocket_TcpClients.Count();
  523. for (int i = 0; i < count; i++)
  524. {
  525. try
  526. {
  527. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  528. {
  529. _HPSocket_TcpClients[i].Stop();
  530. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  531. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  532. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  533. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  534. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  535. }
  536. }
  537. catch
  538. {
  539. }
  540. }
  541. // 关闭Iot
  542. try
  543. {
  544. XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath,
  545. GlobalContext.MqttServerName);
  546. }
  547. catch
  548. {
  549. }
  550. // 关闭AGV Mqtt
  551. try
  552. {
  553. _MQTTHelper.DisconnectAsync_Client().Wait();
  554. }
  555. catch
  556. {
  557. }
  558. }
  559. catch
  560. {
  561. }
  562. }
  563. #endregion 窗体基础事件
  564. #region 监控MES状态
  565. /// <summary>
  566. /// 监控MES连接状态
  567. /// </summary>
  568. private void MonitorMESConnect()
  569. {
  570. while (IsRun) // 运行被控线程
  571. {
  572. try
  573. {
  574. // 开启MES(Http)
  575. if (GlobalContext.IsUseMES)
  576. {
  577. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  578. if (mesret)
  579. {
  580. picMESStatus.Image = imageListState.Images[1];
  581. GlobalContext.MESIsConnect = true;
  582. }
  583. else
  584. {
  585. picMESStatus.Image = imageListState.Images[0];
  586. GlobalContext.MESIsConnect = false;
  587. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  588. }
  589. }
  590. // 开启IOT(MQTT)
  591. if (GlobalContext.IsUseIot)
  592. {
  593. bool iIot = XiaomiMqttClient.IsOpen;
  594. if (iIot)
  595. picIot.Image = imageListState.Images[1];
  596. else
  597. {
  598. picIot.Image = imageListState.Images[0];
  599. OnMessage(LogType.Info,
  600. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  601. }
  602. }
  603. // 开启AGV(Http与MQTT)
  604. if (GlobalContext.IsUseAGV)
  605. {
  606. // AGV Http
  607. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  608. if (mesret1)
  609. picAgvHttp.Image = imageListState.Images[1];
  610. else
  611. {
  612. picAgvHttp.Image = imageListState.Images[0];
  613. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  614. }
  615. // AGV MQTT
  616. if (GlobalContext.AGVMQTTIsConnect)
  617. picAgvMqtt.Image = imageListState.Images[1];
  618. else
  619. {
  620. picAgvMqtt.Image = imageListState.Images[0];
  621. OnMessage(LogType.Info,
  622. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  623. }
  624. }
  625. }
  626. catch (Exception ex)
  627. {
  628. string str = ex.StackTrace;
  629. AddMessage(LogType.Error,
  630. "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  631. str.Length - str.LastIndexOf("\\") - 1));
  632. }
  633. Thread.Sleep(IntervalMonitorMES);
  634. }
  635. }
  636. #endregion 监控MES连接状态
  637. #region 采集设备状态、运行数据、报警数据
  638. /// <summary>
  639. /// 请求设备状态 5000
  640. /// </summary>
  641. /// <param name="no">1</param>
  642. /// <param name="stationNameStr"></param>
  643. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  644. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  645. {
  646. try
  647. {
  648. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  649. {
  650. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  651. return result;
  652. }
  653. else
  654. {
  655. return 0;
  656. }
  657. }
  658. catch (Exception ex)
  659. {
  660. string str = ex.StackTrace;
  661. AddMessage_Station(stationNameStr, LogType.Error,
  662. "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  663. str.Length - str.LastIndexOf("\\") - 1));
  664. return 0;
  665. }
  666. }
  667. /// <summary>
  668. /// 检查是否可采集点检数据 - 不取新值
  669. /// 5000不为1时可点检
  670. /// </summary>
  671. /// <returns></returns>
  672. public bool CheckCanSpotcheck1(int deviceState)
  673. {
  674. //return true;
  675. //D5000 = 1,代表设备控制状态处于运行状态
  676. //D5000 = 2, 代表设备控制状态处于故障状态
  677. //D5000 = 3,代表设备控制状态处于缺料状态
  678. //D5000 = 4, 代表设备控制状态处于待机状态
  679. //D5000 = 5,代表设备控制状态处于维修状态
  680. return deviceState != 1;
  681. }
  682. /// <summary>
  683. /// 检查是否可采集产品数据 - 不取新值
  684. /// </summary>
  685. /// <returns></returns>
  686. public bool CheckCanCollData(int deviceState)
  687. {
  688. return deviceState == 0; // 点检时该值不为0
  689. }
  690. /// <summary>
  691. /// 采集到的设备状态
  692. /// </summary>
  693. private string _DeviceStates = "未知状态";
  694. private string _DeviceStates_Old = "未知状态";
  695. private string _DeviceStates2 = "未知状态";
  696. private string _DeviceStates_Old2 = "未知状态";
  697. private static string AlarmStateCode=""; //记录出发故障时的其中一笔警报编码,上传设备状态用
  698. private static string AlarmStateName = ""; //记录出发故障时的其中一笔警报名称,上传设备状态用
  699. private static string AlarmStateTime = ""; //记录出发故障时的其中一笔警报时间,上传设备状态用
  700. /// <summary>
  701. /// 获取设备报警数据与获取设备运行信息
  702. /// </summary>
  703. private async void ReadAlarmAllPLC()
  704. {
  705. /// 获取设备报警数据与状态信息
  706. string stationNameStr = "获取设备报警数据与状态信息";
  707. // 已连接到PLC
  708. while (IsRun)
  709. {
  710. try
  711. {
  712. #region 报警数据
  713. try
  714. {
  715. //_FaultDatas = new uint[] { 4, 0, 30, 10 };
  716. if (_FaultDatas.Length > 0)
  717. {
  718. ReadPLCAlarmToIot(_FaultDatas, _FaultDatas_Old, stationNameStr,"left");
  719. }
  720. else
  721. {
  722. AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!");
  723. }
  724. if (_FaultDatas2.Length > 0)
  725. {
  726. ReadPLCAlarmToIot(_FaultDatas2, _FaultDatas_Old2, stationNameStr,"right");
  727. }
  728. else
  729. {
  730. AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!");
  731. }
  732. }
  733. catch (Exception ex)
  734. {
  735. string str = ex.StackTrace;
  736. AddMessage_Station(stationNameStr, LogType.Error,
  737. $"【报警日志】{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" +
  738. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  739. }
  740. #endregion 报警数据
  741. #region 设备状态
  742. //if (!GlobalContext._IsCon_plc1Alarm)
  743. //{
  744. // UpdatePLCMonitor(1, -2, 0);
  745. // continue;
  746. //}
  747. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  748. {
  749. if (plcEIP != null)
  750. {
  751. if (plcEIP.IsConnected)
  752. {
  753. #region 主页展示设备运行状态并上传到IOT中,有双工位left就是左工位,没有双工位left就是单工位
  754. switch (xmDeviceStateData.left)
  755. {
  756. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  757. _DeviceStates = "未初始化状态";
  758. lblDeviceStates.Text = _DeviceStates;
  759. break;
  760. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  761. _DeviceStates = "初始化状态";
  762. lblDeviceStates.Text = _DeviceStates;
  763. break;
  764. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  765. _DeviceStates = "初始化完成状态";
  766. lblDeviceStates.Text = _DeviceStates;
  767. break;
  768. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  769. _DeviceStates = "运行状态";
  770. lblDeviceStates.Text = _DeviceStates;
  771. break;
  772. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  773. _DeviceStates = "暂停状态";
  774. lblDeviceStates.Text = _DeviceStates;
  775. break;
  776. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  777. _DeviceStates = "故障状态";
  778. lblDeviceStates.Text = _DeviceStates;
  779. break;
  780. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  781. _DeviceStates = "警报状态";
  782. lblDeviceStates.Text = _DeviceStates;
  783. break;
  784. }
  785. if (!_DeviceStates.Equals(_DeviceStates_Old))
  786. {
  787. var iotResult =
  788. SaveDeviceStateData(stationNameStr, xmDeviceStateData.left, "left"); // 上传+保存
  789. if (iotResult.Item1 == 1)
  790. {
  791. _DeviceStates_Old = _DeviceStates;
  792. AddMessage_Station(stationNameStr, LogType.Info,
  793. "【设备状态】" + stationNameStr + $"_上传设备状态到Iot成功!");
  794. }
  795. else
  796. AddMessage_Station(stationNameStr, LogType.Info,
  797. "【设备状态】" + stationNameStr +
  798. $"_上传设备状态到Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  799. }
  800. #endregion 主页展示设备运行状态并上传到IOT中
  801. #region 右工位
  802. //if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  803. //{
  804. // switch (xmDeviceStateData.right)
  805. // {
  806. // case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  807. // _DeviceStates2 = "未初始化状态";
  808. // lblDeviceStates2.Text = _DeviceStates2;
  809. // break;
  810. // case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  811. // _DeviceStates2 = "初始化状态";
  812. // lblDeviceStates2.Text = _DeviceStates2;
  813. // break;
  814. // case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  815. // _DeviceStates2 = "初始化完成状态";
  816. // lblDeviceStates2.Text = _DeviceStates2;
  817. // break;
  818. // case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  819. // _DeviceStates2 = "运行状态";
  820. // lblDeviceStates2.Text = _DeviceStates2;
  821. // break;
  822. // case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  823. // _DeviceStates2 = "暂停状态";
  824. // lblDeviceStates2.Text = _DeviceStates2;
  825. // break;
  826. // case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  827. // _DeviceStates2 = "故障状态";
  828. // lblDeviceStates2.Text = _DeviceStates2;
  829. // break;
  830. // case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  831. // _DeviceStates2 = "警报状态";
  832. // lblDeviceStates2.Text = _DeviceStates2;
  833. // break;
  834. // }
  835. // if (!_DeviceStates2.Equals(_DeviceStates_Old2))
  836. // {
  837. // var iotResult = SaveDeviceStateData(stationNameStr, xmDeviceStateData.left,
  838. // "right"); // 上传+保存
  839. // if (iotResult.Item1 == 1)
  840. // {
  841. // _DeviceStates_Old2 = _DeviceStates2;
  842. // AddMessage_Station(stationNameStr, LogType.Info,
  843. // "【设备状态】" + stationNameStr + $"_上传Iot成功!");
  844. // }
  845. // else
  846. // AddMessage_Station(stationNameStr, LogType.Info,
  847. // "【设备状态】" + stationNameStr +
  848. // $"_上传Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  849. // }
  850. //}
  851. #endregion 右工位
  852. }
  853. }
  854. }
  855. #endregion
  856. }
  857. catch (Exception ex)
  858. {
  859. //AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  860. AddMessage_Station(stationNameStr, LogType.Error,
  861. $"PLC1_{stationNameStr}_采集运行数据与报警数据出错!错误信息:" + ex.Message.ToString());
  862. }
  863. Thread.Sleep(IntervalAlarm);
  864. }
  865. }
  866. #endregion 轮询PLC
  867. #region 下发订单信息
  868. ///// <summary>
  869. ///// 壳体上料(下发工单)的交互逻辑
  870. ///// </summary>
  871. ///// <param name="no"></param>
  872. ///// <exception cref="NotImplementedException"></exception>
  873. //private void ReadStation_DownOrderInfo(int plcNo)
  874. //{
  875. // // [S1] Tray盘上料装备(板测)
  876. // // [S2] FCT(板测)
  877. // // [S3] 值板机
  878. // // [S4] 取放桁架
  879. // // [S5] Tray盘下料装备
  880. // /// 上位机心跳
  881. // /// 获取设备报警数据与状态信息
  882. // string stationNameStr = "[S0]壳体上料";
  883. // while (IsRun)
  884. // {
  885. // try
  886. // {
  887. // if (!GlobalContext._IsCon_Funs1)
  888. // {
  889. // UpdatePLCMonitor(plcNo, 0);
  890. // continue;
  891. // }
  892. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  893. // {
  894. // #region 壳体上料(下发工单)
  895. // try
  896. // {
  897. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  898. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  899. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  900. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  901. // // 重置数据和信号
  902. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  903. // {
  904. // // 清空写给PLC的数据
  905. // int[] i497 = new int[1] { 0 };
  906. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  907. // // MES_Flag重置为0
  908. // int[] i500 = new int[1] { 0 };
  909. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  910. // }
  911. // }
  912. // catch (Exception ex)
  913. // {
  914. // string str = ex.StackTrace;
  915. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  916. // }
  917. // #endregion 壳体上料(下发工单)
  918. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  919. // }
  920. // else
  921. // {
  922. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  923. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  924. //
  925. // Funs[plcNo].Connect();
  926. // }
  927. // }
  928. // catch (Exception ex)
  929. // {
  930. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  931. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  932. //
  933. // Funs[plcNo].ReConnect();
  934. // }
  935. // Thread.Sleep(IntervalReadPLC);
  936. // }
  937. //}
  938. ///// <summary>
  939. ///// 下发订单信息到PLC
  940. ///// </summary>
  941. ///// <param name="no">PLC编号</param>
  942. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  943. //{
  944. // try
  945. // {
  946. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  947. // {
  948. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  949. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  950. // }
  951. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  952. // }
  953. // catch (Exception ex)
  954. // {
  955. // string str = ex.StackTrace;
  956. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  957. // }
  958. //}
  959. /// <summary>
  960. /// 下发清料信号
  961. /// </summary>
  962. /// <param name="no">PLC编号</param>
  963. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  964. {
  965. try
  966. {
  967. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  968. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  969. return true;
  970. }
  971. catch (Exception ex)
  972. {
  973. string str = ex.StackTrace;
  974. AddMessage_Station(stationNameStr, LogType.Error,
  975. "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  976. str.Length - str.LastIndexOf("\\") - 1));
  977. return false;
  978. }
  979. }
  980. #endregion 下发订单信息
  981. #region Xiaomi 贲流
  982. #region 公共方法
  983. private static bool ProgressState = false;
  984. private static readonly object lockObj = new object(); // 锁对象
  985. private static bool isCollectingFlagLeft;
  986. private static bool isCollectingFlagRight;
  987. public static bool OpenDailogFalg = true; //是否开启扫码弹窗标识
  988. private static int res = 0;
  989. public static bool StopWhile =false; //二维码弹窗后停止循环
  990. public static bool inStationPass = true; //过站结果,保存进站结果
  991. public static string _strProductBarcode = "";
  992. public static string _strCarrierBarcode = "";
  993. public void ConnectToIOT()
  994. {
  995. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  996. // fds
  997. param.parameter.fds.address = GlobalContext.address;
  998. param.parameter.fds.appId = GlobalContext.appId;
  999. param.parameter.fds.appKey = GlobalContext.appKey;
  1000. // mes
  1001. param.parameter.mes.address = GlobalContext.ServerIp;
  1002. param.parameter.mes.appId = GlobalContext.MESAppId;
  1003. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  1004. // mqtt
  1005. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  1006. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  1007. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  1008. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  1009. // 设备配置
  1010. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  1011. if (GlobalContext.IsUsePLC1)
  1012. {
  1013. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  1014. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  1015. xiaomiParm.workstation = GlobalContext.S1_work_station; //工站
  1016. }
  1017. if (GlobalContext.IsUsePLC2)
  1018. {
  1019. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  1020. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  1021. xiaomiParm.workstation = GlobalContext.S2_work_station; //工站
  1022. }
  1023. if (GlobalContext.IsUsePLC3)
  1024. {
  1025. param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
  1026. //param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
  1027. }
  1028. if (GlobalContext.IsUsePLC4)
  1029. {
  1030. param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
  1031. param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
  1032. xiaomiParm.workstation = GlobalContext.s4_work_station; //工站
  1033. }
  1034. if (GlobalContext.IsUsePLC5)
  1035. {
  1036. param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
  1037. param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
  1038. xiaomiParm.workstation = GlobalContext.s5_work_station; //工站
  1039. }
  1040. if (GlobalContext.IsUsePLC6)
  1041. {
  1042. param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
  1043. param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
  1044. xiaomiParm.workstation = GlobalContext.s6_work_station; //工站
  1045. }
  1046. if (GlobalContext.IsUsePLC7)
  1047. {
  1048. param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  1049. //param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  1050. xiaomiParm.stationCode = GlobalContext.s7_1_station;
  1051. }
  1052. if (GlobalContext.IsUsePLC8)
  1053. {
  1054. param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
  1055. param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
  1056. xiaomiParm.workstation = GlobalContext.s8_work_station; //工站
  1057. }
  1058. if (GlobalContext.IsUsePLC9)
  1059. {
  1060. param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
  1061. param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
  1062. xiaomiParm.workstation = GlobalContext.s9_work_station; //工站
  1063. }
  1064. param.parameter.equipment.project = GlobalContext.Project_Code;
  1065. param.parameter.equipment.productMode = "debug";
  1066. param.parameter.other.logLevel = 0;
  1067. param.parameter.other.LogPath = GlobalContext.MqttLogDir;
  1068. XiaomiMqttClient_Extend.ParameterConfig(param);
  1069. }
  1070. /// <summary>
  1071. /// float[]转为string
  1072. /// </summary>
  1073. public string FloatArrayToString(float[] nScrewResults)
  1074. {
  1075. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  1076. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  1077. }
  1078. /// <summary>
  1079. /// short[]转为string
  1080. /// </summary>
  1081. public string ShortArrayToString(short[] nScrewResults)
  1082. {
  1083. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  1084. return string.Join(",", nScrewResults);
  1085. }
  1086. /// <summary>
  1087. /// 写入PLC重复三次
  1088. /// </summary>
  1089. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount,
  1090. T inObj)
  1091. {
  1092. int i = 0;
  1093. int nRet = 0;
  1094. string strRet = "";
  1095. try
  1096. {
  1097. while (i < 3) // 最多上传三次
  1098. {
  1099. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  1100. if (nRet == 0) //成功
  1101. {
  1102. break;
  1103. }
  1104. else
  1105. {
  1106. AddMessage_Station(stationNameStr, LogType.Error,
  1107. $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1108. i++;
  1109. }
  1110. }
  1111. return (nRet, strRet);
  1112. }
  1113. catch (Exception ex)
  1114. {
  1115. return (1, ex.Message);
  1116. }
  1117. }
  1118. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes,
  1119. short[] nScrewOrders, short[] nScrewResults)
  1120. {
  1121. try
  1122. {
  1123. // 获取当前日期
  1124. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1125. // 构建保存路径
  1126. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  1127. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction, "螺丝Mes数据");
  1128. // 确保目录存在
  1129. Directory.CreateDirectory(savePath);
  1130. // 文件名
  1131. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  1132. string filePath = Path.Combine(savePath, fileName);
  1133. // 确保不会超出数组长度,只取前14个或数组的实际长度
  1134. int count = Math.Min(14, fScrewTimes.Length);
  1135. using (StreamWriter sw = new StreamWriter(filePath))
  1136. {
  1137. for (int i = 0; i < count; i++)
  1138. {
  1139. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  1140. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  1141. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  1142. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  1143. sw.WriteLine(); // 空行分隔不同螺丝的信息
  1144. }
  1145. }
  1146. return (0, "");
  1147. }
  1148. catch (Exception ex)
  1149. {
  1150. return (1, ex.Message);
  1151. }
  1152. }
  1153. /// <summary>
  1154. /// 解析三点激光存储的文本
  1155. /// </summary>
  1156. /// <param name="path">文本路径</param>
  1157. /// <returns></returns>
  1158. public string GetLastLineCompensation(string path)
  1159. {
  1160. string result = "";
  1161. try
  1162. {
  1163. // 获取当前日期并格式化为 "yyyy-MM-dd" 格式
  1164. string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
  1165. string filename = $"Laser-{currentDate}-W0.txt";
  1166. // 拼接完整路径
  1167. string fullPath = Path.Combine(path, filename);
  1168. string lastNonEmptyLine = "";
  1169. // 判断文件是否存在
  1170. if (File.Exists(fullPath))
  1171. {
  1172. //读取文件内容
  1173. string[] lines = File.ReadAllLines(fullPath);
  1174. // 获取最后一行数据(忽略标题行)
  1175. if (lines.Length > 1)
  1176. {
  1177. string lastLine = "";
  1178. for (int i = lines.Length - 1; i > 0; i--)
  1179. {
  1180. if (!string.IsNullOrEmpty(lines[i]))
  1181. {
  1182. lastLine = lines[i];
  1183. break;
  1184. }
  1185. }
  1186. // 将最后一行按逗号分隔
  1187. string[] values = lastLine.Split(',');
  1188. // 跳过前两个元素并转换为新的数组
  1189. string[] newValues = values.Skip(0).Skip(1).ToArray();
  1190. string value = string.Join(",", newValues); // 获取值并去除多余空格
  1191. value = value.Replace(" ", "").Replace("\t", "").TrimStart(',');
  1192. if (value.StartsWith(","))
  1193. {
  1194. value = value.Substring(1);
  1195. }
  1196. result = value;
  1197. }
  1198. }
  1199. else
  1200. {
  1201. Console.WriteLine($"文件不存在: {fullPath}");
  1202. }
  1203. }
  1204. catch (Exception ex)
  1205. {
  1206. // 捕获异常并输出错误信息
  1207. Console.WriteLine($"发生错误: {ex.Message}");
  1208. }
  1209. return result;
  1210. }
  1211. public int PCBStationOutData(BarcodeSet_t Barcode, IoT_DataSet_t iotData)
  1212. {
  1213. int res = 0;
  1214. string jsonstr1 = "";
  1215. try
  1216. {
  1217. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1218. outRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备id(可配置)
  1219. outRequest_Body.stationId = GlobalContext.s5_station; // ⼯位ID(可配置)
  1220. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1221. outRequest_Body.clientTime =
  1222. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1223. outRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
  1224. int a1Result = (int)iotData.testStatus;
  1225. //bool pass = a1Result == 1;
  1226. //outRequest_Body.state = pass ? "PASS" : "FAIL"; ; // 出站条件 PASS或FAIL
  1227. outRequest_Body.state = "PASS";
  1228. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1229. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1230. XmStationOut_KeyMaterial keyMaterial = new XmStationOut_KeyMaterial();
  1231. keyMaterial.bindSort = 1;
  1232. keyMaterial.materialSn = Barcode.strProductBarcode;
  1233. outRequest_Body.unitData.keyMaterial.Add(keyMaterial); // 产品码
  1234. jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1235. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1236. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1237. if (response != null && response.header.code == "200")
  1238. {
  1239. res = 1;
  1240. AddMessage(LogType.Info,
  1241. "上传PCB出站数据到MES服务器---成功!请求信息:" + jsonstr1 + ",返回信息:" +
  1242. JsonConvert.SerializeObject(response.body));
  1243. }
  1244. else
  1245. {
  1246. res = 0;
  1247. AddMessage(LogType.Error,
  1248. "上传PCB出站数据到MES服务器---失败!错误信息:" + response.header.desc + ",请求信息:" + jsonstr1 + ",返回信息:" +
  1249. JsonConvert.SerializeObject(response.body));
  1250. }
  1251. }
  1252. catch (Exception e)
  1253. {
  1254. res = 0;
  1255. AddMessage(LogType.Info, "上传PCB出站数据到MES服务器---失败!请求信息:" + jsonstr1 + ",返回信息:" + e.Message);
  1256. }
  1257. return res;
  1258. }
  1259. public int PCBStationInData(BarcodeSet_t Barcode, IoT_DataSet_t iotData)
  1260. {
  1261. int res = 0;
  1262. string json_Body = "";
  1263. try
  1264. {
  1265. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1266. inRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  1267. inRequest_Body.stationId = GlobalContext.s5_station; // ⼯位ID(可配置)
  1268. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1269. inRequest_Body.clientTime =
  1270. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1271. inRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
  1272. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1273. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1274. json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1275. var response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1276. string resultJson = JsonConvert.SerializeObject(response);
  1277. if (response != null && response.header.code == "200")
  1278. {
  1279. res = 1;
  1280. AddMessage(LogType.Info,
  1281. "上传PCB进站数据到MES服务器---成功!请求信息:" + json_Body + ",返回信息:" +
  1282. JsonConvert.SerializeObject(response.body));
  1283. }
  1284. else
  1285. {
  1286. res = 0;
  1287. AddMessage(LogType.Error,
  1288. "上传PCB进站数据到MES服务器---失败!错误信息:" + response.header.desc + ",请求信息:" + json_Body + ",返回信息:" +
  1289. JsonConvert.SerializeObject(response.body));
  1290. }
  1291. }
  1292. catch (Exception e)
  1293. {
  1294. res = 0;
  1295. AddMessage(LogType.Info, "上传PCB进站数据到MES服务器---失败!请求信息:" + json_Body + ",返回信息:" + e.Message);
  1296. }
  1297. return res;
  1298. }
  1299. /// <summary>
  1300. /// 调用进站接口并保存进站数据
  1301. /// </summary>
  1302. /// <param name="stationNameStr">工站信息</param>
  1303. /// <param name="workorder_code">工单号</param>
  1304. /// <param name="mtltmrk">型号(物料号)</param>
  1305. /// <param name="sn">产品SN</param>
  1306. /// <param name="items">进站数据</param>
  1307. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1308. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn,
  1309. List<TestItem> items, string MachineId, string StationId, bool pass, string slot)
  1310. {
  1311. int result = 0;
  1312. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1313. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1314. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1315. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1316. inRequest_Body.clientTime =
  1317. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1318. inRequest_Body.unitSn = sn; // 产品SN
  1319. inRequest_Body.uuidInspection = uuid;
  1320. inRequest_Body.state = pass ? "PASS" : "FAIL";
  1321. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1322. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1323. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1324. StationIn stationIn = new StationIn()
  1325. {
  1326. Workorder_code = workorder_code, // 车间订单号
  1327. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1328. Sn = sn, // SN
  1329. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1330. Parameter_values = items, // 进站数据
  1331. Write_user = inRequest_Body.userId, // 员工Id
  1332. Test_time = inRequest_Body.clientTime // 进站时间
  1333. };
  1334. // 本地数据
  1335. string sql = stationIn.ToStringInsert(0);
  1336. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1337. result = ret == "成功" ? 1 : 6;
  1338. #region MES
  1339. if (GlobalContext.IsSendStationIn)
  1340. {
  1341. try
  1342. {
  1343. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1344. string resultJson = "";
  1345. string mesRet = string.Empty;
  1346. int i = 0;
  1347. while (i < 2) // 1009会多次尝试上传
  1348. {
  1349. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1350. resultJson = JsonConvert.SerializeObject(response);
  1351. if (response != null && response.header.code == "200")
  1352. break;
  1353. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1354. i++;
  1355. i++;
  1356. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1357. // 记录失败原因
  1358. OnMessage(LogType.Error, $"上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:{mesRet},请求参数:{json_Body}");
  1359. }
  1360. if (response?.header?.code == "200")
  1361. {
  1362. inStationPass = true;//上传iot进站结果
  1363. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1364. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1365. result = ret_Upd == "成功" ? 1 : 6;
  1366. AddMessage(LogType.Info,
  1367. $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功,返回参数:{resultJson},请求参数:{json_Body}");
  1368. }
  1369. else
  1370. {
  1371. inStationPass = false;//上传iot进站结果
  1372. result = 5;
  1373. AddMessage(LogType.Info,
  1374. $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息: {mesRet},请求参数:{json_Body}");
  1375. }
  1376. string sql_response =
  1377. stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1378. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1379. }
  1380. catch (Exception ex)
  1381. {
  1382. inStationPass = false;//上传iot进站结果
  1383. result = 6;
  1384. string str = ex.StackTrace;
  1385. AddMessage_Station(stationNameStr, LogType.Error,
  1386. $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1387. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1388. }
  1389. }
  1390. #endregion
  1391. #region IOT
  1392. //过站结果,出站传结果,这里注释掉
  1393. //if (GlobalContext.IsMqttSendProcessData)
  1394. //{
  1395. // PassStationResultRequest request = new PassStationResultRequest();
  1396. // request.project_code = GlobalContext.Project_Code; // 项⽬编码
  1397. // request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
  1398. // request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
  1399. // request.line_code = GlobalContext.LineCode; // 线体编码
  1400. // request.work_station = xiaomiParm.workstation; // ⼯站ID
  1401. // request.device_code = xiaomiParm.deviceCode; // 装备编码
  1402. // request.station = xiaomiParm.stationCode;
  1403. // request.process_time =
  1404. // DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
  1405. // request.slot = slot; // 槽位编码
  1406. // request.sn = sn; // 产品SN
  1407. // // request.enter_status = inpass ? "PASS" : "FAIL"; // 进站状态
  1408. // request.enter_status = pass ? "PASS" : "FAIL"; // 进站状态
  1409. // request.result = ""; // 出站条件 PASS或FAIL; // 过站结果
  1410. // request.work_type = "OUT_STATION"; // 作业类型
  1411. // // 上传过站结果
  1412. // (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
  1413. // if (iotResult.Item1 != 0)
  1414. // {
  1415. // OnMessage(LogType.Info,
  1416. // $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}] 进站结果[{request.enter_status}] 出站结果[{request.result}]");
  1417. // }
  1418. //}
  1419. #endregion
  1420. return result;
  1421. }
  1422. /// <summary>
  1423. /// 选择如何记录出站数据
  1424. /// </summary>
  1425. /// <param name="items">出站数据</param>
  1426. /// <param name="equipmentCode">设备编号</param>
  1427. /// <param name="processItem">测试项目</param>
  1428. /// <param name="workorder_code">车间订单号</param>
  1429. /// <param name="batch_num">批次号</param>
  1430. /// <param name="mtltmrk">型号</param>
  1431. /// <param name="proDate">日期</param>
  1432. /// <param name="supplierCode">供应商代码</param>
  1433. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1434. /// <returns>上传成功时返回1;失败返回0</returns>
  1435. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode,
  1436. string processItem,
  1437. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1438. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId,
  1439. string StationId, string PartBarcode, string detailjson, XmStationOut_InspectionItemData inspectionItemData, string direction = "")
  1440. {
  1441. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num,
  1442. mtltmrk,
  1443. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode, detailjson, inspectionItemData,
  1444. direction);
  1445. }
  1446. /// <summary>
  1447. /// 添加出站数据(提交到MES+本地保存到数据库)
  1448. /// </summary>
  1449. /// <param name="items">出站数据</param>
  1450. /// <param name="equipmentCode">设备编号</param>
  1451. /// <param name="processItem">测试项目</param>
  1452. /// <param name="workorder_code">车间订单号</param>
  1453. /// <param name="batch_num">批次号</param>
  1454. /// <param name="mtltmrk">型号</param>
  1455. /// <param name="proDate">日期</param>
  1456. /// <param name="supplierCode">供应商代码</param>
  1457. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1458. /// <returns>上传成功时返回1;失败返回0</returns>
  1459. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1460. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1461. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot,
  1462. string machineId, string stationId, string partBarcode, string detailjson, XmStationOut_InspectionItemData inspectionItemData, string direction = "")
  1463. {
  1464. int upload = 0;
  1465. int result = 0;
  1466. ProcessData processData = new ProcessData()
  1467. {
  1468. Equipment_code = equipmentCode,
  1469. Workorder_code = workorder_code,
  1470. Batch_number = batch_num,
  1471. Sn = sn, // SN
  1472. Testitem = processItem,
  1473. Parameter_values = items,
  1474. Write_user = GlobalContext.CurrentUser,
  1475. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1476. };
  1477. // 本地数据
  1478. string sql = processData.ToStringInsert(upload);
  1479. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1480. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1481. #region MES
  1482. if (GlobalContext.IsSendProcessData)
  1483. {
  1484. try
  1485. {
  1486. string id = processData.ID.Copy();
  1487. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1488. if (direction == "Right")
  1489. outRequest_Body.uuidInspection = uuid2;
  1490. else
  1491. outRequest_Body.uuidInspection = uuid;
  1492. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1493. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1494. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1495. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1496. outRequest_Body.unitSn = sn; // 产品SN
  1497. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1498. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1499. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1500. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1501. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1502. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1503. if (!string.IsNullOrEmpty(partBarcode))
  1504. {
  1505. outRequest_Body.unitData.keyMaterial.Add(
  1506. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1507. {
  1508. bindSort = 1,
  1509. materialSn = partBarcode
  1510. }); // 设备数据 - 部件码
  1511. }
  1512. #region 过站明细
  1513. if (GlobalContext.IsSendProcessDetail)
  1514. {
  1515. if (detailjson.Length > 0)
  1516. {
  1517. //detailjson = "{\"fGlueSupplySpeed\":0.63,\"fAB_AirPress\":0.0,\"fAB_AirPressDiff\":0.0,\"fMesHeightInfos\":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],\"fIntervalWeights\":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],\"fRemainGlues\":[600.0,600.0]}";
  1518. // 解析JSON字符串为字典
  1519. detailjson = detailjson.Replace("[", "\"[");
  1520. detailjson = detailjson.Replace("]", "]\"");
  1521. var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(detailjson);
  1522. foreach (var kvp in dictionary)
  1523. {
  1524. outRequest_Body.unitData.processData.Add(
  1525. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1526. {
  1527. dataName = kvp.Key.ToString(),
  1528. dataValue = string.IsNullOrEmpty(kvp.Value) ? "" : kvp.Value.ToString()
  1529. });
  1530. }
  1531. }
  1532. }
  1533. #endregion
  1534. #region 测试项
  1535. if (GlobalContext.IsSendTestData)
  1536. {
  1537. if (stationNameStr.Contains("OP31") || stationNameStr.Contains("OP32") || stationNameStr.Contains("OP40") || stationNameStr.Contains("OP50"))
  1538. {
  1539. outRequest_Body.unitData.inspectionItemData.Add(
  1540. new XmStationOut_InspectionItemData()
  1541. {
  1542. childUnitSn = inspectionItemData.childUnitSn,
  1543. childUnitState = inspectionItemData.childUnitState,
  1544. toolVersion = inspectionItemData.toolVersion,
  1545. dataItem = inspectionItemData.dataItem,
  1546. }
  1547. );
  1548. }
  1549. }
  1550. #endregion
  1551. #region OP30站读三点测高
  1552. if (stationNameStr.Contains("OP31") || stationNameStr.Contains("OP32"))
  1553. {
  1554. string path = "";
  1555. if (direction == "Left")
  1556. {
  1557. string pathStr = GlobalContext.MESLaserLPath;
  1558. path = DecFileName(pathStr);
  1559. }
  1560. else
  1561. {
  1562. string pathStr = GlobalContext.MESLaserRPath;
  1563. path = DecFileName(pathStr);
  1564. }
  1565. var item = outRequest_Body.unitData.processData.FirstOrDefault(data => data.dataName == "fMesHeightInfos");
  1566. if (item != null)
  1567. {
  1568. item.dataValue = GetLastLineCompensation(path);
  1569. }
  1570. //outRequest_Body.unitData.processData.Add(
  1571. // new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1572. // {
  1573. // dataName = "fMesHeightInfos",
  1574. // dataValue = GetLastLineCompensation(path)
  1575. // });
  1576. }
  1577. #endregion
  1578. #region 上传文件,添加附件uuid
  1579. if (GlobalContext.MESIsSendUpFile)
  1580. {
  1581. foreach (var item in fileUploadData.fileData)
  1582. {
  1583. if (!string.IsNullOrEmpty(item.FileName))
  1584. {
  1585. outRequest_Body.unitData.fileData.Add(
  1586. new XmStationOut_FileData()
  1587. {
  1588. fileName = item.FileName,
  1589. fileId = item.FileId,
  1590. bucket = item.Bucket
  1591. });
  1592. }
  1593. }
  1594. }
  1595. #endregion
  1596. #region 上传MES
  1597. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1598. if (GlobalContext.IsSendProcessData)
  1599. {
  1600. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1601. string mesRet = string.Empty;
  1602. int i = 0;
  1603. while (i < 2) // 1009会多次尝试上传
  1604. {
  1605. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1606. if (response != null && response.header.code == "200")
  1607. {
  1608. OnMessage(LogType.Info,
  1609. $"【出站数据 SN {sn}】上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" +
  1610. JsonConvert.SerializeObject(response.body));
  1611. break;
  1612. }
  1613. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1614. i++;
  1615. i++;
  1616. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1617. // 记录失败原因
  1618. OnMessage(LogType.Error,
  1619. $"【出站数据 SN {sn}】上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1620. }
  1621. if (response?.header?.code == "200")
  1622. {
  1623. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1624. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1625. result = 1;
  1626. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1627. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1628. }
  1629. else
  1630. {
  1631. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1632. }
  1633. fileUploadData.fileData.Clear();
  1634. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(
  1635. JsonConvert.SerializeObject(outRequest_Body),
  1636. JsonConvert.SerializeObject(response), id);
  1637. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1638. }
  1639. #endregion
  1640. }
  1641. catch (Exception ex)
  1642. {
  1643. string str = ex.StackTrace;
  1644. AddMessage_Station(stationNameStr, LogType.Error,
  1645. $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1646. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1647. }
  1648. }
  1649. #endregion
  1650. #region IOT
  1651. //过站明细
  1652. if (GlobalContext.IsMqttSendProcessData)
  1653. {
  1654. test_item_num = 0;
  1655. PassStationDetailRequest request = new PassStationDetailRequest();
  1656. if (direction == "Right")
  1657. request.pass_station_id = uuid2;
  1658. else
  1659. request.pass_station_id = uuid;
  1660. request.sn = sn; // 产品SN
  1661. request.slot = vehicleSlot; // 槽位编码
  1662. request.function_name = "Machine_加⼯模块";
  1663. request.status = "PASS";
  1664. (int, string) iotResult = (0, "");
  1665. if (detailjson.Length > 0)
  1666. {
  1667. // 解析JSON字符串为字典
  1668. var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(detailjson);
  1669. foreach (var kvp in dictionary)
  1670. {
  1671. test_item_num += 1;
  1672. request.test_item_num = test_item_num.ToString();
  1673. request.test_item = kvp.Key.ToString();
  1674. request.result_val = string.IsNullOrEmpty(kvp.Value) ? "" : kvp.Value.ToString();
  1675. request.description = request.test_item;
  1676. // 上传过站明细
  1677. iotResult = XiaomiMqttClient_Extend.Write_PassStationDetail(request);
  1678. if (iotResult.Item1 != 0)
  1679. {
  1680. OnMessage(LogType.Info,
  1681. $"【IOT过站明细】上传失败!错误原因:{iotResult.Item2},过站明细;产品码[{sn}] 测试项目[{request.test_item}] 测试值[{request.result_val}]");
  1682. }
  1683. }
  1684. }
  1685. }
  1686. //过站结果
  1687. if (GlobalContext.IsMqttSendProcessData)
  1688. {
  1689. PassStationResultRequest request = new PassStationResultRequest();
  1690. if (direction == "Right")
  1691. request.pass_station_id = uuid2;
  1692. else
  1693. request.pass_station_id = uuid;
  1694. request.project_code = GlobalContext.Project_Code; // 项⽬编码
  1695. request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
  1696. request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
  1697. request.line_code = GlobalContext.LineCode; // 线体编码
  1698. request.work_station = xiaomiParm.workstation; // ⼯站ID
  1699. request.device_code = xiaomiParm.deviceCode; // 装备编码
  1700. request.station = xiaomiParm.stationCode;
  1701. request.process_time =
  1702. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
  1703. request.slot = vehicleSlot; // 槽位编码
  1704. request.sn = sn; // 产品SN
  1705. // request.enter_status = inpass ? "PASS" : "FAIL"; // 进站状态
  1706. request.enter_status = inStationPass ? "PASS" : "FAIL";// 进站状态
  1707. request.result = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL; // 过站结果
  1708. request.work_type = "OUT_STATION"; // 作业类型
  1709. // 上传过站结果
  1710. (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
  1711. if (iotResult.Item1 != 0)
  1712. {
  1713. OnMessage(LogType.Info,
  1714. $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}] 进站结果[{request.enter_status}] 出站结果[{request.result}]");
  1715. }
  1716. }
  1717. #endregion
  1718. return result;
  1719. }
  1720. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1721. //{
  1722. // Stopwatch stopwatch = new Stopwatch();
  1723. // stopwatch.Start();
  1724. // try
  1725. // {
  1726. // // 初始化 AtlasScrew 实例
  1727. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1728. // atlasScrew1.Initial();
  1729. // // 存储结果的列表
  1730. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1731. // // 存储角度和扭力的字符串列表
  1732. // List<string> angleStrs = new List<string>();
  1733. // List<string> torqueStrs = new List<string>();
  1734. // // 上一次获取的数据
  1735. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1736. // while (isExitAtlasLeft) // 检查是否收集数据
  1737. // {
  1738. // // 获取当前数据
  1739. // var currentResult = atlasScrew1.GetResults();
  1740. // // 判断是否为新数据
  1741. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1742. // {
  1743. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1744. // // 更新角度和扭力的字符串列表
  1745. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1746. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1747. // // 计算角度、扭力、起始扭力和最大扭力
  1748. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1749. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1750. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1751. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1752. // // 将新数据添加到结果列表
  1753. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1754. // // 更新上一次获取的数据
  1755. // lastResult = currentResult;
  1756. // }
  1757. // // 等待一段时间后再次检查
  1758. // Thread.Sleep(20); // 轮询间隔时间
  1759. // // 如果触发了出站,则退出循环
  1760. // if (!isExitAtlasLeft)
  1761. // {
  1762. // break;
  1763. // }
  1764. // }
  1765. // // 生成文件名
  1766. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1767. // // 写入数据到文件
  1768. // using (StreamWriter writer = new StreamWriter(fileName))
  1769. // {
  1770. // // 写入标题行
  1771. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1772. // // 写入每一行数据
  1773. // foreach (var result in results)
  1774. // {
  1775. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1776. // }
  1777. // }
  1778. // stopwatch.Stop();
  1779. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1780. // }
  1781. // catch (Exception ex)
  1782. // {
  1783. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1784. // }
  1785. // finally
  1786. // {
  1787. // // 重置标志变量
  1788. // isExitAtlasLeft = false;
  1789. // }
  1790. //}
  1791. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1792. //{
  1793. // Stopwatch stopwatch = new Stopwatch();
  1794. // stopwatch.Start();
  1795. // try
  1796. // {
  1797. // // 初始化 AtlasScrew 实例
  1798. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1799. // atlasScrew2.Initial();
  1800. // // 存储结果的列表
  1801. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1802. // // 上一次获取的数据
  1803. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1804. // while (isExitAtlasRight) // 检查是否收集数据
  1805. // {
  1806. // // 获取当前数据
  1807. // var currentResult = atlasScrew2.GetResults();
  1808. // // 判断是否为新数据
  1809. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1810. // {
  1811. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1812. // // 将新数据写入PLC
  1813. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1814. // // 将新数据添加到结果列表
  1815. // results.Add(currentResult);
  1816. // // 更新上一次获取的数据
  1817. // lastResult = currentResult;
  1818. // }
  1819. // // 等待一段时间后再次检查
  1820. // Thread.Sleep(20); // 轮询间隔时间
  1821. // // 如果触发了出站,则退出循环
  1822. // if (!isExitAtlasRight)
  1823. // {
  1824. // break;
  1825. // }
  1826. // }
  1827. // // 将所有数据写入文件
  1828. // //WriteDataToFile(sn, direction, results);
  1829. // stopwatch.Stop();
  1830. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1831. // }
  1832. // catch (Exception ex)
  1833. // {
  1834. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1835. // }
  1836. // finally
  1837. // {
  1838. // // 重置标志变量
  1839. // isExitAtlasRight = false;
  1840. // }
  1841. //}
  1842. /// <summary>
  1843. ///字符串中文乱码解决
  1844. /// </summary>
  1845. /// <param name="str"></param>
  1846. /// <returns></returns>
  1847. public static string DecFileName(string str)
  1848. {
  1849. Encoding utf8 = Encoding.GetEncoding("gbk");
  1850. byte[] btArr = utf8.GetBytes(str);
  1851. return Encoding.UTF8.GetString(btArr);
  1852. }
  1853. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1854. {
  1855. Stopwatch stopwatch = new Stopwatch();
  1856. stopwatch.Start();
  1857. int nRet = 0;
  1858. string strRet = "";
  1859. try
  1860. {
  1861. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1862. while (isCollectingFlagLeft)
  1863. {
  1864. // 从缓存中获取所有未处理的数据
  1865. var cachedData = atlasScrew.GetCachedDataLeft();
  1866. foreach (var currentResult in cachedData)
  1867. {
  1868. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1869. {
  1870. continue; // 跳过无效数据
  1871. }
  1872. OnMessage(LogType.Info,
  1873. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1874. // 写入PLC
  1875. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1876. {
  1877. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1878. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1879. };
  1880. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1881. if (nRet != 0)
  1882. {
  1883. OnMessage(LogType.Info,
  1884. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1885. }
  1886. else
  1887. {
  1888. OnMessage(LogType.Info,
  1889. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1890. }
  1891. // 构建保存路径
  1892. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1893. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1894. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1895. Directory.CreateDirectory(savePath); // 确保目录存在
  1896. // 构建文件名(以 SN + 序号命名)
  1897. string fileName = $"{sn}_{fileCounter}.txt";
  1898. string filePath = Path.Combine(savePath, fileName);
  1899. // 写入文件
  1900. using (StreamWriter writer = new StreamWriter(filePath))
  1901. {
  1902. writer.WriteLine("精度, 扭力");
  1903. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1904. for (int i = 0;
  1905. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  1906. i++)
  1907. {
  1908. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1909. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1910. writer.WriteLine($"{precision}, {torque}");
  1911. }
  1912. }
  1913. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1914. // 增加文件计数器
  1915. fileCounter++;
  1916. }
  1917. // 如果没有更多数据,则短暂休眠以节省资源
  1918. if (!cachedData.Any())
  1919. {
  1920. Thread.Sleep(10); // 根据需要调整休眠时间
  1921. }
  1922. // 如果触发了出站,则退出循环
  1923. if (!isCollectingFlagLeft)
  1924. {
  1925. break;
  1926. }
  1927. }
  1928. stopwatch.Stop();
  1929. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1930. }
  1931. catch (Exception ex)
  1932. {
  1933. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1934. }
  1935. finally
  1936. {
  1937. isCollectingFlagLeft = false;
  1938. }
  1939. }
  1940. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1941. {
  1942. Stopwatch stopwatch = new Stopwatch();
  1943. stopwatch.Start();
  1944. int nRet = 0;
  1945. string strRet = "";
  1946. try
  1947. {
  1948. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1949. while (isCollectingFlagRight)
  1950. {
  1951. // 从缓存中获取所有未处理的数据
  1952. var cachedData = atlasScrew.GetCachedDataLeft();
  1953. foreach (var currentResult in cachedData)
  1954. {
  1955. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1956. {
  1957. continue; // 跳过无效数据
  1958. }
  1959. OnMessage(LogType.Info,
  1960. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1961. // 写入PLC
  1962. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1963. {
  1964. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1965. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1966. };
  1967. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1968. if (nRet != 0)
  1969. {
  1970. OnMessage(LogType.Info,
  1971. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1972. }
  1973. else
  1974. {
  1975. OnMessage(LogType.Info,
  1976. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1977. }
  1978. // 构建保存路径
  1979. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1980. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1981. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1982. Directory.CreateDirectory(savePath); // 确保目录存在
  1983. // 构建文件名(以 SN + 序号命名)
  1984. string fileName = $"{sn}_{fileCounter}.txt";
  1985. string filePath = Path.Combine(savePath, fileName);
  1986. // 写入文件
  1987. using (StreamWriter writer = new StreamWriter(filePath))
  1988. {
  1989. writer.WriteLine("精度, 扭力");
  1990. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1991. for (int i = 0;
  1992. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  1993. i++)
  1994. {
  1995. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1996. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1997. writer.WriteLine($"{precision}, {torque}");
  1998. }
  1999. }
  2000. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  2001. // 增加文件计数器
  2002. fileCounter++;
  2003. }
  2004. // 如果没有更多数据,则短暂休眠以节省资源
  2005. if (!cachedData.Any())
  2006. {
  2007. Thread.Sleep(10); // 根据需要调整休眠时间
  2008. }
  2009. // 如果触发了出站,则退出循环
  2010. if (!isCollectingFlagRight)
  2011. {
  2012. break;
  2013. }
  2014. }
  2015. stopwatch.Stop();
  2016. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  2017. }
  2018. catch (Exception ex)
  2019. {
  2020. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  2021. }
  2022. finally
  2023. {
  2024. isCollectingFlagRight = false;
  2025. }
  2026. }
  2027. private void CopyFileToTempPath(string morepath,string temppath) {
  2028. string tempPath = GlobalContext.MqttFileTempDir; //临时存放图片的文件夹
  2029. var morePath = morepath.Split(",");
  2030. try
  2031. {
  2032. if (Directory.Exists(tempPath))
  2033. {
  2034. Directory.Delete(tempPath, recursive: true); // 清理临时目录
  2035. }
  2036. foreach (var item in morePath)
  2037. {
  2038. foreach (var file in Directory.GetFiles(item, "*.*", SearchOption.AllDirectories))
  2039. {
  2040. var relativePath = file.Substring(item.Length + 1);
  2041. var destFile = Path.Combine(temppath, relativePath);
  2042. Directory.CreateDirectory(Path.GetDirectoryName(destFile));
  2043. File.Copy(file, destFile, overwrite: true);
  2044. //删除文件
  2045. (bool, string) newResult = DeleteFile(file);
  2046. }
  2047. }
  2048. }
  2049. catch (Exception ex){
  2050. throw ex;
  2051. }
  2052. }
  2053. /// <summary>
  2054. /// 压缩文件
  2055. /// </summary>
  2056. /// <param name="folderPath">源文件地址</param>
  2057. /// <param name="zipFilePath">目标地址</param>
  2058. /// <returns></returns>
  2059. public static (int, string) CompressFolder(string folderPath, string zipFilePath)
  2060. {
  2061. try
  2062. {
  2063. // 创建zip文件,将指定文件夹内的所有内容压缩到这个zip文件中
  2064. System.IO.Compression.ZipFile.CreateFromDirectory(folderPath, zipFilePath);
  2065. return (1, "文件夹已成功压缩!");
  2066. }
  2067. catch (Exception ex)
  2068. {
  2069. return (0, "文件压缩出错!" + ex.Message);
  2070. }
  2071. }
  2072. /// <summary>
  2073. /// 上传文件
  2074. /// </summary>
  2075. /// <param name="BarcodeSet_t">条码集合</param>
  2076. /// <param name="stationCode">工站编号</param>
  2077. /// <param name="stationName">工站名称</param>
  2078. /// <param name="path">文件路径</param>
  2079. public async Task<(int, string)> SaveDBbyFileInfo(BarcodeSet_t BarcodeSet, string stationCode,
  2080. string stationName, int pass, string path, string guid = "")
  2081. {
  2082. string sql, filename = "";
  2083. int result = 0;
  2084. var formData = new MultipartFormDataContent();
  2085. string msg = "";
  2086. string file_category = "IMAGE"; //IMAGE 、TEXT 、UNKNOWN
  2087. string file_type = "IMAGE";
  2088. string project = GlobalContext.ProgramName;
  2089. string run_mode = GlobalContext.run_mode;
  2090. string product_mode = GlobalContext.product_mode;
  2091. string pass_result = (pass == 1 ? "PASS" : "Fail");
  2092. string device_code = xiaomiParm.deviceCode;
  2093. string sn = BarcodeSet.strProductBarcode;
  2094. string staion_id = xiaomiParm.stationCode;
  2095. string bucket =
  2096. $"{file_category}/{file_type}/{project}/{product_mode}/{run_mode}/{pass_result}/{device_code}/{sn}/{staion_id}";
  2097. // 获取所有图片文件
  2098. if (guid == "")
  2099. {
  2100. guid = Guid.NewGuid().ToString();
  2101. }
  2102. try
  2103. {
  2104. if (GlobalContext.MESIsSendUpFile)
  2105. {
  2106. List<string> imageFiles = GetAllImageFiles(path);
  2107. string toPath = GlobalContext.MqttFileBackupLogDir;
  2108. filename =
  2109. $"{xiaomiParm.workstation}_{file_type}_{sn}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";
  2110. //string directoryPath = Path.GetDirectoryName(path);
  2111. string strFilePath = toPath + "\\" + filename;
  2112. if (imageFiles.Count > 0)
  2113. {
  2114. var r = CompressFolder(path, strFilePath);
  2115. if (r.Item1 == 0)
  2116. {
  2117. return (0, r.Item2);
  2118. }
  2119. else
  2120. {
  2121. msg = r.Item2 + "\r\n";
  2122. }
  2123. }
  2124. else
  2125. {
  2126. return (0, "文件不存在!");
  2127. }
  2128. FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
  2129. fileUpload_X5.bucket = bucket;
  2130. fileUpload_X5.name = filename;
  2131. fileUpload_X5.uuid = guid.ToString();
  2132. ///需要上传文件
  2133. FileInfo file = new FileInfo(strFilePath);
  2134. string fileMd5Hex = GetMD5Hex(file);
  2135. fileUpload_X5.md5 = fileMd5Hex;
  2136. fileUpload_X5.uploadCloud = true;
  2137. fileUpload_X5.informMqtt = true;
  2138. FileMqttPayload fileMqttPayload = new FileMqttPayload();
  2139. fileMqttPayload.factory = GlobalContext.Factory_Code;
  2140. fileMqttPayload.project_name = GlobalContext.Project_Code;
  2141. fileMqttPayload.product_mode = GlobalContext.product_mode;
  2142. fileMqttPayload.line_no = GlobalContext.LineCode;
  2143. fileMqttPayload.work_station_no = xiaomiParm.workstation;
  2144. fileMqttPayload.equipment_no = xiaomiParm.deviceCode;
  2145. fileMqttPayload.station_no = xiaomiParm.stationCode;
  2146. fileMqttPayload.file_id = guid;
  2147. fileMqttPayload.file_name = filename;
  2148. fileMqttPayload.sn = BarcodeSet.strProductBarcode;
  2149. //fileMqttPayload.opt_time = "";
  2150. //fileMqttPayload.file_type = "";
  2151. //fileMqttPayload.file_category = "";
  2152. //fileMqttPayload.tag = "";
  2153. fileMqttPayload.reference_info.pass_station_id = uuid;
  2154. var fileresult = await
  2155. XiaomiMESHttp_UpLoadFile.FileUoladToMes(strFilePath, fileUpload_X5, fileMqttPayload);
  2156. if (fileresult.Item1 != 1)
  2157. {
  2158. return (0, msg + fileresult.Item2 + "\r\n");
  2159. }
  2160. else
  2161. {
  2162. msg = msg + fileresult.Item2 + "\r\n";
  2163. }
  2164. }
  2165. return (1, msg);
  2166. }
  2167. catch (Exception e)
  2168. {
  2169. return (0,
  2170. filename + $"文件上传错误!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode},错误原因:" +
  2171. e.Message);
  2172. }
  2173. }
  2174. /// <summary>
  2175. /// 获取路径下的所有图片
  2176. /// </summary>
  2177. /// <param name="directoryPath"></param>
  2178. /// <returns></returns>
  2179. public List<string> GetAllImageFiles(string directoryPath)
  2180. {
  2181. var imageExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
  2182. { ".jpg", ".jpeg", ".png", ".bmp", ".gif", ".tiff" };
  2183. var imageFiles = new List<string>();
  2184. try
  2185. {
  2186. // 遍历目录及子目录中的所有文件
  2187. foreach (string file in Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories))
  2188. {
  2189. // 获取文件扩展名并检查是否为图片格式
  2190. string extension = Path.GetExtension(file);
  2191. if (imageExtensions.Contains(extension))
  2192. {
  2193. imageFiles.Add(file);
  2194. }
  2195. }
  2196. }
  2197. catch (Exception ex)
  2198. {
  2199. OnMessage(LogType.Error, $"图片查询发生错误: {ex.Message}");
  2200. }
  2201. return imageFiles;
  2202. }
  2203. /// <summary>
  2204. /// 实例化报警字典
  2205. /// </summary>
  2206. private (bool, string) InitalDicAlarm()
  2207. {
  2208. #region 加载报警表
  2209. string excelPath = "";
  2210. switch (GlobalContext.IsUsePLCNow)
  2211. {
  2212. case 1:
  2213. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_10_壳体清洁上料.xlsx";
  2214. break;
  2215. case 2:
  2216. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_20_上盖板上料装备.xlsx";
  2217. break;
  2218. case 3:
  2219. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_30_点散热胶装备.xlsx";
  2220. break;
  2221. case 4:
  2222. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_40_胶线检测.xlsx";
  2223. break;
  2224. case 5:
  2225. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_50_ADD板上料组装装备.xlsx";
  2226. break;
  2227. case 6:
  2228. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_60_组上盖板.xlsx";
  2229. break;
  2230. case 7:
  2231. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_70_上盖板锁螺丝.xlsx";
  2232. break;
  2233. case 8:
  2234. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_80_NG下料.xlsx";
  2235. break;
  2236. case 9:
  2237. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_90_半成品下料.xlsx";
  2238. break;
  2239. default:
  2240. return (false, $"不支持当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请在设置页切换到正确的plc后重启该软件!");
  2241. }
  2242. if (!File.Exists(excelPath))
  2243. return (false, $"未找到当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请检查文件路径:'{excelPath}'。");
  2244. DataTable DtModel = NPOIHelper.ReadExcel(excelPath);
  2245. if (DtModel == null || DtModel.Rows.Count < 1)
  2246. return (false, $"报警点位表未包含任何报警数据!请检查‘{excelPath}’文件!");
  2247. // 检查列名
  2248. List<string> isNeedParms = new List<string>()
  2249. {
  2250. "设备分类名称", "设备分类编码", "分类层级1", "分类层级2", "分类层级3", "分类层级4", "事件名称", "事件ID", "描述", "标签", "PLC地址", "工位"
  2251. }; // 必须要有的列
  2252. // 指定列名 + 检查列是否完整
  2253. DataRow dtRowName = DtModel.Rows[0];
  2254. int count = DtModel.Columns.Count;
  2255. for (int i = 0; i < count; i++)
  2256. {
  2257. string columeName = dtRowName[i]?.ToString();
  2258. if (!string.IsNullOrEmpty(columeName))
  2259. DtModel.Columns[i].ColumnName = columeName;
  2260. if ((!string.IsNullOrEmpty(columeName)) && isNeedParms.Count > 0 && isNeedParms.Contains(columeName))
  2261. isNeedParms.Remove(columeName);
  2262. }
  2263. DtModel.Rows.RemoveAt(0);
  2264. if (isNeedParms.Count > 0)
  2265. {
  2266. string msg1 = string.Join(",", isNeedParms);
  2267. return (false, $"报警点位表未包含列:{msg1}!请检查‘{excelPath}’文件!");
  2268. }
  2269. #endregion 加载报警表
  2270. List<Alarm> keyValues1 = new List<Alarm>();
  2271. for (int i = 0; i < DtModel.Rows.Count; i++)
  2272. {
  2273. Alarm alarm = new Alarm();
  2274. alarm.plcName = DtModel.Rows[i]["设备分类名称"]?.ToString(); // 设备名;
  2275. string type1Str = DtModel.Rows[i]["分类层级1"]?.ToString(); // 分类层级1;
  2276. alarm.type1CH = type1Str; // 分类层级1 中文
  2277. alarm.type1 = type1Str; // 分类层级1
  2278. if (!string.IsNullOrEmpty(type1Str) && type1Str.Contains("\n"))
  2279. {
  2280. string[] type1Strs = type1Str.Split('\n');
  2281. if (type1Strs.Length >= 2)
  2282. {
  2283. alarm.type1CH = type1Strs[0].Trim(); // 分类层级1 中文
  2284. alarm.type1 = type1Strs[1].Trim(); // 分类层级1
  2285. if (string.IsNullOrEmpty(alarm.type1))
  2286. alarm.type1 = alarm.type1CH;
  2287. }
  2288. }
  2289. string type2Str = DtModel.Rows[i]["分类层级2"]?.ToString(); // 分类层级2;电气控制 electric_control
  2290. alarm.type2CH = type2Str; // 分类层级2 中文
  2291. alarm.type2 = type2Str; // 分类层级2
  2292. if (!string.IsNullOrEmpty(type2Str) && type2Str.Contains("\n"))
  2293. {
  2294. string[] type2Strs = type2Str.Split('\n');
  2295. if (type2Strs.Length >= 2)
  2296. {
  2297. alarm.type2CH = type2Strs[0].Trim(); // 分类层级2 中文
  2298. alarm.type2 = type2Strs[1].Trim(); // 分类层级2
  2299. if (string.IsNullOrEmpty(alarm.type2))
  2300. alarm.type2 = alarm.type2CH;
  2301. }
  2302. }
  2303. string type3Str = DtModel.Rows[i]["分类层级3"]?.ToString(); // 分类层级3;故障 Fault
  2304. alarm.type3CH = type3Str; // 分类层级3 中文
  2305. alarm.type3 = type3Str; // 分类层级3
  2306. if (!string.IsNullOrEmpty(type3Str) && type3Str.Contains("\n"))
  2307. {
  2308. string[] type3Strs = type3Str.Split('\n');
  2309. if (type3Strs.Length >= 2)
  2310. {
  2311. alarm.type3CH = type3Strs[0].Trim(); // 分类层级3 中文
  2312. alarm.type3 = type3Strs[1].Trim(); // 分类层级3
  2313. if (string.IsNullOrEmpty(alarm.type3))
  2314. alarm.type3 = alarm.type3CH;
  2315. }
  2316. }
  2317. string faultStr = DtModel.Rows[i]["分类层级4"]?.ToString(); // 故障部件;overall_module
  2318. alarm.type4 = faultStr; // 分类层级4 中文
  2319. alarm.type4CH = faultStr; // 分类层级4
  2320. if (!string.IsNullOrEmpty(faultStr) && faultStr.Contains("\n"))
  2321. {
  2322. string[] faultStrs = faultStr.Split('\n');
  2323. if (faultStrs.Length >= 2)
  2324. {
  2325. alarm.type4CH = faultStrs[0].Trim(); // 故障部件;overall_module
  2326. alarm.type4 = faultStrs[1].Trim(); // 故障部件
  2327. if (string.IsNullOrEmpty(alarm.type4))
  2328. alarm.type4 = alarm.type4CH;
  2329. }
  2330. }
  2331. alarm.fault_code = DtModel.Rows[i]["事件ID"]?.ToString(); // 故障编码;A40001
  2332. alarm.fault_name = DtModel.Rows[i]["事件名称"]?.ToString(); // 故障名称;AL[1000]_系统_HMI急停故障
  2333. alarm.fault_desc = alarm.fault_name; // 故障描述;AL[1000]_系统_HMI急停故障
  2334. string plcAdress = DtModel.Rows[i]["PLC地址"]?.ToString();
  2335. alarm.PLC地址 = plcAdress;
  2336. plcAdress = plcAdress.Replace("fault_codes[", "");
  2337. plcAdress = plcAdress.Replace("]", "");
  2338. alarm.group_index = Convert.ToInt32(plcAdress.Split(".")[0]);
  2339. keyValues1.Add(alarm);
  2340. }
  2341. DicAlarms_Cur.Add(GlobalContext.IsUseStationName, keyValues1); // 这里使用线体代替工位
  2342. return (true, "报警字典表初始化成功!");
  2343. }
  2344. private async void ReadPLCAlarmToIot(uint[] FaultData, uint[] FaultDataOld, string stationNameStr,string flag)
  2345. {
  2346. DateTime dtNow = DateTime.Now;
  2347. try
  2348. {
  2349. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  2350. List<(int, int)> AlarmIndexList = new List<(int, int)>(); //收集所有报警信息的位置
  2351. AlarmData alarmData = new AlarmData();
  2352. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  2353. bool isNoAlarm = false; //是否有报警
  2354. string binaryString = "";
  2355. bool isNoNewAlarm = false; //是否有新的报警
  2356. if (FaultData.Length > 0)
  2357. {
  2358. //foreach (var item in FaultData)
  2359. //{
  2360. // if (item > 0)
  2361. // {
  2362. // isNoAlarm = true;
  2363. // break;
  2364. // }
  2365. // else {
  2366. // isNoAlarm = false;
  2367. // }
  2368. //}
  2369. //如果警报都是0,则跳过解析
  2370. if (FaultData?.All(x => x == 0) ?? true)
  2371. {
  2372. if (flag == "left")
  2373. {
  2374. _FaultDatas_Old = FaultData.ToArray();
  2375. }
  2376. else
  2377. {
  2378. _FaultDatas_Old2 = FaultData.ToArray();
  2379. }
  2380. return;
  2381. }
  2382. if (!FaultData.SequenceEqual(FaultDataOld))
  2383. {
  2384. isNoNewAlarm = true;
  2385. isNeedUpdUI = true;
  2386. }
  2387. //if (FaultData.Length > 0 && isNoAlarm && isNoNewAlarm)
  2388. if (FaultData.Length > 0 && isNoNewAlarm)
  2389. {
  2390. //解析报警信息,分析当前报警在字典中的定位
  2391. for (int i = 0; i <= FaultData.Length - 1; i++)
  2392. {
  2393. var num = 0;
  2394. if (FaultData[i] > 0)
  2395. {
  2396. //转换二进制
  2397. binaryString = Convert.ToString(FaultData[i], 2);
  2398. for (int j = binaryString.Length - 1; j >= 0; j--)
  2399. {
  2400. num++;
  2401. char s = binaryString[j];
  2402. if (binaryString[j] == '1')
  2403. {
  2404. //记录1的位置
  2405. AlarmIndexList.Add((i, num - 1));
  2406. }
  2407. }
  2408. }
  2409. }
  2410. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  2411. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.IsUseStationName];
  2412. foreach ((int index, int row) in AlarmIndexList)
  2413. {
  2414. var tempDic = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList();
  2415. for (int i = 0; i < tempDic.Count - 1; i++) // 读取
  2416. {
  2417. //若报警字典第[group_index]个数据,第[i]行与AlarmIndexList中的定位匹配,则添加进对应行的报警数据
  2418. if (tempDic[i].group_index == index && i == row)
  2419. {
  2420. dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据 =
  2421. new AlarmData()
  2422. {
  2423. GUID = Guid.NewGuid().ToString(),
  2424. LineName = GlobalContext.IsUseStationName, // 工站
  2425. PlcStation = tempDic[i].plcName, // 工站全称;[S1]
  2426. Type1 = tempDic[i].type1, // 故障层级1
  2427. Type2 = tempDic[i].type2, // 故障层级2
  2428. Type3 = tempDic[i].type3, // 故障层级3
  2429. Type4 = tempDic[i].type4, // 故障层级4
  2430. AlarmType = tempDic[i].fault_code, // 报警类型
  2431. AlarmDesc = tempDic[i].fault_name, // 报警内容
  2432. StartTime = dtNow // 开始时间
  2433. };
  2434. // 传输到页面
  2435. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  2436. {
  2437. 线体名称 = tempDic[i].plcName,
  2438. 报警类型 = tempDic[i].fault_code,
  2439. 报警内容 = tempDic[i].fault_name,
  2440. 开始时间 = dtNow
  2441. });
  2442. // 新增到数据库
  2443. //var data1 = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据;
  2444. //SaveAlarmDataByDB(stationNameStr, data1, false);
  2445. //OnMessage(LogType.Info, $"更新{BodyAlarm}完毕!");
  2446. }
  2447. }
  2448. }
  2449. //筛选含报警数据的字典
  2450. var dicAlarms_Cur = dicAlarms_Cur_PLC1.Where(x => x.报警数据 != null).ToList();
  2451. if (dicAlarms_Cur.Count > 0)
  2452. {
  2453. string stationId = "";
  2454. foreach (var item in dicAlarms_Cur)
  2455. {
  2456. if (!string.IsNullOrEmpty(xiaomiParm.stationCode))
  2457. {
  2458. stationId = xiaomiParm.stationCode;
  2459. //上传
  2460. SaveAlarmDataByDB(GlobalContext.IsUseStationName, stationId, item.报警数据, false);
  2461. }
  2462. else {
  2463. if (flag == "left")
  2464. {
  2465. if (GlobalContext.IsUsePLC3)
  2466. stationId = GlobalContext.s3_1_station;
  2467. if (GlobalContext.IsUsePLC7)
  2468. stationId = GlobalContext.s7_1_station;
  2469. //上传
  2470. SaveAlarmDataByDB(GlobalContext.IsUseStationName, stationId, item.报警数据, false);
  2471. }
  2472. else {
  2473. if (GlobalContext.IsUsePLC3)
  2474. stationId = GlobalContext.s3_2_station;
  2475. if (GlobalContext.IsUsePLC7)
  2476. stationId = GlobalContext.s7_2_station;
  2477. //上传
  2478. SaveAlarmDataByDB(GlobalContext.IsUseStationName, stationId, item.报警数据, false);
  2479. }
  2480. }
  2481. }
  2482. }
  2483. // 有新报警则更新
  2484. if (isNeedUpdUI)
  2485. // UI展示 - 展示到设备状态页
  2486. await Task.Run(() =>
  2487. {
  2488. try
  2489. {
  2490. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  2491. {
  2492. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  2493. if (Form_Main.formDevAlarm.Visible)
  2494. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  2495. }
  2496. }
  2497. catch
  2498. {
  2499. }
  2500. });
  2501. if (flag == "left")
  2502. {
  2503. _FaultDatas_Old = FaultData.ToArray();
  2504. }
  2505. else {
  2506. _FaultDatas_Old2 = FaultData.ToArray();
  2507. }
  2508. }
  2509. }
  2510. //FaultLogRequest request = new FaultLogRequest();
  2511. //request.station = mesStation; // 工位
  2512. //request.fault_name = xmFaultName; // 故障名称(同数据字典中的事件名称)
  2513. //request.fault_code = xmFaultCode2; // 故障编码(A,B,C,D,E)
  2514. //request.fault_cmpnt = xmFaultCmpnt; // 故障部件
  2515. //request.fault_desc = xmFaultDesc; // 故障描述
  2516. //request.fault_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 故障发生时间 2022-06-01 14:27:57.283
  2517. // // 上传
  2518. //(int, string) iotResult = XiaomiMqttClient_Extend.Write_FaultLog(request, type1, type2, type3, request.fault_cmpnt, deciveCode);
  2519. }
  2520. catch (Exception ex)
  2521. {
  2522. string str = ex.StackTrace;
  2523. AddMessage_Station(stationNameStr, LogType.Error,
  2524. $"{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" +
  2525. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2526. }
  2527. }
  2528. public void operateToIot(string action, string stationNameStr)
  2529. {
  2530. OperateLogRequest request = new OperateLogRequest();
  2531. request.software_version = "V" + Application.ProductVersion; // 软件版本号;如:V1.2.4
  2532. request.operate_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 操作时间(2022-06-01 14:27:57.283)
  2533. request.operate_action = action; // 操作动作(对应软件开启/关闭/重新加载项⽬;startup、shutdown、reload)
  2534. //request.current_process = Process.GetCurrentProcess()?.Id.ToString(); // 当前进程;进程ID
  2535. request.current_process = Application.ProductName;
  2536. request.operate_desc = stationNameStr; // 操作描述;如:供应商软件开启/关闭/重新加载项⽬
  2537. request.operate_result = "success"; // 操作结果
  2538. request.operator_name = "default"; // 操作账号名;填当前操作⽤⼾,如⽆则填default
  2539. // 上传
  2540. (int, string) iotResult = XiaomiMqttClient_Extend.Write_OperateLog(request);
  2541. if (iotResult.Item1 != 0)
  2542. {
  2543. AddMessage(LogType.Info, "【操作记录】上传失败!错误原因:" + iotResult.Item2 + "操作状态:" + stationNameStr);
  2544. }
  2545. }
  2546. public void deviceConfigToIot(string id, string value)
  2547. {
  2548. DeviceConfigRequest request = new DeviceConfigRequest();
  2549. request.id = id; // 操作时间(2022-06-01 14:27:57.283)
  2550. request.value = value; // 操作动作(对应软件开启/关闭/重新加载项⽬;startup、shutdown、reload)
  2551. // 上传
  2552. (int, string) iotResult = XiaomiMqttClient_Extend.Write_deviceConfig(request);
  2553. if (iotResult.Item1 != 0)
  2554. {
  2555. AddMessage(LogType.Info, "【装备配置】上传失败!错误原因:" + iotResult.Item2 );
  2556. }
  2557. }
  2558. private static readonly object _oeeLock = new object();
  2559. private void 通用节拍接口(int plcNo, string stationNameStr, string tagMesCommName, string CarrierBarcode,
  2560. IoT_DataSet_t iot_data, out int res)
  2561. {
  2562. lock (_oeeLock) // 保证同一时间只有一个任务执行
  2563. {
  2564. Stopwatch stopwatch1 = new Stopwatch();
  2565. Stopwatch stopwatch2 = new Stopwatch();
  2566. string resultStr = string.Empty;
  2567. try
  2568. {
  2569. string oEEType = iot_data.beatAction.ToString(); // 节拍类型(plc写入)
  2570. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode); //产品SN
  2571. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  2572. (short, string) result = (0, "");
  2573. // 上传开始节拍 节拍只需要PLC传1、3、4、5
  2574. result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2575. //上传结束节拍
  2576. switch (oEEType)
  2577. {
  2578. case "1":
  2579. Enum.TryParse("2", out deviceOEE);
  2580. result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2581. break;
  2582. case "5":
  2583. Enum.TryParse("6", out deviceOEE);
  2584. result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2585. break;
  2586. }
  2587. if (result.Item1 == 1)
  2588. {
  2589. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]上传成功!");
  2590. //写入PLC
  2591. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2592. iotData.machineState = iot_data.machineState;
  2593. iotData.work_type = iot_data.work_type;
  2594. iotData.testStatus = iot_data.testStatus;
  2595. iotData.beatAction = 0;
  2596. iotData.beatReturn = 1; //OK
  2597. iotData.fault_codes = iot_data.fault_codes;
  2598. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2599. if (PLCresult.Item1 == 0)
  2600. {
  2601. res = 1;
  2602. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]写入成功!");
  2603. }
  2604. else
  2605. {
  2606. res = 0;
  2607. }
  2608. }
  2609. else
  2610. {
  2611. res = 0;
  2612. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]接口出错!错误信息:" + result.Item2);
  2613. //写入PLC
  2614. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2615. iotData.machineState = iot_data.machineState;
  2616. iotData.work_type = iot_data.work_type;
  2617. iotData.testStatus = iot_data.testStatus;
  2618. iotData.beatAction = 0;
  2619. iotData.beatReturn = 2; //NG
  2620. iotData.fault_codes = iot_data.fault_codes;
  2621. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2622. }
  2623. }
  2624. catch (Exception ex)
  2625. {
  2626. res = 0;
  2627. string str = ex.StackTrace;
  2628. AddMessage_Station(stationNameStr, LogType.Error,
  2629. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  2630. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2631. //写入PLC
  2632. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2633. iotData.machineState = iot_data.machineState;
  2634. iotData.work_type = iot_data.work_type;
  2635. iotData.testStatus = iot_data.testStatus;
  2636. iotData.beatAction = 0;
  2637. iotData.beatReturn = 2; //NG
  2638. iotData.fault_codes = iot_data.fault_codes;
  2639. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2640. }
  2641. }
  2642. }
  2643. /// <summary>
  2644. /// 去除常见特殊字符,如 \r, \n, \t 等
  2645. /// </summary>
  2646. /// <param name="format"></param>
  2647. /// <returns></returns>
  2648. private static string FormatStrbyPLC(string format)
  2649. {
  2650. string cleanedString = "";
  2651. if (!string.IsNullOrEmpty(format))
  2652. {
  2653. cleanedString = Regex.Replace(format, @"[\r\n\t]", "");
  2654. }
  2655. return cleanedString;
  2656. }
  2657. private void S1_OpenDialog(int plcNo,string stationNameStr,string tagBaseName,string tagMesCommName) {
  2658. Task.Run(() =>
  2659. {
  2660. using (var dialog = new Dialog_BandBarode_S1())
  2661. {
  2662. var rs = dialog.ShowDialog();
  2663. if (rs == DialogResult.OK)
  2664. {
  2665. //绑定载具和产品
  2666. ResponseMessage message = new ResponseMessage();
  2667. message = SQLHelper.InsertCarrierBind(_strCarrierBarcode, _strProductBarcode);
  2668. if (message.result == false)
  2669. {
  2670. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  2671. CommandFromPLC CommandToPlC = new CommandFromPLC();
  2672. CommandToPlC.cmd = 0;
  2673. CommandToPlC.cmdParam = 5;
  2674. CommandToPlC.cmdResult = 0;
  2675. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, CommandToPlC);
  2676. return;
  2677. }
  2678. else
  2679. {
  2680. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定成功");
  2681. CommandFromPLC CommandToPlC = new CommandFromPLC();
  2682. CommandToPlC.cmd = 0;
  2683. CommandToPlC.cmdParam = 4;
  2684. CommandToPlC.cmdResult = 0;
  2685. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, CommandToPlC);
  2686. }
  2687. AddMessage(LogType.Info, $"载具码:{_strCarrierBarcode},产品码:{_strProductBarcode}");
  2688. //StopWhile = false;//开启while循环
  2689. }
  2690. }
  2691. });
  2692. }
  2693. /// <summary>
  2694. /// 连接数组元素
  2695. /// </summary>
  2696. /// <param name="array"></param>
  2697. /// <returns></returns>
  2698. private static string ArrayToString(Array array)
  2699. {
  2700. // 使用 string.Join 连接数组元素
  2701. return string.Join(", ", array.Cast<object>().Select(x => x.ToString()));
  2702. }
  2703. #endregion
  2704. #region S1
  2705. /// <summary>
  2706. /// [S1] 壳体清洁上料装备(10扫码改造注释(临时))
  2707. /// </summary>
  2708. /// <param name="plcNo">PLC编号</param>
  2709. //private void ReadStation_S1(int plcNo)
  2710. //{
  2711. // string stationCode = "[OP10]";
  2712. // string stationName = "壳体清洁上料";
  2713. // string stationNameStr = stationCode + stationName;
  2714. // string tagBaseName = "g_OP10_MES"; //标签变量名称
  2715. // string tagMesCommName = "mesCommToPC"; //标签变量名称
  2716. // string tagAgvCommName = "agvCommFrmPC";
  2717. // string tagiotComnName = "iotData";
  2718. // string tagBarsetName = "BarcodeSet";
  2719. // string CarrierBarcode = "";
  2720. // string ProductBarcode = "";
  2721. // // 触发信号字典
  2722. // //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2723. // s1PLCSignal_Old.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2724. // // PLC数据字典 赋值
  2725. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2726. // s1PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  2727. // OP10_MesData_t stPLC_MesData; //PLC的MES数据
  2728. // (int, string) result;
  2729. // while (true)
  2730. // {
  2731. // try
  2732. // {
  2733. // if (!GlobalContext._IsCon_Funs1)
  2734. // {
  2735. // UpdatePLCMonitor(1, plcNo, 0);
  2736. // continue;
  2737. // }
  2738. // if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2739. // {
  2740. // Stopwatch stopwatch1 = new Stopwatch();
  2741. // Stopwatch stopwatch2 = new Stopwatch();
  2742. // stopwatch1.Start();
  2743. // stopwatch2.Start();
  2744. // #region 一次性读取所有数据
  2745. // // 一次性读取所有数据
  2746. // result = FunsEip[plcNo]
  2747. // .Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2748. // if (result.Item1 != 0)
  2749. // {
  2750. // //richTextBox1.AppendText("\n" + strRet);
  2751. // }
  2752. // else
  2753. // {
  2754. // //richTextBox1.AppendText("\n" + "读取成功");
  2755. // stPLC_MesData.BarcodeSet.strProductBarcode =
  2756. // FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  2757. // stPLC_MesData.BarcodeSet.strPartBarcode =
  2758. // FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  2759. // stPLC_MesData.BarcodeSet.strCarrierBarcode =
  2760. // FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  2761. // stPLC_MesData.BarcodeSet.strPCBBarcode =
  2762. // FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  2763. // //设备状态
  2764. // int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  2765. // xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  2766. // ? XiaomiDeviceState.Unknown
  2767. // : (XiaomiDeviceState)xmDeviceStateInt;
  2768. // // 载具SN
  2769. // CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode.ToString();
  2770. // // 物料码(物料码还未绑定载具SN时必填)
  2771. // ProductBarcode = stPLC_MesData.BarcodeSet.strProductBarcode;
  2772. // // 节拍
  2773. // s1PLCData["a1OEEType"] = stPLC_MesData.iotData.beatAction;
  2774. // //报警信息
  2775. // _FaultDatas = stPLC_MesData.iotData.fault_codes;
  2776. // }
  2777. // #endregion 一次性读取所有数据
  2778. // stopwatch2.Stop();
  2779. // #region 进站
  2780. // try
  2781. // {
  2782. // if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2783. // {
  2784. // lock (lockObj)
  2785. // {
  2786. // if (!ProgressState)
  2787. // {
  2788. // uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  2789. // ProgressState = true;
  2790. // Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData,
  2791. // tagBaseName + "." + tagMesCommName, out ProgressState));
  2792. // }
  2793. // }
  2794. // }
  2795. // }
  2796. // catch (Exception ex)
  2797. // {
  2798. // ProgressState = false;
  2799. // string str = ex.StackTrace;
  2800. // AddMessage_Station(stationNameStr, LogType.Error,
  2801. // $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2802. // str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2803. // }
  2804. // #endregion 进站
  2805. // #region 出站
  2806. // try
  2807. // {
  2808. // if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2809. // {
  2810. // lock (lockObj)
  2811. // {
  2812. // if (!ProgressState)
  2813. // {
  2814. // ProgressState = true;
  2815. // Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData,
  2816. // tagBaseName + "." + tagMesCommName, stationCode, stationName,
  2817. // out ProgressState));
  2818. // stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  2819. // }
  2820. // }
  2821. // }
  2822. // }
  2823. // catch (Exception ex)
  2824. // {
  2825. // ProgressState = false;
  2826. // string str = ex.StackTrace;
  2827. // AddMessage_Station(stationNameStr, LogType.Error,
  2828. // $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2829. // str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2830. // }
  2831. // #endregion 出站
  2832. // #region 节拍接口
  2833. // try
  2834. // {
  2835. // if (stPLC_MesData.iotData.beatAction > 0)
  2836. // {
  2837. // int a1OEEType = Convert.ToInt32(s1PLCData["a1OEEType"]);
  2838. // int a1OEETypeGOld = Convert.ToInt32(s1PLCSignal_Old["a1OEEType"]);
  2839. // if (a1OEEType != a1OEETypeGOld)
  2840. // {
  2841. // s1PLCData["OEETypeFlag"] = "1";
  2842. // }
  2843. // else
  2844. // {
  2845. // s1PLCData["OEETypeFlag"] = "0";
  2846. // }
  2847. // if (s1PLCData["OEETypeFlag"].ToString() == "1" && (a1OEEType == 1 || a1OEEType == 3 || a1OEEType == 4 || a1OEEType == 5))
  2848. // {
  2849. // 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  2850. // if (res == 1)
  2851. // {
  2852. // s1PLCSignal_Old["a1OEEType"] = s1PLCData["a1OEEType"];
  2853. // }
  2854. // else {
  2855. // s1PLCSignal_Old["a1OEEType"] = 0;
  2856. // }
  2857. // }
  2858. // }
  2859. // else {
  2860. // s1PLCSignal_Old["a1OEEType"] = 0;
  2861. // }
  2862. // }
  2863. // catch (Exception ex)
  2864. // {
  2865. // string str = ex.StackTrace;
  2866. // AddMessage_Station(stationNameStr, LogType.Error,
  2867. // $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  2868. // str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2869. // }
  2870. // #endregion
  2871. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2872. // stopwatch1.Stop();
  2873. // //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2874. // }
  2875. // else
  2876. // {
  2877. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2878. // AddMessage_Station(stationNameStr, LogType.Info,
  2879. // "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2880. // FunsEip[plcNo].Connect(); // 重连
  2881. // }
  2882. // }
  2883. // catch (Exception ex)
  2884. // {
  2885. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2886. // AddMessage_Station(stationNameStr, LogType.Error,
  2887. // $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2888. // }
  2889. // Thread.Sleep(IntervalReadPLC);
  2890. // }
  2891. //}
  2892. /// <summary>
  2893. /// [S1] 壳体清洁上料装备(10扫码改造注释(临时))
  2894. /// </summary>
  2895. /// <param name="plcNo">PLC编号</param>
  2896. private async void ReadStation_S1(int plcNo)
  2897. {
  2898. string stationCode = "[OP10]";
  2899. string stationName = "壳体清洁上料";
  2900. string stationNameStr = stationCode + stationName;
  2901. string tagBaseName = "g_OP10_MES"; //标签变量名称
  2902. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2903. string tagAgvCommName = "agvCommFrmPC";
  2904. string tagiotComnName = "iotData";
  2905. string tagBarsetName = "BarcodeSet";
  2906. string CarrierBarcode = "";
  2907. string ProductBarcode = "";
  2908. // 触发信号字典
  2909. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2910. s1PLCSignal_Old.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2911. // PLC数据字典 赋值
  2912. s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2913. s1PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  2914. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  2915. (int, string) result;
  2916. while (true)
  2917. {
  2918. try
  2919. {
  2920. if (!GlobalContext._IsCon_Funs1)
  2921. {
  2922. UpdatePLCMonitor(1, plcNo, 0);
  2923. continue;
  2924. }
  2925. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2926. {
  2927. Stopwatch stopwatch1 = new Stopwatch();
  2928. Stopwatch stopwatch2 = new Stopwatch();
  2929. stopwatch1.Start();
  2930. stopwatch2.Start();
  2931. #region 一次性读取所有数据
  2932. // 一次性读取所有数据
  2933. result = FunsEip[plcNo]
  2934. .Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2935. if (result.Item1 != 0)
  2936. {
  2937. //richTextBox1.AppendText("\n" + strRet);
  2938. }
  2939. else
  2940. {
  2941. //测试数据
  2942. //stPLC_MesData.mesCommFrmPLC.cmdParam = 1;
  2943. //richTextBox1.AppendText("\n" + "读取成功");
  2944. stPLC_MesData.BarcodeSet.strProductBarcode =
  2945. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  2946. stPLC_MesData.BarcodeSet.strPartBarcode =
  2947. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  2948. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  2949. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  2950. stPLC_MesData.BarcodeSet.strPCBBarcode =
  2951. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  2952. //设备状态
  2953. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  2954. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  2955. ? XiaomiDeviceState.Unknown
  2956. : (XiaomiDeviceState)xmDeviceStateInt;
  2957. // 载具SN
  2958. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode.ToString();
  2959. // 物料码(物料码还未绑定载具SN时必填)
  2960. ProductBarcode = stPLC_MesData.BarcodeSet.strProductBarcode;
  2961. // 节拍
  2962. s1PLCData["a1OEEType"] = stPLC_MesData.iotData.beatAction;
  2963. //报警信息
  2964. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  2965. //if (stPLC_MesData.mesCommFrmPLC.cmdParam == 2)
  2966. //{
  2967. // BandBarodeDialog_S1.isNoClose=true;
  2968. //}
  2969. }
  2970. #endregion 一次性读取所有数据
  2971. stopwatch2.Stop();
  2972. #region 扫码
  2973. //弹窗期间跳过循环
  2974. //if (StopWhile)
  2975. //{
  2976. // continue;
  2977. //}
  2978. if (stPLC_MesData.mesCommFrmPLC.cmdParam==1)
  2979. {
  2980. if (OpenDailogFalg)
  2981. {
  2982. //await S1_OpenDialog(plcNo, stationNameStr, tagBaseName, tagMesCommName);
  2983. S1_OpenDialog(plcNo, stationNameStr, tagBaseName, tagMesCommName);
  2984. }
  2985. //using (var dialog = new BandBarodeDialog_S1())
  2986. //{
  2987. // var rs = dialog.ShowDialog();
  2988. // if (rs == DialogResult.OK)
  2989. // {
  2990. // //绑定载具和产品
  2991. // ResponseMessage message = new ResponseMessage();
  2992. // message = SQLHelper.InsertCarrierBind(_strCarrierBarcode, _strProductBarcode);
  2993. // if (message.result == false)
  2994. // {
  2995. // AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  2996. // CommandFromPLC CommandToPlC = new CommandFromPLC();
  2997. // CommandToPlC.cmd = 0;
  2998. // CommandToPlC.cmdParam = 5;
  2999. // CommandToPlC.cmdResult = 0;
  3000. // WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, CommandToPlC);
  3001. // return;
  3002. // }
  3003. // else
  3004. // {
  3005. // AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定成功");
  3006. // CommandFromPLC CommandToPlC = new CommandFromPLC();
  3007. // CommandToPlC.cmd = 0;
  3008. // CommandToPlC.cmdParam = 4;
  3009. // CommandToPlC.cmdResult = 0;
  3010. // WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, CommandToPlC);
  3011. // }
  3012. // AddMessage(LogType.Info, $"载具码:{_strCarrierBarcode},产品码:{_strCarrierBarcode}");
  3013. // //StopWhile = false;//开启while循环
  3014. // }
  3015. //}
  3016. }
  3017. #endregion
  3018. #region 进站
  3019. try
  3020. {
  3021. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3022. {
  3023. lock (lockObj)
  3024. {
  3025. if (!ProgressState)
  3026. {
  3027. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3028. ProgressState = true;
  3029. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData,
  3030. tagBaseName + "." + tagMesCommName, out ProgressState));
  3031. }
  3032. }
  3033. }
  3034. }
  3035. catch (Exception ex)
  3036. {
  3037. ProgressState = false;
  3038. string str = ex.StackTrace;
  3039. AddMessage_Station(stationNameStr, LogType.Error,
  3040. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3041. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3042. }
  3043. #endregion 进站
  3044. #region 出站
  3045. try
  3046. {
  3047. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3048. {
  3049. lock (lockObj)
  3050. {
  3051. if (!ProgressState)
  3052. {
  3053. ProgressState = true;
  3054. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData,
  3055. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  3056. out ProgressState));
  3057. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  3058. }
  3059. }
  3060. }
  3061. }
  3062. catch (Exception ex)
  3063. {
  3064. ProgressState = false;
  3065. string str = ex.StackTrace;
  3066. AddMessage_Station(stationNameStr, LogType.Error,
  3067. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3068. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3069. }
  3070. #endregion 出站
  3071. #region 节拍接口
  3072. try
  3073. {
  3074. if (stPLC_MesData.iotData.beatAction > 0)
  3075. {
  3076. int a1OEEType = Convert.ToInt32(s1PLCData["a1OEEType"]);
  3077. int a1OEETypeGOld = Convert.ToInt32(s1PLCSignal_Old["a1OEEType"]);
  3078. if (a1OEEType != a1OEETypeGOld)
  3079. {
  3080. s1PLCData["OEETypeFlag"] = "1";
  3081. }
  3082. else
  3083. {
  3084. s1PLCData["OEETypeFlag"] = "0";
  3085. }
  3086. if (s1PLCData["OEETypeFlag"].ToString() == "1" && (a1OEEType == 1 || a1OEEType == 3 || a1OEEType == 4 || a1OEEType == 5))
  3087. {
  3088. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  3089. if (res == 1)
  3090. {
  3091. s1PLCSignal_Old["a1OEEType"] = s1PLCData["a1OEEType"];
  3092. }
  3093. else
  3094. {
  3095. s1PLCSignal_Old["a1OEEType"] = 0;
  3096. }
  3097. }
  3098. }
  3099. else
  3100. {
  3101. s1PLCSignal_Old["a1OEEType"] = 0;
  3102. }
  3103. }
  3104. catch (Exception ex)
  3105. {
  3106. string str = ex.StackTrace;
  3107. AddMessage_Station(stationNameStr, LogType.Error,
  3108. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3109. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3110. }
  3111. #endregion
  3112. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3113. stopwatch1.Stop();
  3114. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3115. }
  3116. else
  3117. {
  3118. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3119. AddMessage_Station(stationNameStr, LogType.Info,
  3120. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3121. FunsEip[plcNo].Connect(); // 重连
  3122. }
  3123. }
  3124. catch (Exception ex)
  3125. {
  3126. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3127. AddMessage_Station(stationNameStr, LogType.Error,
  3128. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3129. }
  3130. Thread.Sleep(IntervalReadPLC);
  3131. }
  3132. }
  3133. /// <summary>
  3134. /// [S1] 壳体清洁上料 - 进站
  3135. /// </summary>
  3136. /// <param name="plcNo">PLC编号</param>
  3137. /// <param name="stationNameStr">工站全称</param>
  3138. /// <param name="stPLC_MesData"></param>
  3139. /// <param name="tagMesCommName"></param>
  3140. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  3141. out bool ProgressState)
  3142. {
  3143. Stopwatch stopwatch1 = new Stopwatch();
  3144. Stopwatch stopwatch2 = new Stopwatch();
  3145. try
  3146. {
  3147. stopwatch1.Start();
  3148. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3149. //10扫码改造注释(临时)
  3150. //string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  3151. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3152. string sn = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3153. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  3154. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  3155. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3156. bool pass = a1Result == 1;
  3157. if (string.IsNullOrEmpty(sn))
  3158. {
  3159. ProgressState = false;
  3160. AddMessage(LogType.Error, $"{stationNameStr}_未能查到产品码");
  3161. Thread.Sleep(10000);
  3162. return;
  3163. }
  3164. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  3165. // sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  3166. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3167. //绑定载具和产品
  3168. //测试注释(临时)
  3169. //ResponseMessage message = new ResponseMessage();
  3170. //message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  3171. //if (message.result == false)
  3172. //{
  3173. // AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  3174. // ProgressState = false;
  3175. // Thread.Sleep(10000);
  3176. // return;
  3177. //}
  3178. // 产品SN进站
  3179. List<TestItem> item = new List<TestItem>();
  3180. stopwatch2.Start();
  3181. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3182. item, MachineId, StationId, pass, "01-SLOT-01");
  3183. stopwatch2.Stop();
  3184. //指令执行结果 1:OK 110:失败
  3185. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3186. if (mesResultFrmWeb == 1)
  3187. {
  3188. if (a1Result == 1)
  3189. {
  3190. mesResultFrmWeb = 1;
  3191. }
  3192. else
  3193. {
  3194. mesResultFrmWeb = 110;
  3195. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3196. }
  3197. }
  3198. //进站结果写入PLC
  3199. CommandFromPLC resultToPlC = new CommandFromPLC();
  3200. resultToPlC.cmd = 0;
  3201. resultToPlC.cmdParam = 0;
  3202. resultToPlC.cmdResult = mesResultFrmWeb;
  3203. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3204. }
  3205. catch (Exception ex)
  3206. {
  3207. string str = ex.StackTrace;
  3208. AddMessage(LogType.Error,
  3209. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3210. str.Length - str.LastIndexOf("\\") - 1));
  3211. CommandFromPLC resultToPlC = new CommandFromPLC();
  3212. resultToPlC.cmd = 0;
  3213. resultToPlC.cmdParam = 0; //指令参数
  3214. resultToPlC.cmdResult = 110;
  3215. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3216. }
  3217. stopwatch1.Stop();
  3218. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3219. AddMessage(LogType.Info,
  3220. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3221. stopwatch2.ElapsedMilliseconds + "ms");
  3222. ProgressState = false;
  3223. }
  3224. /// <summary>
  3225. /// [S1] 壳体清洁上料 - 出站接口
  3226. /// </summary>
  3227. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  3228. string stationCode, string stationName, out bool ProgressState)
  3229. {
  3230. Stopwatch stopwatch1 = new Stopwatch();
  3231. Stopwatch stopwatch2 = new Stopwatch();
  3232. try
  3233. {
  3234. stopwatch1.Start();
  3235. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3236. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3237. string processItem = stationName; // 项目
  3238. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3239. string supplierCode = ""; // 供应商代码
  3240. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  3241. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  3242. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  3243. string sn = string.Empty;
  3244. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3245. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  3246. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  3247. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3248. //a1Result = 1;
  3249. bool pass = a1Result == 1;
  3250. //根据载具码获取产品码
  3251. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3252. if (string.IsNullOrEmpty(strProductBarcode))
  3253. {
  3254. ProgressState = false;
  3255. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3256. Thread.Sleep(10000);
  3257. return;
  3258. }
  3259. sn = strProductBarcode;
  3260. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3261. List<TestItem> items = new List<TestItem>();
  3262. items.Add(new TestItem()
  3263. {
  3264. Parameter_name = "载具码",
  3265. Parameter_value = CarrierBarcode,
  3266. Parameter_unit = ""
  3267. });
  3268. items.Add(new TestItem()
  3269. {
  3270. Parameter_name = "产品码",
  3271. Parameter_value = sn,
  3272. Parameter_unit = ""
  3273. });
  3274. #region 转换过站明细字符串
  3275. //创建字典
  3276. var dic = new Dictionary<string, string>();
  3277. // 获取结构体类型
  3278. FieldInfo[] fields = typeof(OP40_DataSet_t).GetFields();
  3279. string resultString = "";
  3280. // 遍历变量名转换成字典描述
  3281. foreach (FieldInfo field in fields)
  3282. {
  3283. //获取枚举描述
  3284. string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
  3285. typeof(XiaomiMESEnum_ProcessData.Enum_40_ProcessData));
  3286. //获取过站明细的值
  3287. object valueObj = field.GetValue(stPLC_MesData.mesData) ?? 0;
  3288. // 检查是否为数组
  3289. if (valueObj.GetType().IsArray)
  3290. {
  3291. var array = valueObj as Array;
  3292. resultString = ArrayToString(array);
  3293. }
  3294. else
  3295. {
  3296. resultString = valueObj.ToString();
  3297. }
  3298. dic.Add(name, resultString);
  3299. }
  3300. string paramJson = JsonConvert.SerializeObject(dic);
  3301. #endregion
  3302. //出站接口
  3303. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3304. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "01-SLOT-01",
  3305. MachineId, StationId, "", paramJson,new XmStationOut_InspectionItemData(), "");
  3306. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3307. if (mesResultFrmWeb == 1)
  3308. {
  3309. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3310. if (mesResultFrmWeb == 110)
  3311. {
  3312. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  3313. }
  3314. }
  3315. stopwatch2.Start();
  3316. //进站结果写入PLC
  3317. CommandFromPLC resultToPlC = new CommandFromPLC();
  3318. resultToPlC.cmd = 0;
  3319. resultToPlC.cmdParam = 0; //指令参数
  3320. resultToPlC.cmdResult = mesResultFrmWeb;
  3321. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3322. stopwatch2.Stop();
  3323. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3324. //保存PLC返回MES数据到本地
  3325. ResponseMessage message = new ResponseMessage();
  3326. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  3327. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress,
  3328. stPLC_MesData.mesData.fCleanSpeed,
  3329. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime,
  3330. stPLC_MesData.mesData.nCleanCount,
  3331. stPLC_MesData.mesData.nRemainCount);
  3332. if (message.result == false)
  3333. {
  3334. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3335. }
  3336. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  3337. }
  3338. catch (Exception ex)
  3339. {
  3340. stopwatch2.Start();
  3341. CommandFromPLC resultToPlC = new CommandFromPLC();
  3342. resultToPlC.cmd = 0;
  3343. resultToPlC.cmdParam = 0; //指令参数
  3344. resultToPlC.cmdResult = 110;
  3345. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3346. stopwatch2.Stop();
  3347. string str = ex.StackTrace;
  3348. AddMessage(LogType.Error,
  3349. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3350. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3351. }
  3352. stopwatch1.Stop();
  3353. AddMessage(LogType.Info,
  3354. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3355. stopwatch2.ElapsedMilliseconds + "ms");
  3356. ProgressState = false;
  3357. uuid = "";
  3358. }
  3359. #endregion
  3360. #region S2
  3361. /// <summary>
  3362. /// [S2] 上盖板上料装备
  3363. /// </summary>
  3364. /// <param name="plcNo">PLC编号</param>
  3365. private void ReadStation_S2(int plcNo)
  3366. {
  3367. string stationCode = "[OP20]";
  3368. string stationName = "上盖板上料装备";
  3369. string stationNameStr = stationCode + stationName;
  3370. string tagBaseName = "g_OP20_MES"; //标签变量名称
  3371. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3372. string tagAgvCommName = "agvCommFrmPC";
  3373. string tagiotComnName = "iotData";
  3374. string tagBarsetName = "BarcodeSet";
  3375. string CarrierBarcode = "";
  3376. // 触发信号字典
  3377. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  3378. s2PLCSignal_Old.Add("a2OEEType", 0); // 节拍类型(plc写入)
  3379. // PLC数据字典 赋值
  3380. s2PLCData.Add("a2OEEType", 0); // 节拍类型(plc写入)
  3381. s2PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  3382. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  3383. (int, string) result;
  3384. while (true)
  3385. {
  3386. try
  3387. {
  3388. if (!GlobalContext._IsCon_Funs2)
  3389. {
  3390. UpdatePLCMonitor(1, plcNo, 0);
  3391. continue;
  3392. }
  3393. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3394. {
  3395. Stopwatch stopwatch1 = new Stopwatch();
  3396. Stopwatch stopwatch2 = new Stopwatch();
  3397. stopwatch1.Start();
  3398. stopwatch2.Start();
  3399. #region 一次性读取所有数据
  3400. // 一次性读取所有数据
  3401. result = FunsEip[plcNo]
  3402. .Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3403. if (result.Item1 != 0)
  3404. {
  3405. //richTextBox1.AppendText("\n" + strRet);
  3406. }
  3407. else
  3408. {
  3409. //richTextBox1.AppendText("\n" + "读取成功");
  3410. stPLC_MesData.BarcodeSet.strProductBarcode =
  3411. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  3412. stPLC_MesData.BarcodeSet.strPartBarcode =
  3413. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  3414. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  3415. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  3416. stPLC_MesData.BarcodeSet.strPCBBarcode =
  3417. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  3418. //设备状态
  3419. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  3420. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  3421. ? XiaomiDeviceState.Unknown
  3422. : (XiaomiDeviceState)xmDeviceStateInt;
  3423. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  3424. s2PLCData["a2OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  3425. //报警信息
  3426. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  3427. }
  3428. #endregion 一次性读取所有数据
  3429. stopwatch2.Stop();
  3430. #region 进站
  3431. try
  3432. {
  3433. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3434. {
  3435. lock (lockObj)
  3436. {
  3437. if (!ProgressState)
  3438. {
  3439. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3440. ProgressState = true;
  3441. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData,
  3442. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  3443. out ProgressState));
  3444. }
  3445. }
  3446. }
  3447. }
  3448. catch (Exception ex)
  3449. {
  3450. ProgressState = false;
  3451. string str = ex.StackTrace;
  3452. AddMessage_Station(stationNameStr, LogType.Error,
  3453. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3454. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3455. }
  3456. #endregion 进站
  3457. #region 出站
  3458. try
  3459. {
  3460. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3461. {
  3462. lock (lockObj)
  3463. {
  3464. if (!ProgressState)
  3465. {
  3466. ProgressState = true;
  3467. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData,
  3468. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  3469. out ProgressState));
  3470. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  3471. }
  3472. }
  3473. }
  3474. }
  3475. catch (Exception ex)
  3476. {
  3477. ProgressState = false;
  3478. string str = ex.StackTrace;
  3479. AddMessage_Station(stationNameStr, LogType.Error,
  3480. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3481. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3482. }
  3483. #endregion 出站
  3484. #region 节拍接口
  3485. try
  3486. {
  3487. if (stPLC_MesData.iotData.beatAction > 0)
  3488. {
  3489. int a2OEEType = Convert.ToInt32(s2PLCData["a2OEEType"]);
  3490. int a2OEETypeGOld = Convert.ToInt32(s2PLCSignal_Old["a2OEEType"]);
  3491. if (a2OEEType != a2OEETypeGOld)
  3492. {
  3493. s2PLCData["OEETypeFlag"] = "1";
  3494. }
  3495. else
  3496. {
  3497. s2PLCData["OEETypeFlag"] = "0";
  3498. }
  3499. if (s2PLCData["OEETypeFlag"].ToString() == "1" && (a2OEEType == 1 || a2OEEType == 3 || a2OEEType == 4 || a2OEEType == 5))
  3500. {
  3501. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  3502. if (res == 1)
  3503. {
  3504. s2PLCSignal_Old["a2OEEType"] = s2PLCData["a2OEEType"];
  3505. }
  3506. else
  3507. {
  3508. s2PLCSignal_Old["a2OEEType"] = 0;
  3509. }
  3510. }
  3511. }
  3512. else {
  3513. s2PLCSignal_Old["a2OEEType"] = 0;
  3514. }
  3515. }
  3516. catch (Exception ex)
  3517. {
  3518. string str = ex.StackTrace;
  3519. AddMessage_Station(stationNameStr, LogType.Error,
  3520. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3521. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3522. }
  3523. #endregion
  3524. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3525. stopwatch1.Stop();
  3526. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  3527. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3528. }
  3529. else
  3530. {
  3531. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3532. AddMessage_Station(stationNameStr, LogType.Info,
  3533. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3534. FunsEip[plcNo].Connect();
  3535. }
  3536. }
  3537. catch (Exception ex)
  3538. {
  3539. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3540. AddMessage_Station(stationNameStr, LogType.Error,
  3541. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3542. //Funs[plcNo].ReConnect();
  3543. }
  3544. Thread.Sleep(IntervalReadPLC);
  3545. }
  3546. }
  3547. /// <summary>
  3548. /// [S2] 上盖板上料装备
  3549. /// </summary>
  3550. /// <param name="plcNo">PLC编号</param>
  3551. /// <param name="stationNameStr">工站全称</param>
  3552. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  3553. string tagBarsetName, out bool ProgressState)
  3554. {
  3555. Stopwatch stopwatch1 = new Stopwatch();
  3556. Stopwatch stopwatch2 = new Stopwatch();
  3557. try
  3558. {
  3559. stopwatch1.Start();
  3560. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3561. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  3562. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  3563. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3564. bool pass = a1Result == 1;
  3565. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  3566. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  3567. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3568. //根据载具码获取产品码
  3569. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3570. if (string.IsNullOrEmpty(strProductBarcode))
  3571. {
  3572. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3573. ProgressState = false;
  3574. Thread.Sleep(10000);
  3575. return;
  3576. }
  3577. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  3578. //if (sn != strProductBarcode)
  3579. //{
  3580. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  3581. //}
  3582. sn = strProductBarcode;
  3583. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3584. // 产品SN(物料码)校验
  3585. List<TestItem> item = new List<TestItem>();
  3586. stopwatch2.Start();
  3587. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3588. item, MachineId, StationId, pass, "01-SLOT-01");
  3589. stopwatch2.Stop();
  3590. //指令执行结果 1:OK 110:失败
  3591. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3592. if (mesResultFrmWeb == 1)
  3593. {
  3594. if (a1Result == 1)
  3595. {
  3596. mesResultFrmWeb = 1;
  3597. }
  3598. else
  3599. {
  3600. mesResultFrmWeb = 110;
  3601. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3602. }
  3603. }
  3604. //进站结果写入PLC
  3605. CommandFromPLC resultToPlC = new CommandFromPLC();
  3606. resultToPlC.cmd = 0;
  3607. resultToPlC.cmdParam = 0; //指令参数
  3608. resultToPlC.cmdResult = mesResultFrmWeb;
  3609. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3610. }
  3611. catch (Exception ex)
  3612. {
  3613. string str = ex.StackTrace;
  3614. AddMessage(LogType.Error,
  3615. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3616. str.Length - str.LastIndexOf("\\") - 1));
  3617. CommandFromPLC resultToPlC = new CommandFromPLC();
  3618. resultToPlC.cmd = 0;
  3619. resultToPlC.cmdParam = 0; //指令参数
  3620. resultToPlC.cmdResult = 110;
  3621. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3622. }
  3623. stopwatch1.Stop();
  3624. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3625. AddMessage(LogType.Info,
  3626. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3627. stopwatch2.ElapsedMilliseconds + "ms");
  3628. ProgressState = false;
  3629. }
  3630. /// <summary>
  3631. /// [S2] 上盖板上料装备 - 出站接口
  3632. /// </summary>
  3633. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  3634. string stationCode, string stationName, out bool ProgressState)
  3635. {
  3636. Stopwatch stopwatch1 = new Stopwatch();
  3637. Stopwatch stopwatch2 = new Stopwatch();
  3638. try
  3639. {
  3640. stopwatch1.Start();
  3641. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3642. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3643. string processItem = stationName; // 测试项目
  3644. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3645. string supplierCode = ""; // 供应商代码
  3646. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3647. string batch_num = GlobalContext.BatchNumber; // 批次号
  3648. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3649. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3650. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3651. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  3652. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  3653. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  3654. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3655. bool pass = a1Result == 1;
  3656. //根据载具码获取产品码
  3657. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3658. if (string.IsNullOrEmpty(strProductBarcode))
  3659. {
  3660. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3661. ProgressState = false;
  3662. Thread.Sleep(10000);
  3663. return;
  3664. }
  3665. sn = strProductBarcode;
  3666. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3667. List<TestItem> items = new List<TestItem>();
  3668. items.Add(new TestItem()
  3669. {
  3670. Parameter_name = "载具码",
  3671. Parameter_value = CarrierBarcode,
  3672. Parameter_unit = ""
  3673. });
  3674. items.Add(new TestItem()
  3675. {
  3676. Parameter_name = "产品码",
  3677. Parameter_value = sn,
  3678. Parameter_unit = ""
  3679. });
  3680. items.Add(new TestItem()
  3681. {
  3682. Parameter_name = "部件码",
  3683. Parameter_value = PartBarcode,
  3684. Parameter_unit = ""
  3685. });
  3686. #region 转换过站明细字符串
  3687. ////创建字典
  3688. //var dic = new Dictionary<string, string>();
  3689. //// 获取结构体类型
  3690. //FieldInfo[] fields = typeof(OP40_DataSet_t).GetFields();
  3691. //string resultString = "";
  3692. //// 遍历变量名转换成字典描述
  3693. //foreach (FieldInfo field in fields)
  3694. //{
  3695. // //获取枚举描述
  3696. // string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
  3697. // typeof(XiaomiMESEnum_ProcessData.Enum_40_ProcessData));
  3698. // //获取过站明细的值
  3699. // object valueObj = field.GetValue(stPLC_MesData.mesData) ?? 0;
  3700. // // 检查是否为数组
  3701. // if (valueObj.GetType().IsArray)
  3702. // {
  3703. // var array = valueObj as Array;
  3704. // resultString = ArrayToString(array);
  3705. // }
  3706. // else
  3707. // {
  3708. // resultString = valueObj.ToString();
  3709. // }
  3710. // dic.Add(name, resultString);
  3711. //}
  3712. //string paramJson = JsonConvert.SerializeObject(dic);
  3713. #endregion
  3714. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3715. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3716. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "01-SLOT-01",
  3717. MachineId, StationId, PartBarcode, paramJson,new XmStationOut_InspectionItemData(), "");
  3718. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3719. if (mesResultFrmWeb == 1)
  3720. {
  3721. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3722. if (mesResultFrmWeb == 110)
  3723. {
  3724. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  3725. }
  3726. }
  3727. stopwatch2.Start();
  3728. //进站结果写入PLC
  3729. CommandFromPLC resultToPlC = new CommandFromPLC();
  3730. resultToPlC.cmd = 0;
  3731. resultToPlC.cmdParam = 0; //指令参数
  3732. resultToPlC.cmdResult = mesResultFrmWeb;
  3733. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3734. stopwatch2.Stop();
  3735. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3736. //保存PLC返回MES数据到本地
  3737. ResponseMessage message = new ResponseMessage();
  3738. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  3739. stPLC_MesData.mesData.nRemainCount);
  3740. if (message.result == false)
  3741. {
  3742. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3743. }
  3744. if (!string.IsNullOrEmpty(PartBarcode))
  3745. {
  3746. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  3747. if (message.result == false)
  3748. {
  3749. AddMessage(LogType.Error, message.text);
  3750. }
  3751. }
  3752. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3753. }
  3754. catch (Exception ex)
  3755. {
  3756. stopwatch2.Start();
  3757. CommandFromPLC resultToPlC = new CommandFromPLC();
  3758. resultToPlC.cmd = 0;
  3759. resultToPlC.cmdParam = 0; //指令参数
  3760. resultToPlC.cmdResult = 110;
  3761. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3762. stopwatch2.Stop();
  3763. string str = ex.StackTrace;
  3764. AddMessage(LogType.Error,
  3765. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3766. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3767. }
  3768. stopwatch1.Stop();
  3769. AddMessage(LogType.Info,
  3770. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3771. stopwatch2.ElapsedMilliseconds + "ms");
  3772. ProgressState = false;
  3773. uuid = "";
  3774. }
  3775. #endregion
  3776. #region S3
  3777. /// <summary>
  3778. /// [S3] 点散热胶装备
  3779. /// </summary>
  3780. /// <param name="plcNo">PLC编号</param>
  3781. private void ReadStation_S3(int plcNo)
  3782. {
  3783. string stationCode = "[OP30]";
  3784. string stationName = "点散热胶装备";
  3785. string stationNameStr = stationCode + stationName;
  3786. string tagBaseName = "g_OP30_MES"; //标签变量名称
  3787. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3788. string tagAgvCommName = "agvCommFrmPC";
  3789. string tagiotComnName = "iotData";
  3790. string tagBarsetName = "BarcodeSet";
  3791. string CarrierBarcode_Left = "";
  3792. string CarrierBarcode_Right = "";
  3793. s3PLCSignal_Old.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
  3794. s3PLCSignal_Old.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
  3795. // PLC数据字典 赋值
  3796. s3PLCData.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
  3797. s3PLCData.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
  3798. s5PLCData.Add("OEETypeFlag_left", 0); // 节拍标识 0 不上传 ,1 上传
  3799. s5PLCData.Add("OEETypeFlag_right", 0); // 节拍标识 0 不上传 ,1 上传
  3800. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  3801. (int, string) result;
  3802. while (true)
  3803. {
  3804. try
  3805. {
  3806. if (!GlobalContext._IsCon_Funs2)
  3807. {
  3808. UpdatePLCMonitor(1, plcNo, 0);
  3809. continue;
  3810. }
  3811. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3812. {
  3813. Stopwatch stopwatch1 = new Stopwatch();
  3814. Stopwatch stopwatch2 = new Stopwatch();
  3815. stopwatch1.Start();
  3816. stopwatch2.Start();
  3817. #region 一次性读取所有数据
  3818. // 一次性读取所有数据
  3819. result = FunsEip[plcNo]
  3820. .Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3821. if (result.Item1 != 0)
  3822. {
  3823. //richTextBox1.AppendText("\n" + strRet);
  3824. }
  3825. else
  3826. {
  3827. //测试数据
  3828. //stPLC_MesData.Left.mesCommFrmPLC.cmdParam = 1;
  3829. //stPLC_MesData.Left.BarcodeSet.strCarrierBarcode = "A123456";
  3830. //stPLC_MesData.Left.BarcodeSet.strPCBBarcode = "A1507V000239";
  3831. //stPLC_MesData.Left.iotData.beatAction = 1;
  3832. //stPLC_MesData.Left.iotData.beatAction = 2;
  3833. //stPLC_MesData.Left.BarcodeSet.strCarrierBarcode = "A123456";
  3834. //stPLC_MesData.Left.testData.fAB_AirPressDiff = 2.5f;
  3835. //stPLC_MesData.Left.testData.fAB_AirPressDiffMax = 2.5f;
  3836. //stPLC_MesData.Left.testData.fAB_AirPressDiffMin = 0;
  3837. //stPLC_MesData.Left.testData.fAB_AirPress = 0.1f;
  3838. //stPLC_MesData.Left.testData.fAB_AirPressMax = 0.2f;
  3839. //stPLC_MesData.Left.testData.fAB_AirPressMin = 0;
  3840. #region 去除扫码产生的特殊字符
  3841. stPLC_MesData.Left.BarcodeSet.strProductBarcode =
  3842. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strProductBarcode);
  3843. stPLC_MesData.Left.BarcodeSet.strPartBarcode =
  3844. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPartBarcode);
  3845. stPLC_MesData.Left.BarcodeSet.strCarrierBarcode =
  3846. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strCarrierBarcode);
  3847. stPLC_MesData.Left.BarcodeSet.strPCBBarcode =
  3848. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPCBBarcode);
  3849. stPLC_MesData.Right.BarcodeSet.strProductBarcode =
  3850. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strProductBarcode);
  3851. stPLC_MesData.Right.BarcodeSet.strPartBarcode =
  3852. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPartBarcode);
  3853. stPLC_MesData.Right.BarcodeSet.strCarrierBarcode =
  3854. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strCarrierBarcode);
  3855. stPLC_MesData.Right.BarcodeSet.strPCBBarcode =
  3856. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPCBBarcode);
  3857. #endregion
  3858. //richTextBox1.AppendText("\n" + "读取成功");
  3859. //设备状态
  3860. int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  3861. int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  3862. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  3863. ? XiaomiDeviceState.Unknown
  3864. : (XiaomiDeviceState)xmDeviceStateInt_L;
  3865. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  3866. ? XiaomiDeviceState.Unknown
  3867. : (XiaomiDeviceState)xmDeviceStateInt_R;
  3868. //载具SN
  3869. CarrierBarcode_Left = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode;
  3870. CarrierBarcode_Right = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode;
  3871. // 节拍
  3872. s3PLCData["a3OEEType_left"] = stPLC_MesData.Left.iotData.beatAction;
  3873. s3PLCData["a3OEEType_right"] = stPLC_MesData.Right.iotData.beatAction;
  3874. //报警信息
  3875. _FaultDatas = stPLC_MesData.Left.iotData.fault_codes;
  3876. _FaultDatas2 = stPLC_MesData.Right.iotData.fault_codes;
  3877. //_FaultDatas = new uint[] { 2, 0, 16, 0, 0, 0, 0, 0, 0, 0 };
  3878. //_FaultDatas2 = new uint[] { 2, 0, 16, 0, 0, 0, 0, 0, 0, 0 };
  3879. }
  3880. #endregion 一次性读取所有数据
  3881. stopwatch2.Stop();
  3882. #region 辅材上料扫码
  3883. if (stPLC_MesData.Left.otherData.ChangeA == 1 || stPLC_MesData.Left.otherData.ChangeB == 1)
  3884. {
  3885. }
  3886. #endregion
  3887. #region 左边进站
  3888. try
  3889. {
  3890. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3891. {
  3892. lock (lockObj)
  3893. {
  3894. if (!ProgressState)
  3895. {
  3896. stationCode = "[OP31]";
  3897. stationName = "点散热胶装备1";
  3898. stationNameStr = stationCode + stationName;
  3899. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3900. ProgressState = true;
  3901. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left,
  3902. tagBaseName + ".Left." + tagMesCommName,
  3903. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  3904. }
  3905. }
  3906. }
  3907. }
  3908. catch (Exception ex)
  3909. {
  3910. ProgressState = false;
  3911. string str = ex.StackTrace;
  3912. AddMessage_Station(stationNameStr, LogType.Error,
  3913. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3914. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3915. }
  3916. #endregion 左边进站
  3917. #region 左边出站
  3918. try
  3919. {
  3920. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3921. {
  3922. lock (lockObj)
  3923. {
  3924. if (!ProgressState)
  3925. {
  3926. stationCode = "[OP31]";
  3927. stationName = "点散热胶装备1";
  3928. stationNameStr = stationCode + stationName;
  3929. ProgressState = true;
  3930. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left,
  3931. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  3932. out ProgressState));
  3933. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  3934. }
  3935. }
  3936. }
  3937. }
  3938. catch (Exception ex)
  3939. {
  3940. ProgressState = false;
  3941. string str = ex.StackTrace;
  3942. AddMessage_Station(stationNameStr, LogType.Error,
  3943. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3944. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3945. }
  3946. #endregion 左边出站
  3947. #region 右边进站
  3948. try
  3949. {
  3950. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3951. {
  3952. lock (lockObj)
  3953. {
  3954. if (!ProgressState)
  3955. {
  3956. uuid2 = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3957. stationCode = "[OP32]";
  3958. stationName = "点散热胶装备2";
  3959. stationNameStr = stationCode + stationName;
  3960. ProgressState = true;
  3961. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right,
  3962. tagBaseName + ".Right." + tagMesCommName,
  3963. tagBaseName + ".Right." + tagBarsetName, "Right", out ProgressState));
  3964. }
  3965. }
  3966. }
  3967. }
  3968. catch (Exception ex)
  3969. {
  3970. ProgressState = false;
  3971. string str = ex.StackTrace;
  3972. AddMessage_Station(stationNameStr, LogType.Error,
  3973. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3974. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3975. }
  3976. #endregion 右边进站
  3977. #region 右边出站
  3978. try
  3979. {
  3980. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3981. {
  3982. lock (lockObj)
  3983. {
  3984. if (!ProgressState)
  3985. {
  3986. stationCode = "[OP32]";
  3987. stationName = "点散热胶装备2";
  3988. stationNameStr = stationCode + stationName;
  3989. ProgressState = true;
  3990. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right,
  3991. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  3992. out ProgressState));
  3993. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  3994. }
  3995. }
  3996. }
  3997. }
  3998. catch (Exception ex)
  3999. {
  4000. string str = ex.StackTrace;
  4001. AddMessage_Station(stationNameStr, LogType.Error,
  4002. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4003. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4004. }
  4005. #endregion 右边出站
  4006. #region 节拍接口
  4007. try
  4008. {
  4009. #region 左工位 节拍
  4010. if (stPLC_MesData.Left.iotData.beatAction > 0)
  4011. {
  4012. stationCode = "[OP31]";
  4013. stationName = "点散热胶装备1";
  4014. stationNameStr = stationCode + stationName;
  4015. int a3OEEType_left = Convert.ToInt32(s3PLCData["a3OEEType_left"]);
  4016. int a3OEETypeGOld_left = Convert.ToInt32(s3PLCSignal_Old["a3OEEType_left"]);
  4017. if (a3OEEType_left != a3OEETypeGOld_left)
  4018. {
  4019. s3PLCData["OEETypeFlag_left"] = "1";
  4020. }
  4021. else
  4022. {
  4023. s3PLCData["OEETypeFlag_left"] = "0";
  4024. }
  4025. if (s3PLCData["OEETypeFlag_left"].ToString() == "1" && (a3OEEType_left == 1 || a3OEEType_left == 3 || a3OEEType_left == 4 || a3OEEType_left == 5))
  4026. {
  4027. 通用节拍接口(plcNo, stationNameStr,
  4028. tagBaseName + ".Left." + tagiotComnName, CarrierBarcode_Left,
  4029. stPLC_MesData.Left.iotData, out res);
  4030. if (res == 1)
  4031. {
  4032. s3PLCSignal_Old["a3OEEType_left"] = a3OEEType_left;
  4033. }
  4034. else {
  4035. s3PLCSignal_Old["a3OEEType_left"] = 0;
  4036. }
  4037. }
  4038. }
  4039. else
  4040. {
  4041. s3PLCSignal_Old["a3OEEType_left"] = 0;
  4042. }
  4043. #endregion 左工位 节拍
  4044. #region 右工位 节拍
  4045. if (stPLC_MesData.Right.iotData.beatAction > 0)
  4046. {
  4047. stationCode = "[OP32]";
  4048. stationName = "点散热胶装备2";
  4049. stationNameStr = stationCode + stationName;
  4050. int a3OEEType_right = Convert.ToInt32(s3PLCData["a3OEEType_right"]);
  4051. int a3OEETypeGOld_right = Convert.ToInt32(s3PLCSignal_Old["a3OEEType_right"]);
  4052. if (a3OEEType_right != a3OEETypeGOld_right)
  4053. {
  4054. s3PLCData["OEETypeFlag_right"] = "1";
  4055. }
  4056. else
  4057. {
  4058. s3PLCData["OEETypeFlag_right"] = "0";
  4059. }
  4060. if (s3PLCData["OEETypeFlag_right"].ToString() == "1" && (a3OEEType_right == 1 || a3OEEType_right == 3 || a3OEEType_right == 4 || a3OEEType_right == 5))
  4061. {
  4062. 通用节拍接口(plcNo, stationNameStr,
  4063. tagBaseName + ".Right." + tagiotComnName, CarrierBarcode_Right,
  4064. stPLC_MesData.Right.iotData, out res);
  4065. if (res == 1)
  4066. {
  4067. s3PLCSignal_Old["a3OEEType_right"] = a3OEEType_right;
  4068. }
  4069. else {
  4070. s3PLCSignal_Old["a3OEEType_right"] = 0;
  4071. }
  4072. }
  4073. }
  4074. else
  4075. {
  4076. s3PLCSignal_Old["a3OEEType_right"] = 0;
  4077. }
  4078. #endregion 右工位 节拍
  4079. }
  4080. catch (Exception ex)
  4081. {
  4082. string str = ex.StackTrace;
  4083. AddMessage_Station(stationNameStr, LogType.Error,
  4084. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4085. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4086. }
  4087. #endregion
  4088. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4089. stopwatch1.Stop();
  4090. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  4091. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4092. }
  4093. else
  4094. {
  4095. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4096. AddMessage_Station(stationNameStr, LogType.Info,
  4097. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4098. FunsEip[plcNo].Connect();
  4099. }
  4100. }
  4101. catch (Exception ex)
  4102. {
  4103. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4104. AddMessage_Station(stationNameStr, LogType.Error,
  4105. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4106. //Funs[plcNo].ReConnect();
  4107. }
  4108. Thread.Sleep(IntervalReadPLC);
  4109. }
  4110. }
  4111. /// <summary>
  4112. /// [S3] 点散热胶装备 - 进站
  4113. /// </summary>
  4114. /// <param name="plcNo">PLC编号</param>
  4115. /// <param name="stationNameStr">工站全称</param>
  4116. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  4117. string tagBarsetName, string direction, out bool ProgressState)
  4118. {
  4119. Stopwatch stopwatch1 = new Stopwatch();
  4120. Stopwatch stopwatch2 = new Stopwatch();
  4121. try
  4122. {
  4123. stopwatch1.Start();
  4124. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  4125. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4126. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  4127. string StationId = string.Empty;
  4128. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4129. bool pass = a1Result == 1;
  4130. string slot = "";
  4131. if (direction == "Left")
  4132. {
  4133. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  4134. slot = "01-SLOT-01";
  4135. }
  4136. if (direction == "Right")
  4137. {
  4138. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  4139. slot = "01-SLOT-02";
  4140. }
  4141. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4142. //载具码验证产品码
  4143. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4144. if (string.IsNullOrEmpty(strProductBarcode))
  4145. {
  4146. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4147. ProgressState = false;
  4148. Thread.Sleep(10000);
  4149. return;
  4150. }
  4151. sn = strProductBarcode;
  4152. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  4153. // 产品SN(物料码)校验
  4154. List<TestItem> item = new List<TestItem>();
  4155. stopwatch2.Start();
  4156. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  4157. item, MachineId, StationId, pass, slot);
  4158. stopwatch2.Stop();
  4159. //指令执行结果 1:OK 110:失败
  4160. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4161. if (mesResultFrmWeb == 1)
  4162. {
  4163. if (a1Result == 1)
  4164. {
  4165. mesResultFrmWeb = 1;
  4166. }
  4167. else
  4168. {
  4169. mesResultFrmWeb = 110;
  4170. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  4171. }
  4172. }
  4173. //进站结果写入PLC
  4174. CommandFromPLC resultToPlC = new CommandFromPLC();
  4175. resultToPlC.cmd = 0;
  4176. resultToPlC.cmdParam = 0; //指令参数
  4177. resultToPlC.cmdResult = mesResultFrmWeb;
  4178. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4179. }
  4180. catch (Exception ex)
  4181. {
  4182. string str = ex.StackTrace;
  4183. AddMessage(LogType.Error,
  4184. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4185. str.Length - str.LastIndexOf("\\") - 1));
  4186. CommandFromPLC resultToPlC = new CommandFromPLC();
  4187. resultToPlC.cmd = 0;
  4188. resultToPlC.cmdParam = 0; //指令参数
  4189. resultToPlC.cmdResult = 110;
  4190. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4191. }
  4192. stopwatch1.Stop();
  4193. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  4194. AddMessage(LogType.Info,
  4195. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4196. stopwatch2.ElapsedMilliseconds + "ms");
  4197. ProgressState = false;
  4198. }
  4199. /// <summary>
  4200. /// [S3] 点散热胶装备 - 出站
  4201. /// </summary>
  4202. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  4203. string stationCode, string stationName, string direction, out bool ProgressState)
  4204. {
  4205. Stopwatch stopwatch1 = new Stopwatch();
  4206. Stopwatch stopwatch2 = new Stopwatch();
  4207. try
  4208. {
  4209. stopwatch1.Start();
  4210. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  4211. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4212. string processItem = stationName; // 测试项目
  4213. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4214. string supplierCode = ""; // 供应商代码
  4215. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4216. string batch_num = GlobalContext.BatchNumber; // 批次号
  4217. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4218. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4219. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4220. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  4221. string StationId = string.Empty;
  4222. string slot = "";
  4223. if (direction == "Left")
  4224. {
  4225. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  4226. slot = "01-SLOT-01";
  4227. }
  4228. if (direction == "Right")
  4229. {
  4230. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  4231. slot = "01-SLOT-02";
  4232. }
  4233. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4234. bool pass = a1Result == 1;
  4235. //根据载具码获取产品码
  4236. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4237. if (string.IsNullOrEmpty(strProductBarcode))
  4238. {
  4239. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4240. ProgressState = false;
  4241. Thread.Sleep(10000);
  4242. return;
  4243. }
  4244. Console.WriteLine($"异常1:{strProductBarcode}");
  4245. sn = strProductBarcode;
  4246. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4247. List<TestItem> items = new List<TestItem>();
  4248. items.Add(new TestItem()
  4249. {
  4250. Parameter_name = "载具码",
  4251. Parameter_value = CarrierBarcode,
  4252. Parameter_unit = ""
  4253. });
  4254. items.Add(new TestItem()
  4255. {
  4256. Parameter_name = "产品码",
  4257. Parameter_value = sn,
  4258. Parameter_unit = ""
  4259. });
  4260. #region 转换过站明细字符串
  4261. ////创建字典
  4262. //var dic = new Dictionary<string, string>();
  4263. //// 获取结构体类型
  4264. //FieldInfo[] fields = typeof(OP40_DataSet_t).GetFields();
  4265. //string resultString = "";
  4266. //// 遍历变量名转换成字典描述
  4267. //foreach (FieldInfo field in fields)
  4268. //{
  4269. // //获取枚举描述
  4270. // string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
  4271. // typeof(XiaomiMESEnum_ProcessData.Enum_40_ProcessData));
  4272. // //获取过站明细的值
  4273. // object valueObj = field.GetValue(stPLC_MesData.mesData) ?? 0;
  4274. // // 检查是否为数组
  4275. // if (valueObj.GetType().IsArray)
  4276. // {
  4277. // var array = valueObj as Array;
  4278. // resultString = ArrayToString(array);
  4279. // }
  4280. // else
  4281. // {
  4282. // resultString = valueObj.ToString();
  4283. // }
  4284. // dic.Add(name, resultString);
  4285. //}
  4286. //string paramJson = JsonConvert.SerializeObject(dic);
  4287. #endregion
  4288. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);//过站生产数据
  4289. #region MAS测试项
  4290. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  4291. string passFlag = "";
  4292. string AllpassFlag = "PASS";
  4293. float fAB_AirPressDiff = stPLC_MesData.testData.fAB_AirPressDiff;
  4294. float fAB_AirPressDiffMax = stPLC_MesData.testData.fAB_AirPressDiffMax;
  4295. float fAB_AirPressDiffMin = stPLC_MesData.testData.fAB_AirPressDiffMin;
  4296. float fAB_AirPress = stPLC_MesData.testData.fAB_AirPress;
  4297. float fAB_AirPressMax = stPLC_MesData.testData.fAB_AirPressMax;
  4298. float fAB_AirPressMin = stPLC_MesData.testData.fAB_AirPressMin;
  4299. XmStationOut_InspectionItemData inspectionItemData = new XmStationOut_InspectionItemData();
  4300. if (fAB_AirPressDiffMax > fAB_AirPressDiffMin && (fAB_AirPressDiffMax != 0 || fAB_AirPressDiffMin != 0))
  4301. {
  4302. if (fAB_AirPressDiff > fAB_AirPressDiffMin && fAB_AirPressDiff <= fAB_AirPressDiffMax)
  4303. passFlag = "PASS";
  4304. else
  4305. passFlag = "FAIL";
  4306. if (passFlag == "FAIL") AllpassFlag = passFlag;
  4307. inspectionItemData.AddDataItem("AirPressure","AB管气压", fAB_AirPressDiff.ToString(), fAB_AirPressDiffMax.ToString(), fAB_AirPressDiffMin.ToString(), passFlag);
  4308. }
  4309. if (fAB_AirPressMax > fAB_AirPressMin && (fAB_AirPressMax != 0 || fAB_AirPressMin != 0))
  4310. {
  4311. if (fAB_AirPress > fAB_AirPressMin && fAB_AirPress <= fAB_AirPressMax)
  4312. passFlag = "PASS";
  4313. else
  4314. passFlag = "FAIL";
  4315. if (passFlag == "FAIL") AllpassFlag = passFlag;
  4316. inspectionItemData.AddDataItem("AirPressure","AB管气压差", fAB_AirPress.ToString(), fAB_AirPressMax.ToString(), fAB_AirPressMin.ToString(), passFlag);
  4317. }
  4318. inspectionItemData.childUnitSn = strProductBarcode;
  4319. inspectionItemData.childUnitState = AllpassFlag;
  4320. inspectionItemData.toolVersion = "1.0";
  4321. #endregion
  4322. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4323. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, strProductBarcode, pass, CarrierBarcode,slot,
  4324. MachineId, StationId, "", paramJson, inspectionItemData, direction);
  4325. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4326. if (mesResultFrmWeb == 1)
  4327. {
  4328. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  4329. if (mesResultFrmWeb == 110)
  4330. {
  4331. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  4332. }
  4333. }
  4334. stopwatch2.Start();
  4335. //进站结果写入PLC
  4336. CommandFromPLC resultToPlC = new CommandFromPLC();
  4337. resultToPlC.cmd = 0;
  4338. resultToPlC.cmdParam = 0; //指令参数
  4339. resultToPlC.cmdResult = mesResultFrmWeb;
  4340. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4341. stopwatch2.Stop();
  4342. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  4343. //保存PLC返回MES数据到本地
  4344. ResponseMessage message = new ResponseMessage();
  4345. if (direction == "Left")
  4346. {
  4347. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  4348. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  4349. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  4350. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  4351. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  4352. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  4353. if (message.result == false)
  4354. {
  4355. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4356. }
  4357. }
  4358. if (direction == "Right")
  4359. {
  4360. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  4361. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  4362. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  4363. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  4364. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  4365. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  4366. if (message.result == false)
  4367. {
  4368. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4369. }
  4370. }
  4371. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4372. }
  4373. catch (Exception ex)
  4374. {
  4375. stopwatch2.Start();
  4376. CommandFromPLC resultToPlC = new CommandFromPLC();
  4377. resultToPlC.cmd = 0;
  4378. resultToPlC.cmdParam = 0; //指令参数
  4379. resultToPlC.cmdResult = 110;
  4380. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4381. stopwatch2.Stop();
  4382. string str = ex.StackTrace;
  4383. AddMessage(LogType.Error,
  4384. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4385. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4386. }
  4387. stopwatch1.Stop();
  4388. AddMessage(LogType.Info,
  4389. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4390. stopwatch2.ElapsedMilliseconds + "ms");
  4391. ProgressState = false;
  4392. if (direction == "Left") uuid = "";
  4393. if (direction == "Right") uuid2 = "";
  4394. }
  4395. #endregion S3
  4396. #region S4
  4397. /// <summary>
  4398. /// [S4] 点胶检测设备
  4399. /// </summary>
  4400. /// <param name="plcNo">PLC编号</param>
  4401. private void ReadStation_S4(int plcNo)
  4402. {
  4403. string stationCode = "[OP40]";
  4404. string stationName = "胶线检测";
  4405. string stationNameStr = stationCode + stationName;
  4406. string tagBaseName = "g_OP40_MES"; //标签变量名称
  4407. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4408. string tagAgvCommName = "agvCommFrmPC";
  4409. string tagiotComnName = "iotData";
  4410. string tagBarsetName = "BarcodeSet";
  4411. string CarrierBarcode = "";
  4412. // 触发信号字典
  4413. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4414. s4PLCSignal_Old.Add("a4OEEType", 0); // 节拍类型(plc写入)
  4415. // PLC数据字典 赋值
  4416. s4PLCData.Add("a4OEEType", 0); // 节拍类型(plc写入)
  4417. s4PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  4418. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  4419. (int, string) result;
  4420. while (true)
  4421. {
  4422. try
  4423. {
  4424. if (!GlobalContext._IsCon_Funs1)
  4425. {
  4426. UpdatePLCMonitor(1, plcNo, 0);
  4427. continue;
  4428. }
  4429. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4430. {
  4431. Stopwatch stopwatch1 = new Stopwatch();
  4432. Stopwatch stopwatch2 = new Stopwatch();
  4433. stopwatch1.Start();
  4434. stopwatch2.Start();
  4435. #region 一次性读取所有数据
  4436. // 一次性读取所有数据
  4437. result = FunsEip[plcNo]
  4438. .Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4439. if (result.Item1 != 0)
  4440. {
  4441. //richTextBox1.AppendText("\n" + strRet);
  4442. }
  4443. else
  4444. {
  4445. //测试数据
  4446. //stPLC_MesData.mesCommFrmPLC.cmd = 2;
  4447. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A235461";
  4448. //stPLC_MesData.BarcodeSet.strPCBBarcode = "A1507V000239";
  4449. //stPLC_MesData.testData.fGlue_Areas = new float[] { 12, 22, 16 };
  4450. //stPLC_MesData.testData.fGlue_AreasMax = 20f;
  4451. //stPLC_MesData.testData.fGlue_AreasMin = 0;
  4452. //stPLC_MesData.testData.fGlue_Heights = new float[] { 5, 8, 6.6f };
  4453. //stPLC_MesData.testData.fGlue_HeightsMax = 10f;
  4454. //stPLC_MesData.testData.fGlue_HeightsMin = 0;
  4455. //去除扫码产生的特殊字符
  4456. stPLC_MesData.BarcodeSet.strProductBarcode =
  4457. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  4458. stPLC_MesData.BarcodeSet.strPartBarcode =
  4459. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  4460. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  4461. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  4462. stPLC_MesData.BarcodeSet.strPCBBarcode =
  4463. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  4464. //richTextBox1.AppendText("\n" + "读取成功");
  4465. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  4466. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  4467. ? XiaomiDeviceState.Unknown
  4468. : (XiaomiDeviceState)xmDeviceStateInt;
  4469. // 载具SN
  4470. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode;
  4471. // 节拍
  4472. s4PLCData["a4OEEType"] = stPLC_MesData.iotData.beatAction;
  4473. //报警信息
  4474. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  4475. }
  4476. #endregion 一次性读取所有数据
  4477. stopwatch2.Stop();
  4478. #region 进站
  4479. try
  4480. {
  4481. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4482. {
  4483. lock (lockObj)
  4484. {
  4485. if (!ProgressState)
  4486. {
  4487. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  4488. ProgressState = true;
  4489. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData,
  4490. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  4491. out ProgressState));
  4492. }
  4493. }
  4494. }
  4495. }
  4496. catch (Exception ex)
  4497. {
  4498. ProgressState = false;
  4499. string str = ex.StackTrace;
  4500. AddMessage_Station(stationNameStr, LogType.Error,
  4501. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4502. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4503. }
  4504. #endregion 进站
  4505. #region 出站
  4506. try
  4507. {
  4508. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4509. {
  4510. lock (lockObj)
  4511. {
  4512. if (!ProgressState)
  4513. {
  4514. ProgressState = true;
  4515. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData,
  4516. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4517. out ProgressState));
  4518. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4519. }
  4520. }
  4521. }
  4522. }
  4523. catch (Exception ex)
  4524. {
  4525. string str = ex.StackTrace;
  4526. AddMessage_Station(stationNameStr, LogType.Error,
  4527. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4528. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4529. }
  4530. #endregion 出站
  4531. #region 节拍接口
  4532. try
  4533. {
  4534. if (stPLC_MesData.iotData.beatAction > 0)
  4535. {
  4536. int a4OEEType = Convert.ToInt32(s4PLCData["a4OEEType"]);
  4537. int a4OEETypeGOld = Convert.ToInt32(s4PLCSignal_Old["a4OEEType"]);
  4538. //若设备紧急复原后节拍重置
  4539. if (a4OEEType == 1)
  4540. {
  4541. a4OEETypeGOld = 0;
  4542. }
  4543. if (a4OEEType != a4OEETypeGOld)
  4544. {
  4545. s4PLCData["OEETypeFlag"] = "1";
  4546. }
  4547. else
  4548. {
  4549. s4PLCData["OEETypeFlag"] = "0";
  4550. }
  4551. if (s4PLCData["OEETypeFlag"].ToString() == "1" && (a4OEEType == 1 || a4OEEType == 3 || a4OEEType == 4 || a4OEEType == 5))
  4552. {
  4553. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  4554. if (res == 1)
  4555. {
  4556. s4PLCSignal_Old["a4OEEType"] = s4PLCData["a4OEEType"];
  4557. }
  4558. else
  4559. {
  4560. s4PLCSignal_Old["a4OEEType"] = 0;
  4561. }
  4562. }
  4563. }
  4564. else {
  4565. s4PLCSignal_Old["a4OEEType"] = 0;
  4566. }
  4567. }
  4568. catch (Exception ex)
  4569. {
  4570. string str = ex.StackTrace;
  4571. AddMessage_Station(stationNameStr, LogType.Error,
  4572. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4573. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4574. }
  4575. #endregion
  4576. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4577. stopwatch1.Stop();
  4578. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4579. }
  4580. else
  4581. {
  4582. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4583. AddMessage_Station(stationNameStr, LogType.Info,
  4584. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4585. FunsEip[plcNo].Connect(); // 重连
  4586. }
  4587. }
  4588. catch (Exception ex)
  4589. {
  4590. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4591. AddMessage_Station(stationNameStr, LogType.Error,
  4592. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4593. }
  4594. Thread.Sleep(IntervalReadPLC);
  4595. }
  4596. }
  4597. /// <summary>
  4598. /// [S4] 点胶检测设备 - 进站
  4599. /// </summary>
  4600. /// <param name="plcNo">PLC编号</param>
  4601. /// <param name="stationNameStr">工站全称</param>
  4602. /// <param name="stPLC_MesData"></param>
  4603. /// <param name="tagMesCommName"></param>
  4604. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  4605. string tagBarsetName, out bool ProgressState)
  4606. {
  4607. Stopwatch stopwatch1 = new Stopwatch();
  4608. Stopwatch stopwatch2 = new Stopwatch();
  4609. try
  4610. {
  4611. stopwatch1.Start();
  4612. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4613. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4614. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  4615. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  4616. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4617. bool pass = a1Result == 1;
  4618. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4619. //载具码验证产品码
  4620. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4621. if (string.IsNullOrEmpty(strProductBarcode))
  4622. {
  4623. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4624. ProgressState = false;
  4625. Thread.Sleep(10000);
  4626. return;
  4627. }
  4628. sn = strProductBarcode;
  4629. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4630. // 产品SN(物料码)校验
  4631. List<TestItem> item = new List<TestItem>();
  4632. stopwatch2.Start();
  4633. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  4634. item, MachineId, StationId, pass, "01-SLOT-01");
  4635. stopwatch2.Stop();
  4636. //指令执行结果 1:OK 110:失败
  4637. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4638. if (mesResultFrmWeb == 1)
  4639. {
  4640. if (a1Result == 1)
  4641. {
  4642. mesResultFrmWeb = 1;
  4643. }
  4644. else
  4645. {
  4646. mesResultFrmWeb = 110;
  4647. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  4648. }
  4649. }
  4650. //进站结果写入PLC
  4651. CommandFromPLC resultToPlC = new CommandFromPLC();
  4652. resultToPlC.cmd = 0;
  4653. resultToPlC.cmdParam = 0; //指令参数
  4654. resultToPlC.cmdResult = mesResultFrmWeb;
  4655. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4656. }
  4657. catch (Exception ex)
  4658. {
  4659. string str = ex.StackTrace;
  4660. AddMessage(LogType.Error,
  4661. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4662. str.Length - str.LastIndexOf("\\") - 1));
  4663. CommandFromPLC resultToPlC = new CommandFromPLC();
  4664. resultToPlC.cmd = 0;
  4665. resultToPlC.cmdParam = 0; //指令参数
  4666. resultToPlC.cmdResult = 110;
  4667. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4668. }
  4669. stopwatch1.Stop();
  4670. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4671. AddMessage(LogType.Info,
  4672. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4673. stopwatch2.ElapsedMilliseconds + "ms");
  4674. ProgressState = false;
  4675. }
  4676. /// <summary>
  4677. /// [S4] 点胶检测设备 - 出站接口
  4678. /// </summary>
  4679. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  4680. string stationCode, string stationName, out bool ProgressState)
  4681. {
  4682. Stopwatch stopwatch1 = new Stopwatch();
  4683. Stopwatch stopwatch2 = new Stopwatch();
  4684. try
  4685. {
  4686. stopwatch1.Start();
  4687. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4688. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4689. string processItem = stationName; // 测试项目
  4690. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4691. string supplierCode = ""; // 供应商代码
  4692. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4693. string batch_num = GlobalContext.BatchNumber; // 批次号
  4694. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4695. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4696. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4697. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  4698. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  4699. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4700. bool pass = a1Result == 1;
  4701. //根据载具码获取产品码
  4702. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4703. if (string.IsNullOrEmpty(strProductBarcode))
  4704. {
  4705. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4706. ProgressState = false;
  4707. Thread.Sleep(10000);
  4708. return;
  4709. }
  4710. sn = strProductBarcode;
  4711. stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
  4712. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4713. List<TestItem> items = new List<TestItem>();
  4714. items.Add(new TestItem()
  4715. {
  4716. Parameter_name = "载具码",
  4717. Parameter_value = CarrierBarcode,
  4718. Parameter_unit = ""
  4719. });
  4720. items.Add(new TestItem()
  4721. {
  4722. Parameter_name = "产品码",
  4723. Parameter_value = sn,
  4724. Parameter_unit = ""
  4725. });
  4726. #region 上传图片
  4727. if (GlobalContext.MQTTIsSendUpFile)
  4728. {
  4729. CopyFileToTempPath(GlobalContext.UpFilePath,GlobalContext.MqttFileTempDir);
  4730. if (Directory.Exists(GlobalContext.MqttFileTempDir))
  4731. {
  4732. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName, a1Result, GlobalContext.MqttFileTempDir, uuid).Result;
  4733. if (result.Item1==1)
  4734. {
  4735. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  4736. }
  4737. }
  4738. //string[] urlarry = GlobalContext.UpFilePath.Split(",");
  4739. //// fileUploadData.fileData.Clear();
  4740. //foreach (var item in urlarry)
  4741. //{
  4742. // if (!string.IsNullOrEmpty(item))
  4743. // {
  4744. // //上传图片
  4745. // var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName, a1Result,
  4746. // item, uuid).Result;
  4747. // OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  4748. // }
  4749. //}
  4750. }
  4751. #endregion
  4752. #region 转换过站明细字符串
  4753. //创建字典
  4754. var dic = new Dictionary<string, string>();
  4755. // 获取结构体类型
  4756. FieldInfo[] fields = typeof(OP40_DataSet_t).GetFields();
  4757. string resultString = "";
  4758. // 遍历变量名转换成字典描述
  4759. foreach (FieldInfo field in fields)
  4760. {
  4761. //获取枚举描述
  4762. string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
  4763. typeof(XiaomiMESEnum_ProcessData.Enum_40_ProcessData));
  4764. //获取过站明细的值
  4765. object valueObj = field.GetValue(stPLC_MesData.mesData) ?? 0;
  4766. // 检查是否为数组
  4767. if (valueObj.GetType().IsArray)
  4768. {
  4769. var array = valueObj as Array;
  4770. resultString = ArrayToString(array);
  4771. }
  4772. else
  4773. {
  4774. resultString = valueObj.ToString();
  4775. }
  4776. dic.Add(name, resultString);
  4777. }
  4778. string paramJson = JsonConvert.SerializeObject(dic);
  4779. #endregion
  4780. //string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);//过站生产数据
  4781. #region MAS测试项
  4782. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  4783. string passFlag = "";
  4784. string AllpassFlag = "PASS";
  4785. //胶线面积
  4786. float[] fGlue_Areas = stPLC_MesData.testData.fGlue_Areas;
  4787. float fGlue_AreasMax = stPLC_MesData.testData.fGlue_AreasMax;
  4788. float fGlue_AreasMin = stPLC_MesData.testData.fGlue_AreasMin;
  4789. //胶线高度
  4790. float[] fGlue_Heights = stPLC_MesData.testData.fGlue_Heights;
  4791. float fGlue_HeightsMax = stPLC_MesData.testData.fGlue_HeightsMax;
  4792. float fGlue_HeightsMin = stPLC_MesData.testData.fGlue_HeightsMin;
  4793. XmStationOut_InspectionItemData inspectionItemData = new XmStationOut_InspectionItemData();
  4794. inspectionItemData.childUnitSn = strProductBarcode;
  4795. inspectionItemData.childUnitState = AllpassFlag;
  4796. inspectionItemData.toolVersion = "1.0";
  4797. if (fGlue_AreasMax > fGlue_AreasMin && (fGlue_AreasMax != 0 || fGlue_AreasMin != 0))
  4798. {
  4799. for (int i = 0; i < fGlue_Areas.Length -1 ; i++)
  4800. {
  4801. if (fGlue_Areas[i] > fGlue_AreasMin && fGlue_Areas[i] <= fGlue_AreasMax)
  4802. passFlag = "PASS";
  4803. else
  4804. passFlag = "FAIL";
  4805. if (passFlag == "FAIL") AllpassFlag = passFlag;
  4806. }
  4807. inspectionItemData.AddDataItem("GlueLine", "胶线面积", string.Join(",", fGlue_Areas), fGlue_AreasMax.ToString(), fGlue_AreasMin.ToString(), passFlag);
  4808. }
  4809. if (fGlue_HeightsMax > fGlue_HeightsMin && (fGlue_HeightsMax != 0 || fGlue_HeightsMin != 0))
  4810. {
  4811. for (int i = 0; i < fGlue_Heights.Length-1; i++)
  4812. {
  4813. if (fGlue_Heights[i] > fGlue_HeightsMin && fGlue_Heights[i] <= fGlue_HeightsMax)
  4814. passFlag = "PASS";
  4815. else
  4816. passFlag = "FAIL";
  4817. if (passFlag == "FAIL") AllpassFlag = passFlag;
  4818. }
  4819. inspectionItemData.AddDataItem("GlueLine", "胶线高度", string.Join(",", fGlue_Heights), fGlue_HeightsMax.ToString(), fGlue_HeightsMin.ToString(), passFlag);
  4820. }
  4821. #endregion
  4822. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4823. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode,
  4824. "01-SLOT-01", MachineId, StationId, "", paramJson,new XmStationOut_InspectionItemData(), "");
  4825. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4826. if (mesResultFrmWeb == 1)
  4827. {
  4828. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  4829. if (mesResultFrmWeb == 110)
  4830. {
  4831. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  4832. }
  4833. }
  4834. stopwatch2.Start();
  4835. //进站结果写入PLC
  4836. CommandFromPLC resultToPlC = new CommandFromPLC();
  4837. resultToPlC.cmd = 0;
  4838. resultToPlC.cmdParam = 0; //指令参数
  4839. resultToPlC.cmdResult = mesResultFrmWeb;
  4840. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4841. stopwatch2.Stop();
  4842. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4843. //保存PLC返回MES数据到本地
  4844. ResponseMessage message = new ResponseMessage();
  4845. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  4846. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  4847. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  4848. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  4849. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  4850. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  4851. if (message.result == false)
  4852. {
  4853. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4854. }
  4855. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4856. }
  4857. catch (Exception ex)
  4858. {
  4859. stopwatch2.Start();
  4860. CommandFromPLC resultToPlC = new CommandFromPLC();
  4861. resultToPlC.cmd = 0;
  4862. resultToPlC.cmdParam = 0; //指令参数
  4863. resultToPlC.cmdResult = 110;
  4864. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4865. stopwatch2.Stop();
  4866. string str = ex.StackTrace;
  4867. AddMessage(LogType.Error,
  4868. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4869. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4870. }
  4871. stopwatch1.Stop();
  4872. AddMessage(LogType.Info,
  4873. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4874. stopwatch2.ElapsedMilliseconds + "ms");
  4875. ProgressState = false;
  4876. uuid = "";
  4877. }
  4878. #endregion
  4879. #region S5
  4880. private static bool isPCBStation = false; //控制PCB是否进出站的标识
  4881. /// <summary>
  4882. /// [S5] 点胶检测设备
  4883. /// </summary>
  4884. /// <param name="plcNo">PLC编号</param>
  4885. private void ReadStation_S5(int plcNo)
  4886. {
  4887. string stationCode = "[OP50]";
  4888. string stationName = "ADD板上料组装装备";
  4889. string stationNameStr = stationCode + stationName;
  4890. string tagBaseName = "g_OP50_MES"; //标签变量名称
  4891. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4892. string tagAgvCommName = "agvCommFrmPC";
  4893. string tagiotComnName = "iotData";
  4894. string tagBarsetName = "BarcodeSet";
  4895. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  4896. string CarrierBarcode = "";
  4897. // 触发信号字典
  4898. s5PLCSignal_Old.Add("a5OEEType", 0); // 节拍类型(plc写入)
  4899. // PLC数据字典 赋值
  4900. s5PLCData.Add("a5OEEType", 0); // 节拍类型(plc写入)
  4901. s5PLCData.Add("OEETypeFlag", 0); // 节拍标识 0 不上传 ,1 上传
  4902. (int, string) result;
  4903. while (true)
  4904. {
  4905. try
  4906. {
  4907. if (!GlobalContext._IsCon_Funs1)
  4908. {
  4909. UpdatePLCMonitor(1, plcNo, 0);
  4910. continue;
  4911. }
  4912. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4913. {
  4914. Stopwatch stopwatch1 = new Stopwatch();
  4915. Stopwatch stopwatch2 = new Stopwatch();
  4916. stopwatch1.Start();
  4917. stopwatch2.Start();
  4918. #region 一次性读取所有数据
  4919. // 一次性读取所有数据
  4920. result = FunsEip[plcNo]
  4921. .Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4922. if (result.Item1 != 0)
  4923. {
  4924. }
  4925. else
  4926. {
  4927. //测试数据
  4928. //stPLC_MesData.mesCommFrmPLC.cmd = 2;
  4929. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A235461";
  4930. //stPLC_MesData.BarcodeSet.strPCBBarcode = "A1507V000239";
  4931. //stPLC_MesData.iotData.beatAction = 1;
  4932. //stPLC_MesData.iotData.beatAction = 2;
  4933. //stPLC_MesData.iotData.beatAction = 3;
  4934. //stPLC_MesData.iotData.beatAction = 4;
  4935. //stPLC_MesData.iotData.beatAction = 5;
  4936. //stPLC_MesData.iotData.beatAction = 6;
  4937. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
  4938. #region 去除扫码产生的特殊字符
  4939. stPLC_MesData.BarcodeSet.strProductBarcode =
  4940. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  4941. stPLC_MesData.BarcodeSet.strPartBarcode =
  4942. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  4943. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  4944. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  4945. stPLC_MesData.BarcodeSet.strPCBBarcode =
  4946. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  4947. #endregion
  4948. //richTextBox1.AppendText("\n" + "读取成功");
  4949. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  4950. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  4951. ? XiaomiDeviceState.Unknown
  4952. : (XiaomiDeviceState)xmDeviceStateInt;
  4953. // 节拍
  4954. s5PLCData["a5OEEType"] = stPLC_MesData.iotData.beatAction;
  4955. //载具码
  4956. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode.ToString();
  4957. //报警信息
  4958. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  4959. }
  4960. #endregion 一次性读取所有数据
  4961. stopwatch2.Stop();
  4962. #region 进站
  4963. try
  4964. {
  4965. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4966. {
  4967. lock (lockObj)
  4968. {
  4969. if (!ProgressState)
  4970. {
  4971. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  4972. ProgressState = true;
  4973. string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
  4974. if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
  4975. {
  4976. ProgressState = true;
  4977. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData,
  4978. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  4979. out ProgressState));
  4980. }
  4981. }
  4982. }
  4983. }
  4984. }
  4985. catch (Exception ex)
  4986. {
  4987. ProgressState = false;
  4988. string str = ex.StackTrace;
  4989. AddMessage_Station(stationNameStr, LogType.Error,
  4990. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4991. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4992. }
  4993. #endregion 进站
  4994. #region 出站
  4995. try
  4996. {
  4997. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4998. {
  4999. lock (lockObj)
  5000. {
  5001. if (!ProgressState)
  5002. {
  5003. ProgressState = true;
  5004. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData,
  5005. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  5006. out ProgressState));
  5007. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  5008. }
  5009. }
  5010. }
  5011. }
  5012. catch (Exception ex)
  5013. {
  5014. ProgressState = false;
  5015. string str = ex.StackTrace;
  5016. AddMessage_Station(stationNameStr, LogType.Error,
  5017. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5018. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5019. }
  5020. #endregion 出站
  5021. #region 节拍接口
  5022. try
  5023. {
  5024. if (stPLC_MesData.iotData.beatAction > 0)
  5025. {
  5026. int a5OEEType = Convert.ToInt32(s5PLCData["a5OEEType"]);
  5027. int a5OEETypeGOld = Convert.ToInt32(s5PLCSignal_Old["a5OEEType"]);
  5028. if (a5OEEType != a5OEETypeGOld)
  5029. {
  5030. s5PLCData["OEETypeFlag"] = "1";
  5031. }
  5032. else
  5033. {
  5034. s5PLCData["OEETypeFlag"] = "0";
  5035. }
  5036. if (s5PLCData["OEETypeFlag"].ToString() == "1" && (a5OEEType == 1 || a5OEEType == 3 || a5OEEType == 4 || a5OEEType == 5))
  5037. {
  5038. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  5039. if (res == 1)
  5040. {
  5041. s5PLCSignal_Old["a5OEEType"] = s5PLCData["a5OEEType"];
  5042. }
  5043. else {
  5044. s5PLCSignal_Old["a5OEEType"] = 0;
  5045. }
  5046. }
  5047. }
  5048. else {
  5049. s5PLCSignal_Old["a5OEEType"] = 0;
  5050. }
  5051. }
  5052. catch (Exception ex)
  5053. {
  5054. string str = ex.StackTrace;
  5055. AddMessage_Station(stationNameStr, LogType.Error,
  5056. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  5057. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5058. }
  5059. #endregion
  5060. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5061. stopwatch1.Stop();
  5062. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5063. }
  5064. else
  5065. {
  5066. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5067. AddMessage_Station(stationNameStr, LogType.Info,
  5068. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5069. FunsEip[plcNo].Connect(); // 重连
  5070. }
  5071. }
  5072. catch (Exception ex)
  5073. {
  5074. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5075. AddMessage_Station(stationNameStr, LogType.Error,
  5076. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5077. }
  5078. Thread.Sleep(IntervalReadPLC);
  5079. }
  5080. }
  5081. /// <summary>
  5082. /// [S5] 点胶检测设备 - 进站
  5083. /// </summary>
  5084. /// <param name="plcNo">PLC编号</param>
  5085. /// <param name="stationNameStr">工站全称</param>
  5086. /// <param name="stPLC_MesData"></param>
  5087. /// <param name="tagMesCommName"></param>
  5088. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  5089. string tagBarsetName, out bool ProgressState)
  5090. {
  5091. Stopwatch stopwatch1 = new Stopwatch();
  5092. Stopwatch stopwatch2 = new Stopwatch();
  5093. try
  5094. {
  5095. stopwatch1.Start();
  5096. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  5097. //string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5098. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  5099. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  5100. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  5101. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码
  5102. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  5103. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5104. bool pass = a1Result == 1;
  5105. AddMessage(LogType.Info, $"ADD板编码(PCB码):{pcbBarcode}");
  5106. //绑定载具和产品
  5107. //ResponseMessage message = new ResponseMessage();
  5108. //message = SQLHelper.PCBCarrierBind(strCarrierBarcode, pcbBarcode);
  5109. //if (message.result == false)
  5110. //{
  5111. // AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  5112. // ProgressState = false;
  5113. // Thread.Sleep(10000);
  5114. // return;
  5115. //}
  5116. //载具码验证产品码 //载具码验证产品码
  5117. //string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  5118. //if (string.IsNullOrEmpty(strProductBarcode))
  5119. //{
  5120. // AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5121. //}
  5122. //sn = strProductBarcode;
  5123. //AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5124. // 产品SN(物料码)校验
  5125. List<TestItem> item = new List<TestItem>();
  5126. stopwatch2.Start();
  5127. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  5128. pcbBarcode,
  5129. item, MachineId, StationId, pass, "01-SLOT-01");
  5130. stopwatch2.Stop();
  5131. //指令执行结果 1:OK 110:失败
  5132. byte mesResultFrmWeb = (byte)(result == 1 ? 2 : 120);
  5133. if (mesResultFrmWeb == 1)
  5134. {
  5135. if (a1Result == 1)
  5136. {
  5137. mesResultFrmWeb = 2;
  5138. }
  5139. else
  5140. {
  5141. mesResultFrmWeb = 120;
  5142. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  5143. }
  5144. }
  5145. //进站结果写入PLC
  5146. CommandFromPLC resultToPlC = new CommandFromPLC();
  5147. resultToPlC.cmd = 0;
  5148. resultToPlC.cmdParam = 0; //指令参数
  5149. resultToPlC.cmdResult = mesResultFrmWeb;
  5150. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5151. }
  5152. catch (Exception ex)
  5153. {
  5154. string str = ex.StackTrace;
  5155. AddMessage(LogType.Error,
  5156. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  5157. str.Length - str.LastIndexOf("\\") - 1));
  5158. CommandFromPLC resultToPlC = new CommandFromPLC();
  5159. resultToPlC.cmd = 0;
  5160. resultToPlC.cmdParam = 0; //指令参数
  5161. resultToPlC.cmdResult = 120;
  5162. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5163. }
  5164. stopwatch1.Stop();
  5165. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  5166. AddMessage(LogType.Info,
  5167. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5168. stopwatch2.ElapsedMilliseconds + "ms");
  5169. ProgressState = false;
  5170. }
  5171. /// <summary>
  5172. /// [S5] 点胶检测设备 - 出站接口
  5173. /// </summary>
  5174. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  5175. string stationCode, string stationName, out bool ProgressState)
  5176. {
  5177. Stopwatch stopwatch1 = new Stopwatch();
  5178. Stopwatch stopwatch2 = new Stopwatch();
  5179. try
  5180. {
  5181. stopwatch1.Start();
  5182. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  5183. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5184. string processItem = stationName; // 测试项目
  5185. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5186. string supplierCode = ""; // 供应商代码
  5187. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5188. string batch_num = GlobalContext.BatchNumber; // 批次号
  5189. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5190. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5191. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 部件条码;
  5192. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5193. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  5194. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  5195. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  5196. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5197. bool pass = a1Result == 1;
  5198. CommandFromPLC resultToPlC = new CommandFromPLC();
  5199. //根据载具码获取产品码
  5200. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5201. if (string.IsNullOrEmpty(strProductBarcode))
  5202. {
  5203. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5204. ProgressState = false;
  5205. Thread.Sleep(10000);
  5206. return;
  5207. }
  5208. stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
  5209. sn = strProductBarcode;
  5210. //数据库绑定载具和PCB
  5211. ResponseMessage message = new ResponseMessage();
  5212. message = SQLHelper.PCBCarrierBind(CarrierBarcode, pcbBarcode);
  5213. if (message.result == false)
  5214. {
  5215. AddMessage(LogType.Error, stationNameStr + "_PCB码数据库绑定失败,错误:" + message.text);
  5216. ProgressState = true; //防止循环报错
  5217. return;
  5218. }
  5219. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn};PCB码:{pcbBarcode}");
  5220. List<TestItem> items = new List<TestItem>();
  5221. items.Add(new TestItem()
  5222. {
  5223. Parameter_name = "载具码",
  5224. Parameter_value = CarrierBarcode,
  5225. Parameter_unit = ""
  5226. });
  5227. items.Add(new TestItem()
  5228. {
  5229. Parameter_name = "产品码",
  5230. Parameter_value = sn,
  5231. Parameter_unit = ""
  5232. });
  5233. items.Add(new TestItem()
  5234. {
  5235. Parameter_name = "PCB码",
  5236. Parameter_value = pcbBarcode,
  5237. Parameter_unit = ""
  5238. });
  5239. #region 上传图片
  5240. if (GlobalContext.MQTTIsSendUpFile)
  5241. {
  5242. CopyFileToTempPath(GlobalContext.UpFilePath, GlobalContext.MqttFileTempDir);
  5243. if (Directory.Exists(GlobalContext.MqttFileTempDir))
  5244. {
  5245. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName, a1Result, GlobalContext.MqttFileTempDir, uuid).Result;
  5246. if (result.Item1 == 1)
  5247. {
  5248. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  5249. }
  5250. }
  5251. //string[] urlarry = GlobalContext.UpFilePath.Split(",");
  5252. //// fileUploadData.fileData.Clear();
  5253. //foreach (var item in urlarry)
  5254. //{
  5255. // if (!string.IsNullOrEmpty(item))
  5256. // {
  5257. // //上传图片
  5258. // var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName, a1Result,
  5259. // item, uuid).Result;
  5260. // OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  5261. // }
  5262. //}
  5263. }
  5264. #endregion
  5265. #region 转换过站明细字符串
  5266. ////创建字典
  5267. //var dic = new Dictionary<string, string>();
  5268. //// 获取结构体类型
  5269. //FieldInfo[] fields = typeof(OP40_DataSet_t).GetFields();
  5270. //string resultString = "";
  5271. //// 遍历变量名转换成字典描述
  5272. //foreach (FieldInfo field in fields)
  5273. //{
  5274. // //获取枚举描述
  5275. // string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
  5276. // typeof(XiaomiMESEnum_ProcessData.Enum_40_ProcessData));
  5277. // //获取过站明细的值
  5278. // object valueObj = field.GetValue(stPLC_MesData.mesData) ?? 0;
  5279. // // 检查是否为数组
  5280. // if (valueObj.GetType().IsArray)
  5281. // {
  5282. // var array = valueObj as Array;
  5283. // resultString = ArrayToString(array);
  5284. // }
  5285. // else
  5286. // {
  5287. // resultString = valueObj.ToString();
  5288. // }
  5289. // dic.Add(name, resultString);
  5290. //}
  5291. //string paramJson = JsonConvert.SerializeObject(dic);
  5292. #endregion
  5293. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  5294. #region MAS测试项
  5295. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  5296. string passFlag = "";
  5297. string AllpassFlag = "PASS";
  5298. //ADD板的压力
  5299. float fForceAddPCB = stPLC_MesData.testData.fForceAddPCB;
  5300. float fForceAddPCBMax = stPLC_MesData.testData.fForceAddPCBMax;
  5301. float fForceAddPCBMin = stPLC_MesData.testData.fForceAddPCBMin;
  5302. XmStationOut_InspectionItemData inspectionItemData = new XmStationOut_InspectionItemData();
  5303. if (fForceAddPCBMax > fForceAddPCBMin && (fForceAddPCBMax != 0 || fForceAddPCBMin != 0))
  5304. {
  5305. if (fForceAddPCB > fForceAddPCBMin && fForceAddPCB <= fForceAddPCBMax)
  5306. passFlag = "PASS";
  5307. else
  5308. passFlag = "FAIL";
  5309. if (passFlag == "FAIL") AllpassFlag = passFlag;
  5310. inspectionItemData.AddDataItem("AirPressure", "ADD板压力", fForceAddPCB.ToString(), fForceAddPCBMax.ToString(), fForceAddPCBMin.ToString(), passFlag);
  5311. }
  5312. inspectionItemData.childUnitSn = strProductBarcode;
  5313. inspectionItemData.childUnitState = AllpassFlag;
  5314. inspectionItemData.toolVersion = "1.0";
  5315. #endregion
  5316. int result1 = 0;
  5317. byte mesResultFrmWeb = 0;
  5318. if (stPLC_MesData.mesCommFrmPLC.cmdParam == 2)
  5319. {
  5320. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem, workorder_code,
  5321. batch_num
  5322. , mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "01-SLOT-01", MachineId, StationId,
  5323. PartBarcode, paramJson,new XmStationOut_InspectionItemData(), "");
  5324. uuid = "";
  5325. }
  5326. else if (stPLC_MesData.mesCommFrmPLC.cmdParam == 1)
  5327. {
  5328. result1 = PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  5329. }
  5330. mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5331. //进站结果写入PLC
  5332. resultToPlC.cmd = 0;
  5333. resultToPlC.cmdParam = 0; //指令参数
  5334. resultToPlC.cmdResult = mesResultFrmWeb;
  5335. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5336. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  5337. //保存PLC返回MES数据到本地
  5338. //ResponseMessage message = new ResponseMessage();
  5339. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  5340. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB,
  5341. stPLC_MesData.mesData.nRemainCount, "");
  5342. if (message.result == false)
  5343. {
  5344. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  5345. }
  5346. //保存部件码信息
  5347. if (!string.IsNullOrEmpty(PartBarcode))
  5348. {
  5349. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  5350. if (message.result == false)
  5351. {
  5352. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  5353. }
  5354. }
  5355. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  5356. }
  5357. catch (Exception ex)
  5358. {
  5359. stopwatch2.Start();
  5360. CommandFromPLC resultToPlC = new CommandFromPLC();
  5361. resultToPlC.cmd = 0;
  5362. resultToPlC.cmdParam = 0; //指令参数
  5363. resultToPlC.cmdResult = 110;
  5364. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5365. stopwatch2.Stop();
  5366. string str = ex.StackTrace;
  5367. AddMessage(LogType.Error,
  5368. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5369. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5370. }
  5371. stopwatch1.Stop();
  5372. AddMessage(LogType.Info,
  5373. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5374. stopwatch2.ElapsedMilliseconds + "ms");
  5375. ProgressState = false;
  5376. }
  5377. private int S5_PCB进出站(OP50_MesData_t stPLC_MesData, int plcNo, string stationNameStr, string tagBaseName,
  5378. string tagMesCommName)
  5379. {
  5380. string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
  5381. if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
  5382. {
  5383. string strProductBarcode =
  5384. SQLHelper.GetProductBarcodeByCarrierCode(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  5385. stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
  5386. CommandFromPLC resultToPlC = new CommandFromPLC();
  5387. resultToPlC.cmd = 0;
  5388. resultToPlC.cmdParam = 0; //指令参数
  5389. if (GlobalContext.IsSendStationIn)
  5390. {
  5391. #region 进站
  5392. //int res1 = PCBStationInData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  5393. //if (res1 == 1)
  5394. //{
  5395. // resultToPlC.cmdResult = 2;//OK
  5396. // WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  5397. //}
  5398. //else
  5399. //{
  5400. // resultToPlC.cmdResult = 120;
  5401. // WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  5402. // return 2;
  5403. //}
  5404. #endregion
  5405. #region 出站
  5406. int res2 = PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  5407. if (res2 == 1)
  5408. {
  5409. resultToPlC.cmdResult = 2; //OK
  5410. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  5411. return 1;
  5412. }
  5413. else
  5414. {
  5415. resultToPlC.cmdResult = 120;
  5416. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  5417. return 2;
  5418. }
  5419. #endregion
  5420. }
  5421. else
  5422. {
  5423. return 2;
  5424. }
  5425. }
  5426. else
  5427. {
  5428. return 2;
  5429. }
  5430. }
  5431. #endregion
  5432. #region S6
  5433. private Dictionary<string, object> s6PLCData = new Dictionary<string, object>();
  5434. private Dictionary<string, object> s6PLCSignal_Old = new Dictionary<string, object>();
  5435. /// <summary>
  5436. /// [S6] 顶盖装配设备
  5437. /// </summary>
  5438. /// <param name="plcNo">PLC编号</param>
  5439. public void ReadStation_S6(int plcNo)
  5440. {
  5441. string stationCode = "[OP70]";
  5442. string stationName = "组上盖板";
  5443. string stationNameStr = stationCode + stationName;
  5444. string tagBaseName = "g_OP60_MES"; //标签变量名称
  5445. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5446. string tagAgvCommName = "agvCommFrmPC";
  5447. string tagiotComnName = "iotData";
  5448. string tagBarsetName = "BarcodeSet";
  5449. string CarrierBarcode = "";
  5450. // 触发信号字典
  5451. s6PLCSignal_Old.Add("a6OEEType", 0); // 节拍类型(plc写入)
  5452. // PLC数据字典 赋值
  5453. s6PLCData.Add("a6OEEType", 0); // 节拍类型(plc写入)
  5454. s6PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  5455. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  5456. (int, string) result;
  5457. while (true)
  5458. {
  5459. try
  5460. {
  5461. if (!GlobalContext._IsCon_Funs1)
  5462. {
  5463. UpdatePLCMonitor(1, plcNo, 0);
  5464. continue;
  5465. }
  5466. if (StopWhile)
  5467. {
  5468. continue;
  5469. }
  5470. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5471. {
  5472. Stopwatch stopwatch1 = new Stopwatch();
  5473. Stopwatch stopwatch2 = new Stopwatch();
  5474. stopwatch1.Start();
  5475. stopwatch2.Start();
  5476. #region 一次性读取所有数据
  5477. // 一次性读取所有数据
  5478. result = FunsEip[plcNo]
  5479. .Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  5480. if (result.Item1 != 0)
  5481. {
  5482. //richTextBox1.AppendText("\n" + strRet);
  5483. }
  5484. else
  5485. {
  5486. //测试
  5487. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
  5488. //stPLC_MesData.mesCommFrmPLC.cmd = 1;
  5489. //去除扫码产生的特殊字符
  5490. stPLC_MesData.BarcodeSet.strProductBarcode =
  5491. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  5492. stPLC_MesData.BarcodeSet.strPartBarcode =
  5493. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  5494. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  5495. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  5496. stPLC_MesData.BarcodeSet.strPCBBarcode =
  5497. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  5498. //richTextBox1.AppendText("\n" + "读取成功");
  5499. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  5500. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  5501. ? XiaomiDeviceState.Unknown
  5502. : (XiaomiDeviceState)xmDeviceStateInt;
  5503. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  5504. s6PLCData["a6OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  5505. //报警信息
  5506. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  5507. }
  5508. #endregion 一次性读取所有数据
  5509. stopwatch2.Stop();
  5510. #region 进站
  5511. try
  5512. {
  5513. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5514. {
  5515. lock (lockObj)
  5516. {
  5517. if (!ProgressState)
  5518. {
  5519. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  5520. ProgressState = true;
  5521. //载具码验证产品码
  5522. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData,
  5523. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  5524. out ProgressState));
  5525. }
  5526. }
  5527. }
  5528. }
  5529. catch (Exception ex)
  5530. {
  5531. ProgressState = false;
  5532. string str = ex.StackTrace;
  5533. AddMessage_Station(stationNameStr, LogType.Error,
  5534. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5535. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5536. }
  5537. #endregion 进站
  5538. #region 出站
  5539. try
  5540. {
  5541. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5542. {
  5543. lock (lockObj)
  5544. {
  5545. if (!ProgressState)
  5546. {
  5547. ProgressState = true;
  5548. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData,
  5549. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  5550. out ProgressState));
  5551. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  5552. }
  5553. }
  5554. }
  5555. }
  5556. catch (Exception ex)
  5557. {
  5558. ProgressState = false;
  5559. string str = ex.StackTrace;
  5560. AddMessage_Station(stationNameStr, LogType.Error,
  5561. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5562. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5563. }
  5564. #endregion 出站
  5565. #region 节拍接口
  5566. try
  5567. {
  5568. if (stPLC_MesData.iotData.beatAction > 0)
  5569. {
  5570. int a6OEEType = Convert.ToInt32(s6PLCData["a6OEEType"]);
  5571. int a6OEETypeGOld = Convert.ToInt32(s6PLCSignal_Old["a6OEEType"]);
  5572. if (a6OEEType != a6OEETypeGOld)
  5573. {
  5574. s6PLCData["OEETypeFlag"] = "1";
  5575. }
  5576. else
  5577. {
  5578. s6PLCData["OEETypeFlag"] = "0";
  5579. }
  5580. if (s6PLCData["OEETypeFlag"].ToString() == "1" && (a6OEEType == 1 || a6OEEType == 3 || a6OEEType == 4 || a6OEEType == 5))
  5581. {
  5582. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  5583. if (res == 1)
  5584. {
  5585. s6PLCSignal_Old["a6OEEType"] = s6PLCData["a6OEEType"];
  5586. }
  5587. else
  5588. {
  5589. s6PLCSignal_Old["a6OEEType"] = 0;
  5590. }
  5591. }
  5592. }
  5593. else {
  5594. s6PLCSignal_Old["a6OEEType"] = 0;
  5595. }
  5596. }
  5597. catch (Exception ex)
  5598. {
  5599. string str = ex.StackTrace;
  5600. AddMessage_Station(stationNameStr, LogType.Error,
  5601. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  5602. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5603. }
  5604. #endregion
  5605. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5606. stopwatch1.Stop();
  5607. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5608. }
  5609. else
  5610. {
  5611. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5612. AddMessage_Station(stationNameStr, LogType.Info,
  5613. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5614. FunsEip[plcNo].Connect(); // 重连
  5615. }
  5616. }
  5617. catch (Exception ex)
  5618. {
  5619. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5620. AddMessage_Station(stationNameStr, LogType.Error,
  5621. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5622. }
  5623. Thread.Sleep(IntervalReadPLC);
  5624. }
  5625. }
  5626. /// <summary>
  5627. /// [S6] 顶盖装配设备 - 进站
  5628. /// </summary>
  5629. /// <param name="plcNo">PLC编号</param>
  5630. /// <param name="stationNameStr">工站全称</param>
  5631. /// <param name="stPLC_MesData"></param>
  5632. /// <param name="tagMesCommName"></param>
  5633. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  5634. string tagBarsetName, out bool ProgressState)
  5635. {
  5636. Stopwatch stopwatch1 = new Stopwatch();
  5637. Stopwatch stopwatch2 = new Stopwatch();
  5638. try
  5639. {
  5640. stopwatch1.Start();
  5641. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  5642. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5643. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  5644. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  5645. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5646. bool pass = a1Result == 1;
  5647. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  5648. string ProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  5649. string PCBBarcode = SQLHelper.GetPCBBarcodeByCarrierCode(strCarrierBarcode);
  5650. //strCarrierBarcode = "N801A-003";
  5651. //载具码验证产品码
  5652. if (string.IsNullOrEmpty(ProductBarcode))
  5653. {
  5654. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5655. ProgressState = false;
  5656. Thread.Sleep(10000);
  5657. return;
  5658. }
  5659. sn = ProductBarcode;
  5660. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5661. if (ProductBarcode != "")
  5662. {
  5663. MessageBox.Show($"产品码:{sn}线外螺丝机过站后点击确认", "提示",
  5664. MessageBoxButtons.OK,
  5665. MessageBoxIcon.Information);
  5666. }
  5667. // 产品SN(物料码)校验
  5668. List<TestItem> item = new List<TestItem>();
  5669. stopwatch2.Start();
  5670. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  5671. item, MachineId, StationId, pass, "01-SLOT-01");
  5672. stopwatch2.Stop();
  5673. //指令执行结果 1:OK 110:失败
  5674. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5675. if (mesResultFrmWeb == 1)
  5676. {
  5677. if (a1Result == 1)
  5678. {
  5679. mesResultFrmWeb = 1;
  5680. if (OpenDailogFalg)
  5681. {
  5682. using (var dialog = new Dialog_BandBarode_S3(strCarrierBarcode, ProductBarcode, PCBBarcode))
  5683. {
  5684. var rs = dialog.ShowDialog();
  5685. if (rs == DialogResult.OK)
  5686. {
  5687. AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode}");
  5688. OpenDailogFalg = false; //关闭扫码
  5689. StopWhile = false;//开启while循环
  5690. }
  5691. else
  5692. {
  5693. ProgressState = false;
  5694. return;
  5695. }
  5696. }
  5697. }
  5698. }
  5699. else
  5700. {
  5701. mesResultFrmWeb = 110;
  5702. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  5703. }
  5704. }
  5705. //进站结果写入PLC
  5706. CommandFromPLC resultToPlC = new CommandFromPLC();
  5707. resultToPlC.cmd = 0;
  5708. resultToPlC.cmdParam = 0; //指令参数
  5709. resultToPlC.cmdResult = mesResultFrmWeb;
  5710. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5711. }
  5712. catch (Exception ex)
  5713. {
  5714. string str = ex.StackTrace;
  5715. AddMessage(LogType.Error,
  5716. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  5717. str.Length - str.LastIndexOf("\\") - 1));
  5718. CommandFromPLC resultToPlC = new CommandFromPLC();
  5719. resultToPlC.cmd = 0;
  5720. resultToPlC.cmdParam = 0; //指令参数
  5721. resultToPlC.cmdResult = 110;
  5722. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5723. }
  5724. stopwatch1.Stop();
  5725. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  5726. AddMessage(LogType.Info,
  5727. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5728. stopwatch2.ElapsedMilliseconds + "ms");
  5729. ProgressState = false;
  5730. }
  5731. /// <summary>
  5732. /// [S6] 顶盖装配设备 - 出站接口
  5733. /// </summary>
  5734. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  5735. string stationCode, string stationName, out bool ProgressState)
  5736. {
  5737. Stopwatch stopwatch1 = new Stopwatch();
  5738. Stopwatch stopwatch2 = new Stopwatch();
  5739. try
  5740. {
  5741. stopwatch1.Start();
  5742. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  5743. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5744. string processItem = stationName; // 测试项目
  5745. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5746. string supplierCode = ""; // 供应商代码
  5747. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5748. string batch_num = GlobalContext.BatchNumber; // 批次号
  5749. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5750. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5751. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5752. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  5753. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  5754. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5755. bool pass = a1Result == 1;
  5756. //根据载具码获取产品码
  5757. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5758. if (string.IsNullOrEmpty(strProductBarcode))
  5759. {
  5760. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5761. ProgressState = false;
  5762. Thread.Sleep(10000);
  5763. return;
  5764. }
  5765. sn = strProductBarcode;
  5766. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  5767. List<TestItem> items = new List<TestItem>();
  5768. items.Add(new TestItem()
  5769. {
  5770. Parameter_name = "载具码",
  5771. Parameter_value = CarrierBarcode,
  5772. Parameter_unit = ""
  5773. });
  5774. items.Add(new TestItem()
  5775. {
  5776. Parameter_name = "产品码",
  5777. Parameter_value = sn,
  5778. Parameter_unit = ""
  5779. });
  5780. #region 转换过站明细字符串
  5781. ////创建字典
  5782. //var dic = new Dictionary<string, string>();
  5783. //// 获取结构体类型
  5784. //FieldInfo[] fields = typeof(OP40_DataSet_t).GetFields();
  5785. //string resultString = "";
  5786. //// 遍历变量名转换成字典描述
  5787. //foreach (FieldInfo field in fields)
  5788. //{
  5789. // //获取枚举描述
  5790. // string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
  5791. // typeof(XiaomiMESEnum_ProcessData.Enum_40_ProcessData));
  5792. // //获取过站明细的值
  5793. // object valueObj = field.GetValue(stPLC_MesData.mesData) ?? 0;
  5794. // // 检查是否为数组
  5795. // if (valueObj.GetType().IsArray)
  5796. // {
  5797. // var array = valueObj as Array;
  5798. // resultString = ArrayToString(array);
  5799. // }
  5800. // else
  5801. // {
  5802. // resultString = valueObj.ToString();
  5803. // }
  5804. // dic.Add(name, resultString);
  5805. //}
  5806. //string paramJson = JsonConvert.SerializeObject(dic);
  5807. #endregion
  5808. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  5809. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  5810. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "01-SLOT-01",
  5811. MachineId, StationId, "", paramJson,new XmStationOut_InspectionItemData(), "");
  5812. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5813. if (mesResultFrmWeb == 1)
  5814. {
  5815. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  5816. if (mesResultFrmWeb==110)
  5817. {
  5818. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  5819. }
  5820. }
  5821. stopwatch2.Start();
  5822. //进站结果写入PLC
  5823. CommandFromPLC resultToPlC = new CommandFromPLC();
  5824. resultToPlC.cmd = 0;
  5825. resultToPlC.cmdParam = 0; //指令参数
  5826. resultToPlC.cmdResult = mesResultFrmWeb;
  5827. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5828. stopwatch2.Stop();
  5829. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  5830. //保存PLC返回MES数据到本地
  5831. ResponseMessage message = new ResponseMessage();
  5832. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  5833. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  5834. }
  5835. catch (Exception ex)
  5836. {
  5837. stopwatch2.Start();
  5838. CommandFromPLC resultToPlC = new CommandFromPLC();
  5839. resultToPlC.cmd = 0;
  5840. resultToPlC.cmdParam = 0; //指令参数
  5841. resultToPlC.cmdResult = 110;
  5842. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5843. stopwatch2.Stop();
  5844. string str = ex.StackTrace;
  5845. AddMessage(LogType.Error,
  5846. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5847. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5848. }
  5849. stopwatch1.Stop();
  5850. AddMessage(LogType.Info,
  5851. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5852. stopwatch2.ElapsedMilliseconds + "ms");
  5853. ProgressState = false;
  5854. uuid = "";
  5855. OpenDailogFalg = true; //开启下一个物料的扫码
  5856. }
  5857. #endregion
  5858. #region S7
  5859. private Dictionary<string, object> s7PLCSignal_Old = new Dictionary<string, object>();
  5860. private Dictionary<string, object> s7PLCData = new Dictionary<string, object>();
  5861. /// <summary>
  5862. /// [S7] 锁螺丝设备
  5863. /// </summary>
  5864. /// <param name="plcNo">PLC编号</param>
  5865. private void ReadStation_S7(int plcNo)
  5866. {
  5867. string stationCode = "[OP80]";
  5868. string stationName = "上盖板锁螺丝";
  5869. string stationNameStr = stationCode + stationName;
  5870. string tagBaseName = "g_OP70_MES"; //标签变量名称
  5871. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5872. string tagAgvCommName = "agvCommFrmPC";
  5873. string tagBarsetName = "BarcodeSet";
  5874. string tagiotComnName = "iotData";
  5875. string tagScrewDataset = "screwDataset";
  5876. string CarrierBarcode_Left = "";
  5877. string CarrierBarcode_Right = "";
  5878. s7PLCSignal_Old.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
  5879. s7PLCSignal_Old.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
  5880. // PLC数据字典 赋值
  5881. s7PLCData.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
  5882. s7PLCData.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
  5883. s5PLCData.Add("OEETypeFlag_left", 0); // 节拍标识 0 不上传 ,1 上传
  5884. s5PLCData.Add("OEETypeFlag_right", 0); // 节拍标识 0 不上传 ,1 上传
  5885. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  5886. (int, string) result;
  5887. AtlasScrew atlasScrewLeft = new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort,
  5888. 3000, 3000, "Left");
  5889. atlasScrewLeft.Initial();
  5890. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort,
  5891. 3000, 3000, "Right");
  5892. atlasScrewRight.Initial();
  5893. while (true)
  5894. {
  5895. try
  5896. {
  5897. if (!GlobalContext._IsCon_Funs1)
  5898. {
  5899. UpdatePLCMonitor(1, plcNo, 0);
  5900. continue;
  5901. }
  5902. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5903. {
  5904. Stopwatch stopwatch1 = new Stopwatch();
  5905. Stopwatch stopwatch2 = new Stopwatch();
  5906. stopwatch1.Start();
  5907. stopwatch2.Start();
  5908. #region 一次性读取所有数据
  5909. // 一次性读取所有数据
  5910. result = FunsEip[plcNo]
  5911. .Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  5912. if (result.Item1 != 0)
  5913. {
  5914. //richTextBox1.AppendText("\n" + strRet);
  5915. }
  5916. else
  5917. {
  5918. #region 去除扫码产生的特殊字符
  5919. stPLC_MesData.Left.BarcodeSet.strProductBarcode =
  5920. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strProductBarcode);
  5921. stPLC_MesData.Left.BarcodeSet.strPartBarcode =
  5922. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPartBarcode);
  5923. stPLC_MesData.Left.BarcodeSet.strCarrierBarcode =
  5924. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strCarrierBarcode);
  5925. stPLC_MesData.Left.BarcodeSet.strPCBBarcode =
  5926. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPCBBarcode);
  5927. stPLC_MesData.Right.BarcodeSet.strProductBarcode =
  5928. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strProductBarcode);
  5929. stPLC_MesData.Right.BarcodeSet.strPartBarcode =
  5930. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPartBarcode);
  5931. stPLC_MesData.Right.BarcodeSet.strCarrierBarcode =
  5932. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strCarrierBarcode);
  5933. stPLC_MesData.Right.BarcodeSet.strPCBBarcode =
  5934. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPCBBarcode);
  5935. #endregion
  5936. int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  5937. int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  5938. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  5939. ? XiaomiDeviceState.Unknown
  5940. : (XiaomiDeviceState)xmDeviceStateInt_L;
  5941. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  5942. ? XiaomiDeviceState.Unknown
  5943. : (XiaomiDeviceState)xmDeviceStateInt_R;
  5944. s7PLCData["a7OEEPartNo"] =
  5945. stPLC_MesData.Left.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  5946. // 载具SN
  5947. CarrierBarcode_Left = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode;
  5948. CarrierBarcode_Right = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode;
  5949. // 节拍
  5950. s7PLCData["a7OEEType"] = stPLC_MesData.Left.iotData.beatAction;
  5951. s7PLCData["a7OEEType_left"] = stPLC_MesData.Left .iotData.beatAction;
  5952. s7PLCData["a7OEEType_right"] = stPLC_MesData.Right.iotData.beatAction;
  5953. //报警信息
  5954. _FaultDatas = stPLC_MesData.Left.iotData.fault_codes;
  5955. _FaultDatas2 = stPLC_MesData.Right.iotData.fault_codes;
  5956. }
  5957. #endregion 一次性读取所有数据
  5958. stopwatch2.Stop();
  5959. #region 左边进站
  5960. try
  5961. {
  5962. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5963. {
  5964. lock (lockObj)
  5965. {
  5966. if (!ProgressState)
  5967. {
  5968. stationCode = "[OP81]";
  5969. stationName = "上盖板锁螺丝1";
  5970. stationNameStr = stationCode + stationName;
  5971. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  5972. ProgressState = true;
  5973. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left,
  5974. tagBaseName + ".Left." + tagMesCommName,
  5975. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState,
  5976. atlasScrewLeft));
  5977. }
  5978. }
  5979. }
  5980. }
  5981. catch (Exception ex)
  5982. {
  5983. ProgressState = false;
  5984. string str = ex.StackTrace;
  5985. AddMessage_Station(stationNameStr, LogType.Error,
  5986. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5987. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5988. }
  5989. #endregion 左边进站
  5990. #region 左边出站
  5991. try
  5992. {
  5993. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5994. {
  5995. lock (lockObj)
  5996. {
  5997. if (!ProgressState)
  5998. {
  5999. stationCode = "[OP81]";
  6000. stationName = "上盖板锁螺丝1";
  6001. stationNameStr = stationCode + stationName;
  6002. ProgressState = true;
  6003. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left,
  6004. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  6005. out ProgressState));
  6006. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  6007. }
  6008. }
  6009. }
  6010. }
  6011. catch (Exception ex)
  6012. {
  6013. ProgressState = false;
  6014. string str = ex.StackTrace;
  6015. AddMessage_Station(stationNameStr, LogType.Error,
  6016. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6017. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6018. }
  6019. #endregion 左边出站
  6020. #region 右边进站
  6021. try
  6022. {
  6023. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  6024. {
  6025. lock (lockObj)
  6026. {
  6027. if (!ProgressState)
  6028. {
  6029. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  6030. stationCode = "[OP82]";
  6031. stationName = "上盖板锁螺丝2";
  6032. stationNameStr = stationCode + stationName;
  6033. ProgressState = true;
  6034. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right,
  6035. tagBaseName + ".Right." + tagMesCommName,
  6036. tagBaseName + ".Right" + tagBarsetName, "Right", out ProgressState,
  6037. atlasScrewRight));
  6038. }
  6039. }
  6040. }
  6041. }
  6042. catch (Exception ex)
  6043. {
  6044. ProgressState = false;
  6045. string str = ex.StackTrace;
  6046. AddMessage_Station(stationNameStr, LogType.Error,
  6047. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6048. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6049. }
  6050. #endregion 右边进站
  6051. #region 右边出站
  6052. try
  6053. {
  6054. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  6055. {
  6056. lock (lockObj)
  6057. {
  6058. if (!ProgressState)
  6059. {
  6060. stationCode = "[OP82]";
  6061. stationName = "上盖板锁螺丝2";
  6062. stationNameStr = stationCode + stationName;
  6063. ProgressState = true;
  6064. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right,
  6065. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  6066. out ProgressState));
  6067. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  6068. }
  6069. }
  6070. }
  6071. }
  6072. catch (Exception ex)
  6073. {
  6074. ProgressState = false;
  6075. string str = ex.StackTrace;
  6076. AddMessage_Station(stationNameStr, LogType.Error,
  6077. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6078. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6079. }
  6080. #endregion 右边出站
  6081. #region 节拍接口
  6082. try
  6083. {
  6084. #region 左工位 节拍
  6085. if (stPLC_MesData.Left.iotData.beatAction > 0)
  6086. {
  6087. stationCode = "[OP81]";
  6088. stationName = "上盖板锁螺丝1";
  6089. stationNameStr = stationCode + stationName;
  6090. int a7OEEType_left = Convert.ToInt32(s7PLCData["a7OEEType_left"]);
  6091. int a7OEETypeGOld_left = Convert.ToInt32(s7PLCSignal_Old["a7OEEType_left"]);
  6092. if (a7OEEType_left != a7OEETypeGOld_left)
  6093. {
  6094. if (a7OEEType_left != a7OEETypeGOld_left)
  6095. s7PLCData["OEETypeFlag_left"] = "1";
  6096. else
  6097. s7PLCData["OEETypeFlag_left"] = "0";
  6098. if (s7PLCData["OEETypeFlag_left"].ToString() == "1" && (a7OEEType_left == 1 || a7OEEType_left == 3 || a7OEEType_left == 4 || a7OEEType_left == 5))
  6099. {
  6100. int res = 0;
  6101. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagiotComnName, CarrierBarcode_Left,
  6102. stPLC_MesData.Left.iotData, out res);
  6103. if (res == 1)
  6104. {
  6105. s7PLCSignal_Old["a7OEEType_left"] = s7PLCData["a7OEEType_left"];
  6106. }
  6107. else {
  6108. s7PLCSignal_Old["a7OEEType_left"] = 0;
  6109. }
  6110. }
  6111. }
  6112. }
  6113. else
  6114. {
  6115. s7PLCSignal_Old["a7OEEType_left"] = 0;
  6116. }
  6117. #endregion 左工位 节拍
  6118. #region 右工位 节拍
  6119. if (stPLC_MesData.Right.iotData.beatAction > 0)
  6120. {
  6121. stationCode = "[OP82]";
  6122. stationName = "上盖板锁螺丝2";
  6123. stationNameStr = stationCode + stationName;
  6124. int a7OEEType_right = Convert.ToInt32(s7PLCData["a7OEEType_right"]);
  6125. int a7OEETypeGOld_right = Convert.ToInt32(s7PLCSignal_Old["a7OEEType_right"]);
  6126. if (a7OEEType_right != a7OEETypeGOld_right)
  6127. {
  6128. if (a7OEEType_right != a7OEETypeGOld_right)
  6129. s7PLCData["a7OEEType_right"] = "1";
  6130. else
  6131. s7PLCData["a7OEEType_right"] = "0";
  6132. if (s7PLCData["a7OEEType_right"].ToString() == "1" && (a7OEEType_right == 1 || a7OEEType_right == 3 || a7OEEType_right == 4 || a7OEEType_right == 5))
  6133. {
  6134. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagiotComnName, CarrierBarcode_Left,
  6135. stPLC_MesData.Right.iotData, out res);
  6136. if (res == 1)
  6137. {
  6138. s7PLCSignal_Old["a7OEEType_right"] = s7PLCData["a7OEEType_right"];
  6139. }
  6140. else {
  6141. s7PLCSignal_Old["a7OEEType_right"] = 0;
  6142. }
  6143. }
  6144. }
  6145. }
  6146. else
  6147. {
  6148. s7PLCSignal_Old["a7OEEType_right"] = 0;
  6149. }
  6150. #endregion 右工位 节拍
  6151. }
  6152. catch (Exception ex)
  6153. {
  6154. string str = ex.StackTrace;
  6155. AddMessage_Station(stationNameStr, LogType.Error,
  6156. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  6157. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6158. }
  6159. #endregion
  6160. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6161. stopwatch1.Stop();
  6162. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6163. }
  6164. else
  6165. {
  6166. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6167. AddMessage_Station(stationNameStr, LogType.Info,
  6168. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6169. FunsEip[plcNo].Connect(); // 重连
  6170. }
  6171. }
  6172. catch (Exception ex)
  6173. {
  6174. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6175. AddMessage_Station(stationNameStr, LogType.Error,
  6176. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6177. }
  6178. Thread.Sleep(IntervalReadPLC);
  6179. }
  6180. }
  6181. /// <summary>
  6182. /// [S7] 锁螺丝设备 - 进站
  6183. /// </summary>
  6184. /// <param name="plcNo">PLC编号</param>
  6185. /// <param name="stationNameStr">工站全称</param>
  6186. /// <param name="stPLC_MesData"></param>
  6187. /// <param name="tagMesCommName"></param>
  6188. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  6189. string tagBarsetName, string direction, out bool ProgressState, AtlasScrew atlasScrew)
  6190. {
  6191. Stopwatch stopwatch1 = new Stopwatch();
  6192. Stopwatch stopwatch2 = new Stopwatch();
  6193. string atlasSn = string.Empty;
  6194. try
  6195. {
  6196. stopwatch1.Start();
  6197. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  6198. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  6199. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  6200. string StationId = string.Empty; // 工位ID(可配置)
  6201. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6202. bool pass = a1Result == 1;
  6203. if (direction == "Left")
  6204. {
  6205. StationId = GlobalContext.S7_StationId_1;
  6206. }
  6207. if (direction == "Right")
  6208. {
  6209. StationId = GlobalContext.S7_StationId_2;
  6210. }
  6211. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  6212. //载具码验证产品码
  6213. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  6214. if (string.IsNullOrEmpty(strProductBarcode))
  6215. {
  6216. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6217. ProgressState = false;
  6218. Thread.Sleep(10000);
  6219. return;
  6220. }
  6221. sn = strProductBarcode;
  6222. atlasSn = strProductBarcode;
  6223. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  6224. string slot = "";
  6225. if (direction == "Left")
  6226. {
  6227. isCollectingFlagLeft = false; //采集螺丝数据结束
  6228. slot = "01-SLOT-01";
  6229. }
  6230. if (direction == "Right")
  6231. {
  6232. isCollectingFlagRight = false; //采集螺丝数据结束
  6233. slot = "01-SLOT-02";
  6234. }
  6235. // 产品SN(物料码)校验
  6236. List<TestItem> item = new List<TestItem>();
  6237. stopwatch2.Start();
  6238. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  6239. item, MachineId, StationId, pass, slot);
  6240. stopwatch2.Stop();
  6241. //指令执行结果 1:OK 110:失败
  6242. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  6243. if (mesResultFrmWeb == 1)
  6244. {
  6245. if (a1Result == 1)
  6246. {
  6247. mesResultFrmWeb = 1;
  6248. }
  6249. else
  6250. {
  6251. mesResultFrmWeb = 110;
  6252. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  6253. }
  6254. }
  6255. //进站结果写入PLC
  6256. CommandFromPLC resultToPlC = new CommandFromPLC();
  6257. resultToPlC.cmd = 0;
  6258. resultToPlC.cmdParam = 0; //指令参数
  6259. resultToPlC.cmdResult = mesResultFrmWeb;
  6260. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6261. }
  6262. catch (Exception ex)
  6263. {
  6264. string str = ex.StackTrace;
  6265. AddMessage(LogType.Error,
  6266. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  6267. str.Length - str.LastIndexOf("\\") - 1));
  6268. CommandFromPLC resultToPlC = new CommandFromPLC();
  6269. resultToPlC.cmd = 0;
  6270. resultToPlC.cmdParam = 0; //指令参数
  6271. resultToPlC.cmdResult = 110;
  6272. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6273. }
  6274. stopwatch1.Stop();
  6275. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  6276. AddMessage(LogType.Info,
  6277. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  6278. stopwatch2.ElapsedMilliseconds + "ms");
  6279. ProgressState = false;
  6280. //开始采集螺丝数据
  6281. if (direction == "Left")
  6282. {
  6283. isCollectingFlagLeft = true;
  6284. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  6285. }
  6286. if (direction == "Right")
  6287. {
  6288. isCollectingFlagRight = true;
  6289. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  6290. }
  6291. }
  6292. /// <summary>
  6293. /// [S7] 锁螺丝设备 - 出站
  6294. /// </summary>
  6295. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  6296. string stationCode, string stationName, string direction, out bool ProgressState)
  6297. {
  6298. Stopwatch stopwatch1 = new Stopwatch();
  6299. Stopwatch stopwatch2 = new Stopwatch();
  6300. try
  6301. {
  6302. stopwatch1.Start();
  6303. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  6304. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6305. string processItem = stationName; // 测试项目
  6306. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6307. string supplierCode = ""; // 供应商代码
  6308. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6309. string batch_num = GlobalContext.BatchNumber; // 批次号
  6310. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6311. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  6312. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  6313. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  6314. string StationId = string.Empty; // 工位ID(可配置)
  6315. string slot = "";//iot槽位
  6316. if (direction == "Left")
  6317. {
  6318. StationId = GlobalContext.S7_StationId_1;
  6319. slot = "01-SLOT-01";
  6320. }
  6321. if (direction == "Right")
  6322. {
  6323. StationId = GlobalContext.S7_StationId_2;
  6324. slot = "01-SLOT-02";
  6325. }
  6326. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6327. //a1Result = 1;
  6328. bool pass = a1Result == 1;
  6329. //根据载具码获取产品码
  6330. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  6331. if (string.IsNullOrEmpty(strProductBarcode))
  6332. {
  6333. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6334. ProgressState = false;
  6335. Thread.Sleep(10000);
  6336. return;
  6337. }
  6338. sn = strProductBarcode;
  6339. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  6340. List<TestItem> items = new List<TestItem>();
  6341. items.Add(new TestItem()
  6342. {
  6343. Parameter_name = "载具码",
  6344. Parameter_value = CarrierBarcode,
  6345. Parameter_unit = ""
  6346. });
  6347. items.Add(new TestItem()
  6348. {
  6349. Parameter_name = "产品码",
  6350. Parameter_value = sn,
  6351. Parameter_unit = ""
  6352. });
  6353. #region 转换过站明细字符串
  6354. ////创建字典
  6355. //var dic = new Dictionary<string, string>();
  6356. //// 获取结构体类型
  6357. //FieldInfo[] fields = typeof(OP40_DataSet_t).GetFields();
  6358. //string resultString = "";
  6359. //// 遍历变量名转换成字典描述
  6360. //foreach (FieldInfo field in fields)
  6361. //{
  6362. // //获取枚举描述
  6363. // string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
  6364. // typeof(XiaomiMESEnum_ProcessData.Enum_40_ProcessData));
  6365. // //获取过站明细的值
  6366. // object valueObj = field.GetValue(stPLC_MesData.mesData) ?? 0;
  6367. // // 检查是否为数组
  6368. // if (valueObj.GetType().IsArray)
  6369. // {
  6370. // var array = valueObj as Array;
  6371. // resultString = ArrayToString(array);
  6372. // }
  6373. // else
  6374. // {
  6375. // resultString = valueObj.ToString();
  6376. // }
  6377. // dic.Add(name, resultString);
  6378. //}
  6379. //string paramJson = JsonConvert.SerializeObject(dic);
  6380. #endregion
  6381. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  6382. //if (direction == "Right")
  6383. //{
  6384. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem, workorder_code,
  6385. batch_num, mtltmrk, plcDate_YMD, supplierCode
  6386. , sn, pass, CarrierBarcode, slot, MachineId, StationId, "", paramJson,new XmStationOut_InspectionItemData(), "");
  6387. //}
  6388. //if (direction == "Left")
  6389. //{
  6390. // isCollectingFlagLeft = false;//采集螺丝数据结束
  6391. //}
  6392. //if (direction == "Right")
  6393. //{
  6394. // isCollectingFlagRight = false;//采集螺丝数据结束
  6395. //}
  6396. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  6397. if (mesResultFrmWeb == 1)
  6398. {
  6399. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  6400. if (mesResultFrmWeb == 110)
  6401. {
  6402. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  6403. }
  6404. }
  6405. stopwatch2.Start();
  6406. //进站结果写入PLC
  6407. CommandFromPLC resultToPlC = new CommandFromPLC();
  6408. resultToPlC.cmd = 0;
  6409. resultToPlC.cmdParam = 0; //指令参数
  6410. resultToPlC.cmdResult = mesResultFrmWeb;
  6411. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6412. stopwatch2.Stop();
  6413. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  6414. //保存PLC返回MES数据到本地
  6415. ResponseMessage message = new ResponseMessage();
  6416. if (direction == "Left")
  6417. {
  6418. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  6419. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  6420. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  6421. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  6422. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  6423. //if (message.result == false)
  6424. //{
  6425. // AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  6426. //}
  6427. }
  6428. if (direction == "Right")
  6429. {
  6430. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  6431. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  6432. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  6433. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  6434. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  6435. //if (message.result == false)
  6436. //{
  6437. // AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  6438. //}
  6439. }
  6440. //保存螺丝数据到txt
  6441. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes,
  6442. stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  6443. if (result.Item1 != 0)
  6444. {
  6445. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  6446. }
  6447. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_保存加工数据到本地成功");
  6448. }
  6449. catch (Exception ex)
  6450. {
  6451. stopwatch2.Start();
  6452. CommandFromPLC resultToPlC = new CommandFromPLC();
  6453. resultToPlC.cmd = 0;
  6454. resultToPlC.cmdParam = 0; //指令参数
  6455. resultToPlC.cmdResult = 110;
  6456. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6457. stopwatch2.Stop();
  6458. string str = ex.StackTrace;
  6459. AddMessage(LogType.Error,
  6460. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  6461. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6462. }
  6463. stopwatch1.Stop();
  6464. AddMessage(LogType.Info,
  6465. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6466. stopwatch2.ElapsedMilliseconds + "ms");
  6467. ProgressState = false;
  6468. if (direction == "Left") uuid = "";
  6469. if (direction == "Right") uuid2 = "";
  6470. }
  6471. #endregion
  6472. #region S8
  6473. private Dictionary<string, object> s8PLCData = new Dictionary<string, object>();
  6474. private Dictionary<string, object> s8PLCSignal_Old = new Dictionary<string, object>();
  6475. /// <summary>
  6476. /// [S8] 3D螺丝高度检测设备
  6477. /// </summary>
  6478. /// <param name="plcNo">PLC编号</param>
  6479. private void ReadStation_S8(int plcNo)
  6480. {
  6481. string stationCode = "[OP90]";
  6482. string stationName = "NG下料";
  6483. string stationNameStr = stationCode + stationName;
  6484. string tagBaseName = "g_OP80_MES"; //标签变量名称
  6485. string tagMesCommName = "mesCommToPC"; //标签变量名称
  6486. string tagAgvCommName = "agvCommFrmPC";
  6487. string tagiotComnName = "iotData";
  6488. string tagBarsetName = "BarcodeSet";
  6489. string CarrierBarcode = "";
  6490. // 触发信号字典
  6491. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6492. s8PLCSignal_Old.Add("a8OEEType", 0); // 节拍类型(plc写入)
  6493. // PLC数据字典 赋值
  6494. s8PLCData.Add("a8OEEType", 0); // 节拍类型(plc写入)
  6495. s8PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  6496. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  6497. (int, string) result;
  6498. while (true)
  6499. {
  6500. try
  6501. {
  6502. if (!GlobalContext._IsCon_Funs1)
  6503. {
  6504. UpdatePLCMonitor(1, plcNo, 0);
  6505. continue;
  6506. }
  6507. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  6508. {
  6509. Stopwatch stopwatch1 = new Stopwatch();
  6510. Stopwatch stopwatch2 = new Stopwatch();
  6511. stopwatch1.Start();
  6512. stopwatch2.Start();
  6513. #region 一次性读取所有数据
  6514. // 一次性读取所有数据
  6515. result = FunsEip[plcNo]
  6516. .Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  6517. if (result.Item1 != 0)
  6518. {
  6519. //richTextBox1.AppendText("\n" + strRet);
  6520. }
  6521. else
  6522. {
  6523. //去除扫码产生的特殊字符
  6524. stPLC_MesData.BarcodeSet.strProductBarcode =
  6525. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  6526. stPLC_MesData.BarcodeSet.strPartBarcode =
  6527. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  6528. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  6529. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  6530. stPLC_MesData.BarcodeSet.strPCBBarcode =
  6531. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  6532. }
  6533. #endregion 一次性读取所有数据
  6534. stopwatch2.Stop();
  6535. //richTextBox1.AppendText("\n" + "读取成功");
  6536. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  6537. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  6538. ? XiaomiDeviceState.Unknown
  6539. : (XiaomiDeviceState)xmDeviceStateInt;
  6540. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  6541. s8PLCData["a8OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  6542. //报警信息
  6543. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  6544. stopwatch2.Stop();
  6545. #region 进站
  6546. try
  6547. {
  6548. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  6549. {
  6550. lock (lockObj)
  6551. {
  6552. if (!ProgressState)
  6553. {
  6554. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  6555. ProgressState = true;
  6556. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData,
  6557. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  6558. out ProgressState));
  6559. }
  6560. }
  6561. }
  6562. }
  6563. catch (Exception ex)
  6564. {
  6565. ProgressState = false;
  6566. string str = ex.StackTrace;
  6567. AddMessage_Station(stationNameStr, LogType.Error,
  6568. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6569. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6570. }
  6571. #endregion 进站
  6572. #region 出站
  6573. try
  6574. {
  6575. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  6576. {
  6577. lock (lockObj)
  6578. {
  6579. if (!ProgressState)
  6580. {
  6581. ProgressState = true;
  6582. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData,
  6583. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  6584. out ProgressState));
  6585. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  6586. }
  6587. }
  6588. }
  6589. }
  6590. catch (Exception ex)
  6591. {
  6592. ProgressState = false;
  6593. string str = ex.StackTrace;
  6594. AddMessage_Station(stationNameStr, LogType.Error,
  6595. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6596. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6597. }
  6598. #endregion 出站
  6599. #region 节拍接口
  6600. try
  6601. {
  6602. int a8OEEType = Convert.ToInt32(s8PLCData["a8OEEType"]);
  6603. int a8OEETypeGOld = Convert.ToInt32(s8PLCSignal_Old["a8OEEType"]);
  6604. if (stPLC_MesData.iotData.beatAction > 0)
  6605. {
  6606. if (a8OEEType != a8OEETypeGOld)
  6607. {
  6608. s8PLCData["OEETypeFlag"] = "1";
  6609. }
  6610. else
  6611. {
  6612. s8PLCData["OEETypeFlag"] = "0";
  6613. }
  6614. if (s8PLCData["OEETypeFlag"].ToString() == "1" && (a8OEEType == 1 || a8OEEType == 3 || a8OEEType == 4 || a8OEEType == 5))
  6615. {
  6616. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  6617. CarrierBarcode, stPLC_MesData.iotData, out res);
  6618. if (res == 1)
  6619. {
  6620. s8PLCSignal_Old["a8OEEType"] = s8PLCData["a8OEEType"];
  6621. }
  6622. else
  6623. {
  6624. s8PLCSignal_Old["a8OEEType"] = 0;
  6625. }
  6626. }
  6627. }
  6628. else {
  6629. s8PLCSignal_Old["a8OEEType"] = 0;
  6630. }
  6631. }
  6632. catch (Exception ex)
  6633. {
  6634. string str = ex.StackTrace;
  6635. AddMessage_Station(stationNameStr, LogType.Error,
  6636. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  6637. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6638. }
  6639. #endregion
  6640. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6641. stopwatch1.Stop();
  6642. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6643. }
  6644. else
  6645. {
  6646. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6647. AddMessage_Station(stationNameStr, LogType.Info,
  6648. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6649. FunsEip[plcNo].Connect(); // 重连
  6650. }
  6651. }
  6652. catch (Exception ex)
  6653. {
  6654. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6655. AddMessage_Station(stationNameStr, LogType.Error,
  6656. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6657. }
  6658. Thread.Sleep(IntervalReadPLC);
  6659. }
  6660. }
  6661. /// <summary>
  6662. /// [S8] 3D螺丝高度检测设备 - 进站
  6663. /// </summary>
  6664. /// <param name="plcNo">PLC编号</param>
  6665. /// <param name="stationNameStr">工站全称</param>
  6666. /// <param name="stPLC_MesData"></param>
  6667. /// <param name="tagMesCommName"></param>
  6668. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  6669. string tagBarsetName, out bool ProgressState)
  6670. {
  6671. Stopwatch stopwatch1 = new Stopwatch();
  6672. Stopwatch stopwatch2 = new Stopwatch();
  6673. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6674. bool pass = a1Result == 1;
  6675. try
  6676. {
  6677. stopwatch1.Start();
  6678. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  6679. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  6680. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  6681. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  6682. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  6683. //载具码验证产品码
  6684. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  6685. if (string.IsNullOrEmpty(strProductBarcode))
  6686. {
  6687. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6688. ProgressState = false;
  6689. Thread.Sleep(10000);
  6690. return;
  6691. }
  6692. sn = strProductBarcode;
  6693. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  6694. // 产品SN(物料码)校验
  6695. List<TestItem> item = new List<TestItem>();
  6696. stopwatch2.Start();
  6697. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  6698. sn,
  6699. item, MachineId, StationId, pass, "01-SLOT-01");
  6700. stopwatch2.Stop();
  6701. //指令执行结果 1:OK 110:失败
  6702. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  6703. if (mesResultFrmWeb == 1)
  6704. {
  6705. if (a1Result == 1)
  6706. {
  6707. mesResultFrmWeb = 1;
  6708. }
  6709. else
  6710. {
  6711. mesResultFrmWeb = 110;
  6712. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  6713. }
  6714. }
  6715. //进站结果写入PLC
  6716. CommandFromPLC resultToPlC = new CommandFromPLC();
  6717. resultToPlC.cmd = 0;
  6718. resultToPlC.cmdParam = 0; //指令参数
  6719. resultToPlC.cmdResult = mesResultFrmWeb;
  6720. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6721. }
  6722. catch (Exception ex)
  6723. {
  6724. string str = ex.StackTrace;
  6725. AddMessage(LogType.Error,
  6726. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(
  6727. str.LastIndexOf("\\") + 1,
  6728. str.Length - str.LastIndexOf("\\") - 1));
  6729. CommandFromPLC resultToPlC = new CommandFromPLC();
  6730. resultToPlC.cmd = 0;
  6731. resultToPlC.cmdParam = 0; //指令参数
  6732. resultToPlC.cmdResult = 110;
  6733. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6734. }
  6735. stopwatch1.Stop();
  6736. AddMessage(LogType.Info,
  6737. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  6738. stopwatch2.ElapsedMilliseconds + "ms");
  6739. ProgressState = false;
  6740. }
  6741. /// <summary>
  6742. /// [S8] 3D螺丝高度检测设备 - 出站接口
  6743. /// </summary>
  6744. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  6745. string stationCode, string stationName, out bool ProgressState)
  6746. {
  6747. Stopwatch stopwatch1 = new Stopwatch();
  6748. Stopwatch stopwatch2 = new Stopwatch();
  6749. try
  6750. {
  6751. stopwatch1.Start();
  6752. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  6753. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6754. string processItem = stationName; // 测试项目
  6755. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6756. string supplierCode = ""; // 供应商代码
  6757. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6758. string batch_num = GlobalContext.BatchNumber; // 批次号
  6759. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6760. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  6761. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  6762. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  6763. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  6764. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6765. bool pass = a1Result == 1;
  6766. //根据载具码获取产品码
  6767. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  6768. if (string.IsNullOrEmpty(strProductBarcode))
  6769. {
  6770. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6771. ProgressState = false;
  6772. Thread.Sleep(10000);
  6773. return;
  6774. }
  6775. sn = strProductBarcode;
  6776. stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
  6777. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  6778. List<TestItem> items = new List<TestItem>();
  6779. items.Add(new TestItem()
  6780. {
  6781. Parameter_name = "载具码",
  6782. Parameter_value = CarrierBarcode,
  6783. Parameter_unit = ""
  6784. });
  6785. items.Add(new TestItem()
  6786. {
  6787. Parameter_name = "产品码",
  6788. Parameter_value = sn,
  6789. Parameter_unit = ""
  6790. });
  6791. #region 上传图片
  6792. if (GlobalContext.MQTTIsSendUpFile)
  6793. {
  6794. CopyFileToTempPath(GlobalContext.UpFilePath, GlobalContext.MqttFileTempDir);
  6795. if (Directory.Exists(GlobalContext.MqttFileTempDir))
  6796. {
  6797. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName, a1Result, GlobalContext.MqttFileTempDir, uuid).Result;
  6798. if (result.Item1 == 1)
  6799. {
  6800. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  6801. }
  6802. }
  6803. //string[] urlarry = GlobalContext.UpFilePath.Split(",");
  6804. //// fileUploadData.fileData.Clear();
  6805. //foreach (var item in urlarry)
  6806. //{
  6807. // if (!string.IsNullOrEmpty(item))
  6808. // {
  6809. // //上传图片
  6810. // var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName,
  6811. // a1Result, item, uuid).Result;
  6812. // OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  6813. // }
  6814. //}
  6815. }
  6816. #endregion
  6817. #region 转换过站明细字符串
  6818. ////创建字典
  6819. //var dic = new Dictionary<string, string>();
  6820. //// 获取结构体类型
  6821. //FieldInfo[] fields = typeof(OP40_DataSet_t).GetFields();
  6822. //string resultString = "";
  6823. //// 遍历变量名转换成字典描述
  6824. //foreach (FieldInfo field in fields)
  6825. //{
  6826. // //获取枚举描述
  6827. // string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
  6828. // typeof(XiaomiMESEnum_ProcessData.Enum_40_ProcessData));
  6829. // //获取过站明细的值
  6830. // object valueObj = field.GetValue(stPLC_MesData.mesData) ?? 0;
  6831. // // 检查是否为数组
  6832. // if (valueObj.GetType().IsArray)
  6833. // {
  6834. // var array = valueObj as Array;
  6835. // resultString = ArrayToString(array);
  6836. // }
  6837. // else
  6838. // {
  6839. // resultString = valueObj.ToString();
  6840. // }
  6841. // dic.Add(name, resultString);
  6842. //}
  6843. //string paramJson = JsonConvert.SerializeObject(dic);
  6844. #endregion
  6845. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  6846. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6847. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "01-SLOT-01",
  6848. MachineId, StationId, "", paramJson,new XmStationOut_InspectionItemData(), "");
  6849. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  6850. if (mesResultFrmWeb == 1)
  6851. {
  6852. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  6853. if (mesResultFrmWeb == 110)
  6854. {
  6855. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  6856. }
  6857. }
  6858. stopwatch2.Start();
  6859. //进站结果写入PLC
  6860. CommandFromPLC resultToPlC = new CommandFromPLC();
  6861. resultToPlC.cmd = 0;
  6862. resultToPlC.cmdParam = 0; //指令参数
  6863. resultToPlC.cmdResult = mesResultFrmWeb;
  6864. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6865. stopwatch2.Stop();
  6866. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  6867. //保存PLC返回MES数据到本地
  6868. ResponseMessage message = new ResponseMessage();
  6869. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  6870. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  6871. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  6872. if (message.result == false)
  6873. {
  6874. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  6875. }
  6876. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  6877. }
  6878. catch (Exception ex)
  6879. {
  6880. stopwatch2.Start();
  6881. CommandFromPLC resultToPlC = new CommandFromPLC();
  6882. resultToPlC.cmd = 0;
  6883. resultToPlC.cmdParam = 0; //指令参数
  6884. resultToPlC.cmdResult = 110;
  6885. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6886. stopwatch2.Stop();
  6887. string str = ex.StackTrace;
  6888. AddMessage(LogType.Error,
  6889. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  6890. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6891. }
  6892. stopwatch1.Stop();
  6893. AddMessage(LogType.Info,
  6894. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6895. stopwatch2.ElapsedMilliseconds + "ms");
  6896. ProgressState = false;
  6897. uuid = "";
  6898. }
  6899. #endregion
  6900. #region S9
  6901. private Dictionary<string, object> s9PLCData = new Dictionary<string, object>();
  6902. private Dictionary<string, object> s9PLCSignal_Old = new Dictionary<string, object>();
  6903. /// <summary>
  6904. /// [S9] 下料设备
  6905. /// </summary>
  6906. /// <param name="plcNo">PLC编号</param>
  6907. private void ReadStation_S9(int plcNo)
  6908. {
  6909. string stationCode = "[OP100]";
  6910. string stationName = "半成品下料";
  6911. string stationNameStr = stationCode + stationName;
  6912. string tagBaseName = "g_OP90_MES"; //标签变量名称
  6913. string tagMesCommName = "mesCommToPC"; //标签变量名称
  6914. string tagAgvCommName = "agvCommFrmPC";
  6915. string tagiotComnName = "iotData";
  6916. string tagBarsetName = "BarcodeSet";
  6917. string CarrierBarcode = "";
  6918. // 触发信号字典
  6919. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6920. s9PLCSignal_Old.Add("a9OEEType", 0); // 节拍类型(plc写入)
  6921. // PLC数据字典 赋值
  6922. s9PLCData.Add("a9OEEType", 0); // 节拍类型(plc写入)
  6923. s9PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  6924. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  6925. (int, string) result;
  6926. while (true)
  6927. {
  6928. try
  6929. {
  6930. if (!GlobalContext._IsCon_Funs1)
  6931. {
  6932. UpdatePLCMonitor(1, plcNo, 0);
  6933. continue;
  6934. }
  6935. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  6936. {
  6937. Stopwatch stopwatch1 = new Stopwatch();
  6938. Stopwatch stopwatch2 = new Stopwatch();
  6939. stopwatch1.Start();
  6940. stopwatch2.Start();
  6941. #region 一次性读取所有数据
  6942. // 一次性读取所有数据
  6943. result = FunsEip[plcNo]
  6944. .Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  6945. if (result.Item1 != 0)
  6946. {
  6947. //richTextBox1.AppendText("\n" + strRet);
  6948. }
  6949. else
  6950. {
  6951. //去除扫码产生的特殊字符
  6952. stPLC_MesData.BarcodeSet.strProductBarcode =
  6953. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  6954. stPLC_MesData.BarcodeSet.strPartBarcode =
  6955. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  6956. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  6957. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  6958. stPLC_MesData.BarcodeSet.strPCBBarcode =
  6959. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  6960. //richTextBox1.AppendText("\n" + "读取成功");
  6961. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  6962. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  6963. ? XiaomiDeviceState.Unknown
  6964. : (XiaomiDeviceState)xmDeviceStateInt;
  6965. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  6966. s9PLCData["a9OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  6967. //报警信息
  6968. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  6969. }
  6970. #endregion 一次性读取所有数据
  6971. stopwatch2.Stop();
  6972. #region 进站
  6973. try
  6974. {
  6975. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  6976. {
  6977. lock (lockObj)
  6978. {
  6979. if (!ProgressState)
  6980. {
  6981. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  6982. ProgressState = true;
  6983. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData,
  6984. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  6985. out ProgressState));
  6986. }
  6987. }
  6988. }
  6989. }
  6990. catch (Exception ex)
  6991. {
  6992. ProgressState = false;
  6993. string str = ex.StackTrace;
  6994. AddMessage_Station(stationNameStr, LogType.Error,
  6995. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6996. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6997. }
  6998. #endregion 进站
  6999. #region 出站
  7000. try
  7001. {
  7002. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  7003. {
  7004. lock (lockObj)
  7005. {
  7006. if (!ProgressState)
  7007. {
  7008. ProgressState = true;
  7009. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData,
  7010. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  7011. out ProgressState));
  7012. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  7013. }
  7014. }
  7015. }
  7016. }
  7017. catch (Exception ex)
  7018. {
  7019. ProgressState = false;
  7020. string str = ex.StackTrace;
  7021. AddMessage_Station(stationNameStr, LogType.Error,
  7022. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  7023. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7024. }
  7025. #endregion 出站
  7026. #region 节拍接口
  7027. try
  7028. {
  7029. if (stPLC_MesData.iotData.beatAction > 0)
  7030. {
  7031. int a9OEEType = Convert.ToInt32(s9PLCData["a9OEEType"]);
  7032. int a9OEETypeGOld = Convert.ToInt32(s9PLCSignal_Old["a9OEEType"]);
  7033. if (a9OEEType != a9OEETypeGOld)
  7034. {
  7035. s9PLCData["OEETypeFlag"] = "1";
  7036. }
  7037. else
  7038. {
  7039. s9PLCData["OEETypeFlag"] = "0";
  7040. }
  7041. if (s9PLCData["OEETypeFlag"].ToString() == "1" && (a9OEEType == 1 || a9OEEType == 3 || a9OEEType == 4 || a9OEEType == 5))
  7042. {
  7043. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  7044. CarrierBarcode, stPLC_MesData.iotData, out res);
  7045. if (res == 1)
  7046. {
  7047. s9PLCSignal_Old["a9OEEType"] = s9PLCData["a9OEEType"];
  7048. }
  7049. else
  7050. {
  7051. s9PLCSignal_Old["a9OEEType"] = 0;
  7052. }
  7053. }
  7054. }
  7055. else {
  7056. s9PLCSignal_Old["a9OEEType"] = 0;
  7057. }
  7058. }
  7059. catch (Exception ex)
  7060. {
  7061. string str = ex.StackTrace;
  7062. AddMessage_Station(stationNameStr, LogType.Error,
  7063. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  7064. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7065. }
  7066. #endregion
  7067. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7068. stopwatch1.Stop();
  7069. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7070. }
  7071. else
  7072. {
  7073. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7074. AddMessage_Station(stationNameStr, LogType.Info,
  7075. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  7076. FunsEip[plcNo].Connect(); // 重连
  7077. }
  7078. }
  7079. catch (Exception ex)
  7080. {
  7081. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7082. AddMessage_Station(stationNameStr, LogType.Error,
  7083. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  7084. }
  7085. Thread.Sleep(IntervalReadPLC);
  7086. }
  7087. }
  7088. /// <summary>
  7089. /// [S9] 下料设备 - 进站
  7090. /// </summary>
  7091. /// <param name="plcNo">PLC编号</param>
  7092. /// <param name="stationNameStr">工站全称</param>
  7093. /// <param name="stPLC_MesData"></param>
  7094. /// <param name="tagMesCommName"></param>
  7095. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  7096. string tagBarsetName, out bool ProgressState)
  7097. {
  7098. Stopwatch stopwatch1 = new Stopwatch();
  7099. Stopwatch stopwatch2 = new Stopwatch();
  7100. try
  7101. {
  7102. stopwatch1.Start();
  7103. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  7104. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  7105. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  7106. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  7107. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  7108. bool pass = a1Result == 1;
  7109. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  7110. //载具码验证产品码
  7111. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  7112. if (string.IsNullOrEmpty(strProductBarcode))
  7113. {
  7114. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  7115. ProgressState = false;
  7116. Thread.Sleep(10000);
  7117. return;
  7118. }
  7119. sn = strProductBarcode;
  7120. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  7121. // 产品SN(物料码)校验
  7122. List<TestItem> item = new List<TestItem>();
  7123. stopwatch2.Start();
  7124. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  7125. item, MachineId, StationId, pass, "01-SLOT-01");
  7126. stopwatch2.Stop();
  7127. //指令执行结果 1:OK 110:失败
  7128. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  7129. if (mesResultFrmWeb == 1)
  7130. {
  7131. if (a1Result == 1)
  7132. {
  7133. mesResultFrmWeb = 1;
  7134. }
  7135. else
  7136. {
  7137. mesResultFrmWeb = 110;
  7138. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  7139. }
  7140. }
  7141. //进站结果写入PLC
  7142. CommandFromPLC resultToPlC = new CommandFromPLC();
  7143. resultToPlC.cmd = 0;
  7144. resultToPlC.cmdParam = 0; //指令参数
  7145. resultToPlC.cmdResult = mesResultFrmWeb;
  7146. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  7147. }
  7148. catch (Exception ex)
  7149. {
  7150. string str = ex.StackTrace;
  7151. AddMessage(LogType.Error,
  7152. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  7153. str.Length - str.LastIndexOf("\\") - 1));
  7154. CommandFromPLC resultToPlC = new CommandFromPLC();
  7155. resultToPlC.cmd = 0;
  7156. resultToPlC.cmdParam = 0; //指令参数
  7157. resultToPlC.cmdResult = 110;
  7158. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  7159. }
  7160. stopwatch1.Stop();
  7161. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  7162. AddMessage(LogType.Info,
  7163. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  7164. stopwatch2.ElapsedMilliseconds + "ms");
  7165. ProgressState = false;
  7166. }
  7167. /// <summary>
  7168. /// [S9] 下料设备 - 出站接口
  7169. /// </summary>
  7170. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  7171. string stationCode, string stationName, out bool ProgressState)
  7172. {
  7173. Stopwatch stopwatch1 = new Stopwatch();
  7174. Stopwatch stopwatch2 = new Stopwatch();
  7175. try
  7176. {
  7177. stopwatch1.Start();
  7178. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  7179. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7180. string processItem = stationName; // 测试项目
  7181. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7182. string supplierCode = ""; // 供应商代码
  7183. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7184. string batch_num = GlobalContext.BatchNumber; // 批次号
  7185. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7186. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  7187. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  7188. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  7189. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  7190. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  7191. bool pass = a1Result == 1;
  7192. //根据载具码获取产品码
  7193. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  7194. if (string.IsNullOrEmpty(strProductBarcode))
  7195. {
  7196. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  7197. ProgressState = false;
  7198. Thread.Sleep(10000);
  7199. return;
  7200. }
  7201. sn = strProductBarcode;
  7202. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  7203. List<TestItem> items = new List<TestItem>();
  7204. items.Add(new TestItem()
  7205. {
  7206. Parameter_name = "载具码",
  7207. Parameter_value = CarrierBarcode,
  7208. Parameter_unit = ""
  7209. });
  7210. items.Add(new TestItem()
  7211. {
  7212. Parameter_name = "产品码",
  7213. Parameter_value = sn,
  7214. Parameter_unit = ""
  7215. });
  7216. #region 转换过站明细字符串
  7217. ////创建字典
  7218. //var dic = new Dictionary<string, string>();
  7219. //// 获取结构体类型
  7220. //FieldInfo[] fields = typeof(OP40_DataSet_t).GetFields();
  7221. //string resultString = "";
  7222. //// 遍历变量名转换成字典描述
  7223. //foreach (FieldInfo field in fields)
  7224. //{
  7225. // //获取枚举描述
  7226. // string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
  7227. // typeof(XiaomiMESEnum_ProcessData.Enum_40_ProcessData));
  7228. // //获取过站明细的值
  7229. // object valueObj = field.GetValue(stPLC_MesData.mesData) ?? 0;
  7230. // // 检查是否为数组
  7231. // if (valueObj.GetType().IsArray)
  7232. // {
  7233. // var array = valueObj as Array;
  7234. // resultString = ArrayToString(array);
  7235. // }
  7236. // else
  7237. // {
  7238. // resultString = valueObj.ToString();
  7239. // }
  7240. // dic.Add(name, resultString);
  7241. //}
  7242. //string paramJson = JsonConvert.SerializeObject(dic);
  7243. #endregion
  7244. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  7245. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  7246. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "01-SLOT-01",
  7247. MachineId, StationId, "", paramJson,new XmStationOut_InspectionItemData(), "");
  7248. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  7249. if (mesResultFrmWeb == 1)
  7250. {
  7251. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  7252. if (mesResultFrmWeb == 110)
  7253. {
  7254. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  7255. }
  7256. }
  7257. stopwatch2.Start();
  7258. //进站结果写入PLC
  7259. CommandFromPLC resultToPlC = new CommandFromPLC();
  7260. resultToPlC.cmd = 0;
  7261. resultToPlC.cmdParam = 0; //指令参数
  7262. resultToPlC.cmdResult = mesResultFrmWeb;
  7263. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  7264. stopwatch2.Stop();
  7265. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  7266. //保存PLC返回MES数据到本地
  7267. ResponseMessage message = new ResponseMessage();
  7268. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  7269. stPLC_MesData.mesData.nRemainCount);
  7270. if (message.result == false)
  7271. {
  7272. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  7273. }
  7274. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  7275. if (result1 == 1)
  7276. {
  7277. //载具码解除绑定
  7278. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  7279. if (message.result == false)
  7280. {
  7281. AddMessage(LogType.Error, message.text);
  7282. }
  7283. }
  7284. }
  7285. catch (Exception ex)
  7286. {
  7287. stopwatch2.Start();
  7288. CommandFromPLC resultToPlC = new CommandFromPLC();
  7289. resultToPlC.cmd = 0;
  7290. resultToPlC.cmdParam = 0; //指令参数
  7291. resultToPlC.cmdResult = 110;
  7292. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  7293. stopwatch2.Stop();
  7294. string str = ex.StackTrace;
  7295. AddMessage(LogType.Error,
  7296. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  7297. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7298. }
  7299. stopwatch1.Stop();
  7300. AddMessage(LogType.Info,
  7301. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7302. stopwatch2.ElapsedMilliseconds + "ms");
  7303. ProgressState = false;
  7304. uuid = "";
  7305. }
  7306. #endregion
  7307. #endregion Xiaomi
  7308. #region PLC1 张超凡
  7309. #region [S1] Tray盘上料装备(板测)
  7310. /// <summary>
  7311. /// S1工位的数据- 触发信号上次的值
  7312. /// </summary>
  7313. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  7314. /// <summary>
  7315. /// S1工位的数据(含触发信号)
  7316. /// </summary>
  7317. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  7318. /// <summary>
  7319. /// S1工位的数据- 回写点位
  7320. /// </summary>
  7321. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  7322. ///// <summary>
  7323. ///// 触发信号
  7324. ///// </summary>
  7325. //private ManualResetEvent[] MreTasks;
  7326. /// <summary>
  7327. /// [S1] Tray盘上料装备(板测)
  7328. /// </summary>
  7329. /// <param name="plcNo">PLC编号</param>
  7330. //private void ReadStation_S1(int plcNo)
  7331. //{
  7332. // // [S1] Tray盘上料装备
  7333. // // [S2] FCT
  7334. // // [S3] 值板机
  7335. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  7336. // // [S5] Tray盘下料装备
  7337. // string stationCode = "[S1]";
  7338. // string stationName = "Tray盘上料装备";
  7339. // string stationNameStr = stationCode + stationName;
  7340. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  7341. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  7342. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  7343. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  7344. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  7345. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  7346. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  7347. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  7348. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  7349. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  7350. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  7351. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  7352. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  7353. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  7354. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  7355. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  7356. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  7357. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  7358. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  7359. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  7360. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  7361. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  7362. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  7363. // s1PLCData.Add("a1Result", 0); // 产品结果
  7364. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  7365. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  7366. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  7367. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  7368. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  7369. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  7370. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  7371. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  7372. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  7373. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  7374. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  7375. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  7376. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  7377. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  7378. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  7379. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  7380. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  7381. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  7382. // while (IsRun)
  7383. // {
  7384. // try
  7385. // {
  7386. // if (!GlobalContext._IsCon_Funs1)
  7387. // {
  7388. // UpdatePLCMonitor(1, plcNo, 0);
  7389. // continue;
  7390. // }
  7391. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  7392. // {
  7393. // Stopwatch stopwatch1 = new Stopwatch();
  7394. // Stopwatch stopwatch2 = new Stopwatch();
  7395. // stopwatch1.Start();
  7396. // stopwatch2.Start();
  7397. // #region 一次性读取所有数据
  7398. // // 一次性读取所有数据
  7399. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  7400. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  7401. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  7402. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  7403. // int[] datas = data1.Concat(data2).ToArray();
  7404. // datas = datas.Concat(data3).ToArray();
  7405. // datas = datas.Concat(data4).ToArray();
  7406. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  7407. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  7408. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  7409. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  7410. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  7411. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  7412. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  7413. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  7414. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  7415. // s1PLCData["a1MES_FLAG"] = datas[109];
  7416. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  7417. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  7418. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  7419. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  7420. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  7421. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  7422. // s1PLCData["a1Result"] = datas[170];
  7423. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  7424. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  7425. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  7426. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  7427. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  7428. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  7429. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  7430. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  7431. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  7432. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  7433. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  7434. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  7435. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  7436. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  7437. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  7438. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  7439. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  7440. // s1PLCData["a1AGVUpStart"] = datas[308];
  7441. // s1PLCData["a1AGVUpEnd"] = datas[309];
  7442. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  7443. // s1PLCData["a1AGVDownStart"] = datas[321];
  7444. // s1PLCData["a1AGVDownEnd"] = datas[322];
  7445. // #endregion 一次性读取所有数据
  7446. // stopwatch2.Stop();
  7447. // #region 回写操作,写后清空flag
  7448. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  7449. // #endregion 回写操作,写后清空flag
  7450. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  7451. // try
  7452. // {
  7453. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  7454. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  7455. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  7456. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  7457. // {
  7458. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  7459. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  7460. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  7461. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  7462. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  7463. // }
  7464. // }
  7465. // catch (Exception ex)
  7466. // {
  7467. // // 6代表上位机报警
  7468. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  7469. // string str = ex.StackTrace;
  7470. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7471. // }
  7472. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  7473. // #region 上料进站校验
  7474. // try
  7475. // {
  7476. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  7477. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  7478. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  7479. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  7480. // {
  7481. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  7482. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  7483. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  7484. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  7485. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  7486. // }
  7487. // }
  7488. // catch (Exception ex)
  7489. // {
  7490. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7491. // string str = ex.StackTrace;
  7492. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7493. // }
  7494. // #endregion 上料进站校验
  7495. // #region Tray盘上料装备-出站接口
  7496. // try
  7497. // {
  7498. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  7499. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  7500. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  7501. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  7502. // {
  7503. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  7504. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  7505. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  7506. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  7507. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  7508. // }
  7509. // }
  7510. // catch (Exception ex)
  7511. // {
  7512. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  7513. // string str = ex.StackTrace;
  7514. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7515. // }
  7516. // #endregion Tray盘上料装备-出站接口
  7517. // #region Tray盘上料装备-将SN发给ICT标机
  7518. // try
  7519. // {
  7520. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  7521. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  7522. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  7523. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  7524. // {
  7525. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  7526. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  7527. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  7528. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  7529. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  7530. // }
  7531. // }
  7532. // catch (Exception ex)
  7533. // {
  7534. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  7535. // string str = ex.StackTrace;
  7536. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7537. // }
  7538. // #endregion Tray盘上料装备-将SN发给ICT标机
  7539. // #region Tray盘上料装备-点检数据
  7540. // //try
  7541. // //{
  7542. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  7543. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  7544. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  7545. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  7546. // // if (pLC_Flag && !mES_Flag) // 1 0
  7547. // // {
  7548. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  7549. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  7550. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  7551. // // }
  7552. // // else if (!pLC_Flag && mES_Flag) // 0 1
  7553. // // {
  7554. // // // 清空写给PLC的数据
  7555. // // // MES_Flag重置为0
  7556. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  7557. // // }
  7558. // //}
  7559. // //catch (Exception ex)
  7560. // //{
  7561. // // // MES_Flag 为2上位机报错
  7562. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  7563. // // string str = ex.StackTrace;
  7564. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7565. // //}
  7566. // #endregion Tray盘上料装备-点检数据
  7567. // #region 节拍接口
  7568. // try
  7569. // {
  7570. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  7571. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  7572. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  7573. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  7574. // {
  7575. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  7576. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7577. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  7578. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  7579. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  7580. // }
  7581. // }
  7582. // catch (Exception ex)
  7583. // {
  7584. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  7585. // string str = ex.StackTrace;
  7586. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7587. // }
  7588. // #endregion 节拍接口
  7589. // #region AGV上料
  7590. // // AGV上料叫AGV信号
  7591. // try
  7592. // {
  7593. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  7594. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  7595. // if (a1AGVUpCall != a1AGVUpCallOld)
  7596. // {
  7597. // if (a1AGVUpCall == 1) // 0->1
  7598. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  7599. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  7600. // }
  7601. // }
  7602. // catch (Exception ex)
  7603. // {
  7604. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  7605. // string str = ex.StackTrace;
  7606. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7607. // }
  7608. // // AGV上料完成信号
  7609. // try
  7610. // {
  7611. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  7612. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  7613. // if (a1AGVUpEnd != a1AGVUpEndOld)
  7614. // {
  7615. // if (a1AGVUpEnd == 1) // 0->1
  7616. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  7617. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  7618. // }
  7619. // }
  7620. // catch (Exception ex)
  7621. // {
  7622. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  7623. // string str = ex.StackTrace;
  7624. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7625. // }
  7626. // #endregion AGV上料
  7627. // #region AGV下料
  7628. // // AGV下料叫agv信号
  7629. // try
  7630. // {
  7631. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  7632. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  7633. // if (a1AGVDownCall != a1AGVDownCallOld)
  7634. // {
  7635. // if (a1AGVDownCall == 1) // 0->1
  7636. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  7637. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  7638. // }
  7639. // }
  7640. // catch (Exception ex)
  7641. // {
  7642. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  7643. // string str = ex.StackTrace;
  7644. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7645. // }
  7646. // // AGV下料完成信号
  7647. // try
  7648. // {
  7649. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  7650. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  7651. // if (a1AGVDownEnd != a1AGVDownEndOld)
  7652. // {
  7653. // if (a1AGVDownEnd == 1) // 0->1
  7654. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  7655. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  7656. // }
  7657. // }
  7658. // catch (Exception ex)
  7659. // {
  7660. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  7661. // string str = ex.StackTrace;
  7662. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7663. // }
  7664. // #endregion AGV下料
  7665. // #region 心跳
  7666. // try
  7667. // {
  7668. // short states = 0;
  7669. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7670. // }
  7671. // catch (Exception ex)
  7672. // {
  7673. // string str = ex.StackTrace;
  7674. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7675. // }
  7676. // #endregion 心跳
  7677. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7678. // stopwatch1.Stop();
  7679. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7680. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7681. // }
  7682. // else
  7683. // {
  7684. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7685. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  7686. // Funs[plcNo].Connect(); // 重连
  7687. // }
  7688. // }
  7689. // catch (Exception ex)
  7690. // {
  7691. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7692. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  7693. // Funs[plcNo].ReConnect();
  7694. // }
  7695. // Thread.Sleep(IntervalReadPLC);
  7696. // }
  7697. //}
  7698. /// <summary>
  7699. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  7700. /// </summary>
  7701. /// <param name="plcNo">PLC编号</param>
  7702. /// <param name="stationNameStr">工站全称</param>
  7703. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  7704. {
  7705. Stopwatch stopwatch1 = new Stopwatch();
  7706. Stopwatch stopwatch2 = new Stopwatch();
  7707. try
  7708. {
  7709. stopwatch1.Start();
  7710. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  7711. sn = sn.Replace("\0", "");
  7712. #region 查询载具上的产品信息
  7713. string cavityData = string.Empty;
  7714. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  7715. if (string.IsNullOrEmpty(cavityData))
  7716. cavityData = "";
  7717. if (snResult != 0)
  7718. {
  7719. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7720. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  7721. writeToPLC_Flag1.Adress = 2003;
  7722. writeToPLC_Flag1.Value = (short)6;
  7723. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  7724. stopwatch1.Stop();
  7725. AddMessage(LogType.Info,
  7726. stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  7727. "ms");
  7728. return;
  7729. }
  7730. #endregion 查询载具上的产品信息
  7731. string[] cavitySNs = cavityData.Split('.');
  7732. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  7733. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  7734. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  7735. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  7736. if (cavitySNs != null && cavitySNs.Length >= 2)
  7737. {
  7738. a1CavitySN1_VehicleStates = cavitySNs[0];
  7739. a1CavitySN2_VehicleStates = cavitySNs[1];
  7740. a1CavityResult1_VehicleStates = 2;
  7741. a1CavityResult2_VehicleStates = 2;
  7742. }
  7743. if (a1CavitySN1_VehicleStates == "假产品")
  7744. a1CavityResult1_VehicleStates = 3;
  7745. if (a1CavitySN2_VehicleStates == "假产品")
  7746. a1CavityResult2_VehicleStates = 3;
  7747. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7748. // 回写
  7749. stopwatch2.Start();
  7750. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  7751. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  7752. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  7753. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  7754. //// MES_Flag
  7755. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  7756. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7757. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  7758. writeToPLC_Flag.Adress = 2003;
  7759. writeToPLC_Flag.Value = mES_Flag;
  7760. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7761. {
  7762. Name = "a1CavitySN1_VehicleStates",
  7763. Adress = 2024,
  7764. ValueType = PLCValueType.String,
  7765. ValueTypeStrLength = 20,
  7766. Value = a1CavitySN1_VehicleStates
  7767. });
  7768. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  7769. {
  7770. Name = "a1CavitySN2_VehicleStates",
  7771. Adress = 2044,
  7772. ValueType = PLCValueType.String,
  7773. ValueTypeStrLength = 20,
  7774. Value = a1CavitySN2_VehicleStates
  7775. });
  7776. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  7777. {
  7778. Name = "a1CavityResult1_VehicleStates",
  7779. Adress = 2064,
  7780. ValueType = PLCValueType.Short,
  7781. Value = a1CavityResult1_VehicleStates
  7782. });
  7783. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  7784. {
  7785. Name = "a1CavityResult2_VehicleStates",
  7786. Adress = 2065,
  7787. ValueType = PLCValueType.Short,
  7788. Value = a1CavityResult2_VehicleStates
  7789. });
  7790. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  7791. stopwatch2.Stop();
  7792. }
  7793. catch (Exception ex)
  7794. {
  7795. string str = ex.StackTrace;
  7796. AddMessage_Station(stationNameStr, LogType.Error,
  7797. $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" +
  7798. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7799. // MES_Flag
  7800. stopwatch2.Start();
  7801. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7802. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7803. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  7804. writeToPLC_Flag.Adress = 2003;
  7805. writeToPLC_Flag.Value = (short)6;
  7806. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  7807. stopwatch2.Stop();
  7808. }
  7809. stopwatch1.Stop();
  7810. AddMessage(LogType.Info,
  7811. stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7812. stopwatch2.ElapsedMilliseconds + "ms");
  7813. }
  7814. /// <summary>
  7815. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  7816. /// </summary>
  7817. /// <param name="plcNo">PLC编号</param>
  7818. /// <param name="stationNameStr">工站全称</param>
  7819. private void S1上料进站校验(int plcNo, string stationNameStr)
  7820. {
  7821. Stopwatch stopwatch1 = new Stopwatch();
  7822. Stopwatch stopwatch2 = new Stopwatch();
  7823. try
  7824. {
  7825. stopwatch1.Start();
  7826. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  7827. sn = sn.Replace("\0", "");
  7828. // 保存进站数据+调用进站MES接口
  7829. List<TestItem> item = new List<TestItem>();
  7830. stopwatch2.Start();
  7831. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  7832. item, out string errorMsg);
  7833. stopwatch2.Stop();
  7834. short a1MES_FLAG_Check = (short)result;
  7835. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7836. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7837. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  7838. writeToPLC_Flag.Adress = 2077;
  7839. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  7840. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  7841. }
  7842. catch (Exception ex)
  7843. {
  7844. string str = ex.StackTrace;
  7845. AddMessage_Station(stationNameStr, LogType.Error,
  7846. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  7847. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7848. // MES_Flag
  7849. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7850. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7851. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  7852. writeToPLC_Flag.Adress = 2077;
  7853. writeToPLC_Flag.Value = (short)6;
  7854. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  7855. }
  7856. stopwatch1.Stop();
  7857. AddMessage(LogType.Info,
  7858. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  7859. stopwatch2.ElapsedMilliseconds + "ms");
  7860. }
  7861. /// <summary>
  7862. /// [S1] Tray盘上料装备(板测)- 出站接口
  7863. /// </summary>
  7864. /// <param name="plcNo"></param>
  7865. /// <param name="stationCode"></param>
  7866. /// <param name="stationName"></param>
  7867. private void S1出站接口(int plcNo, string stationCode, string stationName)
  7868. {
  7869. Stopwatch stopwatch1 = new Stopwatch();
  7870. Stopwatch stopwatch2 = new Stopwatch();
  7871. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7872. string stationNameStr = stationCode + stationName;
  7873. string processItem = stationName; // 测试项目
  7874. try
  7875. {
  7876. stopwatch1.Start();
  7877. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7878. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7879. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7880. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7881. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  7882. sn = sn.Replace("\0", "");
  7883. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  7884. partNo1 = partNo1.Replace("\0", "");
  7885. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  7886. partNo2 = partNo2.Replace("\0", "");
  7887. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  7888. bool pass = a1Result == 1;
  7889. stopwatch2.Start();
  7890. // 产品1
  7891. List<TestItem> items = new List<TestItem>();
  7892. items.Add(new TestItem()
  7893. {
  7894. Parameter_name = "载具码",
  7895. Parameter_value = sn,
  7896. Parameter_unit = ""
  7897. });
  7898. items.Add(new TestItem()
  7899. {
  7900. Parameter_name = "载具穴号",
  7901. Parameter_value = "1",
  7902. Parameter_unit = ""
  7903. });
  7904. items.Add(new TestItem()
  7905. {
  7906. Parameter_name = "产品结果",
  7907. Parameter_value = a1Result == 1 ? "OK" : "NG",
  7908. Parameter_unit = ""
  7909. });
  7910. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  7911. , workorder_code, mtltmrk, partNo1, pass, sn, "01-SLOT-01");
  7912. // 产品2
  7913. items = new List<TestItem>();
  7914. items.Add(new TestItem()
  7915. {
  7916. Parameter_name = "载具码",
  7917. Parameter_value = sn,
  7918. Parameter_unit = ""
  7919. });
  7920. items.Add(new TestItem()
  7921. {
  7922. Parameter_name = "载具穴号",
  7923. Parameter_value = "2",
  7924. Parameter_unit = ""
  7925. });
  7926. items.Add(new TestItem()
  7927. {
  7928. Parameter_name = "产品结果",
  7929. Parameter_value = a1Result == 1 ? "OK" : "NG",
  7930. Parameter_unit = ""
  7931. });
  7932. int result2 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  7933. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  7934. short result = 0;
  7935. List<int> results = new List<int>() { result1, result2 };
  7936. if (result1 == 1 && result2 == 1)
  7937. result = 1;
  7938. else if (results.Contains(3))
  7939. result = 3;
  7940. else if (results.Contains(2))
  7941. result = 2;
  7942. else if (results.Contains(4))
  7943. result = 4;
  7944. else
  7945. result = 4;
  7946. stopwatch2.Stop();
  7947. #region 存储绑定数据到 边线MES系统中
  7948. if (result == 1)
  7949. {
  7950. string data = string.Concat(partNo1, ".", partNo2);
  7951. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7952. if (resultMesR != 0)
  7953. {
  7954. result = 4;
  7955. AddMessage_Station(stationNameStr, LogType.Error,
  7956. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  7957. }
  7958. }
  7959. #endregion 存储绑定数据到 边线MES系统中
  7960. // MES_Flag 为MES报错
  7961. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7962. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  7963. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7964. writeToPLC_Flag.Name = "a1MES_FLAG";
  7965. writeToPLC_Flag.Adress = 2109;
  7966. writeToPLC_Flag.Value = result;
  7967. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  7968. OnMessage(LogType.Debug,
  7969. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7970. }
  7971. catch (Exception ex)
  7972. {
  7973. stopwatch2.Restart();
  7974. // MES_Flag 为4上位机报错
  7975. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  7976. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7977. writeToPLC_Flag.Name = "a1MES_FLAG";
  7978. writeToPLC_Flag.Adress = 2109;
  7979. writeToPLC_Flag.Value = (short)4;
  7980. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  7981. stopwatch2.Stop();
  7982. string str = ex.StackTrace;
  7983. AddMessage_Station(stationNameStr, LogType.Error,
  7984. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  7985. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7986. }
  7987. stopwatch1.Stop();
  7988. AddMessage(LogType.Info,
  7989. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  7990. stopwatch2.ElapsedMilliseconds + "ms");
  7991. }
  7992. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  7993. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  7994. //{
  7995. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7996. // string stationNameStr = stationCode + stationName;
  7997. // string processItem = stationName; // 测试项目
  7998. // try
  7999. // {
  8000. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8001. // string accno = "1"; // 工序编号
  8002. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  8003. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  8004. // List<OneCheckItem> items = new List<OneCheckItem>()
  8005. // {
  8006. // new OneCheckItem()
  8007. // {
  8008. // Onecheck_name="胶圈装配行程设定上限",
  8009. // Onecheck_content="上限值",
  8010. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  8011. // },
  8012. // };
  8013. // OneCheckData oneCheckData = new OneCheckData()
  8014. // {
  8015. // Line_code = GlobalContext.LineCode,
  8016. // Line_name = GlobalContext.LineName,
  8017. // Equipment_code = equipmentCode,
  8018. // Equipment_name = equipmentCode,
  8019. // Workorder_code = workorder_code,
  8020. // Procedure_code = accno,
  8021. // Procedure_name = processItem,
  8022. // Oneckeck_values = items,
  8023. // Onecheck_empcode = "",
  8024. // Onecheck_empname = "",
  8025. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  8026. // };
  8027. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  8028. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  8029. // short result = result1 == 1 ? (short)1 : (short)2;
  8030. // // MES_Flag 为4MES报错
  8031. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  8032. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8033. // }
  8034. // catch (Exception ex)
  8035. // {
  8036. // // MES_Flag 为2上位机报错
  8037. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  8038. // string str = ex.StackTrace;
  8039. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8040. // }
  8041. //}
  8042. // ReadStation_S1_2 节拍接口+AGV
  8043. /// <summary>
  8044. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  8045. /// </summary>
  8046. /// <param name="plcNo">PLC编号</param>
  8047. /// <param name="stationNameStr">工站全称</param>
  8048. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  8049. {
  8050. Stopwatch stopwatch1 = new Stopwatch();
  8051. Stopwatch stopwatch2 = new Stopwatch();
  8052. try
  8053. {
  8054. stopwatch1.Start();
  8055. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  8056. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  8057. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  8058. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  8059. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  8060. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  8061. // ZS 将SN发给ICT标机(串口)
  8062. short a1MES_FLAG_ICT = 1;
  8063. stopwatch2.Start();
  8064. // MES_Flag
  8065. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  8066. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8067. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  8068. writeToPLC_Flag.Adress = 2182;
  8069. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  8070. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  8071. stopwatch2.Stop();
  8072. }
  8073. catch (Exception ex)
  8074. {
  8075. string str = ex.StackTrace;
  8076. AddMessage_Station(stationNameStr, LogType.Error,
  8077. $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" +
  8078. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8079. stopwatch2.Start();
  8080. // MES_Flag
  8081. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  8082. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8083. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  8084. writeToPLC_Flag.Adress = 2182;
  8085. writeToPLC_Flag.Value = (short)4;
  8086. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  8087. stopwatch2.Stop();
  8088. }
  8089. stopwatch1.Stop();
  8090. AddMessage(LogType.Info,
  8091. stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8092. stopwatch2.ElapsedMilliseconds + "ms");
  8093. }
  8094. /// <summary>
  8095. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  8096. /// </summary>
  8097. /// <param name="plcNo">PLC编号</param>
  8098. /// <param name="stationNameStr">工站全称</param>
  8099. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  8100. {
  8101. Stopwatch stopwatch1 = new Stopwatch();
  8102. Stopwatch stopwatch2 = new Stopwatch();
  8103. try
  8104. {
  8105. stopwatch1.Start();
  8106. // ZS 呼叫AGV
  8107. short a1AGVUpCall = 2;
  8108. stopwatch2.Start();
  8109. // a1AGVUpCall
  8110. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  8111. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8112. writeToPLC_Flag.Name = "a1AGVUpCall";
  8113. writeToPLC_Flag.Adress = 2307;
  8114. writeToPLC_Flag.Value = a1AGVUpCall;
  8115. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  8116. stopwatch2.Stop();
  8117. }
  8118. catch (Exception ex)
  8119. {
  8120. string str = ex.StackTrace;
  8121. AddMessage_Station(stationNameStr, LogType.Error,
  8122. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  8123. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8124. // a1AGVUpCall
  8125. stopwatch2.Start();
  8126. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  8127. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8128. writeToPLC_Flag.Name = "a1AGVUpCall";
  8129. writeToPLC_Flag.Adress = 2307;
  8130. writeToPLC_Flag.Value = (short)4;
  8131. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  8132. stopwatch2.Stop();
  8133. }
  8134. stopwatch1.Stop();
  8135. AddMessage(LogType.Info,
  8136. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8137. stopwatch2.ElapsedMilliseconds + "ms");
  8138. }
  8139. /// <summary>
  8140. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  8141. /// </summary>
  8142. /// <param name="plcNo">PLC编号</param>
  8143. /// <param name="stationNameStr">工站全称</param>
  8144. private void S1AGV上料完成(int plcNo, string stationNameStr)
  8145. {
  8146. Stopwatch stopwatch1 = new Stopwatch();
  8147. Stopwatch stopwatch2 = new Stopwatch();
  8148. try
  8149. {
  8150. stopwatch1.Start();
  8151. // ZS AGV上料完成,让小车离开
  8152. short a1AGVUpEnd = 2;
  8153. stopwatch2.Start();
  8154. // a1AGVUpEnd
  8155. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  8156. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8157. writeToPLC_Flag.Name = "a1AGVUpEnd";
  8158. writeToPLC_Flag.Adress = 2309;
  8159. writeToPLC_Flag.Value = a1AGVUpEnd;
  8160. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  8161. stopwatch2.Stop();
  8162. }
  8163. catch (Exception ex)
  8164. {
  8165. string str = ex.StackTrace;
  8166. AddMessage_Station(stationNameStr, LogType.Error,
  8167. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  8168. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8169. // a1AGVUpEnd
  8170. stopwatch2.Start();
  8171. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  8172. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8173. writeToPLC_Flag.Name = "a1AGVUpEnd";
  8174. writeToPLC_Flag.Adress = 2309;
  8175. writeToPLC_Flag.Value = (short)4;
  8176. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  8177. stopwatch2.Stop();
  8178. }
  8179. stopwatch1.Stop();
  8180. AddMessage(LogType.Info,
  8181. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8182. stopwatch2.ElapsedMilliseconds + "ms");
  8183. }
  8184. /// <summary>
  8185. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  8186. /// </summary>
  8187. /// <param name="plcNo">PLC编号</param>
  8188. /// <param name="stationNameStr">工站全称</param>
  8189. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  8190. {
  8191. Stopwatch stopwatch1 = new Stopwatch();
  8192. Stopwatch stopwatch2 = new Stopwatch();
  8193. try
  8194. {
  8195. stopwatch1.Start();
  8196. // ZS 呼叫AGV
  8197. short a1AGVDownCall = 2;
  8198. stopwatch2.Start();
  8199. // a1AGVDownCall
  8200. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  8201. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8202. writeToPLC_Flag.Name = "a1AGVDownCall";
  8203. writeToPLC_Flag.Adress = 2320;
  8204. writeToPLC_Flag.Value = a1AGVDownCall;
  8205. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  8206. stopwatch2.Stop();
  8207. }
  8208. catch (Exception ex)
  8209. {
  8210. string str = ex.StackTrace;
  8211. AddMessage_Station(stationNameStr, LogType.Error,
  8212. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  8213. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8214. // a1AGVDownCall
  8215. stopwatch2.Start();
  8216. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  8217. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8218. writeToPLC_Flag.Name = "a1AGVDownCall";
  8219. writeToPLC_Flag.Adress = 2320;
  8220. writeToPLC_Flag.Value = (short)4;
  8221. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  8222. stopwatch2.Stop();
  8223. }
  8224. stopwatch1.Stop();
  8225. AddMessage(LogType.Info,
  8226. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8227. stopwatch2.ElapsedMilliseconds + "ms");
  8228. }
  8229. /// <summary>
  8230. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  8231. /// </summary>
  8232. /// <param name="plcNo">PLC编号</param>
  8233. /// <param name="stationNameStr">工站全称</param>
  8234. private void S1AGV下料完成(int plcNo, string stationNameStr)
  8235. {
  8236. Stopwatch stopwatch1 = new Stopwatch();
  8237. Stopwatch stopwatch2 = new Stopwatch();
  8238. try
  8239. {
  8240. stopwatch1.Start();
  8241. // ZS AGV上料完成,让小车离开
  8242. short a1AGVDownEnd = 2;
  8243. stopwatch2.Start();
  8244. // a1AGVDownEnd
  8245. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  8246. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8247. writeToPLC_Flag.Name = "a1AGVDownEnd";
  8248. writeToPLC_Flag.Adress = 2322;
  8249. writeToPLC_Flag.Value = a1AGVDownEnd;
  8250. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  8251. stopwatch2.Stop();
  8252. }
  8253. catch (Exception ex)
  8254. {
  8255. string str = ex.StackTrace;
  8256. AddMessage_Station(stationNameStr, LogType.Error,
  8257. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  8258. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8259. // a1AGVDownEnd
  8260. stopwatch2.Start();
  8261. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  8262. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8263. writeToPLC_Flag.Name = "a1AGVDownEnd";
  8264. writeToPLC_Flag.Adress = 2322;
  8265. writeToPLC_Flag.Value = (short)4;
  8266. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  8267. stopwatch2.Stop();
  8268. }
  8269. stopwatch1.Stop();
  8270. AddMessage(LogType.Info,
  8271. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8272. stopwatch2.ElapsedMilliseconds + "ms");
  8273. }
  8274. #endregion [S1] Tray盘上料装备(板测)
  8275. #endregion PLC1 张超凡
  8276. #region PLC2 李晓奇
  8277. #region [S2] FCT(板测)
  8278. /// <summary>
  8279. /// S2工位的数据- 触发信号上次的值
  8280. /// </summary>
  8281. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  8282. /// <summary>
  8283. /// S2工位的数据(含触发信号)
  8284. /// </summary>
  8285. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  8286. /// <summary>
  8287. /// S2工位的数据- 回写点位
  8288. /// </summary>
  8289. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8290. /// <summary>
  8291. /// [S2] FCT(板测)
  8292. /// </summary>
  8293. /// <param name="plcNo">PLC编号</param>
  8294. //private void ReadStation_S2(int plcNo)
  8295. //{
  8296. // // [S1] Tray盘上料装备
  8297. // // [S2] FCT
  8298. // // [S3] 值板机
  8299. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8300. // // [S5] Tray盘下料装备
  8301. // /// 上位机心跳
  8302. // /// 获取设备报警数据与状态信息
  8303. // string stationCode = "[S2]";
  8304. // string stationName = "FCT";
  8305. // string stationNameStr = stationCode + stationName;
  8306. // #region 创建字典
  8307. // // 触发信号字典 赋值
  8308. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8309. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  8310. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8311. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8312. // // PLC数据字典 赋值
  8313. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  8314. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  8315. // s2PLCData.Add("b1ProductSN_Check", 0);
  8316. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  8317. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  8318. // s2PLCData.Add("b1ProductSN_Unbind", "");
  8319. // s2PLCData.Add("b1ProductSN_Bind", "");
  8320. // s2PLCData.Add("b1Part1SN_Bind", "");
  8321. // s2PLCData.Add("b1Part2SN_Bind", "");
  8322. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  8323. // s2PLCData.Add("b1MES_FLAG", 0);
  8324. // s2PLCData.Add("b1ProductSN", 0);
  8325. // s2PLCData.Add("b1Part1Result", 0);
  8326. // s2PLCData.Add("b1Part2Result", 0);
  8327. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  8328. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  8329. // s2PLCData.Add("b1OEEProductSN", "");
  8330. // s2PLCData.Add("b1OEEType", 0);
  8331. // #endregion 创建字典
  8332. // while (IsRun)
  8333. // {
  8334. // try
  8335. // {
  8336. // if (!GlobalContext._IsCon_Funs2)
  8337. // {
  8338. // UpdatePLCMonitor(1, plcNo, 0);
  8339. // continue;
  8340. // }
  8341. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8342. // {
  8343. // Stopwatch stopwatch1 = new Stopwatch();
  8344. // Stopwatch stopwatch2 = new Stopwatch();
  8345. // stopwatch1.Start();
  8346. // stopwatch2.Start();
  8347. // #region 一次性读取所有数据
  8348. // // 一次性读取所有数据
  8349. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  8350. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  8351. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  8352. // int[] datas = data1.Concat(data2).ToArray();
  8353. // datas = datas.Concat(data3).ToArray();
  8354. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  8355. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  8356. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8357. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  8358. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  8359. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  8360. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  8361. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  8362. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  8363. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  8364. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  8365. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  8366. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  8367. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  8368. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  8369. // s2PLCData["b1MES_FLAG"] = datas[169];
  8370. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  8371. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  8372. // s2PLCData["b1Part1Result"] = datas[190];
  8373. // s2PLCData["b1Part2Result"] = datas[191];
  8374. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  8375. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  8376. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  8377. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  8378. // s2PLCData["b1OEEType"] = datas[224];
  8379. // #endregion 一次性读取所有数据
  8380. // stopwatch2.Stop();
  8381. // #region 回写操作,写后清空flag
  8382. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  8383. // #endregion 回写操作,写后清空flag
  8384. // #region 进站校验
  8385. // try
  8386. // {
  8387. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  8388. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  8389. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  8390. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  8391. // {
  8392. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  8393. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8394. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  8395. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8396. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  8397. // }
  8398. // }
  8399. // catch (Exception ex)
  8400. // {
  8401. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8402. // string str = ex.StackTrace;
  8403. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8404. // }
  8405. // #endregion 进站校验
  8406. // #region 二穴载具解绑/绑定(产品换载具)
  8407. // try
  8408. // {
  8409. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  8410. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  8411. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  8412. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  8413. // {
  8414. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  8415. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  8416. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  8417. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  8418. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  8419. // }
  8420. // }
  8421. // catch (Exception ex)
  8422. // {
  8423. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  8424. // string str = ex.StackTrace;
  8425. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8426. // }
  8427. // #endregion 二穴载具解绑/绑定(产品换载具)
  8428. // #region FCT-出站接口
  8429. // try
  8430. // {
  8431. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  8432. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  8433. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  8434. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  8435. // {
  8436. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  8437. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8438. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  8439. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  8440. // }
  8441. // }
  8442. // catch (Exception ex)
  8443. // {
  8444. // // MES_Flag 为6上位机报错
  8445. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  8446. // string str = ex.StackTrace;
  8447. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8448. // }
  8449. // #endregion FCT-出站接口
  8450. // #region 节拍接口
  8451. // try
  8452. // {
  8453. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  8454. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  8455. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  8456. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  8457. // {
  8458. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  8459. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8460. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  8461. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  8462. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  8463. // }
  8464. // }
  8465. // catch (Exception ex)
  8466. // {
  8467. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  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. // #region 心跳
  8473. // try
  8474. // {
  8475. // short states = 0;
  8476. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  8477. // }
  8478. // catch (Exception ex)
  8479. // {
  8480. // string str = ex.StackTrace;
  8481. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8482. // }
  8483. // #endregion 心跳
  8484. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  8485. // stopwatch1.Stop();
  8486. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  8487. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  8488. // }
  8489. // else
  8490. // {
  8491. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8492. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  8493. // Funs[plcNo].Connect();
  8494. // }
  8495. // }
  8496. // catch (Exception ex)
  8497. // {
  8498. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8499. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  8500. // Funs[plcNo].ReConnect();
  8501. // }
  8502. // Thread.Sleep(IntervalReadPLC);
  8503. // }
  8504. //}
  8505. /// <summary>
  8506. /// [S2] FCT(板测)- 进站校验
  8507. /// </summary>
  8508. /// <param name="plcNo">PLC编号</param>
  8509. /// <param name="stationNameStr">工站全称</param>
  8510. private void S2进站校验(int plcNo, string stationNameStr)
  8511. {
  8512. Stopwatch stopwatch1 = new Stopwatch();
  8513. Stopwatch stopwatch2 = new Stopwatch();
  8514. try
  8515. {
  8516. stopwatch1.Start();
  8517. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  8518. sn = sn.Replace("\0", "");
  8519. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  8520. // 查询物料码By载具码 并判断是不是假产品
  8521. string cavityData = string.Empty;
  8522. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  8523. if (string.IsNullOrEmpty(cavityData))
  8524. cavityData = "";
  8525. if (snResult != 0)
  8526. {
  8527. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8528. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  8529. writeToPLC_Flag1.Adress = 2003;
  8530. writeToPLC_Flag1.Value = (short)6;
  8531. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  8532. stopwatch1.Stop();
  8533. AddMessage(LogType.Info,
  8534. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8535. return;
  8536. }
  8537. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  8538. string[] cavitySNs = cavityData.Split('.');
  8539. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  8540. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  8541. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  8542. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  8543. if (cavitySNs != null && cavitySNs.Length >= 2)
  8544. {
  8545. b1Part1SN_Check = cavitySNs[0];
  8546. b1Part2SN_Check = cavitySNs[1];
  8547. b1Part1Result_Check = 2;
  8548. b1Part2Result_Check = 2;
  8549. }
  8550. if (b1Part1SN_Check == "假产品")
  8551. b1Part1Result_Check = 3;
  8552. if (b1Part2SN_Check == "假产品")
  8553. b1Part2Result_Check = 3;
  8554. // 调用MES进站
  8555. stopwatch2.Start();
  8556. // 调用MES进站 - 产品1
  8557. List<TestItem> item;
  8558. int result1 = b1Part1Result_Check;
  8559. if (result1 != 3)
  8560. {
  8561. item = new List<TestItem>();
  8562. item.Add(new TestItem()
  8563. {
  8564. Parameter_name = "载具码",
  8565. Parameter_value = sn,
  8566. });
  8567. item.Add(new TestItem()
  8568. {
  8569. Parameter_name = "载具穴号",
  8570. Parameter_value = "1",
  8571. });
  8572. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8573. b1Part1SN_Check, item, out string errorMsg);
  8574. }
  8575. // 调用MES进站 - 产品2
  8576. int result2 = b1Part2Result_Check;
  8577. if (result2 != 3)
  8578. {
  8579. item = new List<TestItem>();
  8580. item.Add(new TestItem()
  8581. {
  8582. Parameter_name = "载具码",
  8583. Parameter_value = sn,
  8584. });
  8585. item.Add(new TestItem()
  8586. {
  8587. Parameter_name = "载具穴号",
  8588. Parameter_value = "2",
  8589. });
  8590. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8591. b1Part2SN_Check, item, out string errorMsg);
  8592. }
  8593. stopwatch2.Stop();
  8594. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  8595. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  8596. int result = result1;
  8597. if (result == 1)
  8598. result = result2;
  8599. short b1MES_FLAG_Check = (short)result;
  8600. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  8601. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  8602. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  8603. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  8604. //// MES_Flag
  8605. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8606. WriteToPLC_Flag
  8607. writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8608. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  8609. writeToPLC_Flag.Adress = 2003;
  8610. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  8611. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8612. {
  8613. Name = "b1Part1SN_Check",
  8614. Adress = 2024,
  8615. ValueType = PLCValueType.String,
  8616. ValueTypeStrLength = 20,
  8617. Value = b1Part1SN_Check
  8618. });
  8619. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8620. {
  8621. Name = "b1Part2SN_Check",
  8622. Adress = 2044,
  8623. ValueType = PLCValueType.String,
  8624. ValueTypeStrLength = 20,
  8625. Value = b1Part2SN_Check
  8626. });
  8627. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8628. {
  8629. Name = "b1Part1Result_Check",
  8630. Adress = 2064,
  8631. ValueType = PLCValueType.Short,
  8632. Value = b1Part1Result_Check
  8633. });
  8634. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8635. {
  8636. Name = "b1Part2Result_Check",
  8637. Adress = 2065,
  8638. ValueType = PLCValueType.Short,
  8639. Value = b1Part2Result_Check
  8640. });
  8641. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  8642. }
  8643. catch (Exception ex)
  8644. {
  8645. string str = ex.StackTrace;
  8646. AddMessage_Station(stationNameStr, LogType.Error,
  8647. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  8648. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8649. // MES_Flag
  8650. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8651. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8652. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  8653. writeToPLC_Flag.Adress = 2003;
  8654. writeToPLC_Flag.Value = (short)6;
  8655. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  8656. }
  8657. stopwatch1.Stop();
  8658. AddMessage(LogType.Info,
  8659. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  8660. stopwatch2.ElapsedMilliseconds + "ms");
  8661. }
  8662. /// <summary>
  8663. /// [S2] FCT(板测)- 二穴载具解绑绑定
  8664. /// </summary>
  8665. /// <param name="plcNo">PLC编号</param>
  8666. /// <param name="stationNameStr">工站全称</param>
  8667. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  8668. {
  8669. Stopwatch stopwatch1 = new Stopwatch();
  8670. Stopwatch stopwatch2 = new Stopwatch();
  8671. try
  8672. {
  8673. stopwatch1.Start();
  8674. // 产品换载具
  8675. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  8676. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  8677. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  8678. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  8679. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  8680. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  8681. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  8682. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  8683. stopwatch2.Start();
  8684. #region 查询载具上的产品信息
  8685. //string cavityData = string.Empty;
  8686. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  8687. //if (string.IsNullOrEmpty(cavityData))
  8688. // cavityData = "";
  8689. //if (snResult != 0)
  8690. //{
  8691. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8692. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  8693. // writeToPLC_Flag.Adress = 2077;
  8694. // writeToPLC_Flag.Value = (short)6;
  8695. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  8696. // stopwatch1.Stop();
  8697. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8698. // return;
  8699. //}
  8700. #endregion 查询载具上的产品信息
  8701. #region 解绑(边线MES系统)
  8702. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  8703. if (snResult != 0)
  8704. {
  8705. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8706. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  8707. writeToPLC_Flag1.Adress = 2077;
  8708. writeToPLC_Flag1.Value = (short)6;
  8709. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  8710. stopwatch1.Stop();
  8711. AddMessage(LogType.Info,
  8712. stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" +
  8713. stopwatch1.ElapsedMilliseconds + "ms");
  8714. return;
  8715. }
  8716. #endregion 解绑(边线MES系统)
  8717. #region 存储绑定数据到 边线MES系统中
  8718. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  8719. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  8720. if (snResult != 0)
  8721. {
  8722. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8723. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  8724. writeToPLC_Flag1.Adress = 2077;
  8725. writeToPLC_Flag1.Value = (short)6;
  8726. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  8727. stopwatch1.Stop();
  8728. AddMessage(LogType.Info,
  8729. stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" +
  8730. stopwatch1.ElapsedMilliseconds + "ms");
  8731. return;
  8732. }
  8733. #endregion 存储绑定数据到 边线MES系统中
  8734. stopwatch2.Stop();
  8735. short b1MES_FLAG_Unbind = 1;
  8736. // MES_Flag
  8737. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8738. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8739. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  8740. writeToPLC_Flag.Adress = 2077;
  8741. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  8742. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  8743. }
  8744. catch (Exception ex)
  8745. {
  8746. string str = ex.StackTrace;
  8747. AddMessage_Station(stationNameStr, LogType.Error,
  8748. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" +
  8749. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8750. // MES_Flag
  8751. stopwatch2.Start();
  8752. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  8753. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8754. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  8755. writeToPLC_Flag.Adress = 2077;
  8756. writeToPLC_Flag.Value = (short)6;
  8757. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  8758. stopwatch2.Stop();
  8759. }
  8760. stopwatch1.Stop();
  8761. AddMessage(LogType.Info,
  8762. stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8763. stopwatch2.ElapsedMilliseconds + "ms");
  8764. }
  8765. //// 上次采集到的SN
  8766. //private string sn_FCT = string.Empty;
  8767. /// <summary>
  8768. /// [S2] FCT(板测)- 出站数据
  8769. /// </summary>
  8770. private void S2出站接口(int plcNo, string stationCode, string stationName)
  8771. {
  8772. Stopwatch stopwatch1 = new Stopwatch();
  8773. Stopwatch stopwatch2 = new Stopwatch();
  8774. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8775. string stationNameStr = stationCode + stationName;
  8776. string processItem = stationName; // 测试项目
  8777. try
  8778. {
  8779. stopwatch1.Start();
  8780. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8781. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8782. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8783. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8784. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  8785. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  8786. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  8787. bool pass1 = b1Part1Result == 1;
  8788. bool pass2 = b1Part2Result == 1;
  8789. #region 根据 载具SN 查 物料SN
  8790. string cavityData = string.Empty;
  8791. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  8792. if (string.IsNullOrEmpty(cavityData))
  8793. cavityData = "";
  8794. if (snResult != 0)
  8795. {
  8796. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8797. writeToPLC_Flag1.Name = "b1MES_FLAG";
  8798. writeToPLC_Flag1.Adress = 2169;
  8799. writeToPLC_Flag1.Value = (short)4;
  8800. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  8801. stopwatch1.Stop();
  8802. AddMessage(LogType.Info,
  8803. stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8804. "ms");
  8805. return;
  8806. }
  8807. #endregion 根据 载具SN 查 物料SN
  8808. string[] cavitySNs = cavityData.Split('.');
  8809. string b1ProductSN1 = string.Empty;
  8810. string b1ProductSN2 = string.Empty;
  8811. if (cavitySNs != null && cavitySNs.Length >= 2)
  8812. {
  8813. b1ProductSN1 = cavitySNs[0];
  8814. b1ProductSN2 = cavitySNs[1];
  8815. }
  8816. stopwatch2.Start();
  8817. // 产品1
  8818. int result1 = 0;
  8819. if (b1ProductSN1 == "假产品")
  8820. result1 = 1;
  8821. else
  8822. {
  8823. List<TestItem> items1 = new List<TestItem>();
  8824. items1.Add(new TestItem()
  8825. {
  8826. Parameter_name = "载具码",
  8827. Parameter_value = b1ProductSN.ToString(),
  8828. Parameter_unit = ""
  8829. });
  8830. items1.Add(new TestItem()
  8831. {
  8832. Parameter_name = "载具穴号",
  8833. Parameter_value = "1",
  8834. Parameter_unit = ""
  8835. });
  8836. items1.Add(new TestItem()
  8837. {
  8838. Parameter_name = "产品结果",
  8839. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  8840. Parameter_unit = ""
  8841. });
  8842. result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  8843. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  8844. }
  8845. // 产品2
  8846. int result2 = 0;
  8847. if (b1ProductSN1 == "假产品")
  8848. result2 = 1;
  8849. else
  8850. {
  8851. List<TestItem> items2 = new List<TestItem>();
  8852. items2.Add(new TestItem()
  8853. {
  8854. Parameter_name = "载具码",
  8855. Parameter_value = b1ProductSN.ToString(),
  8856. Parameter_unit = ""
  8857. });
  8858. items2.Add(new TestItem()
  8859. {
  8860. Parameter_name = "载具穴号",
  8861. Parameter_value = "2",
  8862. Parameter_unit = ""
  8863. });
  8864. items2.Add(new TestItem()
  8865. {
  8866. Parameter_name = "产品结果",
  8867. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  8868. Parameter_unit = ""
  8869. });
  8870. result2 = SwitctProcessData_old(stationNameStr, items2, equipmentCode, processItem
  8871. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  8872. }
  8873. short result = 0;
  8874. List<int> results = new List<int>() { result1, result2 };
  8875. if (result1 == 1 && result2 == 1)
  8876. result = 1;
  8877. else if (results.Contains(3))
  8878. result = 3;
  8879. else if (results.Contains(2))
  8880. result = 2;
  8881. else if (results.Contains(4))
  8882. result = 4;
  8883. else
  8884. result = 4;
  8885. stopwatch2.Stop();
  8886. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8887. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8888. writeToPLC_Flag.Name = "b1MES_FLAG";
  8889. writeToPLC_Flag.Adress = 2169;
  8890. writeToPLC_Flag.Value = result;
  8891. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  8892. OnMessage(LogType.Debug,
  8893. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8894. }
  8895. catch (Exception ex)
  8896. {
  8897. stopwatch2.Restart();
  8898. // MES_Flag 为4上位机报错
  8899. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  8900. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8901. writeToPLC_Flag.Name = "b1MES_FLAG";
  8902. writeToPLC_Flag.Adress = 2169;
  8903. writeToPLC_Flag.Value = (short)4;
  8904. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  8905. stopwatch2.Stop();
  8906. string str = ex.StackTrace;
  8907. AddMessage_Station(stationNameStr, LogType.Error,
  8908. $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  8909. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8910. }
  8911. stopwatch1.Stop();
  8912. AddMessage(LogType.Info,
  8913. stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  8914. stopwatch2.ElapsedMilliseconds + "ms");
  8915. }
  8916. #endregion [S2] FCT(板测)
  8917. #endregion PLC2 李晓奇
  8918. #region PLC3 刘永村
  8919. #region [S3] 值板机
  8920. /// <summary>
  8921. /// S3工位的数据- 触发信号上次的值
  8922. /// </summary>
  8923. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  8924. /// <summary>
  8925. /// S3工位的数据(含触发信号)
  8926. /// </summary>
  8927. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  8928. /// <summary>
  8929. /// S3工位的数据- 回写点位
  8930. /// </summary>
  8931. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8932. /// <summary>
  8933. /// [S3] 值板机
  8934. /// </summary>
  8935. /// <param name="plcNo">PLC编号</param>
  8936. //private void ReadStation_S3(int plcNo)
  8937. //{
  8938. // // [S1] Tray盘上料装备
  8939. // // [S2] FCT
  8940. // // [S3] 值板机
  8941. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8942. // // [S5] Tray盘下料装备
  8943. // /// 上位机心跳
  8944. // /// 获取设备报警数据与状态信息
  8945. // string stationCode = "[S3]";
  8946. // string stationName = "值板机";
  8947. // string stationNameStr = stationCode + stationName;
  8948. // #region 创建字典
  8949. // // 触发信号字典 赋值
  8950. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8951. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  8952. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  8953. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8954. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8955. // // PLC数据字典 赋值
  8956. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8957. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  8958. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8959. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  8960. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  8961. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8962. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8963. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  8964. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  8965. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8966. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  8967. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  8968. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8969. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8970. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  8971. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  8972. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  8973. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8974. // s3PLCData.Add("c1Result", 0); // 产品结果
  8975. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8976. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  8977. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  8978. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  8979. // #endregion 创建字典
  8980. // while (IsRun)
  8981. // {
  8982. // try
  8983. // {
  8984. // if (!GlobalContext._IsCon_Funs3)
  8985. // {
  8986. // UpdatePLCMonitor(1, plcNo, 0);
  8987. // continue;
  8988. // }
  8989. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8990. // {
  8991. // Stopwatch stopwatch1 = new Stopwatch();
  8992. // Stopwatch stopwatch2 = new Stopwatch();
  8993. // stopwatch1.Start();
  8994. // stopwatch2.Start();
  8995. // #region 一次性读取所有数据
  8996. // // 一次性读取所有数据
  8997. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  8998. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8999. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  9000. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  9001. // int[] datas = data1.Concat(data2).ToArray();
  9002. // datas = datas.Concat(data3).ToArray();
  9003. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  9004. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  9005. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  9006. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  9007. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  9008. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  9009. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  9010. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  9011. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  9012. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  9013. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  9014. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  9015. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  9016. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  9017. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  9018. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  9019. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  9020. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  9021. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  9022. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  9023. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  9024. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  9025. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  9026. // #endregion 一次性读取所有数据
  9027. // stopwatch2.Stop();
  9028. // #region 回写操作,写后清空flag
  9029. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  9030. // #endregion 回写操作,写后清空flag
  9031. // #region S3进站校验
  9032. // try
  9033. // {
  9034. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  9035. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  9036. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  9037. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  9038. // {
  9039. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  9040. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  9041. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  9042. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  9043. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  9044. // }
  9045. // }
  9046. // catch (Exception ex)
  9047. // {
  9048. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9049. // string str = ex.StackTrace;
  9050. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9051. // }
  9052. // #endregion S3进站校验
  9053. // #region S3二穴载具解绑
  9054. // try
  9055. // {
  9056. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  9057. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  9058. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  9059. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  9060. // {
  9061. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  9062. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  9063. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  9064. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  9065. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  9066. // }
  9067. // }
  9068. // catch (Exception ex)
  9069. // {
  9070. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  9071. // string str = ex.StackTrace;
  9072. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9073. // }
  9074. // #endregion S3二穴载具解绑
  9075. // #region S3二穴载具绑定
  9076. // try
  9077. // {
  9078. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  9079. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  9080. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  9081. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  9082. // {
  9083. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  9084. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  9085. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  9086. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  9087. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  9088. // }
  9089. // }
  9090. // catch (Exception ex)
  9091. // {
  9092. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  9093. // string str = ex.StackTrace;
  9094. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9095. // }
  9096. // #endregion S3二穴载具绑定
  9097. // #region S3出站接口(+一穴载具绑定)
  9098. // try
  9099. // {
  9100. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  9101. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  9102. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  9103. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  9104. // {
  9105. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  9106. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  9107. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  9108. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  9109. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  9110. // }
  9111. // }
  9112. // catch (Exception ex)
  9113. // {
  9114. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  9115. // string str = ex.StackTrace;
  9116. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9117. // }
  9118. // #endregion S3出站接口(+一穴载具绑定)
  9119. // #region S3节拍接口
  9120. // try
  9121. // {
  9122. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  9123. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  9124. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  9125. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  9126. // {
  9127. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  9128. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  9129. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  9130. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  9131. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  9132. // }
  9133. // }
  9134. // catch (Exception ex)
  9135. // {
  9136. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  9137. // string str = ex.StackTrace;
  9138. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9139. // }
  9140. // #endregion S3节拍接口
  9141. // #region 心跳
  9142. // try
  9143. // {
  9144. // short states = 0;
  9145. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  9146. // }
  9147. // catch (Exception ex)
  9148. // {
  9149. // string str = ex.StackTrace;
  9150. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9151. // }
  9152. // #endregion 心跳
  9153. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  9154. // stopwatch1.Stop();
  9155. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  9156. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  9157. // }
  9158. // else
  9159. // {
  9160. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9161. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  9162. // Funs[plcNo].Connect();
  9163. // }
  9164. // }
  9165. // catch (Exception ex)
  9166. // {
  9167. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9168. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  9169. // Funs[plcNo].ReConnect();
  9170. // }
  9171. // Thread.Sleep(IntervalReadPLC);
  9172. // }
  9173. //}
  9174. /// <summary>
  9175. /// [S3] 值板机- 进站校验
  9176. /// </summary>
  9177. /// <param name="plcNo">PLC编号</param>
  9178. /// <param name="stationNameStr">工站全称</param>
  9179. private void S3进站校验(int plcNo, string stationNameStr)
  9180. {
  9181. Stopwatch stopwatch1 = new Stopwatch();
  9182. Stopwatch stopwatch2 = new Stopwatch();
  9183. try
  9184. {
  9185. stopwatch1.Start();
  9186. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  9187. sn = sn.Replace("\0", "");
  9188. #region 查询载具上的产品信息
  9189. string cavityData = string.Empty;
  9190. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9191. if (string.IsNullOrEmpty(cavityData))
  9192. cavityData = "";
  9193. if (snResult != 0)
  9194. {
  9195. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9196. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  9197. writeToPLC_Flag1.Adress = 2003;
  9198. writeToPLC_Flag1.Value = (short)6;
  9199. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  9200. stopwatch1.Stop();
  9201. AddMessage(LogType.Info,
  9202. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9203. return;
  9204. }
  9205. #endregion 查询载具上的产品信息
  9206. string[] cavitySNs = cavityData.Split('.');
  9207. string part1Str = ""; // 产品1的SN码
  9208. string part2Str = ""; // 产品2的SN码
  9209. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  9210. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  9211. if (cavitySNs != null && cavitySNs.Length >= 2)
  9212. {
  9213. part1Str = cavitySNs[0];
  9214. part2Str = cavitySNs[1];
  9215. c1Part1Result_Check = 2;
  9216. c1Part2Result_Check = 2;
  9217. }
  9218. if (part1Str == "假产品")
  9219. c1Part1Result_Check = 3;
  9220. if (part2Str == "假产品")
  9221. c1Part2Result_Check = 3;
  9222. // 调用MES进站
  9223. stopwatch2.Start();
  9224. // 调用MES进站 - 产品1
  9225. List<TestItem> item;
  9226. int result1 = c1Part1Result_Check;
  9227. if (result1 != 3)
  9228. {
  9229. item = new List<TestItem>();
  9230. item.Add(new TestItem()
  9231. {
  9232. Parameter_name = "载具码",
  9233. Parameter_value = sn,
  9234. });
  9235. item.Add(new TestItem()
  9236. {
  9237. Parameter_name = "载具穴号",
  9238. Parameter_value = "1",
  9239. });
  9240. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  9241. part1Str, item, out string errorMsg);
  9242. }
  9243. // 调用MES进站 - 产品2
  9244. int result2 = c1Part2Result_Check;
  9245. if (result2 != 3)
  9246. {
  9247. item = new List<TestItem>();
  9248. item.Add(new TestItem()
  9249. {
  9250. Parameter_name = "载具码",
  9251. Parameter_value = sn,
  9252. });
  9253. item.Add(new TestItem()
  9254. {
  9255. Parameter_name = "载具穴号",
  9256. Parameter_value = "2",
  9257. });
  9258. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  9259. part2Str, item, out string errorMsg);
  9260. }
  9261. stopwatch2.Stop();
  9262. if (result1 == 2)
  9263. c1Part1Result_Check = 2;
  9264. if (result2 == 2)
  9265. c1Part2Result_Check = 2;
  9266. int result = result1;
  9267. if (result == 1)
  9268. result = result2;
  9269. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  9270. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  9271. short c1MES_FLAG_Check = (short)result;
  9272. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  9273. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  9274. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  9275. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  9276. //// MES_Flag
  9277. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9278. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9279. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  9280. writeToPLC_Flag.Adress = 2003;
  9281. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  9282. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9283. {
  9284. Name = "c1Part1Result_Check",
  9285. Adress = 2024,
  9286. ValueType = PLCValueType.Short,
  9287. Value = c1Part1Result_Check
  9288. });
  9289. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9290. {
  9291. Name = "c1Part2Result_Check",
  9292. Adress = 2025,
  9293. ValueType = PLCValueType.Short,
  9294. Value = c1Part2Result_Check
  9295. });
  9296. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9297. {
  9298. Name = "c1Part1Num_Check",
  9299. Adress = 2026,
  9300. ValueType = PLCValueType.Short,
  9301. Value = c1Part1Num_Check
  9302. });
  9303. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9304. {
  9305. Name = "c1Part2Num_Check",
  9306. Adress = 2027,
  9307. ValueType = PLCValueType.Short,
  9308. Value = c1Part2Num_Check
  9309. });
  9310. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  9311. }
  9312. catch (Exception ex)
  9313. {
  9314. string str = ex.StackTrace;
  9315. AddMessage_Station(stationNameStr, LogType.Error,
  9316. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  9317. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9318. // MES_Flag
  9319. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9320. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9321. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  9322. writeToPLC_Flag.Adress = 2003;
  9323. writeToPLC_Flag.Value = (short)6;
  9324. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  9325. }
  9326. stopwatch1.Stop();
  9327. AddMessage(LogType.Info,
  9328. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  9329. stopwatch2.ElapsedMilliseconds + "ms");
  9330. }
  9331. /// <summary>
  9332. /// [S3] 值板机 - 二穴载具解绑
  9333. /// </summary>
  9334. /// <param name="plcNo">PLC编号</param>
  9335. /// <param name="stationNameStr">工站全称</param>
  9336. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  9337. {
  9338. Stopwatch stopwatch1 = new Stopwatch();
  9339. Stopwatch stopwatch2 = new Stopwatch();
  9340. try
  9341. {
  9342. stopwatch1.Start();
  9343. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  9344. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  9345. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  9346. // 解绑
  9347. #region 查询载具上的产品信息
  9348. string cavityData = string.Empty;
  9349. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  9350. if (string.IsNullOrEmpty(cavityData))
  9351. cavityData = "";
  9352. if (snResult != 0)
  9353. {
  9354. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9355. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  9356. writeToPLC_Flag1.Adress = 2082;
  9357. writeToPLC_Flag1.Value = (short)6;
  9358. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  9359. stopwatch1.Stop();
  9360. AddMessage(LogType.Info,
  9361. stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9362. "ms");
  9363. return;
  9364. }
  9365. #endregion 查询载具上的产品信息
  9366. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  9367. #region 解绑
  9368. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  9369. {
  9370. // 删除
  9371. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  9372. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  9373. }
  9374. else
  9375. {
  9376. string data_new = string.Join(".", cavitySNs);
  9377. // 删除再插入
  9378. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  9379. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  9380. OnMessage(LogType.Debug,
  9381. $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  9382. }
  9383. #endregion 解绑
  9384. short c1MES_FLAG_Unbind = 1;
  9385. stopwatch2.Start();
  9386. // MES_Flag
  9387. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9388. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9389. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  9390. writeToPLC_Flag.Adress = 2082;
  9391. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  9392. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  9393. stopwatch2.Stop();
  9394. }
  9395. catch (Exception ex)
  9396. {
  9397. string str = ex.StackTrace;
  9398. AddMessage_Station(stationNameStr, LogType.Error,
  9399. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" +
  9400. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9401. // MES_Flag
  9402. stopwatch2.Start();
  9403. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  9404. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9405. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  9406. writeToPLC_Flag.Adress = 2082;
  9407. writeToPLC_Flag.Value = (short)6;
  9408. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  9409. stopwatch2.Stop();
  9410. }
  9411. stopwatch1.Stop();
  9412. AddMessage(LogType.Info,
  9413. stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9414. stopwatch2.ElapsedMilliseconds + "ms");
  9415. }
  9416. /// <summary>
  9417. /// [S3] 值板机 - 二穴载具绑定
  9418. /// </summary>
  9419. /// <param name="plcNo">PLC编号</param>
  9420. /// <param name="stationNameStr">工站全称</param>
  9421. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  9422. {
  9423. Stopwatch stopwatch1 = new Stopwatch();
  9424. Stopwatch stopwatch2 = new Stopwatch();
  9425. try
  9426. {
  9427. stopwatch1.Start();
  9428. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  9429. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  9430. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  9431. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  9432. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  9433. stopwatch2.Start();
  9434. #region 查询载具上的产品信息
  9435. string cavityData = string.Empty;
  9436. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  9437. if (string.IsNullOrEmpty(cavityData))
  9438. cavityData = "";
  9439. if (snResult != 0)
  9440. {
  9441. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9442. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  9443. writeToPLC_Flag1.Adress = 2115;
  9444. writeToPLC_Flag1.Value = (short)6;
  9445. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  9446. stopwatch1.Stop();
  9447. AddMessage(LogType.Info,
  9448. stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9449. "ms");
  9450. return;
  9451. }
  9452. #endregion 查询载具上的产品信息
  9453. // 产品换载具
  9454. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  9455. string partSn1 = "";
  9456. string partSn2 = "";
  9457. if (cavitySNs != null && cavitySNs.Length >= 2)
  9458. {
  9459. partSn1 = cavitySNs[0];
  9460. partSn2 = cavitySNs[1];
  9461. }
  9462. string data_new = string.Empty;
  9463. // 是否是两个穴位交换
  9464. if (c1CavityReverse_Bind == 1)
  9465. {
  9466. // 交换
  9467. data_new = string.Concat(partSn2, ".", partSn1);
  9468. }
  9469. else
  9470. {
  9471. // 不交换
  9472. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  9473. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  9474. cavitySNs[c1VehicleCavityFr_Bind] = "";
  9475. data_new = string.Join(".", cavitySNs);
  9476. }
  9477. // 删除再插入
  9478. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  9479. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  9480. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  9481. stopwatch2.Stop();
  9482. short c1MES_FLAG_Bind = 1;
  9483. // MES_Flag
  9484. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9485. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9486. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  9487. writeToPLC_Flag.Adress = 2115;
  9488. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  9489. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  9490. }
  9491. catch (Exception ex)
  9492. {
  9493. string str = ex.StackTrace;
  9494. AddMessage_Station(stationNameStr, LogType.Error,
  9495. $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" +
  9496. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9497. // MES_Flag
  9498. stopwatch2.Start();
  9499. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  9500. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9501. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  9502. writeToPLC_Flag.Adress = 2115;
  9503. writeToPLC_Flag.Value = (short)6;
  9504. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  9505. stopwatch2.Stop();
  9506. }
  9507. stopwatch1.Stop();
  9508. AddMessage(LogType.Info,
  9509. stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9510. stopwatch2.ElapsedMilliseconds + "ms");
  9511. }
  9512. //// 上次采集到的SN
  9513. //private string sn_值板机 = string.Empty;
  9514. /// <summary>
  9515. /// [S3] 值板机 - 出站接口
  9516. /// </summary>
  9517. /// <param name="plcNo">PLC编号</param>
  9518. private void S3出站接口(int plcNo, string stationCode, string stationName)
  9519. {
  9520. Stopwatch stopwatch1 = new Stopwatch();
  9521. Stopwatch stopwatch2 = new Stopwatch();
  9522. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9523. string stationNameStr = stationCode + stationName;
  9524. string processItem = stationName; // 测试项目
  9525. try
  9526. {
  9527. stopwatch1.Start();
  9528. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9529. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9530. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9531. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9532. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  9533. sn = sn.Replace("\0", "");
  9534. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  9535. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  9536. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  9537. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  9538. bool pass = c1Result == 1;
  9539. // 查sn
  9540. #region 查询载具上的产品信息
  9541. string cavityData = string.Empty;
  9542. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  9543. if (string.IsNullOrEmpty(cavityData))
  9544. cavityData = "";
  9545. if (snResult != 0)
  9546. {
  9547. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9548. writeToPLC_Flag1.Name = "c1MES_FLAG";
  9549. writeToPLC_Flag1.Adress = 2150;
  9550. writeToPLC_Flag1.Value = (short)4;
  9551. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  9552. stopwatch1.Stop();
  9553. AddMessage(LogType.Info,
  9554. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9555. return;
  9556. }
  9557. #endregion 查询载具上的产品信息
  9558. string[] cavitySNs = cavityData.Split('.');
  9559. string productSN = "";
  9560. if (cavitySNs != null && cavitySNs.Length >= 2)
  9561. {
  9562. productSN = cavitySNs[c1VehicleCavity];
  9563. cavitySNs[c1VehicleCavity] = "";
  9564. }
  9565. stopwatch2.Start();
  9566. List<TestItem> items = new List<TestItem>();
  9567. items.Add(new TestItem()
  9568. {
  9569. Parameter_name = "二穴载具码",
  9570. Parameter_value = c1ProductSN_Check,
  9571. Parameter_unit = ""
  9572. });
  9573. items.Add(new TestItem()
  9574. {
  9575. Parameter_name = "二穴载具穴号",
  9576. Parameter_value = c1VehicleCavity.ToString(),
  9577. Parameter_unit = ""
  9578. });
  9579. items.Add(new TestItem()
  9580. {
  9581. Parameter_name = "一穴载具码",
  9582. Parameter_value = sn,
  9583. Parameter_unit = ""
  9584. });
  9585. items.Add(new TestItem()
  9586. {
  9587. Parameter_name = "一穴载具穴号",
  9588. Parameter_value = "1",
  9589. Parameter_unit = ""
  9590. });
  9591. items.Add(new TestItem()
  9592. {
  9593. Parameter_name = "产品结果",
  9594. Parameter_value = c1Result == 1 ? "OK" : "NG",
  9595. Parameter_unit = ""
  9596. });
  9597. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  9598. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  9599. short result = (short)result1;
  9600. stopwatch2.Stop();
  9601. #region 存储绑定数据到 边线MES系统中
  9602. if (result == 1)
  9603. {
  9604. string data = string.Concat(productSN);
  9605. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  9606. if (resultMesR != 0)
  9607. {
  9608. result = 4;
  9609. AddMessage_Station(stationNameStr, LogType.Error,
  9610. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  9611. }
  9612. }
  9613. #endregion 存储绑定数据到 边线MES系统中
  9614. #region 产品从 来源载具(二穴载具)中删除
  9615. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  9616. {
  9617. // 删除
  9618. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  9619. OnMessage(LogType.Debug,
  9620. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  9621. }
  9622. else
  9623. {
  9624. string data_new = string.Join(".", cavitySNs);
  9625. // 删除再插入
  9626. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  9627. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  9628. OnMessage(LogType.Debug,
  9629. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  9630. }
  9631. #endregion 产品从 来源载具(二穴载具)中删除
  9632. // MES_Flag 为MES报错
  9633. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9634. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  9635. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9636. writeToPLC_Flag.Name = "c1MES_FLAG";
  9637. writeToPLC_Flag.Adress = 2150;
  9638. writeToPLC_Flag.Value = result;
  9639. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  9640. OnMessage(LogType.Debug,
  9641. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9642. }
  9643. catch (Exception ex)
  9644. {
  9645. stopwatch2.Restart();
  9646. // MES_Flag 为4上位机报错
  9647. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  9648. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9649. writeToPLC_Flag.Name = "c1MES_FLAG";
  9650. writeToPLC_Flag.Adress = 2150;
  9651. writeToPLC_Flag.Value = (short)4;
  9652. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  9653. stopwatch2.Stop();
  9654. string str = ex.StackTrace;
  9655. AddMessage_Station(stationNameStr, LogType.Error,
  9656. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  9657. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9658. }
  9659. stopwatch1.Stop();
  9660. AddMessage(LogType.Info,
  9661. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  9662. stopwatch2.ElapsedMilliseconds + "ms");
  9663. }
  9664. #endregion [S3] 值板机
  9665. #endregion PLC3 刘永村
  9666. #region PLC4 刘果段
  9667. #region [S4] 取放桁架
  9668. /// <summary>
  9669. /// S4工位的数据- 触发信号上次的值
  9670. /// </summary>
  9671. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  9672. /// <summary>
  9673. /// S4工位的数据(含触发信号)
  9674. /// </summary>
  9675. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  9676. /// <summary>
  9677. /// S4工位的数据- 回写点位
  9678. /// </summary>
  9679. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  9680. /// <summary>
  9681. /// [S4] 取放桁架
  9682. /// </summary>
  9683. /// <param name="plcNo">PLC编号</param>
  9684. //private void ReadStation_S4(int plcNo)
  9685. //{
  9686. // // [S1] Tray盘上料装备
  9687. // // [S2] FCT
  9688. // // [S3] 值板机
  9689. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  9690. // // [S5] Tray盘下料装备
  9691. // /// 上位机心跳
  9692. // /// 获取设备报警数据与状态信息
  9693. // string stationCode = "[S4_1]";
  9694. // string stationName = "载具下线装备";
  9695. // string stationNameStr = stationCode + stationName;
  9696. // string stationCode2 = "[S4_2]";
  9697. // string stationName2 = "桁架";
  9698. // string stationNameStr2 = stationCode2 + stationName2;
  9699. // string stationCode3 = "[S4_3]";
  9700. // string stationName3 = "提升机1";
  9701. // string stationNameStr3 = stationCode3 + stationName3;
  9702. // string stationCode4 = "[S4_4]";
  9703. // string stationName4 = "提升机2";
  9704. // string stationNameStr4 = stationCode4 + stationName4;
  9705. // string stationCode5 = "[S4_5]";
  9706. // string stationName5 = "载具上线装备";
  9707. // string stationNameStr5 = stationCode5 + stationName5;
  9708. // #region 创建字典
  9709. // // 触发信号字典 赋值
  9710. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9711. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  9712. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  9713. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9714. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  9715. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  9716. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  9717. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9718. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  9719. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  9720. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9721. // // PLC数据字典 赋值
  9722. // // 载具下线装备(弹夹上线)
  9723. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9724. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  9725. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  9726. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  9727. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  9728. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  9729. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  9730. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  9731. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  9732. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  9733. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  9734. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  9735. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  9736. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  9737. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  9738. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  9739. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  9740. // s4PLCData.Add("d1Result", 0); // 产品结果
  9741. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9742. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  9743. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  9744. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  9745. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  9746. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  9747. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  9748. // // 真空标机(提升机)
  9749. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  9750. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  9751. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  9752. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  9753. // s4PLCData.Add("d3Result", 0); // 产品结果
  9754. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  9755. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  9756. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  9757. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  9758. // s4PLCData.Add("d4Result", 0); // 产品结果
  9759. // // 载具上线装备(弹夹下线)
  9760. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9761. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  9762. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  9763. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  9764. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  9765. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  9766. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  9767. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  9768. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  9769. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  9770. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  9771. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  9772. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  9773. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  9774. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  9775. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  9776. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  9777. // s4PLCData.Add("d5Result", 0); // 产品结果
  9778. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9779. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  9780. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  9781. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  9782. // #endregion 创建字典
  9783. // while (IsRun)
  9784. // {
  9785. // try
  9786. // {
  9787. // if (!GlobalContext._IsCon_Funs4)
  9788. // {
  9789. // UpdatePLCMonitor(1, plcNo, 0);
  9790. // continue;
  9791. // }
  9792. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  9793. // {
  9794. // Stopwatch stopwatch1 = new Stopwatch();
  9795. // Stopwatch stopwatch2 = new Stopwatch();
  9796. // stopwatch1.Start();
  9797. // stopwatch2.Start();
  9798. // #region 一次性读取所有数据
  9799. // // 载具下线装备(弹夹上线)
  9800. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  9801. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  9802. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  9803. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  9804. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  9805. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  9806. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  9807. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  9808. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  9809. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  9810. // int[] datas = data1.Concat(data2).ToArray();
  9811. // datas = datas.Concat(data3).ToArray();
  9812. // datas = datas.Concat(data4).ToArray();
  9813. // datas = datas.Concat(data5).ToArray();
  9814. // datas = datas.Concat(data6).ToArray();
  9815. // datas = datas.Concat(data7).ToArray();
  9816. // datas = datas.Concat(data8).ToArray();
  9817. // datas = datas.Concat(data9).ToArray();
  9818. // datas = datas.Concat(data10).ToArray();
  9819. // // 载具下线装备(弹夹上线)
  9820. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  9821. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  9822. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  9823. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  9824. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  9825. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  9826. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  9827. // s4PLCData["d1MES_FLAG"] = datas[65];
  9828. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  9829. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  9830. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  9831. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  9832. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  9833. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  9834. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  9835. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  9836. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  9837. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  9838. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  9839. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  9840. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  9841. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  9842. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  9843. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  9844. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  9845. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  9846. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  9847. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  9848. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  9849. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  9850. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  9851. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  9852. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  9853. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  9854. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  9855. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  9856. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  9857. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  9858. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  9859. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  9860. // s4PLCData["d1Result"] = datas[386];
  9861. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  9862. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  9863. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  9864. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  9865. // s4PLCData["d1OEEType"] = datas[419];
  9866. // // 桁架(查询标机中弹夹的状态)
  9867. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  9868. // s4PLCData["d2BulletclipStates"] = datas[431];
  9869. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  9870. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  9871. // // 真空标机
  9872. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  9873. // s4PLCData["d3MES_FLAG"] = datas[463];
  9874. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  9875. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  9876. // s4PLCData["d3Result"] = datas[484];
  9877. // s4PLCData["d3Type"] = datas[485];
  9878. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  9879. // s4PLCData["d4MES_FLAG"] = datas[496];
  9880. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  9881. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  9882. // s4PLCData["d4Result"] = datas[517];
  9883. // s4PLCData["d4Type"] = datas[518];
  9884. // // 载具上线装备(弹夹下线)
  9885. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  9886. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  9887. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  9888. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  9889. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  9890. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  9891. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  9892. // s4PLCData["d5MES_FLAG"] = datas[591];
  9893. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  9894. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  9895. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  9896. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  9897. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  9898. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  9899. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  9900. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  9901. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  9902. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  9903. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  9904. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  9905. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  9906. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  9907. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  9908. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  9909. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  9910. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  9911. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  9912. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  9913. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  9914. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  9915. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  9916. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  9917. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  9918. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  9919. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  9920. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  9921. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  9922. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  9923. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  9924. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  9925. // s4PLCData["d5Result"] = datas[912];
  9926. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  9927. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  9928. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  9929. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  9930. // s4PLCData["d5OEEType"] = datas[945];
  9931. // #endregion 一次性读取所有数据
  9932. // stopwatch2.Stop();
  9933. // #region 回写操作,写后清空flag
  9934. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  9935. // #endregion 回写操作,写后清空flag
  9936. // // N801A-S4_1 弹夹扫码
  9937. // #region N801A-S4_1 弹夹扫码
  9938. // try
  9939. // {
  9940. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  9941. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  9942. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  9943. // {
  9944. // if (d1BulletclipScanCode == 1) // 0->1
  9945. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  9946. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  9947. // }
  9948. // }
  9949. // catch (Exception ex)
  9950. // {
  9951. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  9952. // string str = ex.StackTrace;
  9953. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9954. // }
  9955. // #endregion N801A-S4_1 弹夹扫码
  9956. // // N801A-S4_1 载具扫码
  9957. // #region N801A-S4_1 载具扫码
  9958. // try
  9959. // {
  9960. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  9961. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  9962. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  9963. // {
  9964. // if (d1VehicleScanCode == 1) // 0->1
  9965. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  9966. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  9967. // }
  9968. // }
  9969. // catch (Exception ex)
  9970. // {
  9971. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  9972. // string str = ex.StackTrace;
  9973. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9974. // }
  9975. // #endregion N801A-S4_1 载具扫码
  9976. // // N801A-S4_1 出站接口
  9977. // #region N801A-S4_1 出站接口
  9978. // try
  9979. // {
  9980. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  9981. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  9982. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  9983. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  9984. // {
  9985. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  9986. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  9987. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  9988. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  9989. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  9990. // }
  9991. // }
  9992. // catch (Exception ex)
  9993. // {
  9994. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  9995. // string str = ex.StackTrace;
  9996. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9997. // }
  9998. // #endregion N801A-S4_1 出站接口
  9999. // // N801A-S4_1 节拍接口
  10000. // #region N801A-S4_1 节拍接口
  10001. // try
  10002. // {
  10003. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  10004. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  10005. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  10006. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  10007. // {
  10008. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  10009. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  10010. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  10011. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  10012. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  10013. // }
  10014. // }
  10015. // catch (Exception ex)
  10016. // {
  10017. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  10018. // string str = ex.StackTrace;
  10019. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10020. // }
  10021. // #endregion N801A-S4_1 节拍接口
  10022. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  10023. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  10024. // try
  10025. // {
  10026. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  10027. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  10028. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  10029. // {
  10030. // if (d2BulletclipScanCode == 1) // 0->1
  10031. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  10032. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  10033. // }
  10034. // }
  10035. // catch (Exception ex)
  10036. // {
  10037. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  10038. // string str = ex.StackTrace;
  10039. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10040. // }
  10041. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  10042. // // N801A-S4_3 真空标机1 数据
  10043. // #region N801A-S4_3 真空标机1
  10044. // try
  10045. // {
  10046. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  10047. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  10048. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  10049. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  10050. // {
  10051. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  10052. // {
  10053. // int stationType = (int)s4PLCData["d3Type"];
  10054. // if (stationType == 1)
  10055. // {
  10056. // // S4_3进站接口
  10057. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  10058. // }
  10059. // else if (stationType == 2)
  10060. // {
  10061. // // S4_3出站接口
  10062. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  10063. // }
  10064. // }
  10065. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  10066. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  10067. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  10068. // }
  10069. // }
  10070. // catch (Exception ex)
  10071. // {
  10072. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  10073. // string str = ex.StackTrace;
  10074. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10075. // }
  10076. // #endregion N801A-S4_3 真空标机1
  10077. // // N801A-S4_4 真空标机2 数据
  10078. // #region N801A-S4_4 真空标机2
  10079. // try
  10080. // {
  10081. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  10082. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  10083. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  10084. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  10085. // {
  10086. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  10087. // {
  10088. // int stationType = (int)s4PLCData["d4Type"];
  10089. // if (stationType == 1)
  10090. // {
  10091. // // S4_4进站接口
  10092. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  10093. // }
  10094. // else if (stationType == 2)
  10095. // {
  10096. // // S4_4出站接口
  10097. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  10098. // }
  10099. // }
  10100. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  10101. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  10102. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  10103. // }
  10104. // }
  10105. // catch (Exception ex)
  10106. // {
  10107. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  10108. // string str = ex.StackTrace;
  10109. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10110. // }
  10111. // #endregion N801A-S4_4 真空标机2
  10112. // // N801A-S4_5 弹夹扫码 数据
  10113. // #region N801A-S4_5 弹夹扫码
  10114. // try
  10115. // {
  10116. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  10117. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  10118. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  10119. // {
  10120. // if (d5BulletclipScanCode == 1) // 0->1
  10121. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  10122. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  10123. // }
  10124. // }
  10125. // catch (Exception ex)
  10126. // {
  10127. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  10128. // string str = ex.StackTrace;
  10129. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10130. // }
  10131. // #endregion N801A-S4_5 弹夹扫码
  10132. // // N801A-S4_5 载具扫码 数据
  10133. // #region N801A-S4_5 载具扫码
  10134. // try
  10135. // {
  10136. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  10137. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  10138. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  10139. // {
  10140. // if (d5VehicleScanCode == 1) // 0->1
  10141. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  10142. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  10143. // }
  10144. // }
  10145. // catch (Exception ex)
  10146. // {
  10147. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  10148. // string str = ex.StackTrace;
  10149. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10150. // }
  10151. // #endregion N801A-S4_5 载具扫码
  10152. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  10153. // #region N801A-S4_5 出站接口
  10154. // try
  10155. // {
  10156. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  10157. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  10158. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  10159. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  10160. // {
  10161. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  10162. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  10163. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  10164. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  10165. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  10166. // }
  10167. // }
  10168. // catch (Exception ex)
  10169. // {
  10170. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  10171. // string str = ex.StackTrace;
  10172. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10173. // }
  10174. // #endregion N801A-S4_5 出站接口
  10175. // // N801A-S4_5 节拍接口 数据
  10176. // #region N801A-S4_5 节拍接口
  10177. // try
  10178. // {
  10179. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  10180. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  10181. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  10182. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  10183. // {
  10184. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  10185. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  10186. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  10187. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  10188. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  10189. // }
  10190. // }
  10191. // catch (Exception ex)
  10192. // {
  10193. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  10194. // string str = ex.StackTrace;
  10195. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10196. // }
  10197. // #endregion N801A-S4_5 节拍接口
  10198. // #region 心跳
  10199. // try
  10200. // {
  10201. // short states = 0;
  10202. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  10203. // }
  10204. // catch (Exception ex)
  10205. // {
  10206. // string str = ex.StackTrace;
  10207. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10208. // }
  10209. // #endregion 心跳
  10210. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  10211. // stopwatch1.Stop();
  10212. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  10213. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  10214. // }
  10215. // else
  10216. // {
  10217. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  10218. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  10219. // Funs[plcNo].Connect();
  10220. // }
  10221. // }
  10222. // catch (Exception ex)
  10223. // {
  10224. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  10225. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  10226. // Funs[plcNo].ReConnect();
  10227. // }
  10228. // Thread.Sleep(IntervalReadPLC);
  10229. // }
  10230. //}
  10231. /// <summary>
  10232. /// [S4] 取放桁架 - S4_1弹夹扫码
  10233. /// </summary>
  10234. /// <param name="plcNo">PLC编号</param>
  10235. /// <param name="stationNameStr">工站全称</param>
  10236. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  10237. {
  10238. Stopwatch stopwatch1 = new Stopwatch();
  10239. Stopwatch stopwatch2 = new Stopwatch();
  10240. try
  10241. {
  10242. stopwatch1.Start();
  10243. // ZS 弹夹扫码
  10244. string d1BulletclipCode = " "; // 扫到的码
  10245. short d1BulletclipScanCode = 2;
  10246. stopwatch2.Start();
  10247. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  10248. //// MES_Flag
  10249. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10250. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10251. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  10252. writeToPLC_Flag.Adress = 2002;
  10253. writeToPLC_Flag.Value = d1BulletclipScanCode;
  10254. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  10255. {
  10256. Name = "d1BulletclipCode",
  10257. Adress = 2003,
  10258. ValueType = PLCValueType.String,
  10259. ValueTypeStrLength = 20,
  10260. Value = d1BulletclipCode
  10261. });
  10262. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  10263. stopwatch2.Stop();
  10264. }
  10265. catch (Exception ex)
  10266. {
  10267. string str = ex.StackTrace;
  10268. AddMessage_Station(stationNameStr, LogType.Error,
  10269. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10270. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10271. stopwatch2.Start();
  10272. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  10273. //// MES_Flag
  10274. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  10275. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10276. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  10277. writeToPLC_Flag.Adress = 2002;
  10278. writeToPLC_Flag.Value = (short)6;
  10279. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  10280. {
  10281. Name = "d1BulletclipCode",
  10282. Adress = 2003,
  10283. ValueType = PLCValueType.String,
  10284. ValueTypeStrLength = 20,
  10285. Value = " "
  10286. });
  10287. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  10288. stopwatch2.Stop();
  10289. }
  10290. stopwatch1.Stop();
  10291. AddMessage(LogType.Info,
  10292. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10293. stopwatch2.ElapsedMilliseconds + "ms");
  10294. }
  10295. /// <summary>
  10296. /// [S4] 取放桁架 - S4_1载具扫码
  10297. /// </summary>
  10298. /// <param name="plcNo">PLC编号</param>
  10299. /// <param name="stationNameStr">工站全称</param>
  10300. private void S4_1载具扫码(int plcNo, string stationNameStr)
  10301. {
  10302. Stopwatch stopwatch1 = new Stopwatch();
  10303. Stopwatch stopwatch2 = new Stopwatch();
  10304. try
  10305. {
  10306. stopwatch1.Start();
  10307. // ZS 载具扫码
  10308. string d1VehicleCode = ""; // 扫到的码
  10309. short d1VehicleScanCode = 2;
  10310. #region 进站
  10311. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  10312. {
  10313. #region 查询载具上的产品信息
  10314. string cavityData = string.Empty;
  10315. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  10316. if (string.IsNullOrEmpty(cavityData))
  10317. cavityData = "";
  10318. if (snResult != 0)
  10319. {
  10320. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10321. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  10322. writeToPLC_Flag1.Adress = 2033;
  10323. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  10324. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10325. {
  10326. Name = "d1VehicleCode",
  10327. Adress = 2034,
  10328. ValueType = PLCValueType.String,
  10329. ValueTypeStrLength = 20,
  10330. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  10331. });
  10332. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  10333. stopwatch1.Stop();
  10334. AddMessage(LogType.Info,
  10335. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10336. "ms");
  10337. return;
  10338. }
  10339. string[] cavitySNs = cavityData.Split('.');
  10340. string partNo = "";
  10341. if (cavitySNs != null && cavitySNs.Length >= 1)
  10342. {
  10343. partNo = cavitySNs[0];
  10344. }
  10345. #endregion 查询载具上的产品信息
  10346. List<TestItem> item = new List<TestItem>();
  10347. item.Add(new TestItem()
  10348. {
  10349. Parameter_name = "载具码",
  10350. Parameter_value = d1VehicleCode,
  10351. });
  10352. item.Add(new TestItem()
  10353. {
  10354. Parameter_name = "载具穴号",
  10355. Parameter_value = "1",
  10356. });
  10357. stopwatch2.Start();
  10358. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  10359. partNo, item, out string errorMsg);
  10360. stopwatch2.Stop();
  10361. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  10362. }
  10363. #endregion 进站
  10364. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  10365. //// MES_Flag
  10366. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10367. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10368. writeToPLC_Flag.Name = "d1VehicleScanCode";
  10369. writeToPLC_Flag.Adress = 2033;
  10370. writeToPLC_Flag.Value = d1VehicleScanCode;
  10371. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10372. {
  10373. Name = "d1VehicleCode",
  10374. Adress = 2034,
  10375. ValueType = PLCValueType.String,
  10376. ValueTypeStrLength = 20,
  10377. Value = d1VehicleCode
  10378. });
  10379. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  10380. }
  10381. catch (Exception ex)
  10382. {
  10383. string str = ex.StackTrace;
  10384. AddMessage_Station(stationNameStr, LogType.Error,
  10385. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10386. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10387. stopwatch2.Start();
  10388. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  10389. //// MES_Flag
  10390. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  10391. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10392. writeToPLC_Flag.Name = "d1VehicleScanCode";
  10393. writeToPLC_Flag.Adress = 2033;
  10394. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  10395. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10396. {
  10397. Name = "d1VehicleCode",
  10398. Adress = 2034,
  10399. ValueType = PLCValueType.String,
  10400. ValueTypeStrLength = 20,
  10401. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  10402. });
  10403. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  10404. stopwatch2.Stop();
  10405. }
  10406. stopwatch1.Stop();
  10407. AddMessage(LogType.Info,
  10408. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10409. stopwatch2.ElapsedMilliseconds + "ms");
  10410. }
  10411. // 上次采集到的SN
  10412. //private string sn_S4_1出站接口 = string.Empty;
  10413. /// <summary>
  10414. /// [S4] 取放桁架 - S4_1出站接口
  10415. /// </summary>
  10416. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  10417. {
  10418. Stopwatch stopwatch1 = new Stopwatch();
  10419. Stopwatch stopwatch2 = new Stopwatch();
  10420. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10421. string stationNameStr = stationCode + stationName;
  10422. string processItem = stationName; // 测试项目
  10423. try
  10424. {
  10425. stopwatch1.Start();
  10426. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10427. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10428. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10429. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10430. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  10431. sn = sn.Replace("\0", "");
  10432. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  10433. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  10434. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  10435. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  10436. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  10437. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  10438. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  10439. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  10440. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  10441. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  10442. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  10443. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  10444. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  10445. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  10446. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  10447. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  10448. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  10449. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  10450. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  10451. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  10452. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  10453. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  10454. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  10455. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  10456. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  10457. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  10458. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  10459. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  10460. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  10461. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  10462. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  10463. bool pass = d1Result == 1;
  10464. // 存 载具SN列表
  10465. List<string> vehicleCodes = new List<string>()
  10466. {
  10467. d1VehicleCode1, d1VehicleCode2, d1VehicleCode3, d1VehicleCode4, d1VehicleCode5,
  10468. d1VehicleCode6, d1VehicleCode7, d1VehicleCode8, d1VehicleCode9, d1VehicleCode10,
  10469. d1VehicleCode11, d1VehicleCode12, d1VehicleCode13, d1VehicleCode14, d1VehicleCode15
  10470. };
  10471. // 统一查 产品SN列表
  10472. List<string> partNos = new List<string>();
  10473. foreach (string vehicleCode in vehicleCodes)
  10474. {
  10475. if (string.IsNullOrEmpty(vehicleCode))
  10476. partNos.Add("");
  10477. else
  10478. {
  10479. string partNo = "";
  10480. #region 查询载具上的产品信息
  10481. string cavityData = string.Empty;
  10482. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10483. if (string.IsNullOrEmpty(cavityData))
  10484. cavityData = "";
  10485. if (snResult != 0)
  10486. {
  10487. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10488. writeToPLC_Flag1.Name = "d1MES_FLAG";
  10489. writeToPLC_Flag1.Adress = 2065;
  10490. writeToPLC_Flag1.Value = (short)4;
  10491. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  10492. stopwatch1.Stop();
  10493. AddMessage(LogType.Info,
  10494. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10495. "ms");
  10496. return;
  10497. }
  10498. string[] cavitySNs = cavityData.Split('.');
  10499. if (cavitySNs != null && cavitySNs.Length >= 1)
  10500. partNo = cavitySNs[0];
  10501. #endregion 查询载具上的产品信息
  10502. partNos.Add(partNo);
  10503. }
  10504. }
  10505. // 统一上传
  10506. stopwatch2.Start();
  10507. List<int> results = new List<int>();
  10508. for (int i = 0; i < partNos.Count; i++)
  10509. {
  10510. string index = (i + 1).ToString(); // 弹夹穴号
  10511. if (string.IsNullOrEmpty(partNos[i]))
  10512. results.Add(1);
  10513. else
  10514. {
  10515. List<TestItem> items1 = new List<TestItem>();
  10516. items1.Add(new TestItem()
  10517. {
  10518. Parameter_name = "弹夹码",
  10519. Parameter_value = sn,
  10520. Parameter_unit = ""
  10521. });
  10522. items1.Add(new TestItem()
  10523. {
  10524. Parameter_name = "弹夹穴号",
  10525. Parameter_value = index,
  10526. Parameter_unit = ""
  10527. });
  10528. items1.Add(new TestItem()
  10529. {
  10530. Parameter_name = "载具码",
  10531. Parameter_value = vehicleCodes[i],
  10532. Parameter_unit = ""
  10533. });
  10534. items1.Add(new TestItem()
  10535. {
  10536. Parameter_name = "载具穴号",
  10537. Parameter_value = "1",
  10538. Parameter_unit = ""
  10539. });
  10540. items1.Add(new TestItem()
  10541. {
  10542. Parameter_name = "产品结果",
  10543. Parameter_value = d1Result == 1 ? "OK" : "NG",
  10544. Parameter_unit = ""
  10545. });
  10546. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  10547. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  10548. results.Add(result1);
  10549. }
  10550. }
  10551. short result = 0;
  10552. if (results.All(a => a == 1))
  10553. result = 1;
  10554. else if (results.Contains(3))
  10555. result = 3;
  10556. else if (results.Contains(2))
  10557. result = 2;
  10558. else if (results.Contains(4))
  10559. result = 4;
  10560. else
  10561. result = 4;
  10562. stopwatch2.Stop();
  10563. #region 存储绑定数据到 边线MES系统中
  10564. if (result == 1)
  10565. {
  10566. string data = string.Join(".", vehicleCodes);
  10567. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  10568. if (resultMesR != 0)
  10569. {
  10570. result = 4;
  10571. AddMessage_Station(stationNameStr, LogType.Error,
  10572. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  10573. }
  10574. }
  10575. #endregion 存储绑定数据到 边线MES系统中
  10576. // MES_Flag 为4MES报错
  10577. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10578. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10579. writeToPLC_Flag.Name = "d1MES_FLAG";
  10580. writeToPLC_Flag.Adress = 2065;
  10581. writeToPLC_Flag.Value = result;
  10582. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  10583. OnMessage(LogType.Debug,
  10584. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  10585. }
  10586. catch (Exception ex)
  10587. {
  10588. stopwatch2.Restart();
  10589. // MES_Flag 为4上位机报错
  10590. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  10591. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10592. writeToPLC_Flag.Name = "d1MES_FLAG";
  10593. writeToPLC_Flag.Adress = 2065;
  10594. writeToPLC_Flag.Value = (short)4;
  10595. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  10596. stopwatch2.Stop();
  10597. string str = ex.StackTrace;
  10598. AddMessage_Station(stationNameStr, LogType.Error,
  10599. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10600. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10601. }
  10602. stopwatch1.Stop();
  10603. AddMessage(LogType.Info,
  10604. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10605. stopwatch2.ElapsedMilliseconds + "ms");
  10606. }
  10607. /// <summary>
  10608. /// [S4] 取放桁架 - S4_1节拍接口
  10609. /// </summary>
  10610. /// <param name="plcNo">PLC编号</param>
  10611. /// <param name="stationNameStr">工站全称</param>
  10612. private void S4_1节拍接口(int plcNo, string stationNameStr)
  10613. {
  10614. Stopwatch stopwatch1 = new Stopwatch();
  10615. Stopwatch stopwatch2 = new Stopwatch();
  10616. string resultStr = string.Empty;
  10617. try
  10618. {
  10619. stopwatch1.Start();
  10620. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  10621. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  10622. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  10623. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  10624. if (!actionBool)
  10625. {
  10626. stopwatch2.Start();
  10627. // MES_Flag
  10628. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10629. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10630. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  10631. writeToPLC_Flag1.Adress = 2398;
  10632. writeToPLC_Flag1.Value = (short)4;
  10633. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  10634. stopwatch2.Stop();
  10635. AddMessage(LogType.Info,
  10636. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  10637. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  10638. return;
  10639. }
  10640. string d1OEEPartNo = string.Empty; // 物料码
  10641. if (string.IsNullOrEmpty(d1OEEProductSN))
  10642. {
  10643. stopwatch2.Start();
  10644. // MES_Flag
  10645. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10646. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10647. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  10648. writeToPLC_Flag1.Adress = 2398;
  10649. writeToPLC_Flag1.Value = (short)1;
  10650. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  10651. stopwatch2.Stop();
  10652. AddMessage(LogType.Info,
  10653. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10654. stopwatch2.ElapsedMilliseconds + "ms");
  10655. return;
  10656. }
  10657. else
  10658. {
  10659. // 查产品SN ZS
  10660. d1OEEPartNo = "Test";
  10661. }
  10662. short d1OEEMES_FLAG = 0;
  10663. // 上传OEE
  10664. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  10665. d1OEEMES_FLAG = result.Item1;
  10666. resultStr = result.Item2;
  10667. stopwatch2.Start();
  10668. // MES_Flag
  10669. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10670. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10671. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  10672. writeToPLC_Flag.Adress = 2398;
  10673. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  10674. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  10675. stopwatch2.Stop();
  10676. }
  10677. catch (Exception ex)
  10678. {
  10679. string str = ex.StackTrace;
  10680. AddMessage_Station(stationNameStr, LogType.Error,
  10681. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  10682. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10683. // MES_Flag
  10684. stopwatch2.Start();
  10685. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  10686. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10687. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  10688. writeToPLC_Flag.Adress = 2398;
  10689. writeToPLC_Flag.Value = (short)4;
  10690. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  10691. stopwatch2.Stop();
  10692. }
  10693. stopwatch1.Stop();
  10694. AddMessage(LogType.Info,
  10695. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10696. stopwatch2.ElapsedMilliseconds + "ms");
  10697. }
  10698. /// <summary>
  10699. /// [S4] 取放桁架 - S4_2桁架
  10700. /// </summary>
  10701. /// <param name="plcNo">PLC编号</param>
  10702. /// <param name="stationNameStr">工站全称</param>
  10703. private void S4_2桁架(int plcNo, string stationNameStr)
  10704. {
  10705. Stopwatch stopwatch1 = new Stopwatch();
  10706. Stopwatch stopwatch2 = new Stopwatch();
  10707. try
  10708. {
  10709. stopwatch1.Start();
  10710. // ZS 弹夹扫码
  10711. string d2BulletclipCode = " "; // 扫到的码
  10712. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  10713. short d2BulletclipScanCode = 2;
  10714. stopwatch2.Start();
  10715. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  10716. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  10717. //// MES_Flag
  10718. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10719. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10720. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  10721. writeToPLC_Flag.Adress = 2430;
  10722. writeToPLC_Flag.Value = d2BulletclipScanCode;
  10723. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10724. {
  10725. Name = "d2BulletclipCode",
  10726. Adress = 2432,
  10727. ValueType = PLCValueType.String,
  10728. ValueTypeStrLength = 20,
  10729. Value = d2BulletclipCode
  10730. });
  10731. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10732. {
  10733. Name = "d2BulletclipStates",
  10734. Adress = 2431,
  10735. ValueType = PLCValueType.Short,
  10736. Value = d2BulletclipStates
  10737. });
  10738. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  10739. stopwatch2.Stop();
  10740. }
  10741. catch (Exception ex)
  10742. {
  10743. string str = ex.StackTrace;
  10744. AddMessage_Station(stationNameStr, LogType.Error,
  10745. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10746. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10747. stopwatch2.Start();
  10748. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  10749. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  10750. // MES_Flag
  10751. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  10752. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10753. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  10754. writeToPLC_Flag.Adress = 2430;
  10755. writeToPLC_Flag.Value = (short)6;
  10756. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10757. {
  10758. Name = "d2BulletclipCode",
  10759. Adress = 2432,
  10760. ValueType = PLCValueType.String,
  10761. ValueTypeStrLength = 20,
  10762. Value = " "
  10763. });
  10764. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10765. {
  10766. Name = "d2BulletclipStates",
  10767. Adress = 2431,
  10768. ValueType = PLCValueType.Short,
  10769. Value = (short)0
  10770. });
  10771. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  10772. stopwatch2.Stop();
  10773. }
  10774. stopwatch1.Stop();
  10775. AddMessage(LogType.Info,
  10776. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10777. stopwatch2.ElapsedMilliseconds + "ms");
  10778. }
  10779. // 上次采集到的SN
  10780. //private string sn_S4_3进站接口 = string.Empty;
  10781. /// <summary>
  10782. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  10783. /// </summary>
  10784. private void S4_3进站接口(int plcNo, string stationNameStr)
  10785. {
  10786. Stopwatch stopwatch1 = new Stopwatch();
  10787. Stopwatch stopwatch2 = new Stopwatch();
  10788. try
  10789. {
  10790. stopwatch1.Start();
  10791. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  10792. sn = sn.Replace("\0", "");
  10793. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  10794. #region 查询15个载具码
  10795. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10796. string vehicleData = string.Empty;
  10797. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10798. if (string.IsNullOrEmpty(vehicleData))
  10799. vehicleData = "";
  10800. if (snResult != 0)
  10801. {
  10802. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10803. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10804. writeToPLC_Flag1.Adress = 2463;
  10805. writeToPLC_Flag1.Value = (short)4;
  10806. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10807. stopwatch1.Stop();
  10808. AddMessage(LogType.Info,
  10809. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10810. return;
  10811. }
  10812. string[] cavitySNs = vehicleData.Split('.');
  10813. if (cavitySNs != null && cavitySNs.Length > 0)
  10814. {
  10815. for (int i = 0; i < cavitySNs.Length; i++)
  10816. {
  10817. if (string.IsNullOrEmpty(cavitySNs[i]))
  10818. vehicleCodes.Add("");
  10819. else
  10820. vehicleCodes.Add(cavitySNs[i]);
  10821. }
  10822. }
  10823. #endregion 查询15个载具码
  10824. #region 查询15个产品SN
  10825. List<string> portNos = new List<string>(); // 15个产品SN
  10826. foreach (string vehicleCode in vehicleCodes)
  10827. {
  10828. if (string.IsNullOrEmpty(vehicleCode))
  10829. portNos.Add("");
  10830. else
  10831. {
  10832. // 查询
  10833. string cavityData = string.Empty;
  10834. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10835. if (string.IsNullOrEmpty(cavityData))
  10836. cavityData = "";
  10837. if (snResult1 != 0)
  10838. {
  10839. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10840. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10841. writeToPLC_Flag1.Adress = 2463;
  10842. writeToPLC_Flag1.Value = (short)4;
  10843. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10844. stopwatch1.Stop();
  10845. AddMessage(LogType.Info,
  10846. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  10847. stopwatch1.ElapsedMilliseconds + "ms");
  10848. return;
  10849. }
  10850. string[] partSNs = cavityData.Split('.');
  10851. if (partSNs != null && partSNs.Length >= 1)
  10852. portNos.Add(partSNs[0]);
  10853. else
  10854. portNos.Add("");
  10855. }
  10856. }
  10857. #endregion 查询15个产品SN
  10858. // 调用MES进站(最多15个)
  10859. stopwatch2.Start();
  10860. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  10861. for (int i = 0; i < vehicleCodes.Count; i++)
  10862. {
  10863. // 循环进站
  10864. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  10865. {
  10866. // 产品SN(物料码)校验
  10867. string portNo = portNos[i];
  10868. List<TestItem> item = new List<TestItem>();
  10869. item.Add(new TestItem()
  10870. {
  10871. Parameter_name = "弹夹码",
  10872. Parameter_value = sn,
  10873. });
  10874. item.Add(new TestItem()
  10875. {
  10876. Parameter_name = "弹夹穴位",
  10877. Parameter_value = (i + 1).ToString(),
  10878. });
  10879. item.Add(new TestItem()
  10880. {
  10881. Parameter_name = "载具码",
  10882. Parameter_value = vehicleCodes[i],
  10883. });
  10884. item.Add(new TestItem()
  10885. {
  10886. Parameter_name = "载具穴号",
  10887. Parameter_value = "1",
  10888. });
  10889. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  10890. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  10891. }
  10892. }
  10893. stopwatch2.Stop();
  10894. short result = 0;
  10895. bool haveMesWarn = results.Contains(5);
  10896. bool havePCWarn = results.Contains(6);
  10897. if (haveMesWarn)
  10898. result = 2; // 5->2
  10899. else if (havePCWarn)
  10900. result = 6; // 6->4
  10901. else
  10902. result = 1;
  10903. // MES_Flag 为4MES报错
  10904. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10905. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10906. writeToPLC_Flag.Name = "d3MES_FLAG";
  10907. writeToPLC_Flag.Adress = 2463;
  10908. writeToPLC_Flag.Value = result;
  10909. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10910. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10911. }
  10912. catch (Exception ex)
  10913. {
  10914. stopwatch2.Stop();
  10915. // MES_Flag 为4上位机报错
  10916. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  10917. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10918. writeToPLC_Flag.Name = "d3MES_FLAG";
  10919. writeToPLC_Flag.Adress = 2463;
  10920. writeToPLC_Flag.Value = (short)4;
  10921. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10922. string str = ex.StackTrace;
  10923. AddMessage_Station(stationNameStr, LogType.Error,
  10924. $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10925. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10926. }
  10927. stopwatch1.Stop();
  10928. AddMessage(LogType.Info,
  10929. stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  10930. stopwatch2.ElapsedMilliseconds + "ms");
  10931. }
  10932. // 上次采集到的SN
  10933. //private string sn_S4_3出站接口 = string.Empty;
  10934. /// <summary>
  10935. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  10936. /// </summary>
  10937. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  10938. {
  10939. Stopwatch stopwatch1 = new Stopwatch();
  10940. Stopwatch stopwatch2 = new Stopwatch();
  10941. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10942. string stationNameStr = stationCode + stationName;
  10943. string processItem = stationName; // 测试项目
  10944. try
  10945. {
  10946. stopwatch1.Start();
  10947. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10948. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10949. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10950. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10951. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  10952. sn = sn.Replace("\0", "");
  10953. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  10954. bool isPass = d3Result == 1; // 产品结果 bool
  10955. #region 查询15个载具码
  10956. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10957. string vehicleData = string.Empty;
  10958. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10959. if (string.IsNullOrEmpty(vehicleData))
  10960. vehicleData = "";
  10961. if (snResult1 != 0)
  10962. {
  10963. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10964. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10965. writeToPLC_Flag1.Adress = 2463;
  10966. writeToPLC_Flag1.Value = (short)4;
  10967. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10968. stopwatch1.Stop();
  10969. AddMessage(LogType.Info,
  10970. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10971. return;
  10972. }
  10973. string[] cavitySNs = vehicleData.Split('.');
  10974. if (cavitySNs != null && cavitySNs.Length > 0)
  10975. {
  10976. for (int i = 0; i < cavitySNs.Length; i++)
  10977. {
  10978. if (string.IsNullOrEmpty(cavitySNs[i]))
  10979. vehicleCodes.Add("");
  10980. else
  10981. vehicleCodes.Add(cavitySNs[i]);
  10982. }
  10983. }
  10984. #endregion 查询15个载具码
  10985. // 统一查 产品SN列表
  10986. List<string> partNos = new List<string>();
  10987. foreach (string vehicleCode in vehicleCodes)
  10988. {
  10989. if (string.IsNullOrEmpty(vehicleCode))
  10990. partNos.Add("");
  10991. else
  10992. {
  10993. string partNo = "";
  10994. #region 查询载具上的产品信息
  10995. string cavityData = string.Empty;
  10996. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10997. if (string.IsNullOrEmpty(cavityData))
  10998. cavityData = "";
  10999. if (snResult != 0)
  11000. {
  11001. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11002. writeToPLC_Flag1.Name = "d3MES_FLAG";
  11003. writeToPLC_Flag1.Adress = 2463;
  11004. writeToPLC_Flag1.Value = (short)4;
  11005. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  11006. stopwatch1.Stop();
  11007. AddMessage(LogType.Info,
  11008. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  11009. "ms");
  11010. return;
  11011. }
  11012. string[] partSNs = cavityData.Split('.');
  11013. if (partSNs != null && partSNs.Length >= 1)
  11014. partNo = partSNs[0];
  11015. #endregion 查询载具上的产品信息
  11016. partNos.Add(partNo);
  11017. }
  11018. }
  11019. // 统一上传 - 调用MES出站
  11020. stopwatch2.Start();
  11021. List<int> results = new List<int>();
  11022. for (int i = 0; i < partNos.Count; i++)
  11023. {
  11024. string index = (i + 1).ToString(); // 弹夹穴号
  11025. if (string.IsNullOrEmpty(partNos[i]))
  11026. results.Add(1);
  11027. else
  11028. {
  11029. List<TestItem> items1 = new List<TestItem>();
  11030. items1.Add(new TestItem()
  11031. {
  11032. Parameter_name = "弹夹码",
  11033. Parameter_value = sn,
  11034. Parameter_unit = ""
  11035. });
  11036. items1.Add(new TestItem()
  11037. {
  11038. Parameter_name = "弹夹穴号",
  11039. Parameter_value = index,
  11040. Parameter_unit = ""
  11041. });
  11042. items1.Add(new TestItem()
  11043. {
  11044. Parameter_name = "载具码",
  11045. Parameter_value = vehicleCodes[i],
  11046. Parameter_unit = ""
  11047. });
  11048. items1.Add(new TestItem()
  11049. {
  11050. Parameter_name = "载具穴号",
  11051. Parameter_value = "1",
  11052. Parameter_unit = ""
  11053. });
  11054. items1.Add(new TestItem()
  11055. {
  11056. Parameter_name = "产品结果",
  11057. Parameter_value = d3Result == 1 ? "OK" : "NG",
  11058. Parameter_unit = ""
  11059. });
  11060. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  11061. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  11062. results.Add(result1);
  11063. }
  11064. }
  11065. short result = 0;
  11066. if (results.All(a => a == 1))
  11067. result = 1;
  11068. else if (results.Contains(3))
  11069. result = 3;
  11070. else if (results.Contains(2))
  11071. result = 2;
  11072. else if (results.Contains(4))
  11073. result = 4;
  11074. else
  11075. result = 4;
  11076. stopwatch2.Stop();
  11077. // MES_Flag 为4MES报错
  11078. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11079. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11080. writeToPLC_Flag.Name = "d3MES_FLAG";
  11081. writeToPLC_Flag.Adress = 2463;
  11082. writeToPLC_Flag.Value = result;
  11083. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  11084. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  11085. }
  11086. catch (Exception ex)
  11087. {
  11088. stopwatch2.Restart();
  11089. // MES_Flag 为4上位机报错
  11090. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  11091. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11092. writeToPLC_Flag.Name = "d3MES_FLAG";
  11093. writeToPLC_Flag.Adress = 2463;
  11094. writeToPLC_Flag.Value = (short)4;
  11095. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  11096. string str = ex.StackTrace;
  11097. AddMessage_Station(stationNameStr, LogType.Error,
  11098. $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11099. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11100. stopwatch2.Stop();
  11101. }
  11102. stopwatch1.Stop();
  11103. AddMessage(LogType.Info,
  11104. stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11105. stopwatch2.ElapsedMilliseconds + "ms");
  11106. }
  11107. // 上次采集到的SN
  11108. //private string sn_S4_4进站接口 = string.Empty;
  11109. /// <summary>
  11110. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  11111. /// </summary>
  11112. private void S4_4进站接口(int plcNo, string stationNameStr)
  11113. {
  11114. Stopwatch stopwatch1 = new Stopwatch();
  11115. Stopwatch stopwatch2 = new Stopwatch();
  11116. try
  11117. {
  11118. stopwatch1.Start();
  11119. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  11120. sn = sn.Replace("\0", "");
  11121. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  11122. #region 查询15个载具码
  11123. List<string> vehicleCodes = new List<string>(); // 15个载具码
  11124. string vehicleData = string.Empty;
  11125. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  11126. if (string.IsNullOrEmpty(vehicleData))
  11127. vehicleData = "";
  11128. if (snResult != 0)
  11129. {
  11130. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11131. writeToPLC_Flag1.Name = "d3MES_FLAG";
  11132. writeToPLC_Flag1.Adress = 2463;
  11133. writeToPLC_Flag1.Value = (short)4;
  11134. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  11135. stopwatch1.Stop();
  11136. AddMessage(LogType.Info,
  11137. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11138. return;
  11139. }
  11140. string[] cavitySNs = vehicleData.Split('.');
  11141. if (cavitySNs != null && cavitySNs.Length > 0)
  11142. {
  11143. for (int i = 0; i < cavitySNs.Length; i++)
  11144. {
  11145. if (string.IsNullOrEmpty(cavitySNs[i]))
  11146. vehicleCodes.Add("");
  11147. else
  11148. vehicleCodes.Add(cavitySNs[i]);
  11149. }
  11150. }
  11151. #endregion 查询15个载具码
  11152. #region 查询15个产品SN
  11153. List<string> portNos = new List<string>(); // 15个产品SN
  11154. foreach (string vehicleCode in vehicleCodes)
  11155. {
  11156. if (string.IsNullOrEmpty(vehicleCode))
  11157. portNos.Add("");
  11158. else
  11159. {
  11160. // 查询
  11161. string cavityData = string.Empty;
  11162. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  11163. if (string.IsNullOrEmpty(cavityData))
  11164. cavityData = "";
  11165. if (snResult1 != 0)
  11166. {
  11167. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11168. writeToPLC_Flag1.Name = "d3MES_FLAG";
  11169. writeToPLC_Flag1.Adress = 2463;
  11170. writeToPLC_Flag1.Value = (short)4;
  11171. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  11172. stopwatch1.Stop();
  11173. AddMessage(LogType.Info,
  11174. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  11175. stopwatch1.ElapsedMilliseconds + "ms");
  11176. return;
  11177. }
  11178. string[] partSNs = cavityData.Split('.');
  11179. if (partSNs != null && partSNs.Length >= 1)
  11180. portNos.Add(partSNs[0]);
  11181. else
  11182. portNos.Add("");
  11183. }
  11184. }
  11185. #endregion 查询15个产品SN
  11186. // 调用MES进站(最多15个)
  11187. stopwatch2.Start();
  11188. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  11189. for (int i = 0; i < vehicleCodes.Count; i++)
  11190. {
  11191. // 循环进站
  11192. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  11193. {
  11194. // 产品SN(物料码)校验
  11195. string portNo = portNos[i];
  11196. List<TestItem> item = new List<TestItem>();
  11197. item.Add(new TestItem()
  11198. {
  11199. Parameter_name = "弹夹码",
  11200. Parameter_value = sn,
  11201. });
  11202. item.Add(new TestItem()
  11203. {
  11204. Parameter_name = "弹夹穴位",
  11205. Parameter_value = (i + 1).ToString(),
  11206. });
  11207. item.Add(new TestItem()
  11208. {
  11209. Parameter_name = "载具码",
  11210. Parameter_value = vehicleCodes[i],
  11211. });
  11212. item.Add(new TestItem()
  11213. {
  11214. Parameter_name = "载具穴号",
  11215. Parameter_value = "1",
  11216. });
  11217. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  11218. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  11219. }
  11220. }
  11221. stopwatch2.Stop();
  11222. short result = 0;
  11223. bool haveMesWarn = results.Contains(5);
  11224. bool havePCWarn = results.Contains(6);
  11225. if (haveMesWarn)
  11226. result = 2; // 5->2
  11227. else if (havePCWarn)
  11228. result = 6; // 6->4
  11229. else
  11230. result = 1;
  11231. // MES_Flag 为4MES报错
  11232. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11233. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11234. writeToPLC_Flag.Name = "d4MES_FLAG";
  11235. writeToPLC_Flag.Adress = 2496;
  11236. writeToPLC_Flag.Value = result;
  11237. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  11238. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  11239. }
  11240. catch (Exception ex)
  11241. {
  11242. stopwatch2.Stop();
  11243. // MES_Flag 为4上位机报错
  11244. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  11245. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11246. writeToPLC_Flag.Name = "d4MES_FLAG";
  11247. writeToPLC_Flag.Adress = 2496;
  11248. writeToPLC_Flag.Value = (short)4;
  11249. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  11250. string str = ex.StackTrace;
  11251. AddMessage_Station(stationNameStr, LogType.Error,
  11252. $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11253. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11254. }
  11255. stopwatch1.Stop();
  11256. AddMessage(LogType.Info,
  11257. stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  11258. stopwatch2.ElapsedMilliseconds + "ms");
  11259. }
  11260. // 上次采集到的SN
  11261. //private string sn_S4_4出站接口 = string.Empty;
  11262. /// <summary>
  11263. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  11264. /// </summary>
  11265. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  11266. {
  11267. Stopwatch stopwatch1 = new Stopwatch();
  11268. Stopwatch stopwatch2 = new Stopwatch();
  11269. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  11270. string stationNameStr = stationCode + stationName;
  11271. string processItem = stationName; // 测试项目
  11272. try
  11273. {
  11274. stopwatch1.Start();
  11275. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  11276. //string batch_num = GlobalContext.BatchNumber; // 批次号
  11277. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  11278. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  11279. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  11280. sn = sn.Replace("\0", "");
  11281. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  11282. bool isPass = d4Result == 1; // 产品结果 bool
  11283. #region 查询15个载具码
  11284. List<string> vehicleCodes = new List<string>(); // 15个载具码
  11285. string vehicleData = string.Empty;
  11286. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  11287. if (string.IsNullOrEmpty(vehicleData))
  11288. vehicleData = "";
  11289. if (snResult1 != 0)
  11290. {
  11291. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11292. writeToPLC_Flag1.Name = "d4MES_FLAG";
  11293. writeToPLC_Flag1.Adress = 2496;
  11294. writeToPLC_Flag1.Value = (short)4;
  11295. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  11296. stopwatch1.Stop();
  11297. AddMessage(LogType.Info,
  11298. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11299. return;
  11300. }
  11301. string[] cavitySNs = vehicleData.Split('.');
  11302. if (cavitySNs != null && cavitySNs.Length > 0)
  11303. {
  11304. for (int i = 0; i < cavitySNs.Length; i++)
  11305. {
  11306. if (string.IsNullOrEmpty(cavitySNs[i]))
  11307. vehicleCodes.Add("");
  11308. else
  11309. vehicleCodes.Add(cavitySNs[i]);
  11310. }
  11311. }
  11312. #endregion 查询15个载具码
  11313. // 统一查 产品SN列表
  11314. List<string> partNos = new List<string>();
  11315. foreach (string vehicleCode in vehicleCodes)
  11316. {
  11317. if (string.IsNullOrEmpty(vehicleCode))
  11318. partNos.Add("");
  11319. else
  11320. {
  11321. string partNo = "";
  11322. #region 查询载具上的产品信息
  11323. string cavityData = string.Empty;
  11324. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  11325. if (string.IsNullOrEmpty(cavityData))
  11326. cavityData = "";
  11327. if (snResult != 0)
  11328. {
  11329. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11330. writeToPLC_Flag1.Name = "d4MES_FLAG";
  11331. writeToPLC_Flag1.Adress = 2496;
  11332. writeToPLC_Flag1.Value = (short)4;
  11333. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  11334. stopwatch1.Stop();
  11335. AddMessage(LogType.Info,
  11336. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  11337. "ms");
  11338. return;
  11339. }
  11340. string[] partSNs = cavityData.Split('.');
  11341. if (partSNs != null && partSNs.Length >= 1)
  11342. partNo = partSNs[0];
  11343. #endregion 查询载具上的产品信息
  11344. partNos.Add(partNo);
  11345. }
  11346. }
  11347. // 调用MES出站
  11348. stopwatch2.Start();
  11349. // 统一上传
  11350. List<int> results = new List<int>();
  11351. for (int i = 0; i < partNos.Count; i++)
  11352. {
  11353. string index = (i + 1).ToString(); // 弹夹穴号
  11354. if (string.IsNullOrEmpty(partNos[i]))
  11355. results.Add(1);
  11356. else
  11357. {
  11358. List<TestItem> items1 = new List<TestItem>();
  11359. items1.Add(new TestItem()
  11360. {
  11361. Parameter_name = "弹夹码",
  11362. Parameter_value = sn,
  11363. Parameter_unit = ""
  11364. });
  11365. items1.Add(new TestItem()
  11366. {
  11367. Parameter_name = "弹夹穴号",
  11368. Parameter_value = index,
  11369. Parameter_unit = ""
  11370. });
  11371. items1.Add(new TestItem()
  11372. {
  11373. Parameter_name = "载具码",
  11374. Parameter_value = vehicleCodes[i],
  11375. Parameter_unit = ""
  11376. });
  11377. items1.Add(new TestItem()
  11378. {
  11379. Parameter_name = "载具穴号",
  11380. Parameter_value = "1",
  11381. Parameter_unit = ""
  11382. });
  11383. items1.Add(new TestItem()
  11384. {
  11385. Parameter_name = "产品结果",
  11386. Parameter_value = d4Result == 1 ? "OK" : "NG",
  11387. Parameter_unit = ""
  11388. });
  11389. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  11390. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  11391. results.Add(result1);
  11392. }
  11393. }
  11394. short result = 0;
  11395. if (results.All(a => a == 1))
  11396. result = 1;
  11397. else if (results.Contains(3))
  11398. result = 3;
  11399. else if (results.Contains(2))
  11400. result = 2;
  11401. else if (results.Contains(4))
  11402. result = 4;
  11403. else
  11404. result = 4;
  11405. stopwatch2.Stop();
  11406. // MES_Flag 为4MES报错
  11407. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11408. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11409. writeToPLC_Flag.Name = "d4MES_FLAG";
  11410. writeToPLC_Flag.Adress = 2496;
  11411. writeToPLC_Flag.Value = result;
  11412. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  11413. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  11414. }
  11415. catch (Exception ex)
  11416. {
  11417. stopwatch2.Restart();
  11418. // MES_Flag 为4上位机报错
  11419. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  11420. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11421. writeToPLC_Flag.Name = "d4MES_FLAG";
  11422. writeToPLC_Flag.Adress = 2496;
  11423. writeToPLC_Flag.Value = (short)4;
  11424. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  11425. string str = ex.StackTrace;
  11426. AddMessage_Station(stationNameStr, LogType.Error,
  11427. $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11428. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11429. stopwatch2.Stop();
  11430. }
  11431. stopwatch1.Stop();
  11432. AddMessage(LogType.Info,
  11433. stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11434. stopwatch2.ElapsedMilliseconds + "ms");
  11435. }
  11436. /// <summary>
  11437. /// [S4] 取放桁架 - S4_5弹夹扫码
  11438. /// </summary>
  11439. /// <param name="plcNo">PLC编号</param>
  11440. /// <param name="stationNameStr">工站全称</param>
  11441. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  11442. {
  11443. Stopwatch stopwatch1 = new Stopwatch();
  11444. Stopwatch stopwatch2 = new Stopwatch();
  11445. try
  11446. {
  11447. stopwatch1.Start();
  11448. // ZS 弹夹扫码
  11449. string d5BulletclipCode = " "; // 扫到的码
  11450. short d5BulletclipScanCode = 2;
  11451. stopwatch2.Start();
  11452. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  11453. //// MES_Flag
  11454. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  11455. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11456. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  11457. writeToPLC_Flag.Adress = 2528;
  11458. writeToPLC_Flag.Value = d5BulletclipScanCode;
  11459. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  11460. {
  11461. Name = "d5BulletclipCode",
  11462. Adress = 2529,
  11463. ValueType = PLCValueType.String,
  11464. ValueTypeStrLength = 20,
  11465. Value = d5BulletclipCode
  11466. });
  11467. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  11468. stopwatch2.Stop();
  11469. }
  11470. catch (Exception ex)
  11471. {
  11472. string str = ex.StackTrace;
  11473. AddMessage_Station(stationNameStr, LogType.Error,
  11474. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  11475. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11476. stopwatch2.Start();
  11477. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  11478. //// MES_Flag
  11479. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  11480. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11481. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  11482. writeToPLC_Flag.Adress = 2528;
  11483. writeToPLC_Flag.Value = (short)6;
  11484. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  11485. {
  11486. Name = "d5BulletclipCode",
  11487. Adress = 2529,
  11488. ValueType = PLCValueType.String,
  11489. ValueTypeStrLength = 20,
  11490. Value = " "
  11491. });
  11492. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  11493. stopwatch2.Stop();
  11494. }
  11495. stopwatch1.Stop();
  11496. AddMessage(LogType.Info,
  11497. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11498. stopwatch2.ElapsedMilliseconds + "ms");
  11499. }
  11500. /// <summary>
  11501. /// [S4] 取放桁架 - S4_5载具扫码
  11502. /// </summary>
  11503. /// <param name="plcNo">PLC编号</param>
  11504. /// <param name="stationNameStr">工站全称</param>
  11505. private void S4_5载具扫码(int plcNo, string stationNameStr)
  11506. {
  11507. Stopwatch stopwatch1 = new Stopwatch();
  11508. Stopwatch stopwatch2 = new Stopwatch();
  11509. try
  11510. {
  11511. stopwatch1.Start();
  11512. // ZS 载具扫码
  11513. string d5VehicleCode = " "; // 扫到的码
  11514. short d5VehicleScanCode = 2;
  11515. #region 进站
  11516. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  11517. {
  11518. // 查产品SN
  11519. #region 查询载具上的产品信息
  11520. string cavityData = string.Empty;
  11521. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  11522. if (string.IsNullOrEmpty(cavityData))
  11523. cavityData = "";
  11524. if (snResult != 0)
  11525. {
  11526. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11527. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  11528. writeToPLC_Flag1.Adress = 2559;
  11529. writeToPLC_Flag1.Value = (short)6;
  11530. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  11531. {
  11532. Name = "d5VehicleCode",
  11533. Adress = 2560,
  11534. ValueType = PLCValueType.String,
  11535. ValueTypeStrLength = 20,
  11536. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  11537. });
  11538. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  11539. stopwatch1.Stop();
  11540. AddMessage(LogType.Info,
  11541. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  11542. "ms");
  11543. return;
  11544. }
  11545. string[] cavitySNs = cavityData.Split('.');
  11546. string partNo = "";
  11547. if (cavitySNs != null && cavitySNs.Length >= 1)
  11548. {
  11549. partNo = cavitySNs[0];
  11550. }
  11551. #endregion 查询载具上的产品信息
  11552. List<TestItem> item = new List<TestItem>();
  11553. item.Add(new TestItem()
  11554. {
  11555. Parameter_name = "载具码",
  11556. Parameter_value = d5VehicleCode,
  11557. });
  11558. item.Add(new TestItem()
  11559. {
  11560. Parameter_name = "载具穴号",
  11561. Parameter_value = "1",
  11562. });
  11563. stopwatch2.Start();
  11564. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  11565. partNo, item, out string errorMsg);
  11566. stopwatch2.Stop();
  11567. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  11568. }
  11569. #endregion 进站
  11570. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  11571. //// MES_Flag
  11572. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  11573. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11574. writeToPLC_Flag.Name = "d5VehicleScanCode";
  11575. writeToPLC_Flag.Adress = 2559;
  11576. writeToPLC_Flag.Value = d5VehicleScanCode;
  11577. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  11578. {
  11579. Name = "d5VehicleCode",
  11580. Adress = 2560,
  11581. ValueType = PLCValueType.String,
  11582. ValueTypeStrLength = 20,
  11583. Value = d5VehicleCode
  11584. });
  11585. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  11586. }
  11587. catch (Exception ex)
  11588. {
  11589. string str = ex.StackTrace;
  11590. AddMessage_Station(stationNameStr, LogType.Error,
  11591. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  11592. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11593. stopwatch2.Start();
  11594. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  11595. //// MES_Flag
  11596. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  11597. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11598. writeToPLC_Flag.Name = "d5VehicleScanCode";
  11599. writeToPLC_Flag.Adress = 2559;
  11600. writeToPLC_Flag.Value = (short)6;
  11601. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  11602. {
  11603. Name = "d5VehicleCode",
  11604. Adress = 2560,
  11605. ValueType = PLCValueType.String,
  11606. ValueTypeStrLength = 20,
  11607. Value = " "
  11608. });
  11609. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  11610. stopwatch2.Stop();
  11611. }
  11612. stopwatch1.Stop();
  11613. AddMessage(LogType.Info,
  11614. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11615. stopwatch2.ElapsedMilliseconds + "ms");
  11616. }
  11617. // 上次采集到的SN
  11618. //private string sn_S4_5出站接口 = string.Empty;
  11619. /// <summary>
  11620. /// [S4] 取放桁架 - S4_5出站接口
  11621. /// </summary>
  11622. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  11623. {
  11624. Stopwatch stopwatch1 = new Stopwatch();
  11625. Stopwatch stopwatch2 = new Stopwatch();
  11626. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  11627. string stationNameStr = stationCode + stationName;
  11628. string processItem = stationName; // 测试项目
  11629. try
  11630. {
  11631. stopwatch1.Start();
  11632. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  11633. //string batch_num = GlobalContext.BatchNumber; // 批次号
  11634. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  11635. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  11636. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  11637. sn = sn.Replace("\0", "");
  11638. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  11639. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  11640. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  11641. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  11642. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  11643. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  11644. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  11645. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  11646. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  11647. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  11648. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  11649. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  11650. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  11651. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  11652. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  11653. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  11654. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  11655. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  11656. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  11657. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  11658. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  11659. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  11660. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  11661. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  11662. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  11663. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  11664. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  11665. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  11666. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  11667. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  11668. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  11669. bool pass = d5Result == 1;
  11670. // 存 载具SN列表
  11671. List<string> vehicleCodes = new List<string>()
  11672. {
  11673. d5VehicleCode1, d5VehicleCode2, d5VehicleCode3, d5VehicleCode4, d5VehicleCode5,
  11674. d5VehicleCode6, d5VehicleCode7, d5VehicleCode8, d5VehicleCode9, d5VehicleCode10,
  11675. d5VehicleCode11, d5VehicleCode12, d5VehicleCode13, d5VehicleCode14, d5VehicleCode15
  11676. };
  11677. // 统一查 产品SN列表
  11678. List<string> partNos = new List<string>();
  11679. foreach (string vehicleCode in vehicleCodes)
  11680. {
  11681. if (string.IsNullOrEmpty(vehicleCode))
  11682. partNos.Add("");
  11683. else
  11684. {
  11685. string partNo = "";
  11686. #region 查询载具上的产品信息
  11687. string cavityData = string.Empty;
  11688. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  11689. if (string.IsNullOrEmpty(cavityData))
  11690. cavityData = "";
  11691. if (snResult != 0)
  11692. {
  11693. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11694. writeToPLC_Flag1.Name = "d5MES_FLAG";
  11695. writeToPLC_Flag1.Adress = 2591;
  11696. writeToPLC_Flag1.Value = (short)4;
  11697. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  11698. stopwatch1.Stop();
  11699. AddMessage(LogType.Info,
  11700. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  11701. "ms");
  11702. return;
  11703. }
  11704. string[] cavitySNs = cavityData.Split('.');
  11705. if (cavitySNs != null && cavitySNs.Length >= 1)
  11706. partNo = cavitySNs[0];
  11707. #endregion 查询载具上的产品信息
  11708. partNos.Add(partNo);
  11709. }
  11710. }
  11711. // 统一上传
  11712. stopwatch2.Start();
  11713. List<int> results = new List<int>();
  11714. for (int i = 0; i < partNos.Count; i++)
  11715. {
  11716. string index = (i + 1).ToString(); // 弹夹穴号
  11717. if (string.IsNullOrEmpty(partNos[i]))
  11718. results.Add(1);
  11719. else
  11720. {
  11721. List<TestItem> items1 = new List<TestItem>();
  11722. items1.Add(new TestItem()
  11723. {
  11724. Parameter_name = "弹夹码",
  11725. Parameter_value = sn,
  11726. Parameter_unit = ""
  11727. });
  11728. items1.Add(new TestItem()
  11729. {
  11730. Parameter_name = "弹夹穴号",
  11731. Parameter_value = index,
  11732. Parameter_unit = ""
  11733. });
  11734. items1.Add(new TestItem()
  11735. {
  11736. Parameter_name = "载具码",
  11737. Parameter_value = vehicleCodes[i],
  11738. Parameter_unit = ""
  11739. });
  11740. items1.Add(new TestItem()
  11741. {
  11742. Parameter_name = "载具穴号",
  11743. Parameter_value = "1",
  11744. Parameter_unit = ""
  11745. });
  11746. items1.Add(new TestItem()
  11747. {
  11748. Parameter_name = "产品结果",
  11749. Parameter_value = d5Result == 1 ? "OK" : "NG",
  11750. Parameter_unit = ""
  11751. });
  11752. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  11753. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  11754. results.Add(result1);
  11755. }
  11756. }
  11757. short result = 0;
  11758. if (results.All(a => a == 1))
  11759. result = 1;
  11760. else if (results.Contains(3))
  11761. result = 3;
  11762. else if (results.Contains(2))
  11763. result = 2;
  11764. else if (results.Contains(4))
  11765. result = 4;
  11766. else
  11767. result = 4;
  11768. stopwatch2.Stop();
  11769. #region 存储绑定数据到 边线MES系统中
  11770. if (result == 1)
  11771. {
  11772. // 删除绑定信息
  11773. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  11774. if (resultMesR != 0)
  11775. {
  11776. result = 4;
  11777. AddMessage_Station(stationNameStr, LogType.Error,
  11778. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  11779. }
  11780. }
  11781. #endregion 存储绑定数据到 边线MES系统中
  11782. // MES_Flag 为4MES报错
  11783. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11784. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11785. writeToPLC_Flag.Name = "d5MES_FLAG";
  11786. writeToPLC_Flag.Adress = 2591;
  11787. writeToPLC_Flag.Value = result;
  11788. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  11789. OnMessage(LogType.Debug,
  11790. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  11791. }
  11792. catch (Exception ex)
  11793. {
  11794. stopwatch2.Restart();
  11795. // MES_Flag 为4上位机报错
  11796. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  11797. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11798. writeToPLC_Flag.Name = "d5MES_FLAG";
  11799. writeToPLC_Flag.Adress = 2591;
  11800. writeToPLC_Flag.Value = (short)4;
  11801. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  11802. stopwatch2.Stop();
  11803. string str = ex.StackTrace;
  11804. AddMessage_Station(stationNameStr, LogType.Error,
  11805. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11806. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11807. }
  11808. stopwatch1.Stop();
  11809. AddMessage(LogType.Info,
  11810. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11811. stopwatch2.ElapsedMilliseconds + "ms");
  11812. }
  11813. /// <summary>
  11814. /// [S4] 取放桁架 - S4_5节拍接口
  11815. /// </summary>
  11816. /// <param name="plcNo">PLC编号</param>
  11817. /// <param name="stationNameStr">工站全称</param>
  11818. private void S4_5节拍接口(int plcNo, string stationNameStr)
  11819. {
  11820. Stopwatch stopwatch1 = new Stopwatch();
  11821. Stopwatch stopwatch2 = new Stopwatch();
  11822. string resultStr = string.Empty;
  11823. try
  11824. {
  11825. stopwatch1.Start();
  11826. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  11827. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  11828. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  11829. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  11830. if (!actionBool)
  11831. {
  11832. stopwatch2.Start();
  11833. // MES_Flag
  11834. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  11835. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11836. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  11837. writeToPLC_Flag1.Adress = 2924;
  11838. writeToPLC_Flag1.Value = (short)4;
  11839. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  11840. stopwatch2.Stop();
  11841. AddMessage(LogType.Info,
  11842. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  11843. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  11844. return;
  11845. }
  11846. string d5OEEPartNo = string.Empty; // 物料码
  11847. if (string.IsNullOrEmpty(d5OEEProductSN))
  11848. {
  11849. stopwatch2.Start();
  11850. // MES_Flag
  11851. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11852. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11853. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  11854. writeToPLC_Flag1.Adress = 2924;
  11855. writeToPLC_Flag1.Value = (short)1;
  11856. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  11857. stopwatch2.Stop();
  11858. AddMessage(LogType.Info,
  11859. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11860. stopwatch2.ElapsedMilliseconds + "ms");
  11861. return;
  11862. }
  11863. else
  11864. {
  11865. // 查产品SN
  11866. d5OEEPartNo = "Test"; // ZS
  11867. }
  11868. short d5OEEMES_FLAG = 0;
  11869. // 上传OEE
  11870. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  11871. d5OEEMES_FLAG = result.Item1;
  11872. resultStr = result.Item2;
  11873. stopwatch2.Start();
  11874. // MES_Flag
  11875. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11876. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11877. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  11878. writeToPLC_Flag.Adress = 2924;
  11879. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  11880. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  11881. stopwatch2.Stop();
  11882. }
  11883. catch (Exception ex)
  11884. {
  11885. string str = ex.StackTrace;
  11886. AddMessage_Station(stationNameStr, LogType.Error,
  11887. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  11888. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11889. // MES_Flag
  11890. stopwatch2.Start();
  11891. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  11892. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11893. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  11894. writeToPLC_Flag.Adress = 2924;
  11895. writeToPLC_Flag.Value = (short)4;
  11896. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  11897. stopwatch2.Stop();
  11898. }
  11899. stopwatch1.Stop();
  11900. AddMessage(LogType.Info,
  11901. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11902. stopwatch2.ElapsedMilliseconds + "ms");
  11903. }
  11904. #endregion [S4] 取放桁架
  11905. #endregion PLC4 刘果段
  11906. #region PLC5 张超凡
  11907. #region [S5] Tray盘下料装备
  11908. /// <summary>
  11909. /// S5工位的数据- 触发信号上次的值
  11910. /// </summary>
  11911. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  11912. /// <summary>
  11913. /// S5工位的数据(含触发信号)
  11914. /// </summary>
  11915. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  11916. /// <summary>
  11917. /// S5工位的数据- 回写点位
  11918. /// </summary>
  11919. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  11920. /// <summary>
  11921. /// [S5] Tray盘下料装备
  11922. /// </summary>
  11923. /// <param name="plcNo">PLC编号</param>
  11924. //private void ReadStation_S5(int plcNo)
  11925. //{
  11926. // // [S1] Tray盘上料装备
  11927. // // [S2] FCT
  11928. // // [S3] 值板机
  11929. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  11930. // // [S5] Tray盘下料装备
  11931. // /// 上位机心跳
  11932. // /// 获取设备报警数据与状态信息
  11933. // string stationCode = "[S5]";
  11934. // string stationName = "Tray盘下料装备";
  11935. // string stationNameStr = stationCode + stationName;
  11936. // #region 创建字典
  11937. // // 触发信号字典 赋值
  11938. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  11939. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  11940. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  11941. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  11942. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  11943. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  11944. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  11945. // // PLC数据字典 赋值
  11946. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  11947. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  11948. // s5PLCData.Add("e1ProductSN_Check", ""); //
  11949. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  11950. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  11951. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  11952. // s5PLCData.Add("e1PartNo", ""); // 物料码
  11953. // s5PLCData.Add("e1Result", 0); // 产品结果
  11954. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  11955. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  11956. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  11957. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  11958. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  11959. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  11960. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  11961. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  11962. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  11963. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  11964. // #endregion 创建字典
  11965. // while (IsRun)
  11966. // {
  11967. // try
  11968. // {
  11969. // if (!GlobalContext._IsCon_Funs5)
  11970. // {
  11971. // UpdatePLCMonitor(1, plcNo, 0);
  11972. // continue;
  11973. // }
  11974. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  11975. // {
  11976. // Stopwatch stopwatch1 = new Stopwatch();
  11977. // Stopwatch stopwatch2 = new Stopwatch();
  11978. // stopwatch1.Start();
  11979. // stopwatch2.Start();
  11980. // #region 一次性读取所有数据
  11981. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  11982. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  11983. // int[] datas = data1.Concat(data2).ToArray();
  11984. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  11985. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  11986. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  11987. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  11988. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  11989. // s5PLCData["e1MES_FLAG"] = datas[35];
  11990. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  11991. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  11992. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  11993. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  11994. // s5PLCData["e1Result"] = datas[76];
  11995. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  11996. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  11997. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  11998. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  11999. // s5PLCData["e1OEEType"] = datas[109];
  12000. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  12001. // s5PLCData["e1AGVUpStart"] = datas[121];
  12002. // s5PLCData["e1AGVUpEnd"] = datas[122];
  12003. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  12004. // s5PLCData["e1AGVDownStart"] = datas[134];
  12005. // s5PLCData["e1AGVDownEnd"] = datas[135];
  12006. // #endregion 一次性读取所有数据
  12007. // stopwatch2.Stop();
  12008. // #region 回写操作,写后清空flag
  12009. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  12010. // #endregion 回写操作,写后清空flag
  12011. // #region 进站校验
  12012. // try
  12013. // {
  12014. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  12015. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  12016. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  12017. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  12018. // {
  12019. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  12020. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  12021. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  12022. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  12023. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  12024. // }
  12025. // }
  12026. // catch (Exception ex)
  12027. // {
  12028. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  12029. // string str = ex.StackTrace;
  12030. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12031. // }
  12032. // #endregion 进站校验
  12033. // #region 出站接口
  12034. // try
  12035. // {
  12036. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  12037. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  12038. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  12039. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  12040. // {
  12041. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  12042. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  12043. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  12044. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  12045. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  12046. // }
  12047. // }
  12048. // catch (Exception ex)
  12049. // {
  12050. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  12051. // string str = ex.StackTrace;
  12052. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12053. // }
  12054. // #endregion 出站接口
  12055. // #region 节拍接口
  12056. // try
  12057. // {
  12058. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  12059. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  12060. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  12061. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  12062. // {
  12063. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  12064. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  12065. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  12066. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  12067. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  12068. // }
  12069. // }
  12070. // catch (Exception ex)
  12071. // {
  12072. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  12073. // string str = ex.StackTrace;
  12074. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12075. // }
  12076. // #endregion 节拍接口
  12077. // #region AGV上料
  12078. // // AGV上料叫AGV信号
  12079. // try
  12080. // {
  12081. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  12082. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  12083. // if (e1AGVUpCall != e1AGVUpCallOld)
  12084. // {
  12085. // if (e1AGVUpCall == 1) // 0->1
  12086. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  12087. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  12088. // }
  12089. // }
  12090. // catch (Exception ex)
  12091. // {
  12092. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  12093. // string str = ex.StackTrace;
  12094. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12095. // }
  12096. // // AGV上料完成信号
  12097. // try
  12098. // {
  12099. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  12100. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  12101. // if (e1AGVUpEnd != e1AGVUpEndOld)
  12102. // {
  12103. // if (e1AGVUpEnd == 1) // 0->1
  12104. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  12105. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  12106. // }
  12107. // }
  12108. // catch (Exception ex)
  12109. // {
  12110. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  12111. // string str = ex.StackTrace;
  12112. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12113. // }
  12114. // #endregion AGV上料
  12115. // #region AGV下料
  12116. // // AGV下料叫agv信号
  12117. // try
  12118. // {
  12119. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  12120. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  12121. // if (e1AGVDownCall != e1AGVDownCallOld)
  12122. // {
  12123. // if (e1AGVDownCall == 1) // 0->1
  12124. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  12125. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  12126. // }
  12127. // }
  12128. // catch (Exception ex)
  12129. // {
  12130. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  12131. // string str = ex.StackTrace;
  12132. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12133. // }
  12134. // // AGV下料完成信号
  12135. // try
  12136. // {
  12137. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  12138. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  12139. // if (e1AGVDownEnd != e1AGVDownEndOld)
  12140. // {
  12141. // if (e1AGVDownEnd == 1) // 0->1
  12142. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  12143. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  12144. // }
  12145. // }
  12146. // catch (Exception ex)
  12147. // {
  12148. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  12149. // string str = ex.StackTrace;
  12150. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12151. // }
  12152. // #endregion AGV下料
  12153. // #region 心跳
  12154. // try
  12155. // {
  12156. // short states = 0;
  12157. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  12158. // }
  12159. // catch (Exception ex)
  12160. // {
  12161. // string str = ex.StackTrace;
  12162. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12163. // }
  12164. // #endregion 心跳
  12165. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  12166. // stopwatch1.Stop();
  12167. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  12168. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  12169. // }
  12170. // else
  12171. // {
  12172. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  12173. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  12174. // Funs[plcNo].Connect();
  12175. // }
  12176. // }
  12177. // catch (Exception ex)
  12178. // {
  12179. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  12180. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  12181. // Funs[plcNo].ReConnect();
  12182. // }
  12183. // Thread.Sleep(IntervalReadPLC);
  12184. // }
  12185. //}
  12186. /// <summary>
  12187. /// [S5] Tray盘下料装备 - 进站校验
  12188. /// </summary>
  12189. /// <param name="plcNo">PLC编号</param>
  12190. /// <param name="stationNameStr">工站全称</param>
  12191. private void S5进站校验(int plcNo, string stationNameStr)
  12192. {
  12193. Stopwatch stopwatch1 = new Stopwatch();
  12194. Stopwatch stopwatch2 = new Stopwatch();
  12195. try
  12196. {
  12197. stopwatch1.Start();
  12198. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  12199. sn = sn.Replace("\0", "");
  12200. // 获取产品SN By 载具码
  12201. #region 查询载具上的产品信息
  12202. string cavityData = string.Empty;
  12203. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  12204. if (string.IsNullOrEmpty(cavityData))
  12205. cavityData = "";
  12206. if (snResult != 0)
  12207. {
  12208. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  12209. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  12210. writeToPLC_Flag1.Adress = 2003;
  12211. writeToPLC_Flag1.Value = (short)6;
  12212. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  12213. stopwatch1.Stop();
  12214. AddMessage(LogType.Info,
  12215. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  12216. return;
  12217. }
  12218. string[] cavitySNs = cavityData.Split('.');
  12219. string partNo = string.Empty;
  12220. if (cavitySNs != null && cavitySNs.Length >= 1)
  12221. partNo = cavitySNs[0];
  12222. #endregion 查询载具上的产品信息
  12223. // 产品SN(物料码)校验
  12224. List<TestItem> item = new List<TestItem>();
  12225. item.Add(new TestItem()
  12226. {
  12227. Parameter_name = "载具码",
  12228. Parameter_value = sn,
  12229. });
  12230. item.Add(new TestItem()
  12231. {
  12232. Parameter_name = "载具穴号",
  12233. Parameter_value = "1",
  12234. });
  12235. stopwatch2.Start();
  12236. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  12237. partNo, item, out string errorMsg);
  12238. stopwatch2.Stop();
  12239. short e1MES_FLAG_Check = (short)result;
  12240. // MES_Flag
  12241. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  12242. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12243. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  12244. writeToPLC_Flag.Adress = 2003;
  12245. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  12246. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  12247. }
  12248. catch (Exception ex)
  12249. {
  12250. string str = ex.StackTrace;
  12251. AddMessage_Station(stationNameStr, LogType.Error,
  12252. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  12253. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12254. // MES_Flag
  12255. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  12256. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12257. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  12258. writeToPLC_Flag.Adress = 2003;
  12259. writeToPLC_Flag.Value = (short)6;
  12260. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  12261. }
  12262. stopwatch1.Stop();
  12263. AddMessage(LogType.Info,
  12264. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  12265. stopwatch2.ElapsedMilliseconds + "ms");
  12266. }
  12267. /// <summary>
  12268. /// [S5] Tray盘下料装备 - 出站接口
  12269. /// </summary>
  12270. /// <param name="plcNo"></param>
  12271. /// <param name="stationCode"></param>
  12272. /// <param name="stationName"></param>
  12273. private void S5出站接口(int plcNo, string stationCode, string stationName)
  12274. {
  12275. Stopwatch stopwatch1 = new Stopwatch();
  12276. Stopwatch stopwatch2 = new Stopwatch();
  12277. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  12278. string stationNameStr = stationCode + stationName;
  12279. string processItem = stationName; // 测试项目
  12280. try
  12281. {
  12282. stopwatch1.Start();
  12283. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  12284. //string batch_num = GlobalContext.BatchNumber; // 批次号
  12285. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  12286. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  12287. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  12288. sn = sn.Replace("\0", "");
  12289. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  12290. //partNo = partNo.Replace("\0", "");
  12291. #region 查询载具上的产品信息
  12292. string cavityData = string.Empty;
  12293. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  12294. if (string.IsNullOrEmpty(cavityData))
  12295. cavityData = "";
  12296. if (snResult != 0)
  12297. {
  12298. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  12299. writeToPLC_Flag1.Name = "e1MES_FLAG";
  12300. writeToPLC_Flag1.Adress = 2035;
  12301. writeToPLC_Flag1.Value = (short)4;
  12302. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  12303. stopwatch1.Stop();
  12304. AddMessage(LogType.Info,
  12305. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  12306. return;
  12307. }
  12308. string[] cavitySNs = cavityData.Split('.');
  12309. string partNo = string.Empty;
  12310. if (cavitySNs != null && cavitySNs.Length >= 1)
  12311. partNo = cavitySNs[0];
  12312. #endregion 查询载具上的产品信息
  12313. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  12314. bool pass = e1Result == 1;
  12315. stopwatch2.Start();
  12316. // 上传MES
  12317. List<TestItem> items = new List<TestItem>();
  12318. items.Add(new TestItem()
  12319. {
  12320. Parameter_name = "载具码",
  12321. Parameter_value = sn,
  12322. Parameter_unit = ""
  12323. });
  12324. items.Add(new TestItem()
  12325. {
  12326. Parameter_name = "载具穴号",
  12327. Parameter_value = "1",
  12328. Parameter_unit = ""
  12329. });
  12330. items.Add(new TestItem()
  12331. {
  12332. Parameter_name = "产品结果",
  12333. Parameter_value = e1Result == 1 ? "OK" : "NG",
  12334. Parameter_unit = ""
  12335. });
  12336. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  12337. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  12338. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  12339. short result = result1 == 1 ? (short)1 : (short)3;
  12340. stopwatch2.Stop();
  12341. #region 存储绑定数据到 边线MES系统中
  12342. if (result == 1)
  12343. {
  12344. // 删除绑定信息
  12345. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  12346. if (resultMesR != 0)
  12347. {
  12348. result = 4;
  12349. AddMessage_Station(stationNameStr, LogType.Error,
  12350. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  12351. }
  12352. }
  12353. #endregion 存储绑定数据到 边线MES系统中
  12354. // MES_Flag 为MES报错
  12355. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  12356. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  12357. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12358. writeToPLC_Flag.Name = "e1MES_FLAG";
  12359. writeToPLC_Flag.Adress = 2035;
  12360. writeToPLC_Flag.Value = result;
  12361. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  12362. OnMessage(LogType.Debug,
  12363. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  12364. }
  12365. catch (Exception ex)
  12366. {
  12367. stopwatch2.Restart();
  12368. // MES_Flag 为4上位机报错
  12369. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  12370. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12371. writeToPLC_Flag.Name = "e1MES_FLAG";
  12372. writeToPLC_Flag.Adress = 2035;
  12373. writeToPLC_Flag.Value = (short)4;
  12374. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  12375. stopwatch2.Stop();
  12376. string str = ex.StackTrace;
  12377. AddMessage_Station(stationNameStr, LogType.Error,
  12378. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  12379. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12380. }
  12381. stopwatch1.Stop();
  12382. AddMessage(LogType.Info,
  12383. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  12384. stopwatch2.ElapsedMilliseconds + "ms");
  12385. }
  12386. /// <summary>
  12387. /// [S5] Tray盘下料装备 - 节拍接口
  12388. /// </summary>
  12389. /// <param name="plcNo">PLC编号</param>
  12390. /// <param name="stationNameStr">工站全称</param>
  12391. //private void S5节拍接口(int plcNo, string stationNameStr)
  12392. //{
  12393. // Stopwatch stopwatch1 = new Stopwatch();
  12394. // Stopwatch stopwatch2 = new Stopwatch();
  12395. // string resultStr = string.Empty;
  12396. // try
  12397. // {
  12398. // stopwatch1.Start();
  12399. // string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  12400. // string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  12401. // e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  12402. // bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  12403. // if (!actionBool)
  12404. // {
  12405. // stopwatch2.Start();
  12406. // // MES_Flag
  12407. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  12408. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  12409. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  12410. // writeToPLC_Flag1.Adress = 2088;
  12411. // writeToPLC_Flag1.Value = (short)4;
  12412. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  12413. // stopwatch2.Stop();
  12414. // AddMessage(LogType.Info,
  12415. // stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  12416. // "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  12417. // return;
  12418. // }
  12419. // string e1OEEPartNo = string.Empty; // 物料码
  12420. // if (string.IsNullOrEmpty(e1OEEProductSN))
  12421. // {
  12422. // stopwatch2.Start();
  12423. // // MES_Flag
  12424. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  12425. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  12426. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  12427. // writeToPLC_Flag1.Adress = 2088;
  12428. // writeToPLC_Flag1.Value = (short)1;
  12429. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  12430. // stopwatch2.Stop();
  12431. // AddMessage(LogType.Info,
  12432. // stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12433. // stopwatch2.ElapsedMilliseconds + "ms");
  12434. // return;
  12435. // }
  12436. // else
  12437. // {
  12438. // // 查产品SN
  12439. // e1OEEPartNo = "Test"; // ZS
  12440. // }
  12441. // short e1OEEMES_FLAG = 0;
  12442. // // 上传OEE
  12443. // (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  12444. // e1OEEMES_FLAG = result.Item1;
  12445. // resultStr = result.Item2;
  12446. // stopwatch2.Start();
  12447. // // MES_Flag
  12448. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  12449. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12450. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  12451. // writeToPLC_Flag.Adress = 2088;
  12452. // writeToPLC_Flag.Value = e1OEEMES_FLAG;
  12453. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  12454. // stopwatch2.Stop();
  12455. // }
  12456. // catch (Exception ex)
  12457. // {
  12458. // string str = ex.StackTrace;
  12459. // AddMessage_Station(stationNameStr, LogType.Error,
  12460. // $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  12461. // str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12462. // // MES_Flag
  12463. // stopwatch2.Start();
  12464. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  12465. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12466. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  12467. // writeToPLC_Flag.Adress = 2088;
  12468. // writeToPLC_Flag.Value = (short)4;
  12469. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  12470. // stopwatch2.Stop();
  12471. // }
  12472. // stopwatch1.Stop();
  12473. // AddMessage(LogType.Info,
  12474. // stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12475. // stopwatch2.ElapsedMilliseconds + "ms");
  12476. //}
  12477. /// <summary>
  12478. /// [S5] Tray盘下料装备 - AGV上料叫agv
  12479. /// </summary>
  12480. /// <param name="plcNo">PLC编号</param>
  12481. /// <param name="stationNameStr">工站全称</param>
  12482. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  12483. {
  12484. Stopwatch stopwatch1 = new Stopwatch();
  12485. Stopwatch stopwatch2 = new Stopwatch();
  12486. try
  12487. {
  12488. stopwatch1.Start();
  12489. // ZS 呼叫AGV
  12490. short e1AGVUpCall = 2;
  12491. stopwatch2.Start();
  12492. // e1AGVUpCall
  12493. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  12494. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12495. writeToPLC_Flag.Name = "e1AGVUpCall";
  12496. writeToPLC_Flag.Adress = 2120;
  12497. writeToPLC_Flag.Value = e1AGVUpCall;
  12498. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  12499. stopwatch2.Stop();
  12500. }
  12501. catch (Exception ex)
  12502. {
  12503. string str = ex.StackTrace;
  12504. AddMessage_Station(stationNameStr, LogType.Error,
  12505. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  12506. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12507. // e1AGVUpCall
  12508. stopwatch2.Start();
  12509. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  12510. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12511. writeToPLC_Flag.Name = "e1AGVUpCall";
  12512. writeToPLC_Flag.Adress = 2120;
  12513. writeToPLC_Flag.Value = (short)4;
  12514. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  12515. stopwatch2.Stop();
  12516. }
  12517. stopwatch1.Stop();
  12518. AddMessage(LogType.Info,
  12519. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12520. stopwatch2.ElapsedMilliseconds + "ms");
  12521. }
  12522. /// <summary>
  12523. /// [S5] Tray盘下料装备 - AGV上料完成
  12524. /// </summary>
  12525. /// <param name="plcNo">PLC编号</param>
  12526. /// <param name="stationNameStr">工站全称</param>
  12527. private void S5AGV上料完成(int plcNo, string stationNameStr)
  12528. {
  12529. Stopwatch stopwatch1 = new Stopwatch();
  12530. Stopwatch stopwatch2 = new Stopwatch();
  12531. try
  12532. {
  12533. stopwatch1.Start();
  12534. // ZS AGV上料完成,让小车离开
  12535. short e1AGVUpEnd = 2;
  12536. stopwatch2.Start();
  12537. // e1AGVUpEnd
  12538. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  12539. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12540. writeToPLC_Flag.Name = "e1AGVUpEnd";
  12541. writeToPLC_Flag.Adress = 2122;
  12542. writeToPLC_Flag.Value = e1AGVUpEnd;
  12543. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  12544. stopwatch2.Stop();
  12545. }
  12546. catch (Exception ex)
  12547. {
  12548. string str = ex.StackTrace;
  12549. AddMessage_Station(stationNameStr, LogType.Error,
  12550. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  12551. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12552. // e1AGVUpEnd
  12553. stopwatch2.Start();
  12554. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  12555. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12556. writeToPLC_Flag.Name = "e1AGVUpEnd";
  12557. writeToPLC_Flag.Adress = 2122;
  12558. writeToPLC_Flag.Value = (short)4;
  12559. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  12560. stopwatch2.Stop();
  12561. }
  12562. stopwatch1.Stop();
  12563. AddMessage(LogType.Info,
  12564. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12565. stopwatch2.ElapsedMilliseconds + "ms");
  12566. }
  12567. /// <summary>
  12568. /// [S5] Tray盘下料装备 - AGV下料叫agv
  12569. /// </summary>
  12570. /// <param name="plcNo">PLC编号</param>
  12571. /// <param name="stationNameStr">工站全称</param>
  12572. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  12573. {
  12574. Stopwatch stopwatch1 = new Stopwatch();
  12575. Stopwatch stopwatch2 = new Stopwatch();
  12576. try
  12577. {
  12578. stopwatch1.Start();
  12579. // ZS 呼叫AGV
  12580. short e1AGVDownCall = 2;
  12581. stopwatch2.Start();
  12582. // e1AGVDownCall
  12583. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  12584. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12585. writeToPLC_Flag.Name = "e1AGVDownCall";
  12586. writeToPLC_Flag.Adress = 2133;
  12587. writeToPLC_Flag.Value = e1AGVDownCall;
  12588. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  12589. stopwatch2.Stop();
  12590. }
  12591. catch (Exception ex)
  12592. {
  12593. string str = ex.StackTrace;
  12594. AddMessage_Station(stationNameStr, LogType.Error,
  12595. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  12596. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12597. // e1AGVDownCall
  12598. stopwatch2.Start();
  12599. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  12600. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12601. writeToPLC_Flag.Name = "e1AGVDownCall";
  12602. writeToPLC_Flag.Adress = 2133;
  12603. writeToPLC_Flag.Value = (short)4;
  12604. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  12605. stopwatch2.Stop();
  12606. }
  12607. stopwatch1.Stop();
  12608. AddMessage(LogType.Info,
  12609. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12610. stopwatch2.ElapsedMilliseconds + "ms");
  12611. }
  12612. /// <summary>
  12613. /// [S5] Tray盘下料装备 - AGV下料完成
  12614. /// </summary>
  12615. /// <param name="plcNo">PLC编号</param>
  12616. /// <param name="stationNameStr">工站全称</param>
  12617. private void S5AGV下料完成(int plcNo, string stationNameStr)
  12618. {
  12619. Stopwatch stopwatch1 = new Stopwatch();
  12620. Stopwatch stopwatch2 = new Stopwatch();
  12621. try
  12622. {
  12623. stopwatch1.Start();
  12624. // ZS AGV上料完成,让小车离开
  12625. short e1AGVDownEnd = 2;
  12626. stopwatch2.Start();
  12627. // e1AGVDownEnd
  12628. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  12629. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12630. writeToPLC_Flag.Name = "e1AGVDownEnd";
  12631. writeToPLC_Flag.Adress = 2135;
  12632. writeToPLC_Flag.Value = e1AGVDownEnd;
  12633. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  12634. stopwatch2.Stop();
  12635. }
  12636. catch (Exception ex)
  12637. {
  12638. string str = ex.StackTrace;
  12639. AddMessage_Station(stationNameStr, LogType.Error,
  12640. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  12641. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12642. // e1AGVDownEnd
  12643. stopwatch2.Start();
  12644. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  12645. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12646. writeToPLC_Flag.Name = "e1AGVDownEnd";
  12647. writeToPLC_Flag.Adress = 2135;
  12648. writeToPLC_Flag.Value = (short)4;
  12649. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  12650. stopwatch2.Stop();
  12651. }
  12652. stopwatch1.Stop();
  12653. AddMessage(LogType.Info,
  12654. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12655. stopwatch2.ElapsedMilliseconds + "ms");
  12656. }
  12657. #endregion [S5] Tray盘下料装备
  12658. #endregion PLC5 张超凡
  12659. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  12660. /// <summary>
  12661. /// PLC读取到的数据 -添加数据
  12662. /// </summary>
  12663. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  12664. {
  12665. if (sxPlcData.ContainsKey(newKey))
  12666. sxPlcData[newKey] = newValue;
  12667. else
  12668. sxPlcData.Add(newKey, newValue);
  12669. }
  12670. /// <summary>
  12671. /// PLC需要写入的数据 -添加数据
  12672. /// </summary>
  12673. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey,
  12674. WriteToPLC_Flag newValue)
  12675. {
  12676. if (sxPLCWriteData.ContainsKey(newKey))
  12677. sxPLCWriteData[newKey] = newValue;
  12678. else
  12679. sxPLCWriteData.Add(newKey, newValue);
  12680. }
  12681. /// <summary>
  12682. /// PLC回写操作,写后清空flag
  12683. /// </summary>
  12684. /// <param name="modbusClient">modbus对象</param>
  12685. /// <param name="pLCReadDatas">读取到的数据字典</param>
  12686. /// <param name="pLCWriteDatas">需要写入的数据</param>
  12687. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas,
  12688. ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  12689. {
  12690. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  12691. {
  12692. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  12693. for (int i = 0; i < pLCWriteDatas.Count; i++)
  12694. {
  12695. string mesFlagName = pLCWriteDatas[i].Name;
  12696. int mesFlagAdress = pLCWriteDatas[i].Adress;
  12697. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  12698. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  12699. {
  12700. // 先回写数据
  12701. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  12702. for (int j = 0; j < writeToPLCDatas.Count; j++)
  12703. {
  12704. int mesDataAdress = writeToPLCDatas[j].Adress;
  12705. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  12706. switch (mesDataType)
  12707. {
  12708. case PLCValueType.Short:
  12709. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  12710. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  12711. break;
  12712. case PLCValueType.String:
  12713. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  12714. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  12715. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr,
  12716. mesDataValueStrLength);
  12717. break;
  12718. }
  12719. }
  12720. // 再回写信号
  12721. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  12722. // 存储读取数据的字典
  12723. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  12724. // 存储写入数据的字典 - 清空写入值
  12725. pLCWriteDatas[i].Value = (short)0;
  12726. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  12727. }
  12728. }
  12729. }
  12730. }
  12731. /// <summary>
  12732. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  12733. /// </summary>
  12734. /// <param name="no">3</param>
  12735. /// <param name="stationCode">设备编号</param>
  12736. /// <param name="stationNameStr">设备名称</param>
  12737. /// <param name="plcOrder">车间订单号</param>
  12738. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  12739. {
  12740. try
  12741. {
  12742. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  12743. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  12744. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  12745. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  12746. int result1 = 0;
  12747. switch (stationCode)
  12748. {
  12749. case 2:
  12750. case 3:
  12751. case 4:
  12752. case 6:
  12753. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  12754. break;
  12755. case 102:
  12756. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  12757. break;
  12758. case 103:
  12759. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  12760. break;
  12761. case 104:
  12762. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  12763. break;
  12764. case 106:
  12765. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  12766. break;
  12767. default:
  12768. // MES_Flag 为“6未找到正确设备编号”
  12769. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  12770. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  12771. return;
  12772. }
  12773. short result = result1 == 1 ? (short)1 : (short)2;
  12774. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  12775. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  12776. }
  12777. catch (Exception ex)
  12778. {
  12779. // MES_Flag 为2上位机报错
  12780. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  12781. string str = ex.StackTrace;
  12782. AddMessage_Station(stationNameStr, LogType.Error,
  12783. $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  12784. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12785. }
  12786. }
  12787. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  12788. #region UI刷新
  12789. /// <summary>
  12790. /// 更新商品信息的UI + 下发产品信息(SN)
  12791. /// </summary>
  12792. private void UpdateProductInfo()
  12793. {
  12794. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  12795. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  12796. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  12797. //txt_CurSupplierCode.Text = ""; // 供应商代号
  12798. }
  12799. /// <summary>
  12800. /// 更新PLC连接状态的UI
  12801. /// </summary>
  12802. /// <param name="no">PLC编号</param>
  12803. /// <param name="status">状态</param>
  12804. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  12805. {
  12806. if (this != null && !this.IsDisposed)
  12807. {
  12808. switch (imgNo)
  12809. {
  12810. case 1:
  12811. this.BeginInvoke(new Action(() => { picPLC.Image = imageListState.Images[status]; }));
  12812. break;
  12813. case 2:
  12814. this.BeginInvoke(new Action(() => { pictureBox2.Image = imageListState.Images[status]; }));
  12815. break;
  12816. case 3:
  12817. this.BeginInvoke(new Action(() => { pictureBox3.Image = imageListState.Images[status]; }));
  12818. break;
  12819. case 4:
  12820. this.BeginInvoke(new Action(() => { pictureBox4.Image = imageListState.Images[status]; }));
  12821. break;
  12822. case 5:
  12823. this.BeginInvoke(new Action(() => { pictureBox5.Image = imageListState.Images[status]; }));
  12824. break;
  12825. case 6:
  12826. this.BeginInvoke(new Action(() => { pictureBox6.Image = imageListState.Images[status]; }));
  12827. break;
  12828. case 7:
  12829. this.BeginInvoke(new Action(() => { pictureBox7.Image = imageListState.Images[status]; }));
  12830. break;
  12831. case 8:
  12832. this.BeginInvoke(new Action(() => { pictureBox8.Image = imageListState.Images[status]; }));
  12833. break;
  12834. default:
  12835. break;
  12836. }
  12837. }
  12838. Task.Run(() => // 更新PLC交互页的指示灯
  12839. {
  12840. try
  12841. {
  12842. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  12843. {
  12844. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  12845. }
  12846. }
  12847. catch
  12848. {
  12849. }
  12850. });
  12851. }
  12852. #endregion UI刷新
  12853. #region 日志
  12854. /// <summary>
  12855. /// 添加各工位运行日志(同步至PLC交互页面)
  12856. /// </summary>
  12857. /// <param name="stationNameStr">工站名称</param>
  12858. /// <param name="logType">日志类型</param>
  12859. /// <param name="message">日志内容</param>
  12860. /// <param name="snNumber">产品数字SN</param>
  12861. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  12862. {
  12863. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")))
  12864. {
  12865. AddMessage(logType, message); // 首页展示+日志记录
  12866. }
  12867. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  12868. {
  12869. StationName = stationNameStr,
  12870. SnNumber = snNumber,
  12871. Message = message,
  12872. CreateTime = DateTime.Now
  12873. };
  12874. // PLC交互页展示
  12875. Task.Run(() =>
  12876. {
  12877. try
  12878. {
  12879. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  12880. {
  12881. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  12882. }
  12883. }
  12884. catch
  12885. {
  12886. }
  12887. });
  12888. }
  12889. /// <summary>
  12890. /// 添加运行日志
  12891. /// </summary>
  12892. /// <param name="logType">日志类型</param>
  12893. /// <param name="message">日志内容</param>
  12894. public void AddMessage(LogType logType, string message)
  12895. {
  12896. OnMessage(logType, message);
  12897. string date = DateTime.Now.ToString("yyyy/MM/dd");
  12898. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  12899. string msgShow = time + "--> " + message + "\r\n";
  12900. try
  12901. {
  12902. this.BeginInvoke(new Action(() =>
  12903. {
  12904. systemLog.Rows.Insert(0, date, time, message);
  12905. if (systemLog.Rows.Count >= 100)
  12906. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  12907. }));
  12908. }
  12909. catch (Exception ex) { }
  12910. }
  12911. /// <summary>
  12912. /// 添加运行日志-保存
  12913. /// </summary>
  12914. /// <param name="logType">日志类型</param>
  12915. /// <param name="message">日志内容</param>
  12916. public void OnMessage(LogType logType, string msg)
  12917. {
  12918. MessageEvent?.Invoke(logType, msg);
  12919. }
  12920. /// <summary>
  12921. /// 保存PLC写入日志
  12922. /// </summary>
  12923. /// <param name="logType"></param>
  12924. /// <param name="logValue"></param>
  12925. private void WritePLCLog(LogType logType, string logValue)
  12926. {
  12927. switch ((int)logType)
  12928. {
  12929. case 0:
  12930. _PLCLogNet.WriteDebug(logValue);
  12931. break;
  12932. case 1:
  12933. _PLCLogNet.WriteInfo(logValue);
  12934. break;
  12935. case 2:
  12936. _PLCLogNet.WriteWarn(logValue);
  12937. break;
  12938. case 3:
  12939. _PLCLogNet.WriteError(logValue);
  12940. break;
  12941. default:
  12942. _PLCLogNet.WriteFatal(logValue);
  12943. break;
  12944. }
  12945. }
  12946. /// <summary>
  12947. /// IOT Mqtt回调方法- With DataId
  12948. /// </summary>
  12949. /// <param name="id"></param>
  12950. /// <param name="v"></param>
  12951. /// <param name="dataId"></param>
  12952. public void CallbackWithDataId(string id, string msg, string dataId)
  12953. {
  12954. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  12955. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  12956. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  12957. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  12958. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  12959. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  12960. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  12961. }
  12962. /// <summary>
  12963. /// AGV Mqtt回调方法- 记录Log并处理数据
  12964. /// </summary>
  12965. /// <param name="obj"></param>
  12966. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  12967. {
  12968. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  12969. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  12970. // 接收到的信息
  12971. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  12972. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  12973. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  12974. {
  12975. }
  12976. }
  12977. #endregion 日志
  12978. //private void button1_Click(object sender, EventArgs e)
  12979. //{
  12980. // OpenDailogFalg=true;
  12981. // if (OpenDailogFalg)
  12982. // {
  12983. // using (var dialog = new BandBarodeDialog())
  12984. // {
  12985. // string strCarrierBarcode = "N801A-003";
  12986. // dialog._CarrierBarcode = strCarrierBarcode;
  12987. // string sn = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  12988. // dialog._ProductBarcode = sn;
  12989. // var rs = dialog.ShowDialog();
  12990. // if (rs == DialogResult.OK)
  12991. // {
  12992. // AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  12993. // OpenDailogFalg = false;//关闭扫码
  12994. // }
  12995. // }
  12996. // }
  12997. //}
  12998. }
  12999. }