123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291 |
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Linq;
- //using System.Text;
- using Microsoft.Win32;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using HslCommunication.LogNet;
- using MainForm.FaForm;
- using Sunny.UI;
- using MainForm.ClassFile.XiaomiAPI;
- using System.Diagnostics;
- using MainForm.Models;
- using SqlSugar;
- using EasyModbus;
- using ModBusClientSimple.Util;
- using csharp_networkprotocol_hpsocket;
- using MqttnetServerWin;
- using Sunny.UI.Win32;
- using MainForm.ClassFile.XiaomiAPI_AGV;
- using MainForm.ClassFile.XiaomiAPI_RouteCom;
- using HslCommunication.Controls;
- using EIP_Protocol;
- using MainForm.ClassFile.XiaomiAPI_MES;
- using NPOI.Util;
- using static MainForm.SQLHelper;
- using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
- using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
- using MainForm.ClassFile.ProjectClass;
- using CommonLib;
- using Org.BouncyCastle.Asn1.IsisMtt;
- using System.Web.Services.Description;
- using System.Numerics;
- using MathNet.Numerics.RootFinding;
- using HslCommunication.Enthernet;
- using BZFAStandardLib;
- using MainForm.ClassFile;
- using NPOI.SS.Formula.Functions;
- using static MainForm.ClassFile.XiaomiAPI.XiaomiMqttClient_Extend;
- using System.Net.Http;
- using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_UpLoadFile;
- using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
- using System.Reflection;
- using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
- using FaFrameUI;
- using System.Security.Policy;
- using static MainForm.ClassFile.XiaomiClass.MesHelper;
- using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
- using System.Drawing.Imaging;
- using System.Drawing;
- using ICSharpCode.SharpZipLib.Zip;
- using System.Text.RegularExpressions;
- /*
- * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
- */
- namespace MainForm
- {
- /// <summary>
- /// 记录日志的委托
- /// </summary>
- /// <param name="logType">日志类型</param>
- /// <param name="message">日志信息</param>
- public delegate void HomeMessageHandler(LogType logType, string message);
- /// <summary>
- /// 主页窗体
- /// </summary>
- public partial class Form_Home : Form
- {
- #region 常量
- //文本常量
- private const string Head = "开始采集";
- private const string Tail = "采集完成";
- private const string Body = "工位出站数据";
- private const string BodyCheck = "工位点检数据";
- private const string BodyRun = "整线运行数据";
- private const string BodyAlarm = "整线报警数据";
- #endregion 常量
- #region 变量
- /// <summary>
- /// 委托-记录日志的方法
- /// </summary>
- public event HomeMessageHandler MessageEvent;
- /// <summary>
- /// 日志接口
- /// </summary>
- ILogNet _PLCLogNet;
- /// <summary>
- /// 用于记录IOT MQTT日志
- /// </summary>
- ILogNet _IOTMqttLogNet;
- /// <summary>
- /// 用于记录AGV MQTT日志
- /// </summary>
- ILogNet _AGVMqttLogNet;
- //private int DataSwitch = 1; // 1-SQLServer;2-Excel
- // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
- // 间隔时间
- private int IntervalReadPLC = 300; //ms 读PLC
- private int IntervalMonitorMES = 1000; //ms MES心跳
- private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
- /// <summary>
- /// 设备报警数据
- /// </summary>
- uint[] _FaultDatas = { };
- uint[] _FaultDatas_Old = { };
- uint[] _FaultDatas2 = { };
- uint[] _FaultDatas_Old2 = { };
- // 软件状态
- private bool IsRun = true;
- #region PLC 与 TCP对象
- // 定义一个字典,存plc对象(通讯)
- ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
- Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
- // 定义TCPClient对象列表
- Dictionary<int, HPSocket_TcpClientHelper>
- _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
- // 定义MQTTHelper对象
- MQTTHelper _MQTTHelper = new MQTTHelper();
- #endregion PLC 与 TCP对象
- /// <summary>
- /// 上次的设备运行信息
- /// </summary>
- private string lineWorkingData1_OldStr = string.Empty;
- /// <summary>
- /// 设备报警字典-当前结果
- /// Dictionary<工位代码,List<报警信息>>
- /// </summary>
- private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
- Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
- /// <summary>
- /// 单机用-设备状态
- /// </summary>
- //XiaomiDeviceState xmDeviceState = XiaomiDeviceState.Uninitialized;
- XiaomiDeviceStateData xmDeviceStateData = new XiaomiDeviceStateData();
- private int test_item_num = 0; //iot 过站数据序号
- public static string uuid = "";
- private bool inpass = false; //保存进站测试状态
- public static XiaoMiParm xiaomiParm = new XiaoMiParm();
- //记录上传附件的信息
- public static FileUpload_FileData fileUploadData = new FileUpload_FileData();
- #endregion 变量
- #region 窗体基础事件
- /// <summary>
- /// 初始化
- /// </summary>
- public Form_Home()
- {
- InitializeComponent();
- CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
- _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
- _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
- _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
- GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
- }
- /// <summary>
- /// 窗体加载事件
- /// </summary>
- public void Form_Home_Load(object sender, EventArgs e)
- {
- try
- {
- AddMessage(LogType.Info, "开始初始化程序");
- //组建plc对象字典
- //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
- //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
- if (GlobalContext.IsUsePLC1)
- {
- GlobalContext.IsUsePLCNow = 1;
- GlobalContext.IsUseStationName = "[OP10]壳体清洁上料";
- FunsEip.Add(GlobalContext.IsUsePLCNow,
- new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
- }
- if (GlobalContext.IsUsePLC2)
- {
- GlobalContext.IsUsePLCNow = 2;
- GlobalContext.IsUseStationName = "[OP20]上盖板上料装备";
- FunsEip.Add(GlobalContext.IsUsePLCNow,
- new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
- }
- if (GlobalContext.IsUsePLC3)
- {
- GlobalContext.IsUsePLCNow = 3;
- GlobalContext.IsUseStationName = "[OP30]点散热胶装备";
- FunsEip.Add(GlobalContext.IsUsePLCNow,
- new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
- }
- if (GlobalContext.IsUsePLC4)
- {
- GlobalContext.IsUsePLCNow = 4;
- GlobalContext.IsUseStationName = "[OP40]胶线检测";
- FunsEip.Add(GlobalContext.IsUsePLCNow,
- new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
- }
- if (GlobalContext.IsUsePLC5)
- {
- GlobalContext.IsUsePLCNow = 5;
- GlobalContext.IsUseStationName = "[OP50]ADD板上料组装装备";
- FunsEip.Add(GlobalContext.IsUsePLCNow,
- new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
- }
- if (GlobalContext.IsUsePLC6)
- {
- GlobalContext.IsUsePLCNow = 6;
- GlobalContext.IsUseStationName = "[OP70]组上盖板";
- FunsEip.Add(GlobalContext.IsUsePLCNow,
- new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
- }
- if (GlobalContext.IsUsePLC7)
- {
- GlobalContext.IsUsePLCNow = 7;
- GlobalContext.IsUseStationName = "[OP80]上盖板锁螺丝";
- FunsEip.Add(GlobalContext.IsUsePLCNow,
- new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
- }
- if (GlobalContext.IsUsePLC8)
- {
- GlobalContext.IsUsePLCNow = 8;
- GlobalContext.IsUseStationName = "[OP90]NG下料";
- FunsEip.Add(GlobalContext.IsUsePLCNow,
- new Inovance_EIP(GlobalContext.PC8Address,
- GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
- }
- if (GlobalContext.IsUsePLC9)
- {
- GlobalContext.IsUsePLCNow = 9;
- GlobalContext.IsUseStationName = "[OP100]半成品下料";
- FunsEip.Add(GlobalContext.IsUsePLCNow,
- new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
- }
- (bool, string) DicResult = InitalDicAlarm(); // 实例化报警字典
- AddMessage(LogType.Info, DicResult.Item2);
- foreach (Inovance_EIP plcEIP in FunsEip.Values)
- {
- if (plcEIP != null)
- {
- try
- {
- (int, string) result = plcEIP.Connect();
- }
- catch (Exception ex)
- {
- MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
- "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
- MessageBoxOptions.ServiceNotification);
- }
- }
- }
- // 采集任务
- Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
- List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
- //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
- if (GlobalContext.IsUsePLC1)
- TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
- if (GlobalContext.IsUsePLC2)
- TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
- if (GlobalContext.IsUsePLC3)
- TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
- if (GlobalContext.IsUsePLC4)
- TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
- if (GlobalContext.IsUsePLC5)
- TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
- if (GlobalContext.IsUsePLC6)
- TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
- if (GlobalContext.IsUsePLC7)
- TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
- if (GlobalContext.IsUsePLC8)
- TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
- if (GlobalContext.IsUsePLC9)
- TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
- #region 初始化
- try
- {
- // 开启MES(Http)
- if (GlobalContext.IsUseMES)
- {
- bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
- if (mesret)
- {
- picMESStatus.Image = imageListState.Images[1];
- GlobalContext.MESIsConnect = true;
- AddMessage(LogType.Info, "小米MES初始连接成功!");
- }
- else
- {
- picMESStatus.Image = imageListState.Images[0];
- GlobalContext.MESIsConnect = false;
- AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
- }
- }
- // 开启IOT(MQTT)
- if (GlobalContext.IsUseIot)
- {
- string addr = GlobalContext.MQTTServerHost;
- int port = GlobalContext.MQTTServerPort;
- //生产环境需要修改
- (int, string) qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666,
- GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
- XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult.Item1;
- if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
- {
- picIot.Image = imageListState.Images[1];
- AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
- // 设置回调函数
- //XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
- // 配置参数
- XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
- // fds
- param.parameter.fds.address = GlobalContext.address;
- param.parameter.fds.appId = GlobalContext.appId;
- param.parameter.fds.appKey = GlobalContext.appKey;
- // mes
- param.parameter.mes.address = GlobalContext.ServerIp;
- param.parameter.mes.appId = GlobalContext.MESAppId;
- param.parameter.mes.appKey = GlobalContext.MESAppKey;
- // mqtt
- param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
- param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
- param.parameter.mqtt.username = GlobalContext.MQTTAppId;
- param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
- // 设备配置
- param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
- if (GlobalContext.IsUsePLC1)
- {
- param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
- xiaomiParm.workstation = GlobalContext.S1_work_station; //工站
- }
- if (GlobalContext.IsUsePLC2)
- {
- param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
- xiaomiParm.workstation = GlobalContext.S2_work_station; //工站
- }
- if (GlobalContext.IsUsePLC3)
- {
- param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
- //param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
- }
- if (GlobalContext.IsUsePLC4)
- {
- param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
- xiaomiParm.workstation = GlobalContext.s4_work_station; //工站
- }
- if (GlobalContext.IsUsePLC5)
- {
- param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
- xiaomiParm.workstation = GlobalContext.s5_work_station; //工站
- }
- if (GlobalContext.IsUsePLC6)
- {
- param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
- xiaomiParm.workstation = GlobalContext.s6_work_station; //工站
- }
- if (GlobalContext.IsUsePLC7)
- {
- param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
- //param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
- xiaomiParm.stationCode = GlobalContext.s7_1_station;
- }
- if (GlobalContext.IsUsePLC8)
- {
- param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
- xiaomiParm.workstation = GlobalContext.s8_work_station; //工站
- }
- if (GlobalContext.IsUsePLC9)
- {
- param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
- xiaomiParm.workstation = GlobalContext.s9_work_station; //工站
- }
- param.parameter.equipment.project = GlobalContext.Project_Code;
- param.parameter.equipment.productMode = "debug";
- param.parameter.other.logLevel = 0;
- param.parameter.other.LogPath = GlobalContext.MqttLogDir;
- XiaomiMqttClient_Extend.ParameterConfig(param);
- //保存全局变量
- xiaomiParm.stationCode = param.parameter.equipment.stationCode;
- xiaomiParm.deviceCode = param.parameter.equipment.deviceCode;
- }
- else
- {
- picIot.Image = imageListState.Images[0];
- AddMessage(LogType.Info,
- $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
- }
- }
- // 开启AGV(Http与MQTT)
- if (GlobalContext.IsUseAGV)
- {
- // AGV HTTP
- bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
- if (mesret1)
- {
- picAgvHttp.Image = imageListState.Images[1];
- AddMessage(LogType.Info, "AGV Http初始连接成功!");
- }
- else
- {
- picAgvHttp.Image = imageListState.Images[0];
- AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
- }
- string agvMqttIp = GlobalContext.MQTTServerHost;
- int agvMqttPort = GlobalContext.MQTTServerPort;
- Action<ResultData_MQTT> callback = AGVMqttShowLog;
- ResultData_MQTT result_MQTT = _MQTTHelper
- .CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
- // AGV MQTT
- if (result_MQTT.ResultCode == 1)
- {
- picAgvMqtt.Image = imageListState.Images[1];
- GlobalContext.AGVMQTTIsConnect = true;
- AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
- ResultData_MQTT result =
- XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
- AddMessage(LogType.Info,
- $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
- }
- else
- {
- picAgvMqtt.Image = imageListState.Images[0];
- GlobalContext.AGVMQTTIsConnect = false;
- AddMessage(LogType.Info,
- $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
- }
- }
- // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
- Task.Run(MonitorMESConnect);
- // 查询PLC连接状态
- foreach (int plcNo in FunsEip.Keys)
- {
- bool connected = FunsEip[plcNo].IsConnected;
- if (connected)
- {
- string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
- AddMessage(LogType.Info, msg);
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
- }
- else
- {
- string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
- AddMessage(LogType.Info, msg);
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- }
- }
- // PLC4时 初始化扫码器TCP
- //if (GlobalContext.IsUsePLC4)
- // HpTCPClientInit();
- // 开启PLC的业务处理线程-监听PLC点位+状态
- foreach (Task task in TaskReadProcess)
- {
- if (task != null)
- task.Start();
- }
- //// 开启iot的线程
- TaskReadAlarm.Start();
- ////下传MES信息给1工位(先判断下plc对象数量)
- //if (Funs.Count > 1)
- // DownLoadProductInfo(1);
- if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
- {
- state_l.Text = "设备状态(左):";
- state_r.Text = "设备状态(右):";
- state_r.Visible = true;
- lblDeviceStates2.Visible = true;
- }
- //上传操作记录
- operateToIot("startup", "开启");
- AddMessage(LogType.Info, "程序初始化完成");
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- this.BeginInvoke(new Action(() =>
- {
- AddMessage(LogType.Error,
- "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
- str.Length - str.LastIndexOf("\\") - 1));
- }));
- }
- #endregion
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- OnMessage(LogType.Info,
- "主窗体的首页初始化出错!异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" +
- ex.Message.ToString());
- if (ex.Message != null && ex.Message.Contains("timed out"))
- MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
- else
- MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
- }
- }
- /// <summary>
- /// 窗体关闭事件
- /// </summary>
- private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
- {
- Closed2();
- }
- public void Closed2()
- {
- try
- {
- IsRun = false;
- Thread.Sleep(IntervalReadPLC);
- // 断开TCP
- int count = _HPSocket_TcpClients.Count();
- for (int i = 0; i < count; i++)
- {
- try
- {
- if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
- {
- _HPSocket_TcpClients[i].Stop();
- _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
- _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
- _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
- _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
- _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
- }
- }
- catch
- {
- }
- }
- // 关闭Iot
- try
- {
- XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath,
- GlobalContext.MqttServerName);
- }
- catch
- {
- }
- // 关闭AGV Mqtt
- try
- {
- _MQTTHelper.DisconnectAsync_Client().Wait();
- }
- catch
- {
- }
- }
- catch
- {
- }
- }
- #endregion 窗体基础事件
- #region 监控MES状态
- /// <summary>
- /// 监控MES连接状态
- /// </summary>
- private void MonitorMESConnect()
- {
- while (IsRun) // 运行被控线程
- {
- try
- {
- // 开启MES(Http)
- if (GlobalContext.IsUseMES)
- {
- bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
- if (mesret)
- {
- picMESStatus.Image = imageListState.Images[1];
- GlobalContext.MESIsConnect = true;
- }
- else
- {
- picMESStatus.Image = imageListState.Images[0];
- GlobalContext.MESIsConnect = false;
- OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
- }
- }
- // 开启IOT(MQTT)
- if (GlobalContext.IsUseIot)
- {
- bool iIot = XiaomiMqttClient.IsOpen;
- if (iIot)
- picIot.Image = imageListState.Images[1];
- else
- {
- picIot.Image = imageListState.Images[0];
- OnMessage(LogType.Info,
- $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
- }
- }
- // 开启AGV(Http与MQTT)
- if (GlobalContext.IsUseAGV)
- {
- // AGV Http
- bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
- if (mesret1)
- picAgvHttp.Image = imageListState.Images[1];
- else
- {
- picAgvHttp.Image = imageListState.Images[0];
- OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
- }
- // AGV MQTT
- if (GlobalContext.AGVMQTTIsConnect)
- picAgvMqtt.Image = imageListState.Images[1];
- else
- {
- picAgvMqtt.Image = imageListState.Images[0];
- OnMessage(LogType.Info,
- $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
- }
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage(LogType.Error,
- "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
- str.Length - str.LastIndexOf("\\") - 1));
- }
- Thread.Sleep(IntervalMonitorMES);
- }
- }
- #endregion 监控MES连接状态
- #region 采集设备状态、运行数据、报警数据
- /// <summary>
- /// 请求设备状态 5000
- /// </summary>
- /// <param name="no">1</param>
- /// <param name="stationNameStr"></param>
- /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
- public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
- {
- try
- {
- if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
- return result;
- }
- else
- {
- return 0;
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
- str.Length - str.LastIndexOf("\\") - 1));
- return 0;
- }
- }
- /// <summary>
- /// 检查是否可采集点检数据 - 不取新值
- /// 5000不为1时可点检
- /// </summary>
- /// <returns></returns>
- public bool CheckCanSpotcheck1(int deviceState)
- {
- //return true;
- //D5000 = 1,代表设备控制状态处于运行状态
- //D5000 = 2, 代表设备控制状态处于故障状态
- //D5000 = 3,代表设备控制状态处于缺料状态
- //D5000 = 4, 代表设备控制状态处于待机状态
- //D5000 = 5,代表设备控制状态处于维修状态
- return deviceState != 1;
- }
- /// <summary>
- /// 检查是否可采集产品数据 - 不取新值
- /// </summary>
- /// <returns></returns>
- public bool CheckCanCollData(int deviceState)
- {
- return deviceState == 0; // 点检时该值不为0
- }
- /// <summary>
- /// 采集到的设备状态
- /// </summary>
- private string _DeviceStates = "未知状态";
- private string _DeviceStates_Old = "未知状态";
- private string _DeviceStates2 = "未知状态";
- private string _DeviceStates_Old2 = "未知状态";
- /// <summary>
- /// 获取设备报警数据与获取设备运行信息
- /// </summary>
- private async void ReadAlarmAllPLC()
- {
- /// 获取设备报警数据与状态信息
- string stationNameStr = "获取设备报警数据与状态信息";
- // 已连接到PLC
- while (IsRun)
- {
- try
- {
- #region 报警数据
- try
- {
- //_FaultDatas = new uint[] { 4, 0, 30, 10 };
- if (_FaultDatas.Length > 0)
- {
- ReadPLCAlarmToIot(_FaultDatas, _FaultDatas_Old, stationNameStr);
- }
- else
- {
- AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!");
- }
- if (_FaultDatas2.Length > 0)
- {
- ReadPLCAlarmToIot(_FaultDatas2, _FaultDatas_Old2, stationNameStr);
- }
- else
- {
- AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!");
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"【报警日志】{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 报警数据
- #region 设备状态
- //if (!GlobalContext._IsCon_plc1Alarm)
- //{
- // UpdatePLCMonitor(1, -2, 0);
- // continue;
- //}
- foreach (Inovance_EIP plcEIP in FunsEip.Values)
- {
- if (plcEIP != null)
- {
- if (plcEIP.IsConnected)
- {
- #region 主页展示设备运行状态并上传到IOT中,有双工位left就是左工位,没有双工位left就是单工位
- switch (xmDeviceStateData.left)
- {
- case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
- _DeviceStates = "未初始化状态";
- lblDeviceStates.Text = _DeviceStates;
- break;
- case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
- _DeviceStates = "初始化状态";
- lblDeviceStates.Text = _DeviceStates;
- break;
- case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
- _DeviceStates = "初始化完成状态";
- lblDeviceStates.Text = _DeviceStates;
- break;
- case XiaomiDeviceState.Running: // 运行状态(正常运行中)
- _DeviceStates = "运行状态";
- lblDeviceStates.Text = _DeviceStates;
- break;
- case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
- _DeviceStates = "暂停状态";
- lblDeviceStates.Text = _DeviceStates;
- break;
- case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
- _DeviceStates = "故障状态";
- lblDeviceStates.Text = _DeviceStates;
- break;
- case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
- _DeviceStates = "警报状态";
- lblDeviceStates.Text = _DeviceStates;
- break;
- }
- if (!_DeviceStates.Equals(_DeviceStates_Old))
- {
- var iotResult =
- SaveDeviceStateData(stationNameStr, xmDeviceStateData.left, "left"); // 上传+保存
- if (iotResult.Item1 == 1)
- {
- _DeviceStates_Old = _DeviceStates;
- AddMessage_Station(stationNameStr, LogType.Info,
- "【设备状态】" + stationNameStr + $"_上传设备状态到Iot成功!");
- }
- else
- AddMessage_Station(stationNameStr, LogType.Info,
- "【设备状态】" + stationNameStr +
- $"_上传设备状态到Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
- }
- #endregion 主页展示设备运行状态并上传到IOT中
- #region 右工位
- if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
- {
- switch (xmDeviceStateData.right)
- {
- case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
- _DeviceStates2 = "未初始化状态";
- lblDeviceStates.Text = _DeviceStates2;
- break;
- case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
- _DeviceStates2 = "初始化状态";
- lblDeviceStates.Text = _DeviceStates2;
- break;
- case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
- _DeviceStates2 = "初始化完成状态";
- lblDeviceStates.Text = _DeviceStates2;
- break;
- case XiaomiDeviceState.Running: // 运行状态(正常运行中)
- _DeviceStates2 = "运行状态";
- lblDeviceStates.Text = _DeviceStates2;
- break;
- case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
- _DeviceStates2 = "暂停状态";
- lblDeviceStates.Text = _DeviceStates2;
- break;
- case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
- _DeviceStates2 = "故障状态";
- lblDeviceStates.Text = _DeviceStates2;
- break;
- case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
- _DeviceStates2 = "警报状态";
- lblDeviceStates.Text = _DeviceStates2;
- break;
- }
- if (!_DeviceStates2.Equals(_DeviceStates_Old2))
- {
- var iotResult = SaveDeviceStateData(stationNameStr, xmDeviceStateData.left,
- "right"); // 上传+保存
- if (iotResult.Item1 == 1)
- {
- _DeviceStates_Old2 = _DeviceStates2;
- AddMessage_Station(stationNameStr, LogType.Info,
- "【设备状态】" + stationNameStr + $"_上传Iot成功!");
- }
- else
- AddMessage_Station(stationNameStr, LogType.Info,
- "【设备状态】" + stationNameStr +
- $"_上传Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
- }
- }
- #endregion 右工位
- }
- }
- }
- #endregion
- //if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
- //{
- // DateTime dtNow = DateTime.Now;
- // //#region 获取设备运行信息
- // //try
- // //{
- // // LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
- // // lineWorkingData1.GUID = Guid.NewGuid().ToString();
- // // lineWorkingData1.LineName = GlobalContext.LineCode;
- // // //
- // // lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
- // // lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
- // // lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
- // // lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
- // // lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
- // // lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
- // // lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
- // // lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
- // // lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
- // // lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
- // // lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
- // // lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
- // // lineWorkingData1.CreateTime = DateTime.Now;
- // // string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
- // // // UI展示-展示到设备状态页
- // // if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
- // // {
- // // // 查询数据库最新一条数据,确定是不是更新
- // // string qSql = @"SELECT top(1) [GUID]
- // // ,[LineName]
- // // ,[BootTimeLong]
- // // ,[NormalTimeLong]
- // // ,[StandbyTimeLong]
- // // ,[FaultTimeLong]
- // // ,[MaterialShortageTimeLong]
- // // ,[MaintenanceTimeLong]
- // // ,[FaultNumber]
- // // ,[OutputNumber]
- // // ,[QualifiedNumber]
- // // ,[QualifiedRate]
- // // ,[DesignRhythm]
- // // ,[RealityRhythm]
- // // ,[CreateTime]
- // // FROM [LineWorkingData]
- // // where [CreateTime] > '{0}'
- // // and [LineName]='{1}'
- // // order by [CreateTime] desc
- // // ";
- // // qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
- // // var ds = SQLHelper_New.Query(qSql, null);
- // // if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
- // // {
- // // var dataDBlast = new LineWorkingData_ThisTime();
- // // dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
- // // dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
- // // dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
- // // dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
- // // if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
- // // {
- // // dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
- // // dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
- // // dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
- // // dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
- // // dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
- // // dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
- // // dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
- // // dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
- // // dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
- // // dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
- // // dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
- // // dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
- // // string usql = dataDBlast.ToStringUpdate();
- // // SQLHelper_New.ExecuteSQL(usql, null);
- // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
- // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
- // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
- // // }
- // // }
- // // else
- // // {
- // // // 插入
- // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
- // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
- // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
- // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
- // // }
- // // }
- // // else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
- // // {
- // // LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
- // // //// 本次开机设备运行情况
- // // //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
- // // //Task.Run(() =>
- // // //{
- // // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
- // // // {
- // // // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
- // // // }
- // // //});
- // // // 本日设备运行情况
- // // // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
- // // if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
- // // {
- // // // 更新
- // // lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
- // // lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
- // // lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
- // // lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
- // // lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
- // // lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
- // // lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
- // // lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
- // // lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
- // // lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
- // // lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
- // // lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
- // // SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
- // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
- // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
- // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
- // // }
- // // else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
- // // {
- // // // 插入
- // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
- // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
- // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
- // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
- // // }
- // // await Task.Run(() =>
- // // {
- // // try
- // // {
- // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
- // // {
- // // Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
- // // }
- // // }
- // // catch { }
- // // });
- // // }
- // //}
- // //catch (Exception ex)
- // //{
- // // string str = ex.StackTrace;
- // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // //}
- // //#endregion 获取设备运行信息
- // #region 报警数据
- // try
- // {
- // List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
- // bool isNeedUpdUI = false; // 是否需要更新历史报警UI
- // // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
- // var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
- // for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
- // {
- // short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
- // dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
- // if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
- // {
- // isNeedUpdUI = true; // 需要更新历史报警UI信息
- // // 记录
- // dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
- // switch (dicAlarms_Cur_PLC1[i].是否报警)
- // {
- // case true: // 报警
- // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
- // {
- // GUID = Guid.NewGuid().ToString(),
- // LineName = GlobalContext.LineCode, // 线体
- // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
- // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
- // StartTime = dtNow // 开始时间
- // };
- // // 传输到页面
- // deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
- // {
- // 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
- // 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
- // 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
- // 开始时间 = dtNow
- // });
- // // 新增到数据库
- // var data1 = dicAlarms_Cur_PLC1[i].报警数据;
- // SaveAlarmDataByDB(stationNameStr, data1, false);
- // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
- // break;
- // case false: // 消除报警
- // if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
- // {
- // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
- // {
- // GUID = Guid.NewGuid().ToString(),
- // LineName = GlobalContext.LineCode, // 线体
- // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
- // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
- // StartTime = dtNow, // 开始时间
- // EndTime = dtNow, // 开始时间
- // PersistTime = 1, // 耗时1s
- // };
- // // 新增
- // var data2 = dicAlarms_Cur_PLC1[i].报警数据;
- // SaveAlarmDataByDB(stationNameStr, data2, false);
- // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
- // }
- // else
- // {
- // dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
- // dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
- // - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
- // // 修改
- // var data3 = dicAlarms_Cur_PLC1[i].报警数据;
- // SaveAlarmDataByDB(stationNameStr, data3, true);
- // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
- // }
- // break;
- // default:
- // break;
- // }
- // }
- // }
- // DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
- // // 有新报警则更新
- // if (isNeedUpdUI)
- // {
- // // UI展示 - 展示到设备状态页
- // await Task.Run(() =>
- // {
- // try
- // {
- // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
- // {
- // Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
- // if (Form_Main.formDevAlarm.Visible)
- // {
- // Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
- // }
- // }
- // }
- // catch { }
- // });
- // }
- // }
- // catch (Exception ex)
- // {
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 报警数据
- // UpdatePLCMonitor(1, -2, 1);
- //}
- //else
- //{
- // UpdatePLCMonitor(1, -2, 0);
- //}
- }
- catch (Exception ex)
- {
- //AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC1_{stationNameStr}_采集运行数据与报警数据出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalAlarm);
- }
- }
- #endregion 轮询PLC
- #region 下发订单信息
- ///// <summary>
- ///// 壳体上料(下发工单)的交互逻辑
- ///// </summary>
- ///// <param name="no"></param>
- ///// <exception cref="NotImplementedException"></exception>
- //private void ReadStation_DownOrderInfo(int plcNo)
- //{
- // // [S1] Tray盘上料装备(板测)
- // // [S2] FCT(板测)
- // // [S3] 值板机
- // // [S4] 取放桁架
- // // [S5] Tray盘下料装备
- // /// 上位机心跳
- // /// 获取设备报警数据与状态信息
- // string stationNameStr = "[S0]壳体上料";
- // while (IsRun)
- // {
- // try
- // {
- // if (!GlobalContext._IsCon_Funs1)
- // {
- // UpdatePLCMonitor(plcNo, 0);
- // continue;
- // }
- // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
- // {
- // #region 壳体上料(下发工单)
- // try
- // {
- // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
- // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
- // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
- // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
- // // 重置数据和信号
- // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
- // {
- // // 清空写给PLC的数据
- // int[] i497 = new int[1] { 0 };
- // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
- // // MES_Flag重置为0
- // int[] i500 = new int[1] { 0 };
- // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
- // }
- // }
- // catch (Exception ex)
- // {
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 壳体上料(下发工单)
- // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- // }
- // else
- // {
- // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- //
- // Funs[plcNo].Connect();
- // }
- // }
- // catch (Exception ex)
- // {
- // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- //
- // Funs[plcNo].ReConnect();
- // }
- // Thread.Sleep(IntervalReadPLC);
- // }
- //}
- ///// <summary>
- ///// 下发订单信息到PLC
- ///// </summary>
- ///// <param name="no">PLC编号</param>
- //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
- //{
- // try
- // {
- // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
- // {
- // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
- // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
- // }
- // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
- // }
- // catch (Exception ex)
- // {
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- //}
- /// <summary>
- /// 下发清料信号
- /// </summary>
- /// <param name="no">PLC编号</param>
- public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
- {
- try
- {
- //Funs[plcNo].ReadHoldingRegisters<int>(496); //
- AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
- return true;
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
- str.Length - str.LastIndexOf("\\") - 1));
- return false;
- }
- }
- #endregion 下发订单信息
- #region Xiaomi 贲流
- #region 公共方法
- private static bool ProgressState = false;
- private static readonly object lockObj = new object(); // 锁对象
- private static bool isCollectingFlagLeft;
- private static bool isCollectingFlagRight;
- private bool OpenDailogFalg = true; //是否开启扫码弹窗标识
- public static bool isNoStop = false; //是否停止循环
- public void ConnectToIOT()
- {
- XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
- // fds
- param.parameter.fds.address = GlobalContext.address;
- param.parameter.fds.appId = GlobalContext.appId;
- param.parameter.fds.appKey = GlobalContext.appKey;
- // mes
- param.parameter.mes.address = GlobalContext.ServerIp;
- param.parameter.mes.appId = GlobalContext.MESAppId;
- param.parameter.mes.appKey = GlobalContext.MESAppKey;
- // mqtt
- param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
- param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
- param.parameter.mqtt.username = GlobalContext.MQTTAppId;
- param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
- // 设备配置
- param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
- if (GlobalContext.IsUsePLC1)
- {
- param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
- xiaomiParm.workstation = GlobalContext.S1_work_station; //工站
- }
- if (GlobalContext.IsUsePLC2)
- {
- param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
- xiaomiParm.workstation = GlobalContext.S2_work_station; //工站
- }
- if (GlobalContext.IsUsePLC3)
- {
- param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
- //param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
- }
- if (GlobalContext.IsUsePLC4)
- {
- param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
- xiaomiParm.workstation = GlobalContext.s4_work_station; //工站
- }
- if (GlobalContext.IsUsePLC5)
- {
- param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
- xiaomiParm.workstation = GlobalContext.s5_work_station; //工站
- }
- if (GlobalContext.IsUsePLC6)
- {
- param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
- xiaomiParm.workstation = GlobalContext.s6_work_station; //工站
- }
- if (GlobalContext.IsUsePLC7)
- {
- param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
- //param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
- xiaomiParm.stationCode = GlobalContext.s7_1_station;
- }
- if (GlobalContext.IsUsePLC8)
- {
- param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
- xiaomiParm.workstation = GlobalContext.s8_work_station; //工站
- }
- if (GlobalContext.IsUsePLC9)
- {
- param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
- param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
- xiaomiParm.workstation = GlobalContext.s9_work_station; //工站
- }
- param.parameter.equipment.project = GlobalContext.Project_Code;
- param.parameter.equipment.productMode = "debug";
- param.parameter.other.logLevel = 0;
- param.parameter.other.LogPath = GlobalContext.MqttLogDir;
- XiaomiMqttClient_Extend.ParameterConfig(param);
- }
- /// <summary>
- /// float[]转为string
- /// </summary>
- public string FloatArrayToString(float[] nScrewResults)
- {
- // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
- return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
- }
- /// <summary>
- /// short[]转为string
- /// </summary>
- public string ShortArrayToString(short[] nScrewResults)
- {
- // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
- return string.Join(",", nScrewResults);
- }
- /// <summary>
- /// 写入PLC重复三次
- /// </summary>
- public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount,
- T inObj)
- {
- int i = 0;
- int nRet = 0;
- string strRet = "";
- try
- {
- while (i < 3) // 最多上传三次
- {
- (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
- if (nRet == 0) //成功
- {
- break;
- }
- else
- {
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
- i++;
- }
- }
- return (nRet, strRet);
- }
- catch (Exception ex)
- {
- return (1, ex.Message);
- }
- }
- public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes,
- short[] nScrewOrders, short[] nScrewResults)
- {
- try
- {
- // 获取当前日期
- string dateFolder = DateTime.Now.ToString("yyyyMMdd");
- // 构建保存路径
- string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
- string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction, "螺丝Mes数据");
- // 确保目录存在
- Directory.CreateDirectory(savePath);
- // 文件名
- string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
- string filePath = Path.Combine(savePath, fileName);
- // 确保不会超出数组长度,只取前14个或数组的实际长度
- int count = Math.Min(14, fScrewTimes.Length);
- using (StreamWriter sw = new StreamWriter(filePath))
- {
- for (int i = 0; i < count; i++)
- {
- sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
- sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
- sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
- sw.WriteLine($"锁附结果:{nScrewResults[i]}");
- sw.WriteLine(); // 空行分隔不同螺丝的信息
- }
- }
- return (0, "");
- }
- catch (Exception ex)
- {
- return (1, ex.Message);
- }
- }
- public Dictionary<string, string> GetLastLineCompensation(string path, string direction, string sn)
- {
- // 创建字典存储补偿点及其对应的值
- Dictionary<string, string> compensationDict = new Dictionary<string, string>();
- try
- {
- //string path = GlobalContext.MESLaserRPath;
- // 获取当前日期并格式化为 "yyyy-MM-dd" 格式
- string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
- string filename = $"Laser-{currentDate}-W0.txt";
- // 拼接完整路径
- string fullPath = Path.Combine(path, filename);
- string lastNonEmptyLine = "";
- // 判断文件是否存在
- if (File.Exists(fullPath))
- {
- //读取文件内容
- string[] lines = File.ReadAllLines(fullPath);
- // 获取最后一行数据(忽略标题行)
- if (lines.Length > 1)
- {
- string lastLine = "";
- for (int i = lines.Length - 1; i > 0; i--)
- {
- if (!string.IsNullOrEmpty(lines[i]))
- {
- lastLine = lines[i];
- break;
- }
- }
- // 将最后一行按逗号分隔
- string[] values = lastLine.Split(',');
- values[1] = sn;
- string key = "三点激光_" + direction; // 构造键名
- string value = string.Join(",", values); // 获取值并去除多余空格
- compensationDict[key] = value;
- //// 提取“1点补偿”到“6点补偿”的值
- //for (int i = 2; i <= 7 && i < values.Length; i++) // 从索引2开始,最多提取6个值
- //{
- // string key = $"{i - 1}点补偿"; // 构造键名
- // string value = values[i].Trim(); // 获取值并去除多余空格
- // compensationDict[key] = value;
- //}
- }
- }
- else
- {
- Console.WriteLine($"文件不存在: {fullPath}");
- }
- }
- catch (Exception ex)
- {
- // 捕获异常并输出错误信息
- Console.WriteLine($"发生错误: {ex.Message}");
- }
- return compensationDict;
- }
- public int PCBStationOutData(BarcodeSet_t Barcode,IoT_DataSet_t iotData)
- {
- int res = 0;
- string jsonstr1 = "";
- try
- {
- XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
- outRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备id(可配置)
- outRequest_Body.stationId = GlobalContext.s5_station; // ⼯位ID(可配置)
- outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
- outRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
- outRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
- int a1Result = (int)iotData.testStatus;
- //bool pass = a1Result == 1;
- //outRequest_Body.state = pass ? "PASS" : "FAIL"; ; // 出站条件 PASS或FAIL
- outRequest_Body.state = "PASS";
- outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
- outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
- XmStationOut_KeyMaterial keyMaterial = new XmStationOut_KeyMaterial();
- keyMaterial.bindSort = 1;
- keyMaterial.materialSn = Barcode.strProductBarcode;
- outRequest_Body.unitData.keyMaterial.Add(keyMaterial); // 产品码
- jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
- XmMES_StationOutResponse response = new XmMES_StationOutResponse();
- response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
- if (response != null && response.header.code == "200")
- {
- res = 1;
- AddMessage(LogType.Info, "上传PCB出站数据到MES服务器---成功!请求信息:" + jsonstr1 + ",返回信息:" + JsonConvert.SerializeObject(response.body));
- }
- else
- {
- res = 0;
- AddMessage(LogType.Error, "上传PCB出站数据到MES服务器---失败!错误信息:"+ response.header.desc + ",请求信息:" + jsonstr1 + ",返回信息:" + JsonConvert.SerializeObject(response.body));
- }
- }
- catch (Exception e)
- {
- res = 0;
- AddMessage(LogType.Info, "上传PCB出站数据到MES服务器---失败!请求信息:" + jsonstr1 + ",返回信息:" + e.Message);
- }
-
-
- return res;
- }
- public int PCBStationInData(BarcodeSet_t Barcode, IoT_DataSet_t iotData)
- {
- int res = 0;
- string json_Body = "";
- try
- {
- XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
- inRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
- inRequest_Body.stationId = GlobalContext.s5_station; // ⼯位ID(可配置)
- inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
- inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
- inRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
- inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
- inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
- json_Body = JsonConvert.SerializeObject(inRequest_Body);
- var response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
- string resultJson = JsonConvert.SerializeObject(response);
- if (response != null && response.header.code == "200")
- {
- res = 1;
- AddMessage(LogType.Info, "上传PCB进站数据到MES服务器---成功!请求信息:" + json_Body + ",返回信息:" + JsonConvert.SerializeObject(response.body));
- }
- else
- {
- res = 0;
- AddMessage(LogType.Error, "上传PCB进站数据到MES服务器---失败!错误信息:" + response.header.desc + ",请求信息:" + json_Body + ",返回信息:" + JsonConvert.SerializeObject(response.body));
- }
- }
- catch (Exception e)
- {
- res = 0;
- AddMessage(LogType.Info, "上传PCB进站数据到MES服务器---失败!请求信息:" + json_Body + ",返回信息:" + e.Message);
- }
- return res;
- }
- /// <summary>
- /// 调用进站接口并保存进站数据
- /// </summary>
- /// <param name="stationNameStr">工站信息</param>
- /// <param name="workorder_code">工单号</param>
- /// <param name="mtltmrk">型号(物料号)</param>
- /// <param name="sn">产品SN</param>
- /// <param name="items">进站数据</param>
- /// <returns>1成功;5MES报警;6上位机报警</returns>
- public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn,
- List<TestItem> items, string MachineId, string StationId, bool pass, string slot)
- {
- int result = 0;
- XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
- inRequest_Body.machineId = MachineId; // 装备ID(可配置)
- inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
- inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
- inRequest_Body.clientTime =
- DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
- inRequest_Body.unitSn = sn; // 产品SN
- inRequest_Body.uuidInspection = uuid;
- inRequest_Body.state = pass ? "PASS" : "FAIL";
- inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
- inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
- string json_Body = JsonConvert.SerializeObject(inRequest_Body);
- StationIn stationIn = new StationIn()
- {
- Workorder_code = workorder_code, // 车间订单号
- Mtltmrk = mtltmrk, // 产品型号(物料号)
- Sn = sn, // SN
- StationIn_body = json_Body, // 进站接口Json数据 - Body
- Parameter_values = items, // 进站数据
- Write_user = inRequest_Body.userId, // 员工Id
- Test_time = inRequest_Body.clientTime // 进站时间
- };
- // 本地数据
- string sql = stationIn.ToStringInsert(0);
- string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
- result = ret == "成功" ? 1 : 6;
- #region MES
- if (GlobalContext.IsSendStationIn)
- {
- try
- {
- XmMES_StationInResponse response = new XmMES_StationInResponse();
- string resultJson = "";
- string mesRet = string.Empty;
- int i = 0;
- while (i < 2) // 1009会多次尝试上传
- {
- response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
- resultJson = JsonConvert.SerializeObject(response);
- if (response != null && response.header.code == "200")
- break;
- else if (!mesRet.Contains("1009")) // 1009是未知错误
- i++;
- i++;
- mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
- // 记录失败原因
- OnMessage(LogType.Error, $"上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:{mesRet},请求参数:{json_Body}");
- }
- if (response?.header?.code == "200")
- {
- string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
- string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
- result = ret_Upd == "成功" ? 1 : 6;
- AddMessage(LogType.Info,
- $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功,返回参数:{resultJson},请求参数:{json_Body}");
- }
- else
- {
- result = 5;
- AddMessage(LogType.Info,
- $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息: {mesRet},请求参数:{json_Body}");
- }
- string sql_response =
- stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
- SQLHelper_New.ExecuteNonQuery(sql_response, null);
- }
- catch (Exception ex)
- {
- result = 6;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- }
- #endregion
- #region IOT
- //过站结果
- if (GlobalContext.IsMqttSendProcessData)
- {
- PassStationResultRequest request = new PassStationResultRequest();
- request.project_code = GlobalContext.Project_Code; // 项⽬编码
- request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
- request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
- request.line_code = GlobalContext.LineCode; // 线体编码
- request.work_station = xiaomiParm.workstation; // ⼯站ID
- request.device_code = xiaomiParm.deviceCode; // 装备编码
- request.station = xiaomiParm.stationCode;
- request.process_time =
- DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
- request.slot = slot; // 槽位编码
- request.sn = sn; // 产品SN
- // request.enter_status = inpass ? "PASS" : "FAIL"; // 进站状态
- request.enter_status = pass ? "PASS" : "FAIL"; // 进站状态
- request.result = ""; // 出站条件 PASS或FAIL; // 过站结果
- request.work_type = "OUT_STATION"; // 作业类型
- // 上传过站结果
- (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
- if (iotResult.Item1 != 0)
- {
- OnMessage(LogType.Info,
- $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}] 进站结果[{request.enter_status}] 出站结果[{request.result}]");
- }
- }
- #endregion
- return result;
- }
- /// <summary>
- /// 选择如何记录出站数据
- /// </summary>
- /// <param name="items">出站数据</param>
- /// <param name="equipmentCode">设备编号</param>
- /// <param name="processItem">测试项目</param>
- /// <param name="workorder_code">车间订单号</param>
- /// <param name="batch_num">批次号</param>
- /// <param name="mtltmrk">型号</param>
- /// <param name="proDate">日期</param>
- /// <param name="supplierCode">供应商代码</param>
- /// <param name="sn_Number">产品序列号的 数字序列部分</param>
- /// <returns>上传成功时返回1;失败返回0</returns>
- private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode,
- string processItem,
- string workorder_code, string batch_num, string mtltmrk, string proDate,
- string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId,
- string StationId, string PartBarcode, string jsonParm, string direction = "")
- {
- return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num,
- mtltmrk,
- proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode, jsonParm,
- direction);
- }
- /// <summary>
- /// 添加出站数据(提交到MES+本地保存到数据库)
- /// </summary>
- /// <param name="items">出站数据</param>
- /// <param name="equipmentCode">设备编号</param>
- /// <param name="processItem">测试项目</param>
- /// <param name="workorder_code">车间订单号</param>
- /// <param name="batch_num">批次号</param>
- /// <param name="mtltmrk">型号</param>
- /// <param name="proDate">日期</param>
- /// <param name="supplierCode">供应商代码</param>
- /// <param name="sn_Number">产品序列号的 数字序列部分</param>
- /// <returns>上传成功时返回1;失败返回0</returns>
- public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
- string processItem, string workorder_code, string batch_num, string mtltmrk,
- string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot,
- string machineId, string stationId, string partBarcode, string jsonParm, string direction = "")
- {
- int upload = 0;
- int result = 0;
- ProcessData processData = new ProcessData()
- {
- Equipment_code = equipmentCode,
- Workorder_code = workorder_code,
- Batch_number = batch_num,
- Sn = sn, // SN
- Testitem = processItem,
- Parameter_values = items,
- Write_user = GlobalContext.CurrentUser,
- Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
- };
- // 本地数据
- string sql = processData.ToStringInsert(upload);
- string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
- //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
- #region MES
- if (GlobalContext.IsSendProcessData)
- {
- try
- {
- string id = processData.ID.Copy();
- XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
- outRequest_Body.uuidInspection = uuid;
- outRequest_Body.machineId = machineId; // 装备id(可配置)
- outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
- outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
- outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
- outRequest_Body.unitSn = sn; // 产品SN
- outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
- outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
- outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
- outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
- outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
- outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
- if (!string.IsNullOrEmpty(partBarcode))
- {
- outRequest_Body.unitData.keyMaterial.Add(
- new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
- {
- bindSort = 1,
- materialSn = partBarcode
- }); // 设备数据 - 部件码
- }
- //OP30站读txt数据
- if (stationNameStr.Contains("CPAPHD"))
- {
- string path = "";
- if (direction == "Left")
- path = GlobalContext.MESLaserLPath;
- else
- path = GlobalContext.MESLaserRPath;
- //字典存储数据
- Dictionary<string, string> compensationDict = GetLastLineCompensation(path, direction, sn);
- foreach (var kvp in compensationDict)
- {
- outRequest_Body.unitData.processData.Add(
- new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
- {
- dataName = kvp.Key.ToString(),
- dataValue = kvp.Value.ToString()
- });
- }
- }
- //过站明细
- if (GlobalContext.IsSendProcessDetail)
- {
- if (jsonParm.Length > 0)
- {
- // 解析JSON字符串为字典
- var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonParm);
- foreach (var kvp in dictionary)
- {
- outRequest_Body.unitData.processData.Add(
- new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
- {
- dataName = kvp.Key.ToString(),
- dataValue = string.IsNullOrEmpty(kvp.Value) ? "" : kvp.Value.ToString()
- });
- }
- }
- }
- if (GlobalContext.MESIsSendUpFile)
- {
- foreach (var item in fileUploadData.fileData)
- {
- if (!string.IsNullOrEmpty(item.FileName))
- {
- outRequest_Body.unitData.fileData.Add(
- new XmStationOut_FileData()
- {
- fileName = item.FileName,
- fileId = item.FileId,
- bucket = item.Bucket
- });
- }
- }
- }
- string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
- if (GlobalContext.IsSendProcessData)
- {
- XmMES_StationOutResponse response = new XmMES_StationOutResponse();
- string mesRet = string.Empty;
- int i = 0;
- while (i < 2) // 1009会多次尝试上传
- {
- response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
- if (response != null && response.header.code == "200")
- {
- OnMessage(LogType.Info,
- $"【出站数据 SN {sn}】上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" +
- JsonConvert.SerializeObject(response.body));
- break;
- }
- else if (!mesRet.Contains("1009")) // 1009是未知错误
- i++;
- i++;
- mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
- // 记录失败原因
- OnMessage(LogType.Error,
- $"【出站数据 SN {sn}】上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
- }
- if (response?.header?.code == "200")
- {
- string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
- string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
- result = 1;
- //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
- AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
- }
- else
- {
- AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
- }
- string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(
- JsonConvert.SerializeObject(outRequest_Body),
- JsonConvert.SerializeObject(response), id);
- SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- }
- #endregion
- #region IOT
- //过站明细
- if (GlobalContext.IsMqttSendProcessData)
- {
- test_item_num += 1;
- PassStationDetailRequest request = new PassStationDetailRequest();
- request.pass_station_id = uuid;
- request.sn = sn; // 产品SN
- request.slot = vehicleSlot; // 槽位编码
- request.test_item_num = test_item_num.ToString();
- request.function_name = "Machine_加⼯模块";
- request.status = "PASS";
- (int, string) iotResult = (0, "");
- if (jsonParm.Length > 0)
- {
- // 解析JSON字符串为字典
- var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonParm);
- foreach (var kvp in dictionary)
- {
- request.test_item = kvp.Key.ToString();
- request.result_val = string.IsNullOrEmpty(kvp.Value) ? "" : kvp.Value.ToString();
- request.description = request.test_item;
- // 上传过站明细
- iotResult = XiaomiMqttClient_Extend.Write_PassStationDetail(request);
- if (iotResult.Item1 != 0)
- {
- OnMessage(LogType.Info,
- $"【IOT过站明细】上传失败!错误原因:{iotResult.Item2},过站明细;产品码[{sn}] 测试项目[{request.test_item}] 测试值[{request.result_val}]");
- }
- }
- }
- }
- //过站结果
- if (GlobalContext.IsMqttSendProcessData)
- {
- PassStationResultRequest request = new PassStationResultRequest();
- request.project_code = GlobalContext.Project_Code; // 项⽬编码
- request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
- request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
- request.line_code = GlobalContext.LineCode; // 线体编码
- request.work_station = xiaomiParm.workstation; // ⼯站ID
- request.device_code = xiaomiParm.deviceCode; // 装备编码
- request.station = xiaomiParm.stationCode;
- request.process_time =
- DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
- request.slot = vehicleSlot; // 槽位编码
- request.sn = sn; // 产品SN
- // request.enter_status = inpass ? "PASS" : "FAIL"; // 进站状态
- request.enter_status = ""; // 进站状态
- request.result = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL; // 过站结果
- request.work_type = "OUT_STATION"; // 作业类型
- // 上传过站结果
- (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
- if (iotResult.Item1 != 0)
- {
- OnMessage(LogType.Info,
- $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}] 进站结果[{request.enter_status}] 出站结果[{request.result}]");
- }
- }
- #endregion
- return result;
- }
- //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
- //{
- // Stopwatch stopwatch = new Stopwatch();
- // stopwatch.Start();
- // try
- // {
- // // 初始化 AtlasScrew 实例
- // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
- // atlasScrew1.Initial();
- // // 存储结果的列表
- // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
- // // 存储角度和扭力的字符串列表
- // List<string> angleStrs = new List<string>();
- // List<string> torqueStrs = new List<string>();
- // // 上一次获取的数据
- // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
- // while (isExitAtlasLeft) // 检查是否收集数据
- // {
- // // 获取当前数据
- // var currentResult = atlasScrew1.GetResults();
- // // 判断是否为新数据
- // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
- // {
- // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
- // // 更新角度和扭力的字符串列表
- // angleStrs.Add(currentResult.JD_MEAN.ToString());
- // torqueStrs.Add(currentResult.NL_MEAN.ToString());
- // // 计算角度、扭力、起始扭力和最大扭力
- // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
- // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
- // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
- // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
- // // 将新数据添加到结果列表
- // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
- // // 更新上一次获取的数据
- // lastResult = currentResult;
- // }
- // // 等待一段时间后再次检查
- // Thread.Sleep(20); // 轮询间隔时间
- // // 如果触发了出站,则退出循环
- // if (!isExitAtlasLeft)
- // {
- // break;
- // }
- // }
- // // 生成文件名
- // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
- // // 写入数据到文件
- // using (StreamWriter writer = new StreamWriter(fileName))
- // {
- // // 写入标题行
- // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
- // // 写入每一行数据
- // foreach (var result in results)
- // {
- // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
- // }
- // }
- // stopwatch.Stop();
- // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
- // }
- // catch (Exception ex)
- // {
- // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
- // }
- // finally
- // {
- // // 重置标志变量
- // isExitAtlasLeft = false;
- // }
- //}
- //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
- //{
- // Stopwatch stopwatch = new Stopwatch();
- // stopwatch.Start();
- // try
- // {
- // // 初始化 AtlasScrew 实例
- // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
- // atlasScrew2.Initial();
- // // 存储结果的列表
- // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
- // // 上一次获取的数据
- // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
- // while (isExitAtlasRight) // 检查是否收集数据
- // {
- // // 获取当前数据
- // var currentResult = atlasScrew2.GetResults();
- // // 判断是否为新数据
- // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
- // {
- // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
- // // 将新数据写入PLC
- // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
- // // 将新数据添加到结果列表
- // results.Add(currentResult);
- // // 更新上一次获取的数据
- // lastResult = currentResult;
- // }
- // // 等待一段时间后再次检查
- // Thread.Sleep(20); // 轮询间隔时间
- // // 如果触发了出站,则退出循环
- // if (!isExitAtlasRight)
- // {
- // break;
- // }
- // }
- // // 将所有数据写入文件
- // //WriteDataToFile(sn, direction, results);
- // stopwatch.Stop();
- // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
- // }
- // catch (Exception ex)
- // {
- // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
- // }
- // finally
- // {
- // // 重置标志变量
- // isExitAtlasRight = false;
- // }
- //}
- private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- int nRet = 0;
- string strRet = "";
- try
- {
- int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
- while (isCollectingFlagLeft)
- {
- // 从缓存中获取所有未处理的数据
- var cachedData = atlasScrew.GetCachedDataLeft();
- foreach (var currentResult in cachedData)
- {
- if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
- {
- continue; // 跳过无效数据
- }
- OnMessage(LogType.Info,
- $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
- // 写入PLC
- OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
- {
- fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
- fCircles = float.Parse(currentResult.JD_MEAN.ToString())
- };
- (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
- if (nRet != 0)
- {
- OnMessage(LogType.Info,
- $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
- }
- else
- {
- OnMessage(LogType.Info,
- $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
- }
- // 构建保存路径
- string dateFolder = DateTime.Now.ToString("yyyyMMdd");
- string basePath = AppDomain.CurrentDomain.BaseDirectory;
- string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
- Directory.CreateDirectory(savePath); // 确保目录存在
- // 构建文件名(以 SN + 序号命名)
- string fileName = $"{sn}_{fileCounter}.txt";
- string filePath = Path.Combine(savePath, fileName);
- // 写入文件
- using (StreamWriter writer = new StreamWriter(filePath))
- {
- writer.WriteLine("精度, 扭力");
- // 遍历 Pearkdegree 和 PearkTorque 的所有值
- for (int i = 0;
- i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
- i++)
- {
- double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
- double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
- writer.WriteLine($"{precision}, {torque}");
- }
- }
- OnMessage(LogType.Info, $"保存文件成功: {filePath}");
- // 增加文件计数器
- fileCounter++;
- }
- // 如果没有更多数据,则短暂休眠以节省资源
- if (!cachedData.Any())
- {
- Thread.Sleep(10); // 根据需要调整休眠时间
- }
- // 如果触发了出站,则退出循环
- if (!isCollectingFlagLeft)
- {
- break;
- }
- }
- stopwatch.Stop();
- OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
- }
- catch (Exception ex)
- {
- OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
- }
- finally
- {
- isCollectingFlagLeft = false;
- }
- }
- private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- int nRet = 0;
- string strRet = "";
- try
- {
- int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
- while (isCollectingFlagRight)
- {
- // 从缓存中获取所有未处理的数据
- var cachedData = atlasScrew.GetCachedDataLeft();
- foreach (var currentResult in cachedData)
- {
- if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
- {
- continue; // 跳过无效数据
- }
- OnMessage(LogType.Info,
- $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
- // 写入PLC
- OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
- {
- fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
- fCircles = float.Parse(currentResult.JD_MEAN.ToString())
- };
- (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
- if (nRet != 0)
- {
- OnMessage(LogType.Info,
- $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
- }
- else
- {
- OnMessage(LogType.Info,
- $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
- }
- // 构建保存路径
- string dateFolder = DateTime.Now.ToString("yyyyMMdd");
- string basePath = AppDomain.CurrentDomain.BaseDirectory;
- string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
- Directory.CreateDirectory(savePath); // 确保目录存在
- // 构建文件名(以 SN + 序号命名)
- string fileName = $"{sn}_{fileCounter}.txt";
- string filePath = Path.Combine(savePath, fileName);
- // 写入文件
- using (StreamWriter writer = new StreamWriter(filePath))
- {
- writer.WriteLine("精度, 扭力");
- // 遍历 Pearkdegree 和 PearkTorque 的所有值
- for (int i = 0;
- i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
- i++)
- {
- double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
- double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
- writer.WriteLine($"{precision}, {torque}");
- }
- }
- OnMessage(LogType.Info, $"保存文件成功: {filePath}");
- // 增加文件计数器
- fileCounter++;
- }
- // 如果没有更多数据,则短暂休眠以节省资源
- if (!cachedData.Any())
- {
- Thread.Sleep(10); // 根据需要调整休眠时间
- }
- // 如果触发了出站,则退出循环
- if (!isCollectingFlagRight)
- {
- break;
- }
- }
- stopwatch.Stop();
- OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
- }
- catch (Exception ex)
- {
- OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
- }
- finally
- {
- isCollectingFlagRight = false;
- }
- }
- public static (int,string) CompressFolder(string folderPath, string zipFilePath)
- {
- try
- {
- // 创建zip文件,将指定文件夹内的所有内容压缩到这个zip文件中
- System.IO.Compression.ZipFile.CreateFromDirectory(folderPath, zipFilePath);
- return (1, "文件夹已成功压缩!");
- }
- catch (Exception ex)
- {
- return (0, "文件压缩出错!"+ ex.Message);
- }
- }
- /// <summary>
- /// 上传文件
- /// </summary>
- /// <param name="BarcodeSet_t">条码集合</param>
- /// <param name="stationCode">工站编号</param>
- /// <param name="stationName">工站名称</param>
- /// <param name="path">文件路径</param>
- public async Task<(int, string)> SaveDBbyFileInfo(BarcodeSet_t BarcodeSet, string stationCode,
- string stationName, int pass, string path, string guid = "")
- {
- string sql, filename = "";
- int result = 0;
- var formData = new MultipartFormDataContent();
- string msg = "";
- string file_category = "IMAGE"; //IMAGE 、TEXT 、UNKNOWN
- string file_type = "IMAGE";
- string project = GlobalContext.ProgramName;
- string run_mode = GlobalContext.run_mode;
- string product_mode = GlobalContext.product_mode;
- string pass_result = (pass == 1 ? "PASS" : "Fail");
- string device_code = xiaomiParm.deviceCode;
- string sn = BarcodeSet.strProductBarcode;
- string staion_id = xiaomiParm.stationCode;
- string bucket =
- $"{file_category}/{file_type}/{project}/{product_mode}/{run_mode}/{pass_result}/{device_code}/{sn}/{staion_id}";
- // 获取所有图片文件
- if (guid == "")
- {
- guid = Guid.NewGuid().ToString();
- }
- try
- {
- if (GlobalContext.MESIsSendUpFile)
- {
- List<string> imageFiles = GetAllImageFiles(path);
- string toPath = GlobalContext.MqttFileBackupLogDir;
- filename = $"{xiaomiParm.workstation}_{file_type}_{sn}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";
- //string directoryPath = Path.GetDirectoryName(path);
- string strFilePath = toPath+ "\\"+ filename;
- if (imageFiles.Count > 0)
- {
- var r = CompressFolder(path, strFilePath);
- if (r.Item1 == 0)
- {
- return (0, r.Item2);
- }
- else
- {
- msg = r.Item2 + "\r\n";
- }
- }
- else {
- return (0, "文件不存在!");
- }
- FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
- fileUpload_X5.bucket = bucket;
- fileUpload_X5.name = filename;
- fileUpload_X5.uuid = guid.ToString();
- ///需要上传文件
- FileInfo file = new FileInfo(strFilePath);
- string fileMd5Hex = GetMD5Hex(file);
- fileUpload_X5.md5 = fileMd5Hex;
- fileUpload_X5.uploadCloud = true;
- fileUpload_X5.informMqtt = true;
- FileMqttPayload fileMqttPayload = new FileMqttPayload();
- fileMqttPayload.factory = GlobalContext.Factory_Code;
- fileMqttPayload.project_name = GlobalContext.Project_Code;
- fileMqttPayload.product_mode = GlobalContext.product_mode;
- fileMqttPayload.line_no = GlobalContext.LineCode;
- fileMqttPayload.work_station_no = xiaomiParm.workstation;
- fileMqttPayload.equipment_no = xiaomiParm.deviceCode;
- fileMqttPayload.station_no = xiaomiParm.stationCode;
- fileMqttPayload.file_id = guid;
- fileMqttPayload.file_name = filename;
- fileMqttPayload.sn = BarcodeSet.strProductBarcode;
- //fileMqttPayload.opt_time = "";
- //fileMqttPayload.file_type = "";
- //fileMqttPayload.file_category = "";
- //fileMqttPayload.tag = "";
- fileMqttPayload.reference_info.pass_station_id = uuid;
- var fileresult =await
- XiaomiMESHttp_UpLoadFile.FileUoladToMes(strFilePath, fileUpload_X5, fileMqttPayload);
- if (fileresult.Item1 != 1)
- {
- return (0, msg + fileresult.Item2 + "\r\n");
- }
- else
- {
- msg = msg + fileresult.Item2 + "\r\n";
- }
-
- foreach (var imageFile in imageFiles) {
- if (File.Exists(imageFile))
- {
- //删除文件
- (bool, string) newResult = DeleteFile(imageFile);
- if (!newResult.Item1)
- {
- return (0, Path.GetFileName(imageFile) + newResult.Item2);
- }
- }
- }
- }
- return (1, msg);
- }
- catch (Exception e)
- {
- return (0,
- filename + $"文件上传错误!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode},错误原因:" +
- e.Message);
- }
- }
- /// <summary>
- /// 获取路径下的所有图片
- /// </summary>
- /// <param name="directoryPath"></param>
- /// <returns></returns>
- public List<string> GetAllImageFiles(string directoryPath)
- {
- var imageExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
- { ".jpg", ".jpeg", ".png", ".bmp", ".gif", ".tiff" };
- var imageFiles = new List<string>();
- try
- {
- // 遍历目录及子目录中的所有文件
- foreach (string file in Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories))
- {
- // 获取文件扩展名并检查是否为图片格式
- string extension = Path.GetExtension(file);
- if (imageExtensions.Contains(extension))
- {
- imageFiles.Add(file);
- }
- }
- }
- catch (Exception ex)
- {
- OnMessage(LogType.Error, $"图片查询发生错误: {ex.Message}");
- }
- return imageFiles;
- }
- /// <summary>
- /// 实例化报警字典
- /// </summary>
- private (bool, string) InitalDicAlarm()
- {
- #region 加载报警表
- string excelPath = "";
- switch (GlobalContext.IsUsePLCNow)
- {
- case 1:
- excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_10_壳体清洁上料.xlsx";
- break;
- case 2:
- excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_20_上盖板上料装备.xlsx";
- break;
- case 3:
- excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_30_点散热胶装备.xlsx";
- break;
- case 4:
- excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_40_胶线检测.xlsx";
- break;
- case 5:
- excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_50_ADD板上料组装装备.xlsx";
- break;
- case 6:
- excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_60_组上盖板.xlsx";
- break;
- case 7:
- excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_70_上盖板锁螺丝.xlsx";
- break;
- case 8:
- excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_80_NG下料.xlsx";
- break;
- case 9:
- excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_90_半成品下料.xlsx";
- break;
- default:
- return (false, $"不支持当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请在设置页切换到正确的plc后重启该软件!");
- }
- if (!File.Exists(excelPath))
- return (false, $"未找到当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请检查文件路径:'{excelPath}'。");
- DataTable DtModel = NPOIHelper.ReadExcel(excelPath);
- if (DtModel == null || DtModel.Rows.Count < 1)
- return (false, $"报警点位表未包含任何报警数据!请检查‘{excelPath}’文件!");
- // 检查列名
- List<string> isNeedParms = new List<string>()
- {
- "设备分类名称", "设备分类编码", "分类层级1", "分类层级2", "分类层级3", "分类层级4", "事件名称", "事件ID", "描述", "标签", "PLC地址", "工位"
- }; // 必须要有的列
- // 指定列名 + 检查列是否完整
- DataRow dtRowName = DtModel.Rows[0];
- int count = DtModel.Columns.Count;
- for (int i = 0; i < count; i++)
- {
- string columeName = dtRowName[i]?.ToString();
- if (!string.IsNullOrEmpty(columeName))
- DtModel.Columns[i].ColumnName = columeName;
- if ((!string.IsNullOrEmpty(columeName)) && isNeedParms.Count > 0 && isNeedParms.Contains(columeName))
- isNeedParms.Remove(columeName);
- }
- DtModel.Rows.RemoveAt(0);
- if (isNeedParms.Count > 0)
- {
- string msg1 = string.Join(",", isNeedParms);
- return (false, $"报警点位表未包含列:{msg1}!请检查‘{excelPath}’文件!");
- }
- #endregion 加载报警表
- List<Alarm> keyValues1 = new List<Alarm>();
- for (int i = 0; i < DtModel.Rows.Count; i++)
- {
- Alarm alarm = new Alarm();
- alarm.plcName = DtModel.Rows[i]["设备分类名称"]?.ToString(); // 设备名;
- string type1Str = DtModel.Rows[i]["分类层级1"]?.ToString(); // 分类层级1;
- alarm.type1CH = type1Str; // 分类层级1 中文
- alarm.type1 = type1Str; // 分类层级1
- if (!string.IsNullOrEmpty(type1Str) && type1Str.Contains("\n"))
- {
- string[] type1Strs = type1Str.Split('\n');
- if (type1Strs.Length >= 2)
- {
- alarm.type1CH = type1Strs[0].Trim(); // 分类层级1 中文
- alarm.type1 = type1Strs[1].Trim(); // 分类层级1
- if (string.IsNullOrEmpty(alarm.type1))
- alarm.type1 = alarm.type1CH;
- }
- }
- string type2Str = DtModel.Rows[i]["分类层级2"]?.ToString(); // 分类层级2;电气控制 electric_control
- alarm.type2CH = type2Str; // 分类层级2 中文
- alarm.type2 = type2Str; // 分类层级2
- if (!string.IsNullOrEmpty(type2Str) && type2Str.Contains("\n"))
- {
- string[] type2Strs = type2Str.Split('\n');
- if (type2Strs.Length >= 2)
- {
- alarm.type2CH = type2Strs[0].Trim(); // 分类层级2 中文
- alarm.type2 = type2Strs[1].Trim(); // 分类层级2
- if (string.IsNullOrEmpty(alarm.type2))
- alarm.type2 = alarm.type2CH;
- }
- }
- string type3Str = DtModel.Rows[i]["分类层级3"]?.ToString(); // 分类层级3;故障 Fault
- alarm.type3CH = type3Str; // 分类层级3 中文
- alarm.type3 = type3Str; // 分类层级3
- if (!string.IsNullOrEmpty(type3Str) && type3Str.Contains("\n"))
- {
- string[] type3Strs = type3Str.Split('\n');
- if (type3Strs.Length >= 2)
- {
- alarm.type3CH = type3Strs[0].Trim(); // 分类层级3 中文
- alarm.type3 = type3Strs[1].Trim(); // 分类层级3
- if (string.IsNullOrEmpty(alarm.type3))
- alarm.type3 = alarm.type3CH;
- }
- }
- string faultStr = DtModel.Rows[i]["分类层级4"]?.ToString(); // 故障部件;overall_module
- alarm.type4 = faultStr; // 分类层级4 中文
- alarm.type4CH = faultStr; // 分类层级4
- if (!string.IsNullOrEmpty(faultStr) && faultStr.Contains("\n"))
- {
- string[] faultStrs = faultStr.Split('\n');
- if (faultStrs.Length >= 2)
- {
- alarm.type4CH = faultStrs[0].Trim(); // 故障部件;overall_module
- alarm.type4 = faultStrs[1].Trim(); // 故障部件
- if (string.IsNullOrEmpty(alarm.type4))
- alarm.type4 = alarm.type4CH;
- }
- }
- alarm.fault_code = DtModel.Rows[i]["事件ID"]?.ToString(); // 故障编码;A40001
- alarm.fault_name = DtModel.Rows[i]["事件名称"]?.ToString(); // 故障名称;AL[1000]_系统_HMI急停故障
- alarm.fault_desc = alarm.fault_name; // 故障描述;AL[1000]_系统_HMI急停故障
- string plcAdress = DtModel.Rows[i]["PLC地址"]?.ToString();
- alarm.PLC地址 = plcAdress;
- plcAdress = plcAdress.Replace("fault_codes[", "");
- plcAdress = plcAdress.Replace("]", "");
- alarm.group_index = Convert.ToInt32(plcAdress.Split(".")[0]);
- keyValues1.Add(alarm);
- }
- DicAlarms_Cur.Add(GlobalContext.IsUseStationName, keyValues1); // 这里使用线体代替工位
- return (true, "报警字典表初始化成功!");
- }
- private async void ReadPLCAlarmToIot(uint[] FaultData, uint[] FaultDataOld, string stationNameStr)
- {
- DateTime dtNow = DateTime.Now;
- try
- {
- List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
- List<(int, int)> AlarmIndexList = new List<(int, int)>(); //收集所有报警信息的位置
- AlarmData alarmData = new AlarmData();
- bool isNeedUpdUI = false; // 是否需要更新历史报警UI
- bool isNoAlarm = false; //是否有报警
- string binaryString = "";
- bool isNoNewAlarm = false; //是否有新的报警
- if (FaultData.Length > 0)
- {
- foreach (var item in FaultData)
- {
- isNoAlarm = item > 0 ? true : false;
- }
- if (!FaultData.SequenceEqual(FaultDataOld))
- {
- isNoNewAlarm = true;
- isNeedUpdUI = true;
- }
- if (FaultData.Length > 0 && isNoAlarm && isNoNewAlarm)
- {
- //解析报警信息,分析当前报警在字典中的定位
- for (int i = 0; i <= FaultData.Length - 1; i++)
- {
- var num = 0;
- if (FaultData[i] > 0)
- {
- //转换二进制
- binaryString = Convert.ToString(FaultData[i], 2);
- for (int j = binaryString.Length - 1; j >= 0; j--)
- {
- num++;
- char s = binaryString[j];
- if (binaryString[j] == '1')
- {
- //记录1的位置
- AlarmIndexList.Add((i, num - 1));
- }
- }
- }
- }
- // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
- var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.IsUseStationName];
- foreach ((int index, int row) in AlarmIndexList)
- {
- var tempDic = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList();
- for (int i = 0; i < tempDic.Count - 1; i++) // 读取
- {
- //若报警字典第[group_index]个数据,第[i]行与AlarmIndexList中的定位匹配,则添加进对应行的报警数据
- if (tempDic[i].group_index == index && i == row)
- {
- dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据 =
- new AlarmData()
- {
- GUID = Guid.NewGuid().ToString(),
- LineName = GlobalContext.IsUseStationName, // 工站
- PlcStation = tempDic[i].plcName, // 工站全称;[S1]
- Type1 = tempDic[i].type1, // 故障层级1
- Type2 = tempDic[i].type2, // 故障层级2
- Type3 = tempDic[i].type3, // 故障层级3
- Type4 = tempDic[i].type4, // 故障层级4
- AlarmType = tempDic[i].fault_code, // 报警类型
- AlarmDesc = tempDic[i].fault_name, // 报警内容
- StartTime = dtNow // 开始时间
- };
- // 传输到页面
- deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
- {
- 线体名称 = tempDic[i].plcName,
- 报警类型 = tempDic[i].fault_code,
- 报警内容 = tempDic[i].fault_name,
- 开始时间 = dtNow
- });
- // 新增到数据库
- //var data1 = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据;
- //SaveAlarmDataByDB(stationNameStr, data1, false);
- //OnMessage(LogType.Info, $"更新{BodyAlarm}完毕!");
- }
- }
- }
- //筛选含报警数据的字典
- var dicAlarms_Cur = dicAlarms_Cur_PLC1.Where(x => x.报警数据 != null).ToList();
- if (dicAlarms_Cur.Count > 0)
- {
- foreach (var item in dicAlarms_Cur)
- {
- //上传
- SaveAlarmDataByDB(GlobalContext.IsUseStationName, item.报警数据, false);
- }
- }
- // 有新报警则更新
- if (isNeedUpdUI)
- // UI展示 - 展示到设备状态页
- await Task.Run(() =>
- {
- try
- {
- if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
- {
- Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
- if (Form_Main.formDevAlarm.Visible)
- Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
- }
- }
- catch
- {
- }
- });
- FaultDataOld = FaultData.ToArray();
- }
- }
- //FaultLogRequest request = new FaultLogRequest();
- //request.station = mesStation; // 工位
- //request.fault_name = xmFaultName; // 故障名称(同数据字典中的事件名称)
- //request.fault_code = xmFaultCode2; // 故障编码(A,B,C,D,E)
- //request.fault_cmpnt = xmFaultCmpnt; // 故障部件
- //request.fault_desc = xmFaultDesc; // 故障描述
- //request.fault_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 故障发生时间 2022-06-01 14:27:57.283
- // // 上传
- //(int, string) iotResult = XiaomiMqttClient_Extend.Write_FaultLog(request, type1, type2, type3, request.fault_cmpnt, deciveCode);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- }
- public void operateToIot(string action, string stationNameStr)
- {
- OperateLogRequest request = new OperateLogRequest();
- request.software_version = "V" + Application.ProductVersion; // 软件版本号;如:V1.2.4
- request.operate_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 操作时间(2022-06-01 14:27:57.283)
- request.operate_action = action; // 操作动作(对应软件开启/关闭/重新加载项⽬;startup、shutdown、reload)
- //request.current_process = Process.GetCurrentProcess()?.Id.ToString(); // 当前进程;进程ID
- request.current_process = Application.ProductName;
- request.operate_desc = stationNameStr; // 操作描述;如:供应商软件开启/关闭/重新加载项⽬
- request.operate_result = "success"; // 操作结果
- request.operator_name = "default"; // 操作账号名;填当前操作⽤⼾,如⽆则填default
- // 上传
- (int, string) iotResult = XiaomiMqttClient_Extend.Write_OperateLog(request);
- if (iotResult.Item1 != 0)
- {
- AddMessage(LogType.Info, "【操作记录】上传失败!错误原因:" + iotResult.Item2 + "操作状态:" + stationNameStr);
- }
- }
- private void 通用节拍接口(int plcNo, string stationNameStr, string tagMesCommName, string CarrierBarcode,
- IoT_DataSet_t iot_data)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = iot_data.BeatAction.ToString(); // 节拍类型(plc写入)
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode); //产品SN
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = iot_data.machineState;
- iotData.work_type = iot_data.work_type;
- iotData.testStatus = iot_data.testStatus;
- iotData.BeatAction = iot_data.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = iot_data.fault_codes;
- (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
- if (PLCresult.Item1 != 0)
- {
- OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iotData.BeatAction}写入成功!");
- }
- stopwatch2.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
- "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- //作业开始后要有物料和载具信息
- //if (string.IsNullOrEmpty(strProductBarcode) && string.IsNullOrEmpty(CarrierBarcode) &&
- // Convert.ToInt32(oEEType) > 2)
- //{
- // stopwatch2.Start();
- // //写入PLC
- // IoT_DataSet_t iotData = new IoT_DataSet_t();
- // iotData.machineState = iot_data.machineState;
- // iotData.work_type = iot_data.work_type;
- // iotData.testStatus = iot_data.testStatus;
- // iotData.BeatAction = iot_data.BeatAction;
- // iotData.beatReturn = 2; //NG
- // iotData.fault_codes = iot_data.fault_codes;
- // WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
- // stopwatch2.Stop();
- // AddMessage_Station(stationNameStr, LogType.Info,
- // stationNameStr + $"_[{CarrierBarcode}][{strProductBarcode}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
- // stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- // return;
- //}
- //else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(strProductBarcode))
- //{
- // stopwatch2.Start();
- // //写入PLC
- // IoT_DataSet_t iotData = new IoT_DataSet_t();
- // iotData.machineState = iot_data.machineState;
- // iotData.work_type = iot_data.work_type;
- // iotData.testStatus = iot_data.testStatus;
- // iotData.BeatAction = iot_data.BeatAction;
- // iotData.beatReturn = 2; //NG
- // iotData.fault_codes = iot_data.fault_codes;
- // WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
- // stopwatch2.Stop();
- // AddMessage_Station(stationNameStr, LogType.Info,
- // stationNameStr + $"_[{CarrierBarcode}]上传节拍失败!物料码不可为空;总用时" +
- // stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- // return;
- //}
- //else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(CarrierBarcode))
- //{
- // stopwatch2.Start();
- // //写入PLC
- // IoT_DataSet_t iotData = new IoT_DataSet_t();
- // iotData.machineState = iot_data.machineState;
- // iotData.work_type = iot_data.work_type;
- // iotData.testStatus = iot_data.testStatus;
- // iotData.BeatAction = iot_data.BeatAction;
- // iotData.beatReturn = 2; //NG
- // iotData.fault_codes = iot_data.fault_codes;
- // WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
- // stopwatch2.Stop();
- // AddMessage_Station(stationNameStr, LogType.Info,
- // stationNameStr + $"_上传节拍失败!载具码不可为空;总用时" +
- // stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- // return;
- //}
- short _result = 0;
- // 上传OEE
- (short, string) result =
- SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
- _result = result.Item1;
- resultStr = result.Item2;
- if (_result == 1)
- {
- stopwatch2.Start();
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = iot_data.machineState;
- iotData.work_type = iot_data.work_type;
- iotData.testStatus = iot_data.testStatus;
- iotData.BeatAction = iot_data.BeatAction;
- iotData.beatReturn = 1; //OK
- iotData.fault_codes = iot_data.fault_codes;
- (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
- if (PLCresult.Item1 != 0)
- {
- OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iotData.BeatAction}写入成功!");
- }
- stopwatch2.Stop();
- }
- else
- {
- stopwatch2.Start();
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = iot_data.machineState;
- iotData.work_type = iot_data.work_type;
- iotData.testStatus = iot_data.testStatus;
- iotData.BeatAction = iot_data.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = iot_data.fault_codes;
- (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
- if (PLCresult.Item1 != 0)
- {
- OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iotData.BeatAction}写入成功!");
- }
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = iot_data.machineState;
- iotData.work_type = iot_data.work_type;
- iotData.testStatus = iot_data.testStatus;
- iotData.BeatAction = iot_data.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = iot_data.fault_codes;
- (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- if (PLCresult.Item1 != 0)
- {
- OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iotData.BeatAction}写入成功!");
- }
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// 去除常见特殊字符,如 \r, \n, \t 等
- /// </summary>
- /// <param name="format"></param>
- /// <returns></returns>
- private static string FormatStrbyPLC(string format) {
-
- string cleanedString = Regex.Replace(format, @"[\r\n\t]", "");
- return cleanedString;
- }
- #endregion
- #region S1
- /// <summary>
- /// [S1] 壳体清洁上料装备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S1(int plcNo)
- {
- string stationCode = "[OP10]";
- string stationName = "壳体清洁上料";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP10_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagiotComnName = "iotData";
- string tagBarsetName = "BarcodeSet";
- string CarrierBarcode = "";
- string ProductBarcode = "";
- // 触发信号字典
- //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s1PLCSignal_Old.Add("a1OEEType", 0); // 节拍类型(plc写入)
- // PLC数据字典 赋值
- s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
- OP10_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs1)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = FunsEip[plcNo]
- .Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //richTextBox1.AppendText("\n" + "读取成功");
- stPLC_MesData.BarcodeSet.strProductBarcode=FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
- stPLC_MesData.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
- stPLC_MesData.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
- stPLC_MesData.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
- //设备状态
- int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
- xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
- ? XiaomiDeviceState.Unknown
- : (XiaomiDeviceState)xmDeviceStateInt;
- // 载具SN
- CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode.ToString();
- // 物料码(物料码还未绑定载具SN时必填)
- ProductBarcode = stPLC_MesData.BarcodeSet.strProductBarcode;
- // 节拍
- s1PLCData["a1OEEType"] = stPLC_MesData.iotData.BeatAction;
- //报警信息
- _FaultDatas = stPLC_MesData.iotData.fault_codes;
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 进站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
- ProgressState = true;
- Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData,
- tagBaseName + "." + tagMesCommName, out ProgressState));
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- #region 出站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData,
- tagBaseName + "." + tagMesCommName, stationCode, stationName,
- out ProgressState));
- stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
- uuid = "";
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 出站
- #region 节拍接口
- try
- {
- if (stPLC_MesData.iotData.BeatAction > 0)
- {
- int a1OEEType = Convert.ToInt32(s1PLCData["a1OEEType"]);
- int a1OEETypeGOld = Convert.ToInt32(s1PLCSignal_Old["a1OEEType"]);
- //若设备紧急复原后节拍重置
- if (a1OEEType == 1)
- {
- a1OEETypeGOld = 0;
- }
- if (a1OEEType != a1OEETypeGOld)
- {
- //如果上位机告诉PLC NG,PLC节拍会直接从1跳到4
- if (a1OEETypeGOld <= 2 && a1OEEType == 4)
- {
- Task.Run(() =>
- 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
- CarrierBarcode,
- stPLC_MesData.iotData));
- }
- else
- {
- //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
- if ((a1OEETypeGOld == 1 && a1OEEType != 2) ||
- (a1OEETypeGOld == 3 && a1OEEType != 4) ||
- (a1OEETypeGOld == 5 && a1OEEType != 6))
- {
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = stPLC_MesData.iotData.machineState;
- iotData.work_type = stPLC_MesData.iotData.work_type;
- iotData.testStatus = stPLC_MesData.iotData.testStatus;
- iotData.BeatAction = stPLC_MesData.iotData.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = stPLC_MesData.iotData.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, 1,
- iotData);
- AddMessage(LogType.Info,
- stationNameStr +
- $"_节拍接口-- 设备本次上传节拍[{a1OEEType}],未上传节拍[{a1OEETypeGOld}]的结束信号,请检查;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds +
- "ms");
- return;
- }
- else
- {
- Task.Run(() => 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
- CarrierBarcode, stPLC_MesData.iotData));
- }
- }
- }
- }
- s1PLCSignal_Old["a1OEEType"] = s1PLCData["a1OEEType"];
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info,
- "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- FunsEip[plcNo].Connect(); // 重连
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S1] 壳体清洁上料 - 进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- /// <param name="stPLC_MesData"></param>
- /// <param name="tagMesCommName"></param>
- private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
- out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_进站开始");
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- if (string.IsNullOrEmpty(sn))
- {
- ProgressState = false;
- AddMessage(LogType.Error, $"{stationNameStr}_未能查到产品码");
- Thread.Sleep(10000);
- return;
- }
- //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
- // sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
- AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
- //绑定载具和产品
- ResponseMessage message = new ResponseMessage();
- message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
- if (message.result == false)
- {
- AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
- }
- // 产品SN进站
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
- item, MachineId, StationId, pass, "01-SLOT-01");
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- if (mesResultFrmWeb == 1)
- {
- mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
- AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
- }
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0;
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage(LogType.Error,
- $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
- str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站结束");
- AddMessage(LogType.Info,
- stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- /// <summary>
- /// [S1] 壳体清洁上料 - 出站接口
- /// </summary>
- private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
- string stationCode, string stationName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- test_item_num = 0; //iot 过站明细序号
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_出站开始");
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
- string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
- string sn = string.Empty;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
- string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- //a1Result = 1;
- bool pass = a1Result == 1;
- //根据载具码获取产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- ProgressState = false;
- AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
- Thread.Sleep(10000);
- return;
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- #region 转换过站明细字符串
- //创建字典
- var dic = new Dictionary<string, string>();
- // 获取结构体类型
- FieldInfo[] fields = typeof(OP10_DataSet_t).GetFields();
- // 遍历变量名转换成字典描述
- foreach (FieldInfo field in fields)
- {
- //获取枚举描述
- string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
- typeof(XiaomiMESEnum_ProcessData.Enum_10_ProcessData));
- //获取过站明细的值
- object valueObj = field.GetValue(stPLC_MesData.mesData);
- dic.Add(name, valueObj.ToString());
- }
- string paramJson = JsonConvert.SerializeObject(dic);
- #endregion
- //出站接口
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
- MachineId, StationId, "", paramJson);
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- if (mesResultFrmWeb == 1)
- {
- mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
- AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
- }
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站结束");
- //保存PLC返回MES数据到本地
- ResponseMessage message = new ResponseMessage();
- message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
- stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress,
- stPLC_MesData.mesData.fCleanSpeed,
- stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime,
- stPLC_MesData.mesData.nCleanCount,
- stPLC_MesData.mesData.nRemainCount);
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
- }
- AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage(LogType.Error,
- $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- #endregion
- #region S2
- /// <summary>
- /// [S2] 上盖板上料装备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S2(int plcNo)
- {
- string stationCode = "[OP20]";
- string stationName = "上盖板上料装备";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP20_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagiotComnName = "iotData";
- string tagBarsetName = "BarcodeSet";
- string CarrierBarcode = "";
- // 触发信号字典
- //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s2PLCSignal_Old.Add("a2OEEType", 0); // 节拍类型(plc写入)
- // PLC数据字典 赋值
- s2PLCData.Add("a2OEEType", 0); // 节拍类型(plc写入)
- OP20_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs2)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = FunsEip[plcNo]
- .Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //richTextBox1.AppendText("\n" + "读取成功");
- stPLC_MesData.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
- stPLC_MesData.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
- stPLC_MesData.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
- stPLC_MesData.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
- //设备状态
- int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
- xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
- ? XiaomiDeviceState.Unknown
- : (XiaomiDeviceState)xmDeviceStateInt;
- CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
- s2PLCData["a2OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
- //报警信息
- _FaultDatas = stPLC_MesData.iotData.fault_codes;
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 进站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
- ProgressState = true;
- Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData,
- tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
- out ProgressState));
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- #region 出站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData,
- tagBaseName + "." + tagMesCommName, stationCode, stationName,
- out ProgressState));
- stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
- uuid = "";
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 出站
- #region 节拍接口
- try
- {
- if (stPLC_MesData.iotData.BeatAction > 0)
- {
- int a2OEEType = Convert.ToInt32(s2PLCData["a2OEEType"]);
- int a2OEETypeGOld = Convert.ToInt32(s2PLCSignal_Old["a2OEEType"]);
- //若设备紧急复原后节拍重置
- if (a2OEEType == 1)
- {
- a2OEETypeGOld = 0;
- }
- if (a2OEEType != a2OEETypeGOld)
- {
- //如果上位机告诉PLC NG,PLC节拍会直接从1跳到4
- if (a2OEETypeGOld <= 2 && a2OEEType == 4)
- {
- Task.Run(() =>
- 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
- CarrierBarcode,
- stPLC_MesData.iotData));
- }
- else
- {
- //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
- if ((a2OEETypeGOld == 1 && a2OEEType != 2) ||
- (a2OEETypeGOld == 3 && a2OEEType != 4) ||
- (a2OEETypeGOld == 5 && a2OEEType != 6))
- {
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = stPLC_MesData.iotData.machineState;
- iotData.work_type = stPLC_MesData.iotData.work_type;
- iotData.testStatus = stPLC_MesData.iotData.testStatus;
- iotData.BeatAction = stPLC_MesData.iotData.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = stPLC_MesData.iotData.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
- AddMessage(LogType.Info,
- stationNameStr +
- $"_节拍接口-- 设备本次上传节拍[{a2OEEType}],未上传节拍[{a2OEETypeGOld}]的结束信号,请检查;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds +
- "ms");
- return;
- }
- else
- {
- Task.Run(() => 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
- CarrierBarcode, stPLC_MesData.iotData));
- //Task.Run(() =>
- // S2节拍接口(plcNo, stationNameStr, tagBaseName,
- // stPLC_MesData.iotData));
- }
- }
- }
- }
- s2PLCSignal_Old["a2OEEType"] = s2PLCData["a2OEEType"];
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
- //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info,
- "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- FunsEip[plcNo].Connect();
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- //Funs[plcNo].ReConnect();
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S2] 上盖板上料装备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
- string tagBarsetName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_进站开始");
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
- //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
- string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
- //根据载具码获取产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
- }
- //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
- //if (sn != strProductBarcode)
- //{
- // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
- //}
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
- item, MachineId, StationId, pass, "01-SLOT-01");
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- if (mesResultFrmWeb == 1)
- {
- mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
- AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
- }
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage(LogType.Error,
- $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
- str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站结束");
- AddMessage(LogType.Info,
- stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- /// <summary>
- /// [S2] 上盖板上料装备 - 出站接口
- /// </summary>
- private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
- string stationCode, string stationName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- test_item_num = 0; //iot 过站明细序号
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_出站开始");
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
- string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
- string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- //根据载具码获取产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
- ProgressState = false;
- Thread.Sleep(10000);
- return;
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "部件码",
- Parameter_value = PartBarcode,
- Parameter_unit = ""
- });
- string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
- MachineId, StationId, PartBarcode, paramJson);
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- if (mesResultFrmWeb == 1)
- {
- mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
- AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
- }
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站结束");
- //保存PLC返回MES数据到本地
- ResponseMessage message = new ResponseMessage();
- message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
- stPLC_MesData.mesData.nRemainCount);
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
- }
- if (!string.IsNullOrEmpty(PartBarcode))
- {
- message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
- if (message.result == false)
- {
- AddMessage(LogType.Error, message.text);
- }
- }
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage(LogType.Error,
- $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- #endregion
- #region S3
- /// <summary>
- /// [S3] 点散热胶装备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S3(int plcNo)
- {
- string stationCode = "[OP30]";
- string stationName = "点散热胶装备";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP30_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagiotComnName = "iotData";
- string tagBarsetName = "BarcodeSet";
- string CarrierBarcode_Left = "";
- string CarrierBarcode_Right = "";
- s3PLCSignal_Old.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
- s3PLCSignal_Old.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
- // PLC数据字典 赋值
- s3PLCData.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
- s3PLCData.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
- OP30_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs2)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = FunsEip[plcNo]
- .Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- #region 去除扫码产生的特殊字符
- stPLC_MesData.Left.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strProductBarcode);
- stPLC_MesData.Left.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPartBarcode);
- stPLC_MesData.Left.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strCarrierBarcode);
- stPLC_MesData.Left.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPCBBarcode);
- stPLC_MesData.Right.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strProductBarcode);
- stPLC_MesData.Right.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPartBarcode);
- stPLC_MesData.Right.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strCarrierBarcode);
- stPLC_MesData.Right.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPCBBarcode);
- #endregion
- //richTextBox1.AppendText("\n" + "读取成功");
- //设备状态
- int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
- int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
- xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
- ? XiaomiDeviceState.Unknown
- : (XiaomiDeviceState)xmDeviceStateInt_L;
- xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
- ? XiaomiDeviceState.Unknown
- : (XiaomiDeviceState)xmDeviceStateInt_R;
- //载具SN
- CarrierBarcode_Left = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode;
- CarrierBarcode_Right = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode;
- // 节拍
- s3PLCData["a3OEEType_left"] = stPLC_MesData.Left.iotData.BeatAction;
- s3PLCData["a3OEEType_right"] = stPLC_MesData.Right.iotData.BeatAction;
- //报警信息
- _FaultDatas = stPLC_MesData.Left.iotData.fault_codes;
- _FaultDatas2 = stPLC_MesData.Right.iotData.fault_codes;
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 左边进站
- try
- {
- if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- stationCode = "[OP31]";
- stationName = "点散热胶装备1";
- stationNameStr = stationCode + stationName;
- uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
- ProgressState = true;
- Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left,
- tagBaseName + ".Left." + tagMesCommName,
- tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 左边进站
- #region 左边出站
- try
- {
- if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- stationCode = "[OP31]";
- stationName = "点散热胶装备1";
- stationNameStr = stationCode + stationName;
- ProgressState = true;
- Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left,
- tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
- out ProgressState));
- stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
- uuid = "";
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 左边出站
- #region 右边进站
- try
- {
- if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
- stationCode = "[OP32]";
- stationName = "点散热胶装备2";
- stationNameStr = stationCode + stationName;
- ProgressState = true;
- Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right,
- tagBaseName + ".Right." + tagMesCommName,
- tagBaseName + ".Right." + tagBarsetName, "Right", out ProgressState));
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 右边进站
- #region 右边出站
- try
- {
- if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- stationCode = "[OP32]";
- stationName = "点散热胶装备2";
- stationNameStr = stationCode + stationName;
- ProgressState = true;
- Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right,
- tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
- out ProgressState));
- stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
- uuid = "";
- }
- }
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 右边出站
- #region 节拍接口
- try
- {
- #region 左工位 节拍
- if (stPLC_MesData.Left.iotData.BeatAction > 0)
- {
- stationCode = "[OP31]";
- stationName = "点散热胶装备1";
- stationNameStr = stationCode + stationName;
- int a3OEEType_left = Convert.ToInt32(s3PLCData["a3OEEType_left"]);
- int a3OEETypeGOld_left = Convert.ToInt32(s3PLCSignal_Old["a3OEEType_left"]);
- //若设备紧急复原后节拍重置
- if (a3OEEType_left == 1)
- {
- a3OEETypeGOld_left = 0;
- }
- if (a3OEEType_left != a3OEETypeGOld_left)
- {
- //如果上位机告诉PLC NG,PLC节拍会直接从1跳到4
- if (a3OEETypeGOld_left <= 2 && a3OEEType_left == 4)
- {
- Task.Run(() =>
- 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagiotComnName,
- CarrierBarcode_Left,
- stPLC_MesData.Left.iotData));
- }
- else
- {
- //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
- if ((a3OEETypeGOld_left == 1 && a3OEEType_left != 2) ||
- (a3OEETypeGOld_left == 3 && a3OEEType_left != 4)
- || (a3OEETypeGOld_left == 5 && a3OEEType_left != 6))
- {
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = stPLC_MesData.Left.iotData.machineState;
- iotData.work_type = stPLC_MesData.Left.iotData.work_type;
- iotData.testStatus = stPLC_MesData.Left.iotData.testStatus;
- iotData.BeatAction = stPLC_MesData.Left.iotData.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = stPLC_MesData.Left.iotData.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr,
- tagBaseName + ".Left." + tagiotComnName, 1, iotData);
- AddMessage(LogType.Info,
- stationNameStr +
- $"_节拍接口-- 设备本次上传节拍[{a3OEEType_left}],未上传节拍[{a3OEETypeGOld_left}]的结束信号,请检查;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds +
- "ms");
- return;
- }
- else
- {
- Task.Run(() => 通用节拍接口(plcNo, stationNameStr,
- tagBaseName + ".Left." + tagiotComnName, CarrierBarcode_Left,
- stPLC_MesData.Left.iotData));
- //Task.Run(() =>
- // S3节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagiotComnName, stPLC_MesData.Left.BarcodeSet.strCarrierBarcode.ToString(),
- // stPLC_MesData.Left.iotData));
- }
- }
- }
- }
- s3PLCSignal_Old["a3OEEType_left"] = s3PLCData["a3OEEType_left"];
- #endregion 左工位 节拍
- #region 右工位 节拍
- if (stPLC_MesData.Right.iotData.BeatAction > 0)
- {
- stationCode = "[OP32]";
- stationName = "点散热胶装备2";
- stationNameStr = stationCode + stationName;
- int a3OEEType_right = Convert.ToInt32(s3PLCData["a3OEEType_right"]);
- int a3OEETypeGOld_right = Convert.ToInt32(s3PLCSignal_Old["a3OEEType_right"]);
- //若设备紧急复原后节拍重置
- if (a3OEEType_right == 1)
- {
- a3OEETypeGOld_right = 0;
- }
- if (a3OEEType_right != a3OEETypeGOld_right)
- {
- if (a3OEETypeGOld_right <= 2 && a3OEEType_right == 4)
- {
- Task.Run(() =>
- 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagiotComnName,
- CarrierBarcode_Right,
- stPLC_MesData.Right.iotData));
- }
- else
- {
- //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
- if ((a3OEETypeGOld_right == 1 && a3OEEType_right != 2) ||
- (a3OEETypeGOld_right == 3 && a3OEEType_right != 4) ||
- (a3OEETypeGOld_right == 5 && a3OEEType_right != 6))
- {
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = stPLC_MesData.Left.iotData.machineState;
- iotData.work_type = stPLC_MesData.Left.iotData.work_type;
- iotData.testStatus = stPLC_MesData.Left.iotData.testStatus;
- iotData.BeatAction = stPLC_MesData.Left.iotData.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = stPLC_MesData.Left.iotData.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr,
- tagBaseName + ".Right." + tagiotComnName, 1, iotData);
- AddMessage(LogType.Info,
- stationNameStr +
- $"_节拍接口-- 设备本次上传节拍[{a3OEEType_right}],未上传节拍[{a3OEETypeGOld_right}]的结束信号,请检查;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds +
- "ms");
- return;
- }
- else
- {
- Task.Run(() =>
- 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagiotComnName,
- CarrierBarcode_Right,
- stPLC_MesData.Right.iotData));
- //Task.Run(() =>
- // S3节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagiotComnName,
- // stPLC_MesData.Right.BarcodeSet.strCarrierBarcode,
- // stPLC_MesData.Left.iotData));
- }
- }
- }
- }
- s3PLCSignal_Old["a3OEEType_right"] = s3PLCData["a3OEEType_right"];
- #endregion 右工位 节拍
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
- //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info,
- "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- FunsEip[plcNo].Connect();
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- //Funs[plcNo].ReConnect();
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S3] 点散热胶装备 - 进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
- string tagBarsetName, string direction, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
- string StationId = string.Empty;
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- string slot = "";
- if (direction == "Left")
- {
- StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
- slot = "01-SLOT-01";
- }
- if (direction == "Right")
- {
- StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
- slot = "01-SLOT-02";
- }
- string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
- //载具码验证产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
- item, MachineId, StationId, pass, slot);
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- if (mesResultFrmWeb == 1)
- {
- mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
- AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
- }
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage(LogType.Error,
- $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
- str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
- AddMessage(LogType.Info,
- stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- /// <summary>
- /// [S3] 点散热胶装备 - 出站
- /// </summary>
- private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
- string stationCode, string stationName, string direction, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- test_item_num = 0; //iot 过站明细序号
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
- string StationId = string.Empty;
- if (direction == "Left")
- {
- StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
- }
- if (direction == "Right")
- {
- StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
- }
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- //根据载具码获取产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
- ProgressState = false;
- Thread.Sleep(10000);
- return;
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- //if (direction == "Right")
- //{
- string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
- MachineId, StationId, "", paramJson, direction);
- //}
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- if (mesResultFrmWeb == 1)
- {
- mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
- AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
- }
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
- //保存PLC返回MES数据到本地
- ResponseMessage message = new ResponseMessage();
- if (direction == "Left")
- {
- string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
- string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
- string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
- message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
- stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
- strMesHeightInfos, strIntervalWeights, strRemainGlues);
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
- }
- }
- if (direction == "Right")
- {
- string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
- string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
- string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
- message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
- stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
- strMesHeightInfos, strIntervalWeights, strRemainGlues);
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
- }
- }
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage(LogType.Error,
- $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- #endregion S3
- #region S4
- /// <summary>
- /// [S4] 点胶检测设备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S4(int plcNo)
- {
- string stationCode = "[OP40]";
- string stationName = "胶线检测";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP40_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagiotComnName = "iotData";
- string tagBarsetName = "BarcodeSet";
- string CarrierBarcode = "";
- // 触发信号字典
- //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s4PLCSignal_Old.Add("a4OEEType", 0); // 节拍类型(plc写入)
- // PLC数据字典 赋值
- s4PLCData.Add("a4OEEType", 0); // 节拍类型(plc写入)
- OP40_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs1)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = FunsEip[plcNo]
- .Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //去除扫码产生的特殊字符
- stPLC_MesData.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
- stPLC_MesData.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
- stPLC_MesData.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
- stPLC_MesData.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
- //richTextBox1.AppendText("\n" + "读取成功");
- int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
- xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
- ? XiaomiDeviceState.Unknown
- : (XiaomiDeviceState)xmDeviceStateInt;
- // 载具SN
- CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode;
- // 节拍
- s4PLCData["a4OEEType"] = stPLC_MesData.iotData.BeatAction;
- //报警信息
- _FaultDatas = stPLC_MesData.iotData.fault_codes;
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 进站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
- ProgressState = true;
- Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData,
- tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
- out ProgressState));
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- #region 出站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData,
- tagBaseName + "." + tagMesCommName, stationCode, stationName,
- out ProgressState));
- stPLC_MesData.mesCommFrmPLC.cmd = 0;
- uuid = "";
- }
- }
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 出站
- #region 节拍接口
- try
- {
- if (stPLC_MesData.iotData.BeatAction > 0)
- {
- int a4OEEType = Convert.ToInt32(s4PLCData["a4OEEType"]);
- int a4OEETypeGOld = Convert.ToInt32(s4PLCSignal_Old["a4OEEType"]);
- //若设备紧急复原后节拍重置
- if (a4OEEType == 1)
- {
- a4OEETypeGOld = 0;
- }
- if (a4OEEType != a4OEETypeGOld)
- {
- if (a4OEETypeGOld <= 2 && a4OEEType == 4)
- {
- Task.Run(() =>
- 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
- CarrierBarcode,
- stPLC_MesData.iotData));
- }
- else
- {
- //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
- if ((a4OEETypeGOld == 1 && a4OEEType != 2) ||
- (a4OEETypeGOld == 3 && a4OEEType != 4) ||
- (a4OEETypeGOld == 5 && a4OEEType != 6))
- {
- //写入PLC
- stPLC_MesData.iotData.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1,
- stPLC_MesData.iotData);
- AddMessage(LogType.Info,
- stationNameStr +
- $"_节拍接口-- 设备本次上传节拍[{a4OEEType}],未上传节拍[{a4OEETypeGOld}]的结束信号,请检查;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds +
- "ms");
- return;
- }
- else
- {
- Task.Run(() => 通用节拍接口(plcNo, stationNameStr,
- tagBaseName + "." + tagiotComnName, CarrierBarcode,
- stPLC_MesData.iotData));
- //Task.Run(() =>
- // S4节拍接口(plcNo, stationNameStr, tagBaseName,
- // stPLC_MesData.iotData));
- }
- }
- }
- }
- s4PLCSignal_Old["a4OEEType"] = s4PLCData["a4OEEType"];
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info,
- "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- FunsEip[plcNo].Connect(); // 重连
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S4] 点胶检测设备 - 进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- /// <param name="stPLC_MesData"></param>
- /// <param name="tagMesCommName"></param>
- private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
- string tagBarsetName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- test_item_num = 0; //iot 过站明细序号
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_进站开始");
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
- //载具码验证产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
- ProgressState = false;
- Thread.Sleep(10000);
- return;
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
- item, MachineId, StationId, pass, "01-SLOT-01");
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- if (mesResultFrmWeb == 1)
- {
- mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
- AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
- }
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage(LogType.Error,
- $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
- str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站结束");
- AddMessage(LogType.Info,
- stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- /// <summary>
- /// [S4] 点胶检测设备 - 出站接口
- /// </summary>
- private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
- string stationCode, string stationName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- test_item_num = 0; //iot 过站明细序号
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_出站开始");
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
- string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- //根据载具码获取产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
- ProgressState = false;
- Thread.Sleep(10000);
- return;
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- #region 上传图片
- if (GlobalContext.MQTTIsSendUpFile)
- {
- string[] urlarry = GlobalContext.UpFilePath.Split(",");
- fileUploadData.fileData.Clear();
- foreach (var item in urlarry)
- {
- if (!string.IsNullOrEmpty(item))
- {
- //上传图片
- var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName, a1Result,
- item, uuid).Result;
- OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
- }
- }
- }
- #endregion
- string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode,
- "01-SLOT-01", MachineId, StationId, "", paramJson);
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- if (mesResultFrmWeb == 1)
- {
- mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
- AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
- }
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站结束");
- //保存PLC返回MES数据到本地
- ResponseMessage message = new ResponseMessage();
- string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
- string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
- string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
- string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
- message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
- strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
- }
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage(LogType.Error,
- $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- private void S4节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = ((int)s1PLCData["a4OEEType"]).ToString(); // 节拍类型(plc写入)
- string a40EEPartNo = (string)s1PLCData["a40EEPartNo"]; // 物料码
- a40EEPartNo = a40EEPartNo.Replace("\0", "");
- string a50EEVehicleCode = (string)s1PLCData["a50EEVehicleCode"]; // 载具SN
- a50EEVehicleCode = a50EEVehicleCode.Replace("\0", "");
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
- "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- //作业开始后要有物料和载具信息
- if (string.IsNullOrEmpty(a40EEPartNo) && string.IsNullOrEmpty(a50EEVehicleCode) &&
- Convert.ToInt32(oEEType) > 2)
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a40EEPartNo))
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a50EEVehicleCode))
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- short _result = 0;
- // 上传OEE
- (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a40EEPartNo, a50EEVehicleCode);
- _result = result.Item1;
- resultStr = result.Item2;
- if (_result == 1)
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 1; //OK
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- OnMessage(LogType.Info,
- $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
- stopwatch2.Stop();
- }
- else
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- #endregion
- #region S5
- private static bool isPCBStation = false;//控制PCB是否进出站的标识
- /// <summary>
- /// [S5] 点胶检测设备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S5(int plcNo)
- {
- string stationCode = "[OP50]";
- string stationName = "ADD板上料组装装备";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP50_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagiotComnName = "iotData";
- string tagBarsetName = "BarcodeSet";
- string pcbBarcode = "";
- string pcbBarcodeOld = "";
- OP50_MesData_t stPLC_MesData; //PLC的MES数据
- string CarrierBarcode = "";
- // 触发信号字典
- s5PLCSignal_Old.Add("a5OEEType", 0); // 节拍类型(plc写入)
- // PLC数据字典 赋值
- s5PLCData.Add("a5OEEType", 0); // 节拍类型(plc写入)
- (int, string) result;
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs1)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- //测试数据
- //stPLC_MesData.mesCommFrmPLC.cmd = 2;
- //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
- //stPLC_MesData.BarcodeSet.strPCBBarcode = "A1507V000239";
- //stPLC_MesData.iotData.BeatAction = 1;
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = FunsEip[plcNo]
- .Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- }
- else
- {
- stPLC_MesData.BarcodeSet.strPCBBarcode = "A1507V000239\r";
- //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
- #region 去除扫码产生的特殊字符
- stPLC_MesData.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
- stPLC_MesData.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
- stPLC_MesData.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
- stPLC_MesData.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
- #endregion
- //richTextBox1.AppendText("\n" + "读取成功");
- int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
- xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
- ? XiaomiDeviceState.Unknown
- : (XiaomiDeviceState)xmDeviceStateInt;
- // 节拍
- s5PLCData["a5OEEType"] = stPLC_MesData.iotData.BeatAction;
- //载具码
- CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode.ToString();
- //报警信息
- _FaultDatas = stPLC_MesData.iotData.fault_codes;
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 进站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
- ProgressState = true;
- string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
- if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
- {
- ProgressState = true;
- Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- #region 出站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData,
- tagBaseName + "." + tagMesCommName, stationCode, stationName,
- out ProgressState));
- stPLC_MesData.mesCommFrmPLC.cmd = 0;
- uuid = "";
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 出站
- #region 节拍接口
- try
- {
- if (stPLC_MesData.iotData.BeatAction > 0)
- {
- int a5OEEType = Convert.ToInt32(s5PLCData["a5OEEType"]);
- int a5OEETypeGOld = Convert.ToInt32(s5PLCSignal_Old["a5OEEType"]);
- //若设备紧急复原后节拍重置
- if (a5OEEType == 1)
- {
- a5OEETypeGOld = 0;
- }
- if (a5OEEType != a5OEETypeGOld)
- {
- //如果上位机告诉PLC NG,PLC节拍会直接从1跳到4
- if (a5OEETypeGOld <= 2 && a5OEEType == 4)
- {
- Task.Run(() =>
- 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
- CarrierBarcode,
- stPLC_MesData.iotData));
- }
- else
- {
- //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
- if ((a5OEETypeGOld == 1 && a5OEEType != 2) ||
- (a5OEETypeGOld == 3 && a5OEEType != 4) ||
- (a5OEETypeGOld == 5 && a5OEEType != 6))
- {
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = stPLC_MesData.iotData.machineState;
- iotData.work_type = stPLC_MesData.iotData.work_type;
- iotData.testStatus = stPLC_MesData.iotData.testStatus;
- iotData.BeatAction = stPLC_MesData.iotData.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = stPLC_MesData.iotData.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
- 1, iotData);
- AddMessage(LogType.Info,
- stationNameStr +
- $"_节拍接口-- 设备本次上传节拍[{a5OEEType}],未上传节拍[{a5OEETypeGOld}]的结束信号,请检查;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds +
- "ms");
- return;
- }
- else
- {
- Task.Run(() => 通用节拍接口(plcNo, stationNameStr,
- tagBaseName + "." + tagiotComnName, CarrierBarcode,
- stPLC_MesData.iotData));
- }
- }
- }
- }
- s5PLCSignal_Old["a5OEEType"] = s5PLCData["a5OEEType"];
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info,
- "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- FunsEip[plcNo].Connect(); // 重连
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S5] 点胶检测设备 - 进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- /// <param name="stPLC_MesData"></param>
- /// <param name="tagMesCommName"></param>
- private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
- string tagBarsetName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_进站开始");
- //string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
- string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
- string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码
- string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- AddMessage(LogType.Info, $"ADD板编码(PCB码):{pcbBarcode}");
- //绑定载具和产品
- ResponseMessage message = new ResponseMessage();
- message = SQLHelper.PCBCarrierBind(strCarrierBarcode, pcbBarcode);
- if (message.result == false)
- {
- AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
- }
- //载具码验证产品码 //载具码验证产品码
- //string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
- //if (string.IsNullOrEmpty(strProductBarcode))
- //{
- // AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
- //}
- //sn = strProductBarcode;
- //AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
- item, MachineId, StationId, pass, "01-SLOT-01");
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 2 : 120);
- if (mesResultFrmWeb == 1)
- {
- AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
- }
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage(LogType.Error,
- $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
- str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站结束");
- AddMessage(LogType.Info,
- stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- /// <summary>
- /// [S5] 点胶检测设备 - 出站接口
- /// </summary>
- private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
- string stationCode, string stationName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- test_item_num = 0; //iot 过站明细序号
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_出站开始");
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 部件条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
- string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
- string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- CommandFromPLC resultToPlC = new CommandFromPLC();
- //根据载具码获取产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
- ProgressState=false;
- //写入PLC
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- return;
- }
- stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
- sn = strProductBarcode;
- //数据库绑定载具和PCB
- ResponseMessage message = new ResponseMessage();
- message = SQLHelper.PCBCarrierBind(CarrierBarcode, pcbBarcode);
- if (message.result == false)
- {
- AddMessage(LogType.Error, stationNameStr + "_PCB码数据库绑定失败,错误:" + message.text);
- ProgressState = true;//防止循环报错
- return;
- }
- AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn};PCB码:{pcbBarcode}");
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "PCB码",
- Parameter_value = pcbBarcode,
- Parameter_unit = ""
- });
- #region 上传图片
- if (GlobalContext.MQTTIsSendUpFile)
- {
- string[] urlarry = GlobalContext.UpFilePath.Split(",");
- fileUploadData.fileData.Clear();
- foreach (var item in urlarry)
- {
- if (!string.IsNullOrEmpty(item))
- {
- //上传图片
- var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName, a1Result,
- item, uuid).Result;
- OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
- }
- }
- }
- #endregion
- string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
- MachineId, StationId, PartBarcode, paramJson);
- int result1 = 0;
- byte mesResultFrmWeb = 0;
- if (stPLC_MesData.mesCommFrmPLC.cmdParam == 2) {
- result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num
- , mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode, paramJson);
- }
- else if (stPLC_MesData.mesCommFrmPLC.cmdParam == 1) {
- result1=PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
- }
- mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- //进站结果写入PLC
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- AddMessage(LogType.Info, stationNameStr + "_出站结束");
- //保存PLC返回MES数据到本地
- //ResponseMessage message = new ResponseMessage();
- message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
- stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB, stPLC_MesData.mesData.nRemainCount, "");
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
- }
- //保存部件码信息
- if (!string.IsNullOrEmpty(PartBarcode))
- {
- message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
- }
- }
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage(LogType.Error,
- $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- private int S5_PCB进出站(OP50_MesData_t stPLC_MesData,int plcNo,string stationNameStr,string tagBaseName,string tagMesCommName) {
- string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
- if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
- {
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(stPLC_MesData.BarcodeSet.strCarrierBarcode);
- stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- if (GlobalContext.IsSendStationIn)
- {
- #region 进站
- //int res1 = PCBStationInData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
- //if (res1 == 1)
- //{
- // resultToPlC.cmdResult = 2;//OK
- // WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
- //}
- //else
- //{
- // resultToPlC.cmdResult = 120;
- // WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
- // return 2;
- //}
- #endregion
- #region 出站
- int res2 = PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
- if (res2 == 1)
- {
- resultToPlC.cmdResult = 2;//OK
- WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
- return 1;
- }
- else
- {
- resultToPlC.cmdResult = 120;
- WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
- return 2;
- }
- #endregion
- }
- else {
- return 2;
- }
- }
- else
- {
- return 2;
- }
- }
- private void S5节拍接口(int plcNo, string stationNameStr, string tagMesCommName, string CarrierBarcode,
- IoT_DataSet_t iot_data)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = iot_data.BeatAction.ToString(); // 节拍类型(plc写入)
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode); //产品SN
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = iot_data.machineState;
- iotData.work_type = iot_data.work_type;
- iotData.testStatus = iot_data.testStatus;
- iotData.BeatAction = iot_data.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = iot_data.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
- stopwatch2.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
- "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- //作业开始后要有物料和载具信息
- if (string.IsNullOrEmpty(strProductBarcode) && string.IsNullOrEmpty(CarrierBarcode) &&
- Convert.ToInt32(oEEType) > 2)
- {
- stopwatch2.Start();
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = iot_data.machineState;
- iotData.work_type = iot_data.work_type;
- iotData.testStatus = iot_data.testStatus;
- iotData.BeatAction = iot_data.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = iot_data.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{CarrierBarcode}][{strProductBarcode}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(strProductBarcode))
- {
- stopwatch2.Start();
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = iot_data.machineState;
- iotData.work_type = iot_data.work_type;
- iotData.testStatus = iot_data.testStatus;
- iotData.BeatAction = iot_data.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = iot_data.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{CarrierBarcode}]上传节拍失败!物料码不可为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(CarrierBarcode))
- {
- stopwatch2.Start();
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = iot_data.machineState;
- iotData.work_type = iot_data.work_type;
- iotData.testStatus = iot_data.testStatus;
- iotData.BeatAction = iot_data.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = iot_data.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_上传节拍失败!载具码不可为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- short _result = 0;
- // 上传OEE
- (short, string) result =
- SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
- _result = result.Item1;
- resultStr = result.Item2;
- if (_result == 1)
- {
- stopwatch2.Start();
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = iot_data.machineState;
- iotData.work_type = iot_data.work_type;
- iotData.testStatus = iot_data.testStatus;
- iotData.BeatAction = iot_data.BeatAction;
- iotData.beatReturn = 1; //OK
- iotData.fault_codes = iot_data.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
- OnMessage(LogType.Info,
- $"PLC{plcNo}_{stationNameStr} 节拍{iotData.BeatAction}上传IOT成功!上传结果:" + resultStr);
- stopwatch2.Stop();
- }
- else
- {
- stopwatch2.Start();
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = iot_data.machineState;
- iotData.work_type = iot_data.work_type;
- iotData.testStatus = iot_data.testStatus;
- iotData.BeatAction = iot_data.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = iot_data.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = iot_data.machineState;
- iotData.work_type = iot_data.work_type;
- iotData.testStatus = iot_data.testStatus;
- iotData.BeatAction = iot_data.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = iot_data.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- #endregion
- #region S6
- private Dictionary<string, object> s6PLCData = new Dictionary<string, object>();
- private Dictionary<string, object> s6PLCSignal_Old = new Dictionary<string, object>();
- /// <summary>
- /// [S6] 顶盖装配设备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S6(int plcNo)
- {
- string stationCode = "[OP70]";
- string stationName = "组上盖板";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP60_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagiotComnName = "iotData";
- string tagBarsetName = "BarcodeSet";
- string CarrierBarcode = "";
- // 触发信号字典
- s6PLCSignal_Old.Add("a6OEEType", 0); // 节拍类型(plc写入)
- // PLC数据字典 赋值
- s6PLCData.Add("a6OEEType", 0); // 节拍类型(plc写入)
- OP60_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs1)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- //弹出扫码框则停止循环
- if (isNoStop)
- {
- Task.Delay(1000);
- continue;
- }
- if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = FunsEip[plcNo]
- .Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
- //测试
- //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
- //stPLC_MesData.mesCommFrmPLC.cmd = 1;
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //去除扫码产生的特殊字符
- stPLC_MesData.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
- stPLC_MesData.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
- stPLC_MesData.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
- stPLC_MesData.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
- //richTextBox1.AppendText("\n" + "读取成功");
- int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
- xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
- ? XiaomiDeviceState.Unknown
- : (XiaomiDeviceState)xmDeviceStateInt;
- CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
- s6PLCData["a6OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
- //报警信息
- _FaultDatas = stPLC_MesData.iotData.fault_codes;
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 进站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
- ProgressState = true;
- Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData,
- tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
- out ProgressState));
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- #region 出站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- ;
- Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData,
- tagBaseName + "." + tagMesCommName, stationCode, stationName,
- out ProgressState));
- stPLC_MesData.mesCommFrmPLC.cmd = 0;
- uuid = "";
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 出站
- #region 节拍接口
- try
- {
- if (stPLC_MesData.iotData.BeatAction > 0)
- {
- int a6OEEType = Convert.ToInt32(s6PLCData["a6OEEType"]);
- int a6OEETypeGOld = Convert.ToInt32(s6PLCSignal_Old["a6OEEType"]);
- //若设备紧急复原后节拍重置
- if (a6OEEType == 1)
- {
- a6OEETypeGOld = 0;
- }
- if (a6OEEType != a6OEETypeGOld)
- {
- if (a6OEETypeGOld <= 2 && a6OEEType == 4)
- {
- Task.Run(() =>
- 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
- CarrierBarcode,
- stPLC_MesData.iotData));
- }
- else
- {
- //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
- if ((a6OEETypeGOld == 1 && a6OEEType != 2) ||
- (a6OEETypeGOld == 3 && a6OEEType != 4) ||
- (a6OEETypeGOld == 5 && a6OEEType != 6))
- {
- //写入PLC
- stPLC_MesData.iotData.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1,
- stPLC_MesData.iotData);
- AddMessage(LogType.Info,
- stationNameStr +
- $"_节拍接口-- 设备本次上传节拍[{a6OEEType}],未上传节拍[{a6OEETypeGOld}]的结束信号,请检查;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds +
- "ms");
- return;
- }
- else
- {
- Task.Run(() =>
- 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
- CarrierBarcode,
- stPLC_MesData.iotData));
- //Task.Run(() =>
- // S6节拍接口(plcNo, stationNameStr, tagBaseName,
- // stPLC_MesData.iotData));
- }
- }
- }
- }
- s6PLCSignal_Old["a6OEEType"] = s6PLCData["a6OEEType"];
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info,
- "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- FunsEip[plcNo].Connect(); // 重连
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S6] 顶盖装配设备 - 进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- /// <param name="stPLC_MesData"></param>
- /// <param name="tagMesCommName"></param>
- private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
- string tagBarsetName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_进站开始");
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
- //strCarrierBarcode = "N801A-003";
- //载具码验证产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
- string strPCBBarcode = SQLHelper.GetPCBBarcodeByCarrierCode(strCarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
- if (OpenDailogFalg)
- {
- using (var dialog = new BandBarodeDialog())
- {
- dialog._CarrierBarcode = strCarrierBarcode;
- dialog._ProductBarcode = sn;
- dialog._PCBBarcode = strPCBBarcode;
- var rs = dialog.ShowDialog();
- if (rs == DialogResult.OK)
- {
- AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
- OpenDailogFalg = false; //关闭扫码
- isNoStop = false;
- }
- else
- {
- ProgressState = false;
- return;
- }
- }
- }
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
- item, MachineId, StationId, pass, "01-SLOT-01");
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- if (mesResultFrmWeb == 1)
- {
- mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
- AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
- }
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage(LogType.Error,
- $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
- str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站结束");
- AddMessage(LogType.Info,
- stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- OpenDailogFalg = true; //开启下一个物料的扫码
- }
- /// <summary>
- /// [S6] 顶盖装配设备 - 出站接口
- /// </summary>
- private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
- string stationCode, string stationName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- test_item_num = 0; //iot 过站明细序号
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_出站开始");
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
- string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- //根据载具码获取产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
- MachineId, StationId, "", paramJson);
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- if (mesResultFrmWeb == 1)
- {
- mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
- AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
- }
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站结束");
- //保存PLC返回MES数据到本地
- ResponseMessage message = new ResponseMessage();
- message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
- stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
- }
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage(LogType.Error,
- $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- private void S6节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = ((int)s1PLCData["a6OEEType"]).ToString(); // 节拍类型(plc写入)
- string a60EEPartNo = (string)s1PLCData["a60EEPartNo"]; // 物料码
- a60EEPartNo = a60EEPartNo.Replace("\0", "");
- string a60EEVehicleCode = (string)s1PLCData["a60EEVehicleCode"]; // 载具SN
- a60EEVehicleCode = a60EEVehicleCode.Replace("\0", "");
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
- "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- //作业开始后要有物料和载具信息
- if (string.IsNullOrEmpty(a60EEPartNo) && string.IsNullOrEmpty(a60EEVehicleCode) &&
- Convert.ToInt32(oEEType) > 2)
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a60EEPartNo))
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a60EEVehicleCode))
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- short _result = 0;
- // 上传OEE
- (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a60EEPartNo, a60EEVehicleCode);
- _result = result.Item1;
- resultStr = result.Item2;
- if (_result == 1)
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 1; //OK
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- OnMessage(LogType.Info,
- $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
- stopwatch2.Stop();
- }
- else
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- #endregion
- #region S7
- private Dictionary<string, object> s7PLCSignal_Old = new Dictionary<string, object>();
- private Dictionary<string, object> s7PLCData = new Dictionary<string, object>();
- /// <summary>
- /// [S7] 锁螺丝设备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S7(int plcNo)
- {
- string stationCode = "[OP80]";
- string stationName = "上盖板锁螺丝";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP70_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagBarsetName = "BarcodeSet";
- string tagiotComnName = "iotData";
- string tagScrewDataset = "screwDataset";
- string CarrierBarcode_Left = "";
- string CarrierBarcode_Right = "";
- s7PLCSignal_Old.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
- s7PLCSignal_Old.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
- // PLC数据字典 赋值
- s7PLCData.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
- s7PLCData.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
- OP70_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- AtlasScrew atlasScrewLeft = new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort,
- 3000, 3000, "Left");
- atlasScrewLeft.Initial();
- AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort,
- 3000, 3000, "Right");
- atlasScrewRight.Initial();
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs1)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = FunsEip[plcNo]
- .Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- #region 去除扫码产生的特殊字符
- stPLC_MesData.Left.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strProductBarcode);
- stPLC_MesData.Left.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPartBarcode);
- stPLC_MesData.Left.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strCarrierBarcode);
- stPLC_MesData.Left.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPCBBarcode);
- stPLC_MesData.Right.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strProductBarcode);
- stPLC_MesData.Right.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPartBarcode);
- stPLC_MesData.Right.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strCarrierBarcode);
- stPLC_MesData.Right.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPCBBarcode);
- #endregion
- int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
- int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
- xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
- ? XiaomiDeviceState.Unknown
- : (XiaomiDeviceState)xmDeviceStateInt_L;
- xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
- ? XiaomiDeviceState.Unknown
- : (XiaomiDeviceState)xmDeviceStateInt_R;
- s7PLCData["a7OEEPartNo"] =
- stPLC_MesData.Left.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
- // 载具SN
- CarrierBarcode_Left = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode;
- CarrierBarcode_Right = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode;
- // 节拍
- s7PLCData["a7OEEType"] = stPLC_MesData.Left.iotData.BeatAction;
- s7PLCData["a7OEEType_right"] = stPLC_MesData.Right.iotData.BeatAction;
- //报警信息
- _FaultDatas = stPLC_MesData.Left.iotData.fault_codes;
- _FaultDatas2 = stPLC_MesData.Right.iotData.fault_codes;
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 左边进站
- try
- {
- if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- stationCode = "[OP81]";
- stationName = "上盖板锁螺丝1";
- stationNameStr = stationCode + stationName;
- uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
- ProgressState = true;
- Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left,
- tagBaseName + ".Left." + tagMesCommName,
- tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState,
- atlasScrewLeft));
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 左边进站
- #region 左边出站
- try
- {
- if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- stationCode = "[OP81]";
- stationName = "上盖板锁螺丝1";
- stationNameStr = stationCode + stationName;
- ProgressState = true;
- Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left,
- tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
- out ProgressState));
- stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
- uuid = "";
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 左边出站
- #region 右边进站
- try
- {
- if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
- stationCode = "[OP82]";
- stationName = "上盖板锁螺丝2";
- stationNameStr = stationCode + stationName;
- ProgressState = true;
- Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right,
- tagBaseName + ".Right." + tagMesCommName,
- tagBaseName + ".Right" + tagBarsetName, "Right", out ProgressState,
- atlasScrewRight));
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 右边进站
- #region 右边出站
- try
- {
- if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- stationCode = "[OP82]";
- stationName = "上盖板锁螺丝2";
- stationNameStr = stationCode + stationName;
- ProgressState = true;
- Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right,
- tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
- out ProgressState));
- stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
- uuid = "";
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 右边出站
- #region 节拍接口
- try
- {
- #region 左工位 节拍
- if (stPLC_MesData.Left.iotData.BeatAction > 0)
- {
- stationCode = "[OP81]";
- stationName = "上盖板锁螺丝1";
- stationNameStr = stationCode + stationName;
- int a7OEEType_left = Convert.ToInt32(s7PLCData["a7OEEType_left"]);
- int a7OEETypeGOld_left = Convert.ToInt32(s7PLCSignal_Old["a7OEEType_left"]);
- //若设备紧急复原后节拍重置
- if (a7OEEType_left == 1)
- {
- a7OEETypeGOld_left = 0;
- }
- if (a7OEEType_left != a7OEETypeGOld_left)
- {
- //如果上位机告诉PLC NG,PLC节拍会直接从1跳到4
- if (a7OEETypeGOld_left <= 2 && a7OEEType_left == 4)
- {
- Task.Run(() =>
- 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName,
- CarrierBarcode_Left,
- stPLC_MesData.Left.iotData));
- }
- else
- {
- //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
- if ((a7OEETypeGOld_left == 1 && a7OEEType_left != 2) ||
- (a7OEETypeGOld_left == 3 && a7OEEType_left != 4) ||
- (a7OEETypeGOld_left == 5 && a7OEEType_left != 6))
- {
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = stPLC_MesData.Left.iotData.machineState;
- iotData.work_type = stPLC_MesData.Left.iotData.work_type;
- iotData.testStatus = stPLC_MesData.Left.iotData.testStatus;
- iotData.BeatAction = stPLC_MesData.Left.iotData.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = stPLC_MesData.Left.iotData.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr,
- tagBaseName + ".Left." + tagiotComnName, 1, iotData);
- AddMessage(LogType.Info,
- stationNameStr +
- $"_节拍接口-- 设备本次上传节拍[{a7OEEType_left}],未上传节拍[{a7OEETypeGOld_left}]的结束信号,请检查;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds +
- "ms");
- return;
- }
- else
- {
- Task.Run(() =>
- 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName,
- CarrierBarcode_Left,
- stPLC_MesData.Left.iotData));
- //Task.Run(() =>
- // S7节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName,
- // stPLC_MesData.Left.iotData));
- }
- }
- }
- }
- s7PLCSignal_Old["a7OEEType_left"] = s7PLCData["a7OEEType_left"];
- #endregion 左工位 节拍
- #region 右工位 节拍
- if (stPLC_MesData.Right.iotData.BeatAction > 0)
- {
- stationCode = "[OP82]";
- stationName = "上盖板锁螺丝2";
- stationNameStr = stationCode + stationName;
- int a7OEEType_right = Convert.ToInt32(s7PLCData["a7OEEType_right"]);
- int a7OEETypeGOld_right = Convert.ToInt32(s7PLCSignal_Old["a7OEEType_right"]);
- //若设备紧急复原后节拍重置
- if (a7OEEType_right == 1)
- {
- a7OEETypeGOld_right = 0;
- }
- if (a7OEEType_right != a7OEETypeGOld_right)
- {
- if (a7OEETypeGOld_right <= 2 && a7OEEType_right == 4)
- {
- Task.Run(() =>
- 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName,
- CarrierBarcode_Right,
- stPLC_MesData.Right.iotData));
- }
- else
- {
- //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
- if ((a7OEETypeGOld_right == 1 && a7OEEType_right != 2) ||
- (a7OEETypeGOld_right == 3 && a7OEEType_right != 4) ||
- (a7OEETypeGOld_right == 5 && a7OEEType_right != 6))
- {
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = stPLC_MesData.Left.iotData.machineState;
- iotData.work_type = stPLC_MesData.Left.iotData.work_type;
- iotData.testStatus = stPLC_MesData.Left.iotData.testStatus;
- iotData.BeatAction = stPLC_MesData.Left.iotData.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = stPLC_MesData.Left.iotData.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr,
- tagBaseName + ".Right." + tagiotComnName, 1, iotData);
- AddMessage(LogType.Info,
- stationNameStr +
- $"_节拍接口-- 设备本次上传节拍[{a7OEEType_right}],未上传节拍[{a7OEETypeGOld_right}]的结束信号,请检查;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds +
- "ms");
- return;
- }
- else
- {
- Task.Run(() =>
- 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName,
- CarrierBarcode_Right,
- stPLC_MesData.Right.iotData));
- //Task.Run(() =>
- // S7节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName,
- // stPLC_MesData.Left.iotData));
- }
- }
- }
- }
- s7PLCSignal_Old["a7OEEType_right"] = s7PLCData["a7OEEType_right"];
- #endregion 右工位 节拍
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info,
- "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- FunsEip[plcNo].Connect(); // 重连
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S7] 锁螺丝设备 - 进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- /// <param name="stPLC_MesData"></param>
- /// <param name="tagMesCommName"></param>
- private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
- string tagBarsetName, string direction, out bool ProgressState, AtlasScrew atlasScrew)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string atlasSn = string.Empty;
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
- string StationId = string.Empty; // 工位ID(可配置)
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- if (direction == "Left")
- {
- StationId = GlobalContext.S7_StationId_1;
- }
- if (direction == "Right")
- {
- StationId = GlobalContext.S7_StationId_2;
- }
- string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
- //载具码验证产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
- }
- sn = strProductBarcode;
- atlasSn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
- string slot = "";
- if (direction == "Left")
- {
- isCollectingFlagLeft = false; //采集螺丝数据结束
- slot = "01-SLOT-01";
- }
- if (direction == "Right")
- {
- isCollectingFlagRight = false; //采集螺丝数据结束
- slot = "01-SLOT-02";
- }
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
- item, MachineId, StationId, pass, slot);
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- if (mesResultFrmWeb == 1)
- {
- mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
- AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
- }
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage(LogType.Error,
- $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
- str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
- AddMessage(LogType.Info,
- stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- //开始采集螺丝数据
- if (direction == "Left")
- {
- isCollectingFlagLeft = true;
- CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
- }
- if (direction == "Right")
- {
- isCollectingFlagRight = true;
- CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
- }
- }
- /// <summary>
- /// [S7] 锁螺丝设备 - 出站
- /// </summary>
- private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
- string stationCode, string stationName, string direction, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- test_item_num = 0; //iot 过站明细序号
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
- string StationId = string.Empty; // 工位ID(可配置)
- if (direction == "Left")
- {
- StationId = GlobalContext.S7_StationId_1;
- }
- if (direction == "Right")
- {
- StationId = GlobalContext.S7_StationId_2;
- }
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- //a1Result = 1;
- bool pass = a1Result == 1;
- //根据载具码获取产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- //if (direction == "Right")
- //{
- string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem, workorder_code,
- batch_num, mtltmrk, plcDate_YMD, supplierCode
- , sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
- //}
- //if (direction == "Left")
- //{
- // isCollectingFlagLeft = false;//采集螺丝数据结束
- //}
- //if (direction == "Right")
- //{
- // isCollectingFlagRight = false;//采集螺丝数据结束
- //}
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- if (mesResultFrmWeb == 1)
- {
- mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
- AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
- }
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
- //保存PLC返回MES数据到本地
- ResponseMessage message = new ResponseMessage();
- if (direction == "Left")
- {
- string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
- string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
- string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
- message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
- strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
- }
- }
- if (direction == "Right")
- {
- string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
- string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
- string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
- message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
- strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
- }
- }
- //保存螺丝数据到txt
- (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes,
- stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
- if (result.Item1 != 0)
- {
- AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
- }
- AddMessage(LogType.Info, stationNameStr + "_" + direction + "_保存加工数据到本地成功");
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage(LogType.Error,
- $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- private void S7节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = ((int)s1PLCData["a7OEEType"]).ToString(); // 节拍类型(plc写入)
- string a7OEEPartNo = (string)s1PLCData["a7OEEPartNo"]; // 物料码
- a7OEEPartNo = a7OEEPartNo.Replace("\0", "");
- string a7OEEVehicleCode = (string)s1PLCData["a7OEEVehicleCode"]; // 载具SN
- a7OEEVehicleCode = a7OEEVehicleCode.Replace("\0", "");
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
- "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- //作业开始后要有物料和载具信息
- if (string.IsNullOrEmpty(a7OEEPartNo) && string.IsNullOrEmpty(a7OEEVehicleCode) &&
- Convert.ToInt32(oEEType) > 2)
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a7OEEPartNo))
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a7OEEVehicleCode))
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- short _result = 0;
- // 上传OEE
- (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a7OEEPartNo, a7OEEVehicleCode);
- _result = result.Item1;
- resultStr = result.Item2;
- if (_result == 1)
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 1; //OK
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- OnMessage(LogType.Info,
- $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
- stopwatch2.Stop();
- }
- else
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- #endregion
- #region S8
- private Dictionary<string, object> s8PLCData = new Dictionary<string, object>();
- private Dictionary<string, object> s8PLCSignal_Old = new Dictionary<string, object>();
- /// <summary>
- /// [S8] 3D螺丝高度检测设备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S8(int plcNo)
- {
- string stationCode = "[OP90]";
- string stationName = "NG下料";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP80_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagiotComnName = "iotData";
- string tagBarsetName = "BarcodeSet";
- string CarrierBarcode = "";
- // 触发信号字典
- //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s8PLCSignal_Old.Add("a8OEEType", 0); // 节拍类型(plc写入)
- // PLC数据字典 赋值
- s8PLCData.Add("a8OEEType", 0); // 节拍类型(plc写入)
- OP80_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs1)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = FunsEip[plcNo]
- .Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //去除扫码产生的特殊字符
- stPLC_MesData.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
- stPLC_MesData.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
- stPLC_MesData.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
- stPLC_MesData.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- //richTextBox1.AppendText("\n" + "读取成功");
- int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
- xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
- ? XiaomiDeviceState.Unknown
- : (XiaomiDeviceState)xmDeviceStateInt;
- CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
- s8PLCData["a8OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
- //报警信息
- _FaultDatas = stPLC_MesData.iotData.fault_codes;
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 进站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
- ProgressState = true;
- Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData,
- tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
- out ProgressState));
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- #region 出站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData,
- tagBaseName + "." + tagMesCommName, stationCode, stationName,
- out ProgressState));
- stPLC_MesData.mesCommFrmPLC.cmd = 0;
- uuid = "";
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 出站
- #region 节拍接口
- try
- {
- int a8OEEType = Convert.ToInt32(s9PLCData["a8OEEType"]);
- int a8OEETypeGOld = Convert.ToInt32(s9PLCSignal_Old["a8OEEType"]);
- //若设备紧急复原后节拍重置
- if (a8OEEType == 1)
- {
- a8OEETypeGOld = 0;
- }
- if (stPLC_MesData.iotData.BeatAction > 0)
- {
- if (a8OEEType != a8OEETypeGOld)
- {
- //如果上位机告诉PLC NG,PLC节拍会直接从1跳到4
- if (a8OEETypeGOld <= 2 && a8OEEType == 4)
- {
- Task.Run(() =>
- 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
- CarrierBarcode,
- stPLC_MesData.iotData));
- }
- else
- {
- //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
- if ((a8OEETypeGOld == 1 && a8OEEType != 2) ||
- (a8OEETypeGOld == 3 && a8OEEType != 4) ||
- (a8OEETypeGOld == 5 && a8OEEType != 6))
- {
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = stPLC_MesData.iotData.machineState;
- iotData.work_type = stPLC_MesData.iotData.work_type;
- iotData.testStatus = stPLC_MesData.iotData.testStatus;
- iotData.BeatAction = stPLC_MesData.iotData.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = stPLC_MesData.iotData.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
- 1, iotData);
- AddMessage(LogType.Info,
- stationNameStr +
- $"_节拍接口-- 设备本次上传节拍[{a8OEEType}],未上传节拍[{a8OEETypeGOld}]的结束信号,请检查;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds +
- "ms");
- return;
- }
- else
- {
- Task.Run(() =>
- 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
- CarrierBarcode,
- stPLC_MesData.iotData));
- //Task.Run(() =>
- // S8节拍接口(plcNo, stationNameStr, tagBaseName,
- // stPLC_MesData.iotData));
- }
- }
- }
- }
- s8PLCSignal_Old["a8OEEType"] = s8PLCData["a8OEEType"];
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info,
- "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- FunsEip[plcNo].Connect(); // 重连
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S8] 3D螺丝高度检测设备 - 进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- /// <param name="stPLC_MesData"></param>
- /// <param name="tagMesCommName"></param>
- private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
- string tagBarsetName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_进站开始");
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
- string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
- //载具码验证产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
- sn,
- item, MachineId, StationId, pass, "01-SLOT-01");
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- if (mesResultFrmWeb == 1)
- {
- mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
- AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
- }
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage(LogType.Error,
- $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(
- str.LastIndexOf("\\") + 1,
- str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- /// <summary>
- /// [S8] 3D螺丝高度检测设备 - 出站接口
- /// </summary>
- private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
- string stationCode, string stationName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- test_item_num = 0; //iot 过站明细序号
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_出站开始");
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
- string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- //根据载具码获取产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- #region 上传图片
- if (GlobalContext.MQTTIsSendUpFile)
- {
- string[] urlarry = GlobalContext.UpFilePath.Split(",");
- fileUploadData.fileData.Clear();
- foreach (var item in urlarry)
- {
- if (!string.IsNullOrEmpty(item))
- {
- //上传图片
- var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName,
- a1Result, item, uuid).Result;
- OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
- }
- }
- }
- #endregion
- string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
- MachineId, StationId, "", paramJson);
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- if (mesResultFrmWeb == 1)
- {
- mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
- AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
- }
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站结束");
- //保存PLC返回MES数据到本地
- ResponseMessage message = new ResponseMessage();
- string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
- string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
- message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
- }
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage(LogType.Error,
- $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- private void S8节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = ((int)s1PLCData["a8OEEType"]).ToString(); // 节拍类型(plc写入)
- string a80EEPartNo = (string)s1PLCData["a80EEPartNo"]; // 物料码
- a80EEPartNo = a80EEPartNo.Replace("\0", "");
- string a80EEVehicleCode = (string)s1PLCData["a80EEVehicleCode"]; // 载具SN
- a80EEVehicleCode = a80EEVehicleCode.Replace("\0", "");
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" +
- stopwatch1.ElapsedMilliseconds +
- "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- //作业开始后要有物料和载具信息
- if (string.IsNullOrEmpty(a80EEPartNo) && string.IsNullOrEmpty(a80EEVehicleCode) &&
- Convert.ToInt32(oEEType) > 2)
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a80EEPartNo))
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a80EEVehicleCode))
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- short _result = 0;
- // 上传OEE
- (short, string) result =
- SaveOEEData(plcNo, stationNameStr, deviceOEE, a80EEPartNo, a80EEVehicleCode);
- _result = result.Item1;
- resultStr = result.Item2;
- if (_result == 1)
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 1; //OK
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- OnMessage(LogType.Info,
- $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
- stopwatch2.Stop();
- }
- else
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- #endregion
- #region S9
- private Dictionary<string, object> s9PLCData = new Dictionary<string, object>();
- private Dictionary<string, object> s9PLCSignal_Old = new Dictionary<string, object>();
- /// <summary>
- /// [S9] 下料设备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void ReadStation_S9(int plcNo)
- {
- string stationCode = "[OP100]";
- string stationName = "半成品下料";
- string stationNameStr = stationCode + stationName;
- string tagBaseName = "g_OP90_MES"; //标签变量名称
- string tagMesCommName = "mesCommToPC"; //标签变量名称
- string tagAgvCommName = "agvCommFrmPC";
- string tagiotComnName = "iotData";
- string tagBarsetName = "BarcodeSet";
- string CarrierBarcode = "";
- // 触发信号字典
- //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- s9PLCSignal_Old.Add("a9OEEType", 0); // 节拍类型(plc写入)
- // PLC数据字典 赋值
- s9PLCData.Add("a9OEEType", 0); // 节拍类型(plc写入)
- OP90_MesData_t stPLC_MesData; //PLC的MES数据
- (int, string) result;
- while (true)
- {
- try
- {
- if (!GlobalContext._IsCon_Funs1)
- {
- UpdatePLCMonitor(1, plcNo, 0);
- continue;
- }
- if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- stopwatch1.Start();
- stopwatch2.Start();
- #region 一次性读取所有数据
- // 一次性读取所有数据
- result = FunsEip[plcNo]
- .Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
- if (result.Item1 != 0)
- {
- //richTextBox1.AppendText("\n" + strRet);
- }
- else
- {
- //去除扫码产生的特殊字符
- stPLC_MesData.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
- stPLC_MesData.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
- stPLC_MesData.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
- stPLC_MesData.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
- //richTextBox1.AppendText("\n" + "读取成功");
- int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
- xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
- ? XiaomiDeviceState.Unknown
- : (XiaomiDeviceState)xmDeviceStateInt;
- CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
- s9PLCData["a9OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
- //报警信息
- _FaultDatas = stPLC_MesData.iotData.fault_codes;
- }
- #endregion 一次性读取所有数据
- stopwatch2.Stop();
- #region 进站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
- ProgressState = true;
- Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData,
- tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
- out ProgressState));
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 进站
- #region 出站
- try
- {
- if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
- {
- lock (lockObj)
- {
- if (!ProgressState)
- {
- ProgressState = true;
- Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData,
- tagBaseName + "." + tagMesCommName, stationCode, stationName,
- out ProgressState));
- stPLC_MesData.mesCommFrmPLC.cmd = 0;
- uuid = "";
- }
- }
- }
- }
- catch (Exception ex)
- {
- ProgressState = false;
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion 出站
- #region 节拍接口
- try
- {
- if (stPLC_MesData.iotData.BeatAction > 0)
- {
- int a9OEEType = Convert.ToInt32(s9PLCData["a9OEEType"]);
- int a9OEETypeGOld = Convert.ToInt32(s9PLCSignal_Old["a9OEEType"]);
- //若设备紧急复原后节拍重置
- if (a9OEEType == 1)
- {
- a9OEETypeGOld = 0;
- }
- if (a9OEEType != a9OEETypeGOld)
- {
- //如果上位机告诉PLC NG,PLC节拍会直接从1跳到4
- if (a9OEETypeGOld <= 2 && a9OEEType == 4)
- {
- Task.Run(() =>
- 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
- CarrierBarcode,
- stPLC_MesData.iotData));
- }
- else
- {
- //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
- if ((a9OEETypeGOld == 1 && a9OEEType != 2) || (a9OEETypeGOld == 3 && a9OEEType != 4) ||
- (a9OEETypeGOld == 5 && a9OEEType != 6))
- {
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = stPLC_MesData.iotData.machineState;
- iotData.work_type = stPLC_MesData.iotData.work_type;
- iotData.testStatus = stPLC_MesData.iotData.testStatus;
- iotData.BeatAction = stPLC_MesData.iotData.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = stPLC_MesData.iotData.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
- 1, iotData);
- AddMessage(LogType.Info,
- stationNameStr +
- $"_节拍接口-- 设备本次上传节拍[{a9OEEType}],未上传节拍[{a9OEETypeGOld}]的结束信号,请检查;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
- "ms");
- return;
- }
- else
- {
- Task.Run(() =>
- 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
- CarrierBarcode,
- stPLC_MesData.iotData));
- //Task.Run(() =>
- // S9节拍接口(plcNo, stationNameStr, tagBaseName,
- // stPLC_MesData.iotData));
- }
- }
- }
- }
- s9PLCSignal_Old["a9OEEType"] = s9PLCData["a9OEEType"];
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- #endregion
- UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- stopwatch1.Stop();
- //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- }
- else
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Info,
- "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- FunsEip[plcNo].Connect(); // 重连
- }
- }
- catch (Exception ex)
- {
- UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- }
- Thread.Sleep(IntervalReadPLC);
- }
- }
- /// <summary>
- /// [S9] 下料设备 - 进站
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- /// <param name="stPLC_MesData"></param>
- /// <param name="tagMesCommName"></param>
- private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
- string tagBarsetName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_进站开始");
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
- string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
- string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
- //载具码验证产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
- item, MachineId, StationId, pass, "01-SLOT-01");
- stopwatch2.Stop();
- //指令执行结果 1:OK 110:失败
- byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
- if (mesResultFrmWeb == 1)
- {
- mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
- AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
- }
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage(LogType.Error,
- $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
- str.Length - str.LastIndexOf("\\") - 1));
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info, stationNameStr + "_进站结束");
- AddMessage(LogType.Info,
- stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- /// <summary>
- /// [S9] 下料设备 - 出站接口
- /// </summary>
- private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
- string stationCode, string stationName, out bool ProgressState)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- test_item_num = 0; //iot 过站明细序号
- try
- {
- stopwatch1.Start();
- AddMessage(LogType.Info, stationNameStr + "_出站开始");
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string processItem = stationName; // 测试项目
- string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string supplierCode = ""; // 供应商代码
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
- string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
- string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
- string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
- int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
- bool pass = a1Result == 1;
- //根据载具码获取产品码
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
- if (string.IsNullOrEmpty(strProductBarcode))
- {
- AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
- }
- sn = strProductBarcode;
- AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = CarrierBarcode,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
- int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
- , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
- MachineId, StationId, "", paramJson);
- byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
- if (mesResultFrmWeb == 1)
- {
- mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
- AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
- }
- stopwatch2.Start();
- //进站结果写入PLC
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = mesResultFrmWeb;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- AddMessage(LogType.Info, stationNameStr + "_出站结束");
- //保存PLC返回MES数据到本地
- ResponseMessage message = new ResponseMessage();
- message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
- stPLC_MesData.mesData.nRemainCount);
- if (message.result == false)
- {
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
- }
- AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
- if (result1 == 1)
- {
- //载具码解除绑定
- message = SQLHelper.DelCarrierBind(CarrierBarcode);
- if (message.result == false)
- {
- AddMessage(LogType.Error, message.text);
- }
- }
- }
- catch (Exception ex)
- {
- stopwatch2.Start();
- CommandFromPLC resultToPlC = new CommandFromPLC();
- resultToPlC.cmd = 0;
- resultToPlC.cmdParam = 0; //指令参数
- resultToPlC.cmdResult = 110;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage(LogType.Error,
- $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- ProgressState = false;
- }
- private void S9节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = ((int)s1PLCData["a9OEEType"]).ToString(); // 节拍类型(plc写入)
- string a90EEPartNo = (string)s1PLCData["a90EEPartNo"]; // 物料码
- a90EEPartNo = a90EEPartNo.Replace("\0", "");
- string a90EEVehicleCode = (string)s1PLCData["a90EEVehicleCode"]; // 载具SN
- a90EEVehicleCode = a90EEVehicleCode.Replace("\0", "");
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
- "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- //作业开始后要有物料和载具信息
- if (string.IsNullOrEmpty(a90EEPartNo) && string.IsNullOrEmpty(a90EEVehicleCode) &&
- Convert.ToInt32(oEEType) > 2)
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a90EEPartNo))
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a90EEVehicleCode))
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- short _result = 0;
- // 上传OEE
- (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a90EEPartNo, a90EEVehicleCode);
- _result = result.Item1;
- resultStr = result.Item2;
- if (_result == 1)
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 1; //OK
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- OnMessage(LogType.Info,
- $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
- stopwatch2.Stop();
- }
- else
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- #endregion
- #endregion Xiaomi
- #region PLC1 张超凡
- #region [S1] Tray盘上料装备(板测)
- /// <summary>
- /// S1工位的数据- 触发信号上次的值
- /// </summary>
- private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
- /// <summary>
- /// S1工位的数据(含触发信号)
- /// </summary>
- private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
- /// <summary>
- /// S1工位的数据- 回写点位
- /// </summary>
- private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
- ///// <summary>
- ///// 触发信号
- ///// </summary>
- //private ManualResetEvent[] MreTasks;
- /// <summary>
- /// [S1] Tray盘上料装备(板测)
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- //private void ReadStation_S1(int plcNo)
- //{
- // // [S1] Tray盘上料装备
- // // [S2] FCT
- // // [S3] 值板机
- // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
- // // [S5] Tray盘下料装备
- // string stationCode = "[S1]";
- // string stationName = "Tray盘上料装备";
- // string stationNameStr = stationCode + stationName;
- // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
- // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
- // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
- // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
- // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
- // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
- // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
- // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
- // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
- // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
- // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
- // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
- // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
- // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
- // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
- // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
- // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
- // s1PLCData.Add("a1Result", 0); // 产品结果
- // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
- // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
- // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
- // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
- // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
- // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
- // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
- // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
- // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
- // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
- // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
- // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
- // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
- // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
- // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
- // while (IsRun)
- // {
- // try
- // {
- // if (!GlobalContext._IsCon_Funs1)
- // {
- // UpdatePLCMonitor(1, plcNo, 0);
- // continue;
- // }
- // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- // {
- // Stopwatch stopwatch1 = new Stopwatch();
- // Stopwatch stopwatch2 = new Stopwatch();
- // stopwatch1.Start();
- // stopwatch2.Start();
- // #region 一次性读取所有数据
- // // 一次性读取所有数据
- // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
- // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
- // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
- // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
- // int[] datas = data1.Concat(data2).ToArray();
- // datas = datas.Concat(data3).ToArray();
- // datas = datas.Concat(data4).ToArray();
- // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
- // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
- // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
- // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
- // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
- // s1PLCData["a1MES_FLAG_Check"] = datas[77];
- // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
- // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
- // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
- // s1PLCData["a1MES_FLAG"] = datas[109];
- // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
- // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
- // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
- // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
- // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
- // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
- // s1PLCData["a1Result"] = datas[170];
- // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
- // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
- // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
- // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
- // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
- // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
- // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
- // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
- // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
- // s1PLCData["a1OEEMES_FLAG"] = datas[254];
- // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
- // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
- // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
- // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
- // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
- // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
- // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
- // s1PLCData["a1AGVUpStart"] = datas[308];
- // s1PLCData["a1AGVUpEnd"] = datas[309];
- // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
- // s1PLCData["a1AGVDownStart"] = datas[321];
- // s1PLCData["a1AGVDownEnd"] = datas[322];
- // #endregion 一次性读取所有数据
- // stopwatch2.Stop();
- // #region 回写操作,写后清空flag
- // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
- // #endregion 回写操作,写后清空flag
- // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
- // try
- // {
- // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
- // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
- // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
- // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
- // {
- // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
- // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
- // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
- // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
- // }
- // }
- // catch (Exception ex)
- // {
- // // 6代表上位机报警
- // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
- // #region 上料进站校验
- // try
- // {
- // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
- // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
- // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
- // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
- // {
- // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
- // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
- // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
- // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 上料进站校验
- // #region Tray盘上料装备-出站接口
- // try
- // {
- // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
- // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
- // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
- // if (a1PLC_FLAG != a1PLC_FLAGOld)
- // {
- // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
- // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
- // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
- // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion Tray盘上料装备-出站接口
- // #region Tray盘上料装备-将SN发给ICT标机
- // try
- // {
- // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
- // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
- // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
- // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
- // {
- // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
- // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
- // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
- // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion Tray盘上料装备-将SN发给ICT标机
- // #region Tray盘上料装备-点检数据
- // //try
- // //{
- // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
- // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
- // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
- // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
- // // if (pLC_Flag && !mES_Flag) // 1 0
- // // {
- // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
- // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
- // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
- // // }
- // // else if (!pLC_Flag && mES_Flag) // 0 1
- // // {
- // // // 清空写给PLC的数据
- // // // MES_Flag重置为0
- // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
- // // }
- // //}
- // //catch (Exception ex)
- // //{
- // // // MES_Flag 为2上位机报错
- // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
- // // string str = ex.StackTrace;
- // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // //}
- // #endregion Tray盘上料装备-点检数据
- // #region 节拍接口
- // try
- // {
- // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
- // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
- // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
- // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
- // {
- // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
- // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
- // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
- // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 节拍接口
- // #region AGV上料
- // // AGV上料叫AGV信号
- // try
- // {
- // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
- // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
- // if (a1AGVUpCall != a1AGVUpCallOld)
- // {
- // if (a1AGVUpCall == 1) // 0->1
- // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
- // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // // AGV上料完成信号
- // try
- // {
- // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
- // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
- // if (a1AGVUpEnd != a1AGVUpEndOld)
- // {
- // if (a1AGVUpEnd == 1) // 0->1
- // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
- // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion AGV上料
- // #region AGV下料
- // // AGV下料叫agv信号
- // try
- // {
- // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
- // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
- // if (a1AGVDownCall != a1AGVDownCallOld)
- // {
- // if (a1AGVDownCall == 1) // 0->1
- // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
- // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // // AGV下料完成信号
- // try
- // {
- // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
- // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
- // if (a1AGVDownEnd != a1AGVDownEndOld)
- // {
- // if (a1AGVDownEnd == 1) // 0->1
- // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
- // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion AGV下料
- // #region 心跳
- // try
- // {
- // short states = 0;
- // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
- // }
- // catch (Exception ex)
- // {
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 心跳
- // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- // stopwatch1.Stop();
- // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
- // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- // }
- // else
- // {
- // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- // Funs[plcNo].Connect(); // 重连
- // }
- // }
- // catch (Exception ex)
- // {
- // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- // Funs[plcNo].ReConnect();
- // }
- // Thread.Sleep(IntervalReadPLC);
- // }
- //}
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S1载具进站查询状态(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
- sn = sn.Replace("\0", "");
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
- writeToPLC_Flag1.Adress = 2003;
- writeToPLC_Flag1.Value = (short)6;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
- "ms");
- return;
- }
- #endregion 查询载具上的产品信息
- string[] cavitySNs = cavityData.Split('.');
- string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
- string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
- short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
- short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
- if (cavitySNs != null && cavitySNs.Length >= 2)
- {
- a1CavitySN1_VehicleStates = cavitySNs[0];
- a1CavitySN2_VehicleStates = cavitySNs[1];
- a1CavityResult1_VehicleStates = 2;
- a1CavityResult2_VehicleStates = 2;
- }
- if (a1CavitySN1_VehicleStates == "假产品")
- a1CavityResult1_VehicleStates = 3;
- if (a1CavitySN2_VehicleStates == "假产品")
- a1CavityResult2_VehicleStates = 3;
- short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
- // 回写
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
- //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
- //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
- //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
- writeToPLC_Flag.Adress = 2003;
- writeToPLC_Flag.Value = mES_Flag;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
- {
- Name = "a1CavitySN1_VehicleStates",
- Adress = 2024,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = a1CavitySN1_VehicleStates
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
- {
- Name = "a1CavitySN2_VehicleStates",
- Adress = 2044,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = a1CavitySN2_VehicleStates
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
- {
- Name = "a1CavityResult1_VehicleStates",
- Adress = 2064,
- ValueType = PLCValueType.Short,
- Value = a1CavityResult1_VehicleStates
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
- {
- Name = "a1CavityResult2_VehicleStates",
- Adress = 2065,
- ValueType = PLCValueType.Short,
- Value = a1CavityResult2_VehicleStates
- });
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
- writeToPLC_Flag.Adress = 2003;
- writeToPLC_Flag.Value = (short)6;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- 上料进站校验
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S1上料进站校验(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
- sn = sn.Replace("\0", "");
- // 保存进站数据+调用进站MES接口
- List<TestItem> item = new List<TestItem>();
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
- item, out string errorMsg);
- stopwatch2.Stop();
- short a1MES_FLAG_Check = (short)result;
- //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1MES_FLAG_Check";
- writeToPLC_Flag.Adress = 2077;
- writeToPLC_Flag.Value = a1MES_FLAG_Check;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1MES_FLAG_Check";
- writeToPLC_Flag.Adress = 2077;
- writeToPLC_Flag.Value = (short)6;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- 出站接口
- /// </summary>
- /// <param name="plcNo"></param>
- /// <param name="stationCode"></param>
- /// <param name="stationName"></param>
- private void S1出站接口(int plcNo, string stationCode, string stationName)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string stationNameStr = stationCode + stationName;
- string processItem = stationName; // 测试项目
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- //string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
- sn = sn.Replace("\0", "");
- string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
- partNo1 = partNo1.Replace("\0", "");
- string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
- partNo2 = partNo2.Replace("\0", "");
- int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
- bool pass = a1Result == 1;
- stopwatch2.Start();
- // 产品1
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = a1Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
- , workorder_code, mtltmrk, partNo1, pass, sn, "1");
- // 产品2
- items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "2",
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = a1Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- int result2 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
- , workorder_code, mtltmrk, partNo2, pass, sn, "2");
- short result = 0;
- List<int> results = new List<int>() { result1, result2 };
- if (result1 == 1 && result2 == 1)
- result = 1;
- else if (results.Contains(3))
- result = 3;
- else if (results.Contains(2))
- result = 2;
- else if (results.Contains(4))
- result = 4;
- else
- result = 4;
- stopwatch2.Stop();
- #region 存储绑定数据到 边线MES系统中
- if (result == 1)
- {
- string data = string.Concat(partNo1, ".", partNo2);
- int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
- if (resultMesR != 0)
- {
- result = 4;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
- }
- }
- #endregion 存储绑定数据到 边线MES系统中
- // MES_Flag 为MES报错
- // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1MES_FLAG";
- writeToPLC_Flag.Adress = 2109;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
- OnMessage(LogType.Debug,
- $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Restart();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1MES_FLAG";
- writeToPLC_Flag.Adress = 2109;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- //// 上传点检数据_ [S1] Tray盘上料装备(板测)
- //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
- //{
- // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- // string stationNameStr = stationCode + stationName;
- // string processItem = stationName; // 测试项目
- // try
- // {
- // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- // string accno = "1"; // 工序编号
- // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
- // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
- // List<OneCheckItem> items = new List<OneCheckItem>()
- // {
- // new OneCheckItem()
- // {
- // Onecheck_name="胶圈装配行程设定上限",
- // Onecheck_content="上限值",
- // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
- // },
- // };
- // OneCheckData oneCheckData = new OneCheckData()
- // {
- // Line_code = GlobalContext.LineCode,
- // Line_name = GlobalContext.LineName,
- // Equipment_code = equipmentCode,
- // Equipment_name = equipmentCode,
- // Workorder_code = workorder_code,
- // Procedure_code = accno,
- // Procedure_name = processItem,
- // Oneckeck_values = items,
- // Onecheck_empcode = "",
- // Onecheck_empname = "",
- // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
- // };
- // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
- // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
- // short result = result1 == 1 ? (short)1 : (short)2;
- // // MES_Flag 为4MES报错
- // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
- // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
- // }
- // catch (Exception ex)
- // {
- // // MES_Flag 为2上位机报错
- // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- //}
- // ReadStation_S1_2 节拍接口+AGV
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
- a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
- string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
- a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
- string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
- a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
- // ZS 将SN发给ICT标机(串口)
- short a1MES_FLAG_ICT = 1;
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
- writeToPLC_Flag.Adress = 2182;
- writeToPLC_Flag.Value = a1MES_FLAG_ICT;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
- writeToPLC_Flag.Adress = 2182;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- 节拍接口
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S1节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
- string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
- a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
- string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
- a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
- "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- //作业开始后要有物料和载具信息
- if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode) &&
- Convert.ToInt32(oEEType) > 2)
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a1OEEPartNo))
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a1OEEVehicleCode))
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- short _result = 0;
- // 上传OEE
- (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
- _result = result.Item1;
- resultStr = result.Item2;
- if (_result == 1)
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 1; //OK
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- OnMessage(LogType.Info,
- $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
- stopwatch2.Stop();
- }
- else
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S1AGV上料叫agv(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 呼叫AGV
- short a1AGVUpCall = 2;
- stopwatch2.Start();
- // a1AGVUpCall
- //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVUpCall";
- writeToPLC_Flag.Adress = 2307;
- writeToPLC_Flag.Value = a1AGVUpCall;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // a1AGVUpCall
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVUpCall";
- writeToPLC_Flag.Adress = 2307;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- AGV上料完成
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S1AGV上料完成(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS AGV上料完成,让小车离开
- short a1AGVUpEnd = 2;
- stopwatch2.Start();
- // a1AGVUpEnd
- //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVUpEnd";
- writeToPLC_Flag.Adress = 2309;
- writeToPLC_Flag.Value = a1AGVUpEnd;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // a1AGVUpEnd
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVUpEnd";
- writeToPLC_Flag.Adress = 2309;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S1AGV下料叫agv(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 呼叫AGV
- short a1AGVDownCall = 2;
- stopwatch2.Start();
- // a1AGVDownCall
- //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVDownCall";
- writeToPLC_Flag.Adress = 2320;
- writeToPLC_Flag.Value = a1AGVDownCall;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // a1AGVDownCall
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVDownCall";
- writeToPLC_Flag.Adress = 2320;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S1] Tray盘上料装备(板测)- AGV下料完成
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S1AGV下料完成(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS AGV上料完成,让小车离开
- short a1AGVDownEnd = 2;
- stopwatch2.Start();
- // a1AGVDownEnd
- //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVDownEnd";
- writeToPLC_Flag.Adress = 2322;
- writeToPLC_Flag.Value = a1AGVDownEnd;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // a1AGVDownEnd
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "a1AGVDownEnd";
- writeToPLC_Flag.Adress = 2322;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- #endregion [S1] Tray盘上料装备(板测)
- #endregion PLC1 张超凡
- #region PLC2 李晓奇
- #region [S2] FCT(板测)
- /// <summary>
- /// S2工位的数据- 触发信号上次的值
- /// </summary>
- private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
- /// <summary>
- /// S2工位的数据(含触发信号)
- /// </summary>
- private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
- /// <summary>
- /// S2工位的数据- 回写点位
- /// </summary>
- private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
- /// <summary>
- /// [S2] FCT(板测)
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- //private void ReadStation_S2(int plcNo)
- //{
- // // [S1] Tray盘上料装备
- // // [S2] FCT
- // // [S3] 值板机
- // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
- // // [S5] Tray盘下料装备
- // /// 上位机心跳
- // /// 获取设备报警数据与状态信息
- // string stationCode = "[S2]";
- // string stationName = "FCT";
- // string stationNameStr = stationCode + stationName;
- // #region 创建字典
- // // 触发信号字典 赋值
- // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
- // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
- // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
- // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // // PLC数据字典 赋值
- // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
- // s2PLCData.Add("b1MES_FLAG_Check", 0);
- // s2PLCData.Add("b1ProductSN_Check", 0);
- // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
- // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
- // s2PLCData.Add("b1ProductSN_Unbind", "");
- // s2PLCData.Add("b1ProductSN_Bind", "");
- // s2PLCData.Add("b1Part1SN_Bind", "");
- // s2PLCData.Add("b1Part2SN_Bind", "");
- // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
- // s2PLCData.Add("b1MES_FLAG", 0);
- // s2PLCData.Add("b1ProductSN", 0);
- // s2PLCData.Add("b1Part1Result", 0);
- // s2PLCData.Add("b1Part2Result", 0);
- // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
- // s2PLCData.Add("b1OEEMES_FLAG", 0);
- // s2PLCData.Add("b1OEEProductSN", "");
- // s2PLCData.Add("b1OEEType", 0);
- // #endregion 创建字典
- // while (IsRun)
- // {
- // try
- // {
- // if (!GlobalContext._IsCon_Funs2)
- // {
- // UpdatePLCMonitor(1, plcNo, 0);
- // continue;
- // }
- // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- // {
- // Stopwatch stopwatch1 = new Stopwatch();
- // Stopwatch stopwatch2 = new Stopwatch();
- // stopwatch1.Start();
- // stopwatch2.Start();
- // #region 一次性读取所有数据
- // // 一次性读取所有数据
- // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
- // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
- // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
- // int[] datas = data1.Concat(data2).ToArray();
- // datas = datas.Concat(data3).ToArray();
- // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
- // s2PLCData["b1MES_FLAG_Check"] = datas[3];
- // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
- // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
- // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
- // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
- // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
- // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
- // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
- // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
- // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
- // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
- // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
- // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
- // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
- // s2PLCData["b1MES_FLAG"] = datas[169];
- // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
- // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
- // s2PLCData["b1Part1Result"] = datas[190];
- // s2PLCData["b1Part2Result"] = datas[191];
- // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
- // s2PLCData["b1OEEMES_FLAG"] = datas[203];
- // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
- // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
- // s2PLCData["b1OEEType"] = datas[224];
- // #endregion 一次性读取所有数据
- // stopwatch2.Stop();
- // #region 回写操作,写后清空flag
- // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
- // #endregion 回写操作,写后清空flag
- // #region 进站校验
- // try
- // {
- // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
- // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
- // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
- // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
- // {
- // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
- // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
- // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
- // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 进站校验
- // #region 二穴载具解绑/绑定(产品换载具)
- // try
- // {
- // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
- // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
- // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
- // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
- // {
- // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
- // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
- // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
- // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 二穴载具解绑/绑定(产品换载具)
- // #region FCT-出站接口
- // try
- // {
- // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
- // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
- // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
- // if (b1PLC_FLAG != b1PLC_FLAGOld)
- // {
- // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
- // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
- // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
- // }
- // }
- // catch (Exception ex)
- // {
- // // MES_Flag 为6上位机报错
- // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion FCT-出站接口
- // #region 节拍接口
- // try
- // {
- // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
- // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
- // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
- // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
- // {
- // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
- // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
- // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
- // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 节拍接口
- // #region 心跳
- // try
- // {
- // short states = 0;
- // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
- // }
- // catch (Exception ex)
- // {
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 心跳
- // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- // stopwatch1.Stop();
- // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
- // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- // }
- // else
- // {
- // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- // Funs[plcNo].Connect();
- // }
- // }
- // catch (Exception ex)
- // {
- // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- // Funs[plcNo].ReConnect();
- // }
- // Thread.Sleep(IntervalReadPLC);
- // }
- //}
- /// <summary>
- /// [S2] FCT(板测)- 进站校验
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S2进站校验(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
- sn = sn.Replace("\0", "");
- #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
- // 查询物料码By载具码 并判断是不是假产品
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
- writeToPLC_Flag1.Adress = 2003;
- writeToPLC_Flag1.Value = (short)6;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
- string[] cavitySNs = cavityData.Split('.');
- string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
- string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
- short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
- short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
- if (cavitySNs != null && cavitySNs.Length >= 2)
- {
- b1Part1SN_Check = cavitySNs[0];
- b1Part2SN_Check = cavitySNs[1];
- b1Part1Result_Check = 2;
- b1Part2Result_Check = 2;
- }
- if (b1Part1SN_Check == "假产品")
- b1Part1Result_Check = 3;
- if (b1Part2SN_Check == "假产品")
- b1Part2Result_Check = 3;
- // 调用MES进站
- stopwatch2.Start();
- // 调用MES进站 - 产品1
- List<TestItem> item;
- int result1 = b1Part1Result_Check;
- if (result1 != 3)
- {
- item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = sn,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- });
- result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
- b1Part1SN_Check, item, out string errorMsg);
- }
- // 调用MES进站 - 产品2
- int result2 = b1Part2Result_Check;
- if (result2 != 3)
- {
- item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = sn,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "2",
- });
- result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
- b1Part2SN_Check, item, out string errorMsg);
- }
- stopwatch2.Stop();
- b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
- b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
- int result = result1;
- if (result == 1)
- result = result2;
- short b1MES_FLAG_Check = (short)result;
- //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
- //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
- //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
- //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
- WriteToPLC_Flag
- writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
- writeToPLC_Flag.Name = "b1MES_FLAG_Check";
- writeToPLC_Flag.Adress = 2003;
- writeToPLC_Flag.Value = b1MES_FLAG_Check;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "b1Part1SN_Check",
- Adress = 2024,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = b1Part1SN_Check
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "b1Part2SN_Check",
- Adress = 2044,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = b1Part2SN_Check
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "b1Part1Result_Check",
- Adress = 2064,
- ValueType = PLCValueType.Short,
- Value = b1Part1Result_Check
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "b1Part2Result_Check",
- Adress = 2065,
- ValueType = PLCValueType.Short,
- Value = b1Part2Result_Check
- });
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "b1MES_FLAG_Check";
- writeToPLC_Flag.Adress = 2003;
- writeToPLC_Flag.Value = (short)6;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S2] FCT(板测)- 二穴载具解绑绑定
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // 产品换载具
- string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
- b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
- string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
- b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
- string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
- b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
- string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
- b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
- stopwatch2.Start();
- #region 查询载具上的产品信息
- //string cavityData = string.Empty;
- //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
- //if (string.IsNullOrEmpty(cavityData))
- // cavityData = "";
- //if (snResult != 0)
- //{
- // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
- // writeToPLC_Flag.Adress = 2077;
- // writeToPLC_Flag.Value = (short)6;
- // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
- // stopwatch1.Stop();
- // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- // return;
- //}
- #endregion 查询载具上的产品信息
- #region 解绑(边线MES系统)
- int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
- writeToPLC_Flag1.Adress = 2077;
- writeToPLC_Flag1.Value = (short)6;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" +
- stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- #endregion 解绑(边线MES系统)
- #region 存储绑定数据到 边线MES系统中
- string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
- snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
- writeToPLC_Flag1.Adress = 2077;
- writeToPLC_Flag1.Value = (short)6;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" +
- stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- #endregion 存储绑定数据到 边线MES系统中
- stopwatch2.Stop();
- short b1MES_FLAG_Unbind = 1;
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
- writeToPLC_Flag.Adress = 2077;
- writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
- writeToPLC_Flag.Adress = 2077;
- writeToPLC_Flag.Value = (short)6;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- //// 上次采集到的SN
- //private string sn_FCT = string.Empty;
- /// <summary>
- /// [S2] FCT(板测)- 出站数据
- /// </summary>
- private void S2出站接口(int plcNo, string stationCode, string stationName)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string stationNameStr = stationCode + stationName;
- string processItem = stationName; // 测试项目
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- //string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
- int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
- int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
- bool pass1 = b1Part1Result == 1;
- bool pass2 = b1Part2Result == 1;
- #region 根据 载具SN 查 物料SN
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "b1MES_FLAG";
- writeToPLC_Flag1.Adress = 2169;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
- "ms");
- return;
- }
- #endregion 根据 载具SN 查 物料SN
- string[] cavitySNs = cavityData.Split('.');
- string b1ProductSN1 = string.Empty;
- string b1ProductSN2 = string.Empty;
- if (cavitySNs != null && cavitySNs.Length >= 2)
- {
- b1ProductSN1 = cavitySNs[0];
- b1ProductSN2 = cavitySNs[1];
- }
- stopwatch2.Start();
- // 产品1
- int result1 = 0;
- if (b1ProductSN1 == "假产品")
- result1 = 1;
- else
- {
- List<TestItem> items1 = new List<TestItem>();
- items1.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = b1ProductSN.ToString(),
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
- , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
- }
- // 产品2
- int result2 = 0;
- if (b1ProductSN1 == "假产品")
- result2 = 1;
- else
- {
- List<TestItem> items2 = new List<TestItem>();
- items2.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = b1ProductSN.ToString(),
- Parameter_unit = ""
- });
- items2.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "2",
- Parameter_unit = ""
- });
- items2.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- result2 = SwitctProcessData_old(stationNameStr, items2, equipmentCode, processItem
- , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
- }
- short result = 0;
- List<int> results = new List<int>() { result1, result2 };
- if (result1 == 1 && result2 == 1)
- result = 1;
- else if (results.Contains(3))
- result = 3;
- else if (results.Contains(2))
- result = 2;
- else if (results.Contains(4))
- result = 4;
- else
- result = 4;
- stopwatch2.Stop();
- //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "b1MES_FLAG";
- writeToPLC_Flag.Adress = 2169;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
- OnMessage(LogType.Debug,
- $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Restart();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "b1MES_FLAG";
- writeToPLC_Flag.Adress = 2169;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S2] FCT(板测)- 节拍接口
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S2节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = ((int)s1PLCData["a2OEEType"]).ToString(); // 节拍类型(plc写入)
- string a2OEEPartNo = (string)s1PLCData["a2OEEPartNo"]; // 物料码
- a2OEEPartNo = a2OEEPartNo.Replace("\0", "");
- string a20EEVehicleCode = (string)s1PLCData["a20EEVehicleCode"]; // 载具SN
- a20EEVehicleCode = a20EEVehicleCode.Replace("\0", "");
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
- "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- //作业开始后要有物料和载具信息
- if (string.IsNullOrEmpty(a2OEEPartNo) && string.IsNullOrEmpty(a20EEVehicleCode) &&
- Convert.ToInt32(oEEType) > 2)
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a2OEEPartNo))
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a20EEVehicleCode))
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- short _result = 0;
- // 上传OEE
- (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a2OEEPartNo, a20EEVehicleCode);
- _result = result.Item1;
- resultStr = result.Item2;
- if (_result == 1)
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 1; //OK
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- OnMessage(LogType.Info,
- $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
- stopwatch2.Stop();
- }
- else
- {
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //写入PLC
- iot_data.beatReturn = 2; //NG
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- #endregion [S2] FCT(板测)
- #endregion PLC2 李晓奇
- #region PLC3 刘永村
- #region [S3] 值板机
- /// <summary>
- /// S3工位的数据- 触发信号上次的值
- /// </summary>
- private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
- /// <summary>
- /// S3工位的数据(含触发信号)
- /// </summary>
- private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
- /// <summary>
- /// S3工位的数据- 回写点位
- /// </summary>
- private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
- /// <summary>
- /// [S3] 值板机
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- //private void ReadStation_S3(int plcNo)
- //{
- // // [S1] Tray盘上料装备
- // // [S2] FCT
- // // [S3] 值板机
- // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
- // // [S5] Tray盘下料装备
- // /// 上位机心跳
- // /// 获取设备报警数据与状态信息
- // string stationCode = "[S3]";
- // string stationName = "值板机";
- // string stationNameStr = stationCode + stationName;
- // #region 创建字典
- // // 触发信号字典 赋值
- // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
- // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
- // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
- // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
- // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // // PLC数据字典 赋值
- // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
- // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
- // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
- // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
- // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
- // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
- // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
- // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
- // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
- // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
- // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
- // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
- // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
- // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
- // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
- // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
- // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
- // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
- // s3PLCData.Add("c1Result", 0); // 产品结果
- // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
- // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
- // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
- // #endregion 创建字典
- // while (IsRun)
- // {
- // try
- // {
- // if (!GlobalContext._IsCon_Funs3)
- // {
- // UpdatePLCMonitor(1, plcNo, 0);
- // continue;
- // }
- // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- // {
- // Stopwatch stopwatch1 = new Stopwatch();
- // Stopwatch stopwatch2 = new Stopwatch();
- // stopwatch1.Start();
- // stopwatch2.Start();
- // #region 一次性读取所有数据
- // // 一次性读取所有数据
- // ModbusClientHelper modbusClientHelper = Funs[plcNo];
- // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
- // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
- // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
- // int[] datas = data1.Concat(data2).ToArray();
- // datas = datas.Concat(data3).ToArray();
- // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
- // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
- // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
- // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
- // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
- // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
- // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
- // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
- // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
- // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
- // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
- // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
- // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
- // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
- // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
- // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
- // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
- // s3PLCData["c1Result"] = datas[192]; // 产品结果
- // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
- // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
- // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
- // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
- // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
- // #endregion 一次性读取所有数据
- // stopwatch2.Stop();
- // #region 回写操作,写后清空flag
- // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
- // #endregion 回写操作,写后清空flag
- // #region S3进站校验
- // try
- // {
- // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
- // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
- // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
- // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
- // {
- // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
- // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
- // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
- // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion S3进站校验
- // #region S3二穴载具解绑
- // try
- // {
- // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
- // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
- // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
- // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
- // {
- // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
- // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
- // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
- // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion S3二穴载具解绑
- // #region S3二穴载具绑定
- // try
- // {
- // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
- // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
- // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
- // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
- // {
- // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
- // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
- // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
- // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion S3二穴载具绑定
- // #region S3出站接口(+一穴载具绑定)
- // try
- // {
- // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
- // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
- // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
- // if (c1PLC_FLAG != c1PLC_FLAGOld)
- // {
- // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
- // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
- // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
- // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion S3出站接口(+一穴载具绑定)
- // #region S3节拍接口
- // try
- // {
- // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
- // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
- // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
- // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
- // {
- // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
- // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
- // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
- // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion S3节拍接口
- // #region 心跳
- // try
- // {
- // short states = 0;
- // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
- // }
- // catch (Exception ex)
- // {
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 心跳
- // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- // stopwatch1.Stop();
- // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
- // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- // }
- // else
- // {
- // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- // Funs[plcNo].Connect();
- // }
- // }
- // catch (Exception ex)
- // {
- // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- // Funs[plcNo].ReConnect();
- // }
- // Thread.Sleep(IntervalReadPLC);
- // }
- //}
- /// <summary>
- /// [S3] 值板机- 进站校验
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S3进站校验(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
- sn = sn.Replace("\0", "");
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
- writeToPLC_Flag1.Adress = 2003;
- writeToPLC_Flag1.Value = (short)6;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- #endregion 查询载具上的产品信息
- string[] cavitySNs = cavityData.Split('.');
- string part1Str = ""; // 产品1的SN码
- string part2Str = ""; // 产品2的SN码
- short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
- short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
- if (cavitySNs != null && cavitySNs.Length >= 2)
- {
- part1Str = cavitySNs[0];
- part2Str = cavitySNs[1];
- c1Part1Result_Check = 2;
- c1Part2Result_Check = 2;
- }
- if (part1Str == "假产品")
- c1Part1Result_Check = 3;
- if (part2Str == "假产品")
- c1Part2Result_Check = 3;
- // 调用MES进站
- stopwatch2.Start();
- // 调用MES进站 - 产品1
- List<TestItem> item;
- int result1 = c1Part1Result_Check;
- if (result1 != 3)
- {
- item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = sn,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- });
- result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
- part1Str, item, out string errorMsg);
- }
- // 调用MES进站 - 产品2
- int result2 = c1Part2Result_Check;
- if (result2 != 3)
- {
- item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = sn,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "2",
- });
- result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
- part2Str, item, out string errorMsg);
- }
- stopwatch2.Stop();
- if (result1 == 2)
- c1Part1Result_Check = 2;
- if (result2 == 2)
- c1Part2Result_Check = 2;
- int result = result1;
- if (result == 1)
- result = result2;
- short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
- short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
- short c1MES_FLAG_Check = (short)result;
- //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
- //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
- //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
- //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "c1MES_FLAG_Check";
- writeToPLC_Flag.Adress = 2003;
- writeToPLC_Flag.Value = c1MES_FLAG_Check;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "c1Part1Result_Check",
- Adress = 2024,
- ValueType = PLCValueType.Short,
- Value = c1Part1Result_Check
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "c1Part2Result_Check",
- Adress = 2025,
- ValueType = PLCValueType.Short,
- Value = c1Part2Result_Check
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "c1Part1Num_Check",
- Adress = 2026,
- ValueType = PLCValueType.Short,
- Value = c1Part1Num_Check
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "c1Part2Num_Check",
- Adress = 2027,
- ValueType = PLCValueType.Short,
- Value = c1Part2Num_Check
- });
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "c1MES_FLAG_Check";
- writeToPLC_Flag.Adress = 2003;
- writeToPLC_Flag.Value = (short)6;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S3] 值板机 - 二穴载具解绑
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S3二穴载具解绑(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
- c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
- int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
- // 解绑
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
- writeToPLC_Flag1.Adress = 2082;
- writeToPLC_Flag1.Value = (short)6;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
- "ms");
- return;
- }
- #endregion 查询载具上的产品信息
- string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
- #region 解绑
- if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
- {
- // 删除
- int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
- OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
- }
- else
- {
- string data_new = string.Join(".", cavitySNs);
- // 删除再插入
- int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
- int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
- OnMessage(LogType.Debug,
- $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
- }
- #endregion 解绑
- short c1MES_FLAG_Unbind = 1;
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
- writeToPLC_Flag.Adress = 2082;
- writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
- writeToPLC_Flag.Adress = 2082;
- writeToPLC_Flag.Value = (short)6;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S3] 值板机 - 二穴载具绑定
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S3二穴载具绑定(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
- c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
- int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
- int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
- int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
- stopwatch2.Start();
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
- writeToPLC_Flag1.Adress = 2115;
- writeToPLC_Flag1.Value = (short)6;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
- "ms");
- return;
- }
- #endregion 查询载具上的产品信息
- // 产品换载具
- string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
- string partSn1 = "";
- string partSn2 = "";
- if (cavitySNs != null && cavitySNs.Length >= 2)
- {
- partSn1 = cavitySNs[0];
- partSn2 = cavitySNs[1];
- }
- string data_new = string.Empty;
- // 是否是两个穴位交换
- if (c1CavityReverse_Bind == 1)
- {
- // 交换
- data_new = string.Concat(partSn2, ".", partSn1);
- }
- else
- {
- // 不交换
- string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
- cavitySNs[c1VehicleCavityTo_Bind] = sn;
- cavitySNs[c1VehicleCavityFr_Bind] = "";
- data_new = string.Join(".", cavitySNs);
- }
- // 删除再插入
- int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
- int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
- OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
- stopwatch2.Stop();
- short c1MES_FLAG_Bind = 1;
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
- writeToPLC_Flag.Adress = 2115;
- writeToPLC_Flag.Value = c1MES_FLAG_Bind;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
- writeToPLC_Flag.Adress = 2115;
- writeToPLC_Flag.Value = (short)6;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- //// 上次采集到的SN
- //private string sn_值板机 = string.Empty;
- /// <summary>
- /// [S3] 值板机 - 出站接口
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- private void S3出站接口(int plcNo, string stationCode, string stationName)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string stationNameStr = stationCode + stationName;
- string processItem = stationName; // 测试项目
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- //string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
- sn = sn.Replace("\0", "");
- string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
- c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
- int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
- int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
- bool pass = c1Result == 1;
- // 查sn
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "c1MES_FLAG";
- writeToPLC_Flag1.Adress = 2150;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- #endregion 查询载具上的产品信息
- string[] cavitySNs = cavityData.Split('.');
- string productSN = "";
- if (cavitySNs != null && cavitySNs.Length >= 2)
- {
- productSN = cavitySNs[c1VehicleCavity];
- cavitySNs[c1VehicleCavity] = "";
- }
- stopwatch2.Start();
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "二穴载具码",
- Parameter_value = c1ProductSN_Check,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "二穴载具穴号",
- Parameter_value = c1VehicleCavity.ToString(),
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "一穴载具码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "一穴载具穴号",
- Parameter_value = "1",
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = c1Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
- , workorder_code, mtltmrk, productSN, pass, sn, "1");
- short result = (short)result1;
- stopwatch2.Stop();
- #region 存储绑定数据到 边线MES系统中
- if (result == 1)
- {
- string data = string.Concat(productSN);
- int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
- if (resultMesR != 0)
- {
- result = 4;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
- }
- }
- #endregion 存储绑定数据到 边线MES系统中
- #region 产品从 来源载具(二穴载具)中删除
- if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
- {
- // 删除
- int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
- OnMessage(LogType.Debug,
- $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
- }
- else
- {
- string data_new = string.Join(".", cavitySNs);
- // 删除再插入
- int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
- int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
- OnMessage(LogType.Debug,
- $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
- }
- #endregion 产品从 来源载具(二穴载具)中删除
- // MES_Flag 为MES报错
- // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "c1MES_FLAG";
- writeToPLC_Flag.Adress = 2150;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
- OnMessage(LogType.Debug,
- $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Restart();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "c1MES_FLAG";
- writeToPLC_Flag.Adress = 2150;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S3] 值板机- 节拍接口
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S3节拍接口(int plcNo, string stationNameStr, string tagMesCommName, string CarrierBarcode,
- IoT_DataSet_t iot_data)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = iot_data.BeatAction.ToString(); // 节拍类型(plc写入)
- string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode); //产品SN
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = iot_data.machineState;
- iotData.work_type = iot_data.work_type;
- iotData.testStatus = iot_data.testStatus;
- iotData.BeatAction = iot_data.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = iot_data.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
- stopwatch2.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
- "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- //作业开始后要有物料和载具信息
- if (string.IsNullOrEmpty(strProductBarcode) && string.IsNullOrEmpty(CarrierBarcode) &&
- Convert.ToInt32(oEEType) > 2)
- {
- stopwatch2.Start();
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = iot_data.machineState;
- iotData.work_type = iot_data.work_type;
- iotData.testStatus = iot_data.testStatus;
- iotData.BeatAction = iot_data.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = iot_data.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{CarrierBarcode}][{strProductBarcode}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(strProductBarcode))
- {
- stopwatch2.Start();
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = iot_data.machineState;
- iotData.work_type = iot_data.work_type;
- iotData.testStatus = iot_data.testStatus;
- iotData.BeatAction = iot_data.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = iot_data.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_[{CarrierBarcode}]上传节拍失败!物料码不可为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(CarrierBarcode))
- {
- stopwatch2.Start();
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = iot_data.machineState;
- iotData.work_type = iot_data.work_type;
- iotData.testStatus = iot_data.testStatus;
- iotData.BeatAction = iot_data.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = iot_data.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Info,
- stationNameStr + $"_上传节拍失败!载具码不可为空;总用时" +
- stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- short _result = 0;
- // 上传OEE
- (short, string) result =
- SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
- _result = result.Item1;
- resultStr = result.Item2;
- if (_result == 1)
- {
- stopwatch2.Start();
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = iot_data.machineState;
- iotData.work_type = iot_data.work_type;
- iotData.testStatus = iot_data.testStatus;
- iotData.BeatAction = iot_data.BeatAction;
- iotData.beatReturn = 1; //OK
- iotData.fault_codes = iot_data.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
- OnMessage(LogType.Info,
- $"PLC{plcNo}_{stationNameStr} 节拍{iotData.BeatAction}上传IOT成功!上传结果:" + resultStr);
- stopwatch2.Stop();
- }
- else
- {
- stopwatch2.Start();
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = iot_data.machineState;
- iotData.work_type = iot_data.work_type;
- iotData.testStatus = iot_data.testStatus;
- iotData.BeatAction = iot_data.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = iot_data.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
- stopwatch2.Stop();
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //写入PLC
- IoT_DataSet_t iotData = new IoT_DataSet_t();
- iotData.machineState = iot_data.machineState;
- iotData.work_type = iot_data.work_type;
- iotData.testStatus = iot_data.testStatus;
- iotData.BeatAction = iot_data.BeatAction;
- iotData.beatReturn = 2; //NG
- iotData.fault_codes = iot_data.fault_codes;
- WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- #endregion [S3] 值板机
- #endregion PLC3 刘永村
- #region PLC4 刘果段
- #region [S4] 取放桁架
- /// <summary>
- /// S4工位的数据- 触发信号上次的值
- /// </summary>
- private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
- /// <summary>
- /// S4工位的数据(含触发信号)
- /// </summary>
- private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
- /// <summary>
- /// S4工位的数据- 回写点位
- /// </summary>
- private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
- /// <summary>
- /// [S4] 取放桁架
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- //private void ReadStation_S4(int plcNo)
- //{
- // // [S1] Tray盘上料装备
- // // [S2] FCT
- // // [S3] 值板机
- // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
- // // [S5] Tray盘下料装备
- // /// 上位机心跳
- // /// 获取设备报警数据与状态信息
- // string stationCode = "[S4_1]";
- // string stationName = "载具下线装备";
- // string stationNameStr = stationCode + stationName;
- // string stationCode2 = "[S4_2]";
- // string stationName2 = "桁架";
- // string stationNameStr2 = stationCode2 + stationName2;
- // string stationCode3 = "[S4_3]";
- // string stationName3 = "提升机1";
- // string stationNameStr3 = stationCode3 + stationName3;
- // string stationCode4 = "[S4_4]";
- // string stationName4 = "提升机2";
- // string stationNameStr4 = stationCode4 + stationName4;
- // string stationCode5 = "[S4_5]";
- // string stationName5 = "载具上线装备";
- // string stationNameStr5 = stationCode5 + stationName5;
- // #region 创建字典
- // // 触发信号字典 赋值
- // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
- // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
- // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
- // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
- // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
- // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
- // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
- // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
- // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
- // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // // PLC数据字典 赋值
- // // 载具下线装备(弹夹上线)
- // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
- // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
- // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
- // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
- // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
- // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
- // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
- // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
- // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
- // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
- // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
- // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
- // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
- // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
- // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
- // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
- // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
- // s4PLCData.Add("d1Result", 0); // 产品结果
- // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
- // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
- // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
- // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
- // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
- // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
- // // 真空标机(提升机)
- // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
- // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
- // s4PLCData.Add("d3Type", 0); // 进站还是出站
- // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
- // s4PLCData.Add("d3Result", 0); // 产品结果
- // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
- // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
- // s4PLCData.Add("d4Type", 0); // 进站还是出站
- // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
- // s4PLCData.Add("d4Result", 0); // 产品结果
- // // 载具上线装备(弹夹下线)
- // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
- // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
- // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
- // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
- // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
- // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
- // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
- // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
- // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
- // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
- // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
- // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
- // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
- // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
- // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
- // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
- // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
- // s4PLCData.Add("d5Result", 0); // 产品结果
- // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
- // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
- // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
- // #endregion 创建字典
- // while (IsRun)
- // {
- // try
- // {
- // if (!GlobalContext._IsCon_Funs4)
- // {
- // UpdatePLCMonitor(1, plcNo, 0);
- // continue;
- // }
- // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- // {
- // Stopwatch stopwatch1 = new Stopwatch();
- // Stopwatch stopwatch2 = new Stopwatch();
- // stopwatch1.Start();
- // stopwatch2.Start();
- // #region 一次性读取所有数据
- // // 载具下线装备(弹夹上线)
- // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
- // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
- // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
- // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
- // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
- // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
- // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
- // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
- // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
- // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
- // int[] datas = data1.Concat(data2).ToArray();
- // datas = datas.Concat(data3).ToArray();
- // datas = datas.Concat(data4).ToArray();
- // datas = datas.Concat(data5).ToArray();
- // datas = datas.Concat(data6).ToArray();
- // datas = datas.Concat(data7).ToArray();
- // datas = datas.Concat(data8).ToArray();
- // datas = datas.Concat(data9).ToArray();
- // datas = datas.Concat(data10).ToArray();
- // // 载具下线装备(弹夹上线)
- // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
- // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
- // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
- // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
- // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
- // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
- // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
- // s4PLCData["d1MES_FLAG"] = datas[65];
- // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
- // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
- // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
- // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
- // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
- // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
- // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
- // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
- // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
- // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
- // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
- // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
- // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
- // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
- // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
- // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
- // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
- // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
- // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
- // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
- // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
- // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
- // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
- // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
- // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
- // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
- // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
- // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
- // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
- // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
- // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
- // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
- // s4PLCData["d1Result"] = datas[386];
- // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
- // s4PLCData["d1OEEMES_FLAG"] = datas[398];
- // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
- // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
- // s4PLCData["d1OEEType"] = datas[419];
- // // 桁架(查询标机中弹夹的状态)
- // s4PLCData["d2BulletclipScanCode"] = datas[430];
- // s4PLCData["d2BulletclipStates"] = datas[431];
- // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
- // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
- // // 真空标机
- // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
- // s4PLCData["d3MES_FLAG"] = datas[463];
- // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
- // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
- // s4PLCData["d3Result"] = datas[484];
- // s4PLCData["d3Type"] = datas[485];
- // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
- // s4PLCData["d4MES_FLAG"] = datas[496];
- // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
- // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
- // s4PLCData["d4Result"] = datas[517];
- // s4PLCData["d4Type"] = datas[518];
- // // 载具上线装备(弹夹下线)
- // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
- // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
- // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
- // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
- // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
- // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
- // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
- // s4PLCData["d5MES_FLAG"] = datas[591];
- // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
- // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
- // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
- // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
- // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
- // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
- // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
- // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
- // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
- // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
- // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
- // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
- // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
- // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
- // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
- // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
- // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
- // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
- // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
- // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
- // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
- // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
- // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
- // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
- // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
- // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
- // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
- // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
- // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
- // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
- // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
- // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
- // s4PLCData["d5Result"] = datas[912];
- // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
- // s4PLCData["d5OEEMES_FLAG"] = datas[924];
- // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
- // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
- // s4PLCData["d5OEEType"] = datas[945];
- // #endregion 一次性读取所有数据
- // stopwatch2.Stop();
- // #region 回写操作,写后清空flag
- // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
- // #endregion 回写操作,写后清空flag
- // // N801A-S4_1 弹夹扫码
- // #region N801A-S4_1 弹夹扫码
- // try
- // {
- // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
- // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
- // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
- // {
- // if (d1BulletclipScanCode == 1) // 0->1
- // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
- // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion N801A-S4_1 弹夹扫码
- // // N801A-S4_1 载具扫码
- // #region N801A-S4_1 载具扫码
- // try
- // {
- // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
- // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
- // if (d1VehicleScanCode != d1VehicleScanCodeOld)
- // {
- // if (d1VehicleScanCode == 1) // 0->1
- // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
- // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion N801A-S4_1 载具扫码
- // // N801A-S4_1 出站接口
- // #region N801A-S4_1 出站接口
- // try
- // {
- // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
- // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
- // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
- // if (d1PLC_FLAG != d1PLC_FLAGOld)
- // {
- // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
- // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
- // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
- // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion N801A-S4_1 出站接口
- // // N801A-S4_1 节拍接口
- // #region N801A-S4_1 节拍接口
- // try
- // {
- // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
- // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
- // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
- // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
- // {
- // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
- // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
- // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
- // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion N801A-S4_1 节拍接口
- // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
- // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
- // try
- // {
- // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
- // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
- // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
- // {
- // if (d2BulletclipScanCode == 1) // 0->1
- // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
- // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
- // // N801A-S4_3 真空标机1 数据
- // #region N801A-S4_3 真空标机1
- // try
- // {
- // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
- // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
- // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
- // if (d3PLC_FLAG != d3PLC_FLAGOld)
- // {
- // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
- // {
- // int stationType = (int)s4PLCData["d3Type"];
- // if (stationType == 1)
- // {
- // // S4_3进站接口
- // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
- // }
- // else if (stationType == 2)
- // {
- // // S4_3出站接口
- // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
- // }
- // }
- // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
- // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion N801A-S4_3 真空标机1
- // // N801A-S4_4 真空标机2 数据
- // #region N801A-S4_4 真空标机2
- // try
- // {
- // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
- // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
- // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
- // if (d4PLC_FLAG != d4PLC_FLAGOld)
- // {
- // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
- // {
- // int stationType = (int)s4PLCData["d4Type"];
- // if (stationType == 1)
- // {
- // // S4_4进站接口
- // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
- // }
- // else if (stationType == 2)
- // {
- // // S4_4出站接口
- // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
- // }
- // }
- // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
- // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion N801A-S4_4 真空标机2
- // // N801A-S4_5 弹夹扫码 数据
- // #region N801A-S4_5 弹夹扫码
- // try
- // {
- // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
- // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
- // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
- // {
- // if (d5BulletclipScanCode == 1) // 0->1
- // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
- // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion N801A-S4_5 弹夹扫码
- // // N801A-S4_5 载具扫码 数据
- // #region N801A-S4_5 载具扫码
- // try
- // {
- // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
- // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
- // if (d5VehicleScanCode != d5VehicleScanCodeOld)
- // {
- // if (d5VehicleScanCode == 1) // 0->1
- // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
- // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion N801A-S4_5 载具扫码
- // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
- // #region N801A-S4_5 出站接口
- // try
- // {
- // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
- // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
- // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
- // if (d5PLC_FLAG != d5PLC_FLAGOld)
- // {
- // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
- // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
- // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
- // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion N801A-S4_5 出站接口
- // // N801A-S4_5 节拍接口 数据
- // #region N801A-S4_5 节拍接口
- // try
- // {
- // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
- // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
- // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
- // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
- // {
- // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
- // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
- // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
- // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion N801A-S4_5 节拍接口
- // #region 心跳
- // try
- // {
- // short states = 0;
- // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
- // }
- // catch (Exception ex)
- // {
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 心跳
- // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- // stopwatch1.Stop();
- // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
- // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- // }
- // else
- // {
- // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
- // Funs[plcNo].Connect();
- // }
- // }
- // catch (Exception ex)
- // {
- // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
- // Funs[plcNo].ReConnect();
- // }
- // Thread.Sleep(IntervalReadPLC);
- // }
- //}
- /// <summary>
- /// [S4] 取放桁架 - S4_1弹夹扫码
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S4_1弹夹扫码(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 弹夹扫码
- string d1BulletclipCode = " "; // 扫到的码
- short d1BulletclipScanCode = 2;
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1BulletclipScanCode";
- writeToPLC_Flag.Adress = 2002;
- writeToPLC_Flag.Value = d1BulletclipScanCode;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
- {
- Name = "d1BulletclipCode",
- Adress = 2003,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = d1BulletclipCode
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1BulletclipScanCode";
- writeToPLC_Flag.Adress = 2002;
- writeToPLC_Flag.Value = (short)6;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
- {
- Name = "d1BulletclipCode",
- Adress = 2003,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = " "
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S4] 取放桁架 - S4_1载具扫码
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S4_1载具扫码(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 载具扫码
- string d1VehicleCode = ""; // 扫到的码
- short d1VehicleScanCode = 2;
- #region 进站
- if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
- {
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d1VehicleScanCode";
- writeToPLC_Flag1.Adress = 2033;
- writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
- writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "d1VehicleCode",
- Adress = 2034,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
- "ms");
- return;
- }
- string[] cavitySNs = cavityData.Split('.');
- string partNo = "";
- if (cavitySNs != null && cavitySNs.Length >= 1)
- {
- partNo = cavitySNs[0];
- }
- #endregion 查询载具上的产品信息
- List<TestItem> item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = d1VehicleCode,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- });
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
- partNo, item, out string errorMsg);
- stopwatch2.Stop();
- d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
- }
- #endregion 进站
- //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1VehicleScanCode";
- writeToPLC_Flag.Adress = 2033;
- writeToPLC_Flag.Value = d1VehicleScanCode;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "d1VehicleCode",
- Adress = 2034,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = d1VehicleCode
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1VehicleScanCode";
- writeToPLC_Flag.Adress = 2033;
- writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "d1VehicleCode",
- Adress = 2034,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- // 上次采集到的SN
- //private string sn_S4_1出站接口 = string.Empty;
- /// <summary>
- /// [S4] 取放桁架 - S4_1出站接口
- /// </summary>
- private void S4_1出站接口(int plcNo, string stationCode, string stationName)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string stationNameStr = stationCode + stationName;
- string processItem = stationName; // 测试项目
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- //string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
- sn = sn.Replace("\0", "");
- string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
- d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
- string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
- d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
- string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
- d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
- string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
- d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
- string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
- d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
- string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
- d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
- string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
- d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
- string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
- d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
- string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
- d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
- string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
- d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
- string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
- d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
- string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
- d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
- string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
- d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
- string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
- d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
- string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
- d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
- int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
- bool pass = d1Result == 1;
- // 存 载具SN列表
- List<string> vehicleCodes = new List<string>()
- {
- d1VehicleCode1, d1VehicleCode2, d1VehicleCode3, d1VehicleCode4, d1VehicleCode5,
- d1VehicleCode6, d1VehicleCode7, d1VehicleCode8, d1VehicleCode9, d1VehicleCode10,
- d1VehicleCode11, d1VehicleCode12, d1VehicleCode13, d1VehicleCode14, d1VehicleCode15
- };
- // 统一查 产品SN列表
- List<string> partNos = new List<string>();
- foreach (string vehicleCode in vehicleCodes)
- {
- if (string.IsNullOrEmpty(vehicleCode))
- partNos.Add("");
- else
- {
- string partNo = "";
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d1MES_FLAG";
- writeToPLC_Flag1.Adress = 2065;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
- "ms");
- return;
- }
- string[] cavitySNs = cavityData.Split('.');
- if (cavitySNs != null && cavitySNs.Length >= 1)
- partNo = cavitySNs[0];
- #endregion 查询载具上的产品信息
- partNos.Add(partNo);
- }
- }
- // 统一上传
- stopwatch2.Start();
- List<int> results = new List<int>();
- for (int i = 0; i < partNos.Count; i++)
- {
- string index = (i + 1).ToString(); // 弹夹穴号
- if (string.IsNullOrEmpty(partNos[i]))
- results.Add(1);
- else
- {
- List<TestItem> items1 = new List<TestItem>();
- items1.Add(new TestItem()
- {
- Parameter_name = "弹夹码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "弹夹穴号",
- Parameter_value = index,
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = vehicleCodes[i],
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = d1Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
- , workorder_code, mtltmrk, partNos[i], pass, sn, index);
- results.Add(result1);
- }
- }
- short result = 0;
- if (results.All(a => a == 1))
- result = 1;
- else if (results.Contains(3))
- result = 3;
- else if (results.Contains(2))
- result = 2;
- else if (results.Contains(4))
- result = 4;
- else
- result = 4;
- stopwatch2.Stop();
- #region 存储绑定数据到 边线MES系统中
- if (result == 1)
- {
- string data = string.Join(".", vehicleCodes);
- int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
- if (resultMesR != 0)
- {
- result = 4;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
- }
- }
- #endregion 存储绑定数据到 边线MES系统中
- // MES_Flag 为4MES报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1MES_FLAG";
- writeToPLC_Flag.Adress = 2065;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
- OnMessage(LogType.Debug,
- $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Restart();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1MES_FLAG";
- writeToPLC_Flag.Adress = 2065;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S4] 取放桁架 - S4_1节拍接口
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S4_1节拍接口(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
- string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
- d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2398;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
- "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- string d1OEEPartNo = string.Empty; // 物料码
- if (string.IsNullOrEmpty(d1OEEProductSN))
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2398;
- writeToPLC_Flag1.Value = (short)1;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else
- {
- // 查产品SN ZS
- d1OEEPartNo = "Test";
- }
- short d1OEEMES_FLAG = 0;
- // 上传OEE
- (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
- d1OEEMES_FLAG = result.Item1;
- resultStr = result.Item2;
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2398;
- writeToPLC_Flag.Value = d1OEEMES_FLAG;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d1OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2398;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S4] 取放桁架 - S4_2桁架
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S4_2桁架(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 弹夹扫码
- string d2BulletclipCode = " "; // 扫到的码
- short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
- short d2BulletclipScanCode = 2;
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
- //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d2BulletclipScanCode";
- writeToPLC_Flag.Adress = 2430;
- writeToPLC_Flag.Value = d2BulletclipScanCode;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "d2BulletclipCode",
- Adress = 2432,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = d2BulletclipCode
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "d2BulletclipStates",
- Adress = 2431,
- ValueType = PLCValueType.Short,
- Value = d2BulletclipStates
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- stopwatch2.Start();
- Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
- Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
- // MES_Flag
- Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d2BulletclipScanCode";
- writeToPLC_Flag.Adress = 2430;
- writeToPLC_Flag.Value = (short)6;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "d2BulletclipCode",
- Adress = 2432,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = " "
- });
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
- {
- Name = "d2BulletclipStates",
- Adress = 2431,
- ValueType = PLCValueType.Short,
- Value = (short)0
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- // 上次采集到的SN
- //private string sn_S4_3进站接口 = string.Empty;
- /// <summary>
- /// [S4] 取放桁架 - S4_3进站接口(提升机1)
- /// </summary>
- private void S4_3进站接口(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
- sn = sn.Replace("\0", "");
- int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
- #region 查询15个载具码
- List<string> vehicleCodes = new List<string>(); // 15个载具码
- string vehicleData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
- if (string.IsNullOrEmpty(vehicleData))
- vehicleData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d3MES_FLAG";
- writeToPLC_Flag1.Adress = 2463;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- string[] cavitySNs = vehicleData.Split('.');
- if (cavitySNs != null && cavitySNs.Length > 0)
- {
- for (int i = 0; i < cavitySNs.Length; i++)
- {
- if (string.IsNullOrEmpty(cavitySNs[i]))
- vehicleCodes.Add("");
- else
- vehicleCodes.Add(cavitySNs[i]);
- }
- }
- #endregion 查询15个载具码
- #region 查询15个产品SN
- List<string> portNos = new List<string>(); // 15个产品SN
- foreach (string vehicleCode in vehicleCodes)
- {
- if (string.IsNullOrEmpty(vehicleCode))
- portNos.Add("");
- else
- {
- // 查询
- string cavityData = string.Empty;
- int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult1 != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d3MES_FLAG";
- writeToPLC_Flag1.Adress = 2463;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
- stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- string[] partSNs = cavityData.Split('.');
- if (partSNs != null && partSNs.Length >= 1)
- portNos.Add(partSNs[0]);
- else
- portNos.Add("");
- }
- }
- #endregion 查询15个产品SN
- // 调用MES进站(最多15个)
- stopwatch2.Start();
- List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
- for (int i = 0; i < vehicleCodes.Count; i++)
- {
- // 循环进站
- if (!string.IsNullOrEmpty(vehicleCodes[i]))
- {
- // 产品SN(物料码)校验
- string portNo = portNos[i];
- List<TestItem> item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "弹夹码",
- Parameter_value = sn,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "弹夹穴位",
- Parameter_value = (i + 1).ToString(),
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = vehicleCodes[i],
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- });
- results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
- GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
- }
- }
- stopwatch2.Stop();
- short result = 0;
- bool haveMesWarn = results.Contains(5);
- bool havePCWarn = results.Contains(6);
- if (haveMesWarn)
- result = 2; // 5->2
- else if (havePCWarn)
- result = 6; // 6->4
- else
- result = 1;
- // MES_Flag 为4MES报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d3MES_FLAG";
- writeToPLC_Flag.Adress = 2463;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
- OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Stop();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d3MES_FLAG";
- writeToPLC_Flag.Adress = 2463;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- // 上次采集到的SN
- //private string sn_S4_3出站接口 = string.Empty;
- /// <summary>
- /// [S4] 取放桁架 - S4_3出站接口(提升机1)
- /// </summary>
- private void S4_3出站接口(int plcNo, string stationCode, string stationName)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string stationNameStr = stationCode + stationName;
- string processItem = stationName; // 测试项目
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- //string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
- sn = sn.Replace("\0", "");
- int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
- bool isPass = d3Result == 1; // 产品结果 bool
- #region 查询15个载具码
- List<string> vehicleCodes = new List<string>(); // 15个载具码
- string vehicleData = string.Empty;
- int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
- if (string.IsNullOrEmpty(vehicleData))
- vehicleData = "";
- if (snResult1 != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d3MES_FLAG";
- writeToPLC_Flag1.Adress = 2463;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- string[] cavitySNs = vehicleData.Split('.');
- if (cavitySNs != null && cavitySNs.Length > 0)
- {
- for (int i = 0; i < cavitySNs.Length; i++)
- {
- if (string.IsNullOrEmpty(cavitySNs[i]))
- vehicleCodes.Add("");
- else
- vehicleCodes.Add(cavitySNs[i]);
- }
- }
- #endregion 查询15个载具码
- // 统一查 产品SN列表
- List<string> partNos = new List<string>();
- foreach (string vehicleCode in vehicleCodes)
- {
- if (string.IsNullOrEmpty(vehicleCode))
- partNos.Add("");
- else
- {
- string partNo = "";
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d3MES_FLAG";
- writeToPLC_Flag1.Adress = 2463;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
- "ms");
- return;
- }
- string[] partSNs = cavityData.Split('.');
- if (partSNs != null && partSNs.Length >= 1)
- partNo = partSNs[0];
- #endregion 查询载具上的产品信息
- partNos.Add(partNo);
- }
- }
- // 统一上传 - 调用MES出站
- stopwatch2.Start();
- List<int> results = new List<int>();
- for (int i = 0; i < partNos.Count; i++)
- {
- string index = (i + 1).ToString(); // 弹夹穴号
- if (string.IsNullOrEmpty(partNos[i]))
- results.Add(1);
- else
- {
- List<TestItem> items1 = new List<TestItem>();
- items1.Add(new TestItem()
- {
- Parameter_name = "弹夹码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "弹夹穴号",
- Parameter_value = index,
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = vehicleCodes[i],
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = d3Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
- , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
- results.Add(result1);
- }
- }
- short result = 0;
- if (results.All(a => a == 1))
- result = 1;
- else if (results.Contains(3))
- result = 3;
- else if (results.Contains(2))
- result = 2;
- else if (results.Contains(4))
- result = 4;
- else
- result = 4;
- stopwatch2.Stop();
- // MES_Flag 为4MES报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d3MES_FLAG";
- writeToPLC_Flag.Adress = 2463;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
- OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Restart();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d3MES_FLAG";
- writeToPLC_Flag.Adress = 2463;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- // 上次采集到的SN
- //private string sn_S4_4进站接口 = string.Empty;
- /// <summary>
- /// [S4] 取放桁架 - S4_4进站接口(提升机2)
- /// </summary>
- private void S4_4进站接口(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
- sn = sn.Replace("\0", "");
- int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
- #region 查询15个载具码
- List<string> vehicleCodes = new List<string>(); // 15个载具码
- string vehicleData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
- if (string.IsNullOrEmpty(vehicleData))
- vehicleData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d3MES_FLAG";
- writeToPLC_Flag1.Adress = 2463;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- string[] cavitySNs = vehicleData.Split('.');
- if (cavitySNs != null && cavitySNs.Length > 0)
- {
- for (int i = 0; i < cavitySNs.Length; i++)
- {
- if (string.IsNullOrEmpty(cavitySNs[i]))
- vehicleCodes.Add("");
- else
- vehicleCodes.Add(cavitySNs[i]);
- }
- }
- #endregion 查询15个载具码
- #region 查询15个产品SN
- List<string> portNos = new List<string>(); // 15个产品SN
- foreach (string vehicleCode in vehicleCodes)
- {
- if (string.IsNullOrEmpty(vehicleCode))
- portNos.Add("");
- else
- {
- // 查询
- string cavityData = string.Empty;
- int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult1 != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d3MES_FLAG";
- writeToPLC_Flag1.Adress = 2463;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
- stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- string[] partSNs = cavityData.Split('.');
- if (partSNs != null && partSNs.Length >= 1)
- portNos.Add(partSNs[0]);
- else
- portNos.Add("");
- }
- }
- #endregion 查询15个产品SN
- // 调用MES进站(最多15个)
- stopwatch2.Start();
- List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
- for (int i = 0; i < vehicleCodes.Count; i++)
- {
- // 循环进站
- if (!string.IsNullOrEmpty(vehicleCodes[i]))
- {
- // 产品SN(物料码)校验
- string portNo = portNos[i];
- List<TestItem> item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "弹夹码",
- Parameter_value = sn,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "弹夹穴位",
- Parameter_value = (i + 1).ToString(),
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = vehicleCodes[i],
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- });
- results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
- GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
- }
- }
- stopwatch2.Stop();
- short result = 0;
- bool haveMesWarn = results.Contains(5);
- bool havePCWarn = results.Contains(6);
- if (haveMesWarn)
- result = 2; // 5->2
- else if (havePCWarn)
- result = 6; // 6->4
- else
- result = 1;
- // MES_Flag 为4MES报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d4MES_FLAG";
- writeToPLC_Flag.Adress = 2496;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
- OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Stop();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d4MES_FLAG";
- writeToPLC_Flag.Adress = 2496;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- // 上次采集到的SN
- //private string sn_S4_4出站接口 = string.Empty;
- /// <summary>
- /// [S4] 取放桁架 - S4_4出站接口(提升机2)
- /// </summary>
- private void S4_4出站接口(int plcNo, string stationCode, string stationName)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string stationNameStr = stationCode + stationName;
- string processItem = stationName; // 测试项目
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- //string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
- sn = sn.Replace("\0", "");
- int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
- bool isPass = d4Result == 1; // 产品结果 bool
- #region 查询15个载具码
- List<string> vehicleCodes = new List<string>(); // 15个载具码
- string vehicleData = string.Empty;
- int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
- if (string.IsNullOrEmpty(vehicleData))
- vehicleData = "";
- if (snResult1 != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d4MES_FLAG";
- writeToPLC_Flag1.Adress = 2496;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- string[] cavitySNs = vehicleData.Split('.');
- if (cavitySNs != null && cavitySNs.Length > 0)
- {
- for (int i = 0; i < cavitySNs.Length; i++)
- {
- if (string.IsNullOrEmpty(cavitySNs[i]))
- vehicleCodes.Add("");
- else
- vehicleCodes.Add(cavitySNs[i]);
- }
- }
- #endregion 查询15个载具码
- // 统一查 产品SN列表
- List<string> partNos = new List<string>();
- foreach (string vehicleCode in vehicleCodes)
- {
- if (string.IsNullOrEmpty(vehicleCode))
- partNos.Add("");
- else
- {
- string partNo = "";
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d4MES_FLAG";
- writeToPLC_Flag1.Adress = 2496;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
- "ms");
- return;
- }
- string[] partSNs = cavityData.Split('.');
- if (partSNs != null && partSNs.Length >= 1)
- partNo = partSNs[0];
- #endregion 查询载具上的产品信息
- partNos.Add(partNo);
- }
- }
- // 调用MES出站
- stopwatch2.Start();
- // 统一上传
- List<int> results = new List<int>();
- for (int i = 0; i < partNos.Count; i++)
- {
- string index = (i + 1).ToString(); // 弹夹穴号
- if (string.IsNullOrEmpty(partNos[i]))
- results.Add(1);
- else
- {
- List<TestItem> items1 = new List<TestItem>();
- items1.Add(new TestItem()
- {
- Parameter_name = "弹夹码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "弹夹穴号",
- Parameter_value = index,
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = vehicleCodes[i],
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = d4Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
- , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
- results.Add(result1);
- }
- }
- short result = 0;
- if (results.All(a => a == 1))
- result = 1;
- else if (results.Contains(3))
- result = 3;
- else if (results.Contains(2))
- result = 2;
- else if (results.Contains(4))
- result = 4;
- else
- result = 4;
- stopwatch2.Stop();
- // MES_Flag 为4MES报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d4MES_FLAG";
- writeToPLC_Flag.Adress = 2496;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
- OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Restart();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d4MES_FLAG";
- writeToPLC_Flag.Adress = 2496;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S4] 取放桁架 - S4_5弹夹扫码
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S4_5弹夹扫码(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 弹夹扫码
- string d5BulletclipCode = " "; // 扫到的码
- short d5BulletclipScanCode = 2;
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5BulletclipScanCode";
- writeToPLC_Flag.Adress = 2528;
- writeToPLC_Flag.Value = d5BulletclipScanCode;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
- {
- Name = "d5BulletclipCode",
- Adress = 2529,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = d5BulletclipCode
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5BulletclipScanCode";
- writeToPLC_Flag.Adress = 2528;
- writeToPLC_Flag.Value = (short)6;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
- {
- Name = "d5BulletclipCode",
- Adress = 2529,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = " "
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S4] 取放桁架 - S4_5载具扫码
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S4_5载具扫码(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 载具扫码
- string d5VehicleCode = " "; // 扫到的码
- short d5VehicleScanCode = 2;
- #region 进站
- if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
- {
- // 查产品SN
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d5VehicleScanCode";
- writeToPLC_Flag1.Adress = 2559;
- writeToPLC_Flag1.Value = (short)6;
- writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
- {
- Name = "d5VehicleCode",
- Adress = 2560,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
- "ms");
- return;
- }
- string[] cavitySNs = cavityData.Split('.');
- string partNo = "";
- if (cavitySNs != null && cavitySNs.Length >= 1)
- {
- partNo = cavitySNs[0];
- }
- #endregion 查询载具上的产品信息
- List<TestItem> item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = d5VehicleCode,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- });
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
- partNo, item, out string errorMsg);
- stopwatch2.Stop();
- d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
- }
- #endregion 进站
- //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5VehicleScanCode";
- writeToPLC_Flag.Adress = 2559;
- writeToPLC_Flag.Value = d5VehicleScanCode;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
- {
- Name = "d5VehicleCode",
- Adress = 2560,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = d5VehicleCode
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
- //// MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5VehicleScanCode";
- writeToPLC_Flag.Adress = 2559;
- writeToPLC_Flag.Value = (short)6;
- writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
- {
- Name = "d5VehicleCode",
- Adress = 2560,
- ValueType = PLCValueType.String,
- ValueTypeStrLength = 20,
- Value = " "
- });
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- // 上次采集到的SN
- //private string sn_S4_5出站接口 = string.Empty;
- /// <summary>
- /// [S4] 取放桁架 - S4_5出站接口
- /// </summary>
- private void S4_5出站接口(int plcNo, string stationCode, string stationName)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string stationNameStr = stationCode + stationName;
- string processItem = stationName; // 测试项目
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- //string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
- sn = sn.Replace("\0", "");
- string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
- d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
- string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
- d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
- string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
- d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
- string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
- d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
- string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
- d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
- string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
- d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
- string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
- d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
- string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
- d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
- string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
- d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
- string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
- d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
- string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
- d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
- string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
- d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
- string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
- d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
- string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
- d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
- string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
- d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
- int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
- bool pass = d5Result == 1;
- // 存 载具SN列表
- List<string> vehicleCodes = new List<string>()
- {
- d5VehicleCode1, d5VehicleCode2, d5VehicleCode3, d5VehicleCode4, d5VehicleCode5,
- d5VehicleCode6, d5VehicleCode7, d5VehicleCode8, d5VehicleCode9, d5VehicleCode10,
- d5VehicleCode11, d5VehicleCode12, d5VehicleCode13, d5VehicleCode14, d5VehicleCode15
- };
- // 统一查 产品SN列表
- List<string> partNos = new List<string>();
- foreach (string vehicleCode in vehicleCodes)
- {
- if (string.IsNullOrEmpty(vehicleCode))
- partNos.Add("");
- else
- {
- string partNo = "";
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d5MES_FLAG";
- writeToPLC_Flag1.Adress = 2591;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
- "ms");
- return;
- }
- string[] cavitySNs = cavityData.Split('.');
- if (cavitySNs != null && cavitySNs.Length >= 1)
- partNo = cavitySNs[0];
- #endregion 查询载具上的产品信息
- partNos.Add(partNo);
- }
- }
- // 统一上传
- stopwatch2.Start();
- List<int> results = new List<int>();
- for (int i = 0; i < partNos.Count; i++)
- {
- string index = (i + 1).ToString(); // 弹夹穴号
- if (string.IsNullOrEmpty(partNos[i]))
- results.Add(1);
- else
- {
- List<TestItem> items1 = new List<TestItem>();
- items1.Add(new TestItem()
- {
- Parameter_name = "弹夹码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "弹夹穴号",
- Parameter_value = index,
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = vehicleCodes[i],
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- Parameter_unit = ""
- });
- items1.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = d5Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
- , workorder_code, mtltmrk, partNos[i], pass, sn, index);
- results.Add(result1);
- }
- }
- short result = 0;
- if (results.All(a => a == 1))
- result = 1;
- else if (results.Contains(3))
- result = 3;
- else if (results.Contains(2))
- result = 2;
- else if (results.Contains(4))
- result = 4;
- else
- result = 4;
- stopwatch2.Stop();
- #region 存储绑定数据到 边线MES系统中
- if (result == 1)
- {
- // 删除绑定信息
- int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
- if (resultMesR != 0)
- {
- result = 4;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
- }
- }
- #endregion 存储绑定数据到 边线MES系统中
- // MES_Flag 为4MES报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5MES_FLAG";
- writeToPLC_Flag.Adress = 2591;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
- OnMessage(LogType.Debug,
- $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Restart();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5MES_FLAG";
- writeToPLC_Flag.Adress = 2591;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S4] 取放桁架 - S4_5节拍接口
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S4_5节拍接口(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string resultStr = string.Empty;
- try
- {
- stopwatch1.Start();
- string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
- string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
- d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
- bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- if (!actionBool)
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2924;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
- "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- string d5OEEPartNo = string.Empty; // 物料码
- if (string.IsNullOrEmpty(d5OEEProductSN))
- {
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
- writeToPLC_Flag1.Adress = 2924;
- writeToPLC_Flag1.Value = (short)1;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
- stopwatch2.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- return;
- }
- else
- {
- // 查产品SN
- d5OEEPartNo = "Test"; // ZS
- }
- short d5OEEMES_FLAG = 0;
- // 上传OEE
- (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
- d5OEEMES_FLAG = result.Item1;
- resultStr = result.Item2;
- stopwatch2.Start();
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2924;
- writeToPLC_Flag.Value = d5OEEMES_FLAG;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "d5OEEMES_FLAG";
- writeToPLC_Flag.Adress = 2924;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- #endregion [S4] 取放桁架
- #endregion PLC4 刘果段
- #region PLC5 张超凡
- #region [S5] Tray盘下料装备
- /// <summary>
- /// S5工位的数据- 触发信号上次的值
- /// </summary>
- private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
- /// <summary>
- /// S5工位的数据(含触发信号)
- /// </summary>
- private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
- /// <summary>
- /// S5工位的数据- 回写点位
- /// </summary>
- private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
- /// <summary>
- /// [S5] Tray盘下料装备
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- //private void ReadStation_S5(int plcNo)
- //{
- // // [S1] Tray盘上料装备
- // // [S2] FCT
- // // [S3] 值板机
- // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
- // // [S5] Tray盘下料装备
- // /// 上位机心跳
- // /// 获取设备报警数据与状态信息
- // string stationCode = "[S5]";
- // string stationName = "Tray盘下料装备";
- // string stationNameStr = stationCode + stationName;
- // #region 创建字典
- // // 触发信号字典 赋值
- // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
- // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
- // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
- // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
- // // PLC数据字典 赋值
- // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
- // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
- // s5PLCData.Add("e1ProductSN_Check", ""); //
- // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
- // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
- // s5PLCData.Add("e1ProductSN", ""); // 产品SN
- // s5PLCData.Add("e1PartNo", ""); // 物料码
- // s5PLCData.Add("e1Result", 0); // 产品结果
- // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
- // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
- // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
- // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
- // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
- // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
- // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
- // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
- // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
- // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
- // #endregion 创建字典
- // while (IsRun)
- // {
- // try
- // {
- // if (!GlobalContext._IsCon_Funs5)
- // {
- // UpdatePLCMonitor(1, plcNo, 0);
- // continue;
- // }
- // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
- // {
- // Stopwatch stopwatch1 = new Stopwatch();
- // Stopwatch stopwatch2 = new Stopwatch();
- // stopwatch1.Start();
- // stopwatch2.Start();
- // #region 一次性读取所有数据
- // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
- // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
- // int[] datas = data1.Concat(data2).ToArray();
- // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
- // s5PLCData["e1MES_FLAG_Check"] = datas[3];
- // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
- // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
- // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
- // s5PLCData["e1MES_FLAG"] = datas[35];
- // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
- // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
- // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
- // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
- // s5PLCData["e1Result"] = datas[76];
- // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
- // s5PLCData["e1OEEMES_FLAG"] = datas[88];
- // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
- // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
- // s5PLCData["e1OEEType"] = datas[109];
- // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
- // s5PLCData["e1AGVUpStart"] = datas[121];
- // s5PLCData["e1AGVUpEnd"] = datas[122];
- // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
- // s5PLCData["e1AGVDownStart"] = datas[134];
- // s5PLCData["e1AGVDownEnd"] = datas[135];
- // #endregion 一次性读取所有数据
- // stopwatch2.Stop();
- // #region 回写操作,写后清空flag
- // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
- // #endregion 回写操作,写后清空flag
- // #region 进站校验
- // try
- // {
- // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
- // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
- // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
- // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
- // {
- // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
- // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
- // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
- // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 进站校验
- // #region 出站接口
- // try
- // {
- // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
- // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
- // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
- // if (e1PLC_FLAG != e1PLC_FLAGOld)
- // {
- // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
- // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
- // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
- // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 出站接口
- // #region 节拍接口
- // try
- // {
- // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
- // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
- // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
- // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
- // {
- // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
- // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
- // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
- // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
- // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 节拍接口
- // #region AGV上料
- // // AGV上料叫AGV信号
- // try
- // {
- // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
- // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
- // if (e1AGVUpCall != e1AGVUpCallOld)
- // {
- // if (e1AGVUpCall == 1) // 0->1
- // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
- // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // // AGV上料完成信号
- // try
- // {
- // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
- // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
- // if (e1AGVUpEnd != e1AGVUpEndOld)
- // {
- // if (e1AGVUpEnd == 1) // 0->1
- // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
- // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion AGV上料
- // #region AGV下料
- // // AGV下料叫agv信号
- // try
- // {
- // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
- // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
- // if (e1AGVDownCall != e1AGVDownCallOld)
- // {
- // if (e1AGVDownCall == 1) // 0->1
- // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
- // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // // AGV下料完成信号
- // try
- // {
- // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
- // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
- // if (e1AGVDownEnd != e1AGVDownEndOld)
- // {
- // if (e1AGVDownEnd == 1) // 0->1
- // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
- // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
- // }
- // }
- // catch (Exception ex)
- // {
- // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion AGV下料
- // #region 心跳
- // try
- // {
- // short states = 0;
- // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
- // }
- // catch (Exception ex)
- // {
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // }
- // #endregion 心跳
- // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
- // stopwatch1.Stop();
- // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
- // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
- // }
- // else
- // {
- // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
- // Funs[plcNo].Connect();
- // }
- // }
- // catch (Exception ex)
- // {
- // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
- // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
- // Funs[plcNo].ReConnect();
- // }
- // Thread.Sleep(IntervalReadPLC);
- // }
- //}
- /// <summary>
- /// [S5] Tray盘下料装备 - 进站校验
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S5进站校验(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
- sn = sn.Replace("\0", "");
- // 获取产品SN By 载具码
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
- writeToPLC_Flag1.Adress = 2003;
- writeToPLC_Flag1.Value = (short)6;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- string[] cavitySNs = cavityData.Split('.');
- string partNo = string.Empty;
- if (cavitySNs != null && cavitySNs.Length >= 1)
- partNo = cavitySNs[0];
- #endregion 查询载具上的产品信息
- // 产品SN(物料码)校验
- List<TestItem> item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = sn,
- });
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- });
- stopwatch2.Start();
- int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
- partNo, item, out string errorMsg);
- stopwatch2.Stop();
- short e1MES_FLAG_Check = (short)result;
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1MES_FLAG_Check";
- writeToPLC_Flag.Adress = 2003;
- writeToPLC_Flag.Value = e1MES_FLAG_Check;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // MES_Flag
- //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1MES_FLAG_Check";
- writeToPLC_Flag.Adress = 2003;
- writeToPLC_Flag.Value = (short)6;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S5] Tray盘下料装备 - 出站接口
- /// </summary>
- /// <param name="plcNo"></param>
- /// <param name="stationCode"></param>
- /// <param name="stationName"></param>
- private void S5出站接口(int plcNo, string stationCode, string stationName)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
- string stationNameStr = stationCode + stationName;
- string processItem = stationName; // 测试项目
- try
- {
- stopwatch1.Start();
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- //string batch_num = GlobalContext.BatchNumber; // 批次号
- string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
- //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
- string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
- sn = sn.Replace("\0", "");
- //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
- //partNo = partNo.Replace("\0", "");
- #region 查询载具上的产品信息
- string cavityData = string.Empty;
- int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
- if (string.IsNullOrEmpty(cavityData))
- cavityData = "";
- if (snResult != 0)
- {
- WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag1.Name = "e1MES_FLAG";
- writeToPLC_Flag1.Adress = 2035;
- writeToPLC_Flag1.Value = (short)4;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
- return;
- }
- string[] cavitySNs = cavityData.Split('.');
- string partNo = string.Empty;
- if (cavitySNs != null && cavitySNs.Length >= 1)
- partNo = cavitySNs[0];
- #endregion 查询载具上的产品信息
- int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
- bool pass = e1Result == 1;
- stopwatch2.Start();
- // 上传MES
- List<TestItem> items = new List<TestItem>();
- items.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = sn,
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = "1",
- Parameter_unit = ""
- });
- items.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = e1Result == 1 ? "OK" : "NG",
- Parameter_unit = ""
- });
- int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
- , workorder_code, mtltmrk, partNo, pass, sn, "1");
- //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
- short result = result1 == 1 ? (short)1 : (short)3;
- stopwatch2.Stop();
- #region 存储绑定数据到 边线MES系统中
- if (result == 1)
- {
- // 删除绑定信息
- int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
- if (resultMesR != 0)
- {
- result = 4;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
- }
- }
- #endregion 存储绑定数据到 边线MES系统中
- // MES_Flag 为MES报错
- // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1MES_FLAG";
- writeToPLC_Flag.Adress = 2035;
- writeToPLC_Flag.Value = result;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
- OnMessage(LogType.Debug,
- $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- stopwatch2.Restart();
- // MES_Flag 为4上位机报错
- //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1MES_FLAG";
- writeToPLC_Flag.Adress = 2035;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
- stopwatch2.Stop();
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S5] Tray盘下料装备 - 节拍接口
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- //private void S5节拍接口(int plcNo, string stationNameStr)
- //{
- // Stopwatch stopwatch1 = new Stopwatch();
- // Stopwatch stopwatch2 = new Stopwatch();
- // string resultStr = string.Empty;
- // try
- // {
- // stopwatch1.Start();
- // string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
- // string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
- // e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
- // bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
- // if (!actionBool)
- // {
- // stopwatch2.Start();
- // // MES_Flag
- // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
- // writeToPLC_Flag1.Adress = 2088;
- // writeToPLC_Flag1.Value = (short)4;
- // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
- // stopwatch2.Stop();
- // AddMessage(LogType.Info,
- // stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
- // "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
- // return;
- // }
- // string e1OEEPartNo = string.Empty; // 物料码
- // if (string.IsNullOrEmpty(e1OEEProductSN))
- // {
- // stopwatch2.Start();
- // // MES_Flag
- // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
- // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
- // writeToPLC_Flag1.Adress = 2088;
- // writeToPLC_Flag1.Value = (short)1;
- // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
- // stopwatch2.Stop();
- // AddMessage(LogType.Info,
- // stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- // stopwatch2.ElapsedMilliseconds + "ms");
- // return;
- // }
- // else
- // {
- // // 查产品SN
- // e1OEEPartNo = "Test"; // ZS
- // }
- // short e1OEEMES_FLAG = 0;
- // // 上传OEE
- // (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
- // e1OEEMES_FLAG = result.Item1;
- // resultStr = result.Item2;
- // stopwatch2.Start();
- // // MES_Flag
- // //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
- // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
- // writeToPLC_Flag.Adress = 2088;
- // writeToPLC_Flag.Value = e1OEEMES_FLAG;
- // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
- // stopwatch2.Stop();
- // }
- // catch (Exception ex)
- // {
- // string str = ex.StackTrace;
- // AddMessage_Station(stationNameStr, LogType.Error,
- // $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
- // str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // // MES_Flag
- // stopwatch2.Start();
- // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
- // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
- // writeToPLC_Flag.Adress = 2088;
- // writeToPLC_Flag.Value = (short)4;
- // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
- // stopwatch2.Stop();
- // }
- // stopwatch1.Stop();
- // AddMessage(LogType.Info,
- // stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- // stopwatch2.ElapsedMilliseconds + "ms");
- //}
- /// <summary>
- /// [S5] Tray盘下料装备 - AGV上料叫agv
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S5AGV上料叫agv(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 呼叫AGV
- short e1AGVUpCall = 2;
- stopwatch2.Start();
- // e1AGVUpCall
- //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVUpCall";
- writeToPLC_Flag.Adress = 2120;
- writeToPLC_Flag.Value = e1AGVUpCall;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // e1AGVUpCall
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVUpCall";
- writeToPLC_Flag.Adress = 2120;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S5] Tray盘下料装备 - AGV上料完成
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S5AGV上料完成(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS AGV上料完成,让小车离开
- short e1AGVUpEnd = 2;
- stopwatch2.Start();
- // e1AGVUpEnd
- //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVUpEnd";
- writeToPLC_Flag.Adress = 2122;
- writeToPLC_Flag.Value = e1AGVUpEnd;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // e1AGVUpEnd
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVUpEnd";
- writeToPLC_Flag.Adress = 2122;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S5] Tray盘下料装备 - AGV下料叫agv
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S5AGV下料叫agv(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS 呼叫AGV
- short e1AGVDownCall = 2;
- stopwatch2.Start();
- // e1AGVDownCall
- //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVDownCall";
- writeToPLC_Flag.Adress = 2133;
- writeToPLC_Flag.Value = e1AGVDownCall;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // e1AGVDownCall
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVDownCall";
- writeToPLC_Flag.Adress = 2133;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- /// <summary>
- /// [S5] Tray盘下料装备 - AGV下料完成
- /// </summary>
- /// <param name="plcNo">PLC编号</param>
- /// <param name="stationNameStr">工站全称</param>
- private void S5AGV下料完成(int plcNo, string stationNameStr)
- {
- Stopwatch stopwatch1 = new Stopwatch();
- Stopwatch stopwatch2 = new Stopwatch();
- try
- {
- stopwatch1.Start();
- // ZS AGV上料完成,让小车离开
- short e1AGVDownEnd = 2;
- stopwatch2.Start();
- // e1AGVDownEnd
- //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVDownEnd";
- writeToPLC_Flag.Adress = 2135;
- writeToPLC_Flag.Value = e1AGVDownEnd;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- // e1AGVDownEnd
- stopwatch2.Start();
- //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
- WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
- writeToPLC_Flag.Name = "e1AGVDownEnd";
- writeToPLC_Flag.Adress = 2135;
- writeToPLC_Flag.Value = (short)4;
- SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
- stopwatch2.Stop();
- }
- stopwatch1.Stop();
- AddMessage(LogType.Info,
- stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
- stopwatch2.ElapsedMilliseconds + "ms");
- }
- #endregion [S5] Tray盘下料装备
- #endregion PLC5 张超凡
- #region 缓存读取到的PLC数据 与 需要写入的PLC数据
- /// <summary>
- /// PLC读取到的数据 -添加数据
- /// </summary>
- public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
- {
- if (sxPlcData.ContainsKey(newKey))
- sxPlcData[newKey] = newValue;
- else
- sxPlcData.Add(newKey, newValue);
- }
- /// <summary>
- /// PLC需要写入的数据 -添加数据
- /// </summary>
- public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey,
- WriteToPLC_Flag newValue)
- {
- if (sxPLCWriteData.ContainsKey(newKey))
- sxPLCWriteData[newKey] = newValue;
- else
- sxPLCWriteData.Add(newKey, newValue);
- }
- /// <summary>
- /// PLC回写操作,写后清空flag
- /// </summary>
- /// <param name="modbusClient">modbus对象</param>
- /// <param name="pLCReadDatas">读取到的数据字典</param>
- /// <param name="pLCWriteDatas">需要写入的数据</param>
- public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas,
- ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
- {
- if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
- {
- List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
- for (int i = 0; i < pLCWriteDatas.Count; i++)
- {
- string mesFlagName = pLCWriteDatas[i].Name;
- int mesFlagAdress = pLCWriteDatas[i].Adress;
- short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
- if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
- {
- // 先回写数据
- List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
- for (int j = 0; j < writeToPLCDatas.Count; j++)
- {
- int mesDataAdress = writeToPLCDatas[j].Adress;
- PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
- switch (mesDataType)
- {
- case PLCValueType.Short:
- short mesDataValueShort = (short)writeToPLCDatas[j].Value;
- modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
- break;
- case PLCValueType.String:
- string mesDataValueStr = (string)writeToPLCDatas[j].Value;
- int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
- modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr,
- mesDataValueStrLength);
- break;
- }
- }
- // 再回写信号
- modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
- // 存储读取数据的字典
- pLCReadDatas[mesFlagName] = (int)mesFlagValue;
- // 存储写入数据的字典 - 清空写入值
- pLCWriteDatas[i].Value = (short)0;
- pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
- }
- }
- }
- }
- /// <summary>
- /// 提交点检数据到MES - 取数据库中缓存的 点检数据
- /// </summary>
- /// <param name="no">3</param>
- /// <param name="stationCode">设备编号</param>
- /// <param name="stationNameStr">设备名称</param>
- /// <param name="plcOrder">车间订单号</param>
- private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
- {
- try
- {
- /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
- /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
- /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
- /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
- int result1 = 0;
- switch (stationCode)
- {
- case 2:
- case 3:
- case 4:
- case 6:
- result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
- break;
- case 102:
- result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
- break;
- case 103:
- result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
- break;
- case 104:
- result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
- break;
- case 106:
- result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
- break;
- default:
- // MES_Flag 为“6未找到正确设备编号”
- Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
- AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
- return;
- }
- short result = result1 == 1 ? (short)1 : (short)2;
- Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
- OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
- }
- catch (Exception ex)
- {
- // MES_Flag 为2上位机报错
- Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
- string str = ex.StackTrace;
- AddMessage_Station(stationNameStr, LogType.Error,
- $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
- str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
- }
- }
- #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
- #region UI刷新
- /// <summary>
- /// 更新商品信息的UI + 下发产品信息(SN)
- /// </summary>
- private void UpdateProductInfo()
- {
- currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
- currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
- //currentBN.Text = GlobalContext.BatchNumber; // 批次号
- //txt_CurSupplierCode.Text = ""; // 供应商代号
- }
- /// <summary>
- /// 更新PLC连接状态的UI
- /// </summary>
- /// <param name="no">PLC编号</param>
- /// <param name="status">状态</param>
- private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
- {
- if (this != null && !this.IsDisposed)
- {
- switch (imgNo)
- {
- case 1:
- this.BeginInvoke(new Action(() => { picPLC.Image = imageListState.Images[status]; }));
- break;
- case 2:
- this.BeginInvoke(new Action(() => { pictureBox2.Image = imageListState.Images[status]; }));
- break;
- case 3:
- this.BeginInvoke(new Action(() => { pictureBox3.Image = imageListState.Images[status]; }));
- break;
- case 4:
- this.BeginInvoke(new Action(() => { pictureBox4.Image = imageListState.Images[status]; }));
- break;
- case 5:
- this.BeginInvoke(new Action(() => { pictureBox5.Image = imageListState.Images[status]; }));
- break;
- case 6:
- this.BeginInvoke(new Action(() => { pictureBox6.Image = imageListState.Images[status]; }));
- break;
- case 7:
- this.BeginInvoke(new Action(() => { pictureBox7.Image = imageListState.Images[status]; }));
- break;
- case 8:
- this.BeginInvoke(new Action(() => { pictureBox8.Image = imageListState.Images[status]; }));
- break;
- default:
- break;
- }
- }
- Task.Run(() => // 更新PLC交互页的指示灯
- {
- try
- {
- if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
- {
- Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
- }
- }
- catch
- {
- }
- });
- }
- #endregion UI刷新
- #region 日志
- /// <summary>
- /// 添加各工位运行日志(同步至PLC交互页面)
- /// </summary>
- /// <param name="stationNameStr">工站名称</param>
- /// <param name="logType">日志类型</param>
- /// <param name="message">日志内容</param>
- /// <param name="snNumber">产品数字SN</param>
- public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
- {
- if (!(stationNameStr.Equals("获取设备报警数据与状态信息")))
- {
- AddMessage(logType, message); // 首页展示+日志记录
- }
- PLCDBFormMessage plcMessage = new PLCDBFormMessage()
- {
- StationName = stationNameStr,
- SnNumber = snNumber,
- Message = message,
- CreateTime = DateTime.Now
- };
- // PLC交互页展示
- Task.Run(() =>
- {
- try
- {
- if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
- {
- Form_Main.formPLCDB.UpdateMessage(plcMessage);
- }
- }
- catch
- {
- }
- });
- }
- /// <summary>
- /// 添加运行日志
- /// </summary>
- /// <param name="logType">日志类型</param>
- /// <param name="message">日志内容</param>
- public void AddMessage(LogType logType, string message)
- {
- OnMessage(logType, message);
- string date = DateTime.Now.ToString("yyyy/MM/dd");
- string time = DateTime.Now.ToString("HH:mm:ss:fff");
- string msgShow = time + "--> " + message + "\r\n";
- this.BeginInvoke(new Action(() =>
- {
- systemLog.Rows.Insert(0, date, time, message);
- if (systemLog.Rows.Count >= 100)
- systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
- }));
- }
- /// <summary>
- /// 添加运行日志-保存
- /// </summary>
- /// <param name="logType">日志类型</param>
- /// <param name="message">日志内容</param>
- private void OnMessage(LogType logType, string msg)
- {
- MessageEvent?.Invoke(logType, msg);
- }
- /// <summary>
- /// 保存PLC写入日志
- /// </summary>
- /// <param name="logType"></param>
- /// <param name="logValue"></param>
- private void WritePLCLog(LogType logType, string logValue)
- {
- switch ((int)logType)
- {
- case 0:
- _PLCLogNet.WriteDebug(logValue);
- break;
- case 1:
- _PLCLogNet.WriteInfo(logValue);
- break;
- case 2:
- _PLCLogNet.WriteWarn(logValue);
- break;
- case 3:
- _PLCLogNet.WriteError(logValue);
- break;
- default:
- _PLCLogNet.WriteFatal(logValue);
- break;
- }
- }
- /// <summary>
- /// IOT Mqtt回调方法- With DataId
- /// </summary>
- /// <param name="id"></param>
- /// <param name="v"></param>
- /// <param name="dataId"></param>
- public void CallbackWithDataId(string id, string msg, string dataId)
- {
- //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
- //byte[] buffer1 = Encoding.Default.GetBytes(v);
- //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
- //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
- //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
- string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
- _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
- }
- /// <summary>
- /// AGV Mqtt回调方法- 记录Log并处理数据
- /// </summary>
- /// <param name="obj"></param>
- private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
- {
- string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
- _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
- // 接收到的信息
- string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
- string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
- if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
- {
- }
- }
- #endregion 日志
- //private void button1_Click(object sender, EventArgs e)
- //{
- // OpenDailogFalg=true;
- // if (OpenDailogFalg)
- // {
- // using (var dialog = new BandBarodeDialog())
- // {
- // string strCarrierBarcode = "N801A-003";
- // dialog._CarrierBarcode = strCarrierBarcode;
- // string sn = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
- // dialog._ProductBarcode = sn;
- // var rs = dialog.ShowDialog();
- // if (rs == DialogResult.OK)
- // {
- // AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
- // OpenDailogFalg = false;//关闭扫码
- // }
- // }
- // }
- //}
- }
- }
|