Form_Home.cs 769 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. //using System.Text;
  8. using Microsoft.Win32;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using HslCommunication.LogNet;
  13. using MainForm.FaForm;
  14. using Sunny.UI;
  15. using MainForm.ClassFile.XiaomiAPI;
  16. using System.Diagnostics;
  17. using MainForm.Models;
  18. using SqlSugar;
  19. using EasyModbus;
  20. using ModBusClientSimple.Util;
  21. using csharp_networkprotocol_hpsocket;
  22. using MqttnetServerWin;
  23. using Sunny.UI.Win32;
  24. using MainForm.ClassFile.XiaomiAPI_AGV;
  25. using MainForm.ClassFile.XiaomiAPI_RouteCom;
  26. using HslCommunication.Controls;
  27. using EIP_Protocol;
  28. using MainForm.ClassFile.XiaomiAPI_MES;
  29. using NPOI.Util;
  30. using static MainForm.SQLHelper;
  31. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
  32. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
  33. using MainForm.ClassFile.ProjectClass;
  34. using CommonLib;
  35. using Org.BouncyCastle.Asn1.IsisMtt;
  36. using System.Web.Services.Description;
  37. using System.Numerics;
  38. using MathNet.Numerics.RootFinding;
  39. using HslCommunication.Enthernet;
  40. using BZFAStandardLib;
  41. using MainForm.ClassFile;
  42. using NPOI.SS.Formula.Functions;
  43. using static MainForm.ClassFile.XiaomiAPI.XiaomiMqttClient_Extend;
  44. using System.Net.Http;
  45. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_UpLoadFile;
  46. using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
  47. using System.Reflection;
  48. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
  49. using FaFrameUI;
  50. using System.Security.Policy;
  51. using static MainForm.ClassFile.XiaomiClass.MesHelper;
  52. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
  53. using System.Drawing.Imaging;
  54. using System.Drawing;
  55. using ICSharpCode.SharpZipLib.Zip;
  56. using System.Text.RegularExpressions;
  57. /*
  58. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  59. */
  60. namespace MainForm
  61. {
  62. /// <summary>
  63. /// 记录日志的委托
  64. /// </summary>
  65. /// <param name="logType">日志类型</param>
  66. /// <param name="message">日志信息</param>
  67. public delegate void HomeMessageHandler(LogType logType, string message);
  68. /// <summary>
  69. /// 主页窗体
  70. /// </summary>
  71. public partial class Form_Home : Form
  72. {
  73. #region 常量
  74. //文本常量
  75. private const string Head = "开始采集";
  76. private const string Tail = "采集完成";
  77. private const string Body = "工位出站数据";
  78. private const string BodyCheck = "工位点检数据";
  79. private const string BodyRun = "整线运行数据";
  80. private const string BodyAlarm = "整线报警数据";
  81. #endregion 常量
  82. #region 变量
  83. /// <summary>
  84. /// 委托-记录日志的方法
  85. /// </summary>
  86. public event HomeMessageHandler MessageEvent;
  87. /// <summary>
  88. /// 日志接口
  89. /// </summary>
  90. ILogNet _PLCLogNet;
  91. /// <summary>
  92. /// 用于记录IOT MQTT日志
  93. /// </summary>
  94. ILogNet _IOTMqttLogNet;
  95. /// <summary>
  96. /// 用于记录AGV MQTT日志
  97. /// </summary>
  98. ILogNet _AGVMqttLogNet;
  99. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  100. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  101. // 间隔时间
  102. private int IntervalReadPLC = 300; //ms 读PLC
  103. private int IntervalMonitorMES = 1000; //ms MES心跳
  104. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  105. /// <summary>
  106. /// 设备报警数据
  107. /// </summary>
  108. uint[] _FaultDatas = { };
  109. uint[] _FaultDatas_Old = { };
  110. uint[] _FaultDatas2 = { };
  111. uint[] _FaultDatas_Old2 = { };
  112. // 软件状态
  113. private bool IsRun = true;
  114. #region PLC 与 TCP对象
  115. // 定义一个字典,存plc对象(通讯)
  116. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  117. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  118. // 定义TCPClient对象列表
  119. Dictionary<int, HPSocket_TcpClientHelper>
  120. _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  121. // 定义MQTTHelper对象
  122. MQTTHelper _MQTTHelper = new MQTTHelper();
  123. #endregion PLC 与 TCP对象
  124. /// <summary>
  125. /// 上次的设备运行信息
  126. /// </summary>
  127. private string lineWorkingData1_OldStr = string.Empty;
  128. /// <summary>
  129. /// 设备报警字典-当前结果
  130. /// Dictionary<工位代码,List<报警信息>>
  131. /// </summary>
  132. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  133. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  134. /// <summary>
  135. /// 单机用-设备状态
  136. /// </summary>
  137. //XiaomiDeviceState xmDeviceState = XiaomiDeviceState.Uninitialized;
  138. XiaomiDeviceStateData xmDeviceStateData = new XiaomiDeviceStateData();
  139. private int test_item_num = 0; //iot 过站数据序号
  140. public static string uuid = "";
  141. private bool inpass = false; //保存进站测试状态
  142. public static XiaoMiParm xiaomiParm = new XiaoMiParm();
  143. //记录上传附件的信息
  144. public static FileUpload_FileData fileUploadData = new FileUpload_FileData();
  145. #endregion 变量
  146. #region 窗体基础事件
  147. /// <summary>
  148. /// 初始化
  149. /// </summary>
  150. public Form_Home()
  151. {
  152. InitializeComponent();
  153. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  154. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  155. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  156. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  157. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  158. }
  159. /// <summary>
  160. /// 窗体加载事件
  161. /// </summary>
  162. public void Form_Home_Load(object sender, EventArgs e)
  163. {
  164. try
  165. {
  166. AddMessage(LogType.Info, "开始初始化程序");
  167. //组建plc对象字典
  168. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  169. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  170. if (GlobalContext.IsUsePLC1)
  171. {
  172. GlobalContext.IsUsePLCNow = 1;
  173. GlobalContext.IsUseStationName = "[OP10]壳体清洁上料";
  174. FunsEip.Add(GlobalContext.IsUsePLCNow,
  175. new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  176. }
  177. if (GlobalContext.IsUsePLC2)
  178. {
  179. GlobalContext.IsUsePLCNow = 2;
  180. GlobalContext.IsUseStationName = "[OP20]上盖板上料装备";
  181. FunsEip.Add(GlobalContext.IsUsePLCNow,
  182. new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  183. }
  184. if (GlobalContext.IsUsePLC3)
  185. {
  186. GlobalContext.IsUsePLCNow = 3;
  187. GlobalContext.IsUseStationName = "[OP30]点散热胶装备";
  188. FunsEip.Add(GlobalContext.IsUsePLCNow,
  189. new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  190. }
  191. if (GlobalContext.IsUsePLC4)
  192. {
  193. GlobalContext.IsUsePLCNow = 4;
  194. GlobalContext.IsUseStationName = "[OP40]胶线检测";
  195. FunsEip.Add(GlobalContext.IsUsePLCNow,
  196. new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  197. }
  198. if (GlobalContext.IsUsePLC5)
  199. {
  200. GlobalContext.IsUsePLCNow = 5;
  201. GlobalContext.IsUseStationName = "[OP50]ADD板上料组装装备";
  202. FunsEip.Add(GlobalContext.IsUsePLCNow,
  203. new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  204. }
  205. if (GlobalContext.IsUsePLC6)
  206. {
  207. GlobalContext.IsUsePLCNow = 6;
  208. GlobalContext.IsUseStationName = "[OP70]组上盖板";
  209. FunsEip.Add(GlobalContext.IsUsePLCNow,
  210. new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  211. }
  212. if (GlobalContext.IsUsePLC7)
  213. {
  214. GlobalContext.IsUsePLCNow = 7;
  215. GlobalContext.IsUseStationName = "[OP80]上盖板锁螺丝";
  216. FunsEip.Add(GlobalContext.IsUsePLCNow,
  217. new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  218. }
  219. if (GlobalContext.IsUsePLC8)
  220. {
  221. GlobalContext.IsUsePLCNow = 8;
  222. GlobalContext.IsUseStationName = "[OP90]NG下料";
  223. FunsEip.Add(GlobalContext.IsUsePLCNow,
  224. new Inovance_EIP(GlobalContext.PC8Address,
  225. GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  226. }
  227. if (GlobalContext.IsUsePLC9)
  228. {
  229. GlobalContext.IsUsePLCNow = 9;
  230. GlobalContext.IsUseStationName = "[OP100]半成品下料";
  231. FunsEip.Add(GlobalContext.IsUsePLCNow,
  232. new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  233. }
  234. (bool, string) DicResult = InitalDicAlarm(); // 实例化报警字典
  235. AddMessage(LogType.Info, DicResult.Item2);
  236. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  237. {
  238. if (plcEIP != null)
  239. {
  240. try
  241. {
  242. (int, string) result = plcEIP.Connect();
  243. }
  244. catch (Exception ex)
  245. {
  246. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  247. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
  248. MessageBoxOptions.ServiceNotification);
  249. }
  250. }
  251. }
  252. // 采集任务
  253. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  254. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  255. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  256. if (GlobalContext.IsUsePLC1)
  257. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  258. if (GlobalContext.IsUsePLC2)
  259. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  260. if (GlobalContext.IsUsePLC3)
  261. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  262. if (GlobalContext.IsUsePLC4)
  263. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  264. if (GlobalContext.IsUsePLC5)
  265. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  266. if (GlobalContext.IsUsePLC6)
  267. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  268. if (GlobalContext.IsUsePLC7)
  269. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  270. if (GlobalContext.IsUsePLC8)
  271. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  272. if (GlobalContext.IsUsePLC9)
  273. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  274. #region 初始化
  275. try
  276. {
  277. // 开启MES(Http)
  278. if (GlobalContext.IsUseMES)
  279. {
  280. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  281. if (mesret)
  282. {
  283. picMESStatus.Image = imageListState.Images[1];
  284. GlobalContext.MESIsConnect = true;
  285. AddMessage(LogType.Info, "小米MES初始连接成功!");
  286. }
  287. else
  288. {
  289. picMESStatus.Image = imageListState.Images[0];
  290. GlobalContext.MESIsConnect = false;
  291. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  292. }
  293. }
  294. // 开启IOT(MQTT)
  295. if (GlobalContext.IsUseIot)
  296. {
  297. string addr = GlobalContext.MQTTServerHost;
  298. int port = GlobalContext.MQTTServerPort;
  299. //生产环境需要修改
  300. (int, string) qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666,
  301. GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  302. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult.Item1;
  303. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  304. {
  305. picIot.Image = imageListState.Images[1];
  306. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  307. // 设置回调函数
  308. //XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  309. // 配置参数
  310. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  311. // fds
  312. param.parameter.fds.address = GlobalContext.address;
  313. param.parameter.fds.appId = GlobalContext.appId;
  314. param.parameter.fds.appKey = GlobalContext.appKey;
  315. // mes
  316. param.parameter.mes.address = GlobalContext.ServerIp;
  317. param.parameter.mes.appId = GlobalContext.MESAppId;
  318. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  319. // mqtt
  320. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  321. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  322. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  323. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  324. // 设备配置
  325. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  326. if (GlobalContext.IsUsePLC1)
  327. {
  328. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  329. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  330. xiaomiParm.workstation = GlobalContext.S1_work_station; //工站
  331. }
  332. if (GlobalContext.IsUsePLC2)
  333. {
  334. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  335. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  336. xiaomiParm.workstation = GlobalContext.S2_work_station; //工站
  337. }
  338. if (GlobalContext.IsUsePLC3)
  339. {
  340. param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
  341. //param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
  342. }
  343. if (GlobalContext.IsUsePLC4)
  344. {
  345. param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
  346. param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
  347. xiaomiParm.workstation = GlobalContext.s4_work_station; //工站
  348. }
  349. if (GlobalContext.IsUsePLC5)
  350. {
  351. param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
  352. param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
  353. xiaomiParm.workstation = GlobalContext.s5_work_station; //工站
  354. }
  355. if (GlobalContext.IsUsePLC6)
  356. {
  357. param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
  358. param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
  359. xiaomiParm.workstation = GlobalContext.s6_work_station; //工站
  360. }
  361. if (GlobalContext.IsUsePLC7)
  362. {
  363. param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  364. //param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  365. xiaomiParm.stationCode = GlobalContext.s7_1_station;
  366. }
  367. if (GlobalContext.IsUsePLC8)
  368. {
  369. param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
  370. param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
  371. xiaomiParm.workstation = GlobalContext.s8_work_station; //工站
  372. }
  373. if (GlobalContext.IsUsePLC9)
  374. {
  375. param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
  376. param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
  377. xiaomiParm.workstation = GlobalContext.s9_work_station; //工站
  378. }
  379. param.parameter.equipment.project = GlobalContext.Project_Code;
  380. param.parameter.equipment.productMode = "debug";
  381. param.parameter.other.logLevel = 0;
  382. param.parameter.other.LogPath = GlobalContext.MqttLogDir;
  383. XiaomiMqttClient_Extend.ParameterConfig(param);
  384. //保存全局变量
  385. xiaomiParm.stationCode = param.parameter.equipment.stationCode;
  386. xiaomiParm.deviceCode = param.parameter.equipment.deviceCode;
  387. }
  388. else
  389. {
  390. picIot.Image = imageListState.Images[0];
  391. AddMessage(LogType.Info,
  392. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  393. }
  394. }
  395. // 开启AGV(Http与MQTT)
  396. if (GlobalContext.IsUseAGV)
  397. {
  398. // AGV HTTP
  399. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  400. if (mesret1)
  401. {
  402. picAgvHttp.Image = imageListState.Images[1];
  403. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  404. }
  405. else
  406. {
  407. picAgvHttp.Image = imageListState.Images[0];
  408. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  409. }
  410. string agvMqttIp = GlobalContext.MQTTServerHost;
  411. int agvMqttPort = GlobalContext.MQTTServerPort;
  412. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  413. ResultData_MQTT result_MQTT = _MQTTHelper
  414. .CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  415. // AGV MQTT
  416. if (result_MQTT.ResultCode == 1)
  417. {
  418. picAgvMqtt.Image = imageListState.Images[1];
  419. GlobalContext.AGVMQTTIsConnect = true;
  420. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  421. ResultData_MQTT result =
  422. XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  423. AddMessage(LogType.Info,
  424. $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  425. }
  426. else
  427. {
  428. picAgvMqtt.Image = imageListState.Images[0];
  429. GlobalContext.AGVMQTTIsConnect = false;
  430. AddMessage(LogType.Info,
  431. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  432. }
  433. }
  434. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  435. Task.Run(MonitorMESConnect);
  436. // 查询PLC连接状态
  437. foreach (int plcNo in FunsEip.Keys)
  438. {
  439. bool connected = FunsEip[plcNo].IsConnected;
  440. if (connected)
  441. {
  442. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  443. AddMessage(LogType.Info, msg);
  444. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  445. }
  446. else
  447. {
  448. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  449. AddMessage(LogType.Info, msg);
  450. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  451. }
  452. }
  453. // PLC4时 初始化扫码器TCP
  454. //if (GlobalContext.IsUsePLC4)
  455. // HpTCPClientInit();
  456. // 开启PLC的业务处理线程-监听PLC点位+状态
  457. foreach (Task task in TaskReadProcess)
  458. {
  459. if (task != null)
  460. task.Start();
  461. }
  462. //// 开启iot的线程
  463. TaskReadAlarm.Start();
  464. ////下传MES信息给1工位(先判断下plc对象数量)
  465. //if (Funs.Count > 1)
  466. // DownLoadProductInfo(1);
  467. if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  468. {
  469. state_l.Text = "设备状态(左):";
  470. state_r.Text = "设备状态(右):";
  471. state_r.Visible = true;
  472. lblDeviceStates2.Visible = true;
  473. }
  474. //上传操作记录
  475. operateToIot("startup", "开启");
  476. AddMessage(LogType.Info, "程序初始化完成");
  477. }
  478. catch (Exception ex)
  479. {
  480. string str = ex.StackTrace;
  481. this.BeginInvoke(new Action(() =>
  482. {
  483. AddMessage(LogType.Error,
  484. "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  485. str.Length - str.LastIndexOf("\\") - 1));
  486. }));
  487. }
  488. #endregion
  489. }
  490. catch (Exception ex)
  491. {
  492. string str = ex.StackTrace;
  493. OnMessage(LogType.Info,
  494. "主窗体的首页初始化出错!异常位置:" +
  495. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" +
  496. ex.Message.ToString());
  497. if (ex.Message != null && ex.Message.Contains("timed out"))
  498. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  499. else
  500. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  501. }
  502. }
  503. /// <summary>
  504. /// 窗体关闭事件
  505. /// </summary>
  506. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  507. {
  508. Closed2();
  509. }
  510. public void Closed2()
  511. {
  512. try
  513. {
  514. IsRun = false;
  515. Thread.Sleep(IntervalReadPLC);
  516. // 断开TCP
  517. int count = _HPSocket_TcpClients.Count();
  518. for (int i = 0; i < count; i++)
  519. {
  520. try
  521. {
  522. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  523. {
  524. _HPSocket_TcpClients[i].Stop();
  525. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  526. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  527. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  528. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  529. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  530. }
  531. }
  532. catch
  533. {
  534. }
  535. }
  536. // 关闭Iot
  537. try
  538. {
  539. XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath,
  540. GlobalContext.MqttServerName);
  541. }
  542. catch
  543. {
  544. }
  545. // 关闭AGV Mqtt
  546. try
  547. {
  548. _MQTTHelper.DisconnectAsync_Client().Wait();
  549. }
  550. catch
  551. {
  552. }
  553. }
  554. catch
  555. {
  556. }
  557. }
  558. #endregion 窗体基础事件
  559. #region 监控MES状态
  560. /// <summary>
  561. /// 监控MES连接状态
  562. /// </summary>
  563. private void MonitorMESConnect()
  564. {
  565. while (IsRun) // 运行被控线程
  566. {
  567. try
  568. {
  569. // 开启MES(Http)
  570. if (GlobalContext.IsUseMES)
  571. {
  572. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  573. if (mesret)
  574. {
  575. picMESStatus.Image = imageListState.Images[1];
  576. GlobalContext.MESIsConnect = true;
  577. }
  578. else
  579. {
  580. picMESStatus.Image = imageListState.Images[0];
  581. GlobalContext.MESIsConnect = false;
  582. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  583. }
  584. }
  585. // 开启IOT(MQTT)
  586. if (GlobalContext.IsUseIot)
  587. {
  588. bool iIot = XiaomiMqttClient.IsOpen;
  589. if (iIot)
  590. picIot.Image = imageListState.Images[1];
  591. else
  592. {
  593. picIot.Image = imageListState.Images[0];
  594. OnMessage(LogType.Info,
  595. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  596. }
  597. }
  598. // 开启AGV(Http与MQTT)
  599. if (GlobalContext.IsUseAGV)
  600. {
  601. // AGV Http
  602. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  603. if (mesret1)
  604. picAgvHttp.Image = imageListState.Images[1];
  605. else
  606. {
  607. picAgvHttp.Image = imageListState.Images[0];
  608. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  609. }
  610. // AGV MQTT
  611. if (GlobalContext.AGVMQTTIsConnect)
  612. picAgvMqtt.Image = imageListState.Images[1];
  613. else
  614. {
  615. picAgvMqtt.Image = imageListState.Images[0];
  616. OnMessage(LogType.Info,
  617. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  618. }
  619. }
  620. }
  621. catch (Exception ex)
  622. {
  623. string str = ex.StackTrace;
  624. AddMessage(LogType.Error,
  625. "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  626. str.Length - str.LastIndexOf("\\") - 1));
  627. }
  628. Thread.Sleep(IntervalMonitorMES);
  629. }
  630. }
  631. #endregion 监控MES连接状态
  632. #region 采集设备状态、运行数据、报警数据
  633. /// <summary>
  634. /// 请求设备状态 5000
  635. /// </summary>
  636. /// <param name="no">1</param>
  637. /// <param name="stationNameStr"></param>
  638. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  639. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  640. {
  641. try
  642. {
  643. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  644. {
  645. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  646. return result;
  647. }
  648. else
  649. {
  650. return 0;
  651. }
  652. }
  653. catch (Exception ex)
  654. {
  655. string str = ex.StackTrace;
  656. AddMessage_Station(stationNameStr, LogType.Error,
  657. "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  658. str.Length - str.LastIndexOf("\\") - 1));
  659. return 0;
  660. }
  661. }
  662. /// <summary>
  663. /// 检查是否可采集点检数据 - 不取新值
  664. /// 5000不为1时可点检
  665. /// </summary>
  666. /// <returns></returns>
  667. public bool CheckCanSpotcheck1(int deviceState)
  668. {
  669. //return true;
  670. //D5000 = 1,代表设备控制状态处于运行状态
  671. //D5000 = 2, 代表设备控制状态处于故障状态
  672. //D5000 = 3,代表设备控制状态处于缺料状态
  673. //D5000 = 4, 代表设备控制状态处于待机状态
  674. //D5000 = 5,代表设备控制状态处于维修状态
  675. return deviceState != 1;
  676. }
  677. /// <summary>
  678. /// 检查是否可采集产品数据 - 不取新值
  679. /// </summary>
  680. /// <returns></returns>
  681. public bool CheckCanCollData(int deviceState)
  682. {
  683. return deviceState == 0; // 点检时该值不为0
  684. }
  685. /// <summary>
  686. /// 采集到的设备状态
  687. /// </summary>
  688. private string _DeviceStates = "未知状态";
  689. private string _DeviceStates_Old = "未知状态";
  690. private string _DeviceStates2 = "未知状态";
  691. private string _DeviceStates_Old2 = "未知状态";
  692. /// <summary>
  693. /// 获取设备报警数据与获取设备运行信息
  694. /// </summary>
  695. private async void ReadAlarmAllPLC()
  696. {
  697. /// 获取设备报警数据与状态信息
  698. string stationNameStr = "获取设备报警数据与状态信息";
  699. // 已连接到PLC
  700. while (IsRun)
  701. {
  702. try
  703. {
  704. #region 报警数据
  705. try
  706. {
  707. //_FaultDatas = new uint[] { 4, 0, 30, 10 };
  708. if (_FaultDatas.Length > 0)
  709. {
  710. ReadPLCAlarmToIot(_FaultDatas, _FaultDatas_Old, stationNameStr);
  711. }
  712. else
  713. {
  714. AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!");
  715. }
  716. if (_FaultDatas2.Length > 0)
  717. {
  718. ReadPLCAlarmToIot(_FaultDatas2, _FaultDatas_Old2, stationNameStr);
  719. }
  720. else
  721. {
  722. AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!");
  723. }
  724. }
  725. catch (Exception ex)
  726. {
  727. string str = ex.StackTrace;
  728. AddMessage_Station(stationNameStr, LogType.Error,
  729. $"【报警日志】{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" +
  730. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  731. }
  732. #endregion 报警数据
  733. #region 设备状态
  734. //if (!GlobalContext._IsCon_plc1Alarm)
  735. //{
  736. // UpdatePLCMonitor(1, -2, 0);
  737. // continue;
  738. //}
  739. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  740. {
  741. if (plcEIP != null)
  742. {
  743. if (plcEIP.IsConnected)
  744. {
  745. #region 主页展示设备运行状态并上传到IOT中,有双工位left就是左工位,没有双工位left就是单工位
  746. switch (xmDeviceStateData.left)
  747. {
  748. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  749. _DeviceStates = "未初始化状态";
  750. lblDeviceStates.Text = _DeviceStates;
  751. break;
  752. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  753. _DeviceStates = "初始化状态";
  754. lblDeviceStates.Text = _DeviceStates;
  755. break;
  756. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  757. _DeviceStates = "初始化完成状态";
  758. lblDeviceStates.Text = _DeviceStates;
  759. break;
  760. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  761. _DeviceStates = "运行状态";
  762. lblDeviceStates.Text = _DeviceStates;
  763. break;
  764. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  765. _DeviceStates = "暂停状态";
  766. lblDeviceStates.Text = _DeviceStates;
  767. break;
  768. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  769. _DeviceStates = "故障状态";
  770. lblDeviceStates.Text = _DeviceStates;
  771. break;
  772. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  773. _DeviceStates = "警报状态";
  774. lblDeviceStates.Text = _DeviceStates;
  775. break;
  776. }
  777. if (!_DeviceStates.Equals(_DeviceStates_Old))
  778. {
  779. var iotResult =
  780. SaveDeviceStateData(stationNameStr, xmDeviceStateData.left, "left"); // 上传+保存
  781. if (iotResult.Item1 == 1)
  782. {
  783. _DeviceStates_Old = _DeviceStates;
  784. AddMessage_Station(stationNameStr, LogType.Info,
  785. "【设备状态】" + stationNameStr + $"_上传设备状态到Iot成功!");
  786. }
  787. else
  788. AddMessage_Station(stationNameStr, LogType.Info,
  789. "【设备状态】" + stationNameStr +
  790. $"_上传设备状态到Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  791. }
  792. #endregion 主页展示设备运行状态并上传到IOT中
  793. #region 右工位
  794. if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  795. {
  796. switch (xmDeviceStateData.right)
  797. {
  798. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  799. _DeviceStates2 = "未初始化状态";
  800. lblDeviceStates.Text = _DeviceStates2;
  801. break;
  802. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  803. _DeviceStates2 = "初始化状态";
  804. lblDeviceStates.Text = _DeviceStates2;
  805. break;
  806. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  807. _DeviceStates2 = "初始化完成状态";
  808. lblDeviceStates.Text = _DeviceStates2;
  809. break;
  810. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  811. _DeviceStates2 = "运行状态";
  812. lblDeviceStates.Text = _DeviceStates2;
  813. break;
  814. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  815. _DeviceStates2 = "暂停状态";
  816. lblDeviceStates.Text = _DeviceStates2;
  817. break;
  818. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  819. _DeviceStates2 = "故障状态";
  820. lblDeviceStates.Text = _DeviceStates2;
  821. break;
  822. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  823. _DeviceStates2 = "警报状态";
  824. lblDeviceStates.Text = _DeviceStates2;
  825. break;
  826. }
  827. if (!_DeviceStates2.Equals(_DeviceStates_Old2))
  828. {
  829. var iotResult = SaveDeviceStateData(stationNameStr, xmDeviceStateData.left,
  830. "right"); // 上传+保存
  831. if (iotResult.Item1 == 1)
  832. {
  833. _DeviceStates_Old2 = _DeviceStates2;
  834. AddMessage_Station(stationNameStr, LogType.Info,
  835. "【设备状态】" + stationNameStr + $"_上传Iot成功!");
  836. }
  837. else
  838. AddMessage_Station(stationNameStr, LogType.Info,
  839. "【设备状态】" + stationNameStr +
  840. $"_上传Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  841. }
  842. }
  843. #endregion 右工位
  844. }
  845. }
  846. }
  847. #endregion
  848. //if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  849. //{
  850. // DateTime dtNow = DateTime.Now;
  851. // //#region 获取设备运行信息
  852. // //try
  853. // //{
  854. // // LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  855. // // lineWorkingData1.GUID = Guid.NewGuid().ToString();
  856. // // lineWorkingData1.LineName = GlobalContext.LineCode;
  857. // // //
  858. // // lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  859. // // lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  860. // // lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  861. // // lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  862. // // lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  863. // // lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  864. // // lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  865. // // lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  866. // // lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  867. // // lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  868. // // lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  869. // // lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  870. // // lineWorkingData1.CreateTime = DateTime.Now;
  871. // // string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  872. // // // UI展示-展示到设备状态页
  873. // // if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  874. // // {
  875. // // // 查询数据库最新一条数据,确定是不是更新
  876. // // string qSql = @"SELECT top(1) [GUID]
  877. // // ,[LineName]
  878. // // ,[BootTimeLong]
  879. // // ,[NormalTimeLong]
  880. // // ,[StandbyTimeLong]
  881. // // ,[FaultTimeLong]
  882. // // ,[MaterialShortageTimeLong]
  883. // // ,[MaintenanceTimeLong]
  884. // // ,[FaultNumber]
  885. // // ,[OutputNumber]
  886. // // ,[QualifiedNumber]
  887. // // ,[QualifiedRate]
  888. // // ,[DesignRhythm]
  889. // // ,[RealityRhythm]
  890. // // ,[CreateTime]
  891. // // FROM [LineWorkingData]
  892. // // where [CreateTime] > '{0}'
  893. // // and [LineName]='{1}'
  894. // // order by [CreateTime] desc
  895. // // ";
  896. // // qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  897. // // var ds = SQLHelper_New.Query(qSql, null);
  898. // // if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  899. // // {
  900. // // var dataDBlast = new LineWorkingData_ThisTime();
  901. // // dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  902. // // dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  903. // // dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  904. // // dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  905. // // if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  906. // // {
  907. // // dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  908. // // dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  909. // // dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  910. // // dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  911. // // dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  912. // // dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  913. // // dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  914. // // dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  915. // // dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  916. // // dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  917. // // dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  918. // // dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  919. // // string usql = dataDBlast.ToStringUpdate();
  920. // // SQLHelper_New.ExecuteSQL(usql, null);
  921. // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  922. // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  923. // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  924. // // }
  925. // // }
  926. // // else
  927. // // {
  928. // // // 插入
  929. // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  930. // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  931. // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  932. // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  933. // // }
  934. // // }
  935. // // else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  936. // // {
  937. // // LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  938. // // //// 本次开机设备运行情况
  939. // // //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  940. // // //Task.Run(() =>
  941. // // //{
  942. // // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  943. // // // {
  944. // // // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  945. // // // }
  946. // // //});
  947. // // // 本日设备运行情况
  948. // // // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  949. // // if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  950. // // {
  951. // // // 更新
  952. // // lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  953. // // lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  954. // // lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  955. // // lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  956. // // lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  957. // // lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  958. // // lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  959. // // lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  960. // // lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  961. // // lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  962. // // lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  963. // // lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  964. // // SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  965. // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  966. // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  967. // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  968. // // }
  969. // // else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  970. // // {
  971. // // // 插入
  972. // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  973. // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  974. // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  975. // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  976. // // }
  977. // // await Task.Run(() =>
  978. // // {
  979. // // try
  980. // // {
  981. // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  982. // // {
  983. // // Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  984. // // }
  985. // // }
  986. // // catch { }
  987. // // });
  988. // // }
  989. // //}
  990. // //catch (Exception ex)
  991. // //{
  992. // // string str = ex.StackTrace;
  993. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  994. // //}
  995. // //#endregion 获取设备运行信息
  996. // #region 报警数据
  997. // try
  998. // {
  999. // List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  1000. // bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  1001. // // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  1002. // var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  1003. // for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  1004. // {
  1005. // short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  1006. // dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  1007. // if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  1008. // {
  1009. // isNeedUpdUI = true; // 需要更新历史报警UI信息
  1010. // // 记录
  1011. // dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  1012. // switch (dicAlarms_Cur_PLC1[i].是否报警)
  1013. // {
  1014. // case true: // 报警
  1015. // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  1016. // {
  1017. // GUID = Guid.NewGuid().ToString(),
  1018. // LineName = GlobalContext.LineCode, // 线体
  1019. // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  1020. // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  1021. // StartTime = dtNow // 开始时间
  1022. // };
  1023. // // 传输到页面
  1024. // deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  1025. // {
  1026. // 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  1027. // 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  1028. // 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  1029. // 开始时间 = dtNow
  1030. // });
  1031. // // 新增到数据库
  1032. // var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  1033. // SaveAlarmDataByDB(stationNameStr, data1, false);
  1034. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  1035. // break;
  1036. // case false: // 消除报警
  1037. // if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  1038. // {
  1039. // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  1040. // {
  1041. // GUID = Guid.NewGuid().ToString(),
  1042. // LineName = GlobalContext.LineCode, // 线体
  1043. // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  1044. // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  1045. // StartTime = dtNow, // 开始时间
  1046. // EndTime = dtNow, // 开始时间
  1047. // PersistTime = 1, // 耗时1s
  1048. // };
  1049. // // 新增
  1050. // var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  1051. // SaveAlarmDataByDB(stationNameStr, data2, false);
  1052. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  1053. // }
  1054. // else
  1055. // {
  1056. // dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  1057. // dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  1058. // - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  1059. // // 修改
  1060. // var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  1061. // SaveAlarmDataByDB(stationNameStr, data3, true);
  1062. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  1063. // }
  1064. // break;
  1065. // default:
  1066. // break;
  1067. // }
  1068. // }
  1069. // }
  1070. // DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  1071. // // 有新报警则更新
  1072. // if (isNeedUpdUI)
  1073. // {
  1074. // // UI展示 - 展示到设备状态页
  1075. // await Task.Run(() =>
  1076. // {
  1077. // try
  1078. // {
  1079. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  1080. // {
  1081. // Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  1082. // if (Form_Main.formDevAlarm.Visible)
  1083. // {
  1084. // Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  1085. // }
  1086. // }
  1087. // }
  1088. // catch { }
  1089. // });
  1090. // }
  1091. // }
  1092. // catch (Exception ex)
  1093. // {
  1094. // string str = ex.StackTrace;
  1095. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1096. // }
  1097. // #endregion 报警数据
  1098. // UpdatePLCMonitor(1, -2, 1);
  1099. //}
  1100. //else
  1101. //{
  1102. // UpdatePLCMonitor(1, -2, 0);
  1103. //}
  1104. }
  1105. catch (Exception ex)
  1106. {
  1107. //AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1108. AddMessage_Station(stationNameStr, LogType.Error,
  1109. $"PLC1_{stationNameStr}_采集运行数据与报警数据出错!错误信息:" + ex.Message.ToString());
  1110. }
  1111. Thread.Sleep(IntervalAlarm);
  1112. }
  1113. }
  1114. #endregion 轮询PLC
  1115. #region 下发订单信息
  1116. ///// <summary>
  1117. ///// 壳体上料(下发工单)的交互逻辑
  1118. ///// </summary>
  1119. ///// <param name="no"></param>
  1120. ///// <exception cref="NotImplementedException"></exception>
  1121. //private void ReadStation_DownOrderInfo(int plcNo)
  1122. //{
  1123. // // [S1] Tray盘上料装备(板测)
  1124. // // [S2] FCT(板测)
  1125. // // [S3] 值板机
  1126. // // [S4] 取放桁架
  1127. // // [S5] Tray盘下料装备
  1128. // /// 上位机心跳
  1129. // /// 获取设备报警数据与状态信息
  1130. // string stationNameStr = "[S0]壳体上料";
  1131. // while (IsRun)
  1132. // {
  1133. // try
  1134. // {
  1135. // if (!GlobalContext._IsCon_Funs1)
  1136. // {
  1137. // UpdatePLCMonitor(plcNo, 0);
  1138. // continue;
  1139. // }
  1140. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  1141. // {
  1142. // #region 壳体上料(下发工单)
  1143. // try
  1144. // {
  1145. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  1146. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  1147. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  1148. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  1149. // // 重置数据和信号
  1150. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  1151. // {
  1152. // // 清空写给PLC的数据
  1153. // int[] i497 = new int[1] { 0 };
  1154. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  1155. // // MES_Flag重置为0
  1156. // int[] i500 = new int[1] { 0 };
  1157. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  1158. // }
  1159. // }
  1160. // catch (Exception ex)
  1161. // {
  1162. // string str = ex.StackTrace;
  1163. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1164. // }
  1165. // #endregion 壳体上料(下发工单)
  1166. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1167. // }
  1168. // else
  1169. // {
  1170. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  1171. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1172. //
  1173. // Funs[plcNo].Connect();
  1174. // }
  1175. // }
  1176. // catch (Exception ex)
  1177. // {
  1178. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  1179. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1180. //
  1181. // Funs[plcNo].ReConnect();
  1182. // }
  1183. // Thread.Sleep(IntervalReadPLC);
  1184. // }
  1185. //}
  1186. ///// <summary>
  1187. ///// 下发订单信息到PLC
  1188. ///// </summary>
  1189. ///// <param name="no">PLC编号</param>
  1190. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  1191. //{
  1192. // try
  1193. // {
  1194. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  1195. // {
  1196. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  1197. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  1198. // }
  1199. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  1200. // }
  1201. // catch (Exception ex)
  1202. // {
  1203. // string str = ex.StackTrace;
  1204. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1205. // }
  1206. //}
  1207. /// <summary>
  1208. /// 下发清料信号
  1209. /// </summary>
  1210. /// <param name="no">PLC编号</param>
  1211. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  1212. {
  1213. try
  1214. {
  1215. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  1216. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  1217. return true;
  1218. }
  1219. catch (Exception ex)
  1220. {
  1221. string str = ex.StackTrace;
  1222. AddMessage_Station(stationNameStr, LogType.Error,
  1223. "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  1224. str.Length - str.LastIndexOf("\\") - 1));
  1225. return false;
  1226. }
  1227. }
  1228. #endregion 下发订单信息
  1229. #region Xiaomi 贲流
  1230. #region 公共方法
  1231. private static bool ProgressState = false;
  1232. private static readonly object lockObj = new object(); // 锁对象
  1233. private static bool isCollectingFlagLeft;
  1234. private static bool isCollectingFlagRight;
  1235. private bool OpenDailogFalg = true; //是否开启扫码弹窗标识
  1236. public static bool isNoStop = false; //是否停止循环
  1237. public void ConnectToIOT()
  1238. {
  1239. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  1240. // fds
  1241. param.parameter.fds.address = GlobalContext.address;
  1242. param.parameter.fds.appId = GlobalContext.appId;
  1243. param.parameter.fds.appKey = GlobalContext.appKey;
  1244. // mes
  1245. param.parameter.mes.address = GlobalContext.ServerIp;
  1246. param.parameter.mes.appId = GlobalContext.MESAppId;
  1247. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  1248. // mqtt
  1249. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  1250. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  1251. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  1252. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  1253. // 设备配置
  1254. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  1255. if (GlobalContext.IsUsePLC1)
  1256. {
  1257. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  1258. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  1259. xiaomiParm.workstation = GlobalContext.S1_work_station; //工站
  1260. }
  1261. if (GlobalContext.IsUsePLC2)
  1262. {
  1263. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  1264. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  1265. xiaomiParm.workstation = GlobalContext.S2_work_station; //工站
  1266. }
  1267. if (GlobalContext.IsUsePLC3)
  1268. {
  1269. param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
  1270. //param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
  1271. }
  1272. if (GlobalContext.IsUsePLC4)
  1273. {
  1274. param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
  1275. param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
  1276. xiaomiParm.workstation = GlobalContext.s4_work_station; //工站
  1277. }
  1278. if (GlobalContext.IsUsePLC5)
  1279. {
  1280. param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
  1281. param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
  1282. xiaomiParm.workstation = GlobalContext.s5_work_station; //工站
  1283. }
  1284. if (GlobalContext.IsUsePLC6)
  1285. {
  1286. param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
  1287. param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
  1288. xiaomiParm.workstation = GlobalContext.s6_work_station; //工站
  1289. }
  1290. if (GlobalContext.IsUsePLC7)
  1291. {
  1292. param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  1293. //param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  1294. xiaomiParm.stationCode = GlobalContext.s7_1_station;
  1295. }
  1296. if (GlobalContext.IsUsePLC8)
  1297. {
  1298. param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
  1299. param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
  1300. xiaomiParm.workstation = GlobalContext.s8_work_station; //工站
  1301. }
  1302. if (GlobalContext.IsUsePLC9)
  1303. {
  1304. param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
  1305. param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
  1306. xiaomiParm.workstation = GlobalContext.s9_work_station; //工站
  1307. }
  1308. param.parameter.equipment.project = GlobalContext.Project_Code;
  1309. param.parameter.equipment.productMode = "debug";
  1310. param.parameter.other.logLevel = 0;
  1311. param.parameter.other.LogPath = GlobalContext.MqttLogDir;
  1312. XiaomiMqttClient_Extend.ParameterConfig(param);
  1313. }
  1314. /// <summary>
  1315. /// float[]转为string
  1316. /// </summary>
  1317. public string FloatArrayToString(float[] nScrewResults)
  1318. {
  1319. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  1320. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  1321. }
  1322. /// <summary>
  1323. /// short[]转为string
  1324. /// </summary>
  1325. public string ShortArrayToString(short[] nScrewResults)
  1326. {
  1327. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  1328. return string.Join(",", nScrewResults);
  1329. }
  1330. /// <summary>
  1331. /// 写入PLC重复三次
  1332. /// </summary>
  1333. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount,
  1334. T inObj)
  1335. {
  1336. int i = 0;
  1337. int nRet = 0;
  1338. string strRet = "";
  1339. try
  1340. {
  1341. while (i < 3) // 最多上传三次
  1342. {
  1343. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  1344. if (nRet == 0) //成功
  1345. {
  1346. break;
  1347. }
  1348. else
  1349. {
  1350. AddMessage_Station(stationNameStr, LogType.Error,
  1351. $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1352. i++;
  1353. }
  1354. }
  1355. return (nRet, strRet);
  1356. }
  1357. catch (Exception ex)
  1358. {
  1359. return (1, ex.Message);
  1360. }
  1361. }
  1362. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes,
  1363. short[] nScrewOrders, short[] nScrewResults)
  1364. {
  1365. try
  1366. {
  1367. // 获取当前日期
  1368. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1369. // 构建保存路径
  1370. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  1371. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction, "螺丝Mes数据");
  1372. // 确保目录存在
  1373. Directory.CreateDirectory(savePath);
  1374. // 文件名
  1375. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  1376. string filePath = Path.Combine(savePath, fileName);
  1377. // 确保不会超出数组长度,只取前14个或数组的实际长度
  1378. int count = Math.Min(14, fScrewTimes.Length);
  1379. using (StreamWriter sw = new StreamWriter(filePath))
  1380. {
  1381. for (int i = 0; i < count; i++)
  1382. {
  1383. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  1384. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  1385. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  1386. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  1387. sw.WriteLine(); // 空行分隔不同螺丝的信息
  1388. }
  1389. }
  1390. return (0, "");
  1391. }
  1392. catch (Exception ex)
  1393. {
  1394. return (1, ex.Message);
  1395. }
  1396. }
  1397. public Dictionary<string, string> GetLastLineCompensation(string path, string direction, string sn)
  1398. {
  1399. // 创建字典存储补偿点及其对应的值
  1400. Dictionary<string, string> compensationDict = new Dictionary<string, string>();
  1401. try
  1402. {
  1403. //string path = GlobalContext.MESLaserRPath;
  1404. // 获取当前日期并格式化为 "yyyy-MM-dd" 格式
  1405. string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
  1406. string filename = $"Laser-{currentDate}-W0.txt";
  1407. // 拼接完整路径
  1408. string fullPath = Path.Combine(path, filename);
  1409. string lastNonEmptyLine = "";
  1410. // 判断文件是否存在
  1411. if (File.Exists(fullPath))
  1412. {
  1413. //读取文件内容
  1414. string[] lines = File.ReadAllLines(fullPath);
  1415. // 获取最后一行数据(忽略标题行)
  1416. if (lines.Length > 1)
  1417. {
  1418. string lastLine = "";
  1419. for (int i = lines.Length - 1; i > 0; i--)
  1420. {
  1421. if (!string.IsNullOrEmpty(lines[i]))
  1422. {
  1423. lastLine = lines[i];
  1424. break;
  1425. }
  1426. }
  1427. // 将最后一行按逗号分隔
  1428. string[] values = lastLine.Split(',');
  1429. values[1] = sn;
  1430. string key = "三点激光_" + direction; // 构造键名
  1431. string value = string.Join(",", values); // 获取值并去除多余空格
  1432. compensationDict[key] = value;
  1433. //// 提取“1点补偿”到“6点补偿”的值
  1434. //for (int i = 2; i <= 7 && i < values.Length; i++) // 从索引2开始,最多提取6个值
  1435. //{
  1436. // string key = $"{i - 1}点补偿"; // 构造键名
  1437. // string value = values[i].Trim(); // 获取值并去除多余空格
  1438. // compensationDict[key] = value;
  1439. //}
  1440. }
  1441. }
  1442. else
  1443. {
  1444. Console.WriteLine($"文件不存在: {fullPath}");
  1445. }
  1446. }
  1447. catch (Exception ex)
  1448. {
  1449. // 捕获异常并输出错误信息
  1450. Console.WriteLine($"发生错误: {ex.Message}");
  1451. }
  1452. return compensationDict;
  1453. }
  1454. public int PCBStationOutData(BarcodeSet_t Barcode, IoT_DataSet_t iotData)
  1455. {
  1456. int res = 0;
  1457. string jsonstr1 = "";
  1458. try
  1459. {
  1460. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1461. outRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备id(可配置)
  1462. outRequest_Body.stationId = GlobalContext.s5_station; // ⼯位ID(可配置)
  1463. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1464. outRequest_Body.clientTime =
  1465. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1466. outRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
  1467. int a1Result = (int)iotData.testStatus;
  1468. //bool pass = a1Result == 1;
  1469. //outRequest_Body.state = pass ? "PASS" : "FAIL"; ; // 出站条件 PASS或FAIL
  1470. outRequest_Body.state = "PASS";
  1471. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1472. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1473. XmStationOut_KeyMaterial keyMaterial = new XmStationOut_KeyMaterial();
  1474. keyMaterial.bindSort = 1;
  1475. keyMaterial.materialSn = Barcode.strProductBarcode;
  1476. outRequest_Body.unitData.keyMaterial.Add(keyMaterial); // 产品码
  1477. jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1478. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1479. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1480. if (response != null && response.header.code == "200")
  1481. {
  1482. res = 1;
  1483. AddMessage(LogType.Info,
  1484. "上传PCB出站数据到MES服务器---成功!请求信息:" + jsonstr1 + ",返回信息:" +
  1485. JsonConvert.SerializeObject(response.body));
  1486. }
  1487. else
  1488. {
  1489. res = 0;
  1490. AddMessage(LogType.Error,
  1491. "上传PCB出站数据到MES服务器---失败!错误信息:" + response.header.desc + ",请求信息:" + jsonstr1 + ",返回信息:" +
  1492. JsonConvert.SerializeObject(response.body));
  1493. }
  1494. }
  1495. catch (Exception e)
  1496. {
  1497. res = 0;
  1498. AddMessage(LogType.Info, "上传PCB出站数据到MES服务器---失败!请求信息:" + jsonstr1 + ",返回信息:" + e.Message);
  1499. }
  1500. return res;
  1501. }
  1502. public int PCBStationInData(BarcodeSet_t Barcode, IoT_DataSet_t iotData)
  1503. {
  1504. int res = 0;
  1505. string json_Body = "";
  1506. try
  1507. {
  1508. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1509. inRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  1510. inRequest_Body.stationId = GlobalContext.s5_station; // ⼯位ID(可配置)
  1511. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1512. inRequest_Body.clientTime =
  1513. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1514. inRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
  1515. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1516. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1517. json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1518. var response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1519. string resultJson = JsonConvert.SerializeObject(response);
  1520. if (response != null && response.header.code == "200")
  1521. {
  1522. res = 1;
  1523. AddMessage(LogType.Info,
  1524. "上传PCB进站数据到MES服务器---成功!请求信息:" + json_Body + ",返回信息:" +
  1525. JsonConvert.SerializeObject(response.body));
  1526. }
  1527. else
  1528. {
  1529. res = 0;
  1530. AddMessage(LogType.Error,
  1531. "上传PCB进站数据到MES服务器---失败!错误信息:" + response.header.desc + ",请求信息:" + json_Body + ",返回信息:" +
  1532. JsonConvert.SerializeObject(response.body));
  1533. }
  1534. }
  1535. catch (Exception e)
  1536. {
  1537. res = 0;
  1538. AddMessage(LogType.Info, "上传PCB进站数据到MES服务器---失败!请求信息:" + json_Body + ",返回信息:" + e.Message);
  1539. }
  1540. return res;
  1541. }
  1542. /// <summary>
  1543. /// 调用进站接口并保存进站数据
  1544. /// </summary>
  1545. /// <param name="stationNameStr">工站信息</param>
  1546. /// <param name="workorder_code">工单号</param>
  1547. /// <param name="mtltmrk">型号(物料号)</param>
  1548. /// <param name="sn">产品SN</param>
  1549. /// <param name="items">进站数据</param>
  1550. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1551. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn,
  1552. List<TestItem> items, string MachineId, string StationId, bool pass, string slot)
  1553. {
  1554. int result = 0;
  1555. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1556. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1557. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1558. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1559. inRequest_Body.clientTime =
  1560. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1561. inRequest_Body.unitSn = sn; // 产品SN
  1562. inRequest_Body.uuidInspection = uuid;
  1563. inRequest_Body.state = pass ? "PASS" : "FAIL";
  1564. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1565. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1566. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1567. StationIn stationIn = new StationIn()
  1568. {
  1569. Workorder_code = workorder_code, // 车间订单号
  1570. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1571. Sn = sn, // SN
  1572. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1573. Parameter_values = items, // 进站数据
  1574. Write_user = inRequest_Body.userId, // 员工Id
  1575. Test_time = inRequest_Body.clientTime // 进站时间
  1576. };
  1577. // 本地数据
  1578. string sql = stationIn.ToStringInsert(0);
  1579. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1580. result = ret == "成功" ? 1 : 6;
  1581. #region MES
  1582. if (GlobalContext.IsSendStationIn)
  1583. {
  1584. try
  1585. {
  1586. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1587. string resultJson = "";
  1588. string mesRet = string.Empty;
  1589. int i = 0;
  1590. while (i < 2) // 1009会多次尝试上传
  1591. {
  1592. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1593. resultJson = JsonConvert.SerializeObject(response);
  1594. if (response != null && response.header.code == "200")
  1595. break;
  1596. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1597. i++;
  1598. i++;
  1599. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1600. // 记录失败原因
  1601. OnMessage(LogType.Error, $"上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:{mesRet},请求参数:{json_Body}");
  1602. }
  1603. if (response?.header?.code == "200")
  1604. {
  1605. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1606. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1607. result = ret_Upd == "成功" ? 1 : 6;
  1608. AddMessage(LogType.Info,
  1609. $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功,返回参数:{resultJson},请求参数:{json_Body}");
  1610. }
  1611. else
  1612. {
  1613. result = 5;
  1614. AddMessage(LogType.Info,
  1615. $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息: {mesRet},请求参数:{json_Body}");
  1616. }
  1617. string sql_response =
  1618. stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1619. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1620. }
  1621. catch (Exception ex)
  1622. {
  1623. result = 6;
  1624. string str = ex.StackTrace;
  1625. AddMessage_Station(stationNameStr, LogType.Error,
  1626. $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1627. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1628. }
  1629. }
  1630. #endregion
  1631. #region IOT
  1632. //过站结果
  1633. if (GlobalContext.IsMqttSendProcessData)
  1634. {
  1635. PassStationResultRequest request = new PassStationResultRequest();
  1636. request.project_code = GlobalContext.Project_Code; // 项⽬编码
  1637. request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
  1638. request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
  1639. request.line_code = GlobalContext.LineCode; // 线体编码
  1640. request.work_station = xiaomiParm.workstation; // ⼯站ID
  1641. request.device_code = xiaomiParm.deviceCode; // 装备编码
  1642. request.station = xiaomiParm.stationCode;
  1643. request.process_time =
  1644. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
  1645. request.slot = slot; // 槽位编码
  1646. request.sn = sn; // 产品SN
  1647. // request.enter_status = inpass ? "PASS" : "FAIL"; // 进站状态
  1648. request.enter_status = pass ? "PASS" : "FAIL"; // 进站状态
  1649. request.result = ""; // 出站条件 PASS或FAIL; // 过站结果
  1650. request.work_type = "OUT_STATION"; // 作业类型
  1651. // 上传过站结果
  1652. (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
  1653. if (iotResult.Item1 != 0)
  1654. {
  1655. OnMessage(LogType.Info,
  1656. $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}] 进站结果[{request.enter_status}] 出站结果[{request.result}]");
  1657. }
  1658. }
  1659. #endregion
  1660. return result;
  1661. }
  1662. /// <summary>
  1663. /// 选择如何记录出站数据
  1664. /// </summary>
  1665. /// <param name="items">出站数据</param>
  1666. /// <param name="equipmentCode">设备编号</param>
  1667. /// <param name="processItem">测试项目</param>
  1668. /// <param name="workorder_code">车间订单号</param>
  1669. /// <param name="batch_num">批次号</param>
  1670. /// <param name="mtltmrk">型号</param>
  1671. /// <param name="proDate">日期</param>
  1672. /// <param name="supplierCode">供应商代码</param>
  1673. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1674. /// <returns>上传成功时返回1;失败返回0</returns>
  1675. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode,
  1676. string processItem,
  1677. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1678. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId,
  1679. string StationId, string PartBarcode, string jsonParm, string direction = "")
  1680. {
  1681. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num,
  1682. mtltmrk,
  1683. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode, jsonParm,
  1684. direction);
  1685. }
  1686. /// <summary>
  1687. /// 添加出站数据(提交到MES+本地保存到数据库)
  1688. /// </summary>
  1689. /// <param name="items">出站数据</param>
  1690. /// <param name="equipmentCode">设备编号</param>
  1691. /// <param name="processItem">测试项目</param>
  1692. /// <param name="workorder_code">车间订单号</param>
  1693. /// <param name="batch_num">批次号</param>
  1694. /// <param name="mtltmrk">型号</param>
  1695. /// <param name="proDate">日期</param>
  1696. /// <param name="supplierCode">供应商代码</param>
  1697. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1698. /// <returns>上传成功时返回1;失败返回0</returns>
  1699. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1700. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1701. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot,
  1702. string machineId, string stationId, string partBarcode, string jsonParm, string direction = "")
  1703. {
  1704. int upload = 0;
  1705. int result = 0;
  1706. ProcessData processData = new ProcessData()
  1707. {
  1708. Equipment_code = equipmentCode,
  1709. Workorder_code = workorder_code,
  1710. Batch_number = batch_num,
  1711. Sn = sn, // SN
  1712. Testitem = processItem,
  1713. Parameter_values = items,
  1714. Write_user = GlobalContext.CurrentUser,
  1715. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1716. };
  1717. // 本地数据
  1718. string sql = processData.ToStringInsert(upload);
  1719. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1720. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1721. #region MES
  1722. if (GlobalContext.IsSendProcessData)
  1723. {
  1724. try
  1725. {
  1726. string id = processData.ID.Copy();
  1727. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1728. outRequest_Body.uuidInspection = uuid;
  1729. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1730. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1731. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1732. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1733. outRequest_Body.unitSn = sn; // 产品SN
  1734. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1735. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1736. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1737. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1738. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1739. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1740. if (!string.IsNullOrEmpty(partBarcode))
  1741. {
  1742. outRequest_Body.unitData.keyMaterial.Add(
  1743. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1744. {
  1745. bindSort = 1,
  1746. materialSn = partBarcode
  1747. }); // 设备数据 - 部件码
  1748. }
  1749. //OP30站读txt数据
  1750. if (stationNameStr.Contains("CPAPHD"))
  1751. {
  1752. string path = "";
  1753. if (direction == "Left")
  1754. path = GlobalContext.MESLaserLPath;
  1755. else
  1756. path = GlobalContext.MESLaserRPath;
  1757. //字典存储数据
  1758. Dictionary<string, string> compensationDict = GetLastLineCompensation(path, direction, sn);
  1759. foreach (var kvp in compensationDict)
  1760. {
  1761. outRequest_Body.unitData.processData.Add(
  1762. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1763. {
  1764. dataName = kvp.Key.ToString(),
  1765. dataValue = kvp.Value.ToString()
  1766. });
  1767. }
  1768. }
  1769. //过站明细
  1770. if (GlobalContext.IsSendProcessDetail)
  1771. {
  1772. if (jsonParm.Length > 0)
  1773. {
  1774. // 解析JSON字符串为字典
  1775. var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonParm);
  1776. foreach (var kvp in dictionary)
  1777. {
  1778. outRequest_Body.unitData.processData.Add(
  1779. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1780. {
  1781. dataName = kvp.Key.ToString(),
  1782. dataValue = string.IsNullOrEmpty(kvp.Value) ? "" : kvp.Value.ToString()
  1783. });
  1784. }
  1785. }
  1786. }
  1787. if (GlobalContext.MESIsSendUpFile)
  1788. {
  1789. foreach (var item in fileUploadData.fileData)
  1790. {
  1791. if (!string.IsNullOrEmpty(item.FileName))
  1792. {
  1793. outRequest_Body.unitData.fileData.Add(
  1794. new XmStationOut_FileData()
  1795. {
  1796. fileName = item.FileName,
  1797. fileId = item.FileId,
  1798. bucket = item.Bucket
  1799. });
  1800. }
  1801. }
  1802. }
  1803. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1804. if (GlobalContext.IsSendProcessData)
  1805. {
  1806. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1807. string mesRet = string.Empty;
  1808. int i = 0;
  1809. while (i < 2) // 1009会多次尝试上传
  1810. {
  1811. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1812. if (response != null && response.header.code == "200")
  1813. {
  1814. OnMessage(LogType.Info,
  1815. $"【出站数据 SN {sn}】上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" +
  1816. JsonConvert.SerializeObject(response.body));
  1817. break;
  1818. }
  1819. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1820. i++;
  1821. i++;
  1822. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1823. // 记录失败原因
  1824. OnMessage(LogType.Error,
  1825. $"【出站数据 SN {sn}】上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1826. }
  1827. if (response?.header?.code == "200")
  1828. {
  1829. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1830. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1831. result = 1;
  1832. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1833. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1834. }
  1835. else
  1836. {
  1837. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1838. }
  1839. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(
  1840. JsonConvert.SerializeObject(outRequest_Body),
  1841. JsonConvert.SerializeObject(response), id);
  1842. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1843. }
  1844. }
  1845. catch (Exception ex)
  1846. {
  1847. string str = ex.StackTrace;
  1848. AddMessage_Station(stationNameStr, LogType.Error,
  1849. $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1850. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1851. }
  1852. }
  1853. #endregion
  1854. #region IOT
  1855. //过站明细
  1856. if (GlobalContext.IsMqttSendProcessData)
  1857. {
  1858. test_item_num += 1;
  1859. PassStationDetailRequest request = new PassStationDetailRequest();
  1860. request.pass_station_id = uuid;
  1861. request.sn = sn; // 产品SN
  1862. request.slot = vehicleSlot; // 槽位编码
  1863. request.test_item_num = test_item_num.ToString();
  1864. request.function_name = "Machine_加⼯模块";
  1865. request.status = "PASS";
  1866. (int, string) iotResult = (0, "");
  1867. if (jsonParm.Length > 0)
  1868. {
  1869. // 解析JSON字符串为字典
  1870. var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonParm);
  1871. foreach (var kvp in dictionary)
  1872. {
  1873. request.test_item = kvp.Key.ToString();
  1874. request.result_val = string.IsNullOrEmpty(kvp.Value) ? "" : kvp.Value.ToString();
  1875. request.description = request.test_item;
  1876. // 上传过站明细
  1877. iotResult = XiaomiMqttClient_Extend.Write_PassStationDetail(request);
  1878. if (iotResult.Item1 != 0)
  1879. {
  1880. OnMessage(LogType.Info,
  1881. $"【IOT过站明细】上传失败!错误原因:{iotResult.Item2},过站明细;产品码[{sn}] 测试项目[{request.test_item}] 测试值[{request.result_val}]");
  1882. }
  1883. }
  1884. }
  1885. }
  1886. //过站结果
  1887. if (GlobalContext.IsMqttSendProcessData)
  1888. {
  1889. PassStationResultRequest request = new PassStationResultRequest();
  1890. request.project_code = GlobalContext.Project_Code; // 项⽬编码
  1891. request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
  1892. request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
  1893. request.line_code = GlobalContext.LineCode; // 线体编码
  1894. request.work_station = xiaomiParm.workstation; // ⼯站ID
  1895. request.device_code = xiaomiParm.deviceCode; // 装备编码
  1896. request.station = xiaomiParm.stationCode;
  1897. request.process_time =
  1898. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
  1899. request.slot = vehicleSlot; // 槽位编码
  1900. request.sn = sn; // 产品SN
  1901. // request.enter_status = inpass ? "PASS" : "FAIL"; // 进站状态
  1902. request.enter_status = ""; // 进站状态
  1903. request.result = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL; // 过站结果
  1904. request.work_type = "OUT_STATION"; // 作业类型
  1905. // 上传过站结果
  1906. (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
  1907. if (iotResult.Item1 != 0)
  1908. {
  1909. OnMessage(LogType.Info,
  1910. $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}] 进站结果[{request.enter_status}] 出站结果[{request.result}]");
  1911. }
  1912. }
  1913. #endregion
  1914. return result;
  1915. }
  1916. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1917. //{
  1918. // Stopwatch stopwatch = new Stopwatch();
  1919. // stopwatch.Start();
  1920. // try
  1921. // {
  1922. // // 初始化 AtlasScrew 实例
  1923. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1924. // atlasScrew1.Initial();
  1925. // // 存储结果的列表
  1926. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1927. // // 存储角度和扭力的字符串列表
  1928. // List<string> angleStrs = new List<string>();
  1929. // List<string> torqueStrs = new List<string>();
  1930. // // 上一次获取的数据
  1931. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1932. // while (isExitAtlasLeft) // 检查是否收集数据
  1933. // {
  1934. // // 获取当前数据
  1935. // var currentResult = atlasScrew1.GetResults();
  1936. // // 判断是否为新数据
  1937. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1938. // {
  1939. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1940. // // 更新角度和扭力的字符串列表
  1941. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1942. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1943. // // 计算角度、扭力、起始扭力和最大扭力
  1944. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1945. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1946. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1947. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1948. // // 将新数据添加到结果列表
  1949. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1950. // // 更新上一次获取的数据
  1951. // lastResult = currentResult;
  1952. // }
  1953. // // 等待一段时间后再次检查
  1954. // Thread.Sleep(20); // 轮询间隔时间
  1955. // // 如果触发了出站,则退出循环
  1956. // if (!isExitAtlasLeft)
  1957. // {
  1958. // break;
  1959. // }
  1960. // }
  1961. // // 生成文件名
  1962. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1963. // // 写入数据到文件
  1964. // using (StreamWriter writer = new StreamWriter(fileName))
  1965. // {
  1966. // // 写入标题行
  1967. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1968. // // 写入每一行数据
  1969. // foreach (var result in results)
  1970. // {
  1971. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1972. // }
  1973. // }
  1974. // stopwatch.Stop();
  1975. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1976. // }
  1977. // catch (Exception ex)
  1978. // {
  1979. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1980. // }
  1981. // finally
  1982. // {
  1983. // // 重置标志变量
  1984. // isExitAtlasLeft = false;
  1985. // }
  1986. //}
  1987. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1988. //{
  1989. // Stopwatch stopwatch = new Stopwatch();
  1990. // stopwatch.Start();
  1991. // try
  1992. // {
  1993. // // 初始化 AtlasScrew 实例
  1994. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1995. // atlasScrew2.Initial();
  1996. // // 存储结果的列表
  1997. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1998. // // 上一次获取的数据
  1999. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  2000. // while (isExitAtlasRight) // 检查是否收集数据
  2001. // {
  2002. // // 获取当前数据
  2003. // var currentResult = atlasScrew2.GetResults();
  2004. // // 判断是否为新数据
  2005. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  2006. // {
  2007. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  2008. // // 将新数据写入PLC
  2009. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  2010. // // 将新数据添加到结果列表
  2011. // results.Add(currentResult);
  2012. // // 更新上一次获取的数据
  2013. // lastResult = currentResult;
  2014. // }
  2015. // // 等待一段时间后再次检查
  2016. // Thread.Sleep(20); // 轮询间隔时间
  2017. // // 如果触发了出站,则退出循环
  2018. // if (!isExitAtlasRight)
  2019. // {
  2020. // break;
  2021. // }
  2022. // }
  2023. // // 将所有数据写入文件
  2024. // //WriteDataToFile(sn, direction, results);
  2025. // stopwatch.Stop();
  2026. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  2027. // }
  2028. // catch (Exception ex)
  2029. // {
  2030. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  2031. // }
  2032. // finally
  2033. // {
  2034. // // 重置标志变量
  2035. // isExitAtlasRight = false;
  2036. // }
  2037. //}
  2038. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  2039. {
  2040. Stopwatch stopwatch = new Stopwatch();
  2041. stopwatch.Start();
  2042. int nRet = 0;
  2043. string strRet = "";
  2044. try
  2045. {
  2046. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  2047. while (isCollectingFlagLeft)
  2048. {
  2049. // 从缓存中获取所有未处理的数据
  2050. var cachedData = atlasScrew.GetCachedDataLeft();
  2051. foreach (var currentResult in cachedData)
  2052. {
  2053. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  2054. {
  2055. continue; // 跳过无效数据
  2056. }
  2057. OnMessage(LogType.Info,
  2058. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  2059. // 写入PLC
  2060. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  2061. {
  2062. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  2063. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  2064. };
  2065. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  2066. if (nRet != 0)
  2067. {
  2068. OnMessage(LogType.Info,
  2069. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  2070. }
  2071. else
  2072. {
  2073. OnMessage(LogType.Info,
  2074. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  2075. }
  2076. // 构建保存路径
  2077. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  2078. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  2079. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  2080. Directory.CreateDirectory(savePath); // 确保目录存在
  2081. // 构建文件名(以 SN + 序号命名)
  2082. string fileName = $"{sn}_{fileCounter}.txt";
  2083. string filePath = Path.Combine(savePath, fileName);
  2084. // 写入文件
  2085. using (StreamWriter writer = new StreamWriter(filePath))
  2086. {
  2087. writer.WriteLine("精度, 扭力");
  2088. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  2089. for (int i = 0;
  2090. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  2091. i++)
  2092. {
  2093. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  2094. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  2095. writer.WriteLine($"{precision}, {torque}");
  2096. }
  2097. }
  2098. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  2099. // 增加文件计数器
  2100. fileCounter++;
  2101. }
  2102. // 如果没有更多数据,则短暂休眠以节省资源
  2103. if (!cachedData.Any())
  2104. {
  2105. Thread.Sleep(10); // 根据需要调整休眠时间
  2106. }
  2107. // 如果触发了出站,则退出循环
  2108. if (!isCollectingFlagLeft)
  2109. {
  2110. break;
  2111. }
  2112. }
  2113. stopwatch.Stop();
  2114. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  2115. }
  2116. catch (Exception ex)
  2117. {
  2118. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  2119. }
  2120. finally
  2121. {
  2122. isCollectingFlagLeft = false;
  2123. }
  2124. }
  2125. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  2126. {
  2127. Stopwatch stopwatch = new Stopwatch();
  2128. stopwatch.Start();
  2129. int nRet = 0;
  2130. string strRet = "";
  2131. try
  2132. {
  2133. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  2134. while (isCollectingFlagRight)
  2135. {
  2136. // 从缓存中获取所有未处理的数据
  2137. var cachedData = atlasScrew.GetCachedDataLeft();
  2138. foreach (var currentResult in cachedData)
  2139. {
  2140. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  2141. {
  2142. continue; // 跳过无效数据
  2143. }
  2144. OnMessage(LogType.Info,
  2145. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  2146. // 写入PLC
  2147. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  2148. {
  2149. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  2150. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  2151. };
  2152. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  2153. if (nRet != 0)
  2154. {
  2155. OnMessage(LogType.Info,
  2156. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  2157. }
  2158. else
  2159. {
  2160. OnMessage(LogType.Info,
  2161. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  2162. }
  2163. // 构建保存路径
  2164. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  2165. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  2166. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  2167. Directory.CreateDirectory(savePath); // 确保目录存在
  2168. // 构建文件名(以 SN + 序号命名)
  2169. string fileName = $"{sn}_{fileCounter}.txt";
  2170. string filePath = Path.Combine(savePath, fileName);
  2171. // 写入文件
  2172. using (StreamWriter writer = new StreamWriter(filePath))
  2173. {
  2174. writer.WriteLine("精度, 扭力");
  2175. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  2176. for (int i = 0;
  2177. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  2178. i++)
  2179. {
  2180. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  2181. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  2182. writer.WriteLine($"{precision}, {torque}");
  2183. }
  2184. }
  2185. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  2186. // 增加文件计数器
  2187. fileCounter++;
  2188. }
  2189. // 如果没有更多数据,则短暂休眠以节省资源
  2190. if (!cachedData.Any())
  2191. {
  2192. Thread.Sleep(10); // 根据需要调整休眠时间
  2193. }
  2194. // 如果触发了出站,则退出循环
  2195. if (!isCollectingFlagRight)
  2196. {
  2197. break;
  2198. }
  2199. }
  2200. stopwatch.Stop();
  2201. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  2202. }
  2203. catch (Exception ex)
  2204. {
  2205. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  2206. }
  2207. finally
  2208. {
  2209. isCollectingFlagRight = false;
  2210. }
  2211. }
  2212. public static (int, string) CompressFolder(string folderPath, string zipFilePath)
  2213. {
  2214. try
  2215. {
  2216. // 创建zip文件,将指定文件夹内的所有内容压缩到这个zip文件中
  2217. System.IO.Compression.ZipFile.CreateFromDirectory(folderPath, zipFilePath);
  2218. return (1, "文件夹已成功压缩!");
  2219. }
  2220. catch (Exception ex)
  2221. {
  2222. return (0, "文件压缩出错!" + ex.Message);
  2223. }
  2224. }
  2225. /// <summary>
  2226. /// 上传文件
  2227. /// </summary>
  2228. /// <param name="BarcodeSet_t">条码集合</param>
  2229. /// <param name="stationCode">工站编号</param>
  2230. /// <param name="stationName">工站名称</param>
  2231. /// <param name="path">文件路径</param>
  2232. public async Task<(int, string)> SaveDBbyFileInfo(BarcodeSet_t BarcodeSet, string stationCode,
  2233. string stationName, int pass, string path, string guid = "")
  2234. {
  2235. string sql, filename = "";
  2236. int result = 0;
  2237. var formData = new MultipartFormDataContent();
  2238. string msg = "";
  2239. string file_category = "IMAGE"; //IMAGE 、TEXT 、UNKNOWN
  2240. string file_type = "IMAGE";
  2241. string project = GlobalContext.ProgramName;
  2242. string run_mode = GlobalContext.run_mode;
  2243. string product_mode = GlobalContext.product_mode;
  2244. string pass_result = (pass == 1 ? "PASS" : "Fail");
  2245. string device_code = xiaomiParm.deviceCode;
  2246. string sn = BarcodeSet.strProductBarcode;
  2247. string staion_id = xiaomiParm.stationCode;
  2248. string bucket =
  2249. $"{file_category}/{file_type}/{project}/{product_mode}/{run_mode}/{pass_result}/{device_code}/{sn}/{staion_id}";
  2250. // 获取所有图片文件
  2251. if (guid == "")
  2252. {
  2253. guid = Guid.NewGuid().ToString();
  2254. }
  2255. try
  2256. {
  2257. if (GlobalContext.MESIsSendUpFile)
  2258. {
  2259. List<string> imageFiles = GetAllImageFiles(path);
  2260. string toPath = GlobalContext.MqttFileBackupLogDir;
  2261. filename =
  2262. $"{xiaomiParm.workstation}_{file_type}_{sn}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";
  2263. //string directoryPath = Path.GetDirectoryName(path);
  2264. string strFilePath = toPath + "\\" + filename;
  2265. if (imageFiles.Count > 0)
  2266. {
  2267. var r = CompressFolder(path, strFilePath);
  2268. if (r.Item1 == 0)
  2269. {
  2270. return (0, r.Item2);
  2271. }
  2272. else
  2273. {
  2274. msg = r.Item2 + "\r\n";
  2275. }
  2276. }
  2277. else
  2278. {
  2279. return (0, "文件不存在!");
  2280. }
  2281. FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
  2282. fileUpload_X5.bucket = bucket;
  2283. fileUpload_X5.name = filename;
  2284. fileUpload_X5.uuid = guid.ToString();
  2285. ///需要上传文件
  2286. FileInfo file = new FileInfo(strFilePath);
  2287. string fileMd5Hex = GetMD5Hex(file);
  2288. fileUpload_X5.md5 = fileMd5Hex;
  2289. fileUpload_X5.uploadCloud = true;
  2290. fileUpload_X5.informMqtt = true;
  2291. FileMqttPayload fileMqttPayload = new FileMqttPayload();
  2292. fileMqttPayload.factory = GlobalContext.Factory_Code;
  2293. fileMqttPayload.project_name = GlobalContext.Project_Code;
  2294. fileMqttPayload.product_mode = GlobalContext.product_mode;
  2295. fileMqttPayload.line_no = GlobalContext.LineCode;
  2296. fileMqttPayload.work_station_no = xiaomiParm.workstation;
  2297. fileMqttPayload.equipment_no = xiaomiParm.deviceCode;
  2298. fileMqttPayload.station_no = xiaomiParm.stationCode;
  2299. fileMqttPayload.file_id = guid;
  2300. fileMqttPayload.file_name = filename;
  2301. fileMqttPayload.sn = BarcodeSet.strProductBarcode;
  2302. //fileMqttPayload.opt_time = "";
  2303. //fileMqttPayload.file_type = "";
  2304. //fileMqttPayload.file_category = "";
  2305. //fileMqttPayload.tag = "";
  2306. fileMqttPayload.reference_info.pass_station_id = uuid;
  2307. var fileresult = await
  2308. XiaomiMESHttp_UpLoadFile.FileUoladToMes(strFilePath, fileUpload_X5, fileMqttPayload);
  2309. if (fileresult.Item1 != 1)
  2310. {
  2311. return (0, msg + fileresult.Item2 + "\r\n");
  2312. }
  2313. else
  2314. {
  2315. msg = msg + fileresult.Item2 + "\r\n";
  2316. }
  2317. foreach (var imageFile in imageFiles)
  2318. {
  2319. if (File.Exists(imageFile))
  2320. {
  2321. //删除文件
  2322. (bool, string) newResult = DeleteFile(imageFile);
  2323. if (!newResult.Item1)
  2324. {
  2325. return (0, Path.GetFileName(imageFile) + newResult.Item2);
  2326. }
  2327. }
  2328. }
  2329. }
  2330. return (1, msg);
  2331. }
  2332. catch (Exception e)
  2333. {
  2334. return (0,
  2335. filename + $"文件上传错误!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode},错误原因:" +
  2336. e.Message);
  2337. }
  2338. }
  2339. /// <summary>
  2340. /// 获取路径下的所有图片
  2341. /// </summary>
  2342. /// <param name="directoryPath"></param>
  2343. /// <returns></returns>
  2344. public List<string> GetAllImageFiles(string directoryPath)
  2345. {
  2346. var imageExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
  2347. { ".jpg", ".jpeg", ".png", ".bmp", ".gif", ".tiff" };
  2348. var imageFiles = new List<string>();
  2349. try
  2350. {
  2351. // 遍历目录及子目录中的所有文件
  2352. foreach (string file in Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories))
  2353. {
  2354. // 获取文件扩展名并检查是否为图片格式
  2355. string extension = Path.GetExtension(file);
  2356. if (imageExtensions.Contains(extension))
  2357. {
  2358. imageFiles.Add(file);
  2359. }
  2360. }
  2361. }
  2362. catch (Exception ex)
  2363. {
  2364. OnMessage(LogType.Error, $"图片查询发生错误: {ex.Message}");
  2365. }
  2366. return imageFiles;
  2367. }
  2368. /// <summary>
  2369. /// 实例化报警字典
  2370. /// </summary>
  2371. private (bool, string) InitalDicAlarm()
  2372. {
  2373. #region 加载报警表
  2374. string excelPath = "";
  2375. switch (GlobalContext.IsUsePLCNow)
  2376. {
  2377. case 1:
  2378. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_10_壳体清洁上料.xlsx";
  2379. break;
  2380. case 2:
  2381. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_20_上盖板上料装备.xlsx";
  2382. break;
  2383. case 3:
  2384. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_30_点散热胶装备.xlsx";
  2385. break;
  2386. case 4:
  2387. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_40_胶线检测.xlsx";
  2388. break;
  2389. case 5:
  2390. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_50_ADD板上料组装装备.xlsx";
  2391. break;
  2392. case 6:
  2393. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_60_组上盖板.xlsx";
  2394. break;
  2395. case 7:
  2396. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_70_上盖板锁螺丝.xlsx";
  2397. break;
  2398. case 8:
  2399. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_80_NG下料.xlsx";
  2400. break;
  2401. case 9:
  2402. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_90_半成品下料.xlsx";
  2403. break;
  2404. default:
  2405. return (false, $"不支持当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请在设置页切换到正确的plc后重启该软件!");
  2406. }
  2407. if (!File.Exists(excelPath))
  2408. return (false, $"未找到当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请检查文件路径:'{excelPath}'。");
  2409. DataTable DtModel = NPOIHelper.ReadExcel(excelPath);
  2410. if (DtModel == null || DtModel.Rows.Count < 1)
  2411. return (false, $"报警点位表未包含任何报警数据!请检查‘{excelPath}’文件!");
  2412. // 检查列名
  2413. List<string> isNeedParms = new List<string>()
  2414. {
  2415. "设备分类名称", "设备分类编码", "分类层级1", "分类层级2", "分类层级3", "分类层级4", "事件名称", "事件ID", "描述", "标签", "PLC地址", "工位"
  2416. }; // 必须要有的列
  2417. // 指定列名 + 检查列是否完整
  2418. DataRow dtRowName = DtModel.Rows[0];
  2419. int count = DtModel.Columns.Count;
  2420. for (int i = 0; i < count; i++)
  2421. {
  2422. string columeName = dtRowName[i]?.ToString();
  2423. if (!string.IsNullOrEmpty(columeName))
  2424. DtModel.Columns[i].ColumnName = columeName;
  2425. if ((!string.IsNullOrEmpty(columeName)) && isNeedParms.Count > 0 && isNeedParms.Contains(columeName))
  2426. isNeedParms.Remove(columeName);
  2427. }
  2428. DtModel.Rows.RemoveAt(0);
  2429. if (isNeedParms.Count > 0)
  2430. {
  2431. string msg1 = string.Join(",", isNeedParms);
  2432. return (false, $"报警点位表未包含列:{msg1}!请检查‘{excelPath}’文件!");
  2433. }
  2434. #endregion 加载报警表
  2435. List<Alarm> keyValues1 = new List<Alarm>();
  2436. for (int i = 0; i < DtModel.Rows.Count; i++)
  2437. {
  2438. Alarm alarm = new Alarm();
  2439. alarm.plcName = DtModel.Rows[i]["设备分类名称"]?.ToString(); // 设备名;
  2440. string type1Str = DtModel.Rows[i]["分类层级1"]?.ToString(); // 分类层级1;
  2441. alarm.type1CH = type1Str; // 分类层级1 中文
  2442. alarm.type1 = type1Str; // 分类层级1
  2443. if (!string.IsNullOrEmpty(type1Str) && type1Str.Contains("\n"))
  2444. {
  2445. string[] type1Strs = type1Str.Split('\n');
  2446. if (type1Strs.Length >= 2)
  2447. {
  2448. alarm.type1CH = type1Strs[0].Trim(); // 分类层级1 中文
  2449. alarm.type1 = type1Strs[1].Trim(); // 分类层级1
  2450. if (string.IsNullOrEmpty(alarm.type1))
  2451. alarm.type1 = alarm.type1CH;
  2452. }
  2453. }
  2454. string type2Str = DtModel.Rows[i]["分类层级2"]?.ToString(); // 分类层级2;电气控制 electric_control
  2455. alarm.type2CH = type2Str; // 分类层级2 中文
  2456. alarm.type2 = type2Str; // 分类层级2
  2457. if (!string.IsNullOrEmpty(type2Str) && type2Str.Contains("\n"))
  2458. {
  2459. string[] type2Strs = type2Str.Split('\n');
  2460. if (type2Strs.Length >= 2)
  2461. {
  2462. alarm.type2CH = type2Strs[0].Trim(); // 分类层级2 中文
  2463. alarm.type2 = type2Strs[1].Trim(); // 分类层级2
  2464. if (string.IsNullOrEmpty(alarm.type2))
  2465. alarm.type2 = alarm.type2CH;
  2466. }
  2467. }
  2468. string type3Str = DtModel.Rows[i]["分类层级3"]?.ToString(); // 分类层级3;故障 Fault
  2469. alarm.type3CH = type3Str; // 分类层级3 中文
  2470. alarm.type3 = type3Str; // 分类层级3
  2471. if (!string.IsNullOrEmpty(type3Str) && type3Str.Contains("\n"))
  2472. {
  2473. string[] type3Strs = type3Str.Split('\n');
  2474. if (type3Strs.Length >= 2)
  2475. {
  2476. alarm.type3CH = type3Strs[0].Trim(); // 分类层级3 中文
  2477. alarm.type3 = type3Strs[1].Trim(); // 分类层级3
  2478. if (string.IsNullOrEmpty(alarm.type3))
  2479. alarm.type3 = alarm.type3CH;
  2480. }
  2481. }
  2482. string faultStr = DtModel.Rows[i]["分类层级4"]?.ToString(); // 故障部件;overall_module
  2483. alarm.type4 = faultStr; // 分类层级4 中文
  2484. alarm.type4CH = faultStr; // 分类层级4
  2485. if (!string.IsNullOrEmpty(faultStr) && faultStr.Contains("\n"))
  2486. {
  2487. string[] faultStrs = faultStr.Split('\n');
  2488. if (faultStrs.Length >= 2)
  2489. {
  2490. alarm.type4CH = faultStrs[0].Trim(); // 故障部件;overall_module
  2491. alarm.type4 = faultStrs[1].Trim(); // 故障部件
  2492. if (string.IsNullOrEmpty(alarm.type4))
  2493. alarm.type4 = alarm.type4CH;
  2494. }
  2495. }
  2496. alarm.fault_code = DtModel.Rows[i]["事件ID"]?.ToString(); // 故障编码;A40001
  2497. alarm.fault_name = DtModel.Rows[i]["事件名称"]?.ToString(); // 故障名称;AL[1000]_系统_HMI急停故障
  2498. alarm.fault_desc = alarm.fault_name; // 故障描述;AL[1000]_系统_HMI急停故障
  2499. string plcAdress = DtModel.Rows[i]["PLC地址"]?.ToString();
  2500. alarm.PLC地址 = plcAdress;
  2501. plcAdress = plcAdress.Replace("fault_codes[", "");
  2502. plcAdress = plcAdress.Replace("]", "");
  2503. alarm.group_index = Convert.ToInt32(plcAdress.Split(".")[0]);
  2504. keyValues1.Add(alarm);
  2505. }
  2506. DicAlarms_Cur.Add(GlobalContext.IsUseStationName, keyValues1); // 这里使用线体代替工位
  2507. return (true, "报警字典表初始化成功!");
  2508. }
  2509. private async void ReadPLCAlarmToIot(uint[] FaultData, uint[] FaultDataOld, string stationNameStr)
  2510. {
  2511. DateTime dtNow = DateTime.Now;
  2512. try
  2513. {
  2514. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  2515. List<(int, int)> AlarmIndexList = new List<(int, int)>(); //收集所有报警信息的位置
  2516. AlarmData alarmData = new AlarmData();
  2517. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  2518. bool isNoAlarm = false; //是否有报警
  2519. string binaryString = "";
  2520. bool isNoNewAlarm = false; //是否有新的报警
  2521. if (FaultData.Length > 0)
  2522. {
  2523. foreach (var item in FaultData)
  2524. {
  2525. isNoAlarm = item > 0 ? true : false;
  2526. }
  2527. if (!FaultData.SequenceEqual(FaultDataOld))
  2528. {
  2529. isNoNewAlarm = true;
  2530. isNeedUpdUI = true;
  2531. }
  2532. if (FaultData.Length > 0 && isNoAlarm && isNoNewAlarm)
  2533. {
  2534. //解析报警信息,分析当前报警在字典中的定位
  2535. for (int i = 0; i <= FaultData.Length - 1; i++)
  2536. {
  2537. var num = 0;
  2538. if (FaultData[i] > 0)
  2539. {
  2540. //转换二进制
  2541. binaryString = Convert.ToString(FaultData[i], 2);
  2542. for (int j = binaryString.Length - 1; j >= 0; j--)
  2543. {
  2544. num++;
  2545. char s = binaryString[j];
  2546. if (binaryString[j] == '1')
  2547. {
  2548. //记录1的位置
  2549. AlarmIndexList.Add((i, num - 1));
  2550. }
  2551. }
  2552. }
  2553. }
  2554. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  2555. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.IsUseStationName];
  2556. foreach ((int index, int row) in AlarmIndexList)
  2557. {
  2558. var tempDic = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList();
  2559. for (int i = 0; i < tempDic.Count - 1; i++) // 读取
  2560. {
  2561. //若报警字典第[group_index]个数据,第[i]行与AlarmIndexList中的定位匹配,则添加进对应行的报警数据
  2562. if (tempDic[i].group_index == index && i == row)
  2563. {
  2564. dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据 =
  2565. new AlarmData()
  2566. {
  2567. GUID = Guid.NewGuid().ToString(),
  2568. LineName = GlobalContext.IsUseStationName, // 工站
  2569. PlcStation = tempDic[i].plcName, // 工站全称;[S1]
  2570. Type1 = tempDic[i].type1, // 故障层级1
  2571. Type2 = tempDic[i].type2, // 故障层级2
  2572. Type3 = tempDic[i].type3, // 故障层级3
  2573. Type4 = tempDic[i].type4, // 故障层级4
  2574. AlarmType = tempDic[i].fault_code, // 报警类型
  2575. AlarmDesc = tempDic[i].fault_name, // 报警内容
  2576. StartTime = dtNow // 开始时间
  2577. };
  2578. // 传输到页面
  2579. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  2580. {
  2581. 线体名称 = tempDic[i].plcName,
  2582. 报警类型 = tempDic[i].fault_code,
  2583. 报警内容 = tempDic[i].fault_name,
  2584. 开始时间 = dtNow
  2585. });
  2586. // 新增到数据库
  2587. //var data1 = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据;
  2588. //SaveAlarmDataByDB(stationNameStr, data1, false);
  2589. //OnMessage(LogType.Info, $"更新{BodyAlarm}完毕!");
  2590. }
  2591. }
  2592. }
  2593. //筛选含报警数据的字典
  2594. var dicAlarms_Cur = dicAlarms_Cur_PLC1.Where(x => x.报警数据 != null).ToList();
  2595. if (dicAlarms_Cur.Count > 0)
  2596. {
  2597. foreach (var item in dicAlarms_Cur)
  2598. {
  2599. //上传
  2600. SaveAlarmDataByDB(GlobalContext.IsUseStationName, item.报警数据, false);
  2601. }
  2602. }
  2603. // 有新报警则更新
  2604. if (isNeedUpdUI)
  2605. // UI展示 - 展示到设备状态页
  2606. await Task.Run(() =>
  2607. {
  2608. try
  2609. {
  2610. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  2611. {
  2612. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  2613. if (Form_Main.formDevAlarm.Visible)
  2614. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  2615. }
  2616. }
  2617. catch
  2618. {
  2619. }
  2620. });
  2621. FaultDataOld = FaultData.ToArray();
  2622. }
  2623. }
  2624. //FaultLogRequest request = new FaultLogRequest();
  2625. //request.station = mesStation; // 工位
  2626. //request.fault_name = xmFaultName; // 故障名称(同数据字典中的事件名称)
  2627. //request.fault_code = xmFaultCode2; // 故障编码(A,B,C,D,E)
  2628. //request.fault_cmpnt = xmFaultCmpnt; // 故障部件
  2629. //request.fault_desc = xmFaultDesc; // 故障描述
  2630. //request.fault_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 故障发生时间 2022-06-01 14:27:57.283
  2631. // // 上传
  2632. //(int, string) iotResult = XiaomiMqttClient_Extend.Write_FaultLog(request, type1, type2, type3, request.fault_cmpnt, deciveCode);
  2633. }
  2634. catch (Exception ex)
  2635. {
  2636. string str = ex.StackTrace;
  2637. AddMessage_Station(stationNameStr, LogType.Error,
  2638. $"{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" +
  2639. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2640. }
  2641. }
  2642. public void operateToIot(string action, string stationNameStr)
  2643. {
  2644. OperateLogRequest request = new OperateLogRequest();
  2645. request.software_version = "V" + Application.ProductVersion; // 软件版本号;如:V1.2.4
  2646. request.operate_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 操作时间(2022-06-01 14:27:57.283)
  2647. request.operate_action = action; // 操作动作(对应软件开启/关闭/重新加载项⽬;startup、shutdown、reload)
  2648. //request.current_process = Process.GetCurrentProcess()?.Id.ToString(); // 当前进程;进程ID
  2649. request.current_process = Application.ProductName;
  2650. request.operate_desc = stationNameStr; // 操作描述;如:供应商软件开启/关闭/重新加载项⽬
  2651. request.operate_result = "success"; // 操作结果
  2652. request.operator_name = "default"; // 操作账号名;填当前操作⽤⼾,如⽆则填default
  2653. // 上传
  2654. (int, string) iotResult = XiaomiMqttClient_Extend.Write_OperateLog(request);
  2655. if (iotResult.Item1 != 0)
  2656. {
  2657. AddMessage(LogType.Info, "【操作记录】上传失败!错误原因:" + iotResult.Item2 + "操作状态:" + stationNameStr);
  2658. }
  2659. }
  2660. private void 通用节拍接口(int plcNo, string stationNameStr, string tagMesCommName, string CarrierBarcode,
  2661. IoT_DataSet_t iot_data)
  2662. {
  2663. Stopwatch stopwatch1 = new Stopwatch();
  2664. Stopwatch stopwatch2 = new Stopwatch();
  2665. string resultStr = string.Empty;
  2666. try
  2667. {
  2668. stopwatch1.Start();
  2669. string oEEType = iot_data.BeatAction.ToString(); // 节拍类型(plc写入)
  2670. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode); //产品SN
  2671. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  2672. if (!actionBool)
  2673. {
  2674. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{oEEType}]写入成功!");
  2675. return;
  2676. }
  2677. short _result = 0;
  2678. (short, string) result = (0, "");
  2679. // 上传开始节拍
  2680. result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2681. _result = result.Item1;
  2682. resultStr = result.Item2;
  2683. if (_result == 1)
  2684. {
  2685. //写入PLC
  2686. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2687. iotData.machineState = iot_data.machineState;
  2688. iotData.work_type = iot_data.work_type;
  2689. iotData.testStatus = iot_data.testStatus;
  2690. iotData.BeatAction = iot_data.BeatAction;
  2691. iotData.beatReturn = 1; //OK
  2692. iotData.fault_codes = iot_data.fault_codes;
  2693. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2694. if (PLCresult.Item1 != 0)
  2695. {
  2696. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]写入成功!");
  2697. }
  2698. }
  2699. else
  2700. {
  2701. stopwatch2.Stop();
  2702. AddMessage_Station(stationNameStr, LogType.Error,
  2703. $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]接口出错!错误信息:" + resultStr);
  2704. }
  2705. //上传结束节拍
  2706. switch (oEEType) {
  2707. case "1":
  2708. Enum.TryParse("2", out deviceOEE);
  2709. result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2710. break;
  2711. case "3":
  2712. Enum.TryParse("4", out deviceOEE);
  2713. result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2714. break;
  2715. case "5":
  2716. Enum.TryParse("6", out deviceOEE);
  2717. result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2718. break;
  2719. }
  2720. if (result.Item1 == 1)
  2721. {
  2722. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]上传成功!");
  2723. }
  2724. else {
  2725. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]接口出错!错误信息:" + result.Item2);
  2726. }
  2727. }
  2728. catch (Exception ex)
  2729. {
  2730. string str = ex.StackTrace;
  2731. AddMessage_Station(stationNameStr, LogType.Error,
  2732. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  2733. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2734. }
  2735. }
  2736. /// <summary>
  2737. /// 去除常见特殊字符,如 \r, \n, \t 等
  2738. /// </summary>
  2739. /// <param name="format"></param>
  2740. /// <returns></returns>
  2741. private static string FormatStrbyPLC(string format)
  2742. {
  2743. string cleanedString = "";
  2744. if (!string.IsNullOrEmpty(format))
  2745. {
  2746. cleanedString = Regex.Replace(format, @"[\r\n\t]", "");
  2747. }
  2748. return cleanedString;
  2749. }
  2750. #endregion
  2751. #region S1
  2752. /// <summary>
  2753. /// [S1] 壳体清洁上料装备
  2754. /// </summary>
  2755. /// <param name="plcNo">PLC编号</param>
  2756. private void ReadStation_S1(int plcNo)
  2757. {
  2758. string stationCode = "[OP10]";
  2759. string stationName = "壳体清洁上料";
  2760. string stationNameStr = stationCode + stationName;
  2761. string tagBaseName = "g_OP10_MES"; //标签变量名称
  2762. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2763. string tagAgvCommName = "agvCommFrmPC";
  2764. string tagiotComnName = "iotData";
  2765. string tagBarsetName = "BarcodeSet";
  2766. string CarrierBarcode = "";
  2767. string ProductBarcode = "";
  2768. // 触发信号字典
  2769. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2770. s1PLCSignal_Old.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2771. // PLC数据字典 赋值
  2772. s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2773. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  2774. (int, string) result;
  2775. while (true)
  2776. {
  2777. try
  2778. {
  2779. if (!GlobalContext._IsCon_Funs1)
  2780. {
  2781. UpdatePLCMonitor(1, plcNo, 0);
  2782. continue;
  2783. }
  2784. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2785. {
  2786. Stopwatch stopwatch1 = new Stopwatch();
  2787. Stopwatch stopwatch2 = new Stopwatch();
  2788. stopwatch1.Start();
  2789. stopwatch2.Start();
  2790. #region 一次性读取所有数据
  2791. // 一次性读取所有数据
  2792. result = FunsEip[plcNo]
  2793. .Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2794. if (result.Item1 != 0)
  2795. {
  2796. //richTextBox1.AppendText("\n" + strRet);
  2797. }
  2798. else
  2799. {
  2800. //richTextBox1.AppendText("\n" + "读取成功");
  2801. stPLC_MesData.BarcodeSet.strProductBarcode =
  2802. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  2803. stPLC_MesData.BarcodeSet.strPartBarcode =
  2804. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  2805. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  2806. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  2807. stPLC_MesData.BarcodeSet.strPCBBarcode =
  2808. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  2809. //设备状态
  2810. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  2811. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  2812. ? XiaomiDeviceState.Unknown
  2813. : (XiaomiDeviceState)xmDeviceStateInt;
  2814. // 载具SN
  2815. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode.ToString();
  2816. // 物料码(物料码还未绑定载具SN时必填)
  2817. ProductBarcode = stPLC_MesData.BarcodeSet.strProductBarcode;
  2818. // 节拍
  2819. s1PLCData["a1OEEType"] = stPLC_MesData.iotData.BeatAction;
  2820. //报警信息
  2821. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  2822. }
  2823. #endregion 一次性读取所有数据
  2824. stopwatch2.Stop();
  2825. #region 进站
  2826. try
  2827. {
  2828. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2829. {
  2830. lock (lockObj)
  2831. {
  2832. if (!ProgressState)
  2833. {
  2834. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  2835. ProgressState = true;
  2836. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData,
  2837. tagBaseName + "." + tagMesCommName, out ProgressState));
  2838. }
  2839. }
  2840. }
  2841. }
  2842. catch (Exception ex)
  2843. {
  2844. ProgressState = false;
  2845. string str = ex.StackTrace;
  2846. AddMessage_Station(stationNameStr, LogType.Error,
  2847. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2848. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2849. }
  2850. #endregion 进站
  2851. #region 出站
  2852. try
  2853. {
  2854. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2855. {
  2856. lock (lockObj)
  2857. {
  2858. if (!ProgressState)
  2859. {
  2860. ProgressState = true;
  2861. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData,
  2862. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  2863. out ProgressState));
  2864. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  2865. uuid = "";
  2866. }
  2867. }
  2868. }
  2869. }
  2870. catch (Exception ex)
  2871. {
  2872. ProgressState = false;
  2873. string str = ex.StackTrace;
  2874. AddMessage_Station(stationNameStr, LogType.Error,
  2875. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2876. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2877. }
  2878. #endregion 出站
  2879. #region 节拍接口
  2880. try
  2881. {
  2882. if (stPLC_MesData.iotData.BeatAction > 0)
  2883. {
  2884. int a1OEEType = Convert.ToInt32(s1PLCData["a1OEEType"]);
  2885. int a1OEETypeGOld = Convert.ToInt32(s1PLCSignal_Old["a1OEEType"]);
  2886. //若设备紧急复原后节拍重置
  2887. if (a1OEEType == 1)
  2888. {
  2889. a1OEETypeGOld = 0;
  2890. }
  2891. if (a1OEEType != a1OEETypeGOld)
  2892. {
  2893. //如果上位机告诉PLC NG,PLC节拍会直接从1跳到4
  2894. if (a1OEETypeGOld <= 2 && a1OEEType == 4)
  2895. {
  2896. Task.Run(() =>
  2897. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  2898. CarrierBarcode,
  2899. stPLC_MesData.iotData));
  2900. }
  2901. else
  2902. {
  2903. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  2904. if ((a1OEETypeGOld == 1 && a1OEEType != 2) ||
  2905. (a1OEETypeGOld == 3 && a1OEEType != 4) ||
  2906. (a1OEETypeGOld == 5 && a1OEEType != 6))
  2907. {
  2908. //写入PLC
  2909. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2910. iotData.machineState = stPLC_MesData.iotData.machineState;
  2911. iotData.work_type = stPLC_MesData.iotData.work_type;
  2912. iotData.testStatus = stPLC_MesData.iotData.testStatus;
  2913. iotData.BeatAction = stPLC_MesData.iotData.BeatAction;
  2914. iotData.beatReturn = 2; //NG
  2915. iotData.fault_codes = stPLC_MesData.iotData.fault_codes;
  2916. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  2917. 1,
  2918. iotData);
  2919. AddMessage(LogType.Info,
  2920. stationNameStr +
  2921. $"_节拍接口-- 设备本次上传节拍[{a1OEEType}],未上传节拍[{a1OEETypeGOld}]的结束信号,请检查;总用时" +
  2922. stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  2923. stopwatch2.ElapsedMilliseconds +
  2924. "ms");
  2925. return;
  2926. }
  2927. else
  2928. {
  2929. Task.Run(() => 通用节拍接口(plcNo, stationNameStr,
  2930. tagBaseName + "." + tagiotComnName,
  2931. CarrierBarcode, stPLC_MesData.iotData));
  2932. }
  2933. }
  2934. }
  2935. }
  2936. s1PLCSignal_Old["a1OEEType"] = s1PLCData["a1OEEType"];
  2937. }
  2938. catch (Exception ex)
  2939. {
  2940. string str = ex.StackTrace;
  2941. AddMessage_Station(stationNameStr, LogType.Error,
  2942. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  2943. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2944. }
  2945. #endregion
  2946. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2947. stopwatch1.Stop();
  2948. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2949. }
  2950. else
  2951. {
  2952. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2953. AddMessage_Station(stationNameStr, LogType.Info,
  2954. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2955. FunsEip[plcNo].Connect(); // 重连
  2956. }
  2957. }
  2958. catch (Exception ex)
  2959. {
  2960. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2961. AddMessage_Station(stationNameStr, LogType.Error,
  2962. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2963. }
  2964. Thread.Sleep(IntervalReadPLC);
  2965. }
  2966. }
  2967. /// <summary>
  2968. /// [S1] 壳体清洁上料 - 进站
  2969. /// </summary>
  2970. /// <param name="plcNo">PLC编号</param>
  2971. /// <param name="stationNameStr">工站全称</param>
  2972. /// <param name="stPLC_MesData"></param>
  2973. /// <param name="tagMesCommName"></param>
  2974. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  2975. out bool ProgressState)
  2976. {
  2977. Stopwatch stopwatch1 = new Stopwatch();
  2978. Stopwatch stopwatch2 = new Stopwatch();
  2979. try
  2980. {
  2981. stopwatch1.Start();
  2982. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2983. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  2984. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2985. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  2986. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  2987. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2988. bool pass = a1Result == 1;
  2989. if (string.IsNullOrEmpty(sn))
  2990. {
  2991. ProgressState = false;
  2992. AddMessage(LogType.Error, $"{stationNameStr}_未能查到产品码");
  2993. Thread.Sleep(10000);
  2994. return;
  2995. }
  2996. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  2997. // sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2998. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2999. //绑定载具和产品
  3000. ResponseMessage message = new ResponseMessage();
  3001. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  3002. if (message.result == false)
  3003. {
  3004. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  3005. }
  3006. // 产品SN进站
  3007. List<TestItem> item = new List<TestItem>();
  3008. stopwatch2.Start();
  3009. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3010. item, MachineId, StationId, pass, "01-SLOT-01");
  3011. stopwatch2.Stop();
  3012. //指令执行结果 1:OK 110:失败
  3013. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3014. if (mesResultFrmWeb == 1)
  3015. {
  3016. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3017. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3018. }
  3019. //进站结果写入PLC
  3020. CommandFromPLC resultToPlC = new CommandFromPLC();
  3021. resultToPlC.cmd = 0;
  3022. resultToPlC.cmdParam = 0;
  3023. resultToPlC.cmdResult = mesResultFrmWeb;
  3024. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3025. }
  3026. catch (Exception ex)
  3027. {
  3028. string str = ex.StackTrace;
  3029. AddMessage(LogType.Error,
  3030. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3031. str.Length - str.LastIndexOf("\\") - 1));
  3032. CommandFromPLC resultToPlC = new CommandFromPLC();
  3033. resultToPlC.cmd = 0;
  3034. resultToPlC.cmdParam = 0; //指令参数
  3035. resultToPlC.cmdResult = 110;
  3036. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3037. }
  3038. stopwatch1.Stop();
  3039. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3040. AddMessage(LogType.Info,
  3041. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3042. stopwatch2.ElapsedMilliseconds + "ms");
  3043. ProgressState = false;
  3044. }
  3045. /// <summary>
  3046. /// [S1] 壳体清洁上料 - 出站接口
  3047. /// </summary>
  3048. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  3049. string stationCode, string stationName, out bool ProgressState)
  3050. {
  3051. Stopwatch stopwatch1 = new Stopwatch();
  3052. Stopwatch stopwatch2 = new Stopwatch();
  3053. test_item_num = 0; //iot 过站明细序号
  3054. try
  3055. {
  3056. stopwatch1.Start();
  3057. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3058. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3059. string processItem = stationName; // 项目
  3060. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3061. string supplierCode = ""; // 供应商代码
  3062. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  3063. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  3064. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  3065. string sn = string.Empty;
  3066. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3067. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  3068. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  3069. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3070. //a1Result = 1;
  3071. bool pass = a1Result == 1;
  3072. //根据载具码获取产品码
  3073. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3074. if (string.IsNullOrEmpty(strProductBarcode))
  3075. {
  3076. ProgressState = false;
  3077. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3078. Thread.Sleep(10000);
  3079. return;
  3080. }
  3081. sn = strProductBarcode;
  3082. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3083. List<TestItem> items = new List<TestItem>();
  3084. items.Add(new TestItem()
  3085. {
  3086. Parameter_name = "载具码",
  3087. Parameter_value = CarrierBarcode,
  3088. Parameter_unit = ""
  3089. });
  3090. items.Add(new TestItem()
  3091. {
  3092. Parameter_name = "产品码",
  3093. Parameter_value = sn,
  3094. Parameter_unit = ""
  3095. });
  3096. #region 转换过站明细字符串
  3097. //创建字典
  3098. var dic = new Dictionary<string, string>();
  3099. // 获取结构体类型
  3100. FieldInfo[] fields = typeof(OP10_DataSet_t).GetFields();
  3101. // 遍历变量名转换成字典描述
  3102. foreach (FieldInfo field in fields)
  3103. {
  3104. //获取枚举描述
  3105. string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
  3106. typeof(XiaomiMESEnum_ProcessData.Enum_10_ProcessData));
  3107. //获取过站明细的值
  3108. object valueObj = field.GetValue(stPLC_MesData.mesData);
  3109. dic.Add(name, valueObj.ToString());
  3110. }
  3111. string paramJson = JsonConvert.SerializeObject(dic);
  3112. #endregion
  3113. //出站接口
  3114. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3115. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  3116. MachineId, StationId, "", paramJson);
  3117. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3118. if (mesResultFrmWeb == 1)
  3119. {
  3120. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3121. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  3122. }
  3123. stopwatch2.Start();
  3124. //进站结果写入PLC
  3125. CommandFromPLC resultToPlC = new CommandFromPLC();
  3126. resultToPlC.cmd = 0;
  3127. resultToPlC.cmdParam = 0; //指令参数
  3128. resultToPlC.cmdResult = mesResultFrmWeb;
  3129. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3130. stopwatch2.Stop();
  3131. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3132. //保存PLC返回MES数据到本地
  3133. ResponseMessage message = new ResponseMessage();
  3134. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  3135. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress,
  3136. stPLC_MesData.mesData.fCleanSpeed,
  3137. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime,
  3138. stPLC_MesData.mesData.nCleanCount,
  3139. stPLC_MesData.mesData.nRemainCount);
  3140. if (message.result == false)
  3141. {
  3142. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3143. }
  3144. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  3145. }
  3146. catch (Exception ex)
  3147. {
  3148. stopwatch2.Start();
  3149. CommandFromPLC resultToPlC = new CommandFromPLC();
  3150. resultToPlC.cmd = 0;
  3151. resultToPlC.cmdParam = 0; //指令参数
  3152. resultToPlC.cmdResult = 110;
  3153. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3154. stopwatch2.Stop();
  3155. string str = ex.StackTrace;
  3156. AddMessage(LogType.Error,
  3157. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3158. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3159. }
  3160. stopwatch1.Stop();
  3161. AddMessage(LogType.Info,
  3162. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3163. stopwatch2.ElapsedMilliseconds + "ms");
  3164. ProgressState = false;
  3165. }
  3166. #endregion
  3167. #region S2
  3168. /// <summary>
  3169. /// [S2] 上盖板上料装备
  3170. /// </summary>
  3171. /// <param name="plcNo">PLC编号</param>
  3172. private void ReadStation_S2(int plcNo)
  3173. {
  3174. string stationCode = "[OP20]";
  3175. string stationName = "上盖板上料装备";
  3176. string stationNameStr = stationCode + stationName;
  3177. string tagBaseName = "g_OP20_MES"; //标签变量名称
  3178. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3179. string tagAgvCommName = "agvCommFrmPC";
  3180. string tagiotComnName = "iotData";
  3181. string tagBarsetName = "BarcodeSet";
  3182. string CarrierBarcode = "";
  3183. // 触发信号字典
  3184. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  3185. s2PLCSignal_Old.Add("a2OEEType", 0); // 节拍类型(plc写入)
  3186. // PLC数据字典 赋值
  3187. s2PLCData.Add("a2OEEType", 0); // 节拍类型(plc写入)
  3188. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  3189. (int, string) result;
  3190. while (true)
  3191. {
  3192. try
  3193. {
  3194. if (!GlobalContext._IsCon_Funs2)
  3195. {
  3196. UpdatePLCMonitor(1, plcNo, 0);
  3197. continue;
  3198. }
  3199. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3200. {
  3201. Stopwatch stopwatch1 = new Stopwatch();
  3202. Stopwatch stopwatch2 = new Stopwatch();
  3203. stopwatch1.Start();
  3204. stopwatch2.Start();
  3205. #region 一次性读取所有数据
  3206. // 一次性读取所有数据
  3207. result = FunsEip[plcNo]
  3208. .Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3209. if (result.Item1 != 0)
  3210. {
  3211. //richTextBox1.AppendText("\n" + strRet);
  3212. }
  3213. else
  3214. {
  3215. //richTextBox1.AppendText("\n" + "读取成功");
  3216. stPLC_MesData.BarcodeSet.strProductBarcode =
  3217. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  3218. stPLC_MesData.BarcodeSet.strPartBarcode =
  3219. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  3220. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  3221. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  3222. stPLC_MesData.BarcodeSet.strPCBBarcode =
  3223. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  3224. //设备状态
  3225. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  3226. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  3227. ? XiaomiDeviceState.Unknown
  3228. : (XiaomiDeviceState)xmDeviceStateInt;
  3229. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  3230. s2PLCData["a2OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  3231. //报警信息
  3232. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  3233. }
  3234. #endregion 一次性读取所有数据
  3235. stopwatch2.Stop();
  3236. #region 进站
  3237. try
  3238. {
  3239. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3240. {
  3241. lock (lockObj)
  3242. {
  3243. if (!ProgressState)
  3244. {
  3245. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3246. ProgressState = true;
  3247. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData,
  3248. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  3249. out ProgressState));
  3250. }
  3251. }
  3252. }
  3253. }
  3254. catch (Exception ex)
  3255. {
  3256. ProgressState = false;
  3257. string str = ex.StackTrace;
  3258. AddMessage_Station(stationNameStr, LogType.Error,
  3259. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3260. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3261. }
  3262. #endregion 进站
  3263. #region 出站
  3264. try
  3265. {
  3266. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3267. {
  3268. lock (lockObj)
  3269. {
  3270. if (!ProgressState)
  3271. {
  3272. ProgressState = true;
  3273. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData,
  3274. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  3275. out ProgressState));
  3276. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  3277. uuid = "";
  3278. }
  3279. }
  3280. }
  3281. }
  3282. catch (Exception ex)
  3283. {
  3284. ProgressState = false;
  3285. string str = ex.StackTrace;
  3286. AddMessage_Station(stationNameStr, LogType.Error,
  3287. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3288. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3289. }
  3290. #endregion 出站
  3291. #region 节拍接口
  3292. try
  3293. {
  3294. if (stPLC_MesData.iotData.BeatAction > 0)
  3295. {
  3296. int a2OEEType = Convert.ToInt32(s2PLCData["a2OEEType"]);
  3297. int a2OEETypeGOld = Convert.ToInt32(s2PLCSignal_Old["a2OEEType"]);
  3298. //若设备紧急复原后节拍重置
  3299. if (a2OEEType == 1)
  3300. {
  3301. a2OEETypeGOld = 0;
  3302. }
  3303. if (a2OEEType != a2OEETypeGOld)
  3304. {
  3305. //如果上位机告诉PLC NG,PLC节拍会直接从1跳到4
  3306. if (a2OEETypeGOld <= 2 && a2OEEType == 4)
  3307. {
  3308. Task.Run(() =>
  3309. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  3310. CarrierBarcode,
  3311. stPLC_MesData.iotData));
  3312. }
  3313. else
  3314. {
  3315. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  3316. if ((a2OEETypeGOld == 1 && a2OEEType != 2) ||
  3317. (a2OEETypeGOld == 3 && a2OEEType != 4) ||
  3318. (a2OEETypeGOld == 5 && a2OEEType != 6))
  3319. {
  3320. //写入PLC
  3321. IoT_DataSet_t iotData = new IoT_DataSet_t();
  3322. iotData.machineState = stPLC_MesData.iotData.machineState;
  3323. iotData.work_type = stPLC_MesData.iotData.work_type;
  3324. iotData.testStatus = stPLC_MesData.iotData.testStatus;
  3325. iotData.BeatAction = stPLC_MesData.iotData.BeatAction;
  3326. iotData.beatReturn = 2; //NG
  3327. iotData.fault_codes = stPLC_MesData.iotData.fault_codes;
  3328. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  3329. AddMessage(LogType.Info,
  3330. stationNameStr +
  3331. $"_节拍接口-- 设备本次上传节拍[{a2OEEType}],未上传节拍[{a2OEETypeGOld}]的结束信号,请检查;总用时" +
  3332. stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3333. stopwatch2.ElapsedMilliseconds +
  3334. "ms");
  3335. return;
  3336. }
  3337. else
  3338. {
  3339. Task.Run(() => 通用节拍接口(plcNo, stationNameStr,
  3340. tagBaseName + "." + tagiotComnName,
  3341. CarrierBarcode, stPLC_MesData.iotData));
  3342. //Task.Run(() =>
  3343. // S2节拍接口(plcNo, stationNameStr, tagBaseName,
  3344. // stPLC_MesData.iotData));
  3345. }
  3346. }
  3347. }
  3348. }
  3349. s2PLCSignal_Old["a2OEEType"] = s2PLCData["a2OEEType"];
  3350. }
  3351. catch (Exception ex)
  3352. {
  3353. string str = ex.StackTrace;
  3354. AddMessage_Station(stationNameStr, LogType.Error,
  3355. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3356. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3357. }
  3358. #endregion
  3359. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3360. stopwatch1.Stop();
  3361. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  3362. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3363. }
  3364. else
  3365. {
  3366. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3367. AddMessage_Station(stationNameStr, LogType.Info,
  3368. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3369. FunsEip[plcNo].Connect();
  3370. }
  3371. }
  3372. catch (Exception ex)
  3373. {
  3374. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3375. AddMessage_Station(stationNameStr, LogType.Error,
  3376. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3377. //Funs[plcNo].ReConnect();
  3378. }
  3379. Thread.Sleep(IntervalReadPLC);
  3380. }
  3381. }
  3382. /// <summary>
  3383. /// [S2] 上盖板上料装备
  3384. /// </summary>
  3385. /// <param name="plcNo">PLC编号</param>
  3386. /// <param name="stationNameStr">工站全称</param>
  3387. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  3388. string tagBarsetName, out bool ProgressState)
  3389. {
  3390. Stopwatch stopwatch1 = new Stopwatch();
  3391. Stopwatch stopwatch2 = new Stopwatch();
  3392. try
  3393. {
  3394. stopwatch1.Start();
  3395. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3396. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  3397. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  3398. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3399. bool pass = a1Result == 1;
  3400. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  3401. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  3402. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3403. //根据载具码获取产品码
  3404. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3405. if (string.IsNullOrEmpty(strProductBarcode))
  3406. {
  3407. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3408. }
  3409. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  3410. //if (sn != strProductBarcode)
  3411. //{
  3412. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  3413. //}
  3414. sn = strProductBarcode;
  3415. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3416. // 产品SN(物料码)校验
  3417. List<TestItem> item = new List<TestItem>();
  3418. stopwatch2.Start();
  3419. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3420. item, MachineId, StationId, pass, "01-SLOT-01");
  3421. stopwatch2.Stop();
  3422. //指令执行结果 1:OK 110:失败
  3423. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3424. if (mesResultFrmWeb == 1)
  3425. {
  3426. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3427. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3428. }
  3429. //进站结果写入PLC
  3430. CommandFromPLC resultToPlC = new CommandFromPLC();
  3431. resultToPlC.cmd = 0;
  3432. resultToPlC.cmdParam = 0; //指令参数
  3433. resultToPlC.cmdResult = mesResultFrmWeb;
  3434. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3435. }
  3436. catch (Exception ex)
  3437. {
  3438. string str = ex.StackTrace;
  3439. AddMessage(LogType.Error,
  3440. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3441. str.Length - str.LastIndexOf("\\") - 1));
  3442. CommandFromPLC resultToPlC = new CommandFromPLC();
  3443. resultToPlC.cmd = 0;
  3444. resultToPlC.cmdParam = 0; //指令参数
  3445. resultToPlC.cmdResult = 110;
  3446. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3447. }
  3448. stopwatch1.Stop();
  3449. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3450. AddMessage(LogType.Info,
  3451. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3452. stopwatch2.ElapsedMilliseconds + "ms");
  3453. ProgressState = false;
  3454. }
  3455. /// <summary>
  3456. /// [S2] 上盖板上料装备 - 出站接口
  3457. /// </summary>
  3458. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  3459. string stationCode, string stationName, out bool ProgressState)
  3460. {
  3461. Stopwatch stopwatch1 = new Stopwatch();
  3462. Stopwatch stopwatch2 = new Stopwatch();
  3463. test_item_num = 0; //iot 过站明细序号
  3464. try
  3465. {
  3466. stopwatch1.Start();
  3467. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3468. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3469. string processItem = stationName; // 测试项目
  3470. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3471. string supplierCode = ""; // 供应商代码
  3472. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3473. string batch_num = GlobalContext.BatchNumber; // 批次号
  3474. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3475. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3476. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3477. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  3478. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  3479. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  3480. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3481. bool pass = a1Result == 1;
  3482. //根据载具码获取产品码
  3483. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3484. if (string.IsNullOrEmpty(strProductBarcode))
  3485. {
  3486. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3487. ProgressState = false;
  3488. Thread.Sleep(10000);
  3489. return;
  3490. }
  3491. sn = strProductBarcode;
  3492. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3493. List<TestItem> items = new List<TestItem>();
  3494. items.Add(new TestItem()
  3495. {
  3496. Parameter_name = "载具码",
  3497. Parameter_value = CarrierBarcode,
  3498. Parameter_unit = ""
  3499. });
  3500. items.Add(new TestItem()
  3501. {
  3502. Parameter_name = "产品码",
  3503. Parameter_value = sn,
  3504. Parameter_unit = ""
  3505. });
  3506. items.Add(new TestItem()
  3507. {
  3508. Parameter_name = "部件码",
  3509. Parameter_value = PartBarcode,
  3510. Parameter_unit = ""
  3511. });
  3512. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3513. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3514. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  3515. MachineId, StationId, PartBarcode, paramJson);
  3516. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3517. if (mesResultFrmWeb == 1)
  3518. {
  3519. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3520. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  3521. }
  3522. stopwatch2.Start();
  3523. //进站结果写入PLC
  3524. CommandFromPLC resultToPlC = new CommandFromPLC();
  3525. resultToPlC.cmd = 0;
  3526. resultToPlC.cmdParam = 0; //指令参数
  3527. resultToPlC.cmdResult = mesResultFrmWeb;
  3528. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3529. stopwatch2.Stop();
  3530. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3531. //保存PLC返回MES数据到本地
  3532. ResponseMessage message = new ResponseMessage();
  3533. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  3534. stPLC_MesData.mesData.nRemainCount);
  3535. if (message.result == false)
  3536. {
  3537. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3538. }
  3539. if (!string.IsNullOrEmpty(PartBarcode))
  3540. {
  3541. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  3542. if (message.result == false)
  3543. {
  3544. AddMessage(LogType.Error, message.text);
  3545. }
  3546. }
  3547. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3548. }
  3549. catch (Exception ex)
  3550. {
  3551. stopwatch2.Start();
  3552. CommandFromPLC resultToPlC = new CommandFromPLC();
  3553. resultToPlC.cmd = 0;
  3554. resultToPlC.cmdParam = 0; //指令参数
  3555. resultToPlC.cmdResult = 110;
  3556. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3557. stopwatch2.Stop();
  3558. string str = ex.StackTrace;
  3559. AddMessage(LogType.Error,
  3560. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3561. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3562. }
  3563. stopwatch1.Stop();
  3564. AddMessage(LogType.Info,
  3565. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3566. stopwatch2.ElapsedMilliseconds + "ms");
  3567. ProgressState = false;
  3568. }
  3569. #endregion
  3570. #region S3
  3571. /// <summary>
  3572. /// [S3] 点散热胶装备
  3573. /// </summary>
  3574. /// <param name="plcNo">PLC编号</param>
  3575. private void ReadStation_S3(int plcNo)
  3576. {
  3577. string stationCode = "[OP30]";
  3578. string stationName = "点散热胶装备";
  3579. string stationNameStr = stationCode + stationName;
  3580. string tagBaseName = "g_OP30_MES"; //标签变量名称
  3581. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3582. string tagAgvCommName = "agvCommFrmPC";
  3583. string tagiotComnName = "iotData";
  3584. string tagBarsetName = "BarcodeSet";
  3585. string CarrierBarcode_Left = "";
  3586. string CarrierBarcode_Right = "";
  3587. s3PLCSignal_Old.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
  3588. s3PLCSignal_Old.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
  3589. // PLC数据字典 赋值
  3590. s3PLCData.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
  3591. s3PLCData.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
  3592. s5PLCData.Add("OEETypeFlag_left", 0); // 节拍标识 0 不上传 ,1 上传
  3593. s5PLCData.Add("OEETypeFlag_right", 0); // 节拍标识 0 不上传 ,1 上传
  3594. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  3595. (int, string) result;
  3596. while (true)
  3597. {
  3598. try
  3599. {
  3600. if (!GlobalContext._IsCon_Funs2)
  3601. {
  3602. UpdatePLCMonitor(1, plcNo, 0);
  3603. continue;
  3604. }
  3605. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3606. {
  3607. Stopwatch stopwatch1 = new Stopwatch();
  3608. Stopwatch stopwatch2 = new Stopwatch();
  3609. stopwatch1.Start();
  3610. stopwatch2.Start();
  3611. #region 一次性读取所有数据
  3612. // 一次性读取所有数据
  3613. result = FunsEip[plcNo]
  3614. .Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3615. if (result.Item1 != 0)
  3616. {
  3617. //richTextBox1.AppendText("\n" + strRet);
  3618. }
  3619. else
  3620. {
  3621. //测试数据
  3622. //stPLC_MesData.Left.mesCommFrmPLC.cmd = 2;
  3623. //stPLC_MesData.Left.BarcodeSet.strCarrierBarcode = "A123456";
  3624. //stPLC_MesData.Left.BarcodeSet.strPCBBarcode = "A1507V000239";
  3625. //stPLC_MesData.Left.iotData.BeatAction = 1;
  3626. //stPLC_MesData.Left.iotData.BeatAction = 2;
  3627. //stPLC_MesData.Left.BarcodeSet.strCarrierBarcode = "A123456";
  3628. #region 去除扫码产生的特殊字符
  3629. stPLC_MesData.Left.BarcodeSet.strProductBarcode =
  3630. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strProductBarcode);
  3631. stPLC_MesData.Left.BarcodeSet.strPartBarcode =
  3632. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPartBarcode);
  3633. stPLC_MesData.Left.BarcodeSet.strCarrierBarcode =
  3634. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strCarrierBarcode);
  3635. stPLC_MesData.Left.BarcodeSet.strPCBBarcode =
  3636. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPCBBarcode);
  3637. stPLC_MesData.Right.BarcodeSet.strProductBarcode =
  3638. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strProductBarcode);
  3639. stPLC_MesData.Right.BarcodeSet.strPartBarcode =
  3640. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPartBarcode);
  3641. stPLC_MesData.Right.BarcodeSet.strCarrierBarcode =
  3642. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strCarrierBarcode);
  3643. stPLC_MesData.Right.BarcodeSet.strPCBBarcode =
  3644. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPCBBarcode);
  3645. #endregion
  3646. //richTextBox1.AppendText("\n" + "读取成功");
  3647. //设备状态
  3648. int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  3649. int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  3650. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  3651. ? XiaomiDeviceState.Unknown
  3652. : (XiaomiDeviceState)xmDeviceStateInt_L;
  3653. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  3654. ? XiaomiDeviceState.Unknown
  3655. : (XiaomiDeviceState)xmDeviceStateInt_R;
  3656. //载具SN
  3657. CarrierBarcode_Left = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode;
  3658. CarrierBarcode_Right = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode;
  3659. // 节拍
  3660. s3PLCData["a3OEEType_left"] = stPLC_MesData.Left.iotData.BeatAction;
  3661. s3PLCData["a3OEEType_right"] = stPLC_MesData.Right.iotData.BeatAction;
  3662. //报警信息
  3663. _FaultDatas = stPLC_MesData.Left.iotData.fault_codes;
  3664. _FaultDatas2 = stPLC_MesData.Right.iotData.fault_codes;
  3665. }
  3666. #endregion 一次性读取所有数据
  3667. stopwatch2.Stop();
  3668. #region 左边进站
  3669. try
  3670. {
  3671. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3672. {
  3673. lock (lockObj)
  3674. {
  3675. if (!ProgressState)
  3676. {
  3677. stationCode = "[OP31]";
  3678. stationName = "点散热胶装备1";
  3679. stationNameStr = stationCode + stationName;
  3680. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3681. ProgressState = true;
  3682. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left,
  3683. tagBaseName + ".Left." + tagMesCommName,
  3684. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  3685. }
  3686. }
  3687. }
  3688. }
  3689. catch (Exception ex)
  3690. {
  3691. ProgressState = false;
  3692. string str = ex.StackTrace;
  3693. AddMessage_Station(stationNameStr, LogType.Error,
  3694. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3695. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3696. }
  3697. #endregion 左边进站
  3698. #region 左边出站
  3699. try
  3700. {
  3701. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3702. {
  3703. lock (lockObj)
  3704. {
  3705. if (!ProgressState)
  3706. {
  3707. stationCode = "[OP31]";
  3708. stationName = "点散热胶装备1";
  3709. stationNameStr = stationCode + stationName;
  3710. ProgressState = true;
  3711. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left,
  3712. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  3713. out ProgressState));
  3714. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  3715. uuid = "";
  3716. }
  3717. }
  3718. }
  3719. }
  3720. catch (Exception ex)
  3721. {
  3722. ProgressState = false;
  3723. string str = ex.StackTrace;
  3724. AddMessage_Station(stationNameStr, LogType.Error,
  3725. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3726. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3727. }
  3728. #endregion 左边出站
  3729. #region 右边进站
  3730. try
  3731. {
  3732. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3733. {
  3734. lock (lockObj)
  3735. {
  3736. if (!ProgressState)
  3737. {
  3738. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3739. stationCode = "[OP32]";
  3740. stationName = "点散热胶装备2";
  3741. stationNameStr = stationCode + stationName;
  3742. ProgressState = true;
  3743. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right,
  3744. tagBaseName + ".Right." + tagMesCommName,
  3745. tagBaseName + ".Right." + tagBarsetName, "Right", out ProgressState));
  3746. }
  3747. }
  3748. }
  3749. }
  3750. catch (Exception ex)
  3751. {
  3752. ProgressState = false;
  3753. string str = ex.StackTrace;
  3754. AddMessage_Station(stationNameStr, LogType.Error,
  3755. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3756. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3757. }
  3758. #endregion 右边进站
  3759. #region 右边出站
  3760. try
  3761. {
  3762. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3763. {
  3764. lock (lockObj)
  3765. {
  3766. if (!ProgressState)
  3767. {
  3768. stationCode = "[OP32]";
  3769. stationName = "点散热胶装备2";
  3770. stationNameStr = stationCode + stationName;
  3771. ProgressState = true;
  3772. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right,
  3773. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  3774. out ProgressState));
  3775. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  3776. uuid = "";
  3777. }
  3778. }
  3779. }
  3780. }
  3781. catch (Exception ex)
  3782. {
  3783. string str = ex.StackTrace;
  3784. AddMessage_Station(stationNameStr, LogType.Error,
  3785. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3786. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3787. }
  3788. #endregion 右边出站
  3789. #region 节拍接口
  3790. try
  3791. {
  3792. #region 左工位 节拍
  3793. if (stPLC_MesData.Left.iotData.BeatAction > 0)
  3794. {
  3795. stationCode = "[OP31]";
  3796. stationName = "点散热胶装备1";
  3797. stationNameStr = stationCode + stationName;
  3798. int a3OEEType_left = Convert.ToInt32(s3PLCData["a3OEEType_left"]);
  3799. int a3OEETypeGOld_left = Convert.ToInt32(s3PLCSignal_Old["a3OEEType_left"]);
  3800. if (a3OEEType_left != a3OEETypeGOld_left)
  3801. {
  3802. s3PLCData["OEETypeFlag_left"] = "1";
  3803. }
  3804. else {
  3805. s3PLCData["OEETypeFlag_left"] = "0";
  3806. }
  3807. if (s3PLCData["OEETypeFlag_left"].ToString() == "1" && (a3OEEType_left == 1 || a3OEEType_left == 3 || a3OEEType_left == 5))
  3808. {
  3809. Task.Run(() => 通用节拍接口(plcNo, stationNameStr,
  3810. tagBaseName + ".Left." + tagiotComnName, CarrierBarcode_Left,
  3811. stPLC_MesData.Left.iotData));
  3812. }
  3813. }
  3814. s3PLCSignal_Old["a3OEEType_left"] = s3PLCData["a3OEEType_left"];
  3815. #endregion 左工位 节拍
  3816. #region 右工位 节拍
  3817. if (stPLC_MesData.Right.iotData.BeatAction > 0)
  3818. {
  3819. stationCode = "[OP32]";
  3820. stationName = "点散热胶装备2";
  3821. stationNameStr = stationCode + stationName;
  3822. int a3OEEType_right = Convert.ToInt32(s3PLCData["a3OEEType_right"]);
  3823. int a3OEETypeGOld_right = Convert.ToInt32(s3PLCSignal_Old["a3OEEType_right"]);
  3824. if (a3OEEType_right != a3OEETypeGOld_right)
  3825. {
  3826. s3PLCData["OEETypeFlag_right"] = "1";
  3827. }
  3828. else
  3829. {
  3830. s3PLCData["OEETypeFlag_right"] = "0";
  3831. }
  3832. if (s3PLCData["OEETypeFlag_right"].ToString() == "1" && (a3OEEType_right == 1 || a3OEEType_right == 3 || a3OEEType_right == 5))
  3833. {
  3834. Task.Run(() => 通用节拍接口(plcNo, stationNameStr,
  3835. tagBaseName + ".Right." + tagiotComnName, CarrierBarcode_Right,
  3836. stPLC_MesData.Right.iotData));
  3837. s3PLCSignal_Old["a3OEEType_right"] = s3PLCData["a3OEEType_right"];
  3838. }
  3839. }
  3840. #endregion 右工位 节拍
  3841. }
  3842. catch (Exception ex)
  3843. {
  3844. string str = ex.StackTrace;
  3845. AddMessage_Station(stationNameStr, LogType.Error,
  3846. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3847. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3848. }
  3849. #endregion
  3850. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3851. stopwatch1.Stop();
  3852. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  3853. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3854. }
  3855. else
  3856. {
  3857. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3858. AddMessage_Station(stationNameStr, LogType.Info,
  3859. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3860. FunsEip[plcNo].Connect();
  3861. }
  3862. }
  3863. catch (Exception ex)
  3864. {
  3865. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3866. AddMessage_Station(stationNameStr, LogType.Error,
  3867. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3868. //Funs[plcNo].ReConnect();
  3869. }
  3870. Thread.Sleep(IntervalReadPLC);
  3871. }
  3872. }
  3873. /// <summary>
  3874. /// [S3] 点散热胶装备 - 进站
  3875. /// </summary>
  3876. /// <param name="plcNo">PLC编号</param>
  3877. /// <param name="stationNameStr">工站全称</param>
  3878. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  3879. string tagBarsetName, string direction, out bool ProgressState)
  3880. {
  3881. Stopwatch stopwatch1 = new Stopwatch();
  3882. Stopwatch stopwatch2 = new Stopwatch();
  3883. try
  3884. {
  3885. stopwatch1.Start();
  3886. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  3887. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3888. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  3889. string StationId = string.Empty;
  3890. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3891. bool pass = a1Result == 1;
  3892. string slot = "";
  3893. if (direction == "Left")
  3894. {
  3895. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  3896. slot = "01-SLOT-01";
  3897. }
  3898. if (direction == "Right")
  3899. {
  3900. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  3901. slot = "01-SLOT-02";
  3902. }
  3903. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3904. //载具码验证产品码
  3905. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3906. if (string.IsNullOrEmpty(strProductBarcode))
  3907. {
  3908. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3909. }
  3910. sn = strProductBarcode;
  3911. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  3912. // 产品SN(物料码)校验
  3913. List<TestItem> item = new List<TestItem>();
  3914. stopwatch2.Start();
  3915. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3916. item, MachineId, StationId, pass, slot);
  3917. stopwatch2.Stop();
  3918. //指令执行结果 1:OK 110:失败
  3919. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3920. if (mesResultFrmWeb == 1)
  3921. {
  3922. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3923. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3924. }
  3925. //进站结果写入PLC
  3926. CommandFromPLC resultToPlC = new CommandFromPLC();
  3927. resultToPlC.cmd = 0;
  3928. resultToPlC.cmdParam = 0; //指令参数
  3929. resultToPlC.cmdResult = mesResultFrmWeb;
  3930. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3931. }
  3932. catch (Exception ex)
  3933. {
  3934. string str = ex.StackTrace;
  3935. AddMessage(LogType.Error,
  3936. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3937. str.Length - str.LastIndexOf("\\") - 1));
  3938. CommandFromPLC resultToPlC = new CommandFromPLC();
  3939. resultToPlC.cmd = 0;
  3940. resultToPlC.cmdParam = 0; //指令参数
  3941. resultToPlC.cmdResult = 110;
  3942. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3943. }
  3944. stopwatch1.Stop();
  3945. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3946. AddMessage(LogType.Info,
  3947. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3948. stopwatch2.ElapsedMilliseconds + "ms");
  3949. ProgressState = false;
  3950. }
  3951. /// <summary>
  3952. /// [S3] 点散热胶装备 - 出站
  3953. /// </summary>
  3954. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  3955. string stationCode, string stationName, string direction, out bool ProgressState)
  3956. {
  3957. Stopwatch stopwatch1 = new Stopwatch();
  3958. Stopwatch stopwatch2 = new Stopwatch();
  3959. test_item_num = 0; //iot 过站明细序号
  3960. try
  3961. {
  3962. stopwatch1.Start();
  3963. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  3964. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3965. string processItem = stationName; // 测试项目
  3966. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3967. string supplierCode = ""; // 供应商代码
  3968. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3969. string batch_num = GlobalContext.BatchNumber; // 批次号
  3970. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3971. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3972. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3973. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  3974. string StationId = string.Empty;
  3975. if (direction == "Left")
  3976. {
  3977. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  3978. }
  3979. if (direction == "Right")
  3980. {
  3981. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  3982. }
  3983. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3984. bool pass = a1Result == 1;
  3985. //根据载具码获取产品码
  3986. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3987. if (string.IsNullOrEmpty(strProductBarcode))
  3988. {
  3989. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3990. ProgressState = false;
  3991. Thread.Sleep(10000);
  3992. return;
  3993. }
  3994. sn = strProductBarcode;
  3995. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3996. List<TestItem> items = new List<TestItem>();
  3997. items.Add(new TestItem()
  3998. {
  3999. Parameter_name = "载具码",
  4000. Parameter_value = CarrierBarcode,
  4001. Parameter_unit = ""
  4002. });
  4003. items.Add(new TestItem()
  4004. {
  4005. Parameter_name = "产品码",
  4006. Parameter_value = sn,
  4007. Parameter_unit = ""
  4008. });
  4009. //if (direction == "Right")
  4010. //{
  4011. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4012. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4013. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  4014. MachineId, StationId, "", paramJson, direction);
  4015. //}
  4016. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4017. if (mesResultFrmWeb == 1)
  4018. {
  4019. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  4020. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  4021. }
  4022. stopwatch2.Start();
  4023. //进站结果写入PLC
  4024. CommandFromPLC resultToPlC = new CommandFromPLC();
  4025. resultToPlC.cmd = 0;
  4026. resultToPlC.cmdParam = 0; //指令参数
  4027. resultToPlC.cmdResult = mesResultFrmWeb;
  4028. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4029. stopwatch2.Stop();
  4030. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  4031. //保存PLC返回MES数据到本地
  4032. ResponseMessage message = new ResponseMessage();
  4033. if (direction == "Left")
  4034. {
  4035. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  4036. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  4037. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  4038. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  4039. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  4040. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  4041. if (message.result == false)
  4042. {
  4043. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4044. }
  4045. }
  4046. if (direction == "Right")
  4047. {
  4048. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  4049. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  4050. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  4051. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  4052. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  4053. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  4054. if (message.result == false)
  4055. {
  4056. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4057. }
  4058. }
  4059. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4060. }
  4061. catch (Exception ex)
  4062. {
  4063. stopwatch2.Start();
  4064. CommandFromPLC resultToPlC = new CommandFromPLC();
  4065. resultToPlC.cmd = 0;
  4066. resultToPlC.cmdParam = 0; //指令参数
  4067. resultToPlC.cmdResult = 110;
  4068. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4069. stopwatch2.Stop();
  4070. string str = ex.StackTrace;
  4071. AddMessage(LogType.Error,
  4072. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4073. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4074. }
  4075. stopwatch1.Stop();
  4076. AddMessage(LogType.Info,
  4077. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4078. stopwatch2.ElapsedMilliseconds + "ms");
  4079. ProgressState = false;
  4080. }
  4081. #endregion S3
  4082. #region S4
  4083. /// <summary>
  4084. /// [S4] 点胶检测设备
  4085. /// </summary>
  4086. /// <param name="plcNo">PLC编号</param>
  4087. private void ReadStation_S4(int plcNo)
  4088. {
  4089. string stationCode = "[OP40]";
  4090. string stationName = "胶线检测";
  4091. string stationNameStr = stationCode + stationName;
  4092. string tagBaseName = "g_OP40_MES"; //标签变量名称
  4093. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4094. string tagAgvCommName = "agvCommFrmPC";
  4095. string tagiotComnName = "iotData";
  4096. string tagBarsetName = "BarcodeSet";
  4097. string CarrierBarcode = "";
  4098. // 触发信号字典
  4099. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4100. s4PLCSignal_Old.Add("a4OEEType", 0); // 节拍类型(plc写入)
  4101. // PLC数据字典 赋值
  4102. s4PLCData.Add("a4OEEType", 0); // 节拍类型(plc写入)
  4103. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  4104. (int, string) result;
  4105. while (true)
  4106. {
  4107. try
  4108. {
  4109. if (!GlobalContext._IsCon_Funs1)
  4110. {
  4111. UpdatePLCMonitor(1, plcNo, 0);
  4112. continue;
  4113. }
  4114. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4115. {
  4116. Stopwatch stopwatch1 = new Stopwatch();
  4117. Stopwatch stopwatch2 = new Stopwatch();
  4118. stopwatch1.Start();
  4119. stopwatch2.Start();
  4120. #region 一次性读取所有数据
  4121. // 一次性读取所有数据
  4122. result = FunsEip[plcNo]
  4123. .Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4124. if (result.Item1 != 0)
  4125. {
  4126. //richTextBox1.AppendText("\n" + strRet);
  4127. }
  4128. else
  4129. {
  4130. //去除扫码产生的特殊字符
  4131. stPLC_MesData.BarcodeSet.strProductBarcode =
  4132. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  4133. stPLC_MesData.BarcodeSet.strPartBarcode =
  4134. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  4135. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  4136. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  4137. stPLC_MesData.BarcodeSet.strPCBBarcode =
  4138. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  4139. //richTextBox1.AppendText("\n" + "读取成功");
  4140. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  4141. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  4142. ? XiaomiDeviceState.Unknown
  4143. : (XiaomiDeviceState)xmDeviceStateInt;
  4144. // 载具SN
  4145. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode;
  4146. // 节拍
  4147. s4PLCData["a4OEEType"] = stPLC_MesData.iotData.BeatAction;
  4148. //报警信息
  4149. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  4150. }
  4151. #endregion 一次性读取所有数据
  4152. stopwatch2.Stop();
  4153. #region 进站
  4154. try
  4155. {
  4156. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4157. {
  4158. lock (lockObj)
  4159. {
  4160. if (!ProgressState)
  4161. {
  4162. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  4163. ProgressState = true;
  4164. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData,
  4165. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  4166. out ProgressState));
  4167. }
  4168. }
  4169. }
  4170. }
  4171. catch (Exception ex)
  4172. {
  4173. ProgressState = false;
  4174. string str = ex.StackTrace;
  4175. AddMessage_Station(stationNameStr, LogType.Error,
  4176. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4177. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4178. }
  4179. #endregion 进站
  4180. #region 出站
  4181. try
  4182. {
  4183. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4184. {
  4185. lock (lockObj)
  4186. {
  4187. if (!ProgressState)
  4188. {
  4189. ProgressState = true;
  4190. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData,
  4191. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4192. out ProgressState));
  4193. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4194. uuid = "";
  4195. }
  4196. }
  4197. }
  4198. }
  4199. catch (Exception ex)
  4200. {
  4201. string str = ex.StackTrace;
  4202. AddMessage_Station(stationNameStr, LogType.Error,
  4203. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4204. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4205. }
  4206. #endregion 出站
  4207. #region 节拍接口
  4208. try
  4209. {
  4210. if (stPLC_MesData.iotData.BeatAction > 0)
  4211. {
  4212. int a4OEEType = Convert.ToInt32(s4PLCData["a4OEEType"]);
  4213. int a4OEETypeGOld = Convert.ToInt32(s4PLCSignal_Old["a4OEEType"]);
  4214. //若设备紧急复原后节拍重置
  4215. if (a4OEEType == 1)
  4216. {
  4217. a4OEETypeGOld = 0;
  4218. }
  4219. if (a4OEEType != a4OEETypeGOld)
  4220. {
  4221. if (a4OEETypeGOld <= 2 && a4OEEType == 4)
  4222. {
  4223. Task.Run(() =>
  4224. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  4225. CarrierBarcode,
  4226. stPLC_MesData.iotData));
  4227. }
  4228. else
  4229. {
  4230. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  4231. if ((a4OEETypeGOld == 1 && a4OEEType != 2) ||
  4232. (a4OEETypeGOld == 3 && a4OEEType != 4) ||
  4233. (a4OEETypeGOld == 5 && a4OEEType != 6))
  4234. {
  4235. //写入PLC
  4236. stPLC_MesData.iotData.beatReturn = 2; //NG
  4237. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1,
  4238. stPLC_MesData.iotData);
  4239. AddMessage(LogType.Info,
  4240. stationNameStr +
  4241. $"_节拍接口-- 设备本次上传节拍[{a4OEEType}],未上传节拍[{a4OEETypeGOld}]的结束信号,请检查;总用时" +
  4242. stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4243. stopwatch2.ElapsedMilliseconds +
  4244. "ms");
  4245. return;
  4246. }
  4247. else
  4248. {
  4249. Task.Run(() => 通用节拍接口(plcNo, stationNameStr,
  4250. tagBaseName + "." + tagiotComnName, CarrierBarcode,
  4251. stPLC_MesData.iotData));
  4252. //Task.Run(() =>
  4253. // S4节拍接口(plcNo, stationNameStr, tagBaseName,
  4254. // stPLC_MesData.iotData));
  4255. }
  4256. }
  4257. }
  4258. }
  4259. s4PLCSignal_Old["a4OEEType"] = s4PLCData["a4OEEType"];
  4260. }
  4261. catch (Exception ex)
  4262. {
  4263. string str = ex.StackTrace;
  4264. AddMessage_Station(stationNameStr, LogType.Error,
  4265. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4266. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4267. }
  4268. #endregion
  4269. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4270. stopwatch1.Stop();
  4271. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4272. }
  4273. else
  4274. {
  4275. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4276. AddMessage_Station(stationNameStr, LogType.Info,
  4277. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4278. FunsEip[plcNo].Connect(); // 重连
  4279. }
  4280. }
  4281. catch (Exception ex)
  4282. {
  4283. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4284. AddMessage_Station(stationNameStr, LogType.Error,
  4285. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4286. }
  4287. Thread.Sleep(IntervalReadPLC);
  4288. }
  4289. }
  4290. /// <summary>
  4291. /// [S4] 点胶检测设备 - 进站
  4292. /// </summary>
  4293. /// <param name="plcNo">PLC编号</param>
  4294. /// <param name="stationNameStr">工站全称</param>
  4295. /// <param name="stPLC_MesData"></param>
  4296. /// <param name="tagMesCommName"></param>
  4297. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  4298. string tagBarsetName, out bool ProgressState)
  4299. {
  4300. Stopwatch stopwatch1 = new Stopwatch();
  4301. Stopwatch stopwatch2 = new Stopwatch();
  4302. test_item_num = 0; //iot 过站明细序号
  4303. try
  4304. {
  4305. stopwatch1.Start();
  4306. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4307. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4308. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  4309. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  4310. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4311. bool pass = a1Result == 1;
  4312. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4313. //载具码验证产品码
  4314. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4315. if (string.IsNullOrEmpty(strProductBarcode))
  4316. {
  4317. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4318. ProgressState = false;
  4319. Thread.Sleep(10000);
  4320. return;
  4321. }
  4322. sn = strProductBarcode;
  4323. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4324. // 产品SN(物料码)校验
  4325. List<TestItem> item = new List<TestItem>();
  4326. stopwatch2.Start();
  4327. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  4328. item, MachineId, StationId, pass, "01-SLOT-01");
  4329. stopwatch2.Stop();
  4330. //指令执行结果 1:OK 110:失败
  4331. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4332. if (mesResultFrmWeb == 1)
  4333. {
  4334. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  4335. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  4336. }
  4337. //进站结果写入PLC
  4338. CommandFromPLC resultToPlC = new CommandFromPLC();
  4339. resultToPlC.cmd = 0;
  4340. resultToPlC.cmdParam = 0; //指令参数
  4341. resultToPlC.cmdResult = mesResultFrmWeb;
  4342. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4343. }
  4344. catch (Exception ex)
  4345. {
  4346. string str = ex.StackTrace;
  4347. AddMessage(LogType.Error,
  4348. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4349. str.Length - str.LastIndexOf("\\") - 1));
  4350. CommandFromPLC resultToPlC = new CommandFromPLC();
  4351. resultToPlC.cmd = 0;
  4352. resultToPlC.cmdParam = 0; //指令参数
  4353. resultToPlC.cmdResult = 110;
  4354. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4355. }
  4356. stopwatch1.Stop();
  4357. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4358. AddMessage(LogType.Info,
  4359. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4360. stopwatch2.ElapsedMilliseconds + "ms");
  4361. ProgressState = false;
  4362. }
  4363. /// <summary>
  4364. /// [S4] 点胶检测设备 - 出站接口
  4365. /// </summary>
  4366. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  4367. string stationCode, string stationName, out bool ProgressState)
  4368. {
  4369. Stopwatch stopwatch1 = new Stopwatch();
  4370. Stopwatch stopwatch2 = new Stopwatch();
  4371. test_item_num = 0; //iot 过站明细序号
  4372. try
  4373. {
  4374. stopwatch1.Start();
  4375. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4376. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4377. string processItem = stationName; // 测试项目
  4378. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4379. string supplierCode = ""; // 供应商代码
  4380. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4381. string batch_num = GlobalContext.BatchNumber; // 批次号
  4382. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4383. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4384. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4385. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  4386. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  4387. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4388. bool pass = a1Result == 1;
  4389. //根据载具码获取产品码
  4390. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4391. if (string.IsNullOrEmpty(strProductBarcode))
  4392. {
  4393. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4394. ProgressState = false;
  4395. Thread.Sleep(10000);
  4396. return;
  4397. }
  4398. sn = strProductBarcode;
  4399. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4400. List<TestItem> items = new List<TestItem>();
  4401. items.Add(new TestItem()
  4402. {
  4403. Parameter_name = "载具码",
  4404. Parameter_value = CarrierBarcode,
  4405. Parameter_unit = ""
  4406. });
  4407. items.Add(new TestItem()
  4408. {
  4409. Parameter_name = "产品码",
  4410. Parameter_value = sn,
  4411. Parameter_unit = ""
  4412. });
  4413. #region 上传图片
  4414. if (GlobalContext.MQTTIsSendUpFile)
  4415. {
  4416. string[] urlarry = GlobalContext.UpFilePath.Split(",");
  4417. fileUploadData.fileData.Clear();
  4418. foreach (var item in urlarry)
  4419. {
  4420. if (!string.IsNullOrEmpty(item))
  4421. {
  4422. //上传图片
  4423. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName, a1Result,
  4424. item, uuid).Result;
  4425. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  4426. }
  4427. }
  4428. }
  4429. #endregion
  4430. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4431. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4432. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode,
  4433. "01-SLOT-01", MachineId, StationId, "", paramJson);
  4434. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4435. if (mesResultFrmWeb == 1)
  4436. {
  4437. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  4438. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  4439. }
  4440. stopwatch2.Start();
  4441. //进站结果写入PLC
  4442. CommandFromPLC resultToPlC = new CommandFromPLC();
  4443. resultToPlC.cmd = 0;
  4444. resultToPlC.cmdParam = 0; //指令参数
  4445. resultToPlC.cmdResult = mesResultFrmWeb;
  4446. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4447. stopwatch2.Stop();
  4448. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4449. //保存PLC返回MES数据到本地
  4450. ResponseMessage message = new ResponseMessage();
  4451. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  4452. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  4453. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  4454. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  4455. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  4456. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  4457. if (message.result == false)
  4458. {
  4459. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4460. }
  4461. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4462. }
  4463. catch (Exception ex)
  4464. {
  4465. stopwatch2.Start();
  4466. CommandFromPLC resultToPlC = new CommandFromPLC();
  4467. resultToPlC.cmd = 0;
  4468. resultToPlC.cmdParam = 0; //指令参数
  4469. resultToPlC.cmdResult = 110;
  4470. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4471. stopwatch2.Stop();
  4472. string str = ex.StackTrace;
  4473. AddMessage(LogType.Error,
  4474. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4475. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4476. }
  4477. stopwatch1.Stop();
  4478. AddMessage(LogType.Info,
  4479. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4480. stopwatch2.ElapsedMilliseconds + "ms");
  4481. ProgressState = false;
  4482. }
  4483. private void S4节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  4484. {
  4485. Stopwatch stopwatch1 = new Stopwatch();
  4486. Stopwatch stopwatch2 = new Stopwatch();
  4487. string resultStr = string.Empty;
  4488. try
  4489. {
  4490. stopwatch1.Start();
  4491. string oEEType = ((int)s1PLCData["a4OEEType"]).ToString(); // 节拍类型(plc写入)
  4492. string a40EEPartNo = (string)s1PLCData["a40EEPartNo"]; // 物料码
  4493. a40EEPartNo = a40EEPartNo.Replace("\0", "");
  4494. string a50EEVehicleCode = (string)s1PLCData["a50EEVehicleCode"]; // 载具SN
  4495. a50EEVehicleCode = a50EEVehicleCode.Replace("\0", "");
  4496. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4497. if (!actionBool)
  4498. {
  4499. stopwatch2.Start();
  4500. //写入PLC
  4501. iot_data.beatReturn = 2; //NG
  4502. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4503. stopwatch2.Stop();
  4504. AddMessage(LogType.Info,
  4505. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  4506. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4507. return;
  4508. }
  4509. //作业开始后要有物料和载具信息
  4510. if (string.IsNullOrEmpty(a40EEPartNo) && string.IsNullOrEmpty(a50EEVehicleCode) &&
  4511. Convert.ToInt32(oEEType) > 2)
  4512. {
  4513. stopwatch2.Start();
  4514. //写入PLC
  4515. iot_data.beatReturn = 2; //NG
  4516. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4517. stopwatch2.Stop();
  4518. AddMessage_Station(stationNameStr, LogType.Info,
  4519. stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  4520. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4521. return;
  4522. }
  4523. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a40EEPartNo))
  4524. {
  4525. stopwatch2.Start();
  4526. //写入PLC
  4527. iot_data.beatReturn = 2; //NG
  4528. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4529. stopwatch2.Stop();
  4530. AddMessage_Station(stationNameStr, LogType.Info,
  4531. stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  4532. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4533. return;
  4534. }
  4535. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a50EEVehicleCode))
  4536. {
  4537. stopwatch2.Start();
  4538. //写入PLC
  4539. iot_data.beatReturn = 2; //NG
  4540. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4541. stopwatch2.Stop();
  4542. AddMessage_Station(stationNameStr, LogType.Info,
  4543. stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  4544. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4545. return;
  4546. }
  4547. short _result = 0;
  4548. // 上传OEE
  4549. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a40EEPartNo, a50EEVehicleCode);
  4550. _result = result.Item1;
  4551. resultStr = result.Item2;
  4552. if (_result == 1)
  4553. {
  4554. stopwatch2.Start();
  4555. //写入PLC
  4556. iot_data.beatReturn = 1; //OK
  4557. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4558. OnMessage(LogType.Info,
  4559. $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  4560. stopwatch2.Stop();
  4561. }
  4562. else
  4563. {
  4564. stopwatch2.Start();
  4565. //写入PLC
  4566. iot_data.beatReturn = 2; //NG
  4567. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4568. stopwatch2.Stop();
  4569. AddMessage_Station(stationNameStr, LogType.Error,
  4570. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  4571. }
  4572. }
  4573. catch (Exception ex)
  4574. {
  4575. string str = ex.StackTrace;
  4576. AddMessage_Station(stationNameStr, LogType.Error,
  4577. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  4578. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4579. // MES_Flag
  4580. stopwatch2.Start();
  4581. //写入PLC
  4582. iot_data.beatReturn = 2; //NG
  4583. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4584. stopwatch2.Stop();
  4585. }
  4586. stopwatch1.Stop();
  4587. AddMessage(LogType.Info,
  4588. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4589. stopwatch2.ElapsedMilliseconds + "ms");
  4590. }
  4591. #endregion
  4592. #region S5
  4593. private static bool isPCBStation = false; //控制PCB是否进出站的标识
  4594. /// <summary>
  4595. /// [S5] 点胶检测设备
  4596. /// </summary>
  4597. /// <param name="plcNo">PLC编号</param>
  4598. private void ReadStation_S5(int plcNo)
  4599. {
  4600. string stationCode = "[OP50]";
  4601. string stationName = "ADD板上料组装装备";
  4602. string stationNameStr = stationCode + stationName;
  4603. string tagBaseName = "g_OP50_MES"; //标签变量名称
  4604. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4605. string tagAgvCommName = "agvCommFrmPC";
  4606. string tagiotComnName = "iotData";
  4607. string tagBarsetName = "BarcodeSet";
  4608. string pcbBarcode = "";
  4609. string pcbBarcodeOld = "";
  4610. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  4611. string CarrierBarcode = "";
  4612. // 触发信号字典
  4613. s5PLCSignal_Old.Add("a5OEEType", 0); // 节拍类型(plc写入)
  4614. // PLC数据字典 赋值
  4615. s5PLCData.Add("a5OEEType", 0); // 节拍类型(plc写入)
  4616. s5PLCData.Add("OEETypeFlag", 0); // 节拍标识 0 不上传 ,1 上传
  4617. (int, string) result;
  4618. while (true)
  4619. {
  4620. try
  4621. {
  4622. if (!GlobalContext._IsCon_Funs1)
  4623. {
  4624. UpdatePLCMonitor(1, plcNo, 0);
  4625. continue;
  4626. }
  4627. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4628. {
  4629. Stopwatch stopwatch1 = new Stopwatch();
  4630. Stopwatch stopwatch2 = new Stopwatch();
  4631. stopwatch1.Start();
  4632. stopwatch2.Start();
  4633. #region 一次性读取所有数据
  4634. // 一次性读取所有数据
  4635. result = FunsEip[plcNo]
  4636. .Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4637. if (result.Item1 != 0)
  4638. {
  4639. }
  4640. else
  4641. {
  4642. //测试数据
  4643. //stPLC_MesData.mesCommFrmPLC.cmd = 2;
  4644. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
  4645. //stPLC_MesData.BarcodeSet.strPCBBarcode = "A1507V000239";
  4646. //stPLC_MesData.iotData.BeatAction = 1;
  4647. //stPLC_MesData.iotData.BeatAction = 2;
  4648. //stPLC_MesData.iotData.BeatAction = 3;
  4649. //stPLC_MesData.iotData.BeatAction = 4;
  4650. //stPLC_MesData.iotData.BeatAction = 5;
  4651. //stPLC_MesData.iotData.BeatAction = 6;
  4652. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
  4653. #region 去除扫码产生的特殊字符
  4654. stPLC_MesData.BarcodeSet.strProductBarcode =
  4655. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  4656. stPLC_MesData.BarcodeSet.strPartBarcode =
  4657. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  4658. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  4659. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  4660. stPLC_MesData.BarcodeSet.strPCBBarcode =
  4661. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  4662. #endregion
  4663. //richTextBox1.AppendText("\n" + "读取成功");
  4664. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  4665. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  4666. ? XiaomiDeviceState.Unknown
  4667. : (XiaomiDeviceState)xmDeviceStateInt;
  4668. // 节拍
  4669. s5PLCData["a5OEEType"] = stPLC_MesData.iotData.BeatAction;
  4670. //载具码
  4671. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode.ToString();
  4672. //报警信息
  4673. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  4674. }
  4675. #endregion 一次性读取所有数据
  4676. stopwatch2.Stop();
  4677. #region 进站
  4678. try
  4679. {
  4680. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4681. {
  4682. lock (lockObj)
  4683. {
  4684. if (!ProgressState)
  4685. {
  4686. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  4687. ProgressState = true;
  4688. string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
  4689. if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
  4690. {
  4691. ProgressState = true;
  4692. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData,
  4693. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  4694. out ProgressState));
  4695. }
  4696. }
  4697. }
  4698. }
  4699. }
  4700. catch (Exception ex)
  4701. {
  4702. ProgressState = false;
  4703. string str = ex.StackTrace;
  4704. AddMessage_Station(stationNameStr, LogType.Error,
  4705. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4706. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4707. }
  4708. #endregion 进站
  4709. #region 出站
  4710. try
  4711. {
  4712. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4713. {
  4714. lock (lockObj)
  4715. {
  4716. if (!ProgressState)
  4717. {
  4718. ProgressState = true;
  4719. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData,
  4720. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4721. out ProgressState));
  4722. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4723. uuid = "";
  4724. }
  4725. }
  4726. }
  4727. }
  4728. catch (Exception ex)
  4729. {
  4730. ProgressState = false;
  4731. string str = ex.StackTrace;
  4732. AddMessage_Station(stationNameStr, LogType.Error,
  4733. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4734. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4735. }
  4736. #endregion 出站
  4737. #region 节拍接口
  4738. try
  4739. {
  4740. if (stPLC_MesData.iotData.BeatAction > 0)
  4741. {
  4742. int a5OEEType = Convert.ToInt32(s5PLCData["a5OEEType"]);
  4743. int a5OEETypeGOld = Convert.ToInt32(s5PLCSignal_Old["a5OEEType"]);
  4744. if (a5OEEType != a5OEETypeGOld)
  4745. {
  4746. s5PLCData["OEETypeFlag"] = "1";
  4747. }
  4748. else {
  4749. s5PLCData["OEETypeFlag"] = "0";
  4750. }
  4751. if (s5PLCData["OEETypeFlag"] == "1" && (a5OEEType==1 || a5OEEType == 3 || a5OEEType == 5))
  4752. {
  4753. Task.Run(() => 通用节拍接口(plcNo, stationNameStr,
  4754. tagBaseName + "." + tagiotComnName, CarrierBarcode,
  4755. stPLC_MesData.iotData));
  4756. s5PLCSignal_Old["a5OEEType"] = s5PLCData["a5OEEType"];
  4757. }
  4758. }
  4759. }
  4760. catch (Exception ex)
  4761. {
  4762. string str = ex.StackTrace;
  4763. AddMessage_Station(stationNameStr, LogType.Error,
  4764. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4765. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4766. }
  4767. #endregion
  4768. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4769. stopwatch1.Stop();
  4770. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4771. }
  4772. else
  4773. {
  4774. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4775. AddMessage_Station(stationNameStr, LogType.Info,
  4776. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4777. FunsEip[plcNo].Connect(); // 重连
  4778. }
  4779. }
  4780. catch (Exception ex)
  4781. {
  4782. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4783. AddMessage_Station(stationNameStr, LogType.Error,
  4784. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4785. }
  4786. Thread.Sleep(IntervalReadPLC);
  4787. }
  4788. }
  4789. /// <summary>
  4790. /// [S5] 点胶检测设备 - 进站
  4791. /// </summary>
  4792. /// <param name="plcNo">PLC编号</param>
  4793. /// <param name="stationNameStr">工站全称</param>
  4794. /// <param name="stPLC_MesData"></param>
  4795. /// <param name="tagMesCommName"></param>
  4796. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  4797. string tagBarsetName, out bool ProgressState)
  4798. {
  4799. Stopwatch stopwatch1 = new Stopwatch();
  4800. Stopwatch stopwatch2 = new Stopwatch();
  4801. try
  4802. {
  4803. stopwatch1.Start();
  4804. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4805. //string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4806. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  4807. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  4808. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  4809. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码
  4810. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  4811. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4812. bool pass = a1Result == 1;
  4813. AddMessage(LogType.Info, $"ADD板编码(PCB码):{pcbBarcode}");
  4814. //绑定载具和产品
  4815. ResponseMessage message = new ResponseMessage();
  4816. message = SQLHelper.PCBCarrierBind(strCarrierBarcode, pcbBarcode);
  4817. if (message.result == false)
  4818. {
  4819. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  4820. }
  4821. //载具码验证产品码 //载具码验证产品码
  4822. //string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4823. //if (string.IsNullOrEmpty(strProductBarcode))
  4824. //{
  4825. // AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4826. //}
  4827. //sn = strProductBarcode;
  4828. //AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4829. // 产品SN(物料码)校验
  4830. List<TestItem> item = new List<TestItem>();
  4831. stopwatch2.Start();
  4832. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  4833. pcbBarcode,
  4834. item, MachineId, StationId, pass, "01-SLOT-01");
  4835. stopwatch2.Stop();
  4836. //指令执行结果 1:OK 110:失败
  4837. byte mesResultFrmWeb = (byte)(result == 1 ? 2 : 120);
  4838. if (mesResultFrmWeb == 1)
  4839. {
  4840. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  4841. }
  4842. //进站结果写入PLC
  4843. CommandFromPLC resultToPlC = new CommandFromPLC();
  4844. resultToPlC.cmd = 0;
  4845. resultToPlC.cmdParam = 0; //指令参数
  4846. resultToPlC.cmdResult = mesResultFrmWeb;
  4847. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4848. }
  4849. catch (Exception ex)
  4850. {
  4851. string str = ex.StackTrace;
  4852. AddMessage(LogType.Error,
  4853. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4854. str.Length - str.LastIndexOf("\\") - 1));
  4855. CommandFromPLC resultToPlC = new CommandFromPLC();
  4856. resultToPlC.cmd = 0;
  4857. resultToPlC.cmdParam = 0; //指令参数
  4858. resultToPlC.cmdResult = 110;
  4859. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4860. }
  4861. stopwatch1.Stop();
  4862. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4863. AddMessage(LogType.Info,
  4864. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4865. stopwatch2.ElapsedMilliseconds + "ms");
  4866. ProgressState = false;
  4867. }
  4868. /// <summary>
  4869. /// [S5] 点胶检测设备 - 出站接口
  4870. /// </summary>
  4871. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  4872. string stationCode, string stationName, out bool ProgressState)
  4873. {
  4874. Stopwatch stopwatch1 = new Stopwatch();
  4875. Stopwatch stopwatch2 = new Stopwatch();
  4876. test_item_num = 0; //iot 过站明细序号
  4877. try
  4878. {
  4879. stopwatch1.Start();
  4880. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4881. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4882. string processItem = stationName; // 测试项目
  4883. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4884. string supplierCode = ""; // 供应商代码
  4885. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4886. string batch_num = GlobalContext.BatchNumber; // 批次号
  4887. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4888. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4889. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 部件条码;
  4890. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4891. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  4892. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  4893. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  4894. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4895. bool pass = a1Result == 1;
  4896. CommandFromPLC resultToPlC = new CommandFromPLC();
  4897. //根据载具码获取产品码
  4898. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4899. if (string.IsNullOrEmpty(strProductBarcode))
  4900. {
  4901. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4902. ProgressState = false;
  4903. //写入PLC
  4904. resultToPlC.cmd = 0;
  4905. resultToPlC.cmdParam = 0; //指令参数
  4906. resultToPlC.cmdResult = 110;
  4907. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4908. return;
  4909. }
  4910. stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
  4911. sn = strProductBarcode;
  4912. //数据库绑定载具和PCB
  4913. ResponseMessage message = new ResponseMessage();
  4914. message = SQLHelper.PCBCarrierBind(CarrierBarcode, pcbBarcode);
  4915. if (message.result == false)
  4916. {
  4917. AddMessage(LogType.Error, stationNameStr + "_PCB码数据库绑定失败,错误:" + message.text);
  4918. ProgressState = true; //防止循环报错
  4919. return;
  4920. }
  4921. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn};PCB码:{pcbBarcode}");
  4922. List<TestItem> items = new List<TestItem>();
  4923. items.Add(new TestItem()
  4924. {
  4925. Parameter_name = "载具码",
  4926. Parameter_value = CarrierBarcode,
  4927. Parameter_unit = ""
  4928. });
  4929. items.Add(new TestItem()
  4930. {
  4931. Parameter_name = "产品码",
  4932. Parameter_value = sn,
  4933. Parameter_unit = ""
  4934. });
  4935. items.Add(new TestItem()
  4936. {
  4937. Parameter_name = "PCB码",
  4938. Parameter_value = pcbBarcode,
  4939. Parameter_unit = ""
  4940. });
  4941. #region 上传图片
  4942. if (GlobalContext.MQTTIsSendUpFile)
  4943. {
  4944. string[] urlarry = GlobalContext.UpFilePath.Split(",");
  4945. fileUploadData.fileData.Clear();
  4946. foreach (var item in urlarry)
  4947. {
  4948. if (!string.IsNullOrEmpty(item))
  4949. {
  4950. //上传图片
  4951. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName, a1Result,
  4952. item, uuid).Result;
  4953. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  4954. }
  4955. }
  4956. }
  4957. #endregion
  4958. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4959. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4960. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  4961. MachineId, StationId, PartBarcode, paramJson);
  4962. byte mesResultFrmWeb = 0;
  4963. if (stPLC_MesData.mesCommFrmPLC.cmdParam == 2)
  4964. {
  4965. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem, workorder_code,
  4966. batch_num
  4967. , mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId,
  4968. PartBarcode, paramJson);
  4969. }
  4970. else if (stPLC_MesData.mesCommFrmPLC.cmdParam == 1)
  4971. {
  4972. result1 = PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  4973. }
  4974. mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4975. //进站结果写入PLC
  4976. resultToPlC.cmd = 0;
  4977. resultToPlC.cmdParam = 0; //指令参数
  4978. resultToPlC.cmdResult = mesResultFrmWeb;
  4979. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4980. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4981. //保存PLC返回MES数据到本地
  4982. //ResponseMessage message = new ResponseMessage();
  4983. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  4984. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB,
  4985. stPLC_MesData.mesData.nRemainCount, "");
  4986. if (message.result == false)
  4987. {
  4988. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4989. }
  4990. //保存部件码信息
  4991. if (!string.IsNullOrEmpty(PartBarcode))
  4992. {
  4993. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  4994. if (message.result == false)
  4995. {
  4996. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  4997. }
  4998. }
  4999. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  5000. }
  5001. catch (Exception ex)
  5002. {
  5003. stopwatch2.Start();
  5004. CommandFromPLC resultToPlC = new CommandFromPLC();
  5005. resultToPlC.cmd = 0;
  5006. resultToPlC.cmdParam = 0; //指令参数
  5007. resultToPlC.cmdResult = 110;
  5008. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5009. stopwatch2.Stop();
  5010. string str = ex.StackTrace;
  5011. AddMessage(LogType.Error,
  5012. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5013. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5014. }
  5015. stopwatch1.Stop();
  5016. AddMessage(LogType.Info,
  5017. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5018. stopwatch2.ElapsedMilliseconds + "ms");
  5019. ProgressState = false;
  5020. }
  5021. private int S5_PCB进出站(OP50_MesData_t stPLC_MesData, int plcNo, string stationNameStr, string tagBaseName,
  5022. string tagMesCommName)
  5023. {
  5024. string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
  5025. if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
  5026. {
  5027. string strProductBarcode =
  5028. SQLHelper.GetProductBarcodeByCarrierCode(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  5029. stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
  5030. CommandFromPLC resultToPlC = new CommandFromPLC();
  5031. resultToPlC.cmd = 0;
  5032. resultToPlC.cmdParam = 0; //指令参数
  5033. if (GlobalContext.IsSendStationIn)
  5034. {
  5035. #region 进站
  5036. //int res1 = PCBStationInData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  5037. //if (res1 == 1)
  5038. //{
  5039. // resultToPlC.cmdResult = 2;//OK
  5040. // WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  5041. //}
  5042. //else
  5043. //{
  5044. // resultToPlC.cmdResult = 120;
  5045. // WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  5046. // return 2;
  5047. //}
  5048. #endregion
  5049. #region 出站
  5050. int res2 = PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  5051. if (res2 == 1)
  5052. {
  5053. resultToPlC.cmdResult = 2; //OK
  5054. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  5055. return 1;
  5056. }
  5057. else
  5058. {
  5059. resultToPlC.cmdResult = 120;
  5060. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  5061. return 2;
  5062. }
  5063. #endregion
  5064. }
  5065. else
  5066. {
  5067. return 2;
  5068. }
  5069. }
  5070. else
  5071. {
  5072. return 2;
  5073. }
  5074. }
  5075. private void S5节拍接口(int plcNo, string stationNameStr, string tagMesCommName, string CarrierBarcode,
  5076. IoT_DataSet_t iot_data)
  5077. {
  5078. Stopwatch stopwatch1 = new Stopwatch();
  5079. Stopwatch stopwatch2 = new Stopwatch();
  5080. string resultStr = string.Empty;
  5081. try
  5082. {
  5083. stopwatch1.Start();
  5084. string oEEType = iot_data.BeatAction.ToString(); // 节拍类型(plc写入)
  5085. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode); //产品SN
  5086. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5087. if (!actionBool)
  5088. {
  5089. stopwatch2.Start();
  5090. //写入PLC
  5091. IoT_DataSet_t iotData = new IoT_DataSet_t();
  5092. iotData.machineState = iot_data.machineState;
  5093. iotData.work_type = iot_data.work_type;
  5094. iotData.testStatus = iot_data.testStatus;
  5095. iotData.BeatAction = iot_data.BeatAction;
  5096. iotData.beatReturn = 2; //NG
  5097. iotData.fault_codes = iot_data.fault_codes;
  5098. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  5099. stopwatch2.Stop();
  5100. AddMessage(LogType.Info,
  5101. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  5102. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5103. return;
  5104. }
  5105. //作业开始后要有物料和载具信息
  5106. if (string.IsNullOrEmpty(strProductBarcode) && string.IsNullOrEmpty(CarrierBarcode) &&
  5107. Convert.ToInt32(oEEType) > 2)
  5108. {
  5109. stopwatch2.Start();
  5110. //写入PLC
  5111. IoT_DataSet_t iotData = new IoT_DataSet_t();
  5112. iotData.machineState = iot_data.machineState;
  5113. iotData.work_type = iot_data.work_type;
  5114. iotData.testStatus = iot_data.testStatus;
  5115. iotData.BeatAction = iot_data.BeatAction;
  5116. iotData.beatReturn = 2; //NG
  5117. iotData.fault_codes = iot_data.fault_codes;
  5118. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  5119. stopwatch2.Stop();
  5120. AddMessage_Station(stationNameStr, LogType.Info,
  5121. stationNameStr + $"_[{CarrierBarcode}][{strProductBarcode}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  5122. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5123. return;
  5124. }
  5125. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(strProductBarcode))
  5126. {
  5127. stopwatch2.Start();
  5128. //写入PLC
  5129. IoT_DataSet_t iotData = new IoT_DataSet_t();
  5130. iotData.machineState = iot_data.machineState;
  5131. iotData.work_type = iot_data.work_type;
  5132. iotData.testStatus = iot_data.testStatus;
  5133. iotData.BeatAction = iot_data.BeatAction;
  5134. iotData.beatReturn = 2; //NG
  5135. iotData.fault_codes = iot_data.fault_codes;
  5136. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  5137. stopwatch2.Stop();
  5138. AddMessage_Station(stationNameStr, LogType.Info,
  5139. stationNameStr + $"_[{CarrierBarcode}]上传节拍失败!物料码不可为空;总用时" +
  5140. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5141. return;
  5142. }
  5143. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(CarrierBarcode))
  5144. {
  5145. stopwatch2.Start();
  5146. //写入PLC
  5147. IoT_DataSet_t iotData = new IoT_DataSet_t();
  5148. iotData.machineState = iot_data.machineState;
  5149. iotData.work_type = iot_data.work_type;
  5150. iotData.testStatus = iot_data.testStatus;
  5151. iotData.BeatAction = iot_data.BeatAction;
  5152. iotData.beatReturn = 2; //NG
  5153. iotData.fault_codes = iot_data.fault_codes;
  5154. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  5155. stopwatch2.Stop();
  5156. AddMessage_Station(stationNameStr, LogType.Info,
  5157. stationNameStr + $"_上传节拍失败!载具码不可为空;总用时" +
  5158. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5159. return;
  5160. }
  5161. short _result = 0;
  5162. // 上传OEE
  5163. (short, string) result =
  5164. SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  5165. _result = result.Item1;
  5166. resultStr = result.Item2;
  5167. if (_result == 1)
  5168. {
  5169. stopwatch2.Start();
  5170. //写入PLC
  5171. IoT_DataSet_t iotData = new IoT_DataSet_t();
  5172. iotData.machineState = iot_data.machineState;
  5173. iotData.work_type = iot_data.work_type;
  5174. iotData.testStatus = iot_data.testStatus;
  5175. iotData.BeatAction = iot_data.BeatAction;
  5176. iotData.beatReturn = 1; //OK
  5177. iotData.fault_codes = iot_data.fault_codes;
  5178. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  5179. OnMessage(LogType.Info,
  5180. $"PLC{plcNo}_{stationNameStr} 节拍{iotData.BeatAction}上传IOT成功!上传结果:" + resultStr);
  5181. stopwatch2.Stop();
  5182. }
  5183. else
  5184. {
  5185. stopwatch2.Start();
  5186. //写入PLC
  5187. IoT_DataSet_t iotData = new IoT_DataSet_t();
  5188. iotData.machineState = iot_data.machineState;
  5189. iotData.work_type = iot_data.work_type;
  5190. iotData.testStatus = iot_data.testStatus;
  5191. iotData.BeatAction = iot_data.BeatAction;
  5192. iotData.beatReturn = 2; //NG
  5193. iotData.fault_codes = iot_data.fault_codes;
  5194. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  5195. stopwatch2.Stop();
  5196. AddMessage_Station(stationNameStr, LogType.Error,
  5197. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  5198. }
  5199. }
  5200. catch (Exception ex)
  5201. {
  5202. string str = ex.StackTrace;
  5203. AddMessage_Station(stationNameStr, LogType.Error,
  5204. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  5205. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5206. // MES_Flag
  5207. stopwatch2.Start();
  5208. //写入PLC
  5209. IoT_DataSet_t iotData = new IoT_DataSet_t();
  5210. iotData.machineState = iot_data.machineState;
  5211. iotData.work_type = iot_data.work_type;
  5212. iotData.testStatus = iot_data.testStatus;
  5213. iotData.BeatAction = iot_data.BeatAction;
  5214. iotData.beatReturn = 2; //NG
  5215. iotData.fault_codes = iot_data.fault_codes;
  5216. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5217. stopwatch2.Stop();
  5218. }
  5219. stopwatch1.Stop();
  5220. AddMessage(LogType.Info,
  5221. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5222. stopwatch2.ElapsedMilliseconds + "ms");
  5223. }
  5224. #endregion
  5225. #region S6
  5226. private Dictionary<string, object> s6PLCData = new Dictionary<string, object>();
  5227. private Dictionary<string, object> s6PLCSignal_Old = new Dictionary<string, object>();
  5228. /// <summary>
  5229. /// [S6] 顶盖装配设备
  5230. /// </summary>
  5231. /// <param name="plcNo">PLC编号</param>
  5232. private void ReadStation_S6(int plcNo)
  5233. {
  5234. string stationCode = "[OP70]";
  5235. string stationName = "组上盖板";
  5236. string stationNameStr = stationCode + stationName;
  5237. string tagBaseName = "g_OP60_MES"; //标签变量名称
  5238. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5239. string tagAgvCommName = "agvCommFrmPC";
  5240. string tagiotComnName = "iotData";
  5241. string tagBarsetName = "BarcodeSet";
  5242. string CarrierBarcode = "";
  5243. // 触发信号字典
  5244. s6PLCSignal_Old.Add("a6OEEType", 0); // 节拍类型(plc写入)
  5245. // PLC数据字典 赋值
  5246. s6PLCData.Add("a6OEEType", 0); // 节拍类型(plc写入)
  5247. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  5248. (int, string) result;
  5249. while (true)
  5250. {
  5251. try
  5252. {
  5253. if (!GlobalContext._IsCon_Funs1)
  5254. {
  5255. UpdatePLCMonitor(1, plcNo, 0);
  5256. continue;
  5257. }
  5258. //弹出扫码框则停止循环
  5259. if (isNoStop)
  5260. {
  5261. Task.Delay(1000);
  5262. continue;
  5263. }
  5264. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5265. {
  5266. Stopwatch stopwatch1 = new Stopwatch();
  5267. Stopwatch stopwatch2 = new Stopwatch();
  5268. stopwatch1.Start();
  5269. stopwatch2.Start();
  5270. #region 一次性读取所有数据
  5271. // 一次性读取所有数据
  5272. result = FunsEip[plcNo]
  5273. .Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  5274. //测试
  5275. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
  5276. //stPLC_MesData.mesCommFrmPLC.cmd = 1;
  5277. if (result.Item1 != 0)
  5278. {
  5279. //richTextBox1.AppendText("\n" + strRet);
  5280. }
  5281. else
  5282. {
  5283. //去除扫码产生的特殊字符
  5284. stPLC_MesData.BarcodeSet.strProductBarcode =
  5285. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  5286. stPLC_MesData.BarcodeSet.strPartBarcode =
  5287. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  5288. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  5289. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  5290. stPLC_MesData.BarcodeSet.strPCBBarcode =
  5291. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  5292. //richTextBox1.AppendText("\n" + "读取成功");
  5293. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  5294. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  5295. ? XiaomiDeviceState.Unknown
  5296. : (XiaomiDeviceState)xmDeviceStateInt;
  5297. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  5298. s6PLCData["a6OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  5299. //报警信息
  5300. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  5301. }
  5302. #endregion 一次性读取所有数据
  5303. stopwatch2.Stop();
  5304. #region 进站
  5305. try
  5306. {
  5307. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5308. {
  5309. lock (lockObj)
  5310. {
  5311. if (!ProgressState)
  5312. {
  5313. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  5314. ProgressState = true;
  5315. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData,
  5316. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  5317. out ProgressState));
  5318. }
  5319. }
  5320. }
  5321. }
  5322. catch (Exception ex)
  5323. {
  5324. ProgressState = false;
  5325. string str = ex.StackTrace;
  5326. AddMessage_Station(stationNameStr, LogType.Error,
  5327. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5328. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5329. }
  5330. #endregion 进站
  5331. #region 出站
  5332. try
  5333. {
  5334. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5335. {
  5336. lock (lockObj)
  5337. {
  5338. if (!ProgressState)
  5339. {
  5340. ProgressState = true;
  5341. ;
  5342. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData,
  5343. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  5344. out ProgressState));
  5345. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  5346. uuid = "";
  5347. }
  5348. }
  5349. }
  5350. }
  5351. catch (Exception ex)
  5352. {
  5353. ProgressState = false;
  5354. string str = ex.StackTrace;
  5355. AddMessage_Station(stationNameStr, LogType.Error,
  5356. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5357. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5358. }
  5359. #endregion 出站
  5360. #region 节拍接口
  5361. try
  5362. {
  5363. if (stPLC_MesData.iotData.BeatAction > 0)
  5364. {
  5365. int a6OEEType = Convert.ToInt32(s6PLCData["a6OEEType"]);
  5366. int a6OEETypeGOld = Convert.ToInt32(s6PLCSignal_Old["a6OEEType"]);
  5367. //若设备紧急复原后节拍重置
  5368. if (a6OEEType == 1)
  5369. {
  5370. a6OEETypeGOld = 0;
  5371. }
  5372. if (a6OEEType != a6OEETypeGOld)
  5373. {
  5374. if (a6OEETypeGOld <= 2 && a6OEEType == 4)
  5375. {
  5376. Task.Run(() =>
  5377. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  5378. CarrierBarcode,
  5379. stPLC_MesData.iotData));
  5380. }
  5381. else
  5382. {
  5383. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  5384. if ((a6OEETypeGOld == 1 && a6OEEType != 2) ||
  5385. (a6OEETypeGOld == 3 && a6OEEType != 4) ||
  5386. (a6OEETypeGOld == 5 && a6OEEType != 6))
  5387. {
  5388. //写入PLC
  5389. stPLC_MesData.iotData.beatReturn = 2; //NG
  5390. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1,
  5391. stPLC_MesData.iotData);
  5392. AddMessage(LogType.Info,
  5393. stationNameStr +
  5394. $"_节拍接口-- 设备本次上传节拍[{a6OEEType}],未上传节拍[{a6OEETypeGOld}]的结束信号,请检查;总用时" +
  5395. stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5396. stopwatch2.ElapsedMilliseconds +
  5397. "ms");
  5398. return;
  5399. }
  5400. else
  5401. {
  5402. Task.Run(() =>
  5403. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  5404. CarrierBarcode,
  5405. stPLC_MesData.iotData));
  5406. //Task.Run(() =>
  5407. // S6节拍接口(plcNo, stationNameStr, tagBaseName,
  5408. // stPLC_MesData.iotData));
  5409. }
  5410. }
  5411. }
  5412. }
  5413. s6PLCSignal_Old["a6OEEType"] = s6PLCData["a6OEEType"];
  5414. }
  5415. catch (Exception ex)
  5416. {
  5417. string str = ex.StackTrace;
  5418. AddMessage_Station(stationNameStr, LogType.Error,
  5419. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  5420. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5421. }
  5422. #endregion
  5423. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5424. stopwatch1.Stop();
  5425. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5426. }
  5427. else
  5428. {
  5429. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5430. AddMessage_Station(stationNameStr, LogType.Info,
  5431. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5432. FunsEip[plcNo].Connect(); // 重连
  5433. }
  5434. }
  5435. catch (Exception ex)
  5436. {
  5437. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5438. AddMessage_Station(stationNameStr, LogType.Error,
  5439. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5440. }
  5441. Thread.Sleep(IntervalReadPLC);
  5442. }
  5443. }
  5444. /// <summary>
  5445. /// [S6] 顶盖装配设备 - 进站
  5446. /// </summary>
  5447. /// <param name="plcNo">PLC编号</param>
  5448. /// <param name="stationNameStr">工站全称</param>
  5449. /// <param name="stPLC_MesData"></param>
  5450. /// <param name="tagMesCommName"></param>
  5451. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  5452. string tagBarsetName, out bool ProgressState)
  5453. {
  5454. Stopwatch stopwatch1 = new Stopwatch();
  5455. Stopwatch stopwatch2 = new Stopwatch();
  5456. try
  5457. {
  5458. stopwatch1.Start();
  5459. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  5460. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5461. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  5462. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  5463. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5464. bool pass = a1Result == 1;
  5465. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  5466. //strCarrierBarcode = "N801A-003";
  5467. //载具码验证产品码
  5468. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  5469. string strPCBBarcode = SQLHelper.GetPCBBarcodeByCarrierCode(strCarrierBarcode);
  5470. if (string.IsNullOrEmpty(strProductBarcode))
  5471. {
  5472. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5473. }
  5474. sn = strProductBarcode;
  5475. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5476. if (OpenDailogFalg)
  5477. {
  5478. using (var dialog = new BandBarodeDialog())
  5479. {
  5480. dialog._CarrierBarcode = strCarrierBarcode;
  5481. dialog._ProductBarcode = sn;
  5482. dialog._PCBBarcode = strPCBBarcode;
  5483. var rs = dialog.ShowDialog();
  5484. if (rs == DialogResult.OK)
  5485. {
  5486. AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  5487. OpenDailogFalg = false; //关闭扫码
  5488. isNoStop = false;
  5489. }
  5490. else
  5491. {
  5492. ProgressState = false;
  5493. return;
  5494. }
  5495. }
  5496. }
  5497. // 产品SN(物料码)校验
  5498. List<TestItem> item = new List<TestItem>();
  5499. stopwatch2.Start();
  5500. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  5501. item, MachineId, StationId, pass, "01-SLOT-01");
  5502. stopwatch2.Stop();
  5503. //指令执行结果 1:OK 110:失败
  5504. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5505. if (mesResultFrmWeb == 1)
  5506. {
  5507. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  5508. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  5509. }
  5510. //进站结果写入PLC
  5511. CommandFromPLC resultToPlC = new CommandFromPLC();
  5512. resultToPlC.cmd = 0;
  5513. resultToPlC.cmdParam = 0; //指令参数
  5514. resultToPlC.cmdResult = mesResultFrmWeb;
  5515. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5516. }
  5517. catch (Exception ex)
  5518. {
  5519. string str = ex.StackTrace;
  5520. AddMessage(LogType.Error,
  5521. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  5522. str.Length - str.LastIndexOf("\\") - 1));
  5523. CommandFromPLC resultToPlC = new CommandFromPLC();
  5524. resultToPlC.cmd = 0;
  5525. resultToPlC.cmdParam = 0; //指令参数
  5526. resultToPlC.cmdResult = 110;
  5527. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5528. }
  5529. stopwatch1.Stop();
  5530. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  5531. AddMessage(LogType.Info,
  5532. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5533. stopwatch2.ElapsedMilliseconds + "ms");
  5534. ProgressState = false;
  5535. OpenDailogFalg = true; //开启下一个物料的扫码
  5536. }
  5537. /// <summary>
  5538. /// [S6] 顶盖装配设备 - 出站接口
  5539. /// </summary>
  5540. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  5541. string stationCode, string stationName, out bool ProgressState)
  5542. {
  5543. Stopwatch stopwatch1 = new Stopwatch();
  5544. Stopwatch stopwatch2 = new Stopwatch();
  5545. test_item_num = 0; //iot 过站明细序号
  5546. try
  5547. {
  5548. stopwatch1.Start();
  5549. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  5550. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5551. string processItem = stationName; // 测试项目
  5552. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5553. string supplierCode = ""; // 供应商代码
  5554. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5555. string batch_num = GlobalContext.BatchNumber; // 批次号
  5556. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5557. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5558. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5559. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  5560. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  5561. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5562. bool pass = a1Result == 1;
  5563. //根据载具码获取产品码
  5564. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5565. if (string.IsNullOrEmpty(strProductBarcode))
  5566. {
  5567. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5568. }
  5569. sn = strProductBarcode;
  5570. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  5571. List<TestItem> items = new List<TestItem>();
  5572. items.Add(new TestItem()
  5573. {
  5574. Parameter_name = "载具码",
  5575. Parameter_value = CarrierBarcode,
  5576. Parameter_unit = ""
  5577. });
  5578. items.Add(new TestItem()
  5579. {
  5580. Parameter_name = "产品码",
  5581. Parameter_value = sn,
  5582. Parameter_unit = ""
  5583. });
  5584. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  5585. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  5586. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  5587. MachineId, StationId, "", paramJson);
  5588. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5589. if (mesResultFrmWeb == 1)
  5590. {
  5591. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  5592. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  5593. }
  5594. stopwatch2.Start();
  5595. //进站结果写入PLC
  5596. CommandFromPLC resultToPlC = new CommandFromPLC();
  5597. resultToPlC.cmd = 0;
  5598. resultToPlC.cmdParam = 0; //指令参数
  5599. resultToPlC.cmdResult = mesResultFrmWeb;
  5600. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5601. stopwatch2.Stop();
  5602. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  5603. //保存PLC返回MES数据到本地
  5604. ResponseMessage message = new ResponseMessage();
  5605. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  5606. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  5607. if (message.result == false)
  5608. {
  5609. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  5610. }
  5611. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  5612. }
  5613. catch (Exception ex)
  5614. {
  5615. stopwatch2.Start();
  5616. CommandFromPLC resultToPlC = new CommandFromPLC();
  5617. resultToPlC.cmd = 0;
  5618. resultToPlC.cmdParam = 0; //指令参数
  5619. resultToPlC.cmdResult = 110;
  5620. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5621. stopwatch2.Stop();
  5622. string str = ex.StackTrace;
  5623. AddMessage(LogType.Error,
  5624. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5625. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5626. }
  5627. stopwatch1.Stop();
  5628. AddMessage(LogType.Info,
  5629. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5630. stopwatch2.ElapsedMilliseconds + "ms");
  5631. ProgressState = false;
  5632. }
  5633. private void S6节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  5634. {
  5635. Stopwatch stopwatch1 = new Stopwatch();
  5636. Stopwatch stopwatch2 = new Stopwatch();
  5637. string resultStr = string.Empty;
  5638. try
  5639. {
  5640. stopwatch1.Start();
  5641. string oEEType = ((int)s1PLCData["a6OEEType"]).ToString(); // 节拍类型(plc写入)
  5642. string a60EEPartNo = (string)s1PLCData["a60EEPartNo"]; // 物料码
  5643. a60EEPartNo = a60EEPartNo.Replace("\0", "");
  5644. string a60EEVehicleCode = (string)s1PLCData["a60EEVehicleCode"]; // 载具SN
  5645. a60EEVehicleCode = a60EEVehicleCode.Replace("\0", "");
  5646. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5647. if (!actionBool)
  5648. {
  5649. stopwatch2.Start();
  5650. //写入PLC
  5651. iot_data.beatReturn = 2; //NG
  5652. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5653. stopwatch2.Stop();
  5654. AddMessage(LogType.Info,
  5655. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  5656. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5657. return;
  5658. }
  5659. //作业开始后要有物料和载具信息
  5660. if (string.IsNullOrEmpty(a60EEPartNo) && string.IsNullOrEmpty(a60EEVehicleCode) &&
  5661. Convert.ToInt32(oEEType) > 2)
  5662. {
  5663. stopwatch2.Start();
  5664. //写入PLC
  5665. iot_data.beatReturn = 2; //NG
  5666. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5667. stopwatch2.Stop();
  5668. AddMessage_Station(stationNameStr, LogType.Info,
  5669. stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  5670. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5671. return;
  5672. }
  5673. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a60EEPartNo))
  5674. {
  5675. stopwatch2.Start();
  5676. //写入PLC
  5677. iot_data.beatReturn = 2; //NG
  5678. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5679. stopwatch2.Stop();
  5680. AddMessage_Station(stationNameStr, LogType.Info,
  5681. stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  5682. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5683. return;
  5684. }
  5685. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a60EEVehicleCode))
  5686. {
  5687. stopwatch2.Start();
  5688. //写入PLC
  5689. iot_data.beatReturn = 2; //NG
  5690. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5691. stopwatch2.Stop();
  5692. AddMessage_Station(stationNameStr, LogType.Info,
  5693. stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  5694. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5695. return;
  5696. }
  5697. short _result = 0;
  5698. // 上传OEE
  5699. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a60EEPartNo, a60EEVehicleCode);
  5700. _result = result.Item1;
  5701. resultStr = result.Item2;
  5702. if (_result == 1)
  5703. {
  5704. stopwatch2.Start();
  5705. //写入PLC
  5706. iot_data.beatReturn = 1; //OK
  5707. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5708. OnMessage(LogType.Info,
  5709. $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  5710. stopwatch2.Stop();
  5711. }
  5712. else
  5713. {
  5714. stopwatch2.Start();
  5715. //写入PLC
  5716. iot_data.beatReturn = 2; //NG
  5717. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5718. stopwatch2.Stop();
  5719. AddMessage_Station(stationNameStr, LogType.Error,
  5720. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  5721. }
  5722. }
  5723. catch (Exception ex)
  5724. {
  5725. string str = ex.StackTrace;
  5726. AddMessage_Station(stationNameStr, LogType.Error,
  5727. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  5728. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5729. // MES_Flag
  5730. stopwatch2.Start();
  5731. //写入PLC
  5732. iot_data.beatReturn = 2; //NG
  5733. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5734. stopwatch2.Stop();
  5735. }
  5736. stopwatch1.Stop();
  5737. AddMessage(LogType.Info,
  5738. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5739. stopwatch2.ElapsedMilliseconds + "ms");
  5740. }
  5741. #endregion
  5742. #region S7
  5743. private Dictionary<string, object> s7PLCSignal_Old = new Dictionary<string, object>();
  5744. private Dictionary<string, object> s7PLCData = new Dictionary<string, object>();
  5745. /// <summary>
  5746. /// [S7] 锁螺丝设备
  5747. /// </summary>
  5748. /// <param name="plcNo">PLC编号</param>
  5749. private void ReadStation_S7(int plcNo)
  5750. {
  5751. string stationCode = "[OP80]";
  5752. string stationName = "上盖板锁螺丝";
  5753. string stationNameStr = stationCode + stationName;
  5754. string tagBaseName = "g_OP70_MES"; //标签变量名称
  5755. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5756. string tagAgvCommName = "agvCommFrmPC";
  5757. string tagBarsetName = "BarcodeSet";
  5758. string tagiotComnName = "iotData";
  5759. string tagScrewDataset = "screwDataset";
  5760. string CarrierBarcode_Left = "";
  5761. string CarrierBarcode_Right = "";
  5762. s7PLCSignal_Old.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
  5763. s7PLCSignal_Old.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
  5764. // PLC数据字典 赋值
  5765. s7PLCData.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
  5766. s7PLCData.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
  5767. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  5768. (int, string) result;
  5769. AtlasScrew atlasScrewLeft = new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort,
  5770. 3000, 3000, "Left");
  5771. atlasScrewLeft.Initial();
  5772. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort,
  5773. 3000, 3000, "Right");
  5774. atlasScrewRight.Initial();
  5775. while (true)
  5776. {
  5777. try
  5778. {
  5779. if (!GlobalContext._IsCon_Funs1)
  5780. {
  5781. UpdatePLCMonitor(1, plcNo, 0);
  5782. continue;
  5783. }
  5784. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5785. {
  5786. Stopwatch stopwatch1 = new Stopwatch();
  5787. Stopwatch stopwatch2 = new Stopwatch();
  5788. stopwatch1.Start();
  5789. stopwatch2.Start();
  5790. #region 一次性读取所有数据
  5791. // 一次性读取所有数据
  5792. result = FunsEip[plcNo]
  5793. .Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  5794. if (result.Item1 != 0)
  5795. {
  5796. //richTextBox1.AppendText("\n" + strRet);
  5797. }
  5798. else
  5799. {
  5800. #region 去除扫码产生的特殊字符
  5801. stPLC_MesData.Left.BarcodeSet.strProductBarcode =
  5802. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strProductBarcode);
  5803. stPLC_MesData.Left.BarcodeSet.strPartBarcode =
  5804. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPartBarcode);
  5805. stPLC_MesData.Left.BarcodeSet.strCarrierBarcode =
  5806. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strCarrierBarcode);
  5807. stPLC_MesData.Left.BarcodeSet.strPCBBarcode =
  5808. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPCBBarcode);
  5809. stPLC_MesData.Right.BarcodeSet.strProductBarcode =
  5810. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strProductBarcode);
  5811. stPLC_MesData.Right.BarcodeSet.strPartBarcode =
  5812. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPartBarcode);
  5813. stPLC_MesData.Right.BarcodeSet.strCarrierBarcode =
  5814. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strCarrierBarcode);
  5815. stPLC_MesData.Right.BarcodeSet.strPCBBarcode =
  5816. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPCBBarcode);
  5817. #endregion
  5818. int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  5819. int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  5820. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  5821. ? XiaomiDeviceState.Unknown
  5822. : (XiaomiDeviceState)xmDeviceStateInt_L;
  5823. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  5824. ? XiaomiDeviceState.Unknown
  5825. : (XiaomiDeviceState)xmDeviceStateInt_R;
  5826. s7PLCData["a7OEEPartNo"] =
  5827. stPLC_MesData.Left.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  5828. // 载具SN
  5829. CarrierBarcode_Left = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode;
  5830. CarrierBarcode_Right = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode;
  5831. // 节拍
  5832. s7PLCData["a7OEEType"] = stPLC_MesData.Left.iotData.BeatAction;
  5833. s7PLCData["a7OEEType_right"] = stPLC_MesData.Right.iotData.BeatAction;
  5834. //报警信息
  5835. _FaultDatas = stPLC_MesData.Left.iotData.fault_codes;
  5836. _FaultDatas2 = stPLC_MesData.Right.iotData.fault_codes;
  5837. }
  5838. #endregion 一次性读取所有数据
  5839. stopwatch2.Stop();
  5840. #region 左边进站
  5841. try
  5842. {
  5843. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5844. {
  5845. lock (lockObj)
  5846. {
  5847. if (!ProgressState)
  5848. {
  5849. stationCode = "[OP81]";
  5850. stationName = "上盖板锁螺丝1";
  5851. stationNameStr = stationCode + stationName;
  5852. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  5853. ProgressState = true;
  5854. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left,
  5855. tagBaseName + ".Left." + tagMesCommName,
  5856. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState,
  5857. atlasScrewLeft));
  5858. }
  5859. }
  5860. }
  5861. }
  5862. catch (Exception ex)
  5863. {
  5864. ProgressState = false;
  5865. string str = ex.StackTrace;
  5866. AddMessage_Station(stationNameStr, LogType.Error,
  5867. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5868. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5869. }
  5870. #endregion 左边进站
  5871. #region 左边出站
  5872. try
  5873. {
  5874. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5875. {
  5876. lock (lockObj)
  5877. {
  5878. if (!ProgressState)
  5879. {
  5880. stationCode = "[OP81]";
  5881. stationName = "上盖板锁螺丝1";
  5882. stationNameStr = stationCode + stationName;
  5883. ProgressState = true;
  5884. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left,
  5885. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  5886. out ProgressState));
  5887. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  5888. uuid = "";
  5889. }
  5890. }
  5891. }
  5892. }
  5893. catch (Exception ex)
  5894. {
  5895. ProgressState = false;
  5896. string str = ex.StackTrace;
  5897. AddMessage_Station(stationNameStr, LogType.Error,
  5898. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5899. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5900. }
  5901. #endregion 左边出站
  5902. #region 右边进站
  5903. try
  5904. {
  5905. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5906. {
  5907. lock (lockObj)
  5908. {
  5909. if (!ProgressState)
  5910. {
  5911. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  5912. stationCode = "[OP82]";
  5913. stationName = "上盖板锁螺丝2";
  5914. stationNameStr = stationCode + stationName;
  5915. ProgressState = true;
  5916. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right,
  5917. tagBaseName + ".Right." + tagMesCommName,
  5918. tagBaseName + ".Right" + tagBarsetName, "Right", out ProgressState,
  5919. atlasScrewRight));
  5920. }
  5921. }
  5922. }
  5923. }
  5924. catch (Exception ex)
  5925. {
  5926. ProgressState = false;
  5927. string str = ex.StackTrace;
  5928. AddMessage_Station(stationNameStr, LogType.Error,
  5929. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5930. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5931. }
  5932. #endregion 右边进站
  5933. #region 右边出站
  5934. try
  5935. {
  5936. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5937. {
  5938. lock (lockObj)
  5939. {
  5940. if (!ProgressState)
  5941. {
  5942. stationCode = "[OP82]";
  5943. stationName = "上盖板锁螺丝2";
  5944. stationNameStr = stationCode + stationName;
  5945. ProgressState = true;
  5946. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right,
  5947. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  5948. out ProgressState));
  5949. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  5950. uuid = "";
  5951. }
  5952. }
  5953. }
  5954. }
  5955. catch (Exception ex)
  5956. {
  5957. ProgressState = false;
  5958. string str = ex.StackTrace;
  5959. AddMessage_Station(stationNameStr, LogType.Error,
  5960. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5961. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5962. }
  5963. #endregion 右边出站
  5964. #region 节拍接口
  5965. try
  5966. {
  5967. #region 左工位 节拍
  5968. if (stPLC_MesData.Left.iotData.BeatAction > 0)
  5969. {
  5970. stationCode = "[OP81]";
  5971. stationName = "上盖板锁螺丝1";
  5972. stationNameStr = stationCode + stationName;
  5973. int a7OEEType_left = Convert.ToInt32(s7PLCData["a7OEEType_left"]);
  5974. int a7OEETypeGOld_left = Convert.ToInt32(s7PLCSignal_Old["a7OEEType_left"]);
  5975. //若设备紧急复原后节拍重置
  5976. if (a7OEEType_left == 1)
  5977. {
  5978. a7OEETypeGOld_left = 0;
  5979. }
  5980. if (a7OEEType_left != a7OEETypeGOld_left)
  5981. {
  5982. //如果上位机告诉PLC NG,PLC节拍会直接从1跳到4
  5983. if (a7OEETypeGOld_left <= 2 && a7OEEType_left == 4)
  5984. {
  5985. Task.Run(() =>
  5986. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName,
  5987. CarrierBarcode_Left,
  5988. stPLC_MesData.Left.iotData));
  5989. }
  5990. else
  5991. {
  5992. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  5993. if ((a7OEETypeGOld_left == 1 && a7OEEType_left != 2) ||
  5994. (a7OEETypeGOld_left == 3 && a7OEEType_left != 4) ||
  5995. (a7OEETypeGOld_left == 5 && a7OEEType_left != 6))
  5996. {
  5997. //写入PLC
  5998. IoT_DataSet_t iotData = new IoT_DataSet_t();
  5999. iotData.machineState = stPLC_MesData.Left.iotData.machineState;
  6000. iotData.work_type = stPLC_MesData.Left.iotData.work_type;
  6001. iotData.testStatus = stPLC_MesData.Left.iotData.testStatus;
  6002. iotData.BeatAction = stPLC_MesData.Left.iotData.BeatAction;
  6003. iotData.beatReturn = 2; //NG
  6004. iotData.fault_codes = stPLC_MesData.Left.iotData.fault_codes;
  6005. WriteResultToPlc(plcNo, stationNameStr,
  6006. tagBaseName + ".Left." + tagiotComnName, 1, iotData);
  6007. AddMessage(LogType.Info,
  6008. stationNameStr +
  6009. $"_节拍接口-- 设备本次上传节拍[{a7OEEType_left}],未上传节拍[{a7OEETypeGOld_left}]的结束信号,请检查;总用时" +
  6010. stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6011. stopwatch2.ElapsedMilliseconds +
  6012. "ms");
  6013. return;
  6014. }
  6015. else
  6016. {
  6017. Task.Run(() =>
  6018. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName,
  6019. CarrierBarcode_Left,
  6020. stPLC_MesData.Left.iotData));
  6021. //Task.Run(() =>
  6022. // S7节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName,
  6023. // stPLC_MesData.Left.iotData));
  6024. }
  6025. }
  6026. }
  6027. }
  6028. s7PLCSignal_Old["a7OEEType_left"] = s7PLCData["a7OEEType_left"];
  6029. #endregion 左工位 节拍
  6030. #region 右工位 节拍
  6031. if (stPLC_MesData.Right.iotData.BeatAction > 0)
  6032. {
  6033. stationCode = "[OP82]";
  6034. stationName = "上盖板锁螺丝2";
  6035. stationNameStr = stationCode + stationName;
  6036. int a7OEEType_right = Convert.ToInt32(s7PLCData["a7OEEType_right"]);
  6037. int a7OEETypeGOld_right = Convert.ToInt32(s7PLCSignal_Old["a7OEEType_right"]);
  6038. //若设备紧急复原后节拍重置
  6039. if (a7OEEType_right == 1)
  6040. {
  6041. a7OEETypeGOld_right = 0;
  6042. }
  6043. if (a7OEEType_right != a7OEETypeGOld_right)
  6044. {
  6045. if (a7OEETypeGOld_right <= 2 && a7OEEType_right == 4)
  6046. {
  6047. Task.Run(() =>
  6048. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName,
  6049. CarrierBarcode_Right,
  6050. stPLC_MesData.Right.iotData));
  6051. }
  6052. else
  6053. {
  6054. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  6055. if ((a7OEETypeGOld_right == 1 && a7OEEType_right != 2) ||
  6056. (a7OEETypeGOld_right == 3 && a7OEEType_right != 4) ||
  6057. (a7OEETypeGOld_right == 5 && a7OEEType_right != 6))
  6058. {
  6059. //写入PLC
  6060. IoT_DataSet_t iotData = new IoT_DataSet_t();
  6061. iotData.machineState = stPLC_MesData.Left.iotData.machineState;
  6062. iotData.work_type = stPLC_MesData.Left.iotData.work_type;
  6063. iotData.testStatus = stPLC_MesData.Left.iotData.testStatus;
  6064. iotData.BeatAction = stPLC_MesData.Left.iotData.BeatAction;
  6065. iotData.beatReturn = 2; //NG
  6066. iotData.fault_codes = stPLC_MesData.Left.iotData.fault_codes;
  6067. WriteResultToPlc(plcNo, stationNameStr,
  6068. tagBaseName + ".Right." + tagiotComnName, 1, iotData);
  6069. AddMessage(LogType.Info,
  6070. stationNameStr +
  6071. $"_节拍接口-- 设备本次上传节拍[{a7OEEType_right}],未上传节拍[{a7OEETypeGOld_right}]的结束信号,请检查;总用时" +
  6072. stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6073. stopwatch2.ElapsedMilliseconds +
  6074. "ms");
  6075. return;
  6076. }
  6077. else
  6078. {
  6079. Task.Run(() =>
  6080. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName,
  6081. CarrierBarcode_Right,
  6082. stPLC_MesData.Right.iotData));
  6083. //Task.Run(() =>
  6084. // S7节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName,
  6085. // stPLC_MesData.Left.iotData));
  6086. }
  6087. }
  6088. }
  6089. }
  6090. s7PLCSignal_Old["a7OEEType_right"] = s7PLCData["a7OEEType_right"];
  6091. #endregion 右工位 节拍
  6092. }
  6093. catch (Exception ex)
  6094. {
  6095. string str = ex.StackTrace;
  6096. AddMessage_Station(stationNameStr, LogType.Error,
  6097. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  6098. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6099. }
  6100. #endregion
  6101. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6102. stopwatch1.Stop();
  6103. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6104. }
  6105. else
  6106. {
  6107. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6108. AddMessage_Station(stationNameStr, LogType.Info,
  6109. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6110. FunsEip[plcNo].Connect(); // 重连
  6111. }
  6112. }
  6113. catch (Exception ex)
  6114. {
  6115. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6116. AddMessage_Station(stationNameStr, LogType.Error,
  6117. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6118. }
  6119. Thread.Sleep(IntervalReadPLC);
  6120. }
  6121. }
  6122. /// <summary>
  6123. /// [S7] 锁螺丝设备 - 进站
  6124. /// </summary>
  6125. /// <param name="plcNo">PLC编号</param>
  6126. /// <param name="stationNameStr">工站全称</param>
  6127. /// <param name="stPLC_MesData"></param>
  6128. /// <param name="tagMesCommName"></param>
  6129. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  6130. string tagBarsetName, string direction, out bool ProgressState, AtlasScrew atlasScrew)
  6131. {
  6132. Stopwatch stopwatch1 = new Stopwatch();
  6133. Stopwatch stopwatch2 = new Stopwatch();
  6134. string atlasSn = string.Empty;
  6135. try
  6136. {
  6137. stopwatch1.Start();
  6138. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  6139. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  6140. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  6141. string StationId = string.Empty; // 工位ID(可配置)
  6142. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6143. bool pass = a1Result == 1;
  6144. if (direction == "Left")
  6145. {
  6146. StationId = GlobalContext.S7_StationId_1;
  6147. }
  6148. if (direction == "Right")
  6149. {
  6150. StationId = GlobalContext.S7_StationId_2;
  6151. }
  6152. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  6153. //载具码验证产品码
  6154. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  6155. if (string.IsNullOrEmpty(strProductBarcode))
  6156. {
  6157. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6158. }
  6159. sn = strProductBarcode;
  6160. atlasSn = strProductBarcode;
  6161. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  6162. string slot = "";
  6163. if (direction == "Left")
  6164. {
  6165. isCollectingFlagLeft = false; //采集螺丝数据结束
  6166. slot = "01-SLOT-01";
  6167. }
  6168. if (direction == "Right")
  6169. {
  6170. isCollectingFlagRight = false; //采集螺丝数据结束
  6171. slot = "01-SLOT-02";
  6172. }
  6173. // 产品SN(物料码)校验
  6174. List<TestItem> item = new List<TestItem>();
  6175. stopwatch2.Start();
  6176. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  6177. item, MachineId, StationId, pass, slot);
  6178. stopwatch2.Stop();
  6179. //指令执行结果 1:OK 110:失败
  6180. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  6181. if (mesResultFrmWeb == 1)
  6182. {
  6183. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  6184. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  6185. }
  6186. //进站结果写入PLC
  6187. CommandFromPLC resultToPlC = new CommandFromPLC();
  6188. resultToPlC.cmd = 0;
  6189. resultToPlC.cmdParam = 0; //指令参数
  6190. resultToPlC.cmdResult = mesResultFrmWeb;
  6191. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6192. }
  6193. catch (Exception ex)
  6194. {
  6195. string str = ex.StackTrace;
  6196. AddMessage(LogType.Error,
  6197. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  6198. str.Length - str.LastIndexOf("\\") - 1));
  6199. CommandFromPLC resultToPlC = new CommandFromPLC();
  6200. resultToPlC.cmd = 0;
  6201. resultToPlC.cmdParam = 0; //指令参数
  6202. resultToPlC.cmdResult = 110;
  6203. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6204. }
  6205. stopwatch1.Stop();
  6206. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  6207. AddMessage(LogType.Info,
  6208. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  6209. stopwatch2.ElapsedMilliseconds + "ms");
  6210. ProgressState = false;
  6211. //开始采集螺丝数据
  6212. if (direction == "Left")
  6213. {
  6214. isCollectingFlagLeft = true;
  6215. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  6216. }
  6217. if (direction == "Right")
  6218. {
  6219. isCollectingFlagRight = true;
  6220. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  6221. }
  6222. }
  6223. /// <summary>
  6224. /// [S7] 锁螺丝设备 - 出站
  6225. /// </summary>
  6226. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  6227. string stationCode, string stationName, string direction, out bool ProgressState)
  6228. {
  6229. Stopwatch stopwatch1 = new Stopwatch();
  6230. Stopwatch stopwatch2 = new Stopwatch();
  6231. test_item_num = 0; //iot 过站明细序号
  6232. try
  6233. {
  6234. stopwatch1.Start();
  6235. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  6236. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6237. string processItem = stationName; // 测试项目
  6238. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6239. string supplierCode = ""; // 供应商代码
  6240. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6241. string batch_num = GlobalContext.BatchNumber; // 批次号
  6242. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6243. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  6244. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  6245. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  6246. string StationId = string.Empty; // 工位ID(可配置)
  6247. if (direction == "Left")
  6248. {
  6249. StationId = GlobalContext.S7_StationId_1;
  6250. }
  6251. if (direction == "Right")
  6252. {
  6253. StationId = GlobalContext.S7_StationId_2;
  6254. }
  6255. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6256. //a1Result = 1;
  6257. bool pass = a1Result == 1;
  6258. //根据载具码获取产品码
  6259. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  6260. if (string.IsNullOrEmpty(strProductBarcode))
  6261. {
  6262. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6263. }
  6264. sn = strProductBarcode;
  6265. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  6266. List<TestItem> items = new List<TestItem>();
  6267. items.Add(new TestItem()
  6268. {
  6269. Parameter_name = "载具码",
  6270. Parameter_value = CarrierBarcode,
  6271. Parameter_unit = ""
  6272. });
  6273. items.Add(new TestItem()
  6274. {
  6275. Parameter_name = "产品码",
  6276. Parameter_value = sn,
  6277. Parameter_unit = ""
  6278. });
  6279. //if (direction == "Right")
  6280. //{
  6281. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  6282. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem, workorder_code,
  6283. batch_num, mtltmrk, plcDate_YMD, supplierCode
  6284. , sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  6285. //}
  6286. //if (direction == "Left")
  6287. //{
  6288. // isCollectingFlagLeft = false;//采集螺丝数据结束
  6289. //}
  6290. //if (direction == "Right")
  6291. //{
  6292. // isCollectingFlagRight = false;//采集螺丝数据结束
  6293. //}
  6294. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  6295. if (mesResultFrmWeb == 1)
  6296. {
  6297. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  6298. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  6299. }
  6300. stopwatch2.Start();
  6301. //进站结果写入PLC
  6302. CommandFromPLC resultToPlC = new CommandFromPLC();
  6303. resultToPlC.cmd = 0;
  6304. resultToPlC.cmdParam = 0; //指令参数
  6305. resultToPlC.cmdResult = mesResultFrmWeb;
  6306. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6307. stopwatch2.Stop();
  6308. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  6309. //保存PLC返回MES数据到本地
  6310. ResponseMessage message = new ResponseMessage();
  6311. if (direction == "Left")
  6312. {
  6313. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  6314. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  6315. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  6316. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  6317. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  6318. if (message.result == false)
  6319. {
  6320. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  6321. }
  6322. }
  6323. if (direction == "Right")
  6324. {
  6325. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  6326. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  6327. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  6328. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  6329. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  6330. if (message.result == false)
  6331. {
  6332. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  6333. }
  6334. }
  6335. //保存螺丝数据到txt
  6336. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes,
  6337. stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  6338. if (result.Item1 != 0)
  6339. {
  6340. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  6341. }
  6342. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_保存加工数据到本地成功");
  6343. }
  6344. catch (Exception ex)
  6345. {
  6346. stopwatch2.Start();
  6347. CommandFromPLC resultToPlC = new CommandFromPLC();
  6348. resultToPlC.cmd = 0;
  6349. resultToPlC.cmdParam = 0; //指令参数
  6350. resultToPlC.cmdResult = 110;
  6351. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6352. stopwatch2.Stop();
  6353. string str = ex.StackTrace;
  6354. AddMessage(LogType.Error,
  6355. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  6356. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6357. }
  6358. stopwatch1.Stop();
  6359. AddMessage(LogType.Info,
  6360. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6361. stopwatch2.ElapsedMilliseconds + "ms");
  6362. ProgressState = false;
  6363. }
  6364. private void S7节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  6365. {
  6366. Stopwatch stopwatch1 = new Stopwatch();
  6367. Stopwatch stopwatch2 = new Stopwatch();
  6368. string resultStr = string.Empty;
  6369. try
  6370. {
  6371. stopwatch1.Start();
  6372. string oEEType = ((int)s1PLCData["a7OEEType"]).ToString(); // 节拍类型(plc写入)
  6373. string a7OEEPartNo = (string)s1PLCData["a7OEEPartNo"]; // 物料码
  6374. a7OEEPartNo = a7OEEPartNo.Replace("\0", "");
  6375. string a7OEEVehicleCode = (string)s1PLCData["a7OEEVehicleCode"]; // 载具SN
  6376. a7OEEVehicleCode = a7OEEVehicleCode.Replace("\0", "");
  6377. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6378. if (!actionBool)
  6379. {
  6380. stopwatch2.Start();
  6381. //写入PLC
  6382. iot_data.beatReturn = 2; //NG
  6383. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6384. stopwatch2.Stop();
  6385. AddMessage(LogType.Info,
  6386. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  6387. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6388. return;
  6389. }
  6390. //作业开始后要有物料和载具信息
  6391. if (string.IsNullOrEmpty(a7OEEPartNo) && string.IsNullOrEmpty(a7OEEVehicleCode) &&
  6392. Convert.ToInt32(oEEType) > 2)
  6393. {
  6394. stopwatch2.Start();
  6395. //写入PLC
  6396. iot_data.beatReturn = 2; //NG
  6397. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6398. stopwatch2.Stop();
  6399. AddMessage_Station(stationNameStr, LogType.Info,
  6400. stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  6401. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6402. return;
  6403. }
  6404. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a7OEEPartNo))
  6405. {
  6406. stopwatch2.Start();
  6407. //写入PLC
  6408. iot_data.beatReturn = 2; //NG
  6409. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6410. stopwatch2.Stop();
  6411. AddMessage_Station(stationNameStr, LogType.Info,
  6412. stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  6413. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6414. return;
  6415. }
  6416. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a7OEEVehicleCode))
  6417. {
  6418. stopwatch2.Start();
  6419. //写入PLC
  6420. iot_data.beatReturn = 2; //NG
  6421. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6422. stopwatch2.Stop();
  6423. AddMessage_Station(stationNameStr, LogType.Info,
  6424. stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  6425. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6426. return;
  6427. }
  6428. short _result = 0;
  6429. // 上传OEE
  6430. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a7OEEPartNo, a7OEEVehicleCode);
  6431. _result = result.Item1;
  6432. resultStr = result.Item2;
  6433. if (_result == 1)
  6434. {
  6435. stopwatch2.Start();
  6436. //写入PLC
  6437. iot_data.beatReturn = 1; //OK
  6438. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6439. OnMessage(LogType.Info,
  6440. $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  6441. stopwatch2.Stop();
  6442. }
  6443. else
  6444. {
  6445. stopwatch2.Start();
  6446. //写入PLC
  6447. iot_data.beatReturn = 2; //NG
  6448. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6449. stopwatch2.Stop();
  6450. AddMessage_Station(stationNameStr, LogType.Error,
  6451. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  6452. }
  6453. }
  6454. catch (Exception ex)
  6455. {
  6456. string str = ex.StackTrace;
  6457. AddMessage_Station(stationNameStr, LogType.Error,
  6458. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  6459. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6460. // MES_Flag
  6461. stopwatch2.Start();
  6462. //写入PLC
  6463. iot_data.beatReturn = 2; //NG
  6464. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6465. stopwatch2.Stop();
  6466. }
  6467. stopwatch1.Stop();
  6468. AddMessage(LogType.Info,
  6469. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6470. stopwatch2.ElapsedMilliseconds + "ms");
  6471. }
  6472. #endregion
  6473. #region S8
  6474. private Dictionary<string, object> s8PLCData = new Dictionary<string, object>();
  6475. private Dictionary<string, object> s8PLCSignal_Old = new Dictionary<string, object>();
  6476. /// <summary>
  6477. /// [S8] 3D螺丝高度检测设备
  6478. /// </summary>
  6479. /// <param name="plcNo">PLC编号</param>
  6480. private void ReadStation_S8(int plcNo)
  6481. {
  6482. string stationCode = "[OP90]";
  6483. string stationName = "NG下料";
  6484. string stationNameStr = stationCode + stationName;
  6485. string tagBaseName = "g_OP80_MES"; //标签变量名称
  6486. string tagMesCommName = "mesCommToPC"; //标签变量名称
  6487. string tagAgvCommName = "agvCommFrmPC";
  6488. string tagiotComnName = "iotData";
  6489. string tagBarsetName = "BarcodeSet";
  6490. string CarrierBarcode = "";
  6491. // 触发信号字典
  6492. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6493. s8PLCSignal_Old.Add("a8OEEType", 0); // 节拍类型(plc写入)
  6494. // PLC数据字典 赋值
  6495. s8PLCData.Add("a8OEEType", 0); // 节拍类型(plc写入)
  6496. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  6497. (int, string) result;
  6498. while (true)
  6499. {
  6500. try
  6501. {
  6502. if (!GlobalContext._IsCon_Funs1)
  6503. {
  6504. UpdatePLCMonitor(1, plcNo, 0);
  6505. continue;
  6506. }
  6507. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  6508. {
  6509. Stopwatch stopwatch1 = new Stopwatch();
  6510. Stopwatch stopwatch2 = new Stopwatch();
  6511. stopwatch1.Start();
  6512. stopwatch2.Start();
  6513. #region 一次性读取所有数据
  6514. // 一次性读取所有数据
  6515. result = FunsEip[plcNo]
  6516. .Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  6517. if (result.Item1 != 0)
  6518. {
  6519. //richTextBox1.AppendText("\n" + strRet);
  6520. }
  6521. else
  6522. {
  6523. //去除扫码产生的特殊字符
  6524. stPLC_MesData.BarcodeSet.strProductBarcode =
  6525. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  6526. stPLC_MesData.BarcodeSet.strPartBarcode =
  6527. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  6528. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  6529. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  6530. stPLC_MesData.BarcodeSet.strPCBBarcode =
  6531. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  6532. }
  6533. #endregion 一次性读取所有数据
  6534. stopwatch2.Stop();
  6535. //richTextBox1.AppendText("\n" + "读取成功");
  6536. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  6537. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  6538. ? XiaomiDeviceState.Unknown
  6539. : (XiaomiDeviceState)xmDeviceStateInt;
  6540. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  6541. s8PLCData["a8OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  6542. //报警信息
  6543. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  6544. stopwatch2.Stop();
  6545. #region 进站
  6546. try
  6547. {
  6548. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  6549. {
  6550. lock (lockObj)
  6551. {
  6552. if (!ProgressState)
  6553. {
  6554. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  6555. ProgressState = true;
  6556. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData,
  6557. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  6558. out ProgressState));
  6559. }
  6560. }
  6561. }
  6562. }
  6563. catch (Exception ex)
  6564. {
  6565. ProgressState = false;
  6566. string str = ex.StackTrace;
  6567. AddMessage_Station(stationNameStr, LogType.Error,
  6568. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6569. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6570. }
  6571. #endregion 进站
  6572. #region 出站
  6573. try
  6574. {
  6575. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  6576. {
  6577. lock (lockObj)
  6578. {
  6579. if (!ProgressState)
  6580. {
  6581. ProgressState = true;
  6582. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData,
  6583. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  6584. out ProgressState));
  6585. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  6586. uuid = "";
  6587. }
  6588. }
  6589. }
  6590. }
  6591. catch (Exception ex)
  6592. {
  6593. ProgressState = false;
  6594. string str = ex.StackTrace;
  6595. AddMessage_Station(stationNameStr, LogType.Error,
  6596. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6597. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6598. }
  6599. #endregion 出站
  6600. #region 节拍接口
  6601. try
  6602. {
  6603. int a8OEEType = Convert.ToInt32(s9PLCData["a8OEEType"]);
  6604. int a8OEETypeGOld = Convert.ToInt32(s9PLCSignal_Old["a8OEEType"]);
  6605. //若设备紧急复原后节拍重置
  6606. if (a8OEEType == 1)
  6607. {
  6608. a8OEETypeGOld = 0;
  6609. }
  6610. if (stPLC_MesData.iotData.BeatAction > 0)
  6611. {
  6612. if (a8OEEType != a8OEETypeGOld)
  6613. {
  6614. //如果上位机告诉PLC NG,PLC节拍会直接从1跳到4
  6615. if (a8OEETypeGOld <= 2 && a8OEEType == 4)
  6616. {
  6617. Task.Run(() =>
  6618. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  6619. CarrierBarcode,
  6620. stPLC_MesData.iotData));
  6621. }
  6622. else
  6623. {
  6624. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  6625. if ((a8OEETypeGOld == 1 && a8OEEType != 2) ||
  6626. (a8OEETypeGOld == 3 && a8OEEType != 4) ||
  6627. (a8OEETypeGOld == 5 && a8OEEType != 6))
  6628. {
  6629. //写入PLC
  6630. IoT_DataSet_t iotData = new IoT_DataSet_t();
  6631. iotData.machineState = stPLC_MesData.iotData.machineState;
  6632. iotData.work_type = stPLC_MesData.iotData.work_type;
  6633. iotData.testStatus = stPLC_MesData.iotData.testStatus;
  6634. iotData.BeatAction = stPLC_MesData.iotData.BeatAction;
  6635. iotData.beatReturn = 2; //NG
  6636. iotData.fault_codes = stPLC_MesData.iotData.fault_codes;
  6637. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  6638. 1, iotData);
  6639. AddMessage(LogType.Info,
  6640. stationNameStr +
  6641. $"_节拍接口-- 设备本次上传节拍[{a8OEEType}],未上传节拍[{a8OEETypeGOld}]的结束信号,请检查;总用时" +
  6642. stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6643. stopwatch2.ElapsedMilliseconds +
  6644. "ms");
  6645. return;
  6646. }
  6647. else
  6648. {
  6649. Task.Run(() =>
  6650. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  6651. CarrierBarcode,
  6652. stPLC_MesData.iotData));
  6653. //Task.Run(() =>
  6654. // S8节拍接口(plcNo, stationNameStr, tagBaseName,
  6655. // stPLC_MesData.iotData));
  6656. }
  6657. }
  6658. }
  6659. }
  6660. s8PLCSignal_Old["a8OEEType"] = s8PLCData["a8OEEType"];
  6661. }
  6662. catch (Exception ex)
  6663. {
  6664. string str = ex.StackTrace;
  6665. AddMessage_Station(stationNameStr, LogType.Error,
  6666. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  6667. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6668. }
  6669. #endregion
  6670. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6671. stopwatch1.Stop();
  6672. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6673. }
  6674. else
  6675. {
  6676. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6677. AddMessage_Station(stationNameStr, LogType.Info,
  6678. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6679. FunsEip[plcNo].Connect(); // 重连
  6680. }
  6681. }
  6682. catch (Exception ex)
  6683. {
  6684. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6685. AddMessage_Station(stationNameStr, LogType.Error,
  6686. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6687. }
  6688. Thread.Sleep(IntervalReadPLC);
  6689. }
  6690. }
  6691. /// <summary>
  6692. /// [S8] 3D螺丝高度检测设备 - 进站
  6693. /// </summary>
  6694. /// <param name="plcNo">PLC编号</param>
  6695. /// <param name="stationNameStr">工站全称</param>
  6696. /// <param name="stPLC_MesData"></param>
  6697. /// <param name="tagMesCommName"></param>
  6698. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  6699. string tagBarsetName, out bool ProgressState)
  6700. {
  6701. Stopwatch stopwatch1 = new Stopwatch();
  6702. Stopwatch stopwatch2 = new Stopwatch();
  6703. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6704. bool pass = a1Result == 1;
  6705. try
  6706. {
  6707. stopwatch1.Start();
  6708. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  6709. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  6710. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  6711. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  6712. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  6713. //载具码验证产品码
  6714. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  6715. if (string.IsNullOrEmpty(strProductBarcode))
  6716. {
  6717. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  6718. }
  6719. sn = strProductBarcode;
  6720. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  6721. // 产品SN(物料码)校验
  6722. List<TestItem> item = new List<TestItem>();
  6723. stopwatch2.Start();
  6724. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  6725. sn,
  6726. item, MachineId, StationId, pass, "01-SLOT-01");
  6727. stopwatch2.Stop();
  6728. //指令执行结果 1:OK 110:失败
  6729. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  6730. if (mesResultFrmWeb == 1)
  6731. {
  6732. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  6733. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  6734. }
  6735. //进站结果写入PLC
  6736. CommandFromPLC resultToPlC = new CommandFromPLC();
  6737. resultToPlC.cmd = 0;
  6738. resultToPlC.cmdParam = 0; //指令参数
  6739. resultToPlC.cmdResult = mesResultFrmWeb;
  6740. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6741. }
  6742. catch (Exception ex)
  6743. {
  6744. string str = ex.StackTrace;
  6745. AddMessage(LogType.Error,
  6746. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(
  6747. str.LastIndexOf("\\") + 1,
  6748. str.Length - str.LastIndexOf("\\") - 1));
  6749. CommandFromPLC resultToPlC = new CommandFromPLC();
  6750. resultToPlC.cmd = 0;
  6751. resultToPlC.cmdParam = 0; //指令参数
  6752. resultToPlC.cmdResult = 110;
  6753. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6754. }
  6755. stopwatch1.Stop();
  6756. AddMessage(LogType.Info,
  6757. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  6758. stopwatch2.ElapsedMilliseconds + "ms");
  6759. ProgressState = false;
  6760. }
  6761. /// <summary>
  6762. /// [S8] 3D螺丝高度检测设备 - 出站接口
  6763. /// </summary>
  6764. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  6765. string stationCode, string stationName, out bool ProgressState)
  6766. {
  6767. Stopwatch stopwatch1 = new Stopwatch();
  6768. Stopwatch stopwatch2 = new Stopwatch();
  6769. test_item_num = 0; //iot 过站明细序号
  6770. try
  6771. {
  6772. stopwatch1.Start();
  6773. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  6774. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6775. string processItem = stationName; // 测试项目
  6776. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6777. string supplierCode = ""; // 供应商代码
  6778. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6779. string batch_num = GlobalContext.BatchNumber; // 批次号
  6780. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6781. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  6782. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  6783. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  6784. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  6785. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6786. bool pass = a1Result == 1;
  6787. //根据载具码获取产品码
  6788. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  6789. if (string.IsNullOrEmpty(strProductBarcode))
  6790. {
  6791. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6792. }
  6793. sn = strProductBarcode;
  6794. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  6795. List<TestItem> items = new List<TestItem>();
  6796. items.Add(new TestItem()
  6797. {
  6798. Parameter_name = "载具码",
  6799. Parameter_value = CarrierBarcode,
  6800. Parameter_unit = ""
  6801. });
  6802. items.Add(new TestItem()
  6803. {
  6804. Parameter_name = "产品码",
  6805. Parameter_value = sn,
  6806. Parameter_unit = ""
  6807. });
  6808. #region 上传图片
  6809. if (GlobalContext.MQTTIsSendUpFile)
  6810. {
  6811. string[] urlarry = GlobalContext.UpFilePath.Split(",");
  6812. fileUploadData.fileData.Clear();
  6813. foreach (var item in urlarry)
  6814. {
  6815. if (!string.IsNullOrEmpty(item))
  6816. {
  6817. //上传图片
  6818. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName,
  6819. a1Result, item, uuid).Result;
  6820. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  6821. }
  6822. }
  6823. }
  6824. #endregion
  6825. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  6826. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6827. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  6828. MachineId, StationId, "", paramJson);
  6829. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  6830. if (mesResultFrmWeb == 1)
  6831. {
  6832. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  6833. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  6834. }
  6835. stopwatch2.Start();
  6836. //进站结果写入PLC
  6837. CommandFromPLC resultToPlC = new CommandFromPLC();
  6838. resultToPlC.cmd = 0;
  6839. resultToPlC.cmdParam = 0; //指令参数
  6840. resultToPlC.cmdResult = mesResultFrmWeb;
  6841. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6842. stopwatch2.Stop();
  6843. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  6844. //保存PLC返回MES数据到本地
  6845. ResponseMessage message = new ResponseMessage();
  6846. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  6847. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  6848. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  6849. if (message.result == false)
  6850. {
  6851. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  6852. }
  6853. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  6854. }
  6855. catch (Exception ex)
  6856. {
  6857. stopwatch2.Start();
  6858. CommandFromPLC resultToPlC = new CommandFromPLC();
  6859. resultToPlC.cmd = 0;
  6860. resultToPlC.cmdParam = 0; //指令参数
  6861. resultToPlC.cmdResult = 110;
  6862. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6863. stopwatch2.Stop();
  6864. string str = ex.StackTrace;
  6865. AddMessage(LogType.Error,
  6866. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  6867. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6868. }
  6869. stopwatch1.Stop();
  6870. AddMessage(LogType.Info,
  6871. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6872. stopwatch2.ElapsedMilliseconds + "ms");
  6873. ProgressState = false;
  6874. }
  6875. private void S8节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  6876. {
  6877. Stopwatch stopwatch1 = new Stopwatch();
  6878. Stopwatch stopwatch2 = new Stopwatch();
  6879. string resultStr = string.Empty;
  6880. try
  6881. {
  6882. stopwatch1.Start();
  6883. string oEEType = ((int)s1PLCData["a8OEEType"]).ToString(); // 节拍类型(plc写入)
  6884. string a80EEPartNo = (string)s1PLCData["a80EEPartNo"]; // 物料码
  6885. a80EEPartNo = a80EEPartNo.Replace("\0", "");
  6886. string a80EEVehicleCode = (string)s1PLCData["a80EEVehicleCode"]; // 载具SN
  6887. a80EEVehicleCode = a80EEVehicleCode.Replace("\0", "");
  6888. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6889. if (!actionBool)
  6890. {
  6891. stopwatch2.Start();
  6892. //写入PLC
  6893. iot_data.beatReturn = 2; //NG
  6894. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6895. stopwatch2.Stop();
  6896. AddMessage(LogType.Info,
  6897. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" +
  6898. stopwatch1.ElapsedMilliseconds +
  6899. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6900. return;
  6901. }
  6902. //作业开始后要有物料和载具信息
  6903. if (string.IsNullOrEmpty(a80EEPartNo) && string.IsNullOrEmpty(a80EEVehicleCode) &&
  6904. Convert.ToInt32(oEEType) > 2)
  6905. {
  6906. stopwatch2.Start();
  6907. //写入PLC
  6908. iot_data.beatReturn = 2; //NG
  6909. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6910. stopwatch2.Stop();
  6911. AddMessage_Station(stationNameStr, LogType.Info,
  6912. stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  6913. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6914. return;
  6915. }
  6916. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a80EEPartNo))
  6917. {
  6918. stopwatch2.Start();
  6919. //写入PLC
  6920. iot_data.beatReturn = 2; //NG
  6921. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6922. stopwatch2.Stop();
  6923. AddMessage_Station(stationNameStr, LogType.Info,
  6924. stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  6925. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6926. return;
  6927. }
  6928. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a80EEVehicleCode))
  6929. {
  6930. stopwatch2.Start();
  6931. //写入PLC
  6932. iot_data.beatReturn = 2; //NG
  6933. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6934. stopwatch2.Stop();
  6935. AddMessage_Station(stationNameStr, LogType.Info,
  6936. stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  6937. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6938. return;
  6939. }
  6940. short _result = 0;
  6941. // 上传OEE
  6942. (short, string) result =
  6943. SaveOEEData(plcNo, stationNameStr, deviceOEE, a80EEPartNo, a80EEVehicleCode);
  6944. _result = result.Item1;
  6945. resultStr = result.Item2;
  6946. if (_result == 1)
  6947. {
  6948. stopwatch2.Start();
  6949. //写入PLC
  6950. iot_data.beatReturn = 1; //OK
  6951. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6952. OnMessage(LogType.Info,
  6953. $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  6954. stopwatch2.Stop();
  6955. }
  6956. else
  6957. {
  6958. stopwatch2.Start();
  6959. //写入PLC
  6960. iot_data.beatReturn = 2; //NG
  6961. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6962. stopwatch2.Stop();
  6963. AddMessage_Station(stationNameStr, LogType.Error,
  6964. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  6965. }
  6966. }
  6967. catch (Exception ex)
  6968. {
  6969. string str = ex.StackTrace;
  6970. AddMessage_Station(stationNameStr, LogType.Error,
  6971. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  6972. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6973. // MES_Flag
  6974. stopwatch2.Start();
  6975. //写入PLC
  6976. iot_data.beatReturn = 2; //NG
  6977. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6978. stopwatch2.Stop();
  6979. }
  6980. stopwatch1.Stop();
  6981. AddMessage(LogType.Info,
  6982. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6983. stopwatch2.ElapsedMilliseconds + "ms");
  6984. }
  6985. #endregion
  6986. #region S9
  6987. private Dictionary<string, object> s9PLCData = new Dictionary<string, object>();
  6988. private Dictionary<string, object> s9PLCSignal_Old = new Dictionary<string, object>();
  6989. /// <summary>
  6990. /// [S9] 下料设备
  6991. /// </summary>
  6992. /// <param name="plcNo">PLC编号</param>
  6993. private void ReadStation_S9(int plcNo)
  6994. {
  6995. string stationCode = "[OP100]";
  6996. string stationName = "半成品下料";
  6997. string stationNameStr = stationCode + stationName;
  6998. string tagBaseName = "g_OP90_MES"; //标签变量名称
  6999. string tagMesCommName = "mesCommToPC"; //标签变量名称
  7000. string tagAgvCommName = "agvCommFrmPC";
  7001. string tagiotComnName = "iotData";
  7002. string tagBarsetName = "BarcodeSet";
  7003. string CarrierBarcode = "";
  7004. // 触发信号字典
  7005. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  7006. s9PLCSignal_Old.Add("a9OEEType", 0); // 节拍类型(plc写入)
  7007. // PLC数据字典 赋值
  7008. s9PLCData.Add("a9OEEType", 0); // 节拍类型(plc写入)
  7009. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  7010. (int, string) result;
  7011. while (true)
  7012. {
  7013. try
  7014. {
  7015. if (!GlobalContext._IsCon_Funs1)
  7016. {
  7017. UpdatePLCMonitor(1, plcNo, 0);
  7018. continue;
  7019. }
  7020. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  7021. {
  7022. Stopwatch stopwatch1 = new Stopwatch();
  7023. Stopwatch stopwatch2 = new Stopwatch();
  7024. stopwatch1.Start();
  7025. stopwatch2.Start();
  7026. #region 一次性读取所有数据
  7027. // 一次性读取所有数据
  7028. result = FunsEip[plcNo]
  7029. .Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  7030. if (result.Item1 != 0)
  7031. {
  7032. //richTextBox1.AppendText("\n" + strRet);
  7033. }
  7034. else
  7035. {
  7036. //去除扫码产生的特殊字符
  7037. stPLC_MesData.BarcodeSet.strProductBarcode =
  7038. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  7039. stPLC_MesData.BarcodeSet.strPartBarcode =
  7040. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  7041. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  7042. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  7043. stPLC_MesData.BarcodeSet.strPCBBarcode =
  7044. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  7045. //richTextBox1.AppendText("\n" + "读取成功");
  7046. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  7047. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  7048. ? XiaomiDeviceState.Unknown
  7049. : (XiaomiDeviceState)xmDeviceStateInt;
  7050. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  7051. s9PLCData["a9OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  7052. //报警信息
  7053. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  7054. }
  7055. #endregion 一次性读取所有数据
  7056. stopwatch2.Stop();
  7057. #region 进站
  7058. try
  7059. {
  7060. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  7061. {
  7062. lock (lockObj)
  7063. {
  7064. if (!ProgressState)
  7065. {
  7066. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  7067. ProgressState = true;
  7068. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData,
  7069. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  7070. out ProgressState));
  7071. }
  7072. }
  7073. }
  7074. }
  7075. catch (Exception ex)
  7076. {
  7077. ProgressState = false;
  7078. string str = ex.StackTrace;
  7079. AddMessage_Station(stationNameStr, LogType.Error,
  7080. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  7081. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7082. }
  7083. #endregion 进站
  7084. #region 出站
  7085. try
  7086. {
  7087. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  7088. {
  7089. lock (lockObj)
  7090. {
  7091. if (!ProgressState)
  7092. {
  7093. ProgressState = true;
  7094. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData,
  7095. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  7096. out ProgressState));
  7097. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  7098. uuid = "";
  7099. }
  7100. }
  7101. }
  7102. }
  7103. catch (Exception ex)
  7104. {
  7105. ProgressState = false;
  7106. string str = ex.StackTrace;
  7107. AddMessage_Station(stationNameStr, LogType.Error,
  7108. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  7109. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7110. }
  7111. #endregion 出站
  7112. #region 节拍接口
  7113. try
  7114. {
  7115. if (stPLC_MesData.iotData.BeatAction > 0)
  7116. {
  7117. int a9OEEType = Convert.ToInt32(s9PLCData["a9OEEType"]);
  7118. int a9OEETypeGOld = Convert.ToInt32(s9PLCSignal_Old["a9OEEType"]);
  7119. //若设备紧急复原后节拍重置
  7120. if (a9OEEType == 1)
  7121. {
  7122. a9OEETypeGOld = 0;
  7123. }
  7124. if (a9OEEType != a9OEETypeGOld)
  7125. {
  7126. //如果上位机告诉PLC NG,PLC节拍会直接从1跳到4
  7127. if (a9OEETypeGOld <= 2 && a9OEEType == 4)
  7128. {
  7129. Task.Run(() =>
  7130. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  7131. CarrierBarcode,
  7132. stPLC_MesData.iotData));
  7133. }
  7134. else
  7135. {
  7136. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  7137. if ((a9OEETypeGOld == 1 && a9OEEType != 2) ||
  7138. (a9OEETypeGOld == 3 && a9OEEType != 4) ||
  7139. (a9OEETypeGOld == 5 && a9OEEType != 6))
  7140. {
  7141. //写入PLC
  7142. IoT_DataSet_t iotData = new IoT_DataSet_t();
  7143. iotData.machineState = stPLC_MesData.iotData.machineState;
  7144. iotData.work_type = stPLC_MesData.iotData.work_type;
  7145. iotData.testStatus = stPLC_MesData.iotData.testStatus;
  7146. iotData.BeatAction = stPLC_MesData.iotData.BeatAction;
  7147. iotData.beatReturn = 2; //NG
  7148. iotData.fault_codes = stPLC_MesData.iotData.fault_codes;
  7149. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  7150. 1, iotData);
  7151. AddMessage(LogType.Info,
  7152. stationNameStr +
  7153. $"_节拍接口-- 设备本次上传节拍[{a9OEEType}],未上传节拍[{a9OEETypeGOld}]的结束信号,请检查;总用时" +
  7154. stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7155. stopwatch2.ElapsedMilliseconds +
  7156. "ms");
  7157. return;
  7158. }
  7159. else
  7160. {
  7161. Task.Run(() =>
  7162. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  7163. CarrierBarcode,
  7164. stPLC_MesData.iotData));
  7165. //Task.Run(() =>
  7166. // S9节拍接口(plcNo, stationNameStr, tagBaseName,
  7167. // stPLC_MesData.iotData));
  7168. }
  7169. }
  7170. }
  7171. }
  7172. s9PLCSignal_Old["a9OEEType"] = s9PLCData["a9OEEType"];
  7173. }
  7174. catch (Exception ex)
  7175. {
  7176. string str = ex.StackTrace;
  7177. AddMessage_Station(stationNameStr, LogType.Error,
  7178. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  7179. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7180. }
  7181. #endregion
  7182. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7183. stopwatch1.Stop();
  7184. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7185. }
  7186. else
  7187. {
  7188. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7189. AddMessage_Station(stationNameStr, LogType.Info,
  7190. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  7191. FunsEip[plcNo].Connect(); // 重连
  7192. }
  7193. }
  7194. catch (Exception ex)
  7195. {
  7196. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7197. AddMessage_Station(stationNameStr, LogType.Error,
  7198. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  7199. }
  7200. Thread.Sleep(IntervalReadPLC);
  7201. }
  7202. }
  7203. /// <summary>
  7204. /// [S9] 下料设备 - 进站
  7205. /// </summary>
  7206. /// <param name="plcNo">PLC编号</param>
  7207. /// <param name="stationNameStr">工站全称</param>
  7208. /// <param name="stPLC_MesData"></param>
  7209. /// <param name="tagMesCommName"></param>
  7210. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  7211. string tagBarsetName, out bool ProgressState)
  7212. {
  7213. Stopwatch stopwatch1 = new Stopwatch();
  7214. Stopwatch stopwatch2 = new Stopwatch();
  7215. try
  7216. {
  7217. stopwatch1.Start();
  7218. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  7219. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  7220. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  7221. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  7222. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  7223. bool pass = a1Result == 1;
  7224. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  7225. //载具码验证产品码
  7226. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  7227. if (string.IsNullOrEmpty(strProductBarcode))
  7228. {
  7229. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  7230. }
  7231. sn = strProductBarcode;
  7232. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  7233. // 产品SN(物料码)校验
  7234. List<TestItem> item = new List<TestItem>();
  7235. stopwatch2.Start();
  7236. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  7237. item, MachineId, StationId, pass, "01-SLOT-01");
  7238. stopwatch2.Stop();
  7239. //指令执行结果 1:OK 110:失败
  7240. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  7241. if (mesResultFrmWeb == 1)
  7242. {
  7243. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  7244. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  7245. }
  7246. //进站结果写入PLC
  7247. CommandFromPLC resultToPlC = new CommandFromPLC();
  7248. resultToPlC.cmd = 0;
  7249. resultToPlC.cmdParam = 0; //指令参数
  7250. resultToPlC.cmdResult = mesResultFrmWeb;
  7251. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  7252. }
  7253. catch (Exception ex)
  7254. {
  7255. string str = ex.StackTrace;
  7256. AddMessage(LogType.Error,
  7257. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  7258. str.Length - str.LastIndexOf("\\") - 1));
  7259. CommandFromPLC resultToPlC = new CommandFromPLC();
  7260. resultToPlC.cmd = 0;
  7261. resultToPlC.cmdParam = 0; //指令参数
  7262. resultToPlC.cmdResult = 110;
  7263. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  7264. }
  7265. stopwatch1.Stop();
  7266. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  7267. AddMessage(LogType.Info,
  7268. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  7269. stopwatch2.ElapsedMilliseconds + "ms");
  7270. ProgressState = false;
  7271. }
  7272. /// <summary>
  7273. /// [S9] 下料设备 - 出站接口
  7274. /// </summary>
  7275. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  7276. string stationCode, string stationName, out bool ProgressState)
  7277. {
  7278. Stopwatch stopwatch1 = new Stopwatch();
  7279. Stopwatch stopwatch2 = new Stopwatch();
  7280. test_item_num = 0; //iot 过站明细序号
  7281. try
  7282. {
  7283. stopwatch1.Start();
  7284. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  7285. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7286. string processItem = stationName; // 测试项目
  7287. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7288. string supplierCode = ""; // 供应商代码
  7289. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7290. string batch_num = GlobalContext.BatchNumber; // 批次号
  7291. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7292. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  7293. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  7294. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  7295. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  7296. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  7297. bool pass = a1Result == 1;
  7298. //根据载具码获取产品码
  7299. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  7300. if (string.IsNullOrEmpty(strProductBarcode))
  7301. {
  7302. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  7303. }
  7304. sn = strProductBarcode;
  7305. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  7306. List<TestItem> items = new List<TestItem>();
  7307. items.Add(new TestItem()
  7308. {
  7309. Parameter_name = "载具码",
  7310. Parameter_value = CarrierBarcode,
  7311. Parameter_unit = ""
  7312. });
  7313. items.Add(new TestItem()
  7314. {
  7315. Parameter_name = "产品码",
  7316. Parameter_value = sn,
  7317. Parameter_unit = ""
  7318. });
  7319. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  7320. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  7321. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  7322. MachineId, StationId, "", paramJson);
  7323. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  7324. if (mesResultFrmWeb == 1)
  7325. {
  7326. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  7327. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  7328. }
  7329. stopwatch2.Start();
  7330. //进站结果写入PLC
  7331. CommandFromPLC resultToPlC = new CommandFromPLC();
  7332. resultToPlC.cmd = 0;
  7333. resultToPlC.cmdParam = 0; //指令参数
  7334. resultToPlC.cmdResult = mesResultFrmWeb;
  7335. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  7336. stopwatch2.Stop();
  7337. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  7338. //保存PLC返回MES数据到本地
  7339. ResponseMessage message = new ResponseMessage();
  7340. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  7341. stPLC_MesData.mesData.nRemainCount);
  7342. if (message.result == false)
  7343. {
  7344. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  7345. }
  7346. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  7347. if (result1 == 1)
  7348. {
  7349. //载具码解除绑定
  7350. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  7351. if (message.result == false)
  7352. {
  7353. AddMessage(LogType.Error, message.text);
  7354. }
  7355. }
  7356. }
  7357. catch (Exception ex)
  7358. {
  7359. stopwatch2.Start();
  7360. CommandFromPLC resultToPlC = new CommandFromPLC();
  7361. resultToPlC.cmd = 0;
  7362. resultToPlC.cmdParam = 0; //指令参数
  7363. resultToPlC.cmdResult = 110;
  7364. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  7365. stopwatch2.Stop();
  7366. string str = ex.StackTrace;
  7367. AddMessage(LogType.Error,
  7368. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  7369. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7370. }
  7371. stopwatch1.Stop();
  7372. AddMessage(LogType.Info,
  7373. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7374. stopwatch2.ElapsedMilliseconds + "ms");
  7375. ProgressState = false;
  7376. }
  7377. private void S9节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  7378. {
  7379. Stopwatch stopwatch1 = new Stopwatch();
  7380. Stopwatch stopwatch2 = new Stopwatch();
  7381. string resultStr = string.Empty;
  7382. try
  7383. {
  7384. stopwatch1.Start();
  7385. string oEEType = ((int)s1PLCData["a9OEEType"]).ToString(); // 节拍类型(plc写入)
  7386. string a90EEPartNo = (string)s1PLCData["a90EEPartNo"]; // 物料码
  7387. a90EEPartNo = a90EEPartNo.Replace("\0", "");
  7388. string a90EEVehicleCode = (string)s1PLCData["a90EEVehicleCode"]; // 载具SN
  7389. a90EEVehicleCode = a90EEVehicleCode.Replace("\0", "");
  7390. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7391. if (!actionBool)
  7392. {
  7393. stopwatch2.Start();
  7394. //写入PLC
  7395. iot_data.beatReturn = 2; //NG
  7396. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7397. stopwatch2.Stop();
  7398. AddMessage(LogType.Info,
  7399. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  7400. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7401. return;
  7402. }
  7403. //作业开始后要有物料和载具信息
  7404. if (string.IsNullOrEmpty(a90EEPartNo) && string.IsNullOrEmpty(a90EEVehicleCode) &&
  7405. Convert.ToInt32(oEEType) > 2)
  7406. {
  7407. stopwatch2.Start();
  7408. //写入PLC
  7409. iot_data.beatReturn = 2; //NG
  7410. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7411. stopwatch2.Stop();
  7412. AddMessage_Station(stationNameStr, LogType.Info,
  7413. stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  7414. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7415. return;
  7416. }
  7417. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a90EEPartNo))
  7418. {
  7419. stopwatch2.Start();
  7420. //写入PLC
  7421. iot_data.beatReturn = 2; //NG
  7422. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7423. stopwatch2.Stop();
  7424. AddMessage_Station(stationNameStr, LogType.Info,
  7425. stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  7426. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7427. return;
  7428. }
  7429. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a90EEVehicleCode))
  7430. {
  7431. stopwatch2.Start();
  7432. //写入PLC
  7433. iot_data.beatReturn = 2; //NG
  7434. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7435. stopwatch2.Stop();
  7436. AddMessage_Station(stationNameStr, LogType.Info,
  7437. stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  7438. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7439. return;
  7440. }
  7441. short _result = 0;
  7442. // 上传OEE
  7443. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a90EEPartNo, a90EEVehicleCode);
  7444. _result = result.Item1;
  7445. resultStr = result.Item2;
  7446. if (_result == 1)
  7447. {
  7448. stopwatch2.Start();
  7449. //写入PLC
  7450. iot_data.beatReturn = 1; //OK
  7451. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7452. OnMessage(LogType.Info,
  7453. $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  7454. stopwatch2.Stop();
  7455. }
  7456. else
  7457. {
  7458. stopwatch2.Start();
  7459. //写入PLC
  7460. iot_data.beatReturn = 2; //NG
  7461. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7462. stopwatch2.Stop();
  7463. AddMessage_Station(stationNameStr, LogType.Error,
  7464. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  7465. }
  7466. }
  7467. catch (Exception ex)
  7468. {
  7469. string str = ex.StackTrace;
  7470. AddMessage_Station(stationNameStr, LogType.Error,
  7471. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  7472. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7473. // MES_Flag
  7474. stopwatch2.Start();
  7475. //写入PLC
  7476. iot_data.beatReturn = 2; //NG
  7477. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7478. stopwatch2.Stop();
  7479. }
  7480. stopwatch1.Stop();
  7481. AddMessage(LogType.Info,
  7482. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7483. stopwatch2.ElapsedMilliseconds + "ms");
  7484. }
  7485. #endregion
  7486. #endregion Xiaomi
  7487. #region PLC1 张超凡
  7488. #region [S1] Tray盘上料装备(板测)
  7489. /// <summary>
  7490. /// S1工位的数据- 触发信号上次的值
  7491. /// </summary>
  7492. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  7493. /// <summary>
  7494. /// S1工位的数据(含触发信号)
  7495. /// </summary>
  7496. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  7497. /// <summary>
  7498. /// S1工位的数据- 回写点位
  7499. /// </summary>
  7500. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  7501. ///// <summary>
  7502. ///// 触发信号
  7503. ///// </summary>
  7504. //private ManualResetEvent[] MreTasks;
  7505. /// <summary>
  7506. /// [S1] Tray盘上料装备(板测)
  7507. /// </summary>
  7508. /// <param name="plcNo">PLC编号</param>
  7509. //private void ReadStation_S1(int plcNo)
  7510. //{
  7511. // // [S1] Tray盘上料装备
  7512. // // [S2] FCT
  7513. // // [S3] 值板机
  7514. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  7515. // // [S5] Tray盘下料装备
  7516. // string stationCode = "[S1]";
  7517. // string stationName = "Tray盘上料装备";
  7518. // string stationNameStr = stationCode + stationName;
  7519. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  7520. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  7521. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  7522. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  7523. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  7524. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  7525. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  7526. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  7527. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  7528. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  7529. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  7530. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  7531. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  7532. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  7533. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  7534. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  7535. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  7536. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  7537. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  7538. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  7539. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  7540. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  7541. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  7542. // s1PLCData.Add("a1Result", 0); // 产品结果
  7543. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  7544. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  7545. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  7546. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  7547. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  7548. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  7549. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  7550. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  7551. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  7552. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  7553. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  7554. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  7555. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  7556. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  7557. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  7558. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  7559. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  7560. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  7561. // while (IsRun)
  7562. // {
  7563. // try
  7564. // {
  7565. // if (!GlobalContext._IsCon_Funs1)
  7566. // {
  7567. // UpdatePLCMonitor(1, plcNo, 0);
  7568. // continue;
  7569. // }
  7570. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  7571. // {
  7572. // Stopwatch stopwatch1 = new Stopwatch();
  7573. // Stopwatch stopwatch2 = new Stopwatch();
  7574. // stopwatch1.Start();
  7575. // stopwatch2.Start();
  7576. // #region 一次性读取所有数据
  7577. // // 一次性读取所有数据
  7578. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  7579. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  7580. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  7581. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  7582. // int[] datas = data1.Concat(data2).ToArray();
  7583. // datas = datas.Concat(data3).ToArray();
  7584. // datas = datas.Concat(data4).ToArray();
  7585. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  7586. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  7587. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  7588. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  7589. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  7590. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  7591. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  7592. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  7593. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  7594. // s1PLCData["a1MES_FLAG"] = datas[109];
  7595. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  7596. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  7597. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  7598. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  7599. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  7600. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  7601. // s1PLCData["a1Result"] = datas[170];
  7602. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  7603. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  7604. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  7605. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  7606. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  7607. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  7608. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  7609. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  7610. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  7611. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  7612. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  7613. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  7614. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  7615. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  7616. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  7617. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  7618. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  7619. // s1PLCData["a1AGVUpStart"] = datas[308];
  7620. // s1PLCData["a1AGVUpEnd"] = datas[309];
  7621. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  7622. // s1PLCData["a1AGVDownStart"] = datas[321];
  7623. // s1PLCData["a1AGVDownEnd"] = datas[322];
  7624. // #endregion 一次性读取所有数据
  7625. // stopwatch2.Stop();
  7626. // #region 回写操作,写后清空flag
  7627. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  7628. // #endregion 回写操作,写后清空flag
  7629. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  7630. // try
  7631. // {
  7632. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  7633. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  7634. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  7635. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  7636. // {
  7637. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  7638. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  7639. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  7640. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  7641. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  7642. // }
  7643. // }
  7644. // catch (Exception ex)
  7645. // {
  7646. // // 6代表上位机报警
  7647. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  7648. // string str = ex.StackTrace;
  7649. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7650. // }
  7651. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  7652. // #region 上料进站校验
  7653. // try
  7654. // {
  7655. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  7656. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  7657. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  7658. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  7659. // {
  7660. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  7661. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  7662. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  7663. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  7664. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  7665. // }
  7666. // }
  7667. // catch (Exception ex)
  7668. // {
  7669. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7670. // string str = ex.StackTrace;
  7671. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7672. // }
  7673. // #endregion 上料进站校验
  7674. // #region Tray盘上料装备-出站接口
  7675. // try
  7676. // {
  7677. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  7678. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  7679. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  7680. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  7681. // {
  7682. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  7683. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  7684. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  7685. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  7686. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  7687. // }
  7688. // }
  7689. // catch (Exception ex)
  7690. // {
  7691. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  7692. // string str = ex.StackTrace;
  7693. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7694. // }
  7695. // #endregion Tray盘上料装备-出站接口
  7696. // #region Tray盘上料装备-将SN发给ICT标机
  7697. // try
  7698. // {
  7699. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  7700. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  7701. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  7702. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  7703. // {
  7704. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  7705. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  7706. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  7707. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  7708. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  7709. // }
  7710. // }
  7711. // catch (Exception ex)
  7712. // {
  7713. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  7714. // string str = ex.StackTrace;
  7715. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7716. // }
  7717. // #endregion Tray盘上料装备-将SN发给ICT标机
  7718. // #region Tray盘上料装备-点检数据
  7719. // //try
  7720. // //{
  7721. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  7722. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  7723. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  7724. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  7725. // // if (pLC_Flag && !mES_Flag) // 1 0
  7726. // // {
  7727. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  7728. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  7729. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  7730. // // }
  7731. // // else if (!pLC_Flag && mES_Flag) // 0 1
  7732. // // {
  7733. // // // 清空写给PLC的数据
  7734. // // // MES_Flag重置为0
  7735. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  7736. // // }
  7737. // //}
  7738. // //catch (Exception ex)
  7739. // //{
  7740. // // // MES_Flag 为2上位机报错
  7741. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  7742. // // string str = ex.StackTrace;
  7743. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7744. // //}
  7745. // #endregion Tray盘上料装备-点检数据
  7746. // #region 节拍接口
  7747. // try
  7748. // {
  7749. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  7750. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  7751. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  7752. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  7753. // {
  7754. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  7755. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7756. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  7757. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  7758. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  7759. // }
  7760. // }
  7761. // catch (Exception ex)
  7762. // {
  7763. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  7764. // string str = ex.StackTrace;
  7765. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7766. // }
  7767. // #endregion 节拍接口
  7768. // #region AGV上料
  7769. // // AGV上料叫AGV信号
  7770. // try
  7771. // {
  7772. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  7773. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  7774. // if (a1AGVUpCall != a1AGVUpCallOld)
  7775. // {
  7776. // if (a1AGVUpCall == 1) // 0->1
  7777. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  7778. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  7779. // }
  7780. // }
  7781. // catch (Exception ex)
  7782. // {
  7783. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  7784. // string str = ex.StackTrace;
  7785. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7786. // }
  7787. // // AGV上料完成信号
  7788. // try
  7789. // {
  7790. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  7791. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  7792. // if (a1AGVUpEnd != a1AGVUpEndOld)
  7793. // {
  7794. // if (a1AGVUpEnd == 1) // 0->1
  7795. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  7796. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  7797. // }
  7798. // }
  7799. // catch (Exception ex)
  7800. // {
  7801. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  7802. // string str = ex.StackTrace;
  7803. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7804. // }
  7805. // #endregion AGV上料
  7806. // #region AGV下料
  7807. // // AGV下料叫agv信号
  7808. // try
  7809. // {
  7810. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  7811. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  7812. // if (a1AGVDownCall != a1AGVDownCallOld)
  7813. // {
  7814. // if (a1AGVDownCall == 1) // 0->1
  7815. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  7816. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  7817. // }
  7818. // }
  7819. // catch (Exception ex)
  7820. // {
  7821. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  7822. // string str = ex.StackTrace;
  7823. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7824. // }
  7825. // // AGV下料完成信号
  7826. // try
  7827. // {
  7828. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  7829. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  7830. // if (a1AGVDownEnd != a1AGVDownEndOld)
  7831. // {
  7832. // if (a1AGVDownEnd == 1) // 0->1
  7833. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  7834. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  7835. // }
  7836. // }
  7837. // catch (Exception ex)
  7838. // {
  7839. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  7840. // string str = ex.StackTrace;
  7841. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7842. // }
  7843. // #endregion AGV下料
  7844. // #region 心跳
  7845. // try
  7846. // {
  7847. // short states = 0;
  7848. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7849. // }
  7850. // catch (Exception ex)
  7851. // {
  7852. // string str = ex.StackTrace;
  7853. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7854. // }
  7855. // #endregion 心跳
  7856. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7857. // stopwatch1.Stop();
  7858. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7859. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7860. // }
  7861. // else
  7862. // {
  7863. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7864. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  7865. // Funs[plcNo].Connect(); // 重连
  7866. // }
  7867. // }
  7868. // catch (Exception ex)
  7869. // {
  7870. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7871. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  7872. // Funs[plcNo].ReConnect();
  7873. // }
  7874. // Thread.Sleep(IntervalReadPLC);
  7875. // }
  7876. //}
  7877. /// <summary>
  7878. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  7879. /// </summary>
  7880. /// <param name="plcNo">PLC编号</param>
  7881. /// <param name="stationNameStr">工站全称</param>
  7882. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  7883. {
  7884. Stopwatch stopwatch1 = new Stopwatch();
  7885. Stopwatch stopwatch2 = new Stopwatch();
  7886. try
  7887. {
  7888. stopwatch1.Start();
  7889. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  7890. sn = sn.Replace("\0", "");
  7891. #region 查询载具上的产品信息
  7892. string cavityData = string.Empty;
  7893. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  7894. if (string.IsNullOrEmpty(cavityData))
  7895. cavityData = "";
  7896. if (snResult != 0)
  7897. {
  7898. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7899. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  7900. writeToPLC_Flag1.Adress = 2003;
  7901. writeToPLC_Flag1.Value = (short)6;
  7902. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  7903. stopwatch1.Stop();
  7904. AddMessage(LogType.Info,
  7905. stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  7906. "ms");
  7907. return;
  7908. }
  7909. #endregion 查询载具上的产品信息
  7910. string[] cavitySNs = cavityData.Split('.');
  7911. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  7912. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  7913. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  7914. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  7915. if (cavitySNs != null && cavitySNs.Length >= 2)
  7916. {
  7917. a1CavitySN1_VehicleStates = cavitySNs[0];
  7918. a1CavitySN2_VehicleStates = cavitySNs[1];
  7919. a1CavityResult1_VehicleStates = 2;
  7920. a1CavityResult2_VehicleStates = 2;
  7921. }
  7922. if (a1CavitySN1_VehicleStates == "假产品")
  7923. a1CavityResult1_VehicleStates = 3;
  7924. if (a1CavitySN2_VehicleStates == "假产品")
  7925. a1CavityResult2_VehicleStates = 3;
  7926. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7927. // 回写
  7928. stopwatch2.Start();
  7929. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  7930. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  7931. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  7932. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  7933. //// MES_Flag
  7934. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  7935. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7936. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  7937. writeToPLC_Flag.Adress = 2003;
  7938. writeToPLC_Flag.Value = mES_Flag;
  7939. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7940. {
  7941. Name = "a1CavitySN1_VehicleStates",
  7942. Adress = 2024,
  7943. ValueType = PLCValueType.String,
  7944. ValueTypeStrLength = 20,
  7945. Value = a1CavitySN1_VehicleStates
  7946. });
  7947. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  7948. {
  7949. Name = "a1CavitySN2_VehicleStates",
  7950. Adress = 2044,
  7951. ValueType = PLCValueType.String,
  7952. ValueTypeStrLength = 20,
  7953. Value = a1CavitySN2_VehicleStates
  7954. });
  7955. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  7956. {
  7957. Name = "a1CavityResult1_VehicleStates",
  7958. Adress = 2064,
  7959. ValueType = PLCValueType.Short,
  7960. Value = a1CavityResult1_VehicleStates
  7961. });
  7962. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  7963. {
  7964. Name = "a1CavityResult2_VehicleStates",
  7965. Adress = 2065,
  7966. ValueType = PLCValueType.Short,
  7967. Value = a1CavityResult2_VehicleStates
  7968. });
  7969. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  7970. stopwatch2.Stop();
  7971. }
  7972. catch (Exception ex)
  7973. {
  7974. string str = ex.StackTrace;
  7975. AddMessage_Station(stationNameStr, LogType.Error,
  7976. $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" +
  7977. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7978. // MES_Flag
  7979. stopwatch2.Start();
  7980. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7981. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7982. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  7983. writeToPLC_Flag.Adress = 2003;
  7984. writeToPLC_Flag.Value = (short)6;
  7985. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  7986. stopwatch2.Stop();
  7987. }
  7988. stopwatch1.Stop();
  7989. AddMessage(LogType.Info,
  7990. stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7991. stopwatch2.ElapsedMilliseconds + "ms");
  7992. }
  7993. /// <summary>
  7994. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  7995. /// </summary>
  7996. /// <param name="plcNo">PLC编号</param>
  7997. /// <param name="stationNameStr">工站全称</param>
  7998. private void S1上料进站校验(int plcNo, string stationNameStr)
  7999. {
  8000. Stopwatch stopwatch1 = new Stopwatch();
  8001. Stopwatch stopwatch2 = new Stopwatch();
  8002. try
  8003. {
  8004. stopwatch1.Start();
  8005. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  8006. sn = sn.Replace("\0", "");
  8007. // 保存进站数据+调用进站MES接口
  8008. List<TestItem> item = new List<TestItem>();
  8009. stopwatch2.Start();
  8010. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  8011. item, out string errorMsg);
  8012. stopwatch2.Stop();
  8013. short a1MES_FLAG_Check = (short)result;
  8014. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8015. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8016. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  8017. writeToPLC_Flag.Adress = 2077;
  8018. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  8019. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  8020. }
  8021. catch (Exception ex)
  8022. {
  8023. string str = ex.StackTrace;
  8024. AddMessage_Station(stationNameStr, LogType.Error,
  8025. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  8026. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8027. // MES_Flag
  8028. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  8029. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8030. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  8031. writeToPLC_Flag.Adress = 2077;
  8032. writeToPLC_Flag.Value = (short)6;
  8033. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  8034. }
  8035. stopwatch1.Stop();
  8036. AddMessage(LogType.Info,
  8037. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  8038. stopwatch2.ElapsedMilliseconds + "ms");
  8039. }
  8040. /// <summary>
  8041. /// [S1] Tray盘上料装备(板测)- 出站接口
  8042. /// </summary>
  8043. /// <param name="plcNo"></param>
  8044. /// <param name="stationCode"></param>
  8045. /// <param name="stationName"></param>
  8046. private void S1出站接口(int plcNo, string stationCode, string stationName)
  8047. {
  8048. Stopwatch stopwatch1 = new Stopwatch();
  8049. Stopwatch stopwatch2 = new Stopwatch();
  8050. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8051. string stationNameStr = stationCode + stationName;
  8052. string processItem = stationName; // 测试项目
  8053. try
  8054. {
  8055. stopwatch1.Start();
  8056. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8057. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8058. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8059. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8060. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  8061. sn = sn.Replace("\0", "");
  8062. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  8063. partNo1 = partNo1.Replace("\0", "");
  8064. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  8065. partNo2 = partNo2.Replace("\0", "");
  8066. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  8067. bool pass = a1Result == 1;
  8068. stopwatch2.Start();
  8069. // 产品1
  8070. List<TestItem> items = new List<TestItem>();
  8071. items.Add(new TestItem()
  8072. {
  8073. Parameter_name = "载具码",
  8074. Parameter_value = sn,
  8075. Parameter_unit = ""
  8076. });
  8077. items.Add(new TestItem()
  8078. {
  8079. Parameter_name = "载具穴号",
  8080. Parameter_value = "1",
  8081. Parameter_unit = ""
  8082. });
  8083. items.Add(new TestItem()
  8084. {
  8085. Parameter_name = "产品结果",
  8086. Parameter_value = a1Result == 1 ? "OK" : "NG",
  8087. Parameter_unit = ""
  8088. });
  8089. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  8090. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  8091. // 产品2
  8092. items = new List<TestItem>();
  8093. items.Add(new TestItem()
  8094. {
  8095. Parameter_name = "载具码",
  8096. Parameter_value = sn,
  8097. Parameter_unit = ""
  8098. });
  8099. items.Add(new TestItem()
  8100. {
  8101. Parameter_name = "载具穴号",
  8102. Parameter_value = "2",
  8103. Parameter_unit = ""
  8104. });
  8105. items.Add(new TestItem()
  8106. {
  8107. Parameter_name = "产品结果",
  8108. Parameter_value = a1Result == 1 ? "OK" : "NG",
  8109. Parameter_unit = ""
  8110. });
  8111. int result2 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  8112. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  8113. short result = 0;
  8114. List<int> results = new List<int>() { result1, result2 };
  8115. if (result1 == 1 && result2 == 1)
  8116. result = 1;
  8117. else if (results.Contains(3))
  8118. result = 3;
  8119. else if (results.Contains(2))
  8120. result = 2;
  8121. else if (results.Contains(4))
  8122. result = 4;
  8123. else
  8124. result = 4;
  8125. stopwatch2.Stop();
  8126. #region 存储绑定数据到 边线MES系统中
  8127. if (result == 1)
  8128. {
  8129. string data = string.Concat(partNo1, ".", partNo2);
  8130. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  8131. if (resultMesR != 0)
  8132. {
  8133. result = 4;
  8134. AddMessage_Station(stationNameStr, LogType.Error,
  8135. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  8136. }
  8137. }
  8138. #endregion 存储绑定数据到 边线MES系统中
  8139. // MES_Flag 为MES报错
  8140. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8141. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  8142. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8143. writeToPLC_Flag.Name = "a1MES_FLAG";
  8144. writeToPLC_Flag.Adress = 2109;
  8145. writeToPLC_Flag.Value = result;
  8146. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  8147. OnMessage(LogType.Debug,
  8148. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8149. }
  8150. catch (Exception ex)
  8151. {
  8152. stopwatch2.Restart();
  8153. // MES_Flag 为4上位机报错
  8154. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  8155. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8156. writeToPLC_Flag.Name = "a1MES_FLAG";
  8157. writeToPLC_Flag.Adress = 2109;
  8158. writeToPLC_Flag.Value = (short)4;
  8159. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  8160. stopwatch2.Stop();
  8161. string str = ex.StackTrace;
  8162. AddMessage_Station(stationNameStr, LogType.Error,
  8163. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  8164. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8165. }
  8166. stopwatch1.Stop();
  8167. AddMessage(LogType.Info,
  8168. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  8169. stopwatch2.ElapsedMilliseconds + "ms");
  8170. }
  8171. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  8172. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  8173. //{
  8174. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8175. // string stationNameStr = stationCode + stationName;
  8176. // string processItem = stationName; // 测试项目
  8177. // try
  8178. // {
  8179. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8180. // string accno = "1"; // 工序编号
  8181. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  8182. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  8183. // List<OneCheckItem> items = new List<OneCheckItem>()
  8184. // {
  8185. // new OneCheckItem()
  8186. // {
  8187. // Onecheck_name="胶圈装配行程设定上限",
  8188. // Onecheck_content="上限值",
  8189. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  8190. // },
  8191. // };
  8192. // OneCheckData oneCheckData = new OneCheckData()
  8193. // {
  8194. // Line_code = GlobalContext.LineCode,
  8195. // Line_name = GlobalContext.LineName,
  8196. // Equipment_code = equipmentCode,
  8197. // Equipment_name = equipmentCode,
  8198. // Workorder_code = workorder_code,
  8199. // Procedure_code = accno,
  8200. // Procedure_name = processItem,
  8201. // Oneckeck_values = items,
  8202. // Onecheck_empcode = "",
  8203. // Onecheck_empname = "",
  8204. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  8205. // };
  8206. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  8207. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  8208. // short result = result1 == 1 ? (short)1 : (short)2;
  8209. // // MES_Flag 为4MES报错
  8210. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  8211. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8212. // }
  8213. // catch (Exception ex)
  8214. // {
  8215. // // MES_Flag 为2上位机报错
  8216. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  8217. // string str = ex.StackTrace;
  8218. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8219. // }
  8220. //}
  8221. // ReadStation_S1_2 节拍接口+AGV
  8222. /// <summary>
  8223. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  8224. /// </summary>
  8225. /// <param name="plcNo">PLC编号</param>
  8226. /// <param name="stationNameStr">工站全称</param>
  8227. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  8228. {
  8229. Stopwatch stopwatch1 = new Stopwatch();
  8230. Stopwatch stopwatch2 = new Stopwatch();
  8231. try
  8232. {
  8233. stopwatch1.Start();
  8234. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  8235. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  8236. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  8237. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  8238. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  8239. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  8240. // ZS 将SN发给ICT标机(串口)
  8241. short a1MES_FLAG_ICT = 1;
  8242. stopwatch2.Start();
  8243. // MES_Flag
  8244. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  8245. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8246. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  8247. writeToPLC_Flag.Adress = 2182;
  8248. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  8249. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  8250. stopwatch2.Stop();
  8251. }
  8252. catch (Exception ex)
  8253. {
  8254. string str = ex.StackTrace;
  8255. AddMessage_Station(stationNameStr, LogType.Error,
  8256. $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" +
  8257. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8258. stopwatch2.Start();
  8259. // MES_Flag
  8260. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  8261. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8262. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  8263. writeToPLC_Flag.Adress = 2182;
  8264. writeToPLC_Flag.Value = (short)4;
  8265. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  8266. stopwatch2.Stop();
  8267. }
  8268. stopwatch1.Stop();
  8269. AddMessage(LogType.Info,
  8270. stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8271. stopwatch2.ElapsedMilliseconds + "ms");
  8272. }
  8273. /// <summary>
  8274. /// [S1] Tray盘上料装备(板测)- 节拍接口
  8275. /// </summary>
  8276. /// <param name="plcNo">PLC编号</param>
  8277. /// <param name="stationNameStr">工站全称</param>
  8278. private void S1节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  8279. {
  8280. Stopwatch stopwatch1 = new Stopwatch();
  8281. Stopwatch stopwatch2 = new Stopwatch();
  8282. string resultStr = string.Empty;
  8283. try
  8284. {
  8285. stopwatch1.Start();
  8286. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  8287. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  8288. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  8289. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  8290. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  8291. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8292. if (!actionBool)
  8293. {
  8294. stopwatch2.Start();
  8295. //写入PLC
  8296. iot_data.beatReturn = 2; //NG
  8297. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8298. stopwatch2.Stop();
  8299. AddMessage(LogType.Info,
  8300. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  8301. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8302. return;
  8303. }
  8304. //作业开始后要有物料和载具信息
  8305. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode) &&
  8306. Convert.ToInt32(oEEType) > 2)
  8307. {
  8308. stopwatch2.Start();
  8309. //写入PLC
  8310. iot_data.beatReturn = 2; //NG
  8311. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8312. stopwatch2.Stop();
  8313. AddMessage_Station(stationNameStr, LogType.Info,
  8314. stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  8315. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8316. return;
  8317. }
  8318. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a1OEEPartNo))
  8319. {
  8320. stopwatch2.Start();
  8321. //写入PLC
  8322. iot_data.beatReturn = 2; //NG
  8323. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8324. stopwatch2.Stop();
  8325. AddMessage_Station(stationNameStr, LogType.Info,
  8326. stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  8327. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8328. return;
  8329. }
  8330. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a1OEEVehicleCode))
  8331. {
  8332. stopwatch2.Start();
  8333. //写入PLC
  8334. iot_data.beatReturn = 2; //NG
  8335. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8336. stopwatch2.Stop();
  8337. AddMessage_Station(stationNameStr, LogType.Info,
  8338. stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  8339. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8340. return;
  8341. }
  8342. short _result = 0;
  8343. // 上传OEE
  8344. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  8345. _result = result.Item1;
  8346. resultStr = result.Item2;
  8347. if (_result == 1)
  8348. {
  8349. stopwatch2.Start();
  8350. //写入PLC
  8351. iot_data.beatReturn = 1; //OK
  8352. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8353. OnMessage(LogType.Info,
  8354. $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  8355. stopwatch2.Stop();
  8356. }
  8357. else
  8358. {
  8359. stopwatch2.Start();
  8360. //写入PLC
  8361. iot_data.beatReturn = 2; //NG
  8362. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8363. stopwatch2.Stop();
  8364. AddMessage_Station(stationNameStr, LogType.Error,
  8365. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  8366. }
  8367. }
  8368. catch (Exception ex)
  8369. {
  8370. string str = ex.StackTrace;
  8371. AddMessage_Station(stationNameStr, LogType.Error,
  8372. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  8373. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8374. // MES_Flag
  8375. stopwatch2.Start();
  8376. //写入PLC
  8377. iot_data.beatReturn = 2; //NG
  8378. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8379. stopwatch2.Stop();
  8380. }
  8381. stopwatch1.Stop();
  8382. AddMessage(LogType.Info,
  8383. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8384. stopwatch2.ElapsedMilliseconds + "ms");
  8385. }
  8386. /// <summary>
  8387. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  8388. /// </summary>
  8389. /// <param name="plcNo">PLC编号</param>
  8390. /// <param name="stationNameStr">工站全称</param>
  8391. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  8392. {
  8393. Stopwatch stopwatch1 = new Stopwatch();
  8394. Stopwatch stopwatch2 = new Stopwatch();
  8395. try
  8396. {
  8397. stopwatch1.Start();
  8398. // ZS 呼叫AGV
  8399. short a1AGVUpCall = 2;
  8400. stopwatch2.Start();
  8401. // a1AGVUpCall
  8402. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  8403. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8404. writeToPLC_Flag.Name = "a1AGVUpCall";
  8405. writeToPLC_Flag.Adress = 2307;
  8406. writeToPLC_Flag.Value = a1AGVUpCall;
  8407. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  8408. stopwatch2.Stop();
  8409. }
  8410. catch (Exception ex)
  8411. {
  8412. string str = ex.StackTrace;
  8413. AddMessage_Station(stationNameStr, LogType.Error,
  8414. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  8415. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8416. // a1AGVUpCall
  8417. stopwatch2.Start();
  8418. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  8419. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8420. writeToPLC_Flag.Name = "a1AGVUpCall";
  8421. writeToPLC_Flag.Adress = 2307;
  8422. writeToPLC_Flag.Value = (short)4;
  8423. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  8424. stopwatch2.Stop();
  8425. }
  8426. stopwatch1.Stop();
  8427. AddMessage(LogType.Info,
  8428. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8429. stopwatch2.ElapsedMilliseconds + "ms");
  8430. }
  8431. /// <summary>
  8432. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  8433. /// </summary>
  8434. /// <param name="plcNo">PLC编号</param>
  8435. /// <param name="stationNameStr">工站全称</param>
  8436. private void S1AGV上料完成(int plcNo, string stationNameStr)
  8437. {
  8438. Stopwatch stopwatch1 = new Stopwatch();
  8439. Stopwatch stopwatch2 = new Stopwatch();
  8440. try
  8441. {
  8442. stopwatch1.Start();
  8443. // ZS AGV上料完成,让小车离开
  8444. short a1AGVUpEnd = 2;
  8445. stopwatch2.Start();
  8446. // a1AGVUpEnd
  8447. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  8448. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8449. writeToPLC_Flag.Name = "a1AGVUpEnd";
  8450. writeToPLC_Flag.Adress = 2309;
  8451. writeToPLC_Flag.Value = a1AGVUpEnd;
  8452. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  8453. stopwatch2.Stop();
  8454. }
  8455. catch (Exception ex)
  8456. {
  8457. string str = ex.StackTrace;
  8458. AddMessage_Station(stationNameStr, LogType.Error,
  8459. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  8460. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8461. // a1AGVUpEnd
  8462. stopwatch2.Start();
  8463. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  8464. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8465. writeToPLC_Flag.Name = "a1AGVUpEnd";
  8466. writeToPLC_Flag.Adress = 2309;
  8467. writeToPLC_Flag.Value = (short)4;
  8468. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  8469. stopwatch2.Stop();
  8470. }
  8471. stopwatch1.Stop();
  8472. AddMessage(LogType.Info,
  8473. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8474. stopwatch2.ElapsedMilliseconds + "ms");
  8475. }
  8476. /// <summary>
  8477. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  8478. /// </summary>
  8479. /// <param name="plcNo">PLC编号</param>
  8480. /// <param name="stationNameStr">工站全称</param>
  8481. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  8482. {
  8483. Stopwatch stopwatch1 = new Stopwatch();
  8484. Stopwatch stopwatch2 = new Stopwatch();
  8485. try
  8486. {
  8487. stopwatch1.Start();
  8488. // ZS 呼叫AGV
  8489. short a1AGVDownCall = 2;
  8490. stopwatch2.Start();
  8491. // a1AGVDownCall
  8492. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  8493. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8494. writeToPLC_Flag.Name = "a1AGVDownCall";
  8495. writeToPLC_Flag.Adress = 2320;
  8496. writeToPLC_Flag.Value = a1AGVDownCall;
  8497. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  8498. stopwatch2.Stop();
  8499. }
  8500. catch (Exception ex)
  8501. {
  8502. string str = ex.StackTrace;
  8503. AddMessage_Station(stationNameStr, LogType.Error,
  8504. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  8505. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8506. // a1AGVDownCall
  8507. stopwatch2.Start();
  8508. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  8509. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8510. writeToPLC_Flag.Name = "a1AGVDownCall";
  8511. writeToPLC_Flag.Adress = 2320;
  8512. writeToPLC_Flag.Value = (short)4;
  8513. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  8514. stopwatch2.Stop();
  8515. }
  8516. stopwatch1.Stop();
  8517. AddMessage(LogType.Info,
  8518. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8519. stopwatch2.ElapsedMilliseconds + "ms");
  8520. }
  8521. /// <summary>
  8522. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  8523. /// </summary>
  8524. /// <param name="plcNo">PLC编号</param>
  8525. /// <param name="stationNameStr">工站全称</param>
  8526. private void S1AGV下料完成(int plcNo, string stationNameStr)
  8527. {
  8528. Stopwatch stopwatch1 = new Stopwatch();
  8529. Stopwatch stopwatch2 = new Stopwatch();
  8530. try
  8531. {
  8532. stopwatch1.Start();
  8533. // ZS AGV上料完成,让小车离开
  8534. short a1AGVDownEnd = 2;
  8535. stopwatch2.Start();
  8536. // a1AGVDownEnd
  8537. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  8538. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8539. writeToPLC_Flag.Name = "a1AGVDownEnd";
  8540. writeToPLC_Flag.Adress = 2322;
  8541. writeToPLC_Flag.Value = a1AGVDownEnd;
  8542. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  8543. stopwatch2.Stop();
  8544. }
  8545. catch (Exception ex)
  8546. {
  8547. string str = ex.StackTrace;
  8548. AddMessage_Station(stationNameStr, LogType.Error,
  8549. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  8550. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8551. // a1AGVDownEnd
  8552. stopwatch2.Start();
  8553. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  8554. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8555. writeToPLC_Flag.Name = "a1AGVDownEnd";
  8556. writeToPLC_Flag.Adress = 2322;
  8557. writeToPLC_Flag.Value = (short)4;
  8558. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  8559. stopwatch2.Stop();
  8560. }
  8561. stopwatch1.Stop();
  8562. AddMessage(LogType.Info,
  8563. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8564. stopwatch2.ElapsedMilliseconds + "ms");
  8565. }
  8566. #endregion [S1] Tray盘上料装备(板测)
  8567. #endregion PLC1 张超凡
  8568. #region PLC2 李晓奇
  8569. #region [S2] FCT(板测)
  8570. /// <summary>
  8571. /// S2工位的数据- 触发信号上次的值
  8572. /// </summary>
  8573. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  8574. /// <summary>
  8575. /// S2工位的数据(含触发信号)
  8576. /// </summary>
  8577. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  8578. /// <summary>
  8579. /// S2工位的数据- 回写点位
  8580. /// </summary>
  8581. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8582. /// <summary>
  8583. /// [S2] FCT(板测)
  8584. /// </summary>
  8585. /// <param name="plcNo">PLC编号</param>
  8586. //private void ReadStation_S2(int plcNo)
  8587. //{
  8588. // // [S1] Tray盘上料装备
  8589. // // [S2] FCT
  8590. // // [S3] 值板机
  8591. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8592. // // [S5] Tray盘下料装备
  8593. // /// 上位机心跳
  8594. // /// 获取设备报警数据与状态信息
  8595. // string stationCode = "[S2]";
  8596. // string stationName = "FCT";
  8597. // string stationNameStr = stationCode + stationName;
  8598. // #region 创建字典
  8599. // // 触发信号字典 赋值
  8600. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8601. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  8602. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8603. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8604. // // PLC数据字典 赋值
  8605. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  8606. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  8607. // s2PLCData.Add("b1ProductSN_Check", 0);
  8608. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  8609. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  8610. // s2PLCData.Add("b1ProductSN_Unbind", "");
  8611. // s2PLCData.Add("b1ProductSN_Bind", "");
  8612. // s2PLCData.Add("b1Part1SN_Bind", "");
  8613. // s2PLCData.Add("b1Part2SN_Bind", "");
  8614. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  8615. // s2PLCData.Add("b1MES_FLAG", 0);
  8616. // s2PLCData.Add("b1ProductSN", 0);
  8617. // s2PLCData.Add("b1Part1Result", 0);
  8618. // s2PLCData.Add("b1Part2Result", 0);
  8619. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  8620. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  8621. // s2PLCData.Add("b1OEEProductSN", "");
  8622. // s2PLCData.Add("b1OEEType", 0);
  8623. // #endregion 创建字典
  8624. // while (IsRun)
  8625. // {
  8626. // try
  8627. // {
  8628. // if (!GlobalContext._IsCon_Funs2)
  8629. // {
  8630. // UpdatePLCMonitor(1, plcNo, 0);
  8631. // continue;
  8632. // }
  8633. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8634. // {
  8635. // Stopwatch stopwatch1 = new Stopwatch();
  8636. // Stopwatch stopwatch2 = new Stopwatch();
  8637. // stopwatch1.Start();
  8638. // stopwatch2.Start();
  8639. // #region 一次性读取所有数据
  8640. // // 一次性读取所有数据
  8641. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  8642. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  8643. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  8644. // int[] datas = data1.Concat(data2).ToArray();
  8645. // datas = datas.Concat(data3).ToArray();
  8646. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  8647. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  8648. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8649. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  8650. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  8651. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  8652. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  8653. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  8654. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  8655. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  8656. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  8657. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  8658. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  8659. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  8660. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  8661. // s2PLCData["b1MES_FLAG"] = datas[169];
  8662. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  8663. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  8664. // s2PLCData["b1Part1Result"] = datas[190];
  8665. // s2PLCData["b1Part2Result"] = datas[191];
  8666. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  8667. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  8668. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  8669. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  8670. // s2PLCData["b1OEEType"] = datas[224];
  8671. // #endregion 一次性读取所有数据
  8672. // stopwatch2.Stop();
  8673. // #region 回写操作,写后清空flag
  8674. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  8675. // #endregion 回写操作,写后清空flag
  8676. // #region 进站校验
  8677. // try
  8678. // {
  8679. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  8680. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  8681. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  8682. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  8683. // {
  8684. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  8685. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8686. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  8687. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8688. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  8689. // }
  8690. // }
  8691. // catch (Exception ex)
  8692. // {
  8693. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8694. // string str = ex.StackTrace;
  8695. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8696. // }
  8697. // #endregion 进站校验
  8698. // #region 二穴载具解绑/绑定(产品换载具)
  8699. // try
  8700. // {
  8701. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  8702. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  8703. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  8704. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  8705. // {
  8706. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  8707. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  8708. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  8709. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  8710. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  8711. // }
  8712. // }
  8713. // catch (Exception ex)
  8714. // {
  8715. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  8716. // string str = ex.StackTrace;
  8717. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8718. // }
  8719. // #endregion 二穴载具解绑/绑定(产品换载具)
  8720. // #region FCT-出站接口
  8721. // try
  8722. // {
  8723. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  8724. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  8725. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  8726. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  8727. // {
  8728. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  8729. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8730. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  8731. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  8732. // }
  8733. // }
  8734. // catch (Exception ex)
  8735. // {
  8736. // // MES_Flag 为6上位机报错
  8737. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  8738. // string str = ex.StackTrace;
  8739. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8740. // }
  8741. // #endregion FCT-出站接口
  8742. // #region 节拍接口
  8743. // try
  8744. // {
  8745. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  8746. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  8747. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  8748. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  8749. // {
  8750. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  8751. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8752. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  8753. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  8754. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  8755. // }
  8756. // }
  8757. // catch (Exception ex)
  8758. // {
  8759. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  8760. // string str = ex.StackTrace;
  8761. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8762. // }
  8763. // #endregion 节拍接口
  8764. // #region 心跳
  8765. // try
  8766. // {
  8767. // short states = 0;
  8768. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  8769. // }
  8770. // catch (Exception ex)
  8771. // {
  8772. // string str = ex.StackTrace;
  8773. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8774. // }
  8775. // #endregion 心跳
  8776. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  8777. // stopwatch1.Stop();
  8778. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  8779. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  8780. // }
  8781. // else
  8782. // {
  8783. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8784. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  8785. // Funs[plcNo].Connect();
  8786. // }
  8787. // }
  8788. // catch (Exception ex)
  8789. // {
  8790. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8791. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  8792. // Funs[plcNo].ReConnect();
  8793. // }
  8794. // Thread.Sleep(IntervalReadPLC);
  8795. // }
  8796. //}
  8797. /// <summary>
  8798. /// [S2] FCT(板测)- 进站校验
  8799. /// </summary>
  8800. /// <param name="plcNo">PLC编号</param>
  8801. /// <param name="stationNameStr">工站全称</param>
  8802. private void S2进站校验(int plcNo, string stationNameStr)
  8803. {
  8804. Stopwatch stopwatch1 = new Stopwatch();
  8805. Stopwatch stopwatch2 = new Stopwatch();
  8806. try
  8807. {
  8808. stopwatch1.Start();
  8809. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  8810. sn = sn.Replace("\0", "");
  8811. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  8812. // 查询物料码By载具码 并判断是不是假产品
  8813. string cavityData = string.Empty;
  8814. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  8815. if (string.IsNullOrEmpty(cavityData))
  8816. cavityData = "";
  8817. if (snResult != 0)
  8818. {
  8819. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8820. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  8821. writeToPLC_Flag1.Adress = 2003;
  8822. writeToPLC_Flag1.Value = (short)6;
  8823. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  8824. stopwatch1.Stop();
  8825. AddMessage(LogType.Info,
  8826. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8827. return;
  8828. }
  8829. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  8830. string[] cavitySNs = cavityData.Split('.');
  8831. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  8832. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  8833. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  8834. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  8835. if (cavitySNs != null && cavitySNs.Length >= 2)
  8836. {
  8837. b1Part1SN_Check = cavitySNs[0];
  8838. b1Part2SN_Check = cavitySNs[1];
  8839. b1Part1Result_Check = 2;
  8840. b1Part2Result_Check = 2;
  8841. }
  8842. if (b1Part1SN_Check == "假产品")
  8843. b1Part1Result_Check = 3;
  8844. if (b1Part2SN_Check == "假产品")
  8845. b1Part2Result_Check = 3;
  8846. // 调用MES进站
  8847. stopwatch2.Start();
  8848. // 调用MES进站 - 产品1
  8849. List<TestItem> item;
  8850. int result1 = b1Part1Result_Check;
  8851. if (result1 != 3)
  8852. {
  8853. item = new List<TestItem>();
  8854. item.Add(new TestItem()
  8855. {
  8856. Parameter_name = "载具码",
  8857. Parameter_value = sn,
  8858. });
  8859. item.Add(new TestItem()
  8860. {
  8861. Parameter_name = "载具穴号",
  8862. Parameter_value = "1",
  8863. });
  8864. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8865. b1Part1SN_Check, item, out string errorMsg);
  8866. }
  8867. // 调用MES进站 - 产品2
  8868. int result2 = b1Part2Result_Check;
  8869. if (result2 != 3)
  8870. {
  8871. item = new List<TestItem>();
  8872. item.Add(new TestItem()
  8873. {
  8874. Parameter_name = "载具码",
  8875. Parameter_value = sn,
  8876. });
  8877. item.Add(new TestItem()
  8878. {
  8879. Parameter_name = "载具穴号",
  8880. Parameter_value = "2",
  8881. });
  8882. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8883. b1Part2SN_Check, item, out string errorMsg);
  8884. }
  8885. stopwatch2.Stop();
  8886. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  8887. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  8888. int result = result1;
  8889. if (result == 1)
  8890. result = result2;
  8891. short b1MES_FLAG_Check = (short)result;
  8892. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  8893. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  8894. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  8895. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  8896. //// MES_Flag
  8897. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8898. WriteToPLC_Flag
  8899. writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8900. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  8901. writeToPLC_Flag.Adress = 2003;
  8902. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  8903. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8904. {
  8905. Name = "b1Part1SN_Check",
  8906. Adress = 2024,
  8907. ValueType = PLCValueType.String,
  8908. ValueTypeStrLength = 20,
  8909. Value = b1Part1SN_Check
  8910. });
  8911. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8912. {
  8913. Name = "b1Part2SN_Check",
  8914. Adress = 2044,
  8915. ValueType = PLCValueType.String,
  8916. ValueTypeStrLength = 20,
  8917. Value = b1Part2SN_Check
  8918. });
  8919. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8920. {
  8921. Name = "b1Part1Result_Check",
  8922. Adress = 2064,
  8923. ValueType = PLCValueType.Short,
  8924. Value = b1Part1Result_Check
  8925. });
  8926. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8927. {
  8928. Name = "b1Part2Result_Check",
  8929. Adress = 2065,
  8930. ValueType = PLCValueType.Short,
  8931. Value = b1Part2Result_Check
  8932. });
  8933. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  8934. }
  8935. catch (Exception ex)
  8936. {
  8937. string str = ex.StackTrace;
  8938. AddMessage_Station(stationNameStr, LogType.Error,
  8939. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  8940. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8941. // MES_Flag
  8942. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8943. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8944. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  8945. writeToPLC_Flag.Adress = 2003;
  8946. writeToPLC_Flag.Value = (short)6;
  8947. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  8948. }
  8949. stopwatch1.Stop();
  8950. AddMessage(LogType.Info,
  8951. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  8952. stopwatch2.ElapsedMilliseconds + "ms");
  8953. }
  8954. /// <summary>
  8955. /// [S2] FCT(板测)- 二穴载具解绑绑定
  8956. /// </summary>
  8957. /// <param name="plcNo">PLC编号</param>
  8958. /// <param name="stationNameStr">工站全称</param>
  8959. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  8960. {
  8961. Stopwatch stopwatch1 = new Stopwatch();
  8962. Stopwatch stopwatch2 = new Stopwatch();
  8963. try
  8964. {
  8965. stopwatch1.Start();
  8966. // 产品换载具
  8967. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  8968. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  8969. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  8970. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  8971. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  8972. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  8973. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  8974. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  8975. stopwatch2.Start();
  8976. #region 查询载具上的产品信息
  8977. //string cavityData = string.Empty;
  8978. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  8979. //if (string.IsNullOrEmpty(cavityData))
  8980. // cavityData = "";
  8981. //if (snResult != 0)
  8982. //{
  8983. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8984. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  8985. // writeToPLC_Flag.Adress = 2077;
  8986. // writeToPLC_Flag.Value = (short)6;
  8987. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  8988. // stopwatch1.Stop();
  8989. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8990. // return;
  8991. //}
  8992. #endregion 查询载具上的产品信息
  8993. #region 解绑(边线MES系统)
  8994. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  8995. if (snResult != 0)
  8996. {
  8997. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8998. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  8999. writeToPLC_Flag1.Adress = 2077;
  9000. writeToPLC_Flag1.Value = (short)6;
  9001. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  9002. stopwatch1.Stop();
  9003. AddMessage(LogType.Info,
  9004. stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" +
  9005. stopwatch1.ElapsedMilliseconds + "ms");
  9006. return;
  9007. }
  9008. #endregion 解绑(边线MES系统)
  9009. #region 存储绑定数据到 边线MES系统中
  9010. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  9011. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  9012. if (snResult != 0)
  9013. {
  9014. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9015. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  9016. writeToPLC_Flag1.Adress = 2077;
  9017. writeToPLC_Flag1.Value = (short)6;
  9018. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  9019. stopwatch1.Stop();
  9020. AddMessage(LogType.Info,
  9021. stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" +
  9022. stopwatch1.ElapsedMilliseconds + "ms");
  9023. return;
  9024. }
  9025. #endregion 存储绑定数据到 边线MES系统中
  9026. stopwatch2.Stop();
  9027. short b1MES_FLAG_Unbind = 1;
  9028. // MES_Flag
  9029. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9030. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9031. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  9032. writeToPLC_Flag.Adress = 2077;
  9033. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  9034. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  9035. }
  9036. catch (Exception ex)
  9037. {
  9038. string str = ex.StackTrace;
  9039. AddMessage_Station(stationNameStr, LogType.Error,
  9040. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" +
  9041. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9042. // MES_Flag
  9043. stopwatch2.Start();
  9044. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  9045. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9046. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  9047. writeToPLC_Flag.Adress = 2077;
  9048. writeToPLC_Flag.Value = (short)6;
  9049. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  9050. stopwatch2.Stop();
  9051. }
  9052. stopwatch1.Stop();
  9053. AddMessage(LogType.Info,
  9054. stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9055. stopwatch2.ElapsedMilliseconds + "ms");
  9056. }
  9057. //// 上次采集到的SN
  9058. //private string sn_FCT = string.Empty;
  9059. /// <summary>
  9060. /// [S2] FCT(板测)- 出站数据
  9061. /// </summary>
  9062. private void S2出站接口(int plcNo, string stationCode, string stationName)
  9063. {
  9064. Stopwatch stopwatch1 = new Stopwatch();
  9065. Stopwatch stopwatch2 = new Stopwatch();
  9066. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9067. string stationNameStr = stationCode + stationName;
  9068. string processItem = stationName; // 测试项目
  9069. try
  9070. {
  9071. stopwatch1.Start();
  9072. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9073. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9074. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9075. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9076. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  9077. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  9078. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  9079. bool pass1 = b1Part1Result == 1;
  9080. bool pass2 = b1Part2Result == 1;
  9081. #region 根据 载具SN 查 物料SN
  9082. string cavityData = string.Empty;
  9083. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  9084. if (string.IsNullOrEmpty(cavityData))
  9085. cavityData = "";
  9086. if (snResult != 0)
  9087. {
  9088. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9089. writeToPLC_Flag1.Name = "b1MES_FLAG";
  9090. writeToPLC_Flag1.Adress = 2169;
  9091. writeToPLC_Flag1.Value = (short)4;
  9092. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  9093. stopwatch1.Stop();
  9094. AddMessage(LogType.Info,
  9095. stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9096. "ms");
  9097. return;
  9098. }
  9099. #endregion 根据 载具SN 查 物料SN
  9100. string[] cavitySNs = cavityData.Split('.');
  9101. string b1ProductSN1 = string.Empty;
  9102. string b1ProductSN2 = string.Empty;
  9103. if (cavitySNs != null && cavitySNs.Length >= 2)
  9104. {
  9105. b1ProductSN1 = cavitySNs[0];
  9106. b1ProductSN2 = cavitySNs[1];
  9107. }
  9108. stopwatch2.Start();
  9109. // 产品1
  9110. int result1 = 0;
  9111. if (b1ProductSN1 == "假产品")
  9112. result1 = 1;
  9113. else
  9114. {
  9115. List<TestItem> items1 = new List<TestItem>();
  9116. items1.Add(new TestItem()
  9117. {
  9118. Parameter_name = "载具码",
  9119. Parameter_value = b1ProductSN.ToString(),
  9120. Parameter_unit = ""
  9121. });
  9122. items1.Add(new TestItem()
  9123. {
  9124. Parameter_name = "载具穴号",
  9125. Parameter_value = "1",
  9126. Parameter_unit = ""
  9127. });
  9128. items1.Add(new TestItem()
  9129. {
  9130. Parameter_name = "产品结果",
  9131. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  9132. Parameter_unit = ""
  9133. });
  9134. result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  9135. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  9136. }
  9137. // 产品2
  9138. int result2 = 0;
  9139. if (b1ProductSN1 == "假产品")
  9140. result2 = 1;
  9141. else
  9142. {
  9143. List<TestItem> items2 = new List<TestItem>();
  9144. items2.Add(new TestItem()
  9145. {
  9146. Parameter_name = "载具码",
  9147. Parameter_value = b1ProductSN.ToString(),
  9148. Parameter_unit = ""
  9149. });
  9150. items2.Add(new TestItem()
  9151. {
  9152. Parameter_name = "载具穴号",
  9153. Parameter_value = "2",
  9154. Parameter_unit = ""
  9155. });
  9156. items2.Add(new TestItem()
  9157. {
  9158. Parameter_name = "产品结果",
  9159. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  9160. Parameter_unit = ""
  9161. });
  9162. result2 = SwitctProcessData_old(stationNameStr, items2, equipmentCode, processItem
  9163. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  9164. }
  9165. short result = 0;
  9166. List<int> results = new List<int>() { result1, result2 };
  9167. if (result1 == 1 && result2 == 1)
  9168. result = 1;
  9169. else if (results.Contains(3))
  9170. result = 3;
  9171. else if (results.Contains(2))
  9172. result = 2;
  9173. else if (results.Contains(4))
  9174. result = 4;
  9175. else
  9176. result = 4;
  9177. stopwatch2.Stop();
  9178. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9179. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9180. writeToPLC_Flag.Name = "b1MES_FLAG";
  9181. writeToPLC_Flag.Adress = 2169;
  9182. writeToPLC_Flag.Value = result;
  9183. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  9184. OnMessage(LogType.Debug,
  9185. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9186. }
  9187. catch (Exception ex)
  9188. {
  9189. stopwatch2.Restart();
  9190. // MES_Flag 为4上位机报错
  9191. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  9192. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9193. writeToPLC_Flag.Name = "b1MES_FLAG";
  9194. writeToPLC_Flag.Adress = 2169;
  9195. writeToPLC_Flag.Value = (short)4;
  9196. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  9197. stopwatch2.Stop();
  9198. string str = ex.StackTrace;
  9199. AddMessage_Station(stationNameStr, LogType.Error,
  9200. $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  9201. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9202. }
  9203. stopwatch1.Stop();
  9204. AddMessage(LogType.Info,
  9205. stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  9206. stopwatch2.ElapsedMilliseconds + "ms");
  9207. }
  9208. /// <summary>
  9209. /// [S2] FCT(板测)- 节拍接口
  9210. /// </summary>
  9211. /// <param name="plcNo">PLC编号</param>
  9212. /// <param name="stationNameStr">工站全称</param>
  9213. private void S2节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  9214. {
  9215. Stopwatch stopwatch1 = new Stopwatch();
  9216. Stopwatch stopwatch2 = new Stopwatch();
  9217. string resultStr = string.Empty;
  9218. try
  9219. {
  9220. stopwatch1.Start();
  9221. string oEEType = ((int)s1PLCData["a2OEEType"]).ToString(); // 节拍类型(plc写入)
  9222. string a2OEEPartNo = (string)s1PLCData["a2OEEPartNo"]; // 物料码
  9223. a2OEEPartNo = a2OEEPartNo.Replace("\0", "");
  9224. string a20EEVehicleCode = (string)s1PLCData["a20EEVehicleCode"]; // 载具SN
  9225. a20EEVehicleCode = a20EEVehicleCode.Replace("\0", "");
  9226. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9227. if (!actionBool)
  9228. {
  9229. stopwatch2.Start();
  9230. //写入PLC
  9231. iot_data.beatReturn = 2; //NG
  9232. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9233. stopwatch2.Stop();
  9234. AddMessage(LogType.Info,
  9235. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  9236. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9237. return;
  9238. }
  9239. //作业开始后要有物料和载具信息
  9240. if (string.IsNullOrEmpty(a2OEEPartNo) && string.IsNullOrEmpty(a20EEVehicleCode) &&
  9241. Convert.ToInt32(oEEType) > 2)
  9242. {
  9243. stopwatch2.Start();
  9244. //写入PLC
  9245. iot_data.beatReturn = 2; //NG
  9246. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9247. stopwatch2.Stop();
  9248. AddMessage_Station(stationNameStr, LogType.Info,
  9249. stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  9250. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9251. return;
  9252. }
  9253. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a2OEEPartNo))
  9254. {
  9255. stopwatch2.Start();
  9256. //写入PLC
  9257. iot_data.beatReturn = 2; //NG
  9258. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9259. stopwatch2.Stop();
  9260. AddMessage_Station(stationNameStr, LogType.Info,
  9261. stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  9262. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9263. return;
  9264. }
  9265. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a20EEVehicleCode))
  9266. {
  9267. stopwatch2.Start();
  9268. //写入PLC
  9269. iot_data.beatReturn = 2; //NG
  9270. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9271. stopwatch2.Stop();
  9272. AddMessage_Station(stationNameStr, LogType.Info,
  9273. stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  9274. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9275. return;
  9276. }
  9277. short _result = 0;
  9278. // 上传OEE
  9279. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a2OEEPartNo, a20EEVehicleCode);
  9280. _result = result.Item1;
  9281. resultStr = result.Item2;
  9282. if (_result == 1)
  9283. {
  9284. stopwatch2.Start();
  9285. //写入PLC
  9286. iot_data.beatReturn = 1; //OK
  9287. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9288. OnMessage(LogType.Info,
  9289. $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  9290. stopwatch2.Stop();
  9291. }
  9292. else
  9293. {
  9294. stopwatch2.Start();
  9295. //写入PLC
  9296. iot_data.beatReturn = 2; //NG
  9297. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9298. stopwatch2.Stop();
  9299. AddMessage_Station(stationNameStr, LogType.Error,
  9300. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  9301. }
  9302. }
  9303. catch (Exception ex)
  9304. {
  9305. string str = ex.StackTrace;
  9306. AddMessage_Station(stationNameStr, LogType.Error,
  9307. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  9308. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9309. // MES_Flag
  9310. stopwatch2.Start();
  9311. //写入PLC
  9312. iot_data.beatReturn = 2; //NG
  9313. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9314. stopwatch2.Stop();
  9315. }
  9316. stopwatch1.Stop();
  9317. AddMessage(LogType.Info,
  9318. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9319. stopwatch2.ElapsedMilliseconds + "ms");
  9320. }
  9321. #endregion [S2] FCT(板测)
  9322. #endregion PLC2 李晓奇
  9323. #region PLC3 刘永村
  9324. #region [S3] 值板机
  9325. /// <summary>
  9326. /// S3工位的数据- 触发信号上次的值
  9327. /// </summary>
  9328. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  9329. /// <summary>
  9330. /// S3工位的数据(含触发信号)
  9331. /// </summary>
  9332. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  9333. /// <summary>
  9334. /// S3工位的数据- 回写点位
  9335. /// </summary>
  9336. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  9337. /// <summary>
  9338. /// [S3] 值板机
  9339. /// </summary>
  9340. /// <param name="plcNo">PLC编号</param>
  9341. //private void ReadStation_S3(int plcNo)
  9342. //{
  9343. // // [S1] Tray盘上料装备
  9344. // // [S2] FCT
  9345. // // [S3] 值板机
  9346. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  9347. // // [S5] Tray盘下料装备
  9348. // /// 上位机心跳
  9349. // /// 获取设备报警数据与状态信息
  9350. // string stationCode = "[S3]";
  9351. // string stationName = "值板机";
  9352. // string stationNameStr = stationCode + stationName;
  9353. // #region 创建字典
  9354. // // 触发信号字典 赋值
  9355. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  9356. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  9357. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  9358. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  9359. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9360. // // PLC数据字典 赋值
  9361. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  9362. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  9363. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  9364. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  9365. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  9366. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  9367. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  9368. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  9369. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  9370. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  9371. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  9372. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  9373. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  9374. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  9375. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  9376. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  9377. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  9378. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  9379. // s3PLCData.Add("c1Result", 0); // 产品结果
  9380. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9381. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  9382. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  9383. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  9384. // #endregion 创建字典
  9385. // while (IsRun)
  9386. // {
  9387. // try
  9388. // {
  9389. // if (!GlobalContext._IsCon_Funs3)
  9390. // {
  9391. // UpdatePLCMonitor(1, plcNo, 0);
  9392. // continue;
  9393. // }
  9394. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  9395. // {
  9396. // Stopwatch stopwatch1 = new Stopwatch();
  9397. // Stopwatch stopwatch2 = new Stopwatch();
  9398. // stopwatch1.Start();
  9399. // stopwatch2.Start();
  9400. // #region 一次性读取所有数据
  9401. // // 一次性读取所有数据
  9402. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  9403. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  9404. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  9405. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  9406. // int[] datas = data1.Concat(data2).ToArray();
  9407. // datas = datas.Concat(data3).ToArray();
  9408. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  9409. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  9410. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  9411. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  9412. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  9413. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  9414. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  9415. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  9416. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  9417. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  9418. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  9419. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  9420. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  9421. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  9422. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  9423. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  9424. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  9425. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  9426. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  9427. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  9428. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  9429. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  9430. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  9431. // #endregion 一次性读取所有数据
  9432. // stopwatch2.Stop();
  9433. // #region 回写操作,写后清空flag
  9434. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  9435. // #endregion 回写操作,写后清空flag
  9436. // #region S3进站校验
  9437. // try
  9438. // {
  9439. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  9440. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  9441. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  9442. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  9443. // {
  9444. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  9445. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  9446. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  9447. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  9448. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  9449. // }
  9450. // }
  9451. // catch (Exception ex)
  9452. // {
  9453. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9454. // string str = ex.StackTrace;
  9455. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9456. // }
  9457. // #endregion S3进站校验
  9458. // #region S3二穴载具解绑
  9459. // try
  9460. // {
  9461. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  9462. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  9463. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  9464. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  9465. // {
  9466. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  9467. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  9468. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  9469. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  9470. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  9471. // }
  9472. // }
  9473. // catch (Exception ex)
  9474. // {
  9475. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  9476. // string str = ex.StackTrace;
  9477. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9478. // }
  9479. // #endregion S3二穴载具解绑
  9480. // #region S3二穴载具绑定
  9481. // try
  9482. // {
  9483. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  9484. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  9485. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  9486. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  9487. // {
  9488. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  9489. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  9490. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  9491. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  9492. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  9493. // }
  9494. // }
  9495. // catch (Exception ex)
  9496. // {
  9497. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  9498. // string str = ex.StackTrace;
  9499. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9500. // }
  9501. // #endregion S3二穴载具绑定
  9502. // #region S3出站接口(+一穴载具绑定)
  9503. // try
  9504. // {
  9505. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  9506. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  9507. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  9508. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  9509. // {
  9510. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  9511. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  9512. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  9513. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  9514. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  9515. // }
  9516. // }
  9517. // catch (Exception ex)
  9518. // {
  9519. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  9520. // string str = ex.StackTrace;
  9521. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9522. // }
  9523. // #endregion S3出站接口(+一穴载具绑定)
  9524. // #region S3节拍接口
  9525. // try
  9526. // {
  9527. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  9528. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  9529. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  9530. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  9531. // {
  9532. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  9533. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  9534. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  9535. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  9536. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  9537. // }
  9538. // }
  9539. // catch (Exception ex)
  9540. // {
  9541. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  9542. // string str = ex.StackTrace;
  9543. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9544. // }
  9545. // #endregion S3节拍接口
  9546. // #region 心跳
  9547. // try
  9548. // {
  9549. // short states = 0;
  9550. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  9551. // }
  9552. // catch (Exception ex)
  9553. // {
  9554. // string str = ex.StackTrace;
  9555. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9556. // }
  9557. // #endregion 心跳
  9558. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  9559. // stopwatch1.Stop();
  9560. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  9561. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  9562. // }
  9563. // else
  9564. // {
  9565. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9566. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  9567. // Funs[plcNo].Connect();
  9568. // }
  9569. // }
  9570. // catch (Exception ex)
  9571. // {
  9572. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9573. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  9574. // Funs[plcNo].ReConnect();
  9575. // }
  9576. // Thread.Sleep(IntervalReadPLC);
  9577. // }
  9578. //}
  9579. /// <summary>
  9580. /// [S3] 值板机- 进站校验
  9581. /// </summary>
  9582. /// <param name="plcNo">PLC编号</param>
  9583. /// <param name="stationNameStr">工站全称</param>
  9584. private void S3进站校验(int plcNo, string stationNameStr)
  9585. {
  9586. Stopwatch stopwatch1 = new Stopwatch();
  9587. Stopwatch stopwatch2 = new Stopwatch();
  9588. try
  9589. {
  9590. stopwatch1.Start();
  9591. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  9592. sn = sn.Replace("\0", "");
  9593. #region 查询载具上的产品信息
  9594. string cavityData = string.Empty;
  9595. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9596. if (string.IsNullOrEmpty(cavityData))
  9597. cavityData = "";
  9598. if (snResult != 0)
  9599. {
  9600. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9601. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  9602. writeToPLC_Flag1.Adress = 2003;
  9603. writeToPLC_Flag1.Value = (short)6;
  9604. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  9605. stopwatch1.Stop();
  9606. AddMessage(LogType.Info,
  9607. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9608. return;
  9609. }
  9610. #endregion 查询载具上的产品信息
  9611. string[] cavitySNs = cavityData.Split('.');
  9612. string part1Str = ""; // 产品1的SN码
  9613. string part2Str = ""; // 产品2的SN码
  9614. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  9615. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  9616. if (cavitySNs != null && cavitySNs.Length >= 2)
  9617. {
  9618. part1Str = cavitySNs[0];
  9619. part2Str = cavitySNs[1];
  9620. c1Part1Result_Check = 2;
  9621. c1Part2Result_Check = 2;
  9622. }
  9623. if (part1Str == "假产品")
  9624. c1Part1Result_Check = 3;
  9625. if (part2Str == "假产品")
  9626. c1Part2Result_Check = 3;
  9627. // 调用MES进站
  9628. stopwatch2.Start();
  9629. // 调用MES进站 - 产品1
  9630. List<TestItem> item;
  9631. int result1 = c1Part1Result_Check;
  9632. if (result1 != 3)
  9633. {
  9634. item = new List<TestItem>();
  9635. item.Add(new TestItem()
  9636. {
  9637. Parameter_name = "载具码",
  9638. Parameter_value = sn,
  9639. });
  9640. item.Add(new TestItem()
  9641. {
  9642. Parameter_name = "载具穴号",
  9643. Parameter_value = "1",
  9644. });
  9645. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  9646. part1Str, item, out string errorMsg);
  9647. }
  9648. // 调用MES进站 - 产品2
  9649. int result2 = c1Part2Result_Check;
  9650. if (result2 != 3)
  9651. {
  9652. item = new List<TestItem>();
  9653. item.Add(new TestItem()
  9654. {
  9655. Parameter_name = "载具码",
  9656. Parameter_value = sn,
  9657. });
  9658. item.Add(new TestItem()
  9659. {
  9660. Parameter_name = "载具穴号",
  9661. Parameter_value = "2",
  9662. });
  9663. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  9664. part2Str, item, out string errorMsg);
  9665. }
  9666. stopwatch2.Stop();
  9667. if (result1 == 2)
  9668. c1Part1Result_Check = 2;
  9669. if (result2 == 2)
  9670. c1Part2Result_Check = 2;
  9671. int result = result1;
  9672. if (result == 1)
  9673. result = result2;
  9674. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  9675. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  9676. short c1MES_FLAG_Check = (short)result;
  9677. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  9678. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  9679. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  9680. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  9681. //// MES_Flag
  9682. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9683. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9684. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  9685. writeToPLC_Flag.Adress = 2003;
  9686. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  9687. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9688. {
  9689. Name = "c1Part1Result_Check",
  9690. Adress = 2024,
  9691. ValueType = PLCValueType.Short,
  9692. Value = c1Part1Result_Check
  9693. });
  9694. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9695. {
  9696. Name = "c1Part2Result_Check",
  9697. Adress = 2025,
  9698. ValueType = PLCValueType.Short,
  9699. Value = c1Part2Result_Check
  9700. });
  9701. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9702. {
  9703. Name = "c1Part1Num_Check",
  9704. Adress = 2026,
  9705. ValueType = PLCValueType.Short,
  9706. Value = c1Part1Num_Check
  9707. });
  9708. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9709. {
  9710. Name = "c1Part2Num_Check",
  9711. Adress = 2027,
  9712. ValueType = PLCValueType.Short,
  9713. Value = c1Part2Num_Check
  9714. });
  9715. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  9716. }
  9717. catch (Exception ex)
  9718. {
  9719. string str = ex.StackTrace;
  9720. AddMessage_Station(stationNameStr, LogType.Error,
  9721. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  9722. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9723. // MES_Flag
  9724. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9725. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9726. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  9727. writeToPLC_Flag.Adress = 2003;
  9728. writeToPLC_Flag.Value = (short)6;
  9729. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  9730. }
  9731. stopwatch1.Stop();
  9732. AddMessage(LogType.Info,
  9733. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  9734. stopwatch2.ElapsedMilliseconds + "ms");
  9735. }
  9736. /// <summary>
  9737. /// [S3] 值板机 - 二穴载具解绑
  9738. /// </summary>
  9739. /// <param name="plcNo">PLC编号</param>
  9740. /// <param name="stationNameStr">工站全称</param>
  9741. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  9742. {
  9743. Stopwatch stopwatch1 = new Stopwatch();
  9744. Stopwatch stopwatch2 = new Stopwatch();
  9745. try
  9746. {
  9747. stopwatch1.Start();
  9748. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  9749. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  9750. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  9751. // 解绑
  9752. #region 查询载具上的产品信息
  9753. string cavityData = string.Empty;
  9754. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  9755. if (string.IsNullOrEmpty(cavityData))
  9756. cavityData = "";
  9757. if (snResult != 0)
  9758. {
  9759. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9760. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  9761. writeToPLC_Flag1.Adress = 2082;
  9762. writeToPLC_Flag1.Value = (short)6;
  9763. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  9764. stopwatch1.Stop();
  9765. AddMessage(LogType.Info,
  9766. stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9767. "ms");
  9768. return;
  9769. }
  9770. #endregion 查询载具上的产品信息
  9771. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  9772. #region 解绑
  9773. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  9774. {
  9775. // 删除
  9776. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  9777. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  9778. }
  9779. else
  9780. {
  9781. string data_new = string.Join(".", cavitySNs);
  9782. // 删除再插入
  9783. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  9784. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  9785. OnMessage(LogType.Debug,
  9786. $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  9787. }
  9788. #endregion 解绑
  9789. short c1MES_FLAG_Unbind = 1;
  9790. stopwatch2.Start();
  9791. // MES_Flag
  9792. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9793. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9794. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  9795. writeToPLC_Flag.Adress = 2082;
  9796. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  9797. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  9798. stopwatch2.Stop();
  9799. }
  9800. catch (Exception ex)
  9801. {
  9802. string str = ex.StackTrace;
  9803. AddMessage_Station(stationNameStr, LogType.Error,
  9804. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" +
  9805. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9806. // MES_Flag
  9807. stopwatch2.Start();
  9808. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  9809. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9810. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  9811. writeToPLC_Flag.Adress = 2082;
  9812. writeToPLC_Flag.Value = (short)6;
  9813. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  9814. stopwatch2.Stop();
  9815. }
  9816. stopwatch1.Stop();
  9817. AddMessage(LogType.Info,
  9818. stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9819. stopwatch2.ElapsedMilliseconds + "ms");
  9820. }
  9821. /// <summary>
  9822. /// [S3] 值板机 - 二穴载具绑定
  9823. /// </summary>
  9824. /// <param name="plcNo">PLC编号</param>
  9825. /// <param name="stationNameStr">工站全称</param>
  9826. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  9827. {
  9828. Stopwatch stopwatch1 = new Stopwatch();
  9829. Stopwatch stopwatch2 = new Stopwatch();
  9830. try
  9831. {
  9832. stopwatch1.Start();
  9833. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  9834. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  9835. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  9836. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  9837. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  9838. stopwatch2.Start();
  9839. #region 查询载具上的产品信息
  9840. string cavityData = string.Empty;
  9841. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  9842. if (string.IsNullOrEmpty(cavityData))
  9843. cavityData = "";
  9844. if (snResult != 0)
  9845. {
  9846. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9847. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  9848. writeToPLC_Flag1.Adress = 2115;
  9849. writeToPLC_Flag1.Value = (short)6;
  9850. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  9851. stopwatch1.Stop();
  9852. AddMessage(LogType.Info,
  9853. stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9854. "ms");
  9855. return;
  9856. }
  9857. #endregion 查询载具上的产品信息
  9858. // 产品换载具
  9859. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  9860. string partSn1 = "";
  9861. string partSn2 = "";
  9862. if (cavitySNs != null && cavitySNs.Length >= 2)
  9863. {
  9864. partSn1 = cavitySNs[0];
  9865. partSn2 = cavitySNs[1];
  9866. }
  9867. string data_new = string.Empty;
  9868. // 是否是两个穴位交换
  9869. if (c1CavityReverse_Bind == 1)
  9870. {
  9871. // 交换
  9872. data_new = string.Concat(partSn2, ".", partSn1);
  9873. }
  9874. else
  9875. {
  9876. // 不交换
  9877. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  9878. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  9879. cavitySNs[c1VehicleCavityFr_Bind] = "";
  9880. data_new = string.Join(".", cavitySNs);
  9881. }
  9882. // 删除再插入
  9883. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  9884. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  9885. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  9886. stopwatch2.Stop();
  9887. short c1MES_FLAG_Bind = 1;
  9888. // MES_Flag
  9889. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9890. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9891. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  9892. writeToPLC_Flag.Adress = 2115;
  9893. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  9894. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  9895. }
  9896. catch (Exception ex)
  9897. {
  9898. string str = ex.StackTrace;
  9899. AddMessage_Station(stationNameStr, LogType.Error,
  9900. $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" +
  9901. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9902. // MES_Flag
  9903. stopwatch2.Start();
  9904. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  9905. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9906. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  9907. writeToPLC_Flag.Adress = 2115;
  9908. writeToPLC_Flag.Value = (short)6;
  9909. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  9910. stopwatch2.Stop();
  9911. }
  9912. stopwatch1.Stop();
  9913. AddMessage(LogType.Info,
  9914. stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9915. stopwatch2.ElapsedMilliseconds + "ms");
  9916. }
  9917. //// 上次采集到的SN
  9918. //private string sn_值板机 = string.Empty;
  9919. /// <summary>
  9920. /// [S3] 值板机 - 出站接口
  9921. /// </summary>
  9922. /// <param name="plcNo">PLC编号</param>
  9923. private void S3出站接口(int plcNo, string stationCode, string stationName)
  9924. {
  9925. Stopwatch stopwatch1 = new Stopwatch();
  9926. Stopwatch stopwatch2 = new Stopwatch();
  9927. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9928. string stationNameStr = stationCode + stationName;
  9929. string processItem = stationName; // 测试项目
  9930. try
  9931. {
  9932. stopwatch1.Start();
  9933. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9934. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9935. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9936. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9937. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  9938. sn = sn.Replace("\0", "");
  9939. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  9940. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  9941. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  9942. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  9943. bool pass = c1Result == 1;
  9944. // 查sn
  9945. #region 查询载具上的产品信息
  9946. string cavityData = string.Empty;
  9947. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  9948. if (string.IsNullOrEmpty(cavityData))
  9949. cavityData = "";
  9950. if (snResult != 0)
  9951. {
  9952. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9953. writeToPLC_Flag1.Name = "c1MES_FLAG";
  9954. writeToPLC_Flag1.Adress = 2150;
  9955. writeToPLC_Flag1.Value = (short)4;
  9956. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  9957. stopwatch1.Stop();
  9958. AddMessage(LogType.Info,
  9959. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9960. return;
  9961. }
  9962. #endregion 查询载具上的产品信息
  9963. string[] cavitySNs = cavityData.Split('.');
  9964. string productSN = "";
  9965. if (cavitySNs != null && cavitySNs.Length >= 2)
  9966. {
  9967. productSN = cavitySNs[c1VehicleCavity];
  9968. cavitySNs[c1VehicleCavity] = "";
  9969. }
  9970. stopwatch2.Start();
  9971. List<TestItem> items = new List<TestItem>();
  9972. items.Add(new TestItem()
  9973. {
  9974. Parameter_name = "二穴载具码",
  9975. Parameter_value = c1ProductSN_Check,
  9976. Parameter_unit = ""
  9977. });
  9978. items.Add(new TestItem()
  9979. {
  9980. Parameter_name = "二穴载具穴号",
  9981. Parameter_value = c1VehicleCavity.ToString(),
  9982. Parameter_unit = ""
  9983. });
  9984. items.Add(new TestItem()
  9985. {
  9986. Parameter_name = "一穴载具码",
  9987. Parameter_value = sn,
  9988. Parameter_unit = ""
  9989. });
  9990. items.Add(new TestItem()
  9991. {
  9992. Parameter_name = "一穴载具穴号",
  9993. Parameter_value = "1",
  9994. Parameter_unit = ""
  9995. });
  9996. items.Add(new TestItem()
  9997. {
  9998. Parameter_name = "产品结果",
  9999. Parameter_value = c1Result == 1 ? "OK" : "NG",
  10000. Parameter_unit = ""
  10001. });
  10002. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  10003. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  10004. short result = (short)result1;
  10005. stopwatch2.Stop();
  10006. #region 存储绑定数据到 边线MES系统中
  10007. if (result == 1)
  10008. {
  10009. string data = string.Concat(productSN);
  10010. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  10011. if (resultMesR != 0)
  10012. {
  10013. result = 4;
  10014. AddMessage_Station(stationNameStr, LogType.Error,
  10015. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  10016. }
  10017. }
  10018. #endregion 存储绑定数据到 边线MES系统中
  10019. #region 产品从 来源载具(二穴载具)中删除
  10020. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  10021. {
  10022. // 删除
  10023. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  10024. OnMessage(LogType.Debug,
  10025. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  10026. }
  10027. else
  10028. {
  10029. string data_new = string.Join(".", cavitySNs);
  10030. // 删除再插入
  10031. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  10032. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  10033. OnMessage(LogType.Debug,
  10034. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  10035. }
  10036. #endregion 产品从 来源载具(二穴载具)中删除
  10037. // MES_Flag 为MES报错
  10038. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10039. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  10040. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10041. writeToPLC_Flag.Name = "c1MES_FLAG";
  10042. writeToPLC_Flag.Adress = 2150;
  10043. writeToPLC_Flag.Value = result;
  10044. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  10045. OnMessage(LogType.Debug,
  10046. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  10047. }
  10048. catch (Exception ex)
  10049. {
  10050. stopwatch2.Restart();
  10051. // MES_Flag 为4上位机报错
  10052. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  10053. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10054. writeToPLC_Flag.Name = "c1MES_FLAG";
  10055. writeToPLC_Flag.Adress = 2150;
  10056. writeToPLC_Flag.Value = (short)4;
  10057. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  10058. stopwatch2.Stop();
  10059. string str = ex.StackTrace;
  10060. AddMessage_Station(stationNameStr, LogType.Error,
  10061. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10062. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10063. }
  10064. stopwatch1.Stop();
  10065. AddMessage(LogType.Info,
  10066. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10067. stopwatch2.ElapsedMilliseconds + "ms");
  10068. }
  10069. /// <summary>
  10070. /// [S3] 值板机- 节拍接口
  10071. /// </summary>
  10072. /// <param name="plcNo">PLC编号</param>
  10073. /// <param name="stationNameStr">工站全称</param>
  10074. private void S3节拍接口(int plcNo, string stationNameStr, string tagMesCommName, string CarrierBarcode,
  10075. IoT_DataSet_t iot_data)
  10076. {
  10077. Stopwatch stopwatch1 = new Stopwatch();
  10078. Stopwatch stopwatch2 = new Stopwatch();
  10079. string resultStr = string.Empty;
  10080. try
  10081. {
  10082. stopwatch1.Start();
  10083. string oEEType = iot_data.BeatAction.ToString(); // 节拍类型(plc写入)
  10084. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode); //产品SN
  10085. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  10086. if (!actionBool)
  10087. {
  10088. stopwatch2.Start();
  10089. //写入PLC
  10090. IoT_DataSet_t iotData = new IoT_DataSet_t();
  10091. iotData.machineState = iot_data.machineState;
  10092. iotData.work_type = iot_data.work_type;
  10093. iotData.testStatus = iot_data.testStatus;
  10094. iotData.BeatAction = iot_data.BeatAction;
  10095. iotData.beatReturn = 2; //NG
  10096. iotData.fault_codes = iot_data.fault_codes;
  10097. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  10098. stopwatch2.Stop();
  10099. AddMessage(LogType.Info,
  10100. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  10101. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  10102. return;
  10103. }
  10104. //作业开始后要有物料和载具信息
  10105. if (string.IsNullOrEmpty(strProductBarcode) && string.IsNullOrEmpty(CarrierBarcode) &&
  10106. Convert.ToInt32(oEEType) > 2)
  10107. {
  10108. stopwatch2.Start();
  10109. //写入PLC
  10110. IoT_DataSet_t iotData = new IoT_DataSet_t();
  10111. iotData.machineState = iot_data.machineState;
  10112. iotData.work_type = iot_data.work_type;
  10113. iotData.testStatus = iot_data.testStatus;
  10114. iotData.BeatAction = iot_data.BeatAction;
  10115. iotData.beatReturn = 2; //NG
  10116. iotData.fault_codes = iot_data.fault_codes;
  10117. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  10118. stopwatch2.Stop();
  10119. AddMessage_Station(stationNameStr, LogType.Info,
  10120. stationNameStr + $"_[{CarrierBarcode}][{strProductBarcode}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  10121. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  10122. return;
  10123. }
  10124. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(strProductBarcode))
  10125. {
  10126. stopwatch2.Start();
  10127. //写入PLC
  10128. IoT_DataSet_t iotData = new IoT_DataSet_t();
  10129. iotData.machineState = iot_data.machineState;
  10130. iotData.work_type = iot_data.work_type;
  10131. iotData.testStatus = iot_data.testStatus;
  10132. iotData.BeatAction = iot_data.BeatAction;
  10133. iotData.beatReturn = 2; //NG
  10134. iotData.fault_codes = iot_data.fault_codes;
  10135. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  10136. stopwatch2.Stop();
  10137. AddMessage_Station(stationNameStr, LogType.Info,
  10138. stationNameStr + $"_[{CarrierBarcode}]上传节拍失败!物料码不可为空;总用时" +
  10139. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  10140. return;
  10141. }
  10142. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(CarrierBarcode))
  10143. {
  10144. stopwatch2.Start();
  10145. //写入PLC
  10146. IoT_DataSet_t iotData = new IoT_DataSet_t();
  10147. iotData.machineState = iot_data.machineState;
  10148. iotData.work_type = iot_data.work_type;
  10149. iotData.testStatus = iot_data.testStatus;
  10150. iotData.BeatAction = iot_data.BeatAction;
  10151. iotData.beatReturn = 2; //NG
  10152. iotData.fault_codes = iot_data.fault_codes;
  10153. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  10154. stopwatch2.Stop();
  10155. AddMessage_Station(stationNameStr, LogType.Info,
  10156. stationNameStr + $"_上传节拍失败!载具码不可为空;总用时" +
  10157. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  10158. return;
  10159. }
  10160. short _result = 0;
  10161. // 上传OEE
  10162. (short, string) result =
  10163. SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  10164. _result = result.Item1;
  10165. resultStr = result.Item2;
  10166. if (_result == 1)
  10167. {
  10168. stopwatch2.Start();
  10169. //写入PLC
  10170. IoT_DataSet_t iotData = new IoT_DataSet_t();
  10171. iotData.machineState = iot_data.machineState;
  10172. iotData.work_type = iot_data.work_type;
  10173. iotData.testStatus = iot_data.testStatus;
  10174. iotData.BeatAction = iot_data.BeatAction;
  10175. iotData.beatReturn = 1; //OK
  10176. iotData.fault_codes = iot_data.fault_codes;
  10177. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  10178. OnMessage(LogType.Info,
  10179. $"PLC{plcNo}_{stationNameStr} 节拍{iotData.BeatAction}上传IOT成功!上传结果:" + resultStr);
  10180. stopwatch2.Stop();
  10181. }
  10182. else
  10183. {
  10184. stopwatch2.Start();
  10185. //写入PLC
  10186. IoT_DataSet_t iotData = new IoT_DataSet_t();
  10187. iotData.machineState = iot_data.machineState;
  10188. iotData.work_type = iot_data.work_type;
  10189. iotData.testStatus = iot_data.testStatus;
  10190. iotData.BeatAction = iot_data.BeatAction;
  10191. iotData.beatReturn = 2; //NG
  10192. iotData.fault_codes = iot_data.fault_codes;
  10193. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  10194. stopwatch2.Stop();
  10195. AddMessage_Station(stationNameStr, LogType.Error,
  10196. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  10197. }
  10198. }
  10199. catch (Exception ex)
  10200. {
  10201. string str = ex.StackTrace;
  10202. AddMessage_Station(stationNameStr, LogType.Error,
  10203. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  10204. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10205. // MES_Flag
  10206. stopwatch2.Start();
  10207. //写入PLC
  10208. IoT_DataSet_t iotData = new IoT_DataSet_t();
  10209. iotData.machineState = iot_data.machineState;
  10210. iotData.work_type = iot_data.work_type;
  10211. iotData.testStatus = iot_data.testStatus;
  10212. iotData.BeatAction = iot_data.BeatAction;
  10213. iotData.beatReturn = 2; //NG
  10214. iotData.fault_codes = iot_data.fault_codes;
  10215. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  10216. stopwatch2.Stop();
  10217. }
  10218. stopwatch1.Stop();
  10219. AddMessage(LogType.Info,
  10220. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10221. stopwatch2.ElapsedMilliseconds + "ms");
  10222. }
  10223. #endregion [S3] 值板机
  10224. #endregion PLC3 刘永村
  10225. #region PLC4 刘果段
  10226. #region [S4] 取放桁架
  10227. /// <summary>
  10228. /// S4工位的数据- 触发信号上次的值
  10229. /// </summary>
  10230. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  10231. /// <summary>
  10232. /// S4工位的数据(含触发信号)
  10233. /// </summary>
  10234. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  10235. /// <summary>
  10236. /// S4工位的数据- 回写点位
  10237. /// </summary>
  10238. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  10239. /// <summary>
  10240. /// [S4] 取放桁架
  10241. /// </summary>
  10242. /// <param name="plcNo">PLC编号</param>
  10243. //private void ReadStation_S4(int plcNo)
  10244. //{
  10245. // // [S1] Tray盘上料装备
  10246. // // [S2] FCT
  10247. // // [S3] 值板机
  10248. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  10249. // // [S5] Tray盘下料装备
  10250. // /// 上位机心跳
  10251. // /// 获取设备报警数据与状态信息
  10252. // string stationCode = "[S4_1]";
  10253. // string stationName = "载具下线装备";
  10254. // string stationNameStr = stationCode + stationName;
  10255. // string stationCode2 = "[S4_2]";
  10256. // string stationName2 = "桁架";
  10257. // string stationNameStr2 = stationCode2 + stationName2;
  10258. // string stationCode3 = "[S4_3]";
  10259. // string stationName3 = "提升机1";
  10260. // string stationNameStr3 = stationCode3 + stationName3;
  10261. // string stationCode4 = "[S4_4]";
  10262. // string stationName4 = "提升机2";
  10263. // string stationNameStr4 = stationCode4 + stationName4;
  10264. // string stationCode5 = "[S4_5]";
  10265. // string stationName5 = "载具上线装备";
  10266. // string stationNameStr5 = stationCode5 + stationName5;
  10267. // #region 创建字典
  10268. // // 触发信号字典 赋值
  10269. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  10270. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  10271. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  10272. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  10273. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  10274. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  10275. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  10276. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  10277. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  10278. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  10279. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  10280. // // PLC数据字典 赋值
  10281. // // 载具下线装备(弹夹上线)
  10282. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  10283. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  10284. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  10285. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  10286. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  10287. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  10288. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  10289. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  10290. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  10291. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  10292. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  10293. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  10294. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  10295. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  10296. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  10297. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  10298. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  10299. // s4PLCData.Add("d1Result", 0); // 产品结果
  10300. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  10301. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  10302. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  10303. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  10304. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  10305. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  10306. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  10307. // // 真空标机(提升机)
  10308. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  10309. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  10310. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  10311. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  10312. // s4PLCData.Add("d3Result", 0); // 产品结果
  10313. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  10314. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  10315. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  10316. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  10317. // s4PLCData.Add("d4Result", 0); // 产品结果
  10318. // // 载具上线装备(弹夹下线)
  10319. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  10320. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  10321. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  10322. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  10323. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  10324. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  10325. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  10326. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  10327. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  10328. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  10329. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  10330. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  10331. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  10332. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  10333. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  10334. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  10335. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  10336. // s4PLCData.Add("d5Result", 0); // 产品结果
  10337. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  10338. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  10339. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  10340. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  10341. // #endregion 创建字典
  10342. // while (IsRun)
  10343. // {
  10344. // try
  10345. // {
  10346. // if (!GlobalContext._IsCon_Funs4)
  10347. // {
  10348. // UpdatePLCMonitor(1, plcNo, 0);
  10349. // continue;
  10350. // }
  10351. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  10352. // {
  10353. // Stopwatch stopwatch1 = new Stopwatch();
  10354. // Stopwatch stopwatch2 = new Stopwatch();
  10355. // stopwatch1.Start();
  10356. // stopwatch2.Start();
  10357. // #region 一次性读取所有数据
  10358. // // 载具下线装备(弹夹上线)
  10359. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  10360. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  10361. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  10362. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  10363. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  10364. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  10365. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  10366. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  10367. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  10368. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  10369. // int[] datas = data1.Concat(data2).ToArray();
  10370. // datas = datas.Concat(data3).ToArray();
  10371. // datas = datas.Concat(data4).ToArray();
  10372. // datas = datas.Concat(data5).ToArray();
  10373. // datas = datas.Concat(data6).ToArray();
  10374. // datas = datas.Concat(data7).ToArray();
  10375. // datas = datas.Concat(data8).ToArray();
  10376. // datas = datas.Concat(data9).ToArray();
  10377. // datas = datas.Concat(data10).ToArray();
  10378. // // 载具下线装备(弹夹上线)
  10379. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  10380. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  10381. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  10382. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  10383. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  10384. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  10385. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  10386. // s4PLCData["d1MES_FLAG"] = datas[65];
  10387. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  10388. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  10389. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  10390. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  10391. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  10392. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  10393. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  10394. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  10395. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  10396. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  10397. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  10398. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  10399. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  10400. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  10401. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  10402. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  10403. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  10404. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  10405. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  10406. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  10407. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  10408. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  10409. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  10410. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  10411. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  10412. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  10413. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  10414. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  10415. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  10416. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  10417. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  10418. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  10419. // s4PLCData["d1Result"] = datas[386];
  10420. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  10421. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  10422. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  10423. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  10424. // s4PLCData["d1OEEType"] = datas[419];
  10425. // // 桁架(查询标机中弹夹的状态)
  10426. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  10427. // s4PLCData["d2BulletclipStates"] = datas[431];
  10428. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  10429. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  10430. // // 真空标机
  10431. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  10432. // s4PLCData["d3MES_FLAG"] = datas[463];
  10433. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  10434. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  10435. // s4PLCData["d3Result"] = datas[484];
  10436. // s4PLCData["d3Type"] = datas[485];
  10437. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  10438. // s4PLCData["d4MES_FLAG"] = datas[496];
  10439. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  10440. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  10441. // s4PLCData["d4Result"] = datas[517];
  10442. // s4PLCData["d4Type"] = datas[518];
  10443. // // 载具上线装备(弹夹下线)
  10444. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  10445. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  10446. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  10447. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  10448. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  10449. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  10450. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  10451. // s4PLCData["d5MES_FLAG"] = datas[591];
  10452. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  10453. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  10454. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  10455. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  10456. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  10457. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  10458. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  10459. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  10460. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  10461. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  10462. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  10463. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  10464. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  10465. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  10466. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  10467. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  10468. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  10469. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  10470. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  10471. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  10472. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  10473. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  10474. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  10475. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  10476. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  10477. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  10478. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  10479. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  10480. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  10481. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  10482. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  10483. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  10484. // s4PLCData["d5Result"] = datas[912];
  10485. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  10486. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  10487. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  10488. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  10489. // s4PLCData["d5OEEType"] = datas[945];
  10490. // #endregion 一次性读取所有数据
  10491. // stopwatch2.Stop();
  10492. // #region 回写操作,写后清空flag
  10493. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  10494. // #endregion 回写操作,写后清空flag
  10495. // // N801A-S4_1 弹夹扫码
  10496. // #region N801A-S4_1 弹夹扫码
  10497. // try
  10498. // {
  10499. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  10500. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  10501. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  10502. // {
  10503. // if (d1BulletclipScanCode == 1) // 0->1
  10504. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  10505. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  10506. // }
  10507. // }
  10508. // catch (Exception ex)
  10509. // {
  10510. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  10511. // string str = ex.StackTrace;
  10512. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10513. // }
  10514. // #endregion N801A-S4_1 弹夹扫码
  10515. // // N801A-S4_1 载具扫码
  10516. // #region N801A-S4_1 载具扫码
  10517. // try
  10518. // {
  10519. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  10520. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  10521. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  10522. // {
  10523. // if (d1VehicleScanCode == 1) // 0->1
  10524. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  10525. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  10526. // }
  10527. // }
  10528. // catch (Exception ex)
  10529. // {
  10530. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  10531. // string str = ex.StackTrace;
  10532. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10533. // }
  10534. // #endregion N801A-S4_1 载具扫码
  10535. // // N801A-S4_1 出站接口
  10536. // #region N801A-S4_1 出站接口
  10537. // try
  10538. // {
  10539. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  10540. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  10541. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  10542. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  10543. // {
  10544. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  10545. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  10546. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  10547. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  10548. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  10549. // }
  10550. // }
  10551. // catch (Exception ex)
  10552. // {
  10553. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  10554. // string str = ex.StackTrace;
  10555. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10556. // }
  10557. // #endregion N801A-S4_1 出站接口
  10558. // // N801A-S4_1 节拍接口
  10559. // #region N801A-S4_1 节拍接口
  10560. // try
  10561. // {
  10562. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  10563. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  10564. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  10565. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  10566. // {
  10567. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  10568. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  10569. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  10570. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  10571. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  10572. // }
  10573. // }
  10574. // catch (Exception ex)
  10575. // {
  10576. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  10577. // string str = ex.StackTrace;
  10578. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10579. // }
  10580. // #endregion N801A-S4_1 节拍接口
  10581. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  10582. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  10583. // try
  10584. // {
  10585. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  10586. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  10587. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  10588. // {
  10589. // if (d2BulletclipScanCode == 1) // 0->1
  10590. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  10591. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  10592. // }
  10593. // }
  10594. // catch (Exception ex)
  10595. // {
  10596. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  10597. // string str = ex.StackTrace;
  10598. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10599. // }
  10600. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  10601. // // N801A-S4_3 真空标机1 数据
  10602. // #region N801A-S4_3 真空标机1
  10603. // try
  10604. // {
  10605. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  10606. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  10607. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  10608. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  10609. // {
  10610. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  10611. // {
  10612. // int stationType = (int)s4PLCData["d3Type"];
  10613. // if (stationType == 1)
  10614. // {
  10615. // // S4_3进站接口
  10616. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  10617. // }
  10618. // else if (stationType == 2)
  10619. // {
  10620. // // S4_3出站接口
  10621. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  10622. // }
  10623. // }
  10624. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  10625. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  10626. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  10627. // }
  10628. // }
  10629. // catch (Exception ex)
  10630. // {
  10631. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  10632. // string str = ex.StackTrace;
  10633. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10634. // }
  10635. // #endregion N801A-S4_3 真空标机1
  10636. // // N801A-S4_4 真空标机2 数据
  10637. // #region N801A-S4_4 真空标机2
  10638. // try
  10639. // {
  10640. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  10641. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  10642. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  10643. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  10644. // {
  10645. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  10646. // {
  10647. // int stationType = (int)s4PLCData["d4Type"];
  10648. // if (stationType == 1)
  10649. // {
  10650. // // S4_4进站接口
  10651. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  10652. // }
  10653. // else if (stationType == 2)
  10654. // {
  10655. // // S4_4出站接口
  10656. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  10657. // }
  10658. // }
  10659. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  10660. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  10661. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  10662. // }
  10663. // }
  10664. // catch (Exception ex)
  10665. // {
  10666. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  10667. // string str = ex.StackTrace;
  10668. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10669. // }
  10670. // #endregion N801A-S4_4 真空标机2
  10671. // // N801A-S4_5 弹夹扫码 数据
  10672. // #region N801A-S4_5 弹夹扫码
  10673. // try
  10674. // {
  10675. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  10676. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  10677. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  10678. // {
  10679. // if (d5BulletclipScanCode == 1) // 0->1
  10680. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  10681. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  10682. // }
  10683. // }
  10684. // catch (Exception ex)
  10685. // {
  10686. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  10687. // string str = ex.StackTrace;
  10688. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10689. // }
  10690. // #endregion N801A-S4_5 弹夹扫码
  10691. // // N801A-S4_5 载具扫码 数据
  10692. // #region N801A-S4_5 载具扫码
  10693. // try
  10694. // {
  10695. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  10696. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  10697. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  10698. // {
  10699. // if (d5VehicleScanCode == 1) // 0->1
  10700. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  10701. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  10702. // }
  10703. // }
  10704. // catch (Exception ex)
  10705. // {
  10706. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  10707. // string str = ex.StackTrace;
  10708. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10709. // }
  10710. // #endregion N801A-S4_5 载具扫码
  10711. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  10712. // #region N801A-S4_5 出站接口
  10713. // try
  10714. // {
  10715. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  10716. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  10717. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  10718. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  10719. // {
  10720. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  10721. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  10722. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  10723. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  10724. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  10725. // }
  10726. // }
  10727. // catch (Exception ex)
  10728. // {
  10729. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  10730. // string str = ex.StackTrace;
  10731. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10732. // }
  10733. // #endregion N801A-S4_5 出站接口
  10734. // // N801A-S4_5 节拍接口 数据
  10735. // #region N801A-S4_5 节拍接口
  10736. // try
  10737. // {
  10738. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  10739. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  10740. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  10741. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  10742. // {
  10743. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  10744. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  10745. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  10746. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  10747. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  10748. // }
  10749. // }
  10750. // catch (Exception ex)
  10751. // {
  10752. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  10753. // string str = ex.StackTrace;
  10754. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10755. // }
  10756. // #endregion N801A-S4_5 节拍接口
  10757. // #region 心跳
  10758. // try
  10759. // {
  10760. // short states = 0;
  10761. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  10762. // }
  10763. // catch (Exception ex)
  10764. // {
  10765. // string str = ex.StackTrace;
  10766. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10767. // }
  10768. // #endregion 心跳
  10769. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  10770. // stopwatch1.Stop();
  10771. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  10772. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  10773. // }
  10774. // else
  10775. // {
  10776. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  10777. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  10778. // Funs[plcNo].Connect();
  10779. // }
  10780. // }
  10781. // catch (Exception ex)
  10782. // {
  10783. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  10784. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  10785. // Funs[plcNo].ReConnect();
  10786. // }
  10787. // Thread.Sleep(IntervalReadPLC);
  10788. // }
  10789. //}
  10790. /// <summary>
  10791. /// [S4] 取放桁架 - S4_1弹夹扫码
  10792. /// </summary>
  10793. /// <param name="plcNo">PLC编号</param>
  10794. /// <param name="stationNameStr">工站全称</param>
  10795. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  10796. {
  10797. Stopwatch stopwatch1 = new Stopwatch();
  10798. Stopwatch stopwatch2 = new Stopwatch();
  10799. try
  10800. {
  10801. stopwatch1.Start();
  10802. // ZS 弹夹扫码
  10803. string d1BulletclipCode = " "; // 扫到的码
  10804. short d1BulletclipScanCode = 2;
  10805. stopwatch2.Start();
  10806. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  10807. //// MES_Flag
  10808. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10809. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10810. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  10811. writeToPLC_Flag.Adress = 2002;
  10812. writeToPLC_Flag.Value = d1BulletclipScanCode;
  10813. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  10814. {
  10815. Name = "d1BulletclipCode",
  10816. Adress = 2003,
  10817. ValueType = PLCValueType.String,
  10818. ValueTypeStrLength = 20,
  10819. Value = d1BulletclipCode
  10820. });
  10821. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  10822. stopwatch2.Stop();
  10823. }
  10824. catch (Exception ex)
  10825. {
  10826. string str = ex.StackTrace;
  10827. AddMessage_Station(stationNameStr, LogType.Error,
  10828. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10829. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10830. stopwatch2.Start();
  10831. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  10832. //// MES_Flag
  10833. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  10834. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10835. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  10836. writeToPLC_Flag.Adress = 2002;
  10837. writeToPLC_Flag.Value = (short)6;
  10838. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  10839. {
  10840. Name = "d1BulletclipCode",
  10841. Adress = 2003,
  10842. ValueType = PLCValueType.String,
  10843. ValueTypeStrLength = 20,
  10844. Value = " "
  10845. });
  10846. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  10847. stopwatch2.Stop();
  10848. }
  10849. stopwatch1.Stop();
  10850. AddMessage(LogType.Info,
  10851. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10852. stopwatch2.ElapsedMilliseconds + "ms");
  10853. }
  10854. /// <summary>
  10855. /// [S4] 取放桁架 - S4_1载具扫码
  10856. /// </summary>
  10857. /// <param name="plcNo">PLC编号</param>
  10858. /// <param name="stationNameStr">工站全称</param>
  10859. private void S4_1载具扫码(int plcNo, string stationNameStr)
  10860. {
  10861. Stopwatch stopwatch1 = new Stopwatch();
  10862. Stopwatch stopwatch2 = new Stopwatch();
  10863. try
  10864. {
  10865. stopwatch1.Start();
  10866. // ZS 载具扫码
  10867. string d1VehicleCode = ""; // 扫到的码
  10868. short d1VehicleScanCode = 2;
  10869. #region 进站
  10870. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  10871. {
  10872. #region 查询载具上的产品信息
  10873. string cavityData = string.Empty;
  10874. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  10875. if (string.IsNullOrEmpty(cavityData))
  10876. cavityData = "";
  10877. if (snResult != 0)
  10878. {
  10879. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10880. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  10881. writeToPLC_Flag1.Adress = 2033;
  10882. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  10883. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10884. {
  10885. Name = "d1VehicleCode",
  10886. Adress = 2034,
  10887. ValueType = PLCValueType.String,
  10888. ValueTypeStrLength = 20,
  10889. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  10890. });
  10891. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  10892. stopwatch1.Stop();
  10893. AddMessage(LogType.Info,
  10894. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10895. "ms");
  10896. return;
  10897. }
  10898. string[] cavitySNs = cavityData.Split('.');
  10899. string partNo = "";
  10900. if (cavitySNs != null && cavitySNs.Length >= 1)
  10901. {
  10902. partNo = cavitySNs[0];
  10903. }
  10904. #endregion 查询载具上的产品信息
  10905. List<TestItem> item = new List<TestItem>();
  10906. item.Add(new TestItem()
  10907. {
  10908. Parameter_name = "载具码",
  10909. Parameter_value = d1VehicleCode,
  10910. });
  10911. item.Add(new TestItem()
  10912. {
  10913. Parameter_name = "载具穴号",
  10914. Parameter_value = "1",
  10915. });
  10916. stopwatch2.Start();
  10917. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  10918. partNo, item, out string errorMsg);
  10919. stopwatch2.Stop();
  10920. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  10921. }
  10922. #endregion 进站
  10923. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  10924. //// MES_Flag
  10925. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10926. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10927. writeToPLC_Flag.Name = "d1VehicleScanCode";
  10928. writeToPLC_Flag.Adress = 2033;
  10929. writeToPLC_Flag.Value = d1VehicleScanCode;
  10930. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10931. {
  10932. Name = "d1VehicleCode",
  10933. Adress = 2034,
  10934. ValueType = PLCValueType.String,
  10935. ValueTypeStrLength = 20,
  10936. Value = d1VehicleCode
  10937. });
  10938. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  10939. }
  10940. catch (Exception ex)
  10941. {
  10942. string str = ex.StackTrace;
  10943. AddMessage_Station(stationNameStr, LogType.Error,
  10944. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10945. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10946. stopwatch2.Start();
  10947. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  10948. //// MES_Flag
  10949. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  10950. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10951. writeToPLC_Flag.Name = "d1VehicleScanCode";
  10952. writeToPLC_Flag.Adress = 2033;
  10953. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  10954. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10955. {
  10956. Name = "d1VehicleCode",
  10957. Adress = 2034,
  10958. ValueType = PLCValueType.String,
  10959. ValueTypeStrLength = 20,
  10960. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  10961. });
  10962. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  10963. stopwatch2.Stop();
  10964. }
  10965. stopwatch1.Stop();
  10966. AddMessage(LogType.Info,
  10967. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10968. stopwatch2.ElapsedMilliseconds + "ms");
  10969. }
  10970. // 上次采集到的SN
  10971. //private string sn_S4_1出站接口 = string.Empty;
  10972. /// <summary>
  10973. /// [S4] 取放桁架 - S4_1出站接口
  10974. /// </summary>
  10975. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  10976. {
  10977. Stopwatch stopwatch1 = new Stopwatch();
  10978. Stopwatch stopwatch2 = new Stopwatch();
  10979. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10980. string stationNameStr = stationCode + stationName;
  10981. string processItem = stationName; // 测试项目
  10982. try
  10983. {
  10984. stopwatch1.Start();
  10985. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10986. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10987. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10988. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10989. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  10990. sn = sn.Replace("\0", "");
  10991. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  10992. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  10993. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  10994. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  10995. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  10996. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  10997. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  10998. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  10999. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  11000. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  11001. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  11002. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  11003. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  11004. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  11005. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  11006. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  11007. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  11008. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  11009. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  11010. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  11011. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  11012. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  11013. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  11014. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  11015. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  11016. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  11017. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  11018. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  11019. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  11020. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  11021. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  11022. bool pass = d1Result == 1;
  11023. // 存 载具SN列表
  11024. List<string> vehicleCodes = new List<string>()
  11025. {
  11026. d1VehicleCode1, d1VehicleCode2, d1VehicleCode3, d1VehicleCode4, d1VehicleCode5,
  11027. d1VehicleCode6, d1VehicleCode7, d1VehicleCode8, d1VehicleCode9, d1VehicleCode10,
  11028. d1VehicleCode11, d1VehicleCode12, d1VehicleCode13, d1VehicleCode14, d1VehicleCode15
  11029. };
  11030. // 统一查 产品SN列表
  11031. List<string> partNos = new List<string>();
  11032. foreach (string vehicleCode in vehicleCodes)
  11033. {
  11034. if (string.IsNullOrEmpty(vehicleCode))
  11035. partNos.Add("");
  11036. else
  11037. {
  11038. string partNo = "";
  11039. #region 查询载具上的产品信息
  11040. string cavityData = string.Empty;
  11041. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  11042. if (string.IsNullOrEmpty(cavityData))
  11043. cavityData = "";
  11044. if (snResult != 0)
  11045. {
  11046. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11047. writeToPLC_Flag1.Name = "d1MES_FLAG";
  11048. writeToPLC_Flag1.Adress = 2065;
  11049. writeToPLC_Flag1.Value = (short)4;
  11050. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  11051. stopwatch1.Stop();
  11052. AddMessage(LogType.Info,
  11053. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  11054. "ms");
  11055. return;
  11056. }
  11057. string[] cavitySNs = cavityData.Split('.');
  11058. if (cavitySNs != null && cavitySNs.Length >= 1)
  11059. partNo = cavitySNs[0];
  11060. #endregion 查询载具上的产品信息
  11061. partNos.Add(partNo);
  11062. }
  11063. }
  11064. // 统一上传
  11065. stopwatch2.Start();
  11066. List<int> results = new List<int>();
  11067. for (int i = 0; i < partNos.Count; i++)
  11068. {
  11069. string index = (i + 1).ToString(); // 弹夹穴号
  11070. if (string.IsNullOrEmpty(partNos[i]))
  11071. results.Add(1);
  11072. else
  11073. {
  11074. List<TestItem> items1 = new List<TestItem>();
  11075. items1.Add(new TestItem()
  11076. {
  11077. Parameter_name = "弹夹码",
  11078. Parameter_value = sn,
  11079. Parameter_unit = ""
  11080. });
  11081. items1.Add(new TestItem()
  11082. {
  11083. Parameter_name = "弹夹穴号",
  11084. Parameter_value = index,
  11085. Parameter_unit = ""
  11086. });
  11087. items1.Add(new TestItem()
  11088. {
  11089. Parameter_name = "载具码",
  11090. Parameter_value = vehicleCodes[i],
  11091. Parameter_unit = ""
  11092. });
  11093. items1.Add(new TestItem()
  11094. {
  11095. Parameter_name = "载具穴号",
  11096. Parameter_value = "1",
  11097. Parameter_unit = ""
  11098. });
  11099. items1.Add(new TestItem()
  11100. {
  11101. Parameter_name = "产品结果",
  11102. Parameter_value = d1Result == 1 ? "OK" : "NG",
  11103. Parameter_unit = ""
  11104. });
  11105. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  11106. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  11107. results.Add(result1);
  11108. }
  11109. }
  11110. short result = 0;
  11111. if (results.All(a => a == 1))
  11112. result = 1;
  11113. else if (results.Contains(3))
  11114. result = 3;
  11115. else if (results.Contains(2))
  11116. result = 2;
  11117. else if (results.Contains(4))
  11118. result = 4;
  11119. else
  11120. result = 4;
  11121. stopwatch2.Stop();
  11122. #region 存储绑定数据到 边线MES系统中
  11123. if (result == 1)
  11124. {
  11125. string data = string.Join(".", vehicleCodes);
  11126. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  11127. if (resultMesR != 0)
  11128. {
  11129. result = 4;
  11130. AddMessage_Station(stationNameStr, LogType.Error,
  11131. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  11132. }
  11133. }
  11134. #endregion 存储绑定数据到 边线MES系统中
  11135. // MES_Flag 为4MES报错
  11136. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11137. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11138. writeToPLC_Flag.Name = "d1MES_FLAG";
  11139. writeToPLC_Flag.Adress = 2065;
  11140. writeToPLC_Flag.Value = result;
  11141. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  11142. OnMessage(LogType.Debug,
  11143. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  11144. }
  11145. catch (Exception ex)
  11146. {
  11147. stopwatch2.Restart();
  11148. // MES_Flag 为4上位机报错
  11149. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  11150. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11151. writeToPLC_Flag.Name = "d1MES_FLAG";
  11152. writeToPLC_Flag.Adress = 2065;
  11153. writeToPLC_Flag.Value = (short)4;
  11154. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  11155. stopwatch2.Stop();
  11156. string str = ex.StackTrace;
  11157. AddMessage_Station(stationNameStr, LogType.Error,
  11158. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11159. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11160. }
  11161. stopwatch1.Stop();
  11162. AddMessage(LogType.Info,
  11163. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11164. stopwatch2.ElapsedMilliseconds + "ms");
  11165. }
  11166. /// <summary>
  11167. /// [S4] 取放桁架 - S4_1节拍接口
  11168. /// </summary>
  11169. /// <param name="plcNo">PLC编号</param>
  11170. /// <param name="stationNameStr">工站全称</param>
  11171. private void S4_1节拍接口(int plcNo, string stationNameStr)
  11172. {
  11173. Stopwatch stopwatch1 = new Stopwatch();
  11174. Stopwatch stopwatch2 = new Stopwatch();
  11175. string resultStr = string.Empty;
  11176. try
  11177. {
  11178. stopwatch1.Start();
  11179. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  11180. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  11181. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  11182. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  11183. if (!actionBool)
  11184. {
  11185. stopwatch2.Start();
  11186. // MES_Flag
  11187. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11188. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11189. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  11190. writeToPLC_Flag1.Adress = 2398;
  11191. writeToPLC_Flag1.Value = (short)4;
  11192. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  11193. stopwatch2.Stop();
  11194. AddMessage(LogType.Info,
  11195. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  11196. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  11197. return;
  11198. }
  11199. string d1OEEPartNo = string.Empty; // 物料码
  11200. if (string.IsNullOrEmpty(d1OEEProductSN))
  11201. {
  11202. stopwatch2.Start();
  11203. // MES_Flag
  11204. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11205. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11206. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  11207. writeToPLC_Flag1.Adress = 2398;
  11208. writeToPLC_Flag1.Value = (short)1;
  11209. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  11210. stopwatch2.Stop();
  11211. AddMessage(LogType.Info,
  11212. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11213. stopwatch2.ElapsedMilliseconds + "ms");
  11214. return;
  11215. }
  11216. else
  11217. {
  11218. // 查产品SN ZS
  11219. d1OEEPartNo = "Test";
  11220. }
  11221. short d1OEEMES_FLAG = 0;
  11222. // 上传OEE
  11223. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  11224. d1OEEMES_FLAG = result.Item1;
  11225. resultStr = result.Item2;
  11226. stopwatch2.Start();
  11227. // MES_Flag
  11228. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11229. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11230. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  11231. writeToPLC_Flag.Adress = 2398;
  11232. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  11233. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  11234. stopwatch2.Stop();
  11235. }
  11236. catch (Exception ex)
  11237. {
  11238. string str = ex.StackTrace;
  11239. AddMessage_Station(stationNameStr, LogType.Error,
  11240. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  11241. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11242. // MES_Flag
  11243. stopwatch2.Start();
  11244. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  11245. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11246. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  11247. writeToPLC_Flag.Adress = 2398;
  11248. writeToPLC_Flag.Value = (short)4;
  11249. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  11250. stopwatch2.Stop();
  11251. }
  11252. stopwatch1.Stop();
  11253. AddMessage(LogType.Info,
  11254. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11255. stopwatch2.ElapsedMilliseconds + "ms");
  11256. }
  11257. /// <summary>
  11258. /// [S4] 取放桁架 - S4_2桁架
  11259. /// </summary>
  11260. /// <param name="plcNo">PLC编号</param>
  11261. /// <param name="stationNameStr">工站全称</param>
  11262. private void S4_2桁架(int plcNo, string stationNameStr)
  11263. {
  11264. Stopwatch stopwatch1 = new Stopwatch();
  11265. Stopwatch stopwatch2 = new Stopwatch();
  11266. try
  11267. {
  11268. stopwatch1.Start();
  11269. // ZS 弹夹扫码
  11270. string d2BulletclipCode = " "; // 扫到的码
  11271. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  11272. short d2BulletclipScanCode = 2;
  11273. stopwatch2.Start();
  11274. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  11275. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  11276. //// MES_Flag
  11277. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  11278. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11279. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  11280. writeToPLC_Flag.Adress = 2430;
  11281. writeToPLC_Flag.Value = d2BulletclipScanCode;
  11282. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  11283. {
  11284. Name = "d2BulletclipCode",
  11285. Adress = 2432,
  11286. ValueType = PLCValueType.String,
  11287. ValueTypeStrLength = 20,
  11288. Value = d2BulletclipCode
  11289. });
  11290. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  11291. {
  11292. Name = "d2BulletclipStates",
  11293. Adress = 2431,
  11294. ValueType = PLCValueType.Short,
  11295. Value = d2BulletclipStates
  11296. });
  11297. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  11298. stopwatch2.Stop();
  11299. }
  11300. catch (Exception ex)
  11301. {
  11302. string str = ex.StackTrace;
  11303. AddMessage_Station(stationNameStr, LogType.Error,
  11304. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  11305. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11306. stopwatch2.Start();
  11307. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  11308. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  11309. // MES_Flag
  11310. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  11311. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11312. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  11313. writeToPLC_Flag.Adress = 2430;
  11314. writeToPLC_Flag.Value = (short)6;
  11315. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  11316. {
  11317. Name = "d2BulletclipCode",
  11318. Adress = 2432,
  11319. ValueType = PLCValueType.String,
  11320. ValueTypeStrLength = 20,
  11321. Value = " "
  11322. });
  11323. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  11324. {
  11325. Name = "d2BulletclipStates",
  11326. Adress = 2431,
  11327. ValueType = PLCValueType.Short,
  11328. Value = (short)0
  11329. });
  11330. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  11331. stopwatch2.Stop();
  11332. }
  11333. stopwatch1.Stop();
  11334. AddMessage(LogType.Info,
  11335. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11336. stopwatch2.ElapsedMilliseconds + "ms");
  11337. }
  11338. // 上次采集到的SN
  11339. //private string sn_S4_3进站接口 = string.Empty;
  11340. /// <summary>
  11341. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  11342. /// </summary>
  11343. private void S4_3进站接口(int plcNo, string stationNameStr)
  11344. {
  11345. Stopwatch stopwatch1 = new Stopwatch();
  11346. Stopwatch stopwatch2 = new Stopwatch();
  11347. try
  11348. {
  11349. stopwatch1.Start();
  11350. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  11351. sn = sn.Replace("\0", "");
  11352. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  11353. #region 查询15个载具码
  11354. List<string> vehicleCodes = new List<string>(); // 15个载具码
  11355. string vehicleData = string.Empty;
  11356. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  11357. if (string.IsNullOrEmpty(vehicleData))
  11358. vehicleData = "";
  11359. if (snResult != 0)
  11360. {
  11361. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11362. writeToPLC_Flag1.Name = "d3MES_FLAG";
  11363. writeToPLC_Flag1.Adress = 2463;
  11364. writeToPLC_Flag1.Value = (short)4;
  11365. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  11366. stopwatch1.Stop();
  11367. AddMessage(LogType.Info,
  11368. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11369. return;
  11370. }
  11371. string[] cavitySNs = vehicleData.Split('.');
  11372. if (cavitySNs != null && cavitySNs.Length > 0)
  11373. {
  11374. for (int i = 0; i < cavitySNs.Length; i++)
  11375. {
  11376. if (string.IsNullOrEmpty(cavitySNs[i]))
  11377. vehicleCodes.Add("");
  11378. else
  11379. vehicleCodes.Add(cavitySNs[i]);
  11380. }
  11381. }
  11382. #endregion 查询15个载具码
  11383. #region 查询15个产品SN
  11384. List<string> portNos = new List<string>(); // 15个产品SN
  11385. foreach (string vehicleCode in vehicleCodes)
  11386. {
  11387. if (string.IsNullOrEmpty(vehicleCode))
  11388. portNos.Add("");
  11389. else
  11390. {
  11391. // 查询
  11392. string cavityData = string.Empty;
  11393. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  11394. if (string.IsNullOrEmpty(cavityData))
  11395. cavityData = "";
  11396. if (snResult1 != 0)
  11397. {
  11398. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11399. writeToPLC_Flag1.Name = "d3MES_FLAG";
  11400. writeToPLC_Flag1.Adress = 2463;
  11401. writeToPLC_Flag1.Value = (short)4;
  11402. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  11403. stopwatch1.Stop();
  11404. AddMessage(LogType.Info,
  11405. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  11406. stopwatch1.ElapsedMilliseconds + "ms");
  11407. return;
  11408. }
  11409. string[] partSNs = cavityData.Split('.');
  11410. if (partSNs != null && partSNs.Length >= 1)
  11411. portNos.Add(partSNs[0]);
  11412. else
  11413. portNos.Add("");
  11414. }
  11415. }
  11416. #endregion 查询15个产品SN
  11417. // 调用MES进站(最多15个)
  11418. stopwatch2.Start();
  11419. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  11420. for (int i = 0; i < vehicleCodes.Count; i++)
  11421. {
  11422. // 循环进站
  11423. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  11424. {
  11425. // 产品SN(物料码)校验
  11426. string portNo = portNos[i];
  11427. List<TestItem> item = new List<TestItem>();
  11428. item.Add(new TestItem()
  11429. {
  11430. Parameter_name = "弹夹码",
  11431. Parameter_value = sn,
  11432. });
  11433. item.Add(new TestItem()
  11434. {
  11435. Parameter_name = "弹夹穴位",
  11436. Parameter_value = (i + 1).ToString(),
  11437. });
  11438. item.Add(new TestItem()
  11439. {
  11440. Parameter_name = "载具码",
  11441. Parameter_value = vehicleCodes[i],
  11442. });
  11443. item.Add(new TestItem()
  11444. {
  11445. Parameter_name = "载具穴号",
  11446. Parameter_value = "1",
  11447. });
  11448. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  11449. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  11450. }
  11451. }
  11452. stopwatch2.Stop();
  11453. short result = 0;
  11454. bool haveMesWarn = results.Contains(5);
  11455. bool havePCWarn = results.Contains(6);
  11456. if (haveMesWarn)
  11457. result = 2; // 5->2
  11458. else if (havePCWarn)
  11459. result = 6; // 6->4
  11460. else
  11461. result = 1;
  11462. // MES_Flag 为4MES报错
  11463. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11464. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11465. writeToPLC_Flag.Name = "d3MES_FLAG";
  11466. writeToPLC_Flag.Adress = 2463;
  11467. writeToPLC_Flag.Value = result;
  11468. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  11469. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  11470. }
  11471. catch (Exception ex)
  11472. {
  11473. stopwatch2.Stop();
  11474. // MES_Flag 为4上位机报错
  11475. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  11476. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11477. writeToPLC_Flag.Name = "d3MES_FLAG";
  11478. writeToPLC_Flag.Adress = 2463;
  11479. writeToPLC_Flag.Value = (short)4;
  11480. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  11481. string str = ex.StackTrace;
  11482. AddMessage_Station(stationNameStr, LogType.Error,
  11483. $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11484. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11485. }
  11486. stopwatch1.Stop();
  11487. AddMessage(LogType.Info,
  11488. stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  11489. stopwatch2.ElapsedMilliseconds + "ms");
  11490. }
  11491. // 上次采集到的SN
  11492. //private string sn_S4_3出站接口 = string.Empty;
  11493. /// <summary>
  11494. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  11495. /// </summary>
  11496. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  11497. {
  11498. Stopwatch stopwatch1 = new Stopwatch();
  11499. Stopwatch stopwatch2 = new Stopwatch();
  11500. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  11501. string stationNameStr = stationCode + stationName;
  11502. string processItem = stationName; // 测试项目
  11503. try
  11504. {
  11505. stopwatch1.Start();
  11506. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  11507. //string batch_num = GlobalContext.BatchNumber; // 批次号
  11508. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  11509. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  11510. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  11511. sn = sn.Replace("\0", "");
  11512. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  11513. bool isPass = d3Result == 1; // 产品结果 bool
  11514. #region 查询15个载具码
  11515. List<string> vehicleCodes = new List<string>(); // 15个载具码
  11516. string vehicleData = string.Empty;
  11517. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  11518. if (string.IsNullOrEmpty(vehicleData))
  11519. vehicleData = "";
  11520. if (snResult1 != 0)
  11521. {
  11522. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11523. writeToPLC_Flag1.Name = "d3MES_FLAG";
  11524. writeToPLC_Flag1.Adress = 2463;
  11525. writeToPLC_Flag1.Value = (short)4;
  11526. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  11527. stopwatch1.Stop();
  11528. AddMessage(LogType.Info,
  11529. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11530. return;
  11531. }
  11532. string[] cavitySNs = vehicleData.Split('.');
  11533. if (cavitySNs != null && cavitySNs.Length > 0)
  11534. {
  11535. for (int i = 0; i < cavitySNs.Length; i++)
  11536. {
  11537. if (string.IsNullOrEmpty(cavitySNs[i]))
  11538. vehicleCodes.Add("");
  11539. else
  11540. vehicleCodes.Add(cavitySNs[i]);
  11541. }
  11542. }
  11543. #endregion 查询15个载具码
  11544. // 统一查 产品SN列表
  11545. List<string> partNos = new List<string>();
  11546. foreach (string vehicleCode in vehicleCodes)
  11547. {
  11548. if (string.IsNullOrEmpty(vehicleCode))
  11549. partNos.Add("");
  11550. else
  11551. {
  11552. string partNo = "";
  11553. #region 查询载具上的产品信息
  11554. string cavityData = string.Empty;
  11555. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  11556. if (string.IsNullOrEmpty(cavityData))
  11557. cavityData = "";
  11558. if (snResult != 0)
  11559. {
  11560. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11561. writeToPLC_Flag1.Name = "d3MES_FLAG";
  11562. writeToPLC_Flag1.Adress = 2463;
  11563. writeToPLC_Flag1.Value = (short)4;
  11564. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  11565. stopwatch1.Stop();
  11566. AddMessage(LogType.Info,
  11567. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  11568. "ms");
  11569. return;
  11570. }
  11571. string[] partSNs = cavityData.Split('.');
  11572. if (partSNs != null && partSNs.Length >= 1)
  11573. partNo = partSNs[0];
  11574. #endregion 查询载具上的产品信息
  11575. partNos.Add(partNo);
  11576. }
  11577. }
  11578. // 统一上传 - 调用MES出站
  11579. stopwatch2.Start();
  11580. List<int> results = new List<int>();
  11581. for (int i = 0; i < partNos.Count; i++)
  11582. {
  11583. string index = (i + 1).ToString(); // 弹夹穴号
  11584. if (string.IsNullOrEmpty(partNos[i]))
  11585. results.Add(1);
  11586. else
  11587. {
  11588. List<TestItem> items1 = new List<TestItem>();
  11589. items1.Add(new TestItem()
  11590. {
  11591. Parameter_name = "弹夹码",
  11592. Parameter_value = sn,
  11593. Parameter_unit = ""
  11594. });
  11595. items1.Add(new TestItem()
  11596. {
  11597. Parameter_name = "弹夹穴号",
  11598. Parameter_value = index,
  11599. Parameter_unit = ""
  11600. });
  11601. items1.Add(new TestItem()
  11602. {
  11603. Parameter_name = "载具码",
  11604. Parameter_value = vehicleCodes[i],
  11605. Parameter_unit = ""
  11606. });
  11607. items1.Add(new TestItem()
  11608. {
  11609. Parameter_name = "载具穴号",
  11610. Parameter_value = "1",
  11611. Parameter_unit = ""
  11612. });
  11613. items1.Add(new TestItem()
  11614. {
  11615. Parameter_name = "产品结果",
  11616. Parameter_value = d3Result == 1 ? "OK" : "NG",
  11617. Parameter_unit = ""
  11618. });
  11619. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  11620. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  11621. results.Add(result1);
  11622. }
  11623. }
  11624. short result = 0;
  11625. if (results.All(a => a == 1))
  11626. result = 1;
  11627. else if (results.Contains(3))
  11628. result = 3;
  11629. else if (results.Contains(2))
  11630. result = 2;
  11631. else if (results.Contains(4))
  11632. result = 4;
  11633. else
  11634. result = 4;
  11635. stopwatch2.Stop();
  11636. // MES_Flag 为4MES报错
  11637. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11638. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11639. writeToPLC_Flag.Name = "d3MES_FLAG";
  11640. writeToPLC_Flag.Adress = 2463;
  11641. writeToPLC_Flag.Value = result;
  11642. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  11643. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  11644. }
  11645. catch (Exception ex)
  11646. {
  11647. stopwatch2.Restart();
  11648. // MES_Flag 为4上位机报错
  11649. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  11650. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11651. writeToPLC_Flag.Name = "d3MES_FLAG";
  11652. writeToPLC_Flag.Adress = 2463;
  11653. writeToPLC_Flag.Value = (short)4;
  11654. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  11655. string str = ex.StackTrace;
  11656. AddMessage_Station(stationNameStr, LogType.Error,
  11657. $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11658. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11659. stopwatch2.Stop();
  11660. }
  11661. stopwatch1.Stop();
  11662. AddMessage(LogType.Info,
  11663. stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11664. stopwatch2.ElapsedMilliseconds + "ms");
  11665. }
  11666. // 上次采集到的SN
  11667. //private string sn_S4_4进站接口 = string.Empty;
  11668. /// <summary>
  11669. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  11670. /// </summary>
  11671. private void S4_4进站接口(int plcNo, string stationNameStr)
  11672. {
  11673. Stopwatch stopwatch1 = new Stopwatch();
  11674. Stopwatch stopwatch2 = new Stopwatch();
  11675. try
  11676. {
  11677. stopwatch1.Start();
  11678. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  11679. sn = sn.Replace("\0", "");
  11680. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  11681. #region 查询15个载具码
  11682. List<string> vehicleCodes = new List<string>(); // 15个载具码
  11683. string vehicleData = string.Empty;
  11684. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  11685. if (string.IsNullOrEmpty(vehicleData))
  11686. vehicleData = "";
  11687. if (snResult != 0)
  11688. {
  11689. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11690. writeToPLC_Flag1.Name = "d3MES_FLAG";
  11691. writeToPLC_Flag1.Adress = 2463;
  11692. writeToPLC_Flag1.Value = (short)4;
  11693. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  11694. stopwatch1.Stop();
  11695. AddMessage(LogType.Info,
  11696. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11697. return;
  11698. }
  11699. string[] cavitySNs = vehicleData.Split('.');
  11700. if (cavitySNs != null && cavitySNs.Length > 0)
  11701. {
  11702. for (int i = 0; i < cavitySNs.Length; i++)
  11703. {
  11704. if (string.IsNullOrEmpty(cavitySNs[i]))
  11705. vehicleCodes.Add("");
  11706. else
  11707. vehicleCodes.Add(cavitySNs[i]);
  11708. }
  11709. }
  11710. #endregion 查询15个载具码
  11711. #region 查询15个产品SN
  11712. List<string> portNos = new List<string>(); // 15个产品SN
  11713. foreach (string vehicleCode in vehicleCodes)
  11714. {
  11715. if (string.IsNullOrEmpty(vehicleCode))
  11716. portNos.Add("");
  11717. else
  11718. {
  11719. // 查询
  11720. string cavityData = string.Empty;
  11721. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  11722. if (string.IsNullOrEmpty(cavityData))
  11723. cavityData = "";
  11724. if (snResult1 != 0)
  11725. {
  11726. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11727. writeToPLC_Flag1.Name = "d3MES_FLAG";
  11728. writeToPLC_Flag1.Adress = 2463;
  11729. writeToPLC_Flag1.Value = (short)4;
  11730. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  11731. stopwatch1.Stop();
  11732. AddMessage(LogType.Info,
  11733. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  11734. stopwatch1.ElapsedMilliseconds + "ms");
  11735. return;
  11736. }
  11737. string[] partSNs = cavityData.Split('.');
  11738. if (partSNs != null && partSNs.Length >= 1)
  11739. portNos.Add(partSNs[0]);
  11740. else
  11741. portNos.Add("");
  11742. }
  11743. }
  11744. #endregion 查询15个产品SN
  11745. // 调用MES进站(最多15个)
  11746. stopwatch2.Start();
  11747. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  11748. for (int i = 0; i < vehicleCodes.Count; i++)
  11749. {
  11750. // 循环进站
  11751. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  11752. {
  11753. // 产品SN(物料码)校验
  11754. string portNo = portNos[i];
  11755. List<TestItem> item = new List<TestItem>();
  11756. item.Add(new TestItem()
  11757. {
  11758. Parameter_name = "弹夹码",
  11759. Parameter_value = sn,
  11760. });
  11761. item.Add(new TestItem()
  11762. {
  11763. Parameter_name = "弹夹穴位",
  11764. Parameter_value = (i + 1).ToString(),
  11765. });
  11766. item.Add(new TestItem()
  11767. {
  11768. Parameter_name = "载具码",
  11769. Parameter_value = vehicleCodes[i],
  11770. });
  11771. item.Add(new TestItem()
  11772. {
  11773. Parameter_name = "载具穴号",
  11774. Parameter_value = "1",
  11775. });
  11776. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  11777. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  11778. }
  11779. }
  11780. stopwatch2.Stop();
  11781. short result = 0;
  11782. bool haveMesWarn = results.Contains(5);
  11783. bool havePCWarn = results.Contains(6);
  11784. if (haveMesWarn)
  11785. result = 2; // 5->2
  11786. else if (havePCWarn)
  11787. result = 6; // 6->4
  11788. else
  11789. result = 1;
  11790. // MES_Flag 为4MES报错
  11791. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11792. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11793. writeToPLC_Flag.Name = "d4MES_FLAG";
  11794. writeToPLC_Flag.Adress = 2496;
  11795. writeToPLC_Flag.Value = result;
  11796. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  11797. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  11798. }
  11799. catch (Exception ex)
  11800. {
  11801. stopwatch2.Stop();
  11802. // MES_Flag 为4上位机报错
  11803. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  11804. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11805. writeToPLC_Flag.Name = "d4MES_FLAG";
  11806. writeToPLC_Flag.Adress = 2496;
  11807. writeToPLC_Flag.Value = (short)4;
  11808. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  11809. string str = ex.StackTrace;
  11810. AddMessage_Station(stationNameStr, LogType.Error,
  11811. $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11812. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11813. }
  11814. stopwatch1.Stop();
  11815. AddMessage(LogType.Info,
  11816. stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  11817. stopwatch2.ElapsedMilliseconds + "ms");
  11818. }
  11819. // 上次采集到的SN
  11820. //private string sn_S4_4出站接口 = string.Empty;
  11821. /// <summary>
  11822. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  11823. /// </summary>
  11824. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  11825. {
  11826. Stopwatch stopwatch1 = new Stopwatch();
  11827. Stopwatch stopwatch2 = new Stopwatch();
  11828. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  11829. string stationNameStr = stationCode + stationName;
  11830. string processItem = stationName; // 测试项目
  11831. try
  11832. {
  11833. stopwatch1.Start();
  11834. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  11835. //string batch_num = GlobalContext.BatchNumber; // 批次号
  11836. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  11837. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  11838. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  11839. sn = sn.Replace("\0", "");
  11840. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  11841. bool isPass = d4Result == 1; // 产品结果 bool
  11842. #region 查询15个载具码
  11843. List<string> vehicleCodes = new List<string>(); // 15个载具码
  11844. string vehicleData = string.Empty;
  11845. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  11846. if (string.IsNullOrEmpty(vehicleData))
  11847. vehicleData = "";
  11848. if (snResult1 != 0)
  11849. {
  11850. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11851. writeToPLC_Flag1.Name = "d4MES_FLAG";
  11852. writeToPLC_Flag1.Adress = 2496;
  11853. writeToPLC_Flag1.Value = (short)4;
  11854. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  11855. stopwatch1.Stop();
  11856. AddMessage(LogType.Info,
  11857. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11858. return;
  11859. }
  11860. string[] cavitySNs = vehicleData.Split('.');
  11861. if (cavitySNs != null && cavitySNs.Length > 0)
  11862. {
  11863. for (int i = 0; i < cavitySNs.Length; i++)
  11864. {
  11865. if (string.IsNullOrEmpty(cavitySNs[i]))
  11866. vehicleCodes.Add("");
  11867. else
  11868. vehicleCodes.Add(cavitySNs[i]);
  11869. }
  11870. }
  11871. #endregion 查询15个载具码
  11872. // 统一查 产品SN列表
  11873. List<string> partNos = new List<string>();
  11874. foreach (string vehicleCode in vehicleCodes)
  11875. {
  11876. if (string.IsNullOrEmpty(vehicleCode))
  11877. partNos.Add("");
  11878. else
  11879. {
  11880. string partNo = "";
  11881. #region 查询载具上的产品信息
  11882. string cavityData = string.Empty;
  11883. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  11884. if (string.IsNullOrEmpty(cavityData))
  11885. cavityData = "";
  11886. if (snResult != 0)
  11887. {
  11888. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11889. writeToPLC_Flag1.Name = "d4MES_FLAG";
  11890. writeToPLC_Flag1.Adress = 2496;
  11891. writeToPLC_Flag1.Value = (short)4;
  11892. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  11893. stopwatch1.Stop();
  11894. AddMessage(LogType.Info,
  11895. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  11896. "ms");
  11897. return;
  11898. }
  11899. string[] partSNs = cavityData.Split('.');
  11900. if (partSNs != null && partSNs.Length >= 1)
  11901. partNo = partSNs[0];
  11902. #endregion 查询载具上的产品信息
  11903. partNos.Add(partNo);
  11904. }
  11905. }
  11906. // 调用MES出站
  11907. stopwatch2.Start();
  11908. // 统一上传
  11909. List<int> results = new List<int>();
  11910. for (int i = 0; i < partNos.Count; i++)
  11911. {
  11912. string index = (i + 1).ToString(); // 弹夹穴号
  11913. if (string.IsNullOrEmpty(partNos[i]))
  11914. results.Add(1);
  11915. else
  11916. {
  11917. List<TestItem> items1 = new List<TestItem>();
  11918. items1.Add(new TestItem()
  11919. {
  11920. Parameter_name = "弹夹码",
  11921. Parameter_value = sn,
  11922. Parameter_unit = ""
  11923. });
  11924. items1.Add(new TestItem()
  11925. {
  11926. Parameter_name = "弹夹穴号",
  11927. Parameter_value = index,
  11928. Parameter_unit = ""
  11929. });
  11930. items1.Add(new TestItem()
  11931. {
  11932. Parameter_name = "载具码",
  11933. Parameter_value = vehicleCodes[i],
  11934. Parameter_unit = ""
  11935. });
  11936. items1.Add(new TestItem()
  11937. {
  11938. Parameter_name = "载具穴号",
  11939. Parameter_value = "1",
  11940. Parameter_unit = ""
  11941. });
  11942. items1.Add(new TestItem()
  11943. {
  11944. Parameter_name = "产品结果",
  11945. Parameter_value = d4Result == 1 ? "OK" : "NG",
  11946. Parameter_unit = ""
  11947. });
  11948. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  11949. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  11950. results.Add(result1);
  11951. }
  11952. }
  11953. short result = 0;
  11954. if (results.All(a => a == 1))
  11955. result = 1;
  11956. else if (results.Contains(3))
  11957. result = 3;
  11958. else if (results.Contains(2))
  11959. result = 2;
  11960. else if (results.Contains(4))
  11961. result = 4;
  11962. else
  11963. result = 4;
  11964. stopwatch2.Stop();
  11965. // MES_Flag 为4MES报错
  11966. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11967. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11968. writeToPLC_Flag.Name = "d4MES_FLAG";
  11969. writeToPLC_Flag.Adress = 2496;
  11970. writeToPLC_Flag.Value = result;
  11971. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  11972. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  11973. }
  11974. catch (Exception ex)
  11975. {
  11976. stopwatch2.Restart();
  11977. // MES_Flag 为4上位机报错
  11978. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  11979. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11980. writeToPLC_Flag.Name = "d4MES_FLAG";
  11981. writeToPLC_Flag.Adress = 2496;
  11982. writeToPLC_Flag.Value = (short)4;
  11983. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  11984. string str = ex.StackTrace;
  11985. AddMessage_Station(stationNameStr, LogType.Error,
  11986. $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11987. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11988. stopwatch2.Stop();
  11989. }
  11990. stopwatch1.Stop();
  11991. AddMessage(LogType.Info,
  11992. stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11993. stopwatch2.ElapsedMilliseconds + "ms");
  11994. }
  11995. /// <summary>
  11996. /// [S4] 取放桁架 - S4_5弹夹扫码
  11997. /// </summary>
  11998. /// <param name="plcNo">PLC编号</param>
  11999. /// <param name="stationNameStr">工站全称</param>
  12000. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  12001. {
  12002. Stopwatch stopwatch1 = new Stopwatch();
  12003. Stopwatch stopwatch2 = new Stopwatch();
  12004. try
  12005. {
  12006. stopwatch1.Start();
  12007. // ZS 弹夹扫码
  12008. string d5BulletclipCode = " "; // 扫到的码
  12009. short d5BulletclipScanCode = 2;
  12010. stopwatch2.Start();
  12011. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  12012. //// MES_Flag
  12013. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  12014. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12015. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  12016. writeToPLC_Flag.Adress = 2528;
  12017. writeToPLC_Flag.Value = d5BulletclipScanCode;
  12018. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  12019. {
  12020. Name = "d5BulletclipCode",
  12021. Adress = 2529,
  12022. ValueType = PLCValueType.String,
  12023. ValueTypeStrLength = 20,
  12024. Value = d5BulletclipCode
  12025. });
  12026. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  12027. stopwatch2.Stop();
  12028. }
  12029. catch (Exception ex)
  12030. {
  12031. string str = ex.StackTrace;
  12032. AddMessage_Station(stationNameStr, LogType.Error,
  12033. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  12034. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12035. stopwatch2.Start();
  12036. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  12037. //// MES_Flag
  12038. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  12039. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12040. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  12041. writeToPLC_Flag.Adress = 2528;
  12042. writeToPLC_Flag.Value = (short)6;
  12043. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  12044. {
  12045. Name = "d5BulletclipCode",
  12046. Adress = 2529,
  12047. ValueType = PLCValueType.String,
  12048. ValueTypeStrLength = 20,
  12049. Value = " "
  12050. });
  12051. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  12052. stopwatch2.Stop();
  12053. }
  12054. stopwatch1.Stop();
  12055. AddMessage(LogType.Info,
  12056. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12057. stopwatch2.ElapsedMilliseconds + "ms");
  12058. }
  12059. /// <summary>
  12060. /// [S4] 取放桁架 - S4_5载具扫码
  12061. /// </summary>
  12062. /// <param name="plcNo">PLC编号</param>
  12063. /// <param name="stationNameStr">工站全称</param>
  12064. private void S4_5载具扫码(int plcNo, string stationNameStr)
  12065. {
  12066. Stopwatch stopwatch1 = new Stopwatch();
  12067. Stopwatch stopwatch2 = new Stopwatch();
  12068. try
  12069. {
  12070. stopwatch1.Start();
  12071. // ZS 载具扫码
  12072. string d5VehicleCode = " "; // 扫到的码
  12073. short d5VehicleScanCode = 2;
  12074. #region 进站
  12075. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  12076. {
  12077. // 查产品SN
  12078. #region 查询载具上的产品信息
  12079. string cavityData = string.Empty;
  12080. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  12081. if (string.IsNullOrEmpty(cavityData))
  12082. cavityData = "";
  12083. if (snResult != 0)
  12084. {
  12085. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  12086. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  12087. writeToPLC_Flag1.Adress = 2559;
  12088. writeToPLC_Flag1.Value = (short)6;
  12089. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  12090. {
  12091. Name = "d5VehicleCode",
  12092. Adress = 2560,
  12093. ValueType = PLCValueType.String,
  12094. ValueTypeStrLength = 20,
  12095. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  12096. });
  12097. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  12098. stopwatch1.Stop();
  12099. AddMessage(LogType.Info,
  12100. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  12101. "ms");
  12102. return;
  12103. }
  12104. string[] cavitySNs = cavityData.Split('.');
  12105. string partNo = "";
  12106. if (cavitySNs != null && cavitySNs.Length >= 1)
  12107. {
  12108. partNo = cavitySNs[0];
  12109. }
  12110. #endregion 查询载具上的产品信息
  12111. List<TestItem> item = new List<TestItem>();
  12112. item.Add(new TestItem()
  12113. {
  12114. Parameter_name = "载具码",
  12115. Parameter_value = d5VehicleCode,
  12116. });
  12117. item.Add(new TestItem()
  12118. {
  12119. Parameter_name = "载具穴号",
  12120. Parameter_value = "1",
  12121. });
  12122. stopwatch2.Start();
  12123. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  12124. partNo, item, out string errorMsg);
  12125. stopwatch2.Stop();
  12126. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  12127. }
  12128. #endregion 进站
  12129. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  12130. //// MES_Flag
  12131. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  12132. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12133. writeToPLC_Flag.Name = "d5VehicleScanCode";
  12134. writeToPLC_Flag.Adress = 2559;
  12135. writeToPLC_Flag.Value = d5VehicleScanCode;
  12136. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  12137. {
  12138. Name = "d5VehicleCode",
  12139. Adress = 2560,
  12140. ValueType = PLCValueType.String,
  12141. ValueTypeStrLength = 20,
  12142. Value = d5VehicleCode
  12143. });
  12144. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  12145. }
  12146. catch (Exception ex)
  12147. {
  12148. string str = ex.StackTrace;
  12149. AddMessage_Station(stationNameStr, LogType.Error,
  12150. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  12151. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12152. stopwatch2.Start();
  12153. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  12154. //// MES_Flag
  12155. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  12156. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12157. writeToPLC_Flag.Name = "d5VehicleScanCode";
  12158. writeToPLC_Flag.Adress = 2559;
  12159. writeToPLC_Flag.Value = (short)6;
  12160. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  12161. {
  12162. Name = "d5VehicleCode",
  12163. Adress = 2560,
  12164. ValueType = PLCValueType.String,
  12165. ValueTypeStrLength = 20,
  12166. Value = " "
  12167. });
  12168. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  12169. stopwatch2.Stop();
  12170. }
  12171. stopwatch1.Stop();
  12172. AddMessage(LogType.Info,
  12173. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12174. stopwatch2.ElapsedMilliseconds + "ms");
  12175. }
  12176. // 上次采集到的SN
  12177. //private string sn_S4_5出站接口 = string.Empty;
  12178. /// <summary>
  12179. /// [S4] 取放桁架 - S4_5出站接口
  12180. /// </summary>
  12181. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  12182. {
  12183. Stopwatch stopwatch1 = new Stopwatch();
  12184. Stopwatch stopwatch2 = new Stopwatch();
  12185. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  12186. string stationNameStr = stationCode + stationName;
  12187. string processItem = stationName; // 测试项目
  12188. try
  12189. {
  12190. stopwatch1.Start();
  12191. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  12192. //string batch_num = GlobalContext.BatchNumber; // 批次号
  12193. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  12194. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  12195. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  12196. sn = sn.Replace("\0", "");
  12197. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  12198. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  12199. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  12200. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  12201. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  12202. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  12203. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  12204. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  12205. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  12206. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  12207. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  12208. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  12209. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  12210. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  12211. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  12212. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  12213. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  12214. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  12215. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  12216. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  12217. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  12218. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  12219. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  12220. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  12221. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  12222. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  12223. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  12224. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  12225. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  12226. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  12227. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  12228. bool pass = d5Result == 1;
  12229. // 存 载具SN列表
  12230. List<string> vehicleCodes = new List<string>()
  12231. {
  12232. d5VehicleCode1, d5VehicleCode2, d5VehicleCode3, d5VehicleCode4, d5VehicleCode5,
  12233. d5VehicleCode6, d5VehicleCode7, d5VehicleCode8, d5VehicleCode9, d5VehicleCode10,
  12234. d5VehicleCode11, d5VehicleCode12, d5VehicleCode13, d5VehicleCode14, d5VehicleCode15
  12235. };
  12236. // 统一查 产品SN列表
  12237. List<string> partNos = new List<string>();
  12238. foreach (string vehicleCode in vehicleCodes)
  12239. {
  12240. if (string.IsNullOrEmpty(vehicleCode))
  12241. partNos.Add("");
  12242. else
  12243. {
  12244. string partNo = "";
  12245. #region 查询载具上的产品信息
  12246. string cavityData = string.Empty;
  12247. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  12248. if (string.IsNullOrEmpty(cavityData))
  12249. cavityData = "";
  12250. if (snResult != 0)
  12251. {
  12252. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  12253. writeToPLC_Flag1.Name = "d5MES_FLAG";
  12254. writeToPLC_Flag1.Adress = 2591;
  12255. writeToPLC_Flag1.Value = (short)4;
  12256. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  12257. stopwatch1.Stop();
  12258. AddMessage(LogType.Info,
  12259. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  12260. "ms");
  12261. return;
  12262. }
  12263. string[] cavitySNs = cavityData.Split('.');
  12264. if (cavitySNs != null && cavitySNs.Length >= 1)
  12265. partNo = cavitySNs[0];
  12266. #endregion 查询载具上的产品信息
  12267. partNos.Add(partNo);
  12268. }
  12269. }
  12270. // 统一上传
  12271. stopwatch2.Start();
  12272. List<int> results = new List<int>();
  12273. for (int i = 0; i < partNos.Count; i++)
  12274. {
  12275. string index = (i + 1).ToString(); // 弹夹穴号
  12276. if (string.IsNullOrEmpty(partNos[i]))
  12277. results.Add(1);
  12278. else
  12279. {
  12280. List<TestItem> items1 = new List<TestItem>();
  12281. items1.Add(new TestItem()
  12282. {
  12283. Parameter_name = "弹夹码",
  12284. Parameter_value = sn,
  12285. Parameter_unit = ""
  12286. });
  12287. items1.Add(new TestItem()
  12288. {
  12289. Parameter_name = "弹夹穴号",
  12290. Parameter_value = index,
  12291. Parameter_unit = ""
  12292. });
  12293. items1.Add(new TestItem()
  12294. {
  12295. Parameter_name = "载具码",
  12296. Parameter_value = vehicleCodes[i],
  12297. Parameter_unit = ""
  12298. });
  12299. items1.Add(new TestItem()
  12300. {
  12301. Parameter_name = "载具穴号",
  12302. Parameter_value = "1",
  12303. Parameter_unit = ""
  12304. });
  12305. items1.Add(new TestItem()
  12306. {
  12307. Parameter_name = "产品结果",
  12308. Parameter_value = d5Result == 1 ? "OK" : "NG",
  12309. Parameter_unit = ""
  12310. });
  12311. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  12312. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  12313. results.Add(result1);
  12314. }
  12315. }
  12316. short result = 0;
  12317. if (results.All(a => a == 1))
  12318. result = 1;
  12319. else if (results.Contains(3))
  12320. result = 3;
  12321. else if (results.Contains(2))
  12322. result = 2;
  12323. else if (results.Contains(4))
  12324. result = 4;
  12325. else
  12326. result = 4;
  12327. stopwatch2.Stop();
  12328. #region 存储绑定数据到 边线MES系统中
  12329. if (result == 1)
  12330. {
  12331. // 删除绑定信息
  12332. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  12333. if (resultMesR != 0)
  12334. {
  12335. result = 4;
  12336. AddMessage_Station(stationNameStr, LogType.Error,
  12337. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  12338. }
  12339. }
  12340. #endregion 存储绑定数据到 边线MES系统中
  12341. // MES_Flag 为4MES报错
  12342. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  12343. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12344. writeToPLC_Flag.Name = "d5MES_FLAG";
  12345. writeToPLC_Flag.Adress = 2591;
  12346. writeToPLC_Flag.Value = result;
  12347. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  12348. OnMessage(LogType.Debug,
  12349. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  12350. }
  12351. catch (Exception ex)
  12352. {
  12353. stopwatch2.Restart();
  12354. // MES_Flag 为4上位机报错
  12355. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  12356. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12357. writeToPLC_Flag.Name = "d5MES_FLAG";
  12358. writeToPLC_Flag.Adress = 2591;
  12359. writeToPLC_Flag.Value = (short)4;
  12360. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  12361. stopwatch2.Stop();
  12362. string str = ex.StackTrace;
  12363. AddMessage_Station(stationNameStr, LogType.Error,
  12364. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  12365. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12366. }
  12367. stopwatch1.Stop();
  12368. AddMessage(LogType.Info,
  12369. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  12370. stopwatch2.ElapsedMilliseconds + "ms");
  12371. }
  12372. /// <summary>
  12373. /// [S4] 取放桁架 - S4_5节拍接口
  12374. /// </summary>
  12375. /// <param name="plcNo">PLC编号</param>
  12376. /// <param name="stationNameStr">工站全称</param>
  12377. private void S4_5节拍接口(int plcNo, string stationNameStr)
  12378. {
  12379. Stopwatch stopwatch1 = new Stopwatch();
  12380. Stopwatch stopwatch2 = new Stopwatch();
  12381. string resultStr = string.Empty;
  12382. try
  12383. {
  12384. stopwatch1.Start();
  12385. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  12386. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  12387. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  12388. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  12389. if (!actionBool)
  12390. {
  12391. stopwatch2.Start();
  12392. // MES_Flag
  12393. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  12394. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  12395. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  12396. writeToPLC_Flag1.Adress = 2924;
  12397. writeToPLC_Flag1.Value = (short)4;
  12398. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  12399. stopwatch2.Stop();
  12400. AddMessage(LogType.Info,
  12401. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  12402. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  12403. return;
  12404. }
  12405. string d5OEEPartNo = string.Empty; // 物料码
  12406. if (string.IsNullOrEmpty(d5OEEProductSN))
  12407. {
  12408. stopwatch2.Start();
  12409. // MES_Flag
  12410. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  12411. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  12412. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  12413. writeToPLC_Flag1.Adress = 2924;
  12414. writeToPLC_Flag1.Value = (short)1;
  12415. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  12416. stopwatch2.Stop();
  12417. AddMessage(LogType.Info,
  12418. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12419. stopwatch2.ElapsedMilliseconds + "ms");
  12420. return;
  12421. }
  12422. else
  12423. {
  12424. // 查产品SN
  12425. d5OEEPartNo = "Test"; // ZS
  12426. }
  12427. short d5OEEMES_FLAG = 0;
  12428. // 上传OEE
  12429. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  12430. d5OEEMES_FLAG = result.Item1;
  12431. resultStr = result.Item2;
  12432. stopwatch2.Start();
  12433. // MES_Flag
  12434. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  12435. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12436. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  12437. writeToPLC_Flag.Adress = 2924;
  12438. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  12439. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  12440. stopwatch2.Stop();
  12441. }
  12442. catch (Exception ex)
  12443. {
  12444. string str = ex.StackTrace;
  12445. AddMessage_Station(stationNameStr, LogType.Error,
  12446. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  12447. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12448. // MES_Flag
  12449. stopwatch2.Start();
  12450. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  12451. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12452. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  12453. writeToPLC_Flag.Adress = 2924;
  12454. writeToPLC_Flag.Value = (short)4;
  12455. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  12456. stopwatch2.Stop();
  12457. }
  12458. stopwatch1.Stop();
  12459. AddMessage(LogType.Info,
  12460. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12461. stopwatch2.ElapsedMilliseconds + "ms");
  12462. }
  12463. #endregion [S4] 取放桁架
  12464. #endregion PLC4 刘果段
  12465. #region PLC5 张超凡
  12466. #region [S5] Tray盘下料装备
  12467. /// <summary>
  12468. /// S5工位的数据- 触发信号上次的值
  12469. /// </summary>
  12470. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  12471. /// <summary>
  12472. /// S5工位的数据(含触发信号)
  12473. /// </summary>
  12474. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  12475. /// <summary>
  12476. /// S5工位的数据- 回写点位
  12477. /// </summary>
  12478. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  12479. /// <summary>
  12480. /// [S5] Tray盘下料装备
  12481. /// </summary>
  12482. /// <param name="plcNo">PLC编号</param>
  12483. //private void ReadStation_S5(int plcNo)
  12484. //{
  12485. // // [S1] Tray盘上料装备
  12486. // // [S2] FCT
  12487. // // [S3] 值板机
  12488. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  12489. // // [S5] Tray盘下料装备
  12490. // /// 上位机心跳
  12491. // /// 获取设备报警数据与状态信息
  12492. // string stationCode = "[S5]";
  12493. // string stationName = "Tray盘下料装备";
  12494. // string stationNameStr = stationCode + stationName;
  12495. // #region 创建字典
  12496. // // 触发信号字典 赋值
  12497. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  12498. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  12499. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  12500. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  12501. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  12502. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  12503. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  12504. // // PLC数据字典 赋值
  12505. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  12506. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  12507. // s5PLCData.Add("e1ProductSN_Check", ""); //
  12508. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  12509. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  12510. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  12511. // s5PLCData.Add("e1PartNo", ""); // 物料码
  12512. // s5PLCData.Add("e1Result", 0); // 产品结果
  12513. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  12514. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  12515. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  12516. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  12517. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  12518. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  12519. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  12520. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  12521. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  12522. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  12523. // #endregion 创建字典
  12524. // while (IsRun)
  12525. // {
  12526. // try
  12527. // {
  12528. // if (!GlobalContext._IsCon_Funs5)
  12529. // {
  12530. // UpdatePLCMonitor(1, plcNo, 0);
  12531. // continue;
  12532. // }
  12533. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  12534. // {
  12535. // Stopwatch stopwatch1 = new Stopwatch();
  12536. // Stopwatch stopwatch2 = new Stopwatch();
  12537. // stopwatch1.Start();
  12538. // stopwatch2.Start();
  12539. // #region 一次性读取所有数据
  12540. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  12541. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  12542. // int[] datas = data1.Concat(data2).ToArray();
  12543. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  12544. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  12545. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  12546. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  12547. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  12548. // s5PLCData["e1MES_FLAG"] = datas[35];
  12549. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  12550. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  12551. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  12552. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  12553. // s5PLCData["e1Result"] = datas[76];
  12554. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  12555. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  12556. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  12557. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  12558. // s5PLCData["e1OEEType"] = datas[109];
  12559. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  12560. // s5PLCData["e1AGVUpStart"] = datas[121];
  12561. // s5PLCData["e1AGVUpEnd"] = datas[122];
  12562. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  12563. // s5PLCData["e1AGVDownStart"] = datas[134];
  12564. // s5PLCData["e1AGVDownEnd"] = datas[135];
  12565. // #endregion 一次性读取所有数据
  12566. // stopwatch2.Stop();
  12567. // #region 回写操作,写后清空flag
  12568. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  12569. // #endregion 回写操作,写后清空flag
  12570. // #region 进站校验
  12571. // try
  12572. // {
  12573. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  12574. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  12575. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  12576. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  12577. // {
  12578. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  12579. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  12580. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  12581. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  12582. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  12583. // }
  12584. // }
  12585. // catch (Exception ex)
  12586. // {
  12587. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  12588. // string str = ex.StackTrace;
  12589. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12590. // }
  12591. // #endregion 进站校验
  12592. // #region 出站接口
  12593. // try
  12594. // {
  12595. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  12596. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  12597. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  12598. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  12599. // {
  12600. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  12601. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  12602. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  12603. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  12604. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  12605. // }
  12606. // }
  12607. // catch (Exception ex)
  12608. // {
  12609. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  12610. // string str = ex.StackTrace;
  12611. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12612. // }
  12613. // #endregion 出站接口
  12614. // #region 节拍接口
  12615. // try
  12616. // {
  12617. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  12618. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  12619. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  12620. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  12621. // {
  12622. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  12623. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  12624. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  12625. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  12626. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  12627. // }
  12628. // }
  12629. // catch (Exception ex)
  12630. // {
  12631. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  12632. // string str = ex.StackTrace;
  12633. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12634. // }
  12635. // #endregion 节拍接口
  12636. // #region AGV上料
  12637. // // AGV上料叫AGV信号
  12638. // try
  12639. // {
  12640. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  12641. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  12642. // if (e1AGVUpCall != e1AGVUpCallOld)
  12643. // {
  12644. // if (e1AGVUpCall == 1) // 0->1
  12645. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  12646. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  12647. // }
  12648. // }
  12649. // catch (Exception ex)
  12650. // {
  12651. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  12652. // string str = ex.StackTrace;
  12653. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12654. // }
  12655. // // AGV上料完成信号
  12656. // try
  12657. // {
  12658. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  12659. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  12660. // if (e1AGVUpEnd != e1AGVUpEndOld)
  12661. // {
  12662. // if (e1AGVUpEnd == 1) // 0->1
  12663. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  12664. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  12665. // }
  12666. // }
  12667. // catch (Exception ex)
  12668. // {
  12669. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  12670. // string str = ex.StackTrace;
  12671. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12672. // }
  12673. // #endregion AGV上料
  12674. // #region AGV下料
  12675. // // AGV下料叫agv信号
  12676. // try
  12677. // {
  12678. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  12679. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  12680. // if (e1AGVDownCall != e1AGVDownCallOld)
  12681. // {
  12682. // if (e1AGVDownCall == 1) // 0->1
  12683. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  12684. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  12685. // }
  12686. // }
  12687. // catch (Exception ex)
  12688. // {
  12689. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  12690. // string str = ex.StackTrace;
  12691. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12692. // }
  12693. // // AGV下料完成信号
  12694. // try
  12695. // {
  12696. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  12697. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  12698. // if (e1AGVDownEnd != e1AGVDownEndOld)
  12699. // {
  12700. // if (e1AGVDownEnd == 1) // 0->1
  12701. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  12702. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  12703. // }
  12704. // }
  12705. // catch (Exception ex)
  12706. // {
  12707. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  12708. // string str = ex.StackTrace;
  12709. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12710. // }
  12711. // #endregion AGV下料
  12712. // #region 心跳
  12713. // try
  12714. // {
  12715. // short states = 0;
  12716. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  12717. // }
  12718. // catch (Exception ex)
  12719. // {
  12720. // string str = ex.StackTrace;
  12721. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12722. // }
  12723. // #endregion 心跳
  12724. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  12725. // stopwatch1.Stop();
  12726. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  12727. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  12728. // }
  12729. // else
  12730. // {
  12731. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  12732. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  12733. // Funs[plcNo].Connect();
  12734. // }
  12735. // }
  12736. // catch (Exception ex)
  12737. // {
  12738. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  12739. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  12740. // Funs[plcNo].ReConnect();
  12741. // }
  12742. // Thread.Sleep(IntervalReadPLC);
  12743. // }
  12744. //}
  12745. /// <summary>
  12746. /// [S5] Tray盘下料装备 - 进站校验
  12747. /// </summary>
  12748. /// <param name="plcNo">PLC编号</param>
  12749. /// <param name="stationNameStr">工站全称</param>
  12750. private void S5进站校验(int plcNo, string stationNameStr)
  12751. {
  12752. Stopwatch stopwatch1 = new Stopwatch();
  12753. Stopwatch stopwatch2 = new Stopwatch();
  12754. try
  12755. {
  12756. stopwatch1.Start();
  12757. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  12758. sn = sn.Replace("\0", "");
  12759. // 获取产品SN By 载具码
  12760. #region 查询载具上的产品信息
  12761. string cavityData = string.Empty;
  12762. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  12763. if (string.IsNullOrEmpty(cavityData))
  12764. cavityData = "";
  12765. if (snResult != 0)
  12766. {
  12767. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  12768. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  12769. writeToPLC_Flag1.Adress = 2003;
  12770. writeToPLC_Flag1.Value = (short)6;
  12771. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  12772. stopwatch1.Stop();
  12773. AddMessage(LogType.Info,
  12774. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  12775. return;
  12776. }
  12777. string[] cavitySNs = cavityData.Split('.');
  12778. string partNo = string.Empty;
  12779. if (cavitySNs != null && cavitySNs.Length >= 1)
  12780. partNo = cavitySNs[0];
  12781. #endregion 查询载具上的产品信息
  12782. // 产品SN(物料码)校验
  12783. List<TestItem> item = new List<TestItem>();
  12784. item.Add(new TestItem()
  12785. {
  12786. Parameter_name = "载具码",
  12787. Parameter_value = sn,
  12788. });
  12789. item.Add(new TestItem()
  12790. {
  12791. Parameter_name = "载具穴号",
  12792. Parameter_value = "1",
  12793. });
  12794. stopwatch2.Start();
  12795. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  12796. partNo, item, out string errorMsg);
  12797. stopwatch2.Stop();
  12798. short e1MES_FLAG_Check = (short)result;
  12799. // MES_Flag
  12800. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  12801. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12802. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  12803. writeToPLC_Flag.Adress = 2003;
  12804. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  12805. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  12806. }
  12807. catch (Exception ex)
  12808. {
  12809. string str = ex.StackTrace;
  12810. AddMessage_Station(stationNameStr, LogType.Error,
  12811. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  12812. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12813. // MES_Flag
  12814. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  12815. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12816. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  12817. writeToPLC_Flag.Adress = 2003;
  12818. writeToPLC_Flag.Value = (short)6;
  12819. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  12820. }
  12821. stopwatch1.Stop();
  12822. AddMessage(LogType.Info,
  12823. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  12824. stopwatch2.ElapsedMilliseconds + "ms");
  12825. }
  12826. /// <summary>
  12827. /// [S5] Tray盘下料装备 - 出站接口
  12828. /// </summary>
  12829. /// <param name="plcNo"></param>
  12830. /// <param name="stationCode"></param>
  12831. /// <param name="stationName"></param>
  12832. private void S5出站接口(int plcNo, string stationCode, string stationName)
  12833. {
  12834. Stopwatch stopwatch1 = new Stopwatch();
  12835. Stopwatch stopwatch2 = new Stopwatch();
  12836. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  12837. string stationNameStr = stationCode + stationName;
  12838. string processItem = stationName; // 测试项目
  12839. try
  12840. {
  12841. stopwatch1.Start();
  12842. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  12843. //string batch_num = GlobalContext.BatchNumber; // 批次号
  12844. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  12845. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  12846. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  12847. sn = sn.Replace("\0", "");
  12848. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  12849. //partNo = partNo.Replace("\0", "");
  12850. #region 查询载具上的产品信息
  12851. string cavityData = string.Empty;
  12852. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  12853. if (string.IsNullOrEmpty(cavityData))
  12854. cavityData = "";
  12855. if (snResult != 0)
  12856. {
  12857. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  12858. writeToPLC_Flag1.Name = "e1MES_FLAG";
  12859. writeToPLC_Flag1.Adress = 2035;
  12860. writeToPLC_Flag1.Value = (short)4;
  12861. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  12862. stopwatch1.Stop();
  12863. AddMessage(LogType.Info,
  12864. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  12865. return;
  12866. }
  12867. string[] cavitySNs = cavityData.Split('.');
  12868. string partNo = string.Empty;
  12869. if (cavitySNs != null && cavitySNs.Length >= 1)
  12870. partNo = cavitySNs[0];
  12871. #endregion 查询载具上的产品信息
  12872. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  12873. bool pass = e1Result == 1;
  12874. stopwatch2.Start();
  12875. // 上传MES
  12876. List<TestItem> items = new List<TestItem>();
  12877. items.Add(new TestItem()
  12878. {
  12879. Parameter_name = "载具码",
  12880. Parameter_value = sn,
  12881. Parameter_unit = ""
  12882. });
  12883. items.Add(new TestItem()
  12884. {
  12885. Parameter_name = "载具穴号",
  12886. Parameter_value = "1",
  12887. Parameter_unit = ""
  12888. });
  12889. items.Add(new TestItem()
  12890. {
  12891. Parameter_name = "产品结果",
  12892. Parameter_value = e1Result == 1 ? "OK" : "NG",
  12893. Parameter_unit = ""
  12894. });
  12895. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  12896. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  12897. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  12898. short result = result1 == 1 ? (short)1 : (short)3;
  12899. stopwatch2.Stop();
  12900. #region 存储绑定数据到 边线MES系统中
  12901. if (result == 1)
  12902. {
  12903. // 删除绑定信息
  12904. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  12905. if (resultMesR != 0)
  12906. {
  12907. result = 4;
  12908. AddMessage_Station(stationNameStr, LogType.Error,
  12909. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  12910. }
  12911. }
  12912. #endregion 存储绑定数据到 边线MES系统中
  12913. // MES_Flag 为MES报错
  12914. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  12915. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  12916. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12917. writeToPLC_Flag.Name = "e1MES_FLAG";
  12918. writeToPLC_Flag.Adress = 2035;
  12919. writeToPLC_Flag.Value = result;
  12920. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  12921. OnMessage(LogType.Debug,
  12922. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  12923. }
  12924. catch (Exception ex)
  12925. {
  12926. stopwatch2.Restart();
  12927. // MES_Flag 为4上位机报错
  12928. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  12929. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12930. writeToPLC_Flag.Name = "e1MES_FLAG";
  12931. writeToPLC_Flag.Adress = 2035;
  12932. writeToPLC_Flag.Value = (short)4;
  12933. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  12934. stopwatch2.Stop();
  12935. string str = ex.StackTrace;
  12936. AddMessage_Station(stationNameStr, LogType.Error,
  12937. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  12938. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12939. }
  12940. stopwatch1.Stop();
  12941. AddMessage(LogType.Info,
  12942. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  12943. stopwatch2.ElapsedMilliseconds + "ms");
  12944. }
  12945. /// <summary>
  12946. /// [S5] Tray盘下料装备 - 节拍接口
  12947. /// </summary>
  12948. /// <param name="plcNo">PLC编号</param>
  12949. /// <param name="stationNameStr">工站全称</param>
  12950. //private void S5节拍接口(int plcNo, string stationNameStr)
  12951. //{
  12952. // Stopwatch stopwatch1 = new Stopwatch();
  12953. // Stopwatch stopwatch2 = new Stopwatch();
  12954. // string resultStr = string.Empty;
  12955. // try
  12956. // {
  12957. // stopwatch1.Start();
  12958. // string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  12959. // string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  12960. // e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  12961. // bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  12962. // if (!actionBool)
  12963. // {
  12964. // stopwatch2.Start();
  12965. // // MES_Flag
  12966. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  12967. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  12968. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  12969. // writeToPLC_Flag1.Adress = 2088;
  12970. // writeToPLC_Flag1.Value = (short)4;
  12971. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  12972. // stopwatch2.Stop();
  12973. // AddMessage(LogType.Info,
  12974. // stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  12975. // "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  12976. // return;
  12977. // }
  12978. // string e1OEEPartNo = string.Empty; // 物料码
  12979. // if (string.IsNullOrEmpty(e1OEEProductSN))
  12980. // {
  12981. // stopwatch2.Start();
  12982. // // MES_Flag
  12983. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  12984. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  12985. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  12986. // writeToPLC_Flag1.Adress = 2088;
  12987. // writeToPLC_Flag1.Value = (short)1;
  12988. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  12989. // stopwatch2.Stop();
  12990. // AddMessage(LogType.Info,
  12991. // stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12992. // stopwatch2.ElapsedMilliseconds + "ms");
  12993. // return;
  12994. // }
  12995. // else
  12996. // {
  12997. // // 查产品SN
  12998. // e1OEEPartNo = "Test"; // ZS
  12999. // }
  13000. // short e1OEEMES_FLAG = 0;
  13001. // // 上传OEE
  13002. // (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  13003. // e1OEEMES_FLAG = result.Item1;
  13004. // resultStr = result.Item2;
  13005. // stopwatch2.Start();
  13006. // // MES_Flag
  13007. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  13008. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  13009. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  13010. // writeToPLC_Flag.Adress = 2088;
  13011. // writeToPLC_Flag.Value = e1OEEMES_FLAG;
  13012. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  13013. // stopwatch2.Stop();
  13014. // }
  13015. // catch (Exception ex)
  13016. // {
  13017. // string str = ex.StackTrace;
  13018. // AddMessage_Station(stationNameStr, LogType.Error,
  13019. // $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  13020. // str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  13021. // // MES_Flag
  13022. // stopwatch2.Start();
  13023. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  13024. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  13025. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  13026. // writeToPLC_Flag.Adress = 2088;
  13027. // writeToPLC_Flag.Value = (short)4;
  13028. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  13029. // stopwatch2.Stop();
  13030. // }
  13031. // stopwatch1.Stop();
  13032. // AddMessage(LogType.Info,
  13033. // stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  13034. // stopwatch2.ElapsedMilliseconds + "ms");
  13035. //}
  13036. /// <summary>
  13037. /// [S5] Tray盘下料装备 - AGV上料叫agv
  13038. /// </summary>
  13039. /// <param name="plcNo">PLC编号</param>
  13040. /// <param name="stationNameStr">工站全称</param>
  13041. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  13042. {
  13043. Stopwatch stopwatch1 = new Stopwatch();
  13044. Stopwatch stopwatch2 = new Stopwatch();
  13045. try
  13046. {
  13047. stopwatch1.Start();
  13048. // ZS 呼叫AGV
  13049. short e1AGVUpCall = 2;
  13050. stopwatch2.Start();
  13051. // e1AGVUpCall
  13052. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  13053. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  13054. writeToPLC_Flag.Name = "e1AGVUpCall";
  13055. writeToPLC_Flag.Adress = 2120;
  13056. writeToPLC_Flag.Value = e1AGVUpCall;
  13057. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  13058. stopwatch2.Stop();
  13059. }
  13060. catch (Exception ex)
  13061. {
  13062. string str = ex.StackTrace;
  13063. AddMessage_Station(stationNameStr, LogType.Error,
  13064. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  13065. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  13066. // e1AGVUpCall
  13067. stopwatch2.Start();
  13068. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  13069. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  13070. writeToPLC_Flag.Name = "e1AGVUpCall";
  13071. writeToPLC_Flag.Adress = 2120;
  13072. writeToPLC_Flag.Value = (short)4;
  13073. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  13074. stopwatch2.Stop();
  13075. }
  13076. stopwatch1.Stop();
  13077. AddMessage(LogType.Info,
  13078. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  13079. stopwatch2.ElapsedMilliseconds + "ms");
  13080. }
  13081. /// <summary>
  13082. /// [S5] Tray盘下料装备 - AGV上料完成
  13083. /// </summary>
  13084. /// <param name="plcNo">PLC编号</param>
  13085. /// <param name="stationNameStr">工站全称</param>
  13086. private void S5AGV上料完成(int plcNo, string stationNameStr)
  13087. {
  13088. Stopwatch stopwatch1 = new Stopwatch();
  13089. Stopwatch stopwatch2 = new Stopwatch();
  13090. try
  13091. {
  13092. stopwatch1.Start();
  13093. // ZS AGV上料完成,让小车离开
  13094. short e1AGVUpEnd = 2;
  13095. stopwatch2.Start();
  13096. // e1AGVUpEnd
  13097. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  13098. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  13099. writeToPLC_Flag.Name = "e1AGVUpEnd";
  13100. writeToPLC_Flag.Adress = 2122;
  13101. writeToPLC_Flag.Value = e1AGVUpEnd;
  13102. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  13103. stopwatch2.Stop();
  13104. }
  13105. catch (Exception ex)
  13106. {
  13107. string str = ex.StackTrace;
  13108. AddMessage_Station(stationNameStr, LogType.Error,
  13109. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  13110. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  13111. // e1AGVUpEnd
  13112. stopwatch2.Start();
  13113. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  13114. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  13115. writeToPLC_Flag.Name = "e1AGVUpEnd";
  13116. writeToPLC_Flag.Adress = 2122;
  13117. writeToPLC_Flag.Value = (short)4;
  13118. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  13119. stopwatch2.Stop();
  13120. }
  13121. stopwatch1.Stop();
  13122. AddMessage(LogType.Info,
  13123. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  13124. stopwatch2.ElapsedMilliseconds + "ms");
  13125. }
  13126. /// <summary>
  13127. /// [S5] Tray盘下料装备 - AGV下料叫agv
  13128. /// </summary>
  13129. /// <param name="plcNo">PLC编号</param>
  13130. /// <param name="stationNameStr">工站全称</param>
  13131. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  13132. {
  13133. Stopwatch stopwatch1 = new Stopwatch();
  13134. Stopwatch stopwatch2 = new Stopwatch();
  13135. try
  13136. {
  13137. stopwatch1.Start();
  13138. // ZS 呼叫AGV
  13139. short e1AGVDownCall = 2;
  13140. stopwatch2.Start();
  13141. // e1AGVDownCall
  13142. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  13143. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  13144. writeToPLC_Flag.Name = "e1AGVDownCall";
  13145. writeToPLC_Flag.Adress = 2133;
  13146. writeToPLC_Flag.Value = e1AGVDownCall;
  13147. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  13148. stopwatch2.Stop();
  13149. }
  13150. catch (Exception ex)
  13151. {
  13152. string str = ex.StackTrace;
  13153. AddMessage_Station(stationNameStr, LogType.Error,
  13154. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  13155. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  13156. // e1AGVDownCall
  13157. stopwatch2.Start();
  13158. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  13159. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  13160. writeToPLC_Flag.Name = "e1AGVDownCall";
  13161. writeToPLC_Flag.Adress = 2133;
  13162. writeToPLC_Flag.Value = (short)4;
  13163. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  13164. stopwatch2.Stop();
  13165. }
  13166. stopwatch1.Stop();
  13167. AddMessage(LogType.Info,
  13168. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  13169. stopwatch2.ElapsedMilliseconds + "ms");
  13170. }
  13171. /// <summary>
  13172. /// [S5] Tray盘下料装备 - AGV下料完成
  13173. /// </summary>
  13174. /// <param name="plcNo">PLC编号</param>
  13175. /// <param name="stationNameStr">工站全称</param>
  13176. private void S5AGV下料完成(int plcNo, string stationNameStr)
  13177. {
  13178. Stopwatch stopwatch1 = new Stopwatch();
  13179. Stopwatch stopwatch2 = new Stopwatch();
  13180. try
  13181. {
  13182. stopwatch1.Start();
  13183. // ZS AGV上料完成,让小车离开
  13184. short e1AGVDownEnd = 2;
  13185. stopwatch2.Start();
  13186. // e1AGVDownEnd
  13187. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  13188. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  13189. writeToPLC_Flag.Name = "e1AGVDownEnd";
  13190. writeToPLC_Flag.Adress = 2135;
  13191. writeToPLC_Flag.Value = e1AGVDownEnd;
  13192. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  13193. stopwatch2.Stop();
  13194. }
  13195. catch (Exception ex)
  13196. {
  13197. string str = ex.StackTrace;
  13198. AddMessage_Station(stationNameStr, LogType.Error,
  13199. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  13200. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  13201. // e1AGVDownEnd
  13202. stopwatch2.Start();
  13203. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  13204. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  13205. writeToPLC_Flag.Name = "e1AGVDownEnd";
  13206. writeToPLC_Flag.Adress = 2135;
  13207. writeToPLC_Flag.Value = (short)4;
  13208. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  13209. stopwatch2.Stop();
  13210. }
  13211. stopwatch1.Stop();
  13212. AddMessage(LogType.Info,
  13213. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  13214. stopwatch2.ElapsedMilliseconds + "ms");
  13215. }
  13216. #endregion [S5] Tray盘下料装备
  13217. #endregion PLC5 张超凡
  13218. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  13219. /// <summary>
  13220. /// PLC读取到的数据 -添加数据
  13221. /// </summary>
  13222. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  13223. {
  13224. if (sxPlcData.ContainsKey(newKey))
  13225. sxPlcData[newKey] = newValue;
  13226. else
  13227. sxPlcData.Add(newKey, newValue);
  13228. }
  13229. /// <summary>
  13230. /// PLC需要写入的数据 -添加数据
  13231. /// </summary>
  13232. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey,
  13233. WriteToPLC_Flag newValue)
  13234. {
  13235. if (sxPLCWriteData.ContainsKey(newKey))
  13236. sxPLCWriteData[newKey] = newValue;
  13237. else
  13238. sxPLCWriteData.Add(newKey, newValue);
  13239. }
  13240. /// <summary>
  13241. /// PLC回写操作,写后清空flag
  13242. /// </summary>
  13243. /// <param name="modbusClient">modbus对象</param>
  13244. /// <param name="pLCReadDatas">读取到的数据字典</param>
  13245. /// <param name="pLCWriteDatas">需要写入的数据</param>
  13246. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas,
  13247. ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  13248. {
  13249. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  13250. {
  13251. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  13252. for (int i = 0; i < pLCWriteDatas.Count; i++)
  13253. {
  13254. string mesFlagName = pLCWriteDatas[i].Name;
  13255. int mesFlagAdress = pLCWriteDatas[i].Adress;
  13256. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  13257. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  13258. {
  13259. // 先回写数据
  13260. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  13261. for (int j = 0; j < writeToPLCDatas.Count; j++)
  13262. {
  13263. int mesDataAdress = writeToPLCDatas[j].Adress;
  13264. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  13265. switch (mesDataType)
  13266. {
  13267. case PLCValueType.Short:
  13268. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  13269. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  13270. break;
  13271. case PLCValueType.String:
  13272. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  13273. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  13274. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr,
  13275. mesDataValueStrLength);
  13276. break;
  13277. }
  13278. }
  13279. // 再回写信号
  13280. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  13281. // 存储读取数据的字典
  13282. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  13283. // 存储写入数据的字典 - 清空写入值
  13284. pLCWriteDatas[i].Value = (short)0;
  13285. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  13286. }
  13287. }
  13288. }
  13289. }
  13290. /// <summary>
  13291. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  13292. /// </summary>
  13293. /// <param name="no">3</param>
  13294. /// <param name="stationCode">设备编号</param>
  13295. /// <param name="stationNameStr">设备名称</param>
  13296. /// <param name="plcOrder">车间订单号</param>
  13297. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  13298. {
  13299. try
  13300. {
  13301. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  13302. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  13303. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  13304. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  13305. int result1 = 0;
  13306. switch (stationCode)
  13307. {
  13308. case 2:
  13309. case 3:
  13310. case 4:
  13311. case 6:
  13312. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  13313. break;
  13314. case 102:
  13315. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  13316. break;
  13317. case 103:
  13318. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  13319. break;
  13320. case 104:
  13321. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  13322. break;
  13323. case 106:
  13324. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  13325. break;
  13326. default:
  13327. // MES_Flag 为“6未找到正确设备编号”
  13328. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  13329. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  13330. return;
  13331. }
  13332. short result = result1 == 1 ? (short)1 : (short)2;
  13333. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  13334. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  13335. }
  13336. catch (Exception ex)
  13337. {
  13338. // MES_Flag 为2上位机报错
  13339. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  13340. string str = ex.StackTrace;
  13341. AddMessage_Station(stationNameStr, LogType.Error,
  13342. $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  13343. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  13344. }
  13345. }
  13346. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  13347. #region UI刷新
  13348. /// <summary>
  13349. /// 更新商品信息的UI + 下发产品信息(SN)
  13350. /// </summary>
  13351. private void UpdateProductInfo()
  13352. {
  13353. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  13354. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  13355. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  13356. //txt_CurSupplierCode.Text = ""; // 供应商代号
  13357. }
  13358. /// <summary>
  13359. /// 更新PLC连接状态的UI
  13360. /// </summary>
  13361. /// <param name="no">PLC编号</param>
  13362. /// <param name="status">状态</param>
  13363. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  13364. {
  13365. if (this != null && !this.IsDisposed)
  13366. {
  13367. switch (imgNo)
  13368. {
  13369. case 1:
  13370. this.BeginInvoke(new Action(() => { picPLC.Image = imageListState.Images[status]; }));
  13371. break;
  13372. case 2:
  13373. this.BeginInvoke(new Action(() => { pictureBox2.Image = imageListState.Images[status]; }));
  13374. break;
  13375. case 3:
  13376. this.BeginInvoke(new Action(() => { pictureBox3.Image = imageListState.Images[status]; }));
  13377. break;
  13378. case 4:
  13379. this.BeginInvoke(new Action(() => { pictureBox4.Image = imageListState.Images[status]; }));
  13380. break;
  13381. case 5:
  13382. this.BeginInvoke(new Action(() => { pictureBox5.Image = imageListState.Images[status]; }));
  13383. break;
  13384. case 6:
  13385. this.BeginInvoke(new Action(() => { pictureBox6.Image = imageListState.Images[status]; }));
  13386. break;
  13387. case 7:
  13388. this.BeginInvoke(new Action(() => { pictureBox7.Image = imageListState.Images[status]; }));
  13389. break;
  13390. case 8:
  13391. this.BeginInvoke(new Action(() => { pictureBox8.Image = imageListState.Images[status]; }));
  13392. break;
  13393. default:
  13394. break;
  13395. }
  13396. }
  13397. Task.Run(() => // 更新PLC交互页的指示灯
  13398. {
  13399. try
  13400. {
  13401. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  13402. {
  13403. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  13404. }
  13405. }
  13406. catch
  13407. {
  13408. }
  13409. });
  13410. }
  13411. #endregion UI刷新
  13412. #region 日志
  13413. /// <summary>
  13414. /// 添加各工位运行日志(同步至PLC交互页面)
  13415. /// </summary>
  13416. /// <param name="stationNameStr">工站名称</param>
  13417. /// <param name="logType">日志类型</param>
  13418. /// <param name="message">日志内容</param>
  13419. /// <param name="snNumber">产品数字SN</param>
  13420. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  13421. {
  13422. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")))
  13423. {
  13424. AddMessage(logType, message); // 首页展示+日志记录
  13425. }
  13426. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  13427. {
  13428. StationName = stationNameStr,
  13429. SnNumber = snNumber,
  13430. Message = message,
  13431. CreateTime = DateTime.Now
  13432. };
  13433. // PLC交互页展示
  13434. Task.Run(() =>
  13435. {
  13436. try
  13437. {
  13438. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  13439. {
  13440. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  13441. }
  13442. }
  13443. catch
  13444. {
  13445. }
  13446. });
  13447. }
  13448. /// <summary>
  13449. /// 添加运行日志
  13450. /// </summary>
  13451. /// <param name="logType">日志类型</param>
  13452. /// <param name="message">日志内容</param>
  13453. public void AddMessage(LogType logType, string message)
  13454. {
  13455. OnMessage(logType, message);
  13456. string date = DateTime.Now.ToString("yyyy/MM/dd");
  13457. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  13458. string msgShow = time + "--> " + message + "\r\n";
  13459. this.BeginInvoke(new Action(() =>
  13460. {
  13461. systemLog.Rows.Insert(0, date, time, message);
  13462. if (systemLog.Rows.Count >= 100)
  13463. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  13464. }));
  13465. }
  13466. /// <summary>
  13467. /// 添加运行日志-保存
  13468. /// </summary>
  13469. /// <param name="logType">日志类型</param>
  13470. /// <param name="message">日志内容</param>
  13471. private void OnMessage(LogType logType, string msg)
  13472. {
  13473. MessageEvent?.Invoke(logType, msg);
  13474. }
  13475. /// <summary>
  13476. /// 保存PLC写入日志
  13477. /// </summary>
  13478. /// <param name="logType"></param>
  13479. /// <param name="logValue"></param>
  13480. private void WritePLCLog(LogType logType, string logValue)
  13481. {
  13482. switch ((int)logType)
  13483. {
  13484. case 0:
  13485. _PLCLogNet.WriteDebug(logValue);
  13486. break;
  13487. case 1:
  13488. _PLCLogNet.WriteInfo(logValue);
  13489. break;
  13490. case 2:
  13491. _PLCLogNet.WriteWarn(logValue);
  13492. break;
  13493. case 3:
  13494. _PLCLogNet.WriteError(logValue);
  13495. break;
  13496. default:
  13497. _PLCLogNet.WriteFatal(logValue);
  13498. break;
  13499. }
  13500. }
  13501. /// <summary>
  13502. /// IOT Mqtt回调方法- With DataId
  13503. /// </summary>
  13504. /// <param name="id"></param>
  13505. /// <param name="v"></param>
  13506. /// <param name="dataId"></param>
  13507. public void CallbackWithDataId(string id, string msg, string dataId)
  13508. {
  13509. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  13510. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  13511. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  13512. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  13513. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  13514. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  13515. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  13516. }
  13517. /// <summary>
  13518. /// AGV Mqtt回调方法- 记录Log并处理数据
  13519. /// </summary>
  13520. /// <param name="obj"></param>
  13521. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  13522. {
  13523. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  13524. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  13525. // 接收到的信息
  13526. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  13527. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  13528. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  13529. {
  13530. }
  13531. }
  13532. #endregion 日志
  13533. //private void button1_Click(object sender, EventArgs e)
  13534. //{
  13535. // OpenDailogFalg=true;
  13536. // if (OpenDailogFalg)
  13537. // {
  13538. // using (var dialog = new BandBarodeDialog())
  13539. // {
  13540. // string strCarrierBarcode = "N801A-003";
  13541. // dialog._CarrierBarcode = strCarrierBarcode;
  13542. // string sn = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  13543. // dialog._ProductBarcode = sn;
  13544. // var rs = dialog.ShowDialog();
  13545. // if (rs == DialogResult.OK)
  13546. // {
  13547. // AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  13548. // OpenDailogFalg = false;//关闭扫码
  13549. // }
  13550. // }
  13551. // }
  13552. //}
  13553. }
  13554. }