Form_Home.cs 557 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499
  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. /*
  35. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  36. */
  37. namespace MainForm
  38. {
  39. /// <summary>
  40. /// 记录日志的委托
  41. /// </summary>
  42. /// <param name="logType">日志类型</param>
  43. /// <param name="message">日志信息</param>
  44. public delegate void HomeMessageHandler(LogType logType, string message);
  45. /// <summary>
  46. /// 主页窗体
  47. /// </summary>
  48. public partial class Form_Home : Form
  49. {
  50. #region 常量
  51. //文本常量
  52. private const string Head = "开始采集";
  53. private const string Tail = "采集完成";
  54. private const string Body = "工位出站数据";
  55. private const string BodyCheck = "工位点检数据";
  56. private const string BodyRun = "整线运行数据";
  57. private const string BodyAlarm = "整线报警数据";
  58. #endregion 常量
  59. #region 变量
  60. /// <summary>
  61. /// 委托-记录日志的方法
  62. /// </summary>
  63. public event HomeMessageHandler MessageEvent;
  64. /// <summary>
  65. /// 日志接口
  66. /// </summary>
  67. ILogNet _PLCLogNet;
  68. /// <summary>
  69. /// 用于记录IOT MQTT日志
  70. /// </summary>
  71. ILogNet _IOTMqttLogNet;
  72. /// <summary>
  73. /// 用于记录AGV MQTT日志
  74. /// </summary>
  75. ILogNet _AGVMqttLogNet;
  76. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  77. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  78. // 间隔时间
  79. private int IntervalReadPLC = 300; //ms 读PLC
  80. private int IntervalMonitorMES = 1000; //ms MES心跳
  81. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  82. // 软件状态
  83. private bool IsRun = true;
  84. #region PLC 与 TCP对象
  85. // 定义一个字典,存plc对象(通讯)
  86. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  87. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  88. // 定义TCPClient对象列表
  89. Dictionary<int, HPSocket_TcpClientHelper> _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  90. // 定义MQTTHelper对象
  91. MQTTHelper _MQTTHelper = new MQTTHelper();
  92. #endregion PLC 与 TCP对象
  93. /// <summary>
  94. /// 上次的设备运行信息
  95. /// </summary>
  96. private string lineWorkingData1_OldStr = string.Empty;
  97. /// <summary>
  98. /// 设备报警字典-当前结果
  99. /// Dictionary<工位代码,List<报警信息>>
  100. /// </summary>
  101. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  102. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  103. #endregion 变量
  104. #region 窗体基础事件
  105. /// <summary>
  106. /// 初始化
  107. /// </summary>
  108. public Form_Home()
  109. {
  110. InitializeComponent();
  111. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  112. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  113. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  114. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  115. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  116. }
  117. /// <summary>
  118. /// 窗体加载事件
  119. /// </summary>
  120. private void Form_Home_Load(object sender, EventArgs e)
  121. {
  122. try
  123. {
  124. AddMessage(LogType.Info, "开始初始化程序");
  125. InitalDicAlarm(); // 实例化报警字典
  126. //组建plc对象字典
  127. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  128. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  129. if (GlobalContext.IsUsePLC1)
  130. FunsEip.Add(1, new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  131. //Funs.Add(1, new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort, 2001)); // Tray盘上料装备(板测)
  132. if (GlobalContext.IsUsePLC2)
  133. //Funs.Add(2, new ModbusClientHelper(GlobalContext.Machine2Address, GlobalContext.MachinePort, 2001)); // FCT(板测),
  134. FunsEip.Add(2, new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  135. if (GlobalContext.IsUsePLC3)
  136. FunsEip.Add(3, new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  137. //Funs.Add(3, new ModbusClientHelper(GlobalContext.Machine3Address, GlobalContext.MachinePort, 2001)); // 值板机,
  138. if (GlobalContext.IsUsePLC4)
  139. FunsEip.Add(4, new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  140. //Funs.Add(4, new ModbusClientHelper(GlobalContext.Machine4Address, GlobalContext.MachinePort, 2001)); // 取放桁
  141. if (GlobalContext.IsUsePLC5)
  142. FunsEip.Add(5, new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  143. //Funs.Add(5, new ModbusClientHelper(GlobalContext.Machine5Address, GlobalContext.MachinePort, 2001)); //Tray盘下料装备
  144. if (GlobalContext.IsUsePLC6)
  145. FunsEip.Add(6, new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  146. if (GlobalContext.IsUsePLC7)
  147. FunsEip.Add(7, new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  148. if (GlobalContext.IsUsePLC8)
  149. FunsEip.Add(8, new Inovance_EIP(GlobalContext.PC8Address, GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  150. if (GlobalContext.IsUsePLC9)
  151. FunsEip.Add(9, new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  152. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  153. {
  154. if (plcEIP != null)
  155. {
  156. try
  157. {
  158. (int, string) result = plcEIP.Connect();
  159. }
  160. catch (Exception ex)
  161. {
  162. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  163. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  164. }
  165. }
  166. }
  167. /*
  168. //plc1Alarm.Connect();
  169. foreach (ModbusClientHelper modbusClient in Funs.Values)
  170. {
  171. if (modbusClient != null)
  172. {
  173. try
  174. {
  175. modbusClient.Connect();
  176. }
  177. catch (Exception ex)
  178. {
  179. MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
  180. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  181. }
  182. }
  183. }
  184. */
  185. // 采集任务
  186. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  187. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  188. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  189. if (GlobalContext.IsUsePLC1)
  190. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  191. if (GlobalContext.IsUsePLC2)
  192. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  193. if (GlobalContext.IsUsePLC3)
  194. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  195. if (GlobalContext.IsUsePLC4)
  196. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  197. if (GlobalContext.IsUsePLC5)
  198. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  199. if (GlobalContext.IsUsePLC6)
  200. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  201. if (GlobalContext.IsUsePLC7)
  202. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  203. if (GlobalContext.IsUsePLC8)
  204. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  205. if (GlobalContext.IsUsePLC9)
  206. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  207. #region 初始化
  208. try
  209. {
  210. // 开启边线MES(绑定/查询数据)
  211. //int mesRoute = XiaomiMES_RouteCommunication.Init();
  212. //if (mesRoute == 0)
  213. //{
  214. // //picMESStatus.Image = imageListState.Images[1];
  215. // //GlobalContext.MESIsConnect = true;
  216. // AddMessage(LogType.Info, "小米MES边线初始连接成功!");
  217. //}
  218. //else
  219. //{
  220. // //picMESStatus.Image = imageListState.Images[0];
  221. // //GlobalContext.MESIsConnect = false;
  222. // AddMessage(LogType.Info, $"小米MES边线初始连接失败!");
  223. //}
  224. // 开启MES(Http)
  225. if (GlobalContext.IsUseMES)
  226. {
  227. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  228. if (mesret)
  229. {
  230. picMESStatus.Image = imageListState.Images[1];
  231. GlobalContext.MESIsConnect = true;
  232. AddMessage(LogType.Info, "小米MES初始连接成功!");
  233. }
  234. else
  235. {
  236. picMESStatus.Image = imageListState.Images[0];
  237. GlobalContext.MESIsConnect = false;
  238. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  239. }
  240. }
  241. // 开启IOT(MQTT)
  242. if (GlobalContext.IsUseIot)
  243. {
  244. string addr = GlobalContext.MQTTServerHost;
  245. int port = GlobalContext.MQTTServerPort;
  246. int qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer(addr, port, GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  247. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult;
  248. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  249. {
  250. picIot.Image = imageListState.Images[1];
  251. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  252. XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  253. }
  254. else
  255. {
  256. picIot.Image = imageListState.Images[0];
  257. AddMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  258. }
  259. }
  260. // 开启AGV(Http与MQTT)
  261. if (GlobalContext.IsUseAGV)
  262. {
  263. // AGV HTTP
  264. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  265. if (mesret1)
  266. {
  267. picAgvHttp.Image = imageListState.Images[1];
  268. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  269. }
  270. else
  271. {
  272. picAgvHttp.Image = imageListState.Images[0];
  273. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  274. }
  275. string agvMqttIp = GlobalContext.MQTTServerHost;
  276. int agvMqttPort = GlobalContext.MQTTServerPort;
  277. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  278. ResultData_MQTT result_MQTT = _MQTTHelper.CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  279. // AGV MQTT
  280. if (result_MQTT.ResultCode == 1)
  281. {
  282. picAgvMqtt.Image = imageListState.Images[1];
  283. GlobalContext.AGVMQTTIsConnect = true;
  284. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  285. ResultData_MQTT result = XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  286. AddMessage(LogType.Info, $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  287. }
  288. else
  289. {
  290. picAgvMqtt.Image = imageListState.Images[0];
  291. GlobalContext.AGVMQTTIsConnect = false;
  292. AddMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  293. }
  294. }
  295. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  296. Task.Run(MonitorMESConnect);
  297. // 查询PLC连接状态
  298. foreach (int plcNo in FunsEip.Keys)
  299. {
  300. bool connected = FunsEip[plcNo].IsConnected;
  301. if (connected)
  302. {
  303. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  304. AddMessage(LogType.Info, msg);
  305. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  306. }
  307. else
  308. {
  309. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  310. AddMessage(LogType.Info, msg);
  311. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  312. }
  313. }
  314. // PLC4时 初始化扫码器TCP
  315. //if (GlobalContext.IsUsePLC4)
  316. // HpTCPClientInit();
  317. // 开启PLC的业务处理线程-监听PLC点位+状态
  318. foreach (Task task in TaskReadProcess)
  319. {
  320. if (task != null)
  321. task.Start();
  322. }
  323. //// 开启“获取线体报警数据”的线程
  324. //TaskReadAlarm.Start();
  325. ////下传MES信息给1工位(先判断下plc对象数量)
  326. //if (Funs.Count > 1)
  327. // DownLoadProductInfo(1);
  328. AddMessage(LogType.Info, "程序初始化完成");
  329. }
  330. catch (Exception ex)
  331. {
  332. string str = ex.StackTrace;
  333. this.BeginInvoke(new Action(() =>
  334. {
  335. AddMessage(LogType.Error, "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  336. }));
  337. }
  338. #endregion
  339. }
  340. catch (Exception ex)
  341. {
  342. string str = ex.StackTrace;
  343. OnMessage(LogType.Info, "主窗体的首页初始化出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  344. if (ex.Message != null && ex.Message.Contains("timed out"))
  345. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  346. else
  347. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  348. }
  349. }
  350. /// <summary>
  351. /// 窗体关闭事件
  352. /// </summary>
  353. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  354. {
  355. Closed2();
  356. }
  357. public void Closed2()
  358. {
  359. try
  360. {
  361. IsRun = false;
  362. Thread.Sleep(IntervalReadPLC);
  363. // 断开TCP
  364. int count = _HPSocket_TcpClients.Count();
  365. for (int i = 0; i < count; i++)
  366. {
  367. try
  368. {
  369. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  370. {
  371. _HPSocket_TcpClients[i].Stop();
  372. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  373. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  374. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  375. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  376. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  377. }
  378. }
  379. catch { }
  380. }
  381. // 关闭Iot
  382. try { XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath, GlobalContext.MqttServerName); } catch { }
  383. // 关闭AGV Mqtt
  384. try { _MQTTHelper.DisconnectAsync_Client().Wait(); } catch { }
  385. }
  386. catch { }
  387. }
  388. #endregion 窗体基础事件
  389. #region 监控MES状态
  390. /// <summary>
  391. /// 监控MES连接状态
  392. /// </summary>
  393. private void MonitorMESConnect()
  394. {
  395. while (IsRun) // 运行被控线程
  396. {
  397. try
  398. {
  399. // 开启MES(Http)
  400. if (GlobalContext.IsUseMES)
  401. {
  402. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  403. if (mesret)
  404. {
  405. picMESStatus.Image = imageListState.Images[1];
  406. GlobalContext.MESIsConnect = true;
  407. }
  408. else
  409. {
  410. picMESStatus.Image = imageListState.Images[0];
  411. GlobalContext.MESIsConnect = false;
  412. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  413. }
  414. }
  415. // 开启IOT(MQTT)
  416. if (GlobalContext.IsUseIot)
  417. {
  418. bool iIot = XiaomiMqttClient.IsOpen;
  419. if (iIot)
  420. picIot.Image = imageListState.Images[1];
  421. else
  422. {
  423. picIot.Image = imageListState.Images[0];
  424. OnMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  425. }
  426. }
  427. // 开启AGV(Http与MQTT)
  428. if (GlobalContext.IsUseAGV)
  429. {
  430. // AGV Http
  431. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  432. if (mesret1)
  433. picAgvHttp.Image = imageListState.Images[1];
  434. else
  435. {
  436. picAgvHttp.Image = imageListState.Images[0];
  437. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  438. }
  439. // AGV MQTT
  440. if (GlobalContext.AGVMQTTIsConnect)
  441. picAgvMqtt.Image = imageListState.Images[1];
  442. else
  443. {
  444. picAgvMqtt.Image = imageListState.Images[0];
  445. OnMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  446. }
  447. }
  448. }
  449. catch (Exception ex)
  450. {
  451. string str = ex.StackTrace;
  452. AddMessage(LogType.Error, "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  453. }
  454. Thread.Sleep(IntervalMonitorMES);
  455. }
  456. }
  457. #endregion 监控MES连接状态
  458. #region 采集设备状态、运行数据、报警数据
  459. /// <summary>
  460. /// 请求设备状态 5000
  461. /// </summary>
  462. /// <param name="no">1</param>
  463. /// <param name="stationNameStr"></param>
  464. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  465. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  466. {
  467. try
  468. {
  469. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  470. {
  471. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  472. return result;
  473. }
  474. else
  475. {
  476. return 0;
  477. }
  478. }
  479. catch (Exception ex)
  480. {
  481. string str = ex.StackTrace;
  482. AddMessage_Station(stationNameStr, LogType.Error, "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  483. return 0;
  484. }
  485. }
  486. /// <summary>
  487. /// 检查是否可采集点检数据 - 不取新值
  488. /// 5000不为1时可点检
  489. /// </summary>
  490. /// <returns></returns>
  491. public bool CheckCanSpotcheck1(int deviceState)
  492. {
  493. //return true;
  494. //D5000 = 1,代表设备控制状态处于运行状态
  495. //D5000 = 2, 代表设备控制状态处于故障状态
  496. //D5000 = 3,代表设备控制状态处于缺料状态
  497. //D5000 = 4, 代表设备控制状态处于待机状态
  498. //D5000 = 5,代表设备控制状态处于维修状态
  499. return deviceState != 1;
  500. }
  501. /// <summary>
  502. /// 检查是否可采集产品数据 - 不取新值
  503. /// </summary>
  504. /// <returns></returns>
  505. public bool CheckCanCollData(int deviceState)
  506. {
  507. return deviceState == 0; // 点检时该值不为0
  508. }
  509. /// <summary>
  510. /// 获取设备报警数据与获取设备运行信息
  511. /// </summary>
  512. private async void ReadAlarmAllPLC()
  513. {
  514. // [S1] Tray盘上料装备(板测)
  515. // [S2] FCT(板测)
  516. // [S3] 值板机
  517. // [S4] 取放桁架
  518. // [S5] Tray盘下料装备
  519. /// 上位机心跳
  520. /// 获取设备报警数据与状态信息
  521. string stationNameStr = "获取设备报警数据与状态信息";
  522. while (IsRun)
  523. {
  524. try
  525. {
  526. if (!GlobalContext._IsCon_plc1Alarm)
  527. {
  528. UpdatePLCMonitor(1, -2, 0);
  529. continue;
  530. }
  531. if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  532. {
  533. DateTime dtNow = DateTime.Now;
  534. #region 获取设备运行信息
  535. try
  536. {
  537. LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  538. lineWorkingData1.GUID = Guid.NewGuid().ToString();
  539. lineWorkingData1.LineName = GlobalContext.LineCode;
  540. //
  541. lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  542. lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  543. lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  544. lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  545. lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  546. lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  547. lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  548. lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  549. lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  550. lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  551. lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  552. lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  553. lineWorkingData1.CreateTime = DateTime.Now;
  554. string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  555. // UI展示-展示到设备状态页
  556. if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  557. {
  558. // 查询数据库最新一条数据,确定是不是更新
  559. string qSql = @"SELECT top(1) [GUID]
  560. ,[LineName]
  561. ,[BootTimeLong]
  562. ,[NormalTimeLong]
  563. ,[StandbyTimeLong]
  564. ,[FaultTimeLong]
  565. ,[MaterialShortageTimeLong]
  566. ,[MaintenanceTimeLong]
  567. ,[FaultNumber]
  568. ,[OutputNumber]
  569. ,[QualifiedNumber]
  570. ,[QualifiedRate]
  571. ,[DesignRhythm]
  572. ,[RealityRhythm]
  573. ,[CreateTime]
  574. FROM [LineWorkingData]
  575. where [CreateTime] > '{0}'
  576. and [LineName]='{1}'
  577. order by [CreateTime] desc
  578. ";
  579. qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  580. var ds = SQLHelper_New.Query(qSql, null);
  581. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  582. {
  583. var dataDBlast = new LineWorkingData_ThisTime();
  584. dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  585. dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  586. dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  587. dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  588. if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  589. {
  590. dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  591. dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  592. dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  593. dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  594. dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  595. dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  596. dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  597. dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  598. dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  599. dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  600. dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  601. dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  602. string usql = dataDBlast.ToStringUpdate();
  603. SQLHelper_New.ExecuteSQL(usql, null);
  604. lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  605. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  606. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  607. }
  608. }
  609. else
  610. {
  611. // 插入
  612. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  613. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  614. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  615. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  616. }
  617. }
  618. else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  619. {
  620. LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  621. //// 本次开机设备运行情况
  622. //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  623. //Task.Run(() =>
  624. //{
  625. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  626. // {
  627. // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  628. // }
  629. //});
  630. // 本日设备运行情况
  631. // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  632. if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  633. {
  634. // 更新
  635. lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  636. lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  637. lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  638. lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  639. lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  640. lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  641. lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  642. lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  643. lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  644. lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  645. lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  646. lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  647. SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  648. lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  649. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  650. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  651. }
  652. else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  653. {
  654. // 插入
  655. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  656. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  657. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  658. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  659. }
  660. await Task.Run(() =>
  661. {
  662. try
  663. {
  664. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  665. {
  666. Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  667. }
  668. }
  669. catch { }
  670. });
  671. }
  672. }
  673. catch (Exception ex)
  674. {
  675. string str = ex.StackTrace;
  676. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  677. }
  678. #endregion 获取设备运行信息
  679. #region 报警数据
  680. try
  681. {
  682. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  683. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  684. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  685. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  686. for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  687. {
  688. short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  689. dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  690. if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  691. {
  692. isNeedUpdUI = true; // 需要更新历史报警UI信息
  693. // 记录
  694. dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  695. switch (dicAlarms_Cur_PLC1[i].是否报警)
  696. {
  697. case true: // 报警
  698. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  699. {
  700. GUID = Guid.NewGuid().ToString(),
  701. LineName = GlobalContext.LineCode, // 线体
  702. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  703. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  704. StartTime = dtNow // 开始时间
  705. };
  706. // 传输到页面
  707. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  708. {
  709. 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  710. 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  711. 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  712. 开始时间 = dtNow
  713. });
  714. // 新增到数据库
  715. var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  716. SaveAlarmDataByDB(stationNameStr, data1, false);
  717. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  718. break;
  719. case false: // 消除报警
  720. if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  721. {
  722. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  723. {
  724. GUID = Guid.NewGuid().ToString(),
  725. LineName = GlobalContext.LineCode, // 线体
  726. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  727. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  728. StartTime = dtNow, // 开始时间
  729. EndTime = dtNow, // 开始时间
  730. PersistTime = 1, // 耗时1s
  731. };
  732. // 新增
  733. var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  734. SaveAlarmDataByDB(stationNameStr, data2, false);
  735. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  736. }
  737. else
  738. {
  739. dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  740. dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  741. - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  742. // 修改
  743. var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  744. SaveAlarmDataByDB(stationNameStr, data3, true);
  745. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  746. }
  747. break;
  748. default:
  749. break;
  750. }
  751. }
  752. }
  753. DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  754. // 有新报警则更新
  755. if (isNeedUpdUI)
  756. {
  757. // UI展示 - 展示到设备状态页
  758. await Task.Run(() =>
  759. {
  760. try
  761. {
  762. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  763. {
  764. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  765. if (Form_Main.formDevAlarm.Visible)
  766. {
  767. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  768. }
  769. }
  770. }
  771. catch { }
  772. });
  773. }
  774. }
  775. catch (Exception ex)
  776. {
  777. string str = ex.StackTrace;
  778. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  779. }
  780. #endregion 报警数据
  781. UpdatePLCMonitor(1, -2, 1);
  782. }
  783. else
  784. {
  785. UpdatePLCMonitor(1, -2, 0);
  786. }
  787. }
  788. catch (Exception ex)
  789. {
  790. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  791. }
  792. Thread.Sleep(IntervalAlarm);
  793. }
  794. }
  795. #endregion 轮询PLC
  796. #region 下发订单信息
  797. ///// <summary>
  798. ///// 壳体上料(下发工单)的交互逻辑
  799. ///// </summary>
  800. ///// <param name="no"></param>
  801. ///// <exception cref="NotImplementedException"></exception>
  802. //private void ReadStation_DownOrderInfo(int plcNo)
  803. //{
  804. // // [S1] Tray盘上料装备(板测)
  805. // // [S2] FCT(板测)
  806. // // [S3] 值板机
  807. // // [S4] 取放桁架
  808. // // [S5] Tray盘下料装备
  809. // /// 上位机心跳
  810. // /// 获取设备报警数据与状态信息
  811. // string stationNameStr = "[S0]壳体上料";
  812. // while (IsRun)
  813. // {
  814. // try
  815. // {
  816. // if (!GlobalContext._IsCon_Funs1)
  817. // {
  818. // UpdatePLCMonitor(plcNo, 0);
  819. // continue;
  820. // }
  821. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  822. // {
  823. // #region 壳体上料(下发工单)
  824. // try
  825. // {
  826. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  827. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  828. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  829. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  830. // // 重置数据和信号
  831. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  832. // {
  833. // // 清空写给PLC的数据
  834. // int[] i497 = new int[1] { 0 };
  835. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  836. // // MES_Flag重置为0
  837. // int[] i500 = new int[1] { 0 };
  838. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  839. // }
  840. // }
  841. // catch (Exception ex)
  842. // {
  843. // string str = ex.StackTrace;
  844. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  845. // }
  846. // #endregion 壳体上料(下发工单)
  847. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  848. // }
  849. // else
  850. // {
  851. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  852. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  853. //
  854. // Funs[plcNo].Connect();
  855. // }
  856. // }
  857. // catch (Exception ex)
  858. // {
  859. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  860. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  861. //
  862. // Funs[plcNo].ReConnect();
  863. // }
  864. // Thread.Sleep(IntervalReadPLC);
  865. // }
  866. //}
  867. ///// <summary>
  868. ///// 下发订单信息到PLC
  869. ///// </summary>
  870. ///// <param name="no">PLC编号</param>
  871. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  872. //{
  873. // try
  874. // {
  875. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  876. // {
  877. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  878. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  879. // }
  880. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  881. // }
  882. // catch (Exception ex)
  883. // {
  884. // string str = ex.StackTrace;
  885. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  886. // }
  887. //}
  888. /// <summary>
  889. /// 下发清料信号
  890. /// </summary>
  891. /// <param name="no">PLC编号</param>
  892. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  893. {
  894. try
  895. {
  896. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  897. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  898. return true;
  899. }
  900. catch (Exception ex)
  901. {
  902. string str = ex.StackTrace;
  903. AddMessage_Station(stationNameStr, LogType.Error, "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  904. return false;
  905. }
  906. }
  907. #endregion 下发订单信息
  908. #region Xiaomi 贲流
  909. #region 公共方法
  910. private static bool ProgressState = false;
  911. private static readonly object lockObj = new object(); // 锁对象
  912. /// <summary>
  913. /// float[]转为string
  914. /// </summary>
  915. public string FloatArrayToString(float[] nScrewResults)
  916. {
  917. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  918. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  919. }
  920. /// <summary>
  921. /// short[]转为string
  922. /// </summary>
  923. public string ShortArrayToString(short[] nScrewResults)
  924. {
  925. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  926. return string.Join(",", nScrewResults);
  927. }
  928. /// <summary>
  929. /// 写入PLC重复三次
  930. /// </summary>
  931. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount, T inObj)
  932. {
  933. int i = 0;
  934. int nRet = 0;
  935. string strRet = "";
  936. try
  937. {
  938. while (i < 3) // 最多上传三次
  939. {
  940. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  941. if (nRet == 0) //成功
  942. {
  943. break;
  944. }
  945. else
  946. {
  947. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  948. i++;
  949. }
  950. }
  951. return (nRet, strRet);
  952. }
  953. catch (Exception ex)
  954. {
  955. return (1, ex.Message);
  956. }
  957. }
  958. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes, short[] nScrewOrders, short[] nScrewResults)
  959. {
  960. try
  961. {
  962. // 获取当前日期
  963. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  964. // 构建保存路径
  965. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  966. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction);
  967. // 确保目录存在
  968. Directory.CreateDirectory(savePath);
  969. // 文件名
  970. string fileName = $"{ProductBarcode}.txt";
  971. string filePath = Path.Combine(savePath, fileName);
  972. // 确保不会超出数组长度,只取前14个或数组的实际长度
  973. int count = Math.Min(14, fScrewTimes.Length);
  974. using (StreamWriter sw = new StreamWriter(filePath))
  975. {
  976. for (int i = 0; i < count; i++)
  977. {
  978. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  979. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  980. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  981. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  982. sw.WriteLine(); // 空行分隔不同螺丝的信息
  983. }
  984. }
  985. return (0, "");
  986. }
  987. catch (Exception ex)
  988. {
  989. return (1, ex.Message);
  990. }
  991. }
  992. /// <summary>
  993. /// 调用进站接口并保存进站数据
  994. /// </summary>
  995. /// <param name="stationNameStr">工站信息</param>
  996. /// <param name="workorder_code">工单号</param>
  997. /// <param name="mtltmrk">型号(物料号)</param>
  998. /// <param name="sn">产品SN</param>
  999. /// <param name="items">进站数据</param>
  1000. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1001. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn, List<TestItem> items, string MachineId, string StationId)
  1002. {
  1003. int result = 0;
  1004. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1005. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1006. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1007. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1008. inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1009. inRequest_Body.unitSn = sn; // 产品SN
  1010. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1011. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1012. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1013. StationIn stationIn = new StationIn()
  1014. {
  1015. Workorder_code = workorder_code, // 车间订单号
  1016. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1017. Sn = sn, // SN
  1018. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1019. Parameter_values = items, // 进站数据
  1020. Write_user = inRequest_Body.userId, // 员工Id
  1021. Test_time = inRequest_Body.clientTime // 进站时间
  1022. };
  1023. // 本地数据
  1024. string sql = stationIn.ToStringInsert(0);
  1025. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1026. result = ret == "成功" ? 1 : 6;
  1027. //await Task.Delay(200);
  1028. // 上传MES
  1029. if (GlobalContext.IsSendStationIn)
  1030. {
  1031. try
  1032. {
  1033. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1034. string mesRet = string.Empty;
  1035. int i = 0;
  1036. while (i < 2) // 1009会多次尝试上传
  1037. {
  1038. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1039. if (response != null && response.header.code == "200")
  1040. break;
  1041. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1042. i++;
  1043. i++;
  1044. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1045. // 记录失败原因
  1046. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + json_Body);
  1047. }
  1048. if (response?.header?.code == "200")
  1049. {
  1050. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1051. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1052. result = ret_Upd == "成功" ? 1 : 6;
  1053. AddMessage( LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功");
  1054. }
  1055. else
  1056. {
  1057. result = 5;
  1058. AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1059. }
  1060. string sql_response = stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1061. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1062. }
  1063. catch (Exception ex)
  1064. {
  1065. result = 6;
  1066. string str = ex.StackTrace;
  1067. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1068. }
  1069. }
  1070. return result;
  1071. }
  1072. /// <summary>
  1073. /// 选择如何记录出站数据
  1074. /// </summary>
  1075. /// <param name="items">出站数据</param>
  1076. /// <param name="equipmentCode">设备编号</param>
  1077. /// <param name="processItem">测试项目</param>
  1078. /// <param name="workorder_code">车间订单号</param>
  1079. /// <param name="batch_num">批次号</param>
  1080. /// <param name="mtltmrk">型号</param>
  1081. /// <param name="proDate">日期</param>
  1082. /// <param name="supplierCode">供应商代码</param>
  1083. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1084. /// <returns>上传成功时返回1;失败返回0</returns>
  1085. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode, string processItem,
  1086. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1087. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode)
  1088. {
  1089. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
  1090. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode);
  1091. }
  1092. /// <summary>
  1093. /// 添加出站数据(提交到MES+本地保存到数据库)
  1094. /// </summary>
  1095. /// <param name="items">出站数据</param>
  1096. /// <param name="equipmentCode">设备编号</param>
  1097. /// <param name="processItem">测试项目</param>
  1098. /// <param name="workorder_code">车间订单号</param>
  1099. /// <param name="batch_num">批次号</param>
  1100. /// <param name="mtltmrk">型号</param>
  1101. /// <param name="proDate">日期</param>
  1102. /// <param name="supplierCode">供应商代码</param>
  1103. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1104. /// <returns>上传成功时返回1;失败返回0</returns>
  1105. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1106. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1107. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode)
  1108. {
  1109. int upload = 0;
  1110. int result = 0;
  1111. ProcessData processData = new ProcessData()
  1112. {
  1113. Equipment_code = equipmentCode,
  1114. Workorder_code = workorder_code,
  1115. Batch_number = batch_num,
  1116. Sn = sn, // SN
  1117. Testitem = processItem,
  1118. Parameter_values = items,
  1119. Write_user = GlobalContext.CurrentUser,
  1120. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1121. };
  1122. // 本地数据
  1123. string sql = processData.ToStringInsert(upload);
  1124. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1125. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1126. // 上传MES
  1127. if (GlobalContext.IsSendProcessData)
  1128. {
  1129. try
  1130. {
  1131. string id = processData.ID.Copy();
  1132. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1133. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1134. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1135. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1136. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1137. outRequest_Body.unitSn = sn; // 产品SN
  1138. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1139. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1140. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1141. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1142. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1143. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1144. if (!string.IsNullOrEmpty(partBarcode))
  1145. {
  1146. outRequest_Body.unitData.keyMaterial.Add(
  1147. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1148. {
  1149. bindSort = 1,
  1150. materialSn = partBarcode
  1151. }); // 设备数据 - 部件码
  1152. }
  1153. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1154. if (GlobalContext.IsSendProcessData)
  1155. {
  1156. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1157. string mesRet = string.Empty;
  1158. int i = 0;
  1159. while (i < 2) // 1009会多次尝试上传
  1160. {
  1161. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1162. if (response != null && response.header.code == "200")
  1163. break;
  1164. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1165. i++;
  1166. i++;
  1167. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1168. // 记录失败原因
  1169. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1170. }
  1171. if (response?.header?.code == "200")
  1172. {
  1173. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1174. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1175. result = 1;
  1176. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1177. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1178. }
  1179. else
  1180. {
  1181. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:"+ mesRet);
  1182. }
  1183. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(JsonConvert.SerializeObject(outRequest_Body),
  1184. JsonConvert.SerializeObject(response), id);
  1185. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1186. }
  1187. }
  1188. catch (Exception ex)
  1189. {
  1190. string str = ex.StackTrace;
  1191. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1192. }
  1193. }
  1194. return result;
  1195. }
  1196. #endregion
  1197. #region S1
  1198. /// <summary>
  1199. /// [S1] 壳体清洁上料装备
  1200. /// </summary>
  1201. /// <param name="plcNo">PLC编号</param>
  1202. private void ReadStation_S1(int plcNo)
  1203. {
  1204. string stationCode = "[S1]";
  1205. string stationName = "壳体清洁上料";
  1206. string stationNameStr = stationCode + stationName;
  1207. string tagBaseName = "g_OP10_MES"; //标签变量名称
  1208. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1209. string tagAgvCommName = "agvCommFrmPC";
  1210. string tagBarsetName = "BarcodeSet";
  1211. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  1212. (int, string) result;
  1213. while (true)
  1214. {
  1215. try
  1216. {
  1217. if (!GlobalContext._IsCon_Funs1)
  1218. {
  1219. UpdatePLCMonitor(1, plcNo, 0);
  1220. continue;
  1221. }
  1222. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1223. {
  1224. Stopwatch stopwatch1 = new Stopwatch();
  1225. Stopwatch stopwatch2 = new Stopwatch();
  1226. stopwatch1.Start();
  1227. stopwatch2.Start();
  1228. #region 一次性读取所有数据
  1229. // 一次性读取所有数据
  1230. result = FunsEip[plcNo].Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
  1231. if (result.Item1 != 0)
  1232. {
  1233. //richTextBox1.AppendText("\n" + strRet);
  1234. }
  1235. else
  1236. {
  1237. //richTextBox1.AppendText("\n" + "读取成功");
  1238. }
  1239. #endregion 一次性读取所有数据
  1240. stopwatch2.Stop();
  1241. #region 进站
  1242. try
  1243. {
  1244. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1245. {
  1246. lock (lockObj)
  1247. {
  1248. if (!ProgressState)
  1249. {
  1250. ProgressState = true;
  1251. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  1252. }
  1253. }
  1254. }
  1255. }
  1256. catch (Exception ex)
  1257. {
  1258. ProgressState = false;
  1259. string str = ex.StackTrace;
  1260. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1261. }
  1262. #endregion 进站
  1263. #region 出站
  1264. try
  1265. {
  1266. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1267. {
  1268. lock (lockObj)
  1269. {
  1270. if (!ProgressState)
  1271. {
  1272. ProgressState = true;
  1273. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1274. }
  1275. }
  1276. }
  1277. }
  1278. catch (Exception ex)
  1279. {
  1280. ProgressState = false;
  1281. string str = ex.StackTrace;
  1282. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1283. }
  1284. #endregion 进站
  1285. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1286. stopwatch1.Stop();
  1287. OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1288. }
  1289. else
  1290. {
  1291. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1292. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1293. FunsEip[plcNo].Connect(); // 重连
  1294. }
  1295. }
  1296. catch (Exception ex)
  1297. {
  1298. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1299. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1300. }
  1301. Thread.Sleep(IntervalReadPLC);
  1302. }
  1303. }
  1304. /// <summary>
  1305. /// [S1] 壳体清洁上料 - 进站
  1306. /// </summary>
  1307. /// <param name="plcNo">PLC编号</param>
  1308. /// <param name="stationNameStr">工站全称</param>
  1309. /// <param name="stPLC_MesData"></param>
  1310. /// <param name="tagMesCommName"></param>
  1311. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  1312. {
  1313. Stopwatch stopwatch1 = new Stopwatch();
  1314. Stopwatch stopwatch2 = new Stopwatch();
  1315. try
  1316. {
  1317. stopwatch1.Start();
  1318. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  1319. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1320. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  1321. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  1322. if (string.IsNullOrEmpty(sn))
  1323. {
  1324. ProgressState = false;
  1325. return;
  1326. }
  1327. //拍照取得SN码,截取成9位码
  1328. sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1329. AddMessage(LogType.Info, stationNameStr + "_进站SN:" + sn);
  1330. //绑定载具和产品
  1331. ResponseMessage message = new ResponseMessage();
  1332. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  1333. if (message.result == false)
  1334. {
  1335. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  1336. }
  1337. // 产品SN进站
  1338. List<TestItem> item = new List<TestItem>();
  1339. stopwatch2.Start();
  1340. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1341. stopwatch2.Stop();
  1342. //指令执行结果 1:OK 110:失败
  1343. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1344. //进站结果写入PLC
  1345. CommandFromPLC resultToPlC = new CommandFromPLC();
  1346. resultToPlC.cmd = 0;
  1347. resultToPlC.cmdParam = 0;
  1348. resultToPlC.cmdResult = mesResultFrmWeb;
  1349. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1350. }
  1351. catch (Exception ex)
  1352. {
  1353. string str = ex.StackTrace;
  1354. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1355. CommandFromPLC resultToPlC = new CommandFromPLC();
  1356. resultToPlC.cmd = 0;
  1357. resultToPlC.cmdParam = 0; //指令参数
  1358. resultToPlC.cmdResult = 110;
  1359. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1360. }
  1361. stopwatch1.Stop();
  1362. ProgressState = false;
  1363. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1364. }
  1365. /// <summary>
  1366. /// [S1] 壳体清洁上料 - 出站接口
  1367. /// </summary>
  1368. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1369. {
  1370. Stopwatch stopwatch1 = new Stopwatch();
  1371. Stopwatch stopwatch2 = new Stopwatch();
  1372. try
  1373. {
  1374. stopwatch1.Start();
  1375. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1376. string processItem = stationName; // 项目
  1377. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1378. string supplierCode = ""; // 供应商代码
  1379. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  1380. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  1381. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  1382. string sn = string.Empty;
  1383. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1384. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  1385. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  1386. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1387. bool pass = a1Result == 1;
  1388. //根据载具码获取产品码
  1389. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1390. if (string.IsNullOrEmpty(strProductBarcode))
  1391. {
  1392. AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr} 未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1393. }
  1394. sn = strProductBarcode;
  1395. List<TestItem> items = new List<TestItem>();
  1396. items.Add(new TestItem()
  1397. {
  1398. Parameter_name = "载具码",
  1399. Parameter_value = CarrierBarcode,
  1400. Parameter_unit = ""
  1401. });
  1402. items.Add(new TestItem()
  1403. {
  1404. Parameter_name = "产品码",
  1405. Parameter_value = sn,
  1406. Parameter_unit = ""
  1407. });
  1408. //保存PLC返回MES数据到本地
  1409. ResponseMessage message = new ResponseMessage();
  1410. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  1411. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress, stPLC_MesData.mesData.fCleanSpeed,
  1412. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime, stPLC_MesData.mesData.nCleanCount,
  1413. stPLC_MesData.mesData.nRemainCount);
  1414. if (message.result == false)
  1415. {
  1416. AddMessage(LogType.Debug, message.text);
  1417. }
  1418. //出站接口
  1419. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1420. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  1421. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1422. stopwatch2.Start();
  1423. //进站结果写入PLC
  1424. CommandFromPLC resultToPlC = new CommandFromPLC();
  1425. resultToPlC.cmd = 0;
  1426. resultToPlC.cmdParam = 0; //指令参数
  1427. resultToPlC.cmdResult = mesResultFrmWeb;
  1428. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1429. stopwatch2.Stop();
  1430. }
  1431. catch (Exception ex)
  1432. {
  1433. stopwatch2.Start();
  1434. CommandFromPLC resultToPlC = new CommandFromPLC();
  1435. resultToPlC.cmd = 0;
  1436. resultToPlC.cmdParam = 0; //指令参数
  1437. resultToPlC.cmdResult = 110;
  1438. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1439. stopwatch2.Stop();
  1440. ProgressState = true;
  1441. string str = ex.StackTrace;
  1442. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1443. }
  1444. stopwatch1.Stop();
  1445. ProgressState = false;
  1446. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1447. }
  1448. #endregion
  1449. #region S2
  1450. /// <summary>
  1451. /// [S2] 上盖板上料装备
  1452. /// </summary>
  1453. /// <param name="plcNo">PLC编号</param>
  1454. private void ReadStation_S2(int plcNo)
  1455. {
  1456. string stationCode = "[OP20]";
  1457. string stationName = "上盖板上料装备";
  1458. string stationNameStr = stationCode + stationName;
  1459. string tagBaseName = "g_OP20_MES"; //标签变量名称
  1460. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1461. string tagAgvCommName = "agvCommFrmPC";
  1462. string tagBarsetName = "BarcodeSet";
  1463. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  1464. (int, string) result;
  1465. while (true)
  1466. {
  1467. try
  1468. {
  1469. if (!GlobalContext._IsCon_Funs2)
  1470. {
  1471. UpdatePLCMonitor(1, plcNo, 0);
  1472. continue;
  1473. }
  1474. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1475. {
  1476. Stopwatch stopwatch1 = new Stopwatch();
  1477. Stopwatch stopwatch2 = new Stopwatch();
  1478. stopwatch1.Start();
  1479. stopwatch2.Start();
  1480. #region 一次性读取所有数据
  1481. // 一次性读取所有数据
  1482. result = FunsEip[plcNo].Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
  1483. if (result.Item1 != 0)
  1484. {
  1485. //richTextBox1.AppendText("\n" + strRet);
  1486. }
  1487. else
  1488. {
  1489. //richTextBox1.AppendText("\n" + "读取成功");
  1490. }
  1491. #endregion 一次性读取所有数据
  1492. stopwatch2.Stop();
  1493. #region 进站
  1494. try
  1495. {
  1496. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1497. {
  1498. lock (lockObj)
  1499. {
  1500. if (!ProgressState)
  1501. {
  1502. ProgressState = true;
  1503. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  1504. }
  1505. }
  1506. }
  1507. }
  1508. catch (Exception ex)
  1509. {
  1510. ProgressState = false;
  1511. string str = ex.StackTrace;
  1512. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1513. }
  1514. #endregion 进站
  1515. #region 出站
  1516. try
  1517. {
  1518. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1519. {
  1520. lock (lockObj)
  1521. {
  1522. if (!ProgressState)
  1523. {
  1524. ProgressState = true;
  1525. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1526. }
  1527. }
  1528. }
  1529. }
  1530. catch (Exception ex)
  1531. {
  1532. ProgressState = false;
  1533. string str = ex.StackTrace;
  1534. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1535. }
  1536. #endregion 进站
  1537. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1538. stopwatch1.Stop();
  1539. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  1540. OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1541. }
  1542. else
  1543. {
  1544. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1545. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1546. FunsEip[plcNo].Connect();
  1547. }
  1548. }
  1549. catch (Exception ex)
  1550. {
  1551. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1552. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1553. //Funs[plcNo].ReConnect();
  1554. }
  1555. Thread.Sleep(IntervalReadPLC);
  1556. }
  1557. }
  1558. /// <summary>
  1559. /// [S2] 上盖板上料装备
  1560. /// </summary>
  1561. /// <param name="plcNo">PLC编号</param>
  1562. /// <param name="stationNameStr">工站全称</param>
  1563. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  1564. {
  1565. Stopwatch stopwatch1 = new Stopwatch();
  1566. Stopwatch stopwatch2 = new Stopwatch();
  1567. try
  1568. {
  1569. stopwatch1.Start();
  1570. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  1571. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  1572. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  1573. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  1574. //根据载具码获取产品码
  1575. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  1576. if (string.IsNullOrEmpty(strProductBarcode))
  1577. {
  1578. AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr} 未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1579. }
  1580. sn = strProductBarcode;
  1581. // 产品SN(物料码)校验
  1582. List<TestItem> item = new List<TestItem>();
  1583. stopwatch2.Start();
  1584. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1585. stopwatch2.Stop();
  1586. //指令执行结果 1:OK 110:失败
  1587. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1588. //进站结果写入PLC
  1589. CommandFromPLC resultToPlC = new CommandFromPLC();
  1590. resultToPlC.cmd = 0;
  1591. resultToPlC.cmdParam = 0; //指令参数
  1592. resultToPlC.cmdResult = mesResultFrmWeb;
  1593. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1594. }
  1595. catch (Exception ex)
  1596. {
  1597. string str = ex.StackTrace;
  1598. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1599. CommandFromPLC resultToPlC = new CommandFromPLC();
  1600. resultToPlC.cmd = 0;
  1601. resultToPlC.cmdParam = 0; //指令参数
  1602. resultToPlC.cmdResult = 110;
  1603. }
  1604. stopwatch1.Stop();
  1605. ProgressState = false;
  1606. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1607. }
  1608. /// <summary>
  1609. /// [S2] 上盖板上料装备 - 出站接口
  1610. /// </summary>
  1611. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1612. {
  1613. Stopwatch stopwatch1 = new Stopwatch();
  1614. Stopwatch stopwatch2 = new Stopwatch();
  1615. try
  1616. {
  1617. stopwatch1.Start();
  1618. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1619. string processItem = stationName; // 测试项目
  1620. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1621. string supplierCode = ""; // 供应商代码
  1622. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  1623. string batch_num = GlobalContext.BatchNumber; // 批次号
  1624. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  1625. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  1626. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1627. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  1628. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  1629. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  1630. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1631. bool pass = a1Result == 1;
  1632. //根据载具码获取产品码
  1633. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1634. if (string.IsNullOrEmpty(strProductBarcode))
  1635. {
  1636. AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr} 未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1637. }
  1638. sn = strProductBarcode;
  1639. List<TestItem> items = new List<TestItem>();
  1640. items.Add(new TestItem()
  1641. {
  1642. Parameter_name = "载具码",
  1643. Parameter_value = CarrierBarcode,
  1644. Parameter_unit = ""
  1645. });
  1646. items.Add(new TestItem()
  1647. {
  1648. Parameter_name = "产品码",
  1649. Parameter_value = sn,
  1650. Parameter_unit = ""
  1651. });
  1652. items.Add(new TestItem()
  1653. {
  1654. Parameter_name = "部件码",
  1655. Parameter_value = PartBarcode,
  1656. Parameter_unit = ""
  1657. });
  1658. //保存PLC返回MES数据到本地
  1659. ResponseMessage message = new ResponseMessage();
  1660. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  1661. if (message.result == false)
  1662. {
  1663. AddMessage(LogType.Error, message.text);
  1664. }
  1665. if (!string.IsNullOrEmpty(PartBarcode))
  1666. {
  1667. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  1668. if (message.result == false)
  1669. {
  1670. AddMessage(LogType.Error, message.text);
  1671. }
  1672. }
  1673. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1674. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  1675. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1676. stopwatch2.Start();
  1677. //进站结果写入PLC
  1678. CommandFromPLC resultToPlC = new CommandFromPLC();
  1679. resultToPlC.cmd = 0;
  1680. resultToPlC.cmdParam = 0; //指令参数
  1681. resultToPlC.cmdResult = mesResultFrmWeb;
  1682. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1683. stopwatch2.Stop();
  1684. WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
  1685. }
  1686. catch (Exception ex)
  1687. {
  1688. stopwatch2.Start();
  1689. CommandFromPLC resultToPlC = new CommandFromPLC();
  1690. resultToPlC.cmd = 0;
  1691. resultToPlC.cmdParam = 0; //指令参数
  1692. resultToPlC.cmdResult = 110;
  1693. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1694. stopwatch2.Stop();
  1695. string str = ex.StackTrace;
  1696. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1697. }
  1698. stopwatch1.Stop();
  1699. ProgressState = false;
  1700. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1701. }
  1702. #endregion
  1703. #region S3
  1704. /// <summary>
  1705. /// [S3] 点散热胶装备
  1706. /// </summary>
  1707. /// <param name="plcNo">PLC编号</param>
  1708. private void ReadStation_S3(int plcNo)
  1709. {
  1710. string stationCode = "[OP30]";
  1711. string stationName = "点散热胶装备";
  1712. string stationNameStr = stationCode + stationName;
  1713. string tagBaseName = "g_OP30_MES"; //标签变量名称
  1714. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1715. string tagAgvCommName = "agvCommFrmPC";
  1716. string tagBarsetName = "BarcodeSet";
  1717. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  1718. (int, string) result;
  1719. #region 创建字典
  1720. // 触发信号字典 赋值
  1721. s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  1722. s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  1723. s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  1724. s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  1725. s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  1726. // PLC数据字典 赋值
  1727. s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  1728. s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  1729. s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  1730. s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  1731. s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  1732. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  1733. s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  1734. s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  1735. s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  1736. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  1737. s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  1738. s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  1739. s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  1740. s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  1741. s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  1742. s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  1743. //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  1744. s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  1745. s3PLCData.Add("c1Result", 0); // 产品结果
  1746. s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  1747. s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  1748. s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  1749. s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  1750. #endregion 创建字典
  1751. while (true)
  1752. {
  1753. try
  1754. {
  1755. if (!GlobalContext._IsCon_Funs2)
  1756. {
  1757. UpdatePLCMonitor(1, plcNo, 0);
  1758. continue;
  1759. }
  1760. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1761. {
  1762. Stopwatch stopwatch1 = new Stopwatch();
  1763. Stopwatch stopwatch2 = new Stopwatch();
  1764. stopwatch1.Start();
  1765. stopwatch2.Start();
  1766. #region 一次性读取所有数据
  1767. // 一次性读取所有数据
  1768. result = FunsEip[plcNo].Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
  1769. if (result.Item1 != 0)
  1770. {
  1771. //richTextBox1.AppendText("\n" + strRet);
  1772. }
  1773. else
  1774. {
  1775. //richTextBox1.AppendText("\n" + "读取成功");
  1776. }
  1777. #endregion 一次性读取所有数据
  1778. stopwatch2.Stop();
  1779. #region 左边进站
  1780. try
  1781. {
  1782. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1783. {
  1784. lock (lockObj)
  1785. {
  1786. if (!ProgressState)
  1787. {
  1788. ProgressState = true;
  1789. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  1790. }
  1791. }
  1792. }
  1793. }
  1794. catch (Exception ex)
  1795. {
  1796. ProgressState = false;
  1797. string str = ex.StackTrace;
  1798. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1799. }
  1800. #endregion 左边进站
  1801. #region 左边出站
  1802. try
  1803. {
  1804. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1805. {
  1806. lock (lockObj)
  1807. {
  1808. if (!ProgressState)
  1809. {
  1810. ProgressState = true;
  1811. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  1812. }
  1813. }
  1814. }
  1815. }
  1816. catch (Exception ex)
  1817. {
  1818. ProgressState = false;
  1819. string str = ex.StackTrace;
  1820. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1821. }
  1822. #endregion 左边出站
  1823. #region 右边进站
  1824. try
  1825. {
  1826. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1827. {
  1828. lock (lockObj)
  1829. {
  1830. if (!ProgressState)
  1831. {
  1832. ProgressState = true;
  1833. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right." + tagBarsetName,"Right", out ProgressState));
  1834. }
  1835. }
  1836. }
  1837. }
  1838. catch (Exception ex)
  1839. {
  1840. ProgressState = false;
  1841. string str = ex.StackTrace;
  1842. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1843. }
  1844. #endregion 右边进站
  1845. #region 右边出站
  1846. try
  1847. {
  1848. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1849. {
  1850. lock (lockObj)
  1851. {
  1852. if (!ProgressState)
  1853. {
  1854. ProgressState = true;
  1855. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  1856. }
  1857. }
  1858. }
  1859. }
  1860. catch (Exception ex)
  1861. {
  1862. string str = ex.StackTrace;
  1863. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1864. }
  1865. #endregion 右边出站
  1866. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1867. stopwatch1.Stop();
  1868. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  1869. OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1870. }
  1871. else
  1872. {
  1873. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1874. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1875. FunsEip[plcNo].Connect();
  1876. }
  1877. }
  1878. catch (Exception ex)
  1879. {
  1880. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1881. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1882. //Funs[plcNo].ReConnect();
  1883. }
  1884. Thread.Sleep(IntervalReadPLC);
  1885. }
  1886. }
  1887. /// <summary>
  1888. /// [S3] 点散热胶装备 - 进站
  1889. /// </summary>
  1890. /// <param name="plcNo">PLC编号</param>
  1891. /// <param name="stationNameStr">工站全称</param>
  1892. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName,string direction, out bool ProgressState)
  1893. {
  1894. Stopwatch stopwatch1 = new Stopwatch();
  1895. Stopwatch stopwatch2 = new Stopwatch();
  1896. try
  1897. {
  1898. stopwatch1.Start();
  1899. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  1900. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  1901. string StationId=string.Empty;
  1902. if (direction=="Left")
  1903. {
  1904. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  1905. }
  1906. if (direction == "Right")
  1907. {
  1908. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  1909. }
  1910. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  1911. //载具码验证产品码
  1912. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  1913. if (string.IsNullOrEmpty(strProductBarcode))
  1914. {
  1915. AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr} 未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1916. }
  1917. //只OP10,OP50 PLC返回SN,其他抓绑定的PLC
  1918. sn = strProductBarcode;
  1919. // 产品SN(物料码)校验
  1920. List<TestItem> item = new List<TestItem>();
  1921. stopwatch2.Start();
  1922. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1923. stopwatch2.Stop();
  1924. //指令执行结果 1:OK 110:失败
  1925. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1926. ////if (!string.IsNullOrEmpty(strProductBarcode) && !string.IsNullOrEmpty(sn) && strProductBarcode != sn)
  1927. ////{
  1928. //// mesResultFrmWeb = 111;
  1929. ////}
  1930. //进站结果写入PLC
  1931. CommandFromPLC resultToPlC = new CommandFromPLC();
  1932. resultToPlC.cmd = 0;
  1933. resultToPlC.cmdParam = 0; //指令参数
  1934. resultToPlC.cmdResult = mesResultFrmWeb;
  1935. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1936. //if (!string.IsNullOrEmpty(strProductBarcode) && strProductBarcode != sn)
  1937. //{
  1938. // BarcodeSet_t BarcodeToPlc = new BarcodeSet_t();
  1939. // BarcodeToPlc.strCarrierBarcode = strCarrierBarcode;
  1940. // BarcodeToPlc.strProductBarcode = sn;
  1941. // BarcodeToPlc.strPartBarcode = stPLC_MesData.BarcodeSet.strPartBarcode;
  1942. // FunsEip[plcNo].Write_SingleTag<BarcodeSet_t>(tagBarsetName, 1, BarcodeToPlc);
  1943. //}
  1944. }
  1945. catch (Exception ex)
  1946. {
  1947. string str = ex.StackTrace;
  1948. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1949. CommandFromPLC resultToPlC = new CommandFromPLC();
  1950. resultToPlC.cmd = 0;
  1951. resultToPlC.cmdParam = 0; //指令参数
  1952. resultToPlC.cmdResult = 110;
  1953. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1954. }
  1955. stopwatch1.Stop();
  1956. ProgressState = false;
  1957. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1958. }
  1959. /// <summary>
  1960. /// [S3] 点散热胶装备 - 出站
  1961. /// </summary>
  1962. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  1963. {
  1964. Stopwatch stopwatch1 = new Stopwatch();
  1965. Stopwatch stopwatch2 = new Stopwatch();
  1966. try
  1967. {
  1968. stopwatch1.Start();
  1969. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1970. string processItem = stationName; // 测试项目
  1971. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1972. string supplierCode = ""; // 供应商代码
  1973. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  1974. string batch_num = GlobalContext.BatchNumber; // 批次号
  1975. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  1976. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  1977. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1978. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  1979. string StationId = string.Empty;
  1980. if (direction == "Left")
  1981. {
  1982. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  1983. }
  1984. if (direction == "Right")
  1985. {
  1986. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  1987. }
  1988. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1989. bool pass = a1Result == 1;
  1990. //根据载具码获取产品码
  1991. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1992. if (string.IsNullOrEmpty(strProductBarcode))
  1993. {
  1994. AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr} 未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1995. }
  1996. sn = strProductBarcode;
  1997. List<TestItem> items = new List<TestItem>();
  1998. items.Add(new TestItem()
  1999. {
  2000. Parameter_name = "载具码",
  2001. Parameter_value = CarrierBarcode,
  2002. Parameter_unit = ""
  2003. });
  2004. items.Add(new TestItem()
  2005. {
  2006. Parameter_name = "产品码",
  2007. Parameter_value = sn,
  2008. Parameter_unit = ""
  2009. });
  2010. //保存PLC返回MES数据到本地
  2011. ResponseMessage message = new ResponseMessage();
  2012. if (direction == "Left")
  2013. {
  2014. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2015. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2016. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2017. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2018. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2019. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2020. if (message.result == false)
  2021. {
  2022. AddMessage(LogType.Error, message.text);
  2023. }
  2024. }
  2025. if (direction == "Right")
  2026. {
  2027. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2028. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2029. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2030. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2031. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2032. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2033. if (message.result == false)
  2034. {
  2035. AddMessage(LogType.Error, message.text);
  2036. }
  2037. }
  2038. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2039. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2040. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2041. stopwatch2.Start();
  2042. //进站结果写入PLC
  2043. CommandFromPLC resultToPlC = new CommandFromPLC();
  2044. resultToPlC.cmd = 0;
  2045. resultToPlC.cmdParam = 0; //指令参数
  2046. resultToPlC.cmdResult = mesResultFrmWeb;
  2047. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2048. stopwatch2.Stop();
  2049. WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
  2050. }
  2051. catch (Exception ex)
  2052. {
  2053. stopwatch2.Start();
  2054. CommandFromPLC resultToPlC = new CommandFromPLC();
  2055. resultToPlC.cmd = 0;
  2056. resultToPlC.cmdParam = 0; //指令参数
  2057. resultToPlC.cmdResult = 110;
  2058. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2059. stopwatch2.Stop();
  2060. string str = ex.StackTrace;
  2061. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2062. }
  2063. stopwatch1.Stop();
  2064. ProgressState = false;
  2065. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2066. }
  2067. #endregion S3
  2068. #region S4
  2069. /// <summary>
  2070. /// [S4] 点胶检测设备
  2071. /// </summary>
  2072. /// <param name="plcNo">PLC编号</param>
  2073. private void ReadStation_S4(int plcNo)
  2074. {
  2075. string stationCode = "[OP40]";
  2076. string stationName = "胶线检测";
  2077. string stationNameStr = stationCode + stationName;
  2078. string tagBaseName = "g_OP40_MES"; //标签变量名称
  2079. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2080. string tagAgvCommName = "agvCommFrmPC";
  2081. string tagBarsetName = "BarcodeSet";
  2082. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  2083. (int, string) result;
  2084. while (true)
  2085. {
  2086. try
  2087. {
  2088. if (!GlobalContext._IsCon_Funs1)
  2089. {
  2090. UpdatePLCMonitor(1, plcNo, 0);
  2091. continue;
  2092. }
  2093. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2094. {
  2095. Stopwatch stopwatch1 = new Stopwatch();
  2096. Stopwatch stopwatch2 = new Stopwatch();
  2097. stopwatch1.Start();
  2098. stopwatch2.Start();
  2099. #region 一次性读取所有数据
  2100. // 一次性读取所有数据
  2101. result = FunsEip[plcNo].Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
  2102. if (result.Item1 != 0)
  2103. {
  2104. //richTextBox1.AppendText("\n" + strRet);
  2105. }
  2106. else
  2107. {
  2108. //richTextBox1.AppendText("\n" + "读取成功");
  2109. }
  2110. #endregion 一次性读取所有数据
  2111. stopwatch2.Stop();
  2112. #region 进站
  2113. try
  2114. {
  2115. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2116. {
  2117. lock (lockObj)
  2118. {
  2119. if (!ProgressState)
  2120. {
  2121. ProgressState = true;
  2122. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2123. }
  2124. }
  2125. }
  2126. }
  2127. catch (Exception ex)
  2128. {
  2129. ProgressState = false;
  2130. string str = ex.StackTrace;
  2131. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2132. }
  2133. #endregion 进站
  2134. #region 出站
  2135. try
  2136. {
  2137. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2138. {
  2139. lock (lockObj)
  2140. {
  2141. if (!ProgressState)
  2142. {
  2143. ProgressState = true;
  2144. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2145. }
  2146. }
  2147. }
  2148. }
  2149. catch (Exception ex)
  2150. {
  2151. string str = ex.StackTrace;
  2152. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2153. }
  2154. #endregion 进站
  2155. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2156. stopwatch1.Stop();
  2157. OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2158. }
  2159. else
  2160. {
  2161. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2162. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2163. FunsEip[plcNo].Connect(); // 重连
  2164. }
  2165. }
  2166. catch (Exception ex)
  2167. {
  2168. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2169. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2170. }
  2171. Thread.Sleep(IntervalReadPLC);
  2172. }
  2173. }
  2174. /// <summary>
  2175. /// [S4] 点胶检测设备 - 进站
  2176. /// </summary>
  2177. /// <param name="plcNo">PLC编号</param>
  2178. /// <param name="stationNameStr">工站全称</param>
  2179. /// <param name="stPLC_MesData"></param>
  2180. /// <param name="tagMesCommName"></param>
  2181. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2182. {
  2183. Stopwatch stopwatch1 = new Stopwatch();
  2184. Stopwatch stopwatch2 = new Stopwatch();
  2185. try
  2186. {
  2187. stopwatch1.Start();
  2188. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2189. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  2190. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  2191. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2192. //载具码验证产品码
  2193. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2194. if (string.IsNullOrEmpty(strProductBarcode))
  2195. {
  2196. AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr} 未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2197. }
  2198. //只OP10,OP50 PLC返回SN,其他抓绑定的PLC
  2199. sn = strProductBarcode;
  2200. // 产品SN(物料码)校验
  2201. List<TestItem> item = new List<TestItem>();
  2202. stopwatch2.Start();
  2203. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2204. stopwatch2.Stop();
  2205. //指令执行结果 1:OK 110:失败
  2206. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2207. //进站结果写入PLC
  2208. CommandFromPLC resultToPlC = new CommandFromPLC();
  2209. resultToPlC.cmd = 0;
  2210. resultToPlC.cmdParam = 0; //指令参数
  2211. resultToPlC.cmdResult = mesResultFrmWeb;
  2212. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2213. }
  2214. catch (Exception ex)
  2215. {
  2216. string str = ex.StackTrace;
  2217. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2218. CommandFromPLC resultToPlC = new CommandFromPLC();
  2219. resultToPlC.cmd = 0;
  2220. resultToPlC.cmdParam = 0; //指令参数
  2221. resultToPlC.cmdResult = 110;
  2222. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2223. }
  2224. stopwatch1.Stop();
  2225. ProgressState = false;
  2226. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2227. }
  2228. /// <summary>
  2229. /// [S4] 点胶检测设备 - 出站接口
  2230. /// </summary>
  2231. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2232. {
  2233. Stopwatch stopwatch1 = new Stopwatch();
  2234. Stopwatch stopwatch2 = new Stopwatch();
  2235. try
  2236. {
  2237. stopwatch1.Start();
  2238. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2239. string processItem = stationName; // 测试项目
  2240. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2241. string supplierCode = ""; // 供应商代码
  2242. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2243. string batch_num = GlobalContext.BatchNumber; // 批次号
  2244. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2245. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2246. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2247. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  2248. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  2249. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2250. bool pass = a1Result == 1;
  2251. //根据载具码获取产品码
  2252. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2253. if (string.IsNullOrEmpty(strProductBarcode))
  2254. {
  2255. AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr} 未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2256. }
  2257. sn = strProductBarcode;
  2258. List<TestItem> items = new List<TestItem>();
  2259. items.Add(new TestItem()
  2260. {
  2261. Parameter_name = "载具码",
  2262. Parameter_value = CarrierBarcode,
  2263. Parameter_unit = ""
  2264. });
  2265. items.Add(new TestItem()
  2266. {
  2267. Parameter_name = "产品码",
  2268. Parameter_value = sn,
  2269. Parameter_unit = ""
  2270. });
  2271. //保存PLC返回MES数据到本地
  2272. ResponseMessage message = new ResponseMessage();
  2273. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  2274. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  2275. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  2276. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  2277. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  2278. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  2279. if (message.result == false)
  2280. {
  2281. AddMessage(LogType.Error, message.text);
  2282. }
  2283. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2284. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2285. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2286. stopwatch2.Start();
  2287. //进站结果写入PLC
  2288. CommandFromPLC resultToPlC = new CommandFromPLC();
  2289. resultToPlC.cmd = 0;
  2290. resultToPlC.cmdParam = 0; //指令参数
  2291. resultToPlC.cmdResult = mesResultFrmWeb;
  2292. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2293. stopwatch2.Stop();
  2294. WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
  2295. }
  2296. catch (Exception ex)
  2297. {
  2298. stopwatch2.Start();
  2299. CommandFromPLC resultToPlC = new CommandFromPLC();
  2300. resultToPlC.cmd = 0;
  2301. resultToPlC.cmdParam = 0; //指令参数
  2302. resultToPlC.cmdResult = 110;
  2303. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2304. stopwatch2.Stop();
  2305. string str = ex.StackTrace;
  2306. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2307. }
  2308. stopwatch1.Stop();
  2309. ProgressState = false;
  2310. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2311. }
  2312. #endregion
  2313. #region S5
  2314. /// <summary>
  2315. /// [S5] 点胶检测设备
  2316. /// </summary>
  2317. /// <param name="plcNo">PLC编号</param>
  2318. private void ReadStation_S5(int plcNo)
  2319. {
  2320. string stationCode = "[OP50]";
  2321. string stationName = "ADD板上料组装装备";
  2322. string stationNameStr = stationCode + stationName;
  2323. string tagBaseName = "g_OP50_MES"; //标签变量名称
  2324. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2325. string tagAgvCommName = "agvCommFrmPC";
  2326. string tagBarsetName = "BarcodeSet";
  2327. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  2328. (int, string) result;
  2329. while (true)
  2330. {
  2331. try
  2332. {
  2333. if (!GlobalContext._IsCon_Funs1)
  2334. {
  2335. UpdatePLCMonitor(1, plcNo, 0);
  2336. continue;
  2337. }
  2338. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2339. {
  2340. Stopwatch stopwatch1 = new Stopwatch();
  2341. Stopwatch stopwatch2 = new Stopwatch();
  2342. stopwatch1.Start();
  2343. stopwatch2.Start();
  2344. #region 一次性读取所有数据
  2345. // 一次性读取所有数据
  2346. result = FunsEip[plcNo].Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
  2347. if (result.Item1 != 0)
  2348. {
  2349. //richTextBox1.AppendText("\n" + strRet);
  2350. }
  2351. else
  2352. {
  2353. //richTextBox1.AppendText("\n" + "读取成功");
  2354. }
  2355. #endregion 一次性读取所有数据
  2356. stopwatch2.Stop();
  2357. #region 进站
  2358. try
  2359. {
  2360. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2361. {
  2362. lock (lockObj)
  2363. {
  2364. if (!ProgressState)
  2365. {
  2366. ProgressState = true;
  2367. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2368. }
  2369. }
  2370. }
  2371. }
  2372. catch (Exception ex)
  2373. {
  2374. ProgressState = false;
  2375. string str = ex.StackTrace;
  2376. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2377. }
  2378. #endregion 进站
  2379. #region 出站
  2380. try
  2381. {
  2382. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2383. {
  2384. lock (lockObj)
  2385. {
  2386. if (!ProgressState)
  2387. {
  2388. ProgressState = true;
  2389. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2390. }
  2391. }
  2392. }
  2393. }
  2394. catch (Exception ex)
  2395. {
  2396. ProgressState = false;
  2397. string str = ex.StackTrace;
  2398. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2399. }
  2400. #endregion 进站
  2401. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2402. stopwatch1.Stop();
  2403. OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2404. }
  2405. else
  2406. {
  2407. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2408. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2409. FunsEip[plcNo].Connect(); // 重连
  2410. }
  2411. }
  2412. catch (Exception ex)
  2413. {
  2414. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2415. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2416. }
  2417. Thread.Sleep(IntervalReadPLC);
  2418. }
  2419. }
  2420. /// <summary>
  2421. /// [S5] 点胶检测设备 - 进站
  2422. /// </summary>
  2423. /// <param name="plcNo">PLC编号</param>
  2424. /// <param name="stationNameStr">工站全称</param>
  2425. /// <param name="stPLC_MesData"></param>
  2426. /// <param name="tagMesCommName"></param>
  2427. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2428. {
  2429. Stopwatch stopwatch1 = new Stopwatch();
  2430. Stopwatch stopwatch2 = new Stopwatch();
  2431. try
  2432. {
  2433. stopwatch1.Start();
  2434. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2435. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  2436. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  2437. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2438. //载具码验证产品码 //载具码验证产品码
  2439. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2440. if (string.IsNullOrEmpty(strProductBarcode))
  2441. {
  2442. AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr} 未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2443. }
  2444. if (!string.IsNullOrEmpty(strProductBarcode) && strProductBarcode != sn)
  2445. {
  2446. AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr} PLC返回产品码与载具初始绑定产品码不同");
  2447. }
  2448. // 产品SN(物料码)校验
  2449. List<TestItem> item = new List<TestItem>();
  2450. stopwatch2.Start();
  2451. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2452. stopwatch2.Stop();
  2453. //指令执行结果 1:OK 110:失败
  2454. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2455. if (!string.IsNullOrEmpty(strProductBarcode) && !string.IsNullOrEmpty(sn) && strProductBarcode != sn)
  2456. {
  2457. mesResultFrmWeb = 111;
  2458. }
  2459. //进站结果写入PLC
  2460. CommandFromPLC resultToPlC = new CommandFromPLC();
  2461. resultToPlC.cmd = 0;
  2462. resultToPlC.cmdParam = 0; //指令参数
  2463. resultToPlC.cmdResult = mesResultFrmWeb;
  2464. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2465. }
  2466. catch (Exception ex)
  2467. {
  2468. string str = ex.StackTrace;
  2469. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2470. CommandFromPLC resultToPlC = new CommandFromPLC();
  2471. resultToPlC.cmd = 0;
  2472. resultToPlC.cmdParam = 0; //指令参数
  2473. resultToPlC.cmdResult = 110;
  2474. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2475. }
  2476. stopwatch1.Stop();
  2477. ProgressState = false;
  2478. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2479. }
  2480. /// <summary>
  2481. /// [S5] 点胶检测设备 - 出站接口
  2482. /// </summary>
  2483. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2484. {
  2485. Stopwatch stopwatch1 = new Stopwatch();
  2486. Stopwatch stopwatch2 = new Stopwatch();
  2487. try
  2488. {
  2489. stopwatch1.Start();
  2490. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2491. string processItem = stationName; // 测试项目
  2492. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2493. string supplierCode = ""; // 供应商代码
  2494. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2495. string batch_num = GlobalContext.BatchNumber; // 批次号
  2496. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2497. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2498. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
  2499. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2500. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  2501. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  2502. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2503. bool pass = a1Result == 1;
  2504. //根据载具码获取产品码
  2505. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2506. if (string.IsNullOrEmpty(strProductBarcode))
  2507. {
  2508. AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr} 未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2509. }
  2510. sn = strProductBarcode;
  2511. List<TestItem> items = new List<TestItem>();
  2512. items.Add(new TestItem()
  2513. {
  2514. Parameter_name = "载具码",
  2515. Parameter_value = CarrierBarcode,
  2516. Parameter_unit = ""
  2517. });
  2518. items.Add(new TestItem()
  2519. {
  2520. Parameter_name = "产品码",
  2521. Parameter_value = sn,
  2522. Parameter_unit = ""
  2523. });
  2524. //保存PLC返回MES数据到本地
  2525. ResponseMessage message = new ResponseMessage();
  2526. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  2527. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB, stPLC_MesData.mesData.nRemainCount, "");
  2528. if (message.result == false)
  2529. {
  2530. AddMessage(LogType.Error, message.text);
  2531. }
  2532. //保存部件码信息
  2533. if (!string.IsNullOrEmpty(PartBarcode))
  2534. {
  2535. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  2536. if (message.result == false)
  2537. {
  2538. AddMessage(LogType.Error, message.text);
  2539. }
  2540. }
  2541. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2542. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  2543. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2544. stopwatch2.Start();
  2545. //进站结果写入PLC
  2546. CommandFromPLC resultToPlC = new CommandFromPLC();
  2547. resultToPlC.cmd = 0;
  2548. resultToPlC.cmdParam = 0; //指令参数
  2549. resultToPlC.cmdResult = mesResultFrmWeb;
  2550. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2551. stopwatch2.Stop();
  2552. WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
  2553. }
  2554. catch (Exception ex)
  2555. {
  2556. stopwatch2.Start();
  2557. CommandFromPLC resultToPlC = new CommandFromPLC();
  2558. resultToPlC.cmd = 0;
  2559. resultToPlC.cmdParam = 0; //指令参数
  2560. resultToPlC.cmdResult = 110;
  2561. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2562. stopwatch2.Stop();
  2563. string str = ex.StackTrace;
  2564. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2565. }
  2566. stopwatch1.Stop();
  2567. ProgressState = false;
  2568. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2569. }
  2570. #endregion
  2571. #region S6
  2572. /// <summary>
  2573. /// [S6] 顶盖装配设备
  2574. /// </summary>
  2575. /// <param name="plcNo">PLC编号</param>
  2576. private void ReadStation_S6(int plcNo)
  2577. {
  2578. string stationCode = "[OP60]";
  2579. string stationName = "组上盖板";
  2580. string stationNameStr = stationCode + stationName;
  2581. string tagBaseName = "g_OP60_MES"; //标签变量名称
  2582. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2583. string tagAgvCommName = "agvCommFrmPC";
  2584. string tagBarsetName = "BarcodeSet";
  2585. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  2586. (int, string) result;
  2587. while (true)
  2588. {
  2589. try
  2590. {
  2591. if (!GlobalContext._IsCon_Funs1)
  2592. {
  2593. UpdatePLCMonitor(1, plcNo, 0);
  2594. continue;
  2595. }
  2596. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2597. {
  2598. Stopwatch stopwatch1 = new Stopwatch();
  2599. Stopwatch stopwatch2 = new Stopwatch();
  2600. stopwatch1.Start();
  2601. stopwatch2.Start();
  2602. #region 一次性读取所有数据
  2603. // 一次性读取所有数据
  2604. result = FunsEip[plcNo].Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
  2605. if (result.Item1 != 0)
  2606. {
  2607. //richTextBox1.AppendText("\n" + strRet);
  2608. }
  2609. else
  2610. {
  2611. //richTextBox1.AppendText("\n" + "读取成功");
  2612. }
  2613. #endregion 一次性读取所有数据
  2614. stopwatch2.Stop();
  2615. #region 进站
  2616. try
  2617. {
  2618. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2619. {
  2620. lock (lockObj)
  2621. {
  2622. if (!ProgressState)
  2623. {
  2624. ProgressState = true;
  2625. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2626. }
  2627. }
  2628. }
  2629. }
  2630. catch (Exception ex)
  2631. {
  2632. ProgressState = false;
  2633. string str = ex.StackTrace;
  2634. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2635. }
  2636. #endregion 进站
  2637. #region 出站
  2638. try
  2639. {
  2640. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2641. {
  2642. lock (lockObj)
  2643. {
  2644. if (!ProgressState)
  2645. {
  2646. ProgressState = true; ;
  2647. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2648. }
  2649. }
  2650. }
  2651. }
  2652. catch (Exception ex)
  2653. {
  2654. ProgressState = false;
  2655. string str = ex.StackTrace;
  2656. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2657. }
  2658. #endregion 进站
  2659. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2660. stopwatch1.Stop();
  2661. OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2662. }
  2663. else
  2664. {
  2665. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2666. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2667. FunsEip[plcNo].Connect(); // 重连
  2668. }
  2669. }
  2670. catch (Exception ex)
  2671. {
  2672. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2673. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2674. }
  2675. Thread.Sleep(IntervalReadPLC);
  2676. }
  2677. }
  2678. /// <summary>
  2679. /// [S6] 顶盖装配设备 - 进站
  2680. /// </summary>
  2681. /// <param name="plcNo">PLC编号</param>
  2682. /// <param name="stationNameStr">工站全称</param>
  2683. /// <param name="stPLC_MesData"></param>
  2684. /// <param name="tagMesCommName"></param>
  2685. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2686. {
  2687. Stopwatch stopwatch1 = new Stopwatch();
  2688. Stopwatch stopwatch2 = new Stopwatch();
  2689. try
  2690. {
  2691. stopwatch1.Start();
  2692. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2693. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  2694. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  2695. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2696. //载具码验证产品码
  2697. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2698. if (string.IsNullOrEmpty(strProductBarcode))
  2699. {
  2700. AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr} 未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2701. }
  2702. sn = strProductBarcode;
  2703. // 产品SN(物料码)校验
  2704. List<TestItem> item = new List<TestItem>();
  2705. stopwatch2.Start();
  2706. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2707. stopwatch2.Stop();
  2708. //指令执行结果 1:OK 110:失败
  2709. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2710. //进站结果写入PLC
  2711. CommandFromPLC resultToPlC = new CommandFromPLC();
  2712. resultToPlC.cmd = 0;
  2713. resultToPlC.cmdParam = 0; //指令参数
  2714. resultToPlC.cmdResult = mesResultFrmWeb;
  2715. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2716. if (!string.IsNullOrEmpty(strProductBarcode) && strProductBarcode != sn)
  2717. {
  2718. BarcodeSet_t BarcodeToPlc = new BarcodeSet_t();
  2719. BarcodeToPlc.strCarrierBarcode = strCarrierBarcode;
  2720. BarcodeToPlc.strProductBarcode = sn;
  2721. BarcodeToPlc.strPartBarcode = stPLC_MesData.BarcodeSet.strPartBarcode;
  2722. FunsEip[plcNo].Write_SingleTag<BarcodeSet_t>(tagBarsetName, 1, BarcodeToPlc);
  2723. }
  2724. }
  2725. catch (Exception ex)
  2726. {
  2727. string str = ex.StackTrace;
  2728. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2729. CommandFromPLC resultToPlC = new CommandFromPLC();
  2730. resultToPlC.cmd = 0;
  2731. resultToPlC.cmdParam = 0; //指令参数
  2732. resultToPlC.cmdResult = 110;
  2733. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2734. }
  2735. stopwatch1.Stop();
  2736. ProgressState = false;
  2737. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2738. }
  2739. /// <summary>
  2740. /// [S6] 顶盖装配设备 - 出站接口
  2741. /// </summary>
  2742. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2743. {
  2744. Stopwatch stopwatch1 = new Stopwatch();
  2745. Stopwatch stopwatch2 = new Stopwatch();
  2746. try
  2747. {
  2748. stopwatch1.Start();
  2749. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2750. string processItem = stationName; // 测试项目
  2751. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2752. string supplierCode = ""; // 供应商代码
  2753. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2754. string batch_num = GlobalContext.BatchNumber; // 批次号
  2755. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2756. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2757. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2758. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  2759. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  2760. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2761. bool pass = a1Result == 1;
  2762. //根据载具码获取产品码
  2763. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2764. if (string.IsNullOrEmpty(strProductBarcode))
  2765. {
  2766. AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr} 未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2767. }
  2768. sn = strProductBarcode;
  2769. List<TestItem> items = new List<TestItem>();
  2770. items.Add(new TestItem()
  2771. {
  2772. Parameter_name = "载具码",
  2773. Parameter_value = CarrierBarcode,
  2774. Parameter_unit = ""
  2775. });
  2776. items.Add(new TestItem()
  2777. {
  2778. Parameter_name = "产品码",
  2779. Parameter_value = sn,
  2780. Parameter_unit = ""
  2781. });
  2782. //保存PLC返回MES数据到本地
  2783. ResponseMessage message = new ResponseMessage();
  2784. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  2785. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  2786. if (message.result == false)
  2787. {
  2788. AddMessage(LogType.Error, message.text);
  2789. }
  2790. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2791. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2792. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2793. stopwatch2.Start();
  2794. //进站结果写入PLC
  2795. CommandFromPLC resultToPlC = new CommandFromPLC();
  2796. resultToPlC.cmd = 0;
  2797. resultToPlC.cmdParam = 0; //指令参数
  2798. resultToPlC.cmdResult = mesResultFrmWeb;
  2799. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2800. stopwatch2.Stop();
  2801. WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
  2802. }
  2803. catch (Exception ex)
  2804. {
  2805. stopwatch2.Start();
  2806. CommandFromPLC resultToPlC = new CommandFromPLC();
  2807. resultToPlC.cmd = 0;
  2808. resultToPlC.cmdParam = 0; //指令参数
  2809. resultToPlC.cmdResult = 110;
  2810. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2811. stopwatch2.Stop();
  2812. string str = ex.StackTrace;
  2813. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2814. }
  2815. stopwatch1.Stop();
  2816. ProgressState = false;
  2817. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2818. }
  2819. #endregion
  2820. #region S7
  2821. /// <summary>
  2822. /// [S7] 锁螺丝设备
  2823. /// </summary>
  2824. /// <param name="plcNo">PLC编号</param>
  2825. private void ReadStation_S7(int plcNo)
  2826. {
  2827. string stationCode = "[OP70]";
  2828. string stationName = "上盖板锁螺丝";
  2829. string stationNameStr = stationCode + stationName;
  2830. string tagBaseName = "g_OP70_MES"; //标签变量名称
  2831. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2832. string tagAgvCommName = "agvCommFrmPC";
  2833. string tagBarsetName = "BarcodeSet";
  2834. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  2835. (int, string) result;
  2836. while (true)
  2837. {
  2838. try
  2839. {
  2840. if (!GlobalContext._IsCon_Funs1)
  2841. {
  2842. UpdatePLCMonitor(1, plcNo, 0);
  2843. continue;
  2844. }
  2845. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2846. {
  2847. Stopwatch stopwatch1 = new Stopwatch();
  2848. Stopwatch stopwatch2 = new Stopwatch();
  2849. stopwatch1.Start();
  2850. stopwatch2.Start();
  2851. #region 一次性读取所有数据
  2852. // 一次性读取所有数据
  2853. result = FunsEip[plcNo].Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
  2854. if (result.Item1 != 0)
  2855. {
  2856. //richTextBox1.AppendText("\n" + strRet);
  2857. }
  2858. else
  2859. {
  2860. //richTextBox1.AppendText("\n" + "读取成功");
  2861. }
  2862. #endregion 一次性读取所有数据
  2863. stopwatch2.Stop();
  2864. #region 左边进站
  2865. try
  2866. {
  2867. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2868. {
  2869. lock (lockObj)
  2870. {
  2871. if (!ProgressState)
  2872. {
  2873. ProgressState = true;
  2874. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName,"Left", out ProgressState));
  2875. }
  2876. }
  2877. }
  2878. }
  2879. catch (Exception ex)
  2880. {
  2881. ProgressState = false;
  2882. string str = ex.StackTrace;
  2883. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2884. }
  2885. #endregion 左边进站
  2886. #region 左边出站
  2887. try
  2888. {
  2889. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2890. {
  2891. lock (lockObj)
  2892. {
  2893. if (!ProgressState)
  2894. {
  2895. ProgressState = true;
  2896. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  2897. }
  2898. }
  2899. }
  2900. }
  2901. catch (Exception ex)
  2902. {
  2903. ProgressState = false;
  2904. string str = ex.StackTrace;
  2905. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2906. }
  2907. #endregion 左边出站
  2908. #region 右边进站
  2909. try
  2910. {
  2911. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2912. {
  2913. lock (lockObj)
  2914. {
  2915. if (!ProgressState)
  2916. {
  2917. ProgressState = true;
  2918. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right" + tagBarsetName,"Right", out ProgressState));
  2919. }
  2920. }
  2921. }
  2922. }
  2923. catch (Exception ex)
  2924. {
  2925. ProgressState = false;
  2926. string str = ex.StackTrace;
  2927. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2928. }
  2929. #endregion 右边进站
  2930. #region 右边出站
  2931. try
  2932. {
  2933. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2934. {
  2935. lock (lockObj)
  2936. {
  2937. if (!ProgressState)
  2938. {
  2939. ProgressState = true;
  2940. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  2941. }
  2942. }
  2943. }
  2944. }
  2945. catch (Exception ex)
  2946. {
  2947. ProgressState = false;
  2948. string str = ex.StackTrace;
  2949. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2950. }
  2951. #endregion 右边出站
  2952. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2953. stopwatch1.Stop();
  2954. OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2955. }
  2956. else
  2957. {
  2958. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2959. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2960. FunsEip[plcNo].Connect(); // 重连
  2961. }
  2962. }
  2963. catch (Exception ex)
  2964. {
  2965. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2966. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2967. }
  2968. Thread.Sleep(IntervalReadPLC);
  2969. }
  2970. }
  2971. /// <summary>
  2972. /// [S7] 锁螺丝设备 - 进站
  2973. /// </summary>
  2974. /// <param name="plcNo">PLC编号</param>
  2975. /// <param name="stationNameStr">工站全称</param>
  2976. /// <param name="stPLC_MesData"></param>
  2977. /// <param name="tagMesCommName"></param>
  2978. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName, string direction,out bool ProgressState)
  2979. {
  2980. Stopwatch stopwatch1 = new Stopwatch();
  2981. Stopwatch stopwatch2 = new Stopwatch();
  2982. try
  2983. {
  2984. stopwatch1.Start();
  2985. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2986. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  2987. string StationId = string.Empty; // 工位ID(可配置)
  2988. if (direction == "Left")
  2989. {
  2990. StationId = GlobalContext.S7_StationId_1;
  2991. }
  2992. if (direction == "Right")
  2993. {
  2994. StationId = GlobalContext.S7_StationId_2;
  2995. }
  2996. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2997. //载具码验证产品码
  2998. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2999. if (string.IsNullOrEmpty(strProductBarcode))
  3000. {
  3001. AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr} 未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3002. }
  3003. sn = strProductBarcode;
  3004. // 产品SN(物料码)校验
  3005. List<TestItem> item = new List<TestItem>();
  3006. stopwatch2.Start();
  3007. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3008. stopwatch2.Stop();
  3009. //指令执行结果 1:OK 110:失败
  3010. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3011. //进站结果写入PLC
  3012. CommandFromPLC resultToPlC = new CommandFromPLC();
  3013. resultToPlC.cmd = 0;
  3014. resultToPlC.cmdParam = 0; //指令参数
  3015. resultToPlC.cmdResult = mesResultFrmWeb;
  3016. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3017. }
  3018. catch (Exception ex)
  3019. {
  3020. string str = ex.StackTrace;
  3021. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3022. CommandFromPLC resultToPlC = new CommandFromPLC();
  3023. resultToPlC.cmd = 0;
  3024. resultToPlC.cmdParam = 0; //指令参数
  3025. resultToPlC.cmdResult = 110;
  3026. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3027. }
  3028. stopwatch1.Stop();
  3029. ProgressState = false;
  3030. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3031. }
  3032. /// <summary>
  3033. /// [S7] 锁螺丝设备 - 出站
  3034. /// </summary>
  3035. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  3036. {
  3037. Stopwatch stopwatch1 = new Stopwatch();
  3038. Stopwatch stopwatch2 = new Stopwatch();
  3039. try
  3040. {
  3041. stopwatch1.Start();
  3042. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3043. string processItem = stationName; // 测试项目
  3044. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3045. string supplierCode = ""; // 供应商代码
  3046. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3047. string batch_num = GlobalContext.BatchNumber; // 批次号
  3048. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3049. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3050. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3051. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  3052. string StationId = string.Empty; // 工位ID(可配置)
  3053. if (direction == "Left")
  3054. {
  3055. StationId = GlobalContext.S7_StationId_1;
  3056. }
  3057. if (direction == "Right")
  3058. {
  3059. StationId = GlobalContext.S7_StationId_2;
  3060. }
  3061. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3062. bool pass = a1Result == 1;
  3063. //根据载具码获取产品码
  3064. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3065. if (string.IsNullOrEmpty(strProductBarcode))
  3066. {
  3067. AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr} 未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3068. }
  3069. sn = strProductBarcode;
  3070. List<TestItem> items = new List<TestItem>();
  3071. items.Add(new TestItem()
  3072. {
  3073. Parameter_name = "载具码",
  3074. Parameter_value = CarrierBarcode,
  3075. Parameter_unit = ""
  3076. });
  3077. items.Add(new TestItem()
  3078. {
  3079. Parameter_name = "产品码",
  3080. Parameter_value = sn,
  3081. Parameter_unit = ""
  3082. });
  3083. //保存PLC返回MES数据到本地
  3084. ResponseMessage message = new ResponseMessage();
  3085. if (direction == "Left")
  3086. {
  3087. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3088. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3089. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3090. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  3091. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3092. if (message.result == false)
  3093. {
  3094. AddMessage(LogType.Error, message.text);
  3095. }
  3096. }
  3097. if (direction == "Right")
  3098. {
  3099. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3100. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3101. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3102. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  3103. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3104. if (message.result == false)
  3105. {
  3106. AddMessage(LogType.Error, message.text);
  3107. }
  3108. }
  3109. //保存螺丝数据到txt
  3110. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes, stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  3111. if (result.Item1 != 0)
  3112. {
  3113. AddMessage(LogType.Error, $"PLC{plcNo}_[{stationNameStr}]-{direction} 螺丝数据保存失败 " + message.text);
  3114. }
  3115. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3116. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3117. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3118. stopwatch2.Start();
  3119. //进站结果写入PLC
  3120. CommandFromPLC resultToPlC = new CommandFromPLC();
  3121. resultToPlC.cmd = 0;
  3122. resultToPlC.cmdParam = 0; //指令参数
  3123. resultToPlC.cmdResult = mesResultFrmWeb;
  3124. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3125. stopwatch2.Stop();
  3126. WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
  3127. }
  3128. catch (Exception ex)
  3129. {
  3130. stopwatch2.Start();
  3131. CommandFromPLC resultToPlC = new CommandFromPLC();
  3132. resultToPlC.cmd = 0;
  3133. resultToPlC.cmdParam = 0; //指令参数
  3134. resultToPlC.cmdResult = 110;
  3135. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3136. stopwatch2.Stop();
  3137. string str = ex.StackTrace;
  3138. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3139. }
  3140. stopwatch1.Stop();
  3141. ProgressState = false;
  3142. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3143. }
  3144. #endregion
  3145. #region S8
  3146. /// <summary>
  3147. /// [S8] 3D螺丝高度检测设备
  3148. /// </summary>
  3149. /// <param name="plcNo">PLC编号</param>
  3150. private void ReadStation_S8(int plcNo)
  3151. {
  3152. string stationCode = "[OP80]";
  3153. string stationName = "NG下料";
  3154. string stationNameStr = stationCode + stationName;
  3155. string tagBaseName = "g_OP80_MES"; //标签变量名称
  3156. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3157. string tagAgvCommName = "agvCommFrmPC";
  3158. string tagBarsetName = "BarcodeSet";
  3159. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  3160. (int, string) result;
  3161. while (true)
  3162. {
  3163. try
  3164. {
  3165. if (!GlobalContext._IsCon_Funs1)
  3166. {
  3167. UpdatePLCMonitor(1, plcNo, 0);
  3168. continue;
  3169. }
  3170. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3171. {
  3172. Stopwatch stopwatch1 = new Stopwatch();
  3173. Stopwatch stopwatch2 = new Stopwatch();
  3174. stopwatch1.Start();
  3175. stopwatch2.Start();
  3176. #region 一次性读取所有数据
  3177. // 一次性读取所有数据
  3178. result = FunsEip[plcNo].Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
  3179. if (result.Item1 != 0)
  3180. {
  3181. //richTextBox1.AppendText("\n" + strRet);
  3182. }
  3183. else
  3184. {
  3185. //richTextBox1.AppendText("\n" + "读取成功");
  3186. }
  3187. #endregion 一次性读取所有数据
  3188. stopwatch2.Stop();
  3189. #region 进站
  3190. try
  3191. {
  3192. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3193. {
  3194. lock (lockObj)
  3195. {
  3196. if (!ProgressState)
  3197. {
  3198. ProgressState = true;
  3199. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3200. }
  3201. }
  3202. }
  3203. }
  3204. catch (Exception ex)
  3205. {
  3206. ProgressState = false;
  3207. string str = ex.StackTrace;
  3208. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3209. }
  3210. #endregion 进站
  3211. #region 出站
  3212. try
  3213. {
  3214. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3215. {
  3216. lock (lockObj)
  3217. {
  3218. if (!ProgressState)
  3219. {
  3220. ProgressState = true;
  3221. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3222. }
  3223. }
  3224. }
  3225. }
  3226. catch (Exception ex)
  3227. {
  3228. ProgressState = false;
  3229. string str = ex.StackTrace;
  3230. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3231. }
  3232. #endregion 进站
  3233. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3234. stopwatch1.Stop();
  3235. OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3236. }
  3237. else
  3238. {
  3239. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3240. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3241. FunsEip[plcNo].Connect(); // 重连
  3242. }
  3243. }
  3244. catch (Exception ex)
  3245. {
  3246. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3247. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3248. }
  3249. Thread.Sleep(IntervalReadPLC);
  3250. }
  3251. }
  3252. /// <summary>
  3253. /// [S8] 3D螺丝高度检测设备 - 进站
  3254. /// </summary>
  3255. /// <param name="plcNo">PLC编号</param>
  3256. /// <param name="stationNameStr">工站全称</param>
  3257. /// <param name="stPLC_MesData"></param>
  3258. /// <param name="tagMesCommName"></param>
  3259. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3260. {
  3261. Stopwatch stopwatch1 = new Stopwatch();
  3262. Stopwatch stopwatch2 = new Stopwatch();
  3263. try
  3264. {
  3265. stopwatch1.Start();
  3266. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3267. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  3268. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  3269. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3270. //载具码验证产品码
  3271. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3272. if (string.IsNullOrEmpty(strProductBarcode))
  3273. {
  3274. AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr} 未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3275. }
  3276. sn = strProductBarcode;
  3277. // 产品SN(物料码)校验
  3278. List<TestItem> item = new List<TestItem>();
  3279. stopwatch2.Start();
  3280. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3281. stopwatch2.Stop();
  3282. //指令执行结果 1:OK 110:失败
  3283. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3284. //进站结果写入PLC
  3285. CommandFromPLC resultToPlC = new CommandFromPLC();
  3286. resultToPlC.cmd = 0;
  3287. resultToPlC.cmdParam = 0; //指令参数
  3288. resultToPlC.cmdResult = mesResultFrmWeb;
  3289. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3290. }
  3291. catch (Exception ex)
  3292. {
  3293. string str = ex.StackTrace;
  3294. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3295. CommandFromPLC resultToPlC = new CommandFromPLC();
  3296. resultToPlC.cmd = 0;
  3297. resultToPlC.cmdParam = 0; //指令参数
  3298. resultToPlC.cmdResult = 110;
  3299. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3300. }
  3301. stopwatch1.Stop();
  3302. ProgressState = false;
  3303. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3304. }
  3305. /// <summary>
  3306. /// [S8] 3D螺丝高度检测设备 - 出站接口
  3307. /// </summary>
  3308. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3309. {
  3310. Stopwatch stopwatch1 = new Stopwatch();
  3311. Stopwatch stopwatch2 = new Stopwatch();
  3312. try
  3313. {
  3314. stopwatch1.Start();
  3315. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3316. string processItem = stationName; // 测试项目
  3317. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3318. string supplierCode = ""; // 供应商代码
  3319. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3320. string batch_num = GlobalContext.BatchNumber; // 批次号
  3321. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3322. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3323. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3324. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  3325. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  3326. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3327. bool pass = a1Result == 1;
  3328. //根据载具码获取产品码
  3329. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3330. if (string.IsNullOrEmpty(strProductBarcode))
  3331. {
  3332. AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr} 未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3333. }
  3334. sn = strProductBarcode;
  3335. List<TestItem> items = new List<TestItem>();
  3336. items.Add(new TestItem()
  3337. {
  3338. Parameter_name = "载具码",
  3339. Parameter_value = CarrierBarcode,
  3340. Parameter_unit = ""
  3341. });
  3342. items.Add(new TestItem()
  3343. {
  3344. Parameter_name = "产品码",
  3345. Parameter_value = sn,
  3346. Parameter_unit = ""
  3347. });
  3348. //保存PLC返回MES数据到本地
  3349. ResponseMessage message = new ResponseMessage();
  3350. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  3351. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3352. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  3353. if (message.result == false)
  3354. {
  3355. AddMessage(LogType.Error, message.text);
  3356. }
  3357. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3358. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3359. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3360. stopwatch2.Start();
  3361. //进站结果写入PLC
  3362. CommandFromPLC resultToPlC = new CommandFromPLC();
  3363. resultToPlC.cmd = 0;
  3364. resultToPlC.cmdParam = 0; //指令参数
  3365. resultToPlC.cmdResult = mesResultFrmWeb;
  3366. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3367. stopwatch2.Stop();
  3368. WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
  3369. }
  3370. catch (Exception ex)
  3371. {
  3372. stopwatch2.Start();
  3373. CommandFromPLC resultToPlC = new CommandFromPLC();
  3374. resultToPlC.cmd = 0;
  3375. resultToPlC.cmdParam = 0; //指令参数
  3376. resultToPlC.cmdResult = 110;
  3377. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3378. stopwatch2.Stop();
  3379. string str = ex.StackTrace;
  3380. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3381. }
  3382. stopwatch1.Stop();
  3383. ProgressState = false;
  3384. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3385. }
  3386. #endregion
  3387. #region S9
  3388. /// <summary>
  3389. /// [S9] 下料设备
  3390. /// </summary>
  3391. /// <param name="plcNo">PLC编号</param>
  3392. private void ReadStation_S9(int plcNo)
  3393. {
  3394. string stationCode = "[OP90]";
  3395. string stationName = "半成品下料";
  3396. string stationNameStr = stationCode + stationName;
  3397. string tagBaseName = "g_OP90_MES"; //标签变量名称
  3398. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3399. string tagAgvCommName = "agvCommFrmPC";
  3400. string tagBarsetName = "BarcodeSet";
  3401. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  3402. (int, string) result;
  3403. while (true)
  3404. {
  3405. try
  3406. {
  3407. if (!GlobalContext._IsCon_Funs1)
  3408. {
  3409. UpdatePLCMonitor(1, plcNo, 0);
  3410. continue;
  3411. }
  3412. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3413. {
  3414. Stopwatch stopwatch1 = new Stopwatch();
  3415. Stopwatch stopwatch2 = new Stopwatch();
  3416. stopwatch1.Start();
  3417. stopwatch2.Start();
  3418. #region 一次性读取所有数据
  3419. // 一次性读取所有数据
  3420. result = FunsEip[plcNo].Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData); //读取单个结构体数据
  3421. if (result.Item1 != 0)
  3422. {
  3423. //richTextBox1.AppendText("\n" + strRet);
  3424. }
  3425. else
  3426. {
  3427. //richTextBox1.AppendText("\n" + "读取成功");
  3428. }
  3429. #endregion 一次性读取所有数据
  3430. stopwatch2.Stop();
  3431. #region 进站
  3432. try
  3433. {
  3434. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3435. {
  3436. lock (lockObj)
  3437. {
  3438. if (!ProgressState)
  3439. {
  3440. ProgressState = true;
  3441. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3442. }
  3443. }
  3444. }
  3445. }
  3446. catch (Exception ex)
  3447. {
  3448. ProgressState = false;
  3449. string str = ex.StackTrace;
  3450. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3451. }
  3452. #endregion 进站
  3453. #region 出站
  3454. try
  3455. {
  3456. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3457. {
  3458. lock (lockObj)
  3459. {
  3460. if (!ProgressState)
  3461. {
  3462. ProgressState = true;
  3463. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3464. }
  3465. }
  3466. }
  3467. }
  3468. catch (Exception ex)
  3469. {
  3470. ProgressState = false;
  3471. string str = ex.StackTrace;
  3472. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3473. }
  3474. #endregion 进站
  3475. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3476. stopwatch1.Stop();
  3477. OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3478. }
  3479. else
  3480. {
  3481. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3482. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3483. FunsEip[plcNo].Connect(); // 重连
  3484. }
  3485. }
  3486. catch (Exception ex)
  3487. {
  3488. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3489. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3490. }
  3491. Thread.Sleep(IntervalReadPLC);
  3492. }
  3493. }
  3494. /// <summary>
  3495. /// [S9] 下料设备 - 进站
  3496. /// </summary>
  3497. /// <param name="plcNo">PLC编号</param>
  3498. /// <param name="stationNameStr">工站全称</param>
  3499. /// <param name="stPLC_MesData"></param>
  3500. /// <param name="tagMesCommName"></param>
  3501. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3502. {
  3503. Stopwatch stopwatch1 = new Stopwatch();
  3504. Stopwatch stopwatch2 = new Stopwatch();
  3505. try
  3506. {
  3507. stopwatch1.Start();
  3508. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3509. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  3510. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  3511. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3512. //载具码验证产品码
  3513. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3514. if (string.IsNullOrEmpty(strProductBarcode))
  3515. {
  3516. AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr} 未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3517. }
  3518. sn = strProductBarcode;
  3519. // 产品SN(物料码)校验
  3520. List<TestItem> item = new List<TestItem>();
  3521. stopwatch2.Start();
  3522. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3523. stopwatch2.Stop();
  3524. //指令执行结果 1:OK 110:失败
  3525. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3526. //进站结果写入PLC
  3527. CommandFromPLC resultToPlC = new CommandFromPLC();
  3528. resultToPlC.cmd = 0;
  3529. resultToPlC.cmdParam = 0; //指令参数
  3530. resultToPlC.cmdResult = mesResultFrmWeb;
  3531. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3532. ////if (!string.IsNullOrEmpty(strProductBarcode) && strProductBarcode != sn)
  3533. ////{
  3534. //// BarcodeSet_t BarcodeToPlc = new BarcodeSet_t();
  3535. //// BarcodeToPlc.strCarrierBarcode = strCarrierBarcode;
  3536. //// BarcodeToPlc.strProductBarcode = sn;
  3537. //// BarcodeToPlc.strPartBarcode = stPLC_MesData.BarcodeSet.strPartBarcode;
  3538. //// FunsEip[plcNo].Write_SingleTag<BarcodeSet_t>(tagBarsetName, 1, BarcodeToPlc);
  3539. ////}
  3540. }
  3541. catch (Exception ex)
  3542. {
  3543. string str = ex.StackTrace;
  3544. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3545. CommandFromPLC resultToPlC = new CommandFromPLC();
  3546. resultToPlC.cmd = 0;
  3547. resultToPlC.cmdParam = 0; //指令参数
  3548. resultToPlC.cmdResult = 110;
  3549. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3550. }
  3551. stopwatch1.Stop();
  3552. ProgressState = false;
  3553. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3554. }
  3555. /// <summary>
  3556. /// [S9] 下料设备 - 出站接口
  3557. /// </summary>
  3558. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3559. {
  3560. Stopwatch stopwatch1 = new Stopwatch();
  3561. Stopwatch stopwatch2 = new Stopwatch();
  3562. try
  3563. {
  3564. stopwatch1.Start();
  3565. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3566. string processItem = stationName; // 测试项目
  3567. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3568. string supplierCode = ""; // 供应商代码
  3569. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3570. string batch_num = GlobalContext.BatchNumber; // 批次号
  3571. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3572. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3573. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3574. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  3575. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  3576. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3577. bool pass = a1Result == 1;
  3578. //根据载具码获取产品码
  3579. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3580. if (string.IsNullOrEmpty(strProductBarcode))
  3581. {
  3582. AddMessage(LogType.Error, $"PLC{plcNo}_{stationNameStr} 未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3583. }
  3584. sn = strProductBarcode;
  3585. List<TestItem> items = new List<TestItem>();
  3586. items.Add(new TestItem()
  3587. {
  3588. Parameter_name = "载具码",
  3589. Parameter_value = CarrierBarcode,
  3590. Parameter_unit = ""
  3591. });
  3592. items.Add(new TestItem()
  3593. {
  3594. Parameter_name = "产品码",
  3595. Parameter_value = sn,
  3596. Parameter_unit = ""
  3597. });
  3598. //保存PLC返回MES数据到本地
  3599. ResponseMessage message = new ResponseMessage();
  3600. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  3601. if (message.result == false)
  3602. {
  3603. AddMessage(LogType.Error, message.text);
  3604. }
  3605. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3606. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3607. if (result1==1)
  3608. {
  3609. //载具码解除绑定
  3610. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  3611. if (message.result == false)
  3612. {
  3613. AddMessage(LogType.Error, message.text);
  3614. }
  3615. }
  3616. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3617. stopwatch2.Start();
  3618. //进站结果写入PLC
  3619. CommandFromPLC resultToPlC = new CommandFromPLC();
  3620. resultToPlC.cmd = 0;
  3621. resultToPlC.cmdParam = 0; //指令参数
  3622. resultToPlC.cmdResult = mesResultFrmWeb;
  3623. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3624. stopwatch2.Stop();
  3625. WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-Write" + (result1 == 1 ? "成功!" : "失败!"));
  3626. }
  3627. catch (Exception ex)
  3628. {
  3629. stopwatch2.Start();
  3630. CommandFromPLC resultToPlC = new CommandFromPLC();
  3631. resultToPlC.cmd = 0;
  3632. resultToPlC.cmdParam = 0; //指令参数
  3633. resultToPlC.cmdResult = 110;
  3634. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3635. stopwatch2.Stop();
  3636. string str = ex.StackTrace;
  3637. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{stationNameStr}]上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3638. }
  3639. stopwatch1.Stop();
  3640. ProgressState = false;
  3641. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3642. }
  3643. #endregion
  3644. #endregion Xiaomi
  3645. #region PLC1 张超凡
  3646. #region [S1] Tray盘上料装备(板测)
  3647. /// <summary>
  3648. /// S1工位的数据- 触发信号上次的值
  3649. /// </summary>
  3650. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  3651. /// <summary>
  3652. /// S1工位的数据(含触发信号)
  3653. /// </summary>
  3654. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  3655. /// <summary>
  3656. /// S1工位的数据- 回写点位
  3657. /// </summary>
  3658. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  3659. ///// <summary>
  3660. ///// 触发信号
  3661. ///// </summary>
  3662. //private ManualResetEvent[] MreTasks;
  3663. /// <summary>
  3664. /// [S1] Tray盘上料装备(板测)
  3665. /// </summary>
  3666. /// <param name="plcNo">PLC编号</param>
  3667. //private void ReadStation_S1(int plcNo)
  3668. //{
  3669. // // [S1] Tray盘上料装备
  3670. // // [S2] FCT
  3671. // // [S3] 值板机
  3672. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  3673. // // [S5] Tray盘下料装备
  3674. // string stationCode = "[S1]";
  3675. // string stationName = "Tray盘上料装备";
  3676. // string stationNameStr = stationCode + stationName;
  3677. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  3678. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  3679. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  3680. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  3681. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  3682. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  3683. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  3684. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  3685. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  3686. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  3687. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  3688. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  3689. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  3690. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  3691. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  3692. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  3693. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  3694. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  3695. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  3696. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  3697. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  3698. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  3699. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  3700. // s1PLCData.Add("a1Result", 0); // 产品结果
  3701. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  3702. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  3703. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  3704. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  3705. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  3706. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  3707. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  3708. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  3709. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  3710. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  3711. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  3712. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  3713. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  3714. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  3715. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  3716. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  3717. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  3718. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  3719. // while (IsRun)
  3720. // {
  3721. // try
  3722. // {
  3723. // if (!GlobalContext._IsCon_Funs1)
  3724. // {
  3725. // UpdatePLCMonitor(1, plcNo, 0);
  3726. // continue;
  3727. // }
  3728. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  3729. // {
  3730. // Stopwatch stopwatch1 = new Stopwatch();
  3731. // Stopwatch stopwatch2 = new Stopwatch();
  3732. // stopwatch1.Start();
  3733. // stopwatch2.Start();
  3734. // #region 一次性读取所有数据
  3735. // // 一次性读取所有数据
  3736. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  3737. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  3738. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  3739. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  3740. // int[] datas = data1.Concat(data2).ToArray();
  3741. // datas = datas.Concat(data3).ToArray();
  3742. // datas = datas.Concat(data4).ToArray();
  3743. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  3744. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  3745. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  3746. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  3747. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  3748. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  3749. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  3750. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  3751. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  3752. // s1PLCData["a1MES_FLAG"] = datas[109];
  3753. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  3754. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  3755. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  3756. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  3757. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  3758. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  3759. // s1PLCData["a1Result"] = datas[170];
  3760. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  3761. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  3762. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  3763. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  3764. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  3765. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  3766. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  3767. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  3768. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  3769. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  3770. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  3771. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  3772. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  3773. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  3774. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  3775. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  3776. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  3777. // s1PLCData["a1AGVUpStart"] = datas[308];
  3778. // s1PLCData["a1AGVUpEnd"] = datas[309];
  3779. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  3780. // s1PLCData["a1AGVDownStart"] = datas[321];
  3781. // s1PLCData["a1AGVDownEnd"] = datas[322];
  3782. // #endregion 一次性读取所有数据
  3783. // stopwatch2.Stop();
  3784. // #region 回写操作,写后清空flag
  3785. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  3786. // #endregion 回写操作,写后清空flag
  3787. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  3788. // try
  3789. // {
  3790. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  3791. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  3792. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  3793. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  3794. // {
  3795. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  3796. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  3797. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  3798. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  3799. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  3800. // }
  3801. // }
  3802. // catch (Exception ex)
  3803. // {
  3804. // // 6代表上位机报警
  3805. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  3806. // string str = ex.StackTrace;
  3807. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3808. // }
  3809. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  3810. // #region 上料进站校验
  3811. // try
  3812. // {
  3813. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  3814. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  3815. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  3816. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  3817. // {
  3818. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  3819. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  3820. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  3821. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  3822. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  3823. // }
  3824. // }
  3825. // catch (Exception ex)
  3826. // {
  3827. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  3828. // string str = ex.StackTrace;
  3829. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3830. // }
  3831. // #endregion 上料进站校验
  3832. // #region Tray盘上料装备-出站接口
  3833. // try
  3834. // {
  3835. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  3836. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  3837. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  3838. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  3839. // {
  3840. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  3841. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  3842. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  3843. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  3844. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  3845. // }
  3846. // }
  3847. // catch (Exception ex)
  3848. // {
  3849. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  3850. // string str = ex.StackTrace;
  3851. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3852. // }
  3853. // #endregion Tray盘上料装备-出站接口
  3854. // #region Tray盘上料装备-将SN发给ICT标机
  3855. // try
  3856. // {
  3857. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  3858. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  3859. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  3860. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  3861. // {
  3862. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  3863. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  3864. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  3865. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  3866. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  3867. // }
  3868. // }
  3869. // catch (Exception ex)
  3870. // {
  3871. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  3872. // string str = ex.StackTrace;
  3873. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3874. // }
  3875. // #endregion Tray盘上料装备-将SN发给ICT标机
  3876. // #region Tray盘上料装备-点检数据
  3877. // //try
  3878. // //{
  3879. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  3880. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  3881. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  3882. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  3883. // // if (pLC_Flag && !mES_Flag) // 1 0
  3884. // // {
  3885. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  3886. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  3887. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  3888. // // }
  3889. // // else if (!pLC_Flag && mES_Flag) // 0 1
  3890. // // {
  3891. // // // 清空写给PLC的数据
  3892. // // // MES_Flag重置为0
  3893. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  3894. // // }
  3895. // //}
  3896. // //catch (Exception ex)
  3897. // //{
  3898. // // // MES_Flag 为2上位机报错
  3899. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  3900. // // string str = ex.StackTrace;
  3901. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3902. // //}
  3903. // #endregion Tray盘上料装备-点检数据
  3904. // #region 节拍接口
  3905. // try
  3906. // {
  3907. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  3908. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  3909. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  3910. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  3911. // {
  3912. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  3913. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  3914. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  3915. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  3916. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  3917. // }
  3918. // }
  3919. // catch (Exception ex)
  3920. // {
  3921. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  3922. // string str = ex.StackTrace;
  3923. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3924. // }
  3925. // #endregion 节拍接口
  3926. // #region AGV上料
  3927. // // AGV上料叫AGV信号
  3928. // try
  3929. // {
  3930. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  3931. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  3932. // if (a1AGVUpCall != a1AGVUpCallOld)
  3933. // {
  3934. // if (a1AGVUpCall == 1) // 0->1
  3935. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  3936. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  3937. // }
  3938. // }
  3939. // catch (Exception ex)
  3940. // {
  3941. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  3942. // string str = ex.StackTrace;
  3943. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3944. // }
  3945. // // AGV上料完成信号
  3946. // try
  3947. // {
  3948. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  3949. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  3950. // if (a1AGVUpEnd != a1AGVUpEndOld)
  3951. // {
  3952. // if (a1AGVUpEnd == 1) // 0->1
  3953. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  3954. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  3955. // }
  3956. // }
  3957. // catch (Exception ex)
  3958. // {
  3959. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  3960. // string str = ex.StackTrace;
  3961. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3962. // }
  3963. // #endregion AGV上料
  3964. // #region AGV下料
  3965. // // AGV下料叫agv信号
  3966. // try
  3967. // {
  3968. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  3969. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  3970. // if (a1AGVDownCall != a1AGVDownCallOld)
  3971. // {
  3972. // if (a1AGVDownCall == 1) // 0->1
  3973. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  3974. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  3975. // }
  3976. // }
  3977. // catch (Exception ex)
  3978. // {
  3979. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  3980. // string str = ex.StackTrace;
  3981. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3982. // }
  3983. // // AGV下料完成信号
  3984. // try
  3985. // {
  3986. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  3987. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  3988. // if (a1AGVDownEnd != a1AGVDownEndOld)
  3989. // {
  3990. // if (a1AGVDownEnd == 1) // 0->1
  3991. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  3992. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  3993. // }
  3994. // }
  3995. // catch (Exception ex)
  3996. // {
  3997. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  3998. // string str = ex.StackTrace;
  3999. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4000. // }
  4001. // #endregion AGV下料
  4002. // #region 心跳
  4003. // try
  4004. // {
  4005. // short states = 0;
  4006. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  4007. // }
  4008. // catch (Exception ex)
  4009. // {
  4010. // string str = ex.StackTrace;
  4011. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4012. // }
  4013. // #endregion 心跳
  4014. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4015. // stopwatch1.Stop();
  4016. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  4017. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4018. // }
  4019. // else
  4020. // {
  4021. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4022. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4023. // Funs[plcNo].Connect(); // 重连
  4024. // }
  4025. // }
  4026. // catch (Exception ex)
  4027. // {
  4028. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4029. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4030. // Funs[plcNo].ReConnect();
  4031. // }
  4032. // Thread.Sleep(IntervalReadPLC);
  4033. // }
  4034. //}
  4035. /// <summary>
  4036. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  4037. /// </summary>
  4038. /// <param name="plcNo">PLC编号</param>
  4039. /// <param name="stationNameStr">工站全称</param>
  4040. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  4041. {
  4042. Stopwatch stopwatch1 = new Stopwatch();
  4043. Stopwatch stopwatch2 = new Stopwatch();
  4044. try
  4045. {
  4046. stopwatch1.Start();
  4047. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  4048. sn = sn.Replace("\0", "");
  4049. #region 查询载具上的产品信息
  4050. string cavityData = string.Empty;
  4051. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  4052. if (string.IsNullOrEmpty(cavityData))
  4053. cavityData = "";
  4054. if (snResult != 0)
  4055. {
  4056. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4057. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  4058. writeToPLC_Flag1.Adress = 2003;
  4059. writeToPLC_Flag1.Value = (short)6;
  4060. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  4061. stopwatch1.Stop();
  4062. AddMessage(LogType.Info, stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  4063. return;
  4064. }
  4065. #endregion 查询载具上的产品信息
  4066. string[] cavitySNs = cavityData.Split('.');
  4067. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  4068. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  4069. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  4070. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  4071. if (cavitySNs != null && cavitySNs.Length >= 2)
  4072. {
  4073. a1CavitySN1_VehicleStates = cavitySNs[0];
  4074. a1CavitySN2_VehicleStates = cavitySNs[1];
  4075. a1CavityResult1_VehicleStates = 2;
  4076. a1CavityResult2_VehicleStates = 2;
  4077. }
  4078. if (a1CavitySN1_VehicleStates == "假产品")
  4079. a1CavityResult1_VehicleStates = 3;
  4080. if (a1CavitySN2_VehicleStates == "假产品")
  4081. a1CavityResult2_VehicleStates = 3;
  4082. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4083. // 回写
  4084. stopwatch2.Start();
  4085. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  4086. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  4087. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  4088. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  4089. //// MES_Flag
  4090. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  4091. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4092. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4093. writeToPLC_Flag.Adress = 2003;
  4094. writeToPLC_Flag.Value = mES_Flag;
  4095. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  4096. {
  4097. Name = "a1CavitySN1_VehicleStates",
  4098. Adress = 2024,
  4099. ValueType = PLCValueType.String,
  4100. ValueTypeStrLength = 20,
  4101. Value = a1CavitySN1_VehicleStates
  4102. });
  4103. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  4104. {
  4105. Name = "a1CavitySN2_VehicleStates",
  4106. Adress = 2044,
  4107. ValueType = PLCValueType.String,
  4108. ValueTypeStrLength = 20,
  4109. Value = a1CavitySN2_VehicleStates
  4110. });
  4111. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4112. {
  4113. Name = "a1CavityResult1_VehicleStates",
  4114. Adress = 2064,
  4115. ValueType = PLCValueType.Short,
  4116. Value = a1CavityResult1_VehicleStates
  4117. });
  4118. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4119. {
  4120. Name = "a1CavityResult2_VehicleStates",
  4121. Adress = 2065,
  4122. ValueType = PLCValueType.Short,
  4123. Value = a1CavityResult2_VehicleStates
  4124. });
  4125. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4126. stopwatch2.Stop();
  4127. }
  4128. catch (Exception ex)
  4129. {
  4130. string str = ex.StackTrace;
  4131. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4132. // MES_Flag
  4133. stopwatch2.Start();
  4134. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  4135. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4136. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4137. writeToPLC_Flag.Adress = 2003;
  4138. writeToPLC_Flag.Value = (short)6;
  4139. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4140. stopwatch2.Stop();
  4141. }
  4142. stopwatch1.Stop();
  4143. AddMessage(LogType.Info, stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4144. }
  4145. /// <summary>
  4146. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  4147. /// </summary>
  4148. /// <param name="plcNo">PLC编号</param>
  4149. /// <param name="stationNameStr">工站全称</param>
  4150. private void S1上料进站校验(int plcNo, string stationNameStr)
  4151. {
  4152. Stopwatch stopwatch1 = new Stopwatch();
  4153. Stopwatch stopwatch2 = new Stopwatch();
  4154. try
  4155. {
  4156. stopwatch1.Start();
  4157. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  4158. sn = sn.Replace("\0", "");
  4159. // 保存进站数据+调用进站MES接口
  4160. List<TestItem> item = new List<TestItem>();
  4161. stopwatch2.Start();
  4162. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, out string errorMsg);
  4163. stopwatch2.Stop();
  4164. short a1MES_FLAG_Check = (short)result;
  4165. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4166. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4167. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4168. writeToPLC_Flag.Adress = 2077;
  4169. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  4170. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4171. }
  4172. catch (Exception ex)
  4173. {
  4174. string str = ex.StackTrace;
  4175. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4176. // MES_Flag
  4177. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4178. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4179. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4180. writeToPLC_Flag.Adress = 2077;
  4181. writeToPLC_Flag.Value = (short)6;
  4182. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4183. }
  4184. stopwatch1.Stop();
  4185. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4186. }
  4187. /// <summary>
  4188. /// [S1] Tray盘上料装备(板测)- 出站接口
  4189. /// </summary>
  4190. /// <param name="plcNo"></param>
  4191. /// <param name="stationCode"></param>
  4192. /// <param name="stationName"></param>
  4193. private void S1出站接口(int plcNo, string stationCode, string stationName)
  4194. {
  4195. Stopwatch stopwatch1 = new Stopwatch();
  4196. Stopwatch stopwatch2 = new Stopwatch();
  4197. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4198. string stationNameStr = stationCode + stationName;
  4199. string processItem = stationName; // 测试项目
  4200. try
  4201. {
  4202. stopwatch1.Start();
  4203. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4204. //string batch_num = GlobalContext.BatchNumber; // 批次号
  4205. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4206. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4207. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  4208. sn = sn.Replace("\0", "");
  4209. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  4210. partNo1 = partNo1.Replace("\0", "");
  4211. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  4212. partNo2 = partNo2.Replace("\0", "");
  4213. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  4214. bool pass = a1Result == 1;
  4215. stopwatch2.Start();
  4216. // 产品1
  4217. List<TestItem> items = new List<TestItem>();
  4218. items.Add(new TestItem()
  4219. {
  4220. Parameter_name = "载具码",
  4221. Parameter_value = sn,
  4222. Parameter_unit = ""
  4223. });
  4224. items.Add(new TestItem()
  4225. {
  4226. Parameter_name = "载具穴号",
  4227. Parameter_value = "1",
  4228. Parameter_unit = ""
  4229. });
  4230. items.Add(new TestItem()
  4231. {
  4232. Parameter_name = "产品结果",
  4233. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4234. Parameter_unit = ""
  4235. });
  4236. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4237. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  4238. // 产品2
  4239. items = new List<TestItem>();
  4240. items.Add(new TestItem()
  4241. {
  4242. Parameter_name = "载具码",
  4243. Parameter_value = sn,
  4244. Parameter_unit = ""
  4245. });
  4246. items.Add(new TestItem()
  4247. {
  4248. Parameter_name = "载具穴号",
  4249. Parameter_value = "2",
  4250. Parameter_unit = ""
  4251. });
  4252. items.Add(new TestItem()
  4253. {
  4254. Parameter_name = "产品结果",
  4255. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4256. Parameter_unit = ""
  4257. });
  4258. int result2 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4259. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  4260. short result = 0;
  4261. List<int> results = new List<int>() { result1, result2 };
  4262. if (result1 == 1 && result2 == 1)
  4263. result = 1;
  4264. else if (results.Contains(3))
  4265. result = 3;
  4266. else if (results.Contains(2))
  4267. result = 2;
  4268. else if (results.Contains(4))
  4269. result = 4;
  4270. else
  4271. result = 4;
  4272. stopwatch2.Stop();
  4273. #region 存储绑定数据到 边线MES系统中
  4274. if (result == 1)
  4275. {
  4276. string data = string.Concat(partNo1, ".", partNo2);
  4277. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  4278. if (resultMesR != 0)
  4279. {
  4280. result = 4;
  4281. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  4282. }
  4283. }
  4284. #endregion 存储绑定数据到 边线MES系统中
  4285. // MES_Flag 为MES报错
  4286. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4287. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  4288. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4289. writeToPLC_Flag.Name = "a1MES_FLAG";
  4290. writeToPLC_Flag.Adress = 2109;
  4291. writeToPLC_Flag.Value = result;
  4292. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4293. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4294. }
  4295. catch (Exception ex)
  4296. {
  4297. stopwatch2.Restart();
  4298. // MES_Flag 为4上位机报错
  4299. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  4300. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4301. writeToPLC_Flag.Name = "a1MES_FLAG";
  4302. writeToPLC_Flag.Adress = 2109;
  4303. writeToPLC_Flag.Value = (short)4;
  4304. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4305. stopwatch2.Stop();
  4306. string str = ex.StackTrace;
  4307. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4308. }
  4309. stopwatch1.Stop();
  4310. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4311. }
  4312. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  4313. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  4314. //{
  4315. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4316. // string stationNameStr = stationCode + stationName;
  4317. // string processItem = stationName; // 测试项目
  4318. // try
  4319. // {
  4320. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4321. // string accno = "1"; // 工序编号
  4322. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  4323. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  4324. // List<OneCheckItem> items = new List<OneCheckItem>()
  4325. // {
  4326. // new OneCheckItem()
  4327. // {
  4328. // Onecheck_name="胶圈装配行程设定上限",
  4329. // Onecheck_content="上限值",
  4330. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  4331. // },
  4332. // };
  4333. // OneCheckData oneCheckData = new OneCheckData()
  4334. // {
  4335. // Line_code = GlobalContext.LineCode,
  4336. // Line_name = GlobalContext.LineName,
  4337. // Equipment_code = equipmentCode,
  4338. // Equipment_name = equipmentCode,
  4339. // Workorder_code = workorder_code,
  4340. // Procedure_code = accno,
  4341. // Procedure_name = processItem,
  4342. // Oneckeck_values = items,
  4343. // Onecheck_empcode = "",
  4344. // Onecheck_empname = "",
  4345. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  4346. // };
  4347. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  4348. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  4349. // short result = result1 == 1 ? (short)1 : (short)2;
  4350. // // MES_Flag 为4MES报错
  4351. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  4352. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4353. // }
  4354. // catch (Exception ex)
  4355. // {
  4356. // // MES_Flag 为2上位机报错
  4357. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4358. // string str = ex.StackTrace;
  4359. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4360. // }
  4361. //}
  4362. // ReadStation_S1_2 节拍接口+AGV
  4363. /// <summary>
  4364. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  4365. /// </summary>
  4366. /// <param name="plcNo">PLC编号</param>
  4367. /// <param name="stationNameStr">工站全称</param>
  4368. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  4369. {
  4370. Stopwatch stopwatch1 = new Stopwatch();
  4371. Stopwatch stopwatch2 = new Stopwatch();
  4372. try
  4373. {
  4374. stopwatch1.Start();
  4375. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  4376. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  4377. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  4378. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  4379. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  4380. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  4381. // ZS 将SN发给ICT标机(串口)
  4382. short a1MES_FLAG_ICT = 1;
  4383. stopwatch2.Start();
  4384. // MES_Flag
  4385. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  4386. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4387. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4388. writeToPLC_Flag.Adress = 2182;
  4389. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  4390. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4391. stopwatch2.Stop();
  4392. }
  4393. catch (Exception ex)
  4394. {
  4395. string str = ex.StackTrace;
  4396. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4397. stopwatch2.Start();
  4398. // MES_Flag
  4399. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4400. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4401. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4402. writeToPLC_Flag.Adress = 2182;
  4403. writeToPLC_Flag.Value = (short)4;
  4404. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4405. stopwatch2.Stop();
  4406. }
  4407. stopwatch1.Stop();
  4408. AddMessage(LogType.Info, stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4409. }
  4410. /// <summary>
  4411. /// [S1] Tray盘上料装备(板测)- 节拍接口
  4412. /// </summary>
  4413. /// <param name="plcNo">PLC编号</param>
  4414. /// <param name="stationNameStr">工站全称</param>
  4415. private void S1节拍接口(int plcNo, string stationNameStr)
  4416. {
  4417. Stopwatch stopwatch1 = new Stopwatch();
  4418. Stopwatch stopwatch2 = new Stopwatch();
  4419. string resultStr = string.Empty;
  4420. try
  4421. {
  4422. stopwatch1.Start();
  4423. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  4424. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  4425. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  4426. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  4427. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  4428. string a1OEEPartNum = ((int)s1PLCData["a1OEEPartNum"]).ToString(); // 穴位号
  4429. a1OEEPartNum = a1OEEPartNum.Replace("\0", "");
  4430. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4431. if (!actionBool)
  4432. {
  4433. stopwatch2.Start();
  4434. // MES_Flag
  4435. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4436. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4437. writeToPLC_Flag1.Name = "a1OEEMES_FLAG";
  4438. writeToPLC_Flag1.Adress = 2254;
  4439. writeToPLC_Flag1.Value = (short)1;
  4440. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag1);
  4441. stopwatch2.Stop();
  4442. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4443. return;
  4444. }
  4445. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode))
  4446. {
  4447. stopwatch2.Start();
  4448. // MES_Flag
  4449. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4450. WriteToPLC_Flag writeToPLC_Flag2 = new WriteToPLC_Flag(); // MES_Flag
  4451. writeToPLC_Flag2.Name = "a1OEEMES_FLAG";
  4452. writeToPLC_Flag2.Adress = 2254;
  4453. writeToPLC_Flag2.Value = (short)1;
  4454. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag2);
  4455. stopwatch2.Stop();
  4456. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4457. return;
  4458. }
  4459. else if (string.IsNullOrEmpty(a1OEEPartNo) && !string.IsNullOrEmpty(a1OEEVehicleCode))
  4460. { // 查产品SN
  4461. a1OEEPartNo = "Test"; // ZS
  4462. }
  4463. short a1OEEMES_FLAG = 0;
  4464. // 上传OEE
  4465. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  4466. a1OEEMES_FLAG = result.Item1;
  4467. resultStr = result.Item2;
  4468. stopwatch2.Start();
  4469. // MES_Flag
  4470. //Funs[plcNo].WriteMultipleRegisters<short>(2254, a1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4471. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4472. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  4473. writeToPLC_Flag.Adress = 2254;
  4474. writeToPLC_Flag.Value = a1OEEMES_FLAG;
  4475. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  4476. stopwatch2.Stop();
  4477. }
  4478. catch (Exception ex)
  4479. {
  4480. string str = ex.StackTrace;
  4481. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4482. // MES_Flag
  4483. stopwatch2.Start();
  4484. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4485. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4486. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  4487. writeToPLC_Flag.Adress = 2254;
  4488. writeToPLC_Flag.Value = (short)4;
  4489. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  4490. stopwatch2.Stop();
  4491. }
  4492. stopwatch1.Stop();
  4493. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4494. }
  4495. /// <summary>
  4496. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  4497. /// </summary>
  4498. /// <param name="plcNo">PLC编号</param>
  4499. /// <param name="stationNameStr">工站全称</param>
  4500. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  4501. {
  4502. Stopwatch stopwatch1 = new Stopwatch();
  4503. Stopwatch stopwatch2 = new Stopwatch();
  4504. try
  4505. {
  4506. stopwatch1.Start();
  4507. // ZS 呼叫AGV
  4508. short a1AGVUpCall = 2;
  4509. stopwatch2.Start();
  4510. // a1AGVUpCall
  4511. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4512. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4513. writeToPLC_Flag.Name = "a1AGVUpCall";
  4514. writeToPLC_Flag.Adress = 2307;
  4515. writeToPLC_Flag.Value = a1AGVUpCall;
  4516. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  4517. stopwatch2.Stop();
  4518. }
  4519. catch (Exception ex)
  4520. {
  4521. string str = ex.StackTrace;
  4522. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4523. // a1AGVUpCall
  4524. stopwatch2.Start();
  4525. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4526. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4527. writeToPLC_Flag.Name = "a1AGVUpCall";
  4528. writeToPLC_Flag.Adress = 2307;
  4529. writeToPLC_Flag.Value = (short)4;
  4530. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  4531. stopwatch2.Stop();
  4532. }
  4533. stopwatch1.Stop();
  4534. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4535. }
  4536. /// <summary>
  4537. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  4538. /// </summary>
  4539. /// <param name="plcNo">PLC编号</param>
  4540. /// <param name="stationNameStr">工站全称</param>
  4541. private void S1AGV上料完成(int plcNo, string stationNameStr)
  4542. {
  4543. Stopwatch stopwatch1 = new Stopwatch();
  4544. Stopwatch stopwatch2 = new Stopwatch();
  4545. try
  4546. {
  4547. stopwatch1.Start();
  4548. // ZS AGV上料完成,让小车离开
  4549. short a1AGVUpEnd = 2;
  4550. stopwatch2.Start();
  4551. // a1AGVUpEnd
  4552. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4553. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4554. writeToPLC_Flag.Name = "a1AGVUpEnd";
  4555. writeToPLC_Flag.Adress = 2309;
  4556. writeToPLC_Flag.Value = a1AGVUpEnd;
  4557. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  4558. stopwatch2.Stop();
  4559. }
  4560. catch (Exception ex)
  4561. {
  4562. string str = ex.StackTrace;
  4563. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4564. // a1AGVUpEnd
  4565. stopwatch2.Start();
  4566. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  4567. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4568. writeToPLC_Flag.Name = "a1AGVUpEnd";
  4569. writeToPLC_Flag.Adress = 2309;
  4570. writeToPLC_Flag.Value = (short)4;
  4571. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  4572. stopwatch2.Stop();
  4573. }
  4574. stopwatch1.Stop();
  4575. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4576. }
  4577. /// <summary>
  4578. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  4579. /// </summary>
  4580. /// <param name="plcNo">PLC编号</param>
  4581. /// <param name="stationNameStr">工站全称</param>
  4582. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  4583. {
  4584. Stopwatch stopwatch1 = new Stopwatch();
  4585. Stopwatch stopwatch2 = new Stopwatch();
  4586. try
  4587. {
  4588. stopwatch1.Start();
  4589. // ZS 呼叫AGV
  4590. short a1AGVDownCall = 2;
  4591. stopwatch2.Start();
  4592. // a1AGVDownCall
  4593. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4594. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4595. writeToPLC_Flag.Name = "a1AGVDownCall";
  4596. writeToPLC_Flag.Adress = 2320;
  4597. writeToPLC_Flag.Value = a1AGVDownCall;
  4598. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  4599. stopwatch2.Stop();
  4600. }
  4601. catch (Exception ex)
  4602. {
  4603. string str = ex.StackTrace;
  4604. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4605. // a1AGVDownCall
  4606. stopwatch2.Start();
  4607. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  4608. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4609. writeToPLC_Flag.Name = "a1AGVDownCall";
  4610. writeToPLC_Flag.Adress = 2320;
  4611. writeToPLC_Flag.Value = (short)4;
  4612. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  4613. stopwatch2.Stop();
  4614. }
  4615. stopwatch1.Stop();
  4616. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4617. }
  4618. /// <summary>
  4619. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  4620. /// </summary>
  4621. /// <param name="plcNo">PLC编号</param>
  4622. /// <param name="stationNameStr">工站全称</param>
  4623. private void S1AGV下料完成(int plcNo, string stationNameStr)
  4624. {
  4625. Stopwatch stopwatch1 = new Stopwatch();
  4626. Stopwatch stopwatch2 = new Stopwatch();
  4627. try
  4628. {
  4629. stopwatch1.Start();
  4630. // ZS AGV上料完成,让小车离开
  4631. short a1AGVDownEnd = 2;
  4632. stopwatch2.Start();
  4633. // a1AGVDownEnd
  4634. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4635. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4636. writeToPLC_Flag.Name = "a1AGVDownEnd";
  4637. writeToPLC_Flag.Adress = 2322;
  4638. writeToPLC_Flag.Value = a1AGVDownEnd;
  4639. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  4640. stopwatch2.Stop();
  4641. }
  4642. catch (Exception ex)
  4643. {
  4644. string str = ex.StackTrace;
  4645. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4646. // a1AGVDownEnd
  4647. stopwatch2.Start();
  4648. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  4649. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4650. writeToPLC_Flag.Name = "a1AGVDownEnd";
  4651. writeToPLC_Flag.Adress = 2322;
  4652. writeToPLC_Flag.Value = (short)4;
  4653. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  4654. stopwatch2.Stop();
  4655. }
  4656. stopwatch1.Stop();
  4657. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4658. }
  4659. #endregion [S1] Tray盘上料装备(板测)
  4660. #endregion PLC1 张超凡
  4661. #region PLC2 李晓奇
  4662. #region [S2] FCT(板测)
  4663. /// <summary>
  4664. /// S2工位的数据- 触发信号上次的值
  4665. /// </summary>
  4666. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  4667. /// <summary>
  4668. /// S2工位的数据(含触发信号)
  4669. /// </summary>
  4670. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  4671. /// <summary>
  4672. /// S2工位的数据- 回写点位
  4673. /// </summary>
  4674. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  4675. /// <summary>
  4676. /// [S2] FCT(板测)
  4677. /// </summary>
  4678. /// <param name="plcNo">PLC编号</param>
  4679. //private void ReadStation_S2(int plcNo)
  4680. //{
  4681. // // [S1] Tray盘上料装备
  4682. // // [S2] FCT
  4683. // // [S3] 值板机
  4684. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  4685. // // [S5] Tray盘下料装备
  4686. // /// 上位机心跳
  4687. // /// 获取设备报警数据与状态信息
  4688. // string stationCode = "[S2]";
  4689. // string stationName = "FCT";
  4690. // string stationNameStr = stationCode + stationName;
  4691. // #region 创建字典
  4692. // // 触发信号字典 赋值
  4693. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  4694. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  4695. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4696. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4697. // // PLC数据字典 赋值
  4698. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  4699. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  4700. // s2PLCData.Add("b1ProductSN_Check", 0);
  4701. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  4702. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  4703. // s2PLCData.Add("b1ProductSN_Unbind", "");
  4704. // s2PLCData.Add("b1ProductSN_Bind", "");
  4705. // s2PLCData.Add("b1Part1SN_Bind", "");
  4706. // s2PLCData.Add("b1Part2SN_Bind", "");
  4707. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  4708. // s2PLCData.Add("b1MES_FLAG", 0);
  4709. // s2PLCData.Add("b1ProductSN", 0);
  4710. // s2PLCData.Add("b1Part1Result", 0);
  4711. // s2PLCData.Add("b1Part2Result", 0);
  4712. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  4713. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  4714. // s2PLCData.Add("b1OEEProductSN", "");
  4715. // s2PLCData.Add("b1OEEType", 0);
  4716. // #endregion 创建字典
  4717. // while (IsRun)
  4718. // {
  4719. // try
  4720. // {
  4721. // if (!GlobalContext._IsCon_Funs2)
  4722. // {
  4723. // UpdatePLCMonitor(1, plcNo, 0);
  4724. // continue;
  4725. // }
  4726. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  4727. // {
  4728. // Stopwatch stopwatch1 = new Stopwatch();
  4729. // Stopwatch stopwatch2 = new Stopwatch();
  4730. // stopwatch1.Start();
  4731. // stopwatch2.Start();
  4732. // #region 一次性读取所有数据
  4733. // // 一次性读取所有数据
  4734. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  4735. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  4736. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  4737. // int[] datas = data1.Concat(data2).ToArray();
  4738. // datas = datas.Concat(data3).ToArray();
  4739. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  4740. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  4741. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  4742. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  4743. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  4744. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  4745. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  4746. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  4747. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  4748. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  4749. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  4750. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  4751. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  4752. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  4753. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  4754. // s2PLCData["b1MES_FLAG"] = datas[169];
  4755. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  4756. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  4757. // s2PLCData["b1Part1Result"] = datas[190];
  4758. // s2PLCData["b1Part2Result"] = datas[191];
  4759. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  4760. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  4761. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  4762. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  4763. // s2PLCData["b1OEEType"] = datas[224];
  4764. // #endregion 一次性读取所有数据
  4765. // stopwatch2.Stop();
  4766. // #region 回写操作,写后清空flag
  4767. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  4768. // #endregion 回写操作,写后清空flag
  4769. // #region 进站校验
  4770. // try
  4771. // {
  4772. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  4773. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  4774. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  4775. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  4776. // {
  4777. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  4778. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  4779. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  4780. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  4781. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  4782. // }
  4783. // }
  4784. // catch (Exception ex)
  4785. // {
  4786. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  4787. // string str = ex.StackTrace;
  4788. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4789. // }
  4790. // #endregion 进站校验
  4791. // #region 二穴载具解绑/绑定(产品换载具)
  4792. // try
  4793. // {
  4794. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  4795. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  4796. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  4797. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  4798. // {
  4799. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  4800. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  4801. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  4802. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  4803. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  4804. // }
  4805. // }
  4806. // catch (Exception ex)
  4807. // {
  4808. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4809. // string str = ex.StackTrace;
  4810. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4811. // }
  4812. // #endregion 二穴载具解绑/绑定(产品换载具)
  4813. // #region FCT-出站接口
  4814. // try
  4815. // {
  4816. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  4817. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  4818. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  4819. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  4820. // {
  4821. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  4822. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  4823. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  4824. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  4825. // }
  4826. // }
  4827. // catch (Exception ex)
  4828. // {
  4829. // // MES_Flag 为6上位机报错
  4830. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  4831. // string str = ex.StackTrace;
  4832. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4833. // }
  4834. // #endregion FCT-出站接口
  4835. // #region 节拍接口
  4836. // try
  4837. // {
  4838. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  4839. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  4840. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  4841. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  4842. // {
  4843. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  4844. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  4845. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  4846. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  4847. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  4848. // }
  4849. // }
  4850. // catch (Exception ex)
  4851. // {
  4852. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  4853. // string str = ex.StackTrace;
  4854. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4855. // }
  4856. // #endregion 节拍接口
  4857. // #region 心跳
  4858. // try
  4859. // {
  4860. // short states = 0;
  4861. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  4862. // }
  4863. // catch (Exception ex)
  4864. // {
  4865. // string str = ex.StackTrace;
  4866. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4867. // }
  4868. // #endregion 心跳
  4869. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4870. // stopwatch1.Stop();
  4871. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  4872. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4873. // }
  4874. // else
  4875. // {
  4876. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4877. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4878. // Funs[plcNo].Connect();
  4879. // }
  4880. // }
  4881. // catch (Exception ex)
  4882. // {
  4883. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4884. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4885. // Funs[plcNo].ReConnect();
  4886. // }
  4887. // Thread.Sleep(IntervalReadPLC);
  4888. // }
  4889. //}
  4890. /// <summary>
  4891. /// [S2] FCT(板测)- 进站校验
  4892. /// </summary>
  4893. /// <param name="plcNo">PLC编号</param>
  4894. /// <param name="stationNameStr">工站全称</param>
  4895. private void S2进站校验(int plcNo, string stationNameStr)
  4896. {
  4897. Stopwatch stopwatch1 = new Stopwatch();
  4898. Stopwatch stopwatch2 = new Stopwatch();
  4899. try
  4900. {
  4901. stopwatch1.Start();
  4902. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  4903. sn = sn.Replace("\0", "");
  4904. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  4905. // 查询物料码By载具码 并判断是不是假产品
  4906. string cavityData = string.Empty;
  4907. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  4908. if (string.IsNullOrEmpty(cavityData))
  4909. cavityData = "";
  4910. if (snResult != 0)
  4911. {
  4912. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4913. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  4914. writeToPLC_Flag1.Adress = 2003;
  4915. writeToPLC_Flag1.Value = (short)6;
  4916. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  4917. stopwatch1.Stop();
  4918. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  4919. return;
  4920. }
  4921. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  4922. string[] cavitySNs = cavityData.Split('.');
  4923. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  4924. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  4925. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  4926. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  4927. if (cavitySNs != null && cavitySNs.Length >= 2)
  4928. {
  4929. b1Part1SN_Check = cavitySNs[0];
  4930. b1Part2SN_Check = cavitySNs[1];
  4931. b1Part1Result_Check = 2;
  4932. b1Part2Result_Check = 2;
  4933. }
  4934. if (b1Part1SN_Check == "假产品")
  4935. b1Part1Result_Check = 3;
  4936. if (b1Part2SN_Check == "假产品")
  4937. b1Part2Result_Check = 3;
  4938. // 调用MES进站
  4939. stopwatch2.Start();
  4940. // 调用MES进站 - 产品1
  4941. List<TestItem> item;
  4942. int result1 = b1Part1Result_Check;
  4943. if (result1 != 3)
  4944. {
  4945. item = new List<TestItem>();
  4946. item.Add(new TestItem()
  4947. {
  4948. Parameter_name = "载具码",
  4949. Parameter_value = sn,
  4950. });
  4951. item.Add(new TestItem()
  4952. {
  4953. Parameter_name = "载具穴号",
  4954. Parameter_value = "1",
  4955. });
  4956. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part1SN_Check, item, out string errorMsg);
  4957. }
  4958. // 调用MES进站 - 产品2
  4959. int result2 = b1Part2Result_Check;
  4960. if (result2 != 3)
  4961. {
  4962. item = new List<TestItem>();
  4963. item.Add(new TestItem()
  4964. {
  4965. Parameter_name = "载具码",
  4966. Parameter_value = sn,
  4967. });
  4968. item.Add(new TestItem()
  4969. {
  4970. Parameter_name = "载具穴号",
  4971. Parameter_value = "2",
  4972. });
  4973. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part2SN_Check, item, out string errorMsg);
  4974. }
  4975. stopwatch2.Stop();
  4976. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  4977. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  4978. int result = result1;
  4979. if (result == 1)
  4980. result = result2;
  4981. short b1MES_FLAG_Check = (short)result;
  4982. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  4983. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  4984. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  4985. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  4986. //// MES_Flag
  4987. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4988. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4989. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  4990. writeToPLC_Flag.Adress = 2003;
  4991. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  4992. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  4993. {
  4994. Name = "b1Part1SN_Check",
  4995. Adress = 2024,
  4996. ValueType = PLCValueType.String,
  4997. ValueTypeStrLength = 20,
  4998. Value = b1Part1SN_Check
  4999. });
  5000. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5001. {
  5002. Name = "b1Part2SN_Check",
  5003. Adress = 2044,
  5004. ValueType = PLCValueType.String,
  5005. ValueTypeStrLength = 20,
  5006. Value = b1Part2SN_Check
  5007. });
  5008. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5009. {
  5010. Name = "b1Part1Result_Check",
  5011. Adress = 2064,
  5012. ValueType = PLCValueType.Short,
  5013. Value = b1Part1Result_Check
  5014. });
  5015. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5016. {
  5017. Name = "b1Part2Result_Check",
  5018. Adress = 2065,
  5019. ValueType = PLCValueType.Short,
  5020. Value = b1Part2Result_Check
  5021. });
  5022. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5023. }
  5024. catch (Exception ex)
  5025. {
  5026. string str = ex.StackTrace;
  5027. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5028. // MES_Flag
  5029. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5030. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5031. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5032. writeToPLC_Flag.Adress = 2003;
  5033. writeToPLC_Flag.Value = (short)6;
  5034. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5035. }
  5036. stopwatch1.Stop();
  5037. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5038. }
  5039. /// <summary>
  5040. /// [S2] FCT(板测)- 二穴载具解绑绑定
  5041. /// </summary>
  5042. /// <param name="plcNo">PLC编号</param>
  5043. /// <param name="stationNameStr">工站全称</param>
  5044. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  5045. {
  5046. Stopwatch stopwatch1 = new Stopwatch();
  5047. Stopwatch stopwatch2 = new Stopwatch();
  5048. try
  5049. {
  5050. stopwatch1.Start();
  5051. // 产品换载具
  5052. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  5053. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  5054. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  5055. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  5056. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  5057. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  5058. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  5059. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  5060. stopwatch2.Start();
  5061. #region 查询载具上的产品信息
  5062. //string cavityData = string.Empty;
  5063. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  5064. //if (string.IsNullOrEmpty(cavityData))
  5065. // cavityData = "";
  5066. //if (snResult != 0)
  5067. //{
  5068. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5069. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5070. // writeToPLC_Flag.Adress = 2077;
  5071. // writeToPLC_Flag.Value = (short)6;
  5072. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5073. // stopwatch1.Stop();
  5074. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5075. // return;
  5076. //}
  5077. #endregion 查询载具上的产品信息
  5078. #region 解绑(边线MES系统)
  5079. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  5080. if (snResult != 0)
  5081. {
  5082. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5083. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5084. writeToPLC_Flag1.Adress = 2077;
  5085. writeToPLC_Flag1.Value = (short)6;
  5086. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5087. stopwatch1.Stop();
  5088. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5089. return;
  5090. }
  5091. #endregion 解绑(边线MES系统)
  5092. #region 存储绑定数据到 边线MES系统中
  5093. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  5094. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  5095. if (snResult != 0)
  5096. {
  5097. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5098. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5099. writeToPLC_Flag1.Adress = 2077;
  5100. writeToPLC_Flag1.Value = (short)6;
  5101. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5102. stopwatch1.Stop();
  5103. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5104. return;
  5105. }
  5106. #endregion 存储绑定数据到 边线MES系统中
  5107. stopwatch2.Stop();
  5108. short b1MES_FLAG_Unbind = 1;
  5109. // MES_Flag
  5110. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5111. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5112. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5113. writeToPLC_Flag.Adress = 2077;
  5114. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  5115. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5116. }
  5117. catch (Exception ex)
  5118. {
  5119. string str = ex.StackTrace;
  5120. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5121. // MES_Flag
  5122. stopwatch2.Start();
  5123. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5124. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5125. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5126. writeToPLC_Flag.Adress = 2077;
  5127. writeToPLC_Flag.Value = (short)6;
  5128. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5129. stopwatch2.Stop();
  5130. }
  5131. stopwatch1.Stop();
  5132. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5133. }
  5134. //// 上次采集到的SN
  5135. //private string sn_FCT = string.Empty;
  5136. /// <summary>
  5137. /// [S2] FCT(板测)- 出站数据
  5138. /// </summary>
  5139. private void S2出站接口(int plcNo, string stationCode, string stationName)
  5140. {
  5141. Stopwatch stopwatch1 = new Stopwatch();
  5142. Stopwatch stopwatch2 = new Stopwatch();
  5143. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5144. string stationNameStr = stationCode + stationName;
  5145. string processItem = stationName; // 测试项目
  5146. try
  5147. {
  5148. stopwatch1.Start();
  5149. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5150. //string batch_num = GlobalContext.BatchNumber; // 批次号
  5151. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5152. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5153. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  5154. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  5155. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  5156. bool pass1 = b1Part1Result == 1;
  5157. bool pass2 = b1Part2Result == 1;
  5158. #region 根据 载具SN 查 物料SN
  5159. string cavityData = string.Empty;
  5160. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  5161. if (string.IsNullOrEmpty(cavityData))
  5162. cavityData = "";
  5163. if (snResult != 0)
  5164. {
  5165. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5166. writeToPLC_Flag1.Name = "b1MES_FLAG";
  5167. writeToPLC_Flag1.Adress = 2169;
  5168. writeToPLC_Flag1.Value = (short)4;
  5169. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  5170. stopwatch1.Stop();
  5171. AddMessage(LogType.Info, stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5172. return;
  5173. }
  5174. #endregion 根据 载具SN 查 物料SN
  5175. string[] cavitySNs = cavityData.Split('.');
  5176. string b1ProductSN1 = string.Empty;
  5177. string b1ProductSN2 = string.Empty;
  5178. if (cavitySNs != null && cavitySNs.Length >= 2)
  5179. {
  5180. b1ProductSN1 = cavitySNs[0];
  5181. b1ProductSN2 = cavitySNs[1];
  5182. }
  5183. stopwatch2.Start();
  5184. // 产品1
  5185. int result1 = 0;
  5186. if (b1ProductSN1 == "假产品")
  5187. result1 = 1;
  5188. else
  5189. {
  5190. List<TestItem> items1 = new List<TestItem>();
  5191. items1.Add(new TestItem()
  5192. {
  5193. Parameter_name = "载具码",
  5194. Parameter_value = b1ProductSN.ToString(),
  5195. Parameter_unit = ""
  5196. });
  5197. items1.Add(new TestItem()
  5198. {
  5199. Parameter_name = "载具穴号",
  5200. Parameter_value = "1",
  5201. Parameter_unit = ""
  5202. });
  5203. items1.Add(new TestItem()
  5204. {
  5205. Parameter_name = "产品结果",
  5206. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  5207. Parameter_unit = ""
  5208. });
  5209. result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  5210. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  5211. }
  5212. // 产品2
  5213. int result2 = 0;
  5214. if (b1ProductSN1 == "假产品")
  5215. result2 = 1;
  5216. else
  5217. {
  5218. List<TestItem> items2 = new List<TestItem>();
  5219. items2.Add(new TestItem()
  5220. {
  5221. Parameter_name = "载具码",
  5222. Parameter_value = b1ProductSN.ToString(),
  5223. Parameter_unit = ""
  5224. });
  5225. items2.Add(new TestItem()
  5226. {
  5227. Parameter_name = "载具穴号",
  5228. Parameter_value = "2",
  5229. Parameter_unit = ""
  5230. });
  5231. items2.Add(new TestItem()
  5232. {
  5233. Parameter_name = "产品结果",
  5234. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  5235. Parameter_unit = ""
  5236. });
  5237. result2 = SwitctProcessData(stationNameStr, items2, equipmentCode, processItem
  5238. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  5239. }
  5240. short result = 0;
  5241. List<int> results = new List<int>() { result1, result2 };
  5242. if (result1 == 1 && result2 == 1)
  5243. result = 1;
  5244. else if (results.Contains(3))
  5245. result = 3;
  5246. else if (results.Contains(2))
  5247. result = 2;
  5248. else if (results.Contains(4))
  5249. result = 4;
  5250. else
  5251. result = 4;
  5252. stopwatch2.Stop();
  5253. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5254. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5255. writeToPLC_Flag.Name = "b1MES_FLAG";
  5256. writeToPLC_Flag.Adress = 2169;
  5257. writeToPLC_Flag.Value = result;
  5258. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5259. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  5260. }
  5261. catch (Exception ex)
  5262. {
  5263. stopwatch2.Restart();
  5264. // MES_Flag 为4上位机报错
  5265. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  5266. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5267. writeToPLC_Flag.Name = "b1MES_FLAG";
  5268. writeToPLC_Flag.Adress = 2169;
  5269. writeToPLC_Flag.Value = (short)4;
  5270. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5271. stopwatch2.Stop();
  5272. string str = ex.StackTrace;
  5273. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5274. }
  5275. stopwatch1.Stop();
  5276. AddMessage(LogType.Info, stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5277. }
  5278. /// <summary>
  5279. /// [S2] FCT(板测)- 节拍接口
  5280. /// </summary>
  5281. /// <param name="plcNo">PLC编号</param>
  5282. /// <param name="stationNameStr">工站全称</param>
  5283. private void S2节拍接口(int plcNo, string stationNameStr)
  5284. {
  5285. Stopwatch stopwatch1 = new Stopwatch();
  5286. Stopwatch stopwatch2 = new Stopwatch();
  5287. string resultStr = string.Empty;
  5288. try
  5289. {
  5290. stopwatch1.Start();
  5291. string oEEType = ((int)s2PLCData["b1OEEType"]).ToString(); // 节拍类型(plc写入)
  5292. string b1OEEProductSN = (string)s2PLCData["b1OEEProductSN"]; // 载具SN
  5293. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5294. if (!actionBool)
  5295. {
  5296. stopwatch2.Start();
  5297. // MES_Flag
  5298. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5299. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5300. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5301. writeToPLC_Flag1.Adress = 2203;
  5302. writeToPLC_Flag1.Value = (short)4;
  5303. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5304. stopwatch2.Stop();
  5305. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5306. return;
  5307. }
  5308. string b1OEEPartNo = string.Empty; // 物料码
  5309. if (string.IsNullOrEmpty(b1OEEProductSN))
  5310. {
  5311. stopwatch2.Start();
  5312. // MES_Flag
  5313. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5314. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5315. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5316. writeToPLC_Flag1.Adress = 2203;
  5317. writeToPLC_Flag1.Value = (short)1;
  5318. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5319. stopwatch2.Stop();
  5320. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5321. return;
  5322. }
  5323. else
  5324. { // 查产品SN
  5325. b1OEEPartNo = "Test"; // ZS
  5326. }
  5327. short b1OEEMES_FLAG = 0;
  5328. // 上传OEE
  5329. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, b1OEEPartNo, b1OEEProductSN);
  5330. b1OEEMES_FLAG = result.Item1;
  5331. resultStr = result.Item2;
  5332. stopwatch2.Start();
  5333. // MES_Flag
  5334. //Funs[plcNo].WriteMultipleRegisters<short>(2203, b1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5335. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5336. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5337. writeToPLC_Flag.Adress = 2203;
  5338. writeToPLC_Flag.Value = b1OEEMES_FLAG;
  5339. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5340. stopwatch2.Stop();
  5341. }
  5342. catch (Exception ex)
  5343. {
  5344. string str = ex.StackTrace;
  5345. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5346. // MES_Flag
  5347. stopwatch2.Start();
  5348. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5349. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5350. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5351. writeToPLC_Flag.Adress = 2203;
  5352. writeToPLC_Flag.Value = (short)4;
  5353. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5354. stopwatch2.Stop();
  5355. }
  5356. stopwatch1.Stop();
  5357. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5358. }
  5359. #endregion [S2] FCT(板测)
  5360. #endregion PLC2 李晓奇
  5361. #region PLC3 刘永村
  5362. #region [S3] 值板机
  5363. /// <summary>
  5364. /// S3工位的数据- 触发信号上次的值
  5365. /// </summary>
  5366. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  5367. /// <summary>
  5368. /// S3工位的数据(含触发信号)
  5369. /// </summary>
  5370. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  5371. /// <summary>
  5372. /// S3工位的数据- 回写点位
  5373. /// </summary>
  5374. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5375. /// <summary>
  5376. /// [S3] 值板机
  5377. /// </summary>
  5378. /// <param name="plcNo">PLC编号</param>
  5379. //private void ReadStation_S3(int plcNo)
  5380. //{
  5381. // // [S1] Tray盘上料装备
  5382. // // [S2] FCT
  5383. // // [S3] 值板机
  5384. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5385. // // [S5] Tray盘下料装备
  5386. // /// 上位机心跳
  5387. // /// 获取设备报警数据与状态信息
  5388. // string stationCode = "[S3]";
  5389. // string stationName = "值板机";
  5390. // string stationNameStr = stationCode + stationName;
  5391. // #region 创建字典
  5392. // // 触发信号字典 赋值
  5393. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5394. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5395. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5396. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5397. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5398. // // PLC数据字典 赋值
  5399. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5400. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  5401. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5402. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5403. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  5404. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5405. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5406. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5407. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  5408. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5409. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  5410. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  5411. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5412. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5413. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  5414. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  5415. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  5416. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5417. // s3PLCData.Add("c1Result", 0); // 产品结果
  5418. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5419. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  5420. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  5421. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  5422. // #endregion 创建字典
  5423. // while (IsRun)
  5424. // {
  5425. // try
  5426. // {
  5427. // if (!GlobalContext._IsCon_Funs3)
  5428. // {
  5429. // UpdatePLCMonitor(1, plcNo, 0);
  5430. // continue;
  5431. // }
  5432. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5433. // {
  5434. // Stopwatch stopwatch1 = new Stopwatch();
  5435. // Stopwatch stopwatch2 = new Stopwatch();
  5436. // stopwatch1.Start();
  5437. // stopwatch2.Start();
  5438. // #region 一次性读取所有数据
  5439. // // 一次性读取所有数据
  5440. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  5441. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  5442. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  5443. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  5444. // int[] datas = data1.Concat(data2).ToArray();
  5445. // datas = datas.Concat(data3).ToArray();
  5446. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  5447. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  5448. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5449. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  5450. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  5451. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  5452. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5453. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  5454. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  5455. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  5456. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  5457. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5458. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  5459. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  5460. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  5461. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  5462. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5463. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  5464. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  5465. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  5466. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  5467. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  5468. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  5469. // #endregion 一次性读取所有数据
  5470. // stopwatch2.Stop();
  5471. // #region 回写操作,写后清空flag
  5472. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  5473. // #endregion 回写操作,写后清空flag
  5474. // #region S3进站校验
  5475. // try
  5476. // {
  5477. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  5478. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  5479. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  5480. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  5481. // {
  5482. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  5483. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5484. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  5485. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5486. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  5487. // }
  5488. // }
  5489. // catch (Exception ex)
  5490. // {
  5491. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5492. // string str = ex.StackTrace;
  5493. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5494. // }
  5495. // #endregion S3进站校验
  5496. // #region S3二穴载具解绑
  5497. // try
  5498. // {
  5499. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  5500. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  5501. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  5502. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  5503. // {
  5504. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  5505. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  5506. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  5507. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  5508. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  5509. // }
  5510. // }
  5511. // catch (Exception ex)
  5512. // {
  5513. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  5514. // string str = ex.StackTrace;
  5515. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5516. // }
  5517. // #endregion S3二穴载具解绑
  5518. // #region S3二穴载具绑定
  5519. // try
  5520. // {
  5521. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  5522. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  5523. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  5524. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  5525. // {
  5526. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  5527. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5528. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  5529. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  5530. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  5531. // }
  5532. // }
  5533. // catch (Exception ex)
  5534. // {
  5535. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  5536. // string str = ex.StackTrace;
  5537. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5538. // }
  5539. // #endregion S3二穴载具绑定
  5540. // #region S3出站接口(+一穴载具绑定)
  5541. // try
  5542. // {
  5543. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  5544. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  5545. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  5546. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  5547. // {
  5548. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  5549. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5550. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  5551. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  5552. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  5553. // }
  5554. // }
  5555. // catch (Exception ex)
  5556. // {
  5557. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  5558. // string str = ex.StackTrace;
  5559. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5560. // }
  5561. // #endregion S3出站接口(+一穴载具绑定)
  5562. // #region S3节拍接口
  5563. // try
  5564. // {
  5565. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  5566. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  5567. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  5568. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  5569. // {
  5570. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  5571. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5572. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  5573. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  5574. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  5575. // }
  5576. // }
  5577. // catch (Exception ex)
  5578. // {
  5579. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  5580. // string str = ex.StackTrace;
  5581. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5582. // }
  5583. // #endregion S3节拍接口
  5584. // #region 心跳
  5585. // try
  5586. // {
  5587. // short states = 0;
  5588. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  5589. // }
  5590. // catch (Exception ex)
  5591. // {
  5592. // string str = ex.StackTrace;
  5593. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5594. // }
  5595. // #endregion 心跳
  5596. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5597. // stopwatch1.Stop();
  5598. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  5599. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5600. // }
  5601. // else
  5602. // {
  5603. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5604. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5605. // Funs[plcNo].Connect();
  5606. // }
  5607. // }
  5608. // catch (Exception ex)
  5609. // {
  5610. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5611. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5612. // Funs[plcNo].ReConnect();
  5613. // }
  5614. // Thread.Sleep(IntervalReadPLC);
  5615. // }
  5616. //}
  5617. /// <summary>
  5618. /// [S3] 值板机- 进站校验
  5619. /// </summary>
  5620. /// <param name="plcNo">PLC编号</param>
  5621. /// <param name="stationNameStr">工站全称</param>
  5622. private void S3进站校验(int plcNo, string stationNameStr)
  5623. {
  5624. Stopwatch stopwatch1 = new Stopwatch();
  5625. Stopwatch stopwatch2 = new Stopwatch();
  5626. try
  5627. {
  5628. stopwatch1.Start();
  5629. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  5630. sn = sn.Replace("\0", "");
  5631. #region 查询载具上的产品信息
  5632. string cavityData = string.Empty;
  5633. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  5634. if (string.IsNullOrEmpty(cavityData))
  5635. cavityData = "";
  5636. if (snResult != 0)
  5637. {
  5638. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5639. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  5640. writeToPLC_Flag1.Adress = 2003;
  5641. writeToPLC_Flag1.Value = (short)6;
  5642. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  5643. stopwatch1.Stop();
  5644. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5645. return;
  5646. }
  5647. #endregion 查询载具上的产品信息
  5648. string[] cavitySNs = cavityData.Split('.');
  5649. string part1Str = ""; // 产品1的SN码
  5650. string part2Str = ""; // 产品2的SN码
  5651. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5652. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5653. if (cavitySNs != null && cavitySNs.Length >= 2)
  5654. {
  5655. part1Str = cavitySNs[0];
  5656. part2Str = cavitySNs[1];
  5657. c1Part1Result_Check = 2;
  5658. c1Part2Result_Check = 2;
  5659. }
  5660. if (part1Str == "假产品")
  5661. c1Part1Result_Check = 3;
  5662. if (part2Str == "假产品")
  5663. c1Part2Result_Check = 3;
  5664. // 调用MES进站
  5665. stopwatch2.Start();
  5666. // 调用MES进站 - 产品1
  5667. List<TestItem> item;
  5668. int result1 = c1Part1Result_Check;
  5669. if (result1 != 3)
  5670. {
  5671. item = new List<TestItem>();
  5672. item.Add(new TestItem()
  5673. {
  5674. Parameter_name = "载具码",
  5675. Parameter_value = sn,
  5676. });
  5677. item.Add(new TestItem()
  5678. {
  5679. Parameter_name = "载具穴号",
  5680. Parameter_value = "1",
  5681. });
  5682. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part1Str, item, out string errorMsg);
  5683. }
  5684. // 调用MES进站 - 产品2
  5685. int result2 = c1Part2Result_Check;
  5686. if (result2 != 3)
  5687. {
  5688. item = new List<TestItem>();
  5689. item.Add(new TestItem()
  5690. {
  5691. Parameter_name = "载具码",
  5692. Parameter_value = sn,
  5693. });
  5694. item.Add(new TestItem()
  5695. {
  5696. Parameter_name = "载具穴号",
  5697. Parameter_value = "2",
  5698. });
  5699. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part2Str, item, out string errorMsg);
  5700. }
  5701. stopwatch2.Stop();
  5702. if (result1 == 2)
  5703. c1Part1Result_Check = 2;
  5704. if (result2 == 2)
  5705. c1Part2Result_Check = 2;
  5706. int result = result1;
  5707. if (result == 1)
  5708. result = result2;
  5709. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  5710. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  5711. short c1MES_FLAG_Check = (short)result;
  5712. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  5713. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  5714. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  5715. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  5716. //// MES_Flag
  5717. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5718. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5719. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  5720. writeToPLC_Flag.Adress = 2003;
  5721. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  5722. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5723. {
  5724. Name = "c1Part1Result_Check",
  5725. Adress = 2024,
  5726. ValueType = PLCValueType.Short,
  5727. Value = c1Part1Result_Check
  5728. });
  5729. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5730. {
  5731. Name = "c1Part2Result_Check",
  5732. Adress = 2025,
  5733. ValueType = PLCValueType.Short,
  5734. Value = c1Part2Result_Check
  5735. });
  5736. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5737. {
  5738. Name = "c1Part1Num_Check",
  5739. Adress = 2026,
  5740. ValueType = PLCValueType.Short,
  5741. Value = c1Part1Num_Check
  5742. });
  5743. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5744. {
  5745. Name = "c1Part2Num_Check",
  5746. Adress = 2027,
  5747. ValueType = PLCValueType.Short,
  5748. Value = c1Part2Num_Check
  5749. });
  5750. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  5751. }
  5752. catch (Exception ex)
  5753. {
  5754. string str = ex.StackTrace;
  5755. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5756. // MES_Flag
  5757. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5758. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5759. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  5760. writeToPLC_Flag.Adress = 2003;
  5761. writeToPLC_Flag.Value = (short)6;
  5762. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  5763. }
  5764. stopwatch1.Stop();
  5765. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5766. }
  5767. /// <summary>
  5768. /// [S3] 值板机 - 二穴载具解绑
  5769. /// </summary>
  5770. /// <param name="plcNo">PLC编号</param>
  5771. /// <param name="stationNameStr">工站全称</param>
  5772. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  5773. {
  5774. Stopwatch stopwatch1 = new Stopwatch();
  5775. Stopwatch stopwatch2 = new Stopwatch();
  5776. try
  5777. {
  5778. stopwatch1.Start();
  5779. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  5780. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  5781. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5782. // 解绑
  5783. #region 查询载具上的产品信息
  5784. string cavityData = string.Empty;
  5785. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  5786. if (string.IsNullOrEmpty(cavityData))
  5787. cavityData = "";
  5788. if (snResult != 0)
  5789. {
  5790. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5791. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  5792. writeToPLC_Flag1.Adress = 2082;
  5793. writeToPLC_Flag1.Value = (short)6;
  5794. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  5795. stopwatch1.Stop();
  5796. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5797. return;
  5798. }
  5799. #endregion 查询载具上的产品信息
  5800. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  5801. #region 解绑
  5802. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  5803. {
  5804. // 删除
  5805. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  5806. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  5807. }
  5808. else
  5809. {
  5810. string data_new = string.Join(".", cavitySNs);
  5811. // 删除再插入
  5812. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  5813. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  5814. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  5815. }
  5816. #endregion 解绑
  5817. short c1MES_FLAG_Unbind = 1;
  5818. stopwatch2.Start();
  5819. // MES_Flag
  5820. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5821. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5822. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  5823. writeToPLC_Flag.Adress = 2082;
  5824. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  5825. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  5826. stopwatch2.Stop();
  5827. }
  5828. catch (Exception ex)
  5829. {
  5830. string str = ex.StackTrace;
  5831. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5832. // MES_Flag
  5833. stopwatch2.Start();
  5834. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  5835. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5836. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  5837. writeToPLC_Flag.Adress = 2082;
  5838. writeToPLC_Flag.Value = (short)6;
  5839. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  5840. stopwatch2.Stop();
  5841. }
  5842. stopwatch1.Stop();
  5843. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5844. }
  5845. /// <summary>
  5846. /// [S3] 值板机 - 二穴载具绑定
  5847. /// </summary>
  5848. /// <param name="plcNo">PLC编号</param>
  5849. /// <param name="stationNameStr">工站全称</param>
  5850. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  5851. {
  5852. Stopwatch stopwatch1 = new Stopwatch();
  5853. Stopwatch stopwatch2 = new Stopwatch();
  5854. try
  5855. {
  5856. stopwatch1.Start();
  5857. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  5858. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  5859. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  5860. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  5861. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5862. stopwatch2.Start();
  5863. #region 查询载具上的产品信息
  5864. string cavityData = string.Empty;
  5865. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  5866. if (string.IsNullOrEmpty(cavityData))
  5867. cavityData = "";
  5868. if (snResult != 0)
  5869. {
  5870. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5871. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  5872. writeToPLC_Flag1.Adress = 2115;
  5873. writeToPLC_Flag1.Value = (short)6;
  5874. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  5875. stopwatch1.Stop();
  5876. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5877. return;
  5878. }
  5879. #endregion 查询载具上的产品信息
  5880. // 产品换载具
  5881. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  5882. string partSn1 = "";
  5883. string partSn2 = "";
  5884. if (cavitySNs != null && cavitySNs.Length >= 2)
  5885. {
  5886. partSn1 = cavitySNs[0];
  5887. partSn2 = cavitySNs[1];
  5888. }
  5889. string data_new = string.Empty;
  5890. // 是否是两个穴位交换
  5891. if (c1CavityReverse_Bind == 1)
  5892. {
  5893. // 交换
  5894. data_new = string.Concat(partSn2, ".", partSn1);
  5895. }
  5896. else
  5897. { // 不交换
  5898. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  5899. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  5900. cavitySNs[c1VehicleCavityFr_Bind] = "";
  5901. data_new = string.Join(".", cavitySNs);
  5902. }
  5903. // 删除再插入
  5904. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  5905. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  5906. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  5907. stopwatch2.Stop();
  5908. short c1MES_FLAG_Bind = 1;
  5909. // MES_Flag
  5910. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5911. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5912. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  5913. writeToPLC_Flag.Adress = 2115;
  5914. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  5915. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  5916. }
  5917. catch (Exception ex)
  5918. {
  5919. string str = ex.StackTrace;
  5920. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5921. // MES_Flag
  5922. stopwatch2.Start();
  5923. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  5924. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5925. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  5926. writeToPLC_Flag.Adress = 2115;
  5927. writeToPLC_Flag.Value = (short)6;
  5928. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  5929. stopwatch2.Stop();
  5930. }
  5931. stopwatch1.Stop();
  5932. AddMessage(LogType.Info, stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5933. }
  5934. //// 上次采集到的SN
  5935. //private string sn_值板机 = string.Empty;
  5936. /// <summary>
  5937. /// [S3] 值板机 - 出站接口
  5938. /// </summary>
  5939. /// <param name="plcNo">PLC编号</param>
  5940. private void S3出站接口(int plcNo, string stationCode, string stationName)
  5941. {
  5942. Stopwatch stopwatch1 = new Stopwatch();
  5943. Stopwatch stopwatch2 = new Stopwatch();
  5944. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5945. string stationNameStr = stationCode + stationName;
  5946. string processItem = stationName; // 测试项目
  5947. try
  5948. {
  5949. stopwatch1.Start();
  5950. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5951. //string batch_num = GlobalContext.BatchNumber; // 批次号
  5952. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5953. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5954. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  5955. sn = sn.Replace("\0", "");
  5956. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  5957. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  5958. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5959. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  5960. bool pass = c1Result == 1;
  5961. // 查sn
  5962. #region 查询载具上的产品信息
  5963. string cavityData = string.Empty;
  5964. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  5965. if (string.IsNullOrEmpty(cavityData))
  5966. cavityData = "";
  5967. if (snResult != 0)
  5968. {
  5969. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5970. writeToPLC_Flag1.Name = "c1MES_FLAG";
  5971. writeToPLC_Flag1.Adress = 2150;
  5972. writeToPLC_Flag1.Value = (short)4;
  5973. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  5974. stopwatch1.Stop();
  5975. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5976. return;
  5977. }
  5978. #endregion 查询载具上的产品信息
  5979. string[] cavitySNs = cavityData.Split('.');
  5980. string productSN = "";
  5981. if (cavitySNs != null && cavitySNs.Length >= 2)
  5982. {
  5983. productSN = cavitySNs[c1VehicleCavity];
  5984. cavitySNs[c1VehicleCavity] = "";
  5985. }
  5986. stopwatch2.Start();
  5987. List<TestItem> items = new List<TestItem>();
  5988. items.Add(new TestItem()
  5989. {
  5990. Parameter_name = "二穴载具码",
  5991. Parameter_value = c1ProductSN_Check,
  5992. Parameter_unit = ""
  5993. });
  5994. items.Add(new TestItem()
  5995. {
  5996. Parameter_name = "二穴载具穴号",
  5997. Parameter_value = c1VehicleCavity.ToString(),
  5998. Parameter_unit = ""
  5999. });
  6000. items.Add(new TestItem()
  6001. {
  6002. Parameter_name = "一穴载具码",
  6003. Parameter_value = sn,
  6004. Parameter_unit = ""
  6005. });
  6006. items.Add(new TestItem()
  6007. {
  6008. Parameter_name = "一穴载具穴号",
  6009. Parameter_value = "1",
  6010. Parameter_unit = ""
  6011. });
  6012. items.Add(new TestItem()
  6013. {
  6014. Parameter_name = "产品结果",
  6015. Parameter_value = c1Result == 1 ? "OK" : "NG",
  6016. Parameter_unit = ""
  6017. });
  6018. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6019. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  6020. short result = (short)result1;
  6021. stopwatch2.Stop();
  6022. #region 存储绑定数据到 边线MES系统中
  6023. if (result == 1)
  6024. {
  6025. string data = string.Concat(productSN);
  6026. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  6027. if (resultMesR != 0)
  6028. {
  6029. result = 4;
  6030. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  6031. }
  6032. }
  6033. #endregion 存储绑定数据到 边线MES系统中
  6034. #region 产品从 来源载具(二穴载具)中删除
  6035. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6036. {
  6037. // 删除
  6038. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6039. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  6040. }
  6041. else
  6042. {
  6043. string data_new = string.Join(".", cavitySNs);
  6044. // 删除再插入
  6045. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6046. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6047. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6048. }
  6049. #endregion 产品从 来源载具(二穴载具)中删除
  6050. // MES_Flag 为MES报错
  6051. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6052. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  6053. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6054. writeToPLC_Flag.Name = "c1MES_FLAG";
  6055. writeToPLC_Flag.Adress = 2150;
  6056. writeToPLC_Flag.Value = result;
  6057. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6058. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  6059. }
  6060. catch (Exception ex)
  6061. {
  6062. stopwatch2.Restart();
  6063. // MES_Flag 为4上位机报错
  6064. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  6065. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6066. writeToPLC_Flag.Name = "c1MES_FLAG";
  6067. writeToPLC_Flag.Adress = 2150;
  6068. writeToPLC_Flag.Value = (short)4;
  6069. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6070. stopwatch2.Stop();
  6071. string str = ex.StackTrace;
  6072. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6073. }
  6074. stopwatch1.Stop();
  6075. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6076. }
  6077. /// <summary>
  6078. /// [S3] 值板机- 节拍接口
  6079. /// </summary>
  6080. /// <param name="plcNo">PLC编号</param>
  6081. /// <param name="stationNameStr">工站全称</param>
  6082. private void S3节拍接口(int plcNo, string stationNameStr)
  6083. {
  6084. Stopwatch stopwatch1 = new Stopwatch();
  6085. Stopwatch stopwatch2 = new Stopwatch();
  6086. string resultStr = string.Empty;
  6087. try
  6088. {
  6089. stopwatch1.Start();
  6090. string oEEType = ((int)s3PLCData["c1OEEType"]).ToString(); // 节拍类型(plc写入)
  6091. string c1OEEProductSN = (string)s3PLCData["c1OEEProductSN"]; // 载具SN
  6092. c1OEEProductSN = c1OEEProductSN.Replace("\0", "");
  6093. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6094. if (!actionBool)
  6095. {
  6096. stopwatch2.Start();
  6097. // MES_Flag
  6098. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6099. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6100. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6101. writeToPLC_Flag1.Adress = 2204;
  6102. writeToPLC_Flag1.Value = (short)4;
  6103. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6104. stopwatch2.Stop();
  6105. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6106. return;
  6107. }
  6108. string c1OEEPartNo = string.Empty; // 物料码
  6109. if (string.IsNullOrEmpty(c1OEEProductSN))
  6110. {
  6111. stopwatch2.Start();
  6112. // MES_Flag
  6113. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6114. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6115. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6116. writeToPLC_Flag1.Adress = 2204;
  6117. writeToPLC_Flag1.Value = (short)1;
  6118. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6119. stopwatch2.Stop();
  6120. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6121. return;
  6122. }
  6123. else
  6124. { // 查产品SN
  6125. c1OEEPartNo = "Test"; // ZS
  6126. }
  6127. short c1OEEMES_FLAG = 0;
  6128. // 上传OEE
  6129. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, c1OEEPartNo, c1OEEProductSN);
  6130. c1OEEMES_FLAG = result.Item1;
  6131. resultStr = result.Item2;
  6132. stopwatch2.Start();
  6133. // MES_Flag
  6134. //Funs[plcNo].WriteMultipleRegisters<short>(2204, c1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6135. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6136. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6137. writeToPLC_Flag.Adress = 2204;
  6138. writeToPLC_Flag.Value = c1OEEMES_FLAG;
  6139. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6140. stopwatch2.Stop();
  6141. }
  6142. catch (Exception ex)
  6143. {
  6144. string str = ex.StackTrace;
  6145. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6146. // MES_Flag
  6147. stopwatch2.Start();
  6148. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6149. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6150. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6151. writeToPLC_Flag.Adress = 2204;
  6152. writeToPLC_Flag.Value = (short)4;
  6153. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6154. stopwatch2.Stop();
  6155. }
  6156. stopwatch1.Stop();
  6157. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6158. }
  6159. #endregion [S3] 值板机
  6160. #endregion PLC3 刘永村
  6161. #region PLC4 刘果段
  6162. #region [S4] 取放桁架
  6163. /// <summary>
  6164. /// S4工位的数据- 触发信号上次的值
  6165. /// </summary>
  6166. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  6167. /// <summary>
  6168. /// S4工位的数据(含触发信号)
  6169. /// </summary>
  6170. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  6171. /// <summary>
  6172. /// S4工位的数据- 回写点位
  6173. /// </summary>
  6174. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6175. /// <summary>
  6176. /// [S4] 取放桁架
  6177. /// </summary>
  6178. /// <param name="plcNo">PLC编号</param>
  6179. //private void ReadStation_S4(int plcNo)
  6180. //{
  6181. // // [S1] Tray盘上料装备
  6182. // // [S2] FCT
  6183. // // [S3] 值板机
  6184. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6185. // // [S5] Tray盘下料装备
  6186. // /// 上位机心跳
  6187. // /// 获取设备报警数据与状态信息
  6188. // string stationCode = "[S4_1]";
  6189. // string stationName = "载具下线装备";
  6190. // string stationNameStr = stationCode + stationName;
  6191. // string stationCode2 = "[S4_2]";
  6192. // string stationName2 = "桁架";
  6193. // string stationNameStr2 = stationCode2 + stationName2;
  6194. // string stationCode3 = "[S4_3]";
  6195. // string stationName3 = "提升机1";
  6196. // string stationNameStr3 = stationCode3 + stationName3;
  6197. // string stationCode4 = "[S4_4]";
  6198. // string stationName4 = "提升机2";
  6199. // string stationNameStr4 = stationCode4 + stationName4;
  6200. // string stationCode5 = "[S4_5]";
  6201. // string stationName5 = "载具上线装备";
  6202. // string stationNameStr5 = stationCode5 + stationName5;
  6203. // #region 创建字典
  6204. // // 触发信号字典 赋值
  6205. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6206. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6207. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6208. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6209. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6210. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6211. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6212. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6213. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6214. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6215. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6216. // // PLC数据字典 赋值
  6217. // // 载具下线装备(弹夹上线)
  6218. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6219. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  6220. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6221. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  6222. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6223. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  6224. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  6225. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6226. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6227. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6228. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6229. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6230. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6231. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6232. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6233. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6234. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6235. // s4PLCData.Add("d1Result", 0); // 产品结果
  6236. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6237. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  6238. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  6239. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  6240. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6241. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  6242. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  6243. // // 真空标机(提升机)
  6244. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6245. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  6246. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  6247. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  6248. // s4PLCData.Add("d3Result", 0); // 产品结果
  6249. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6250. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  6251. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  6252. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  6253. // s4PLCData.Add("d4Result", 0); // 产品结果
  6254. // // 载具上线装备(弹夹下线)
  6255. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6256. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  6257. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6258. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  6259. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6260. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  6261. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  6262. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6263. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6264. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6265. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6266. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6267. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6268. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6269. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6270. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6271. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6272. // s4PLCData.Add("d5Result", 0); // 产品结果
  6273. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6274. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  6275. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  6276. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  6277. // #endregion 创建字典
  6278. // while (IsRun)
  6279. // {
  6280. // try
  6281. // {
  6282. // if (!GlobalContext._IsCon_Funs4)
  6283. // {
  6284. // UpdatePLCMonitor(1, plcNo, 0);
  6285. // continue;
  6286. // }
  6287. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6288. // {
  6289. // Stopwatch stopwatch1 = new Stopwatch();
  6290. // Stopwatch stopwatch2 = new Stopwatch();
  6291. // stopwatch1.Start();
  6292. // stopwatch2.Start();
  6293. // #region 一次性读取所有数据
  6294. // // 载具下线装备(弹夹上线)
  6295. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6296. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6297. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6298. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  6299. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  6300. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  6301. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  6302. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  6303. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  6304. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  6305. // int[] datas = data1.Concat(data2).ToArray();
  6306. // datas = datas.Concat(data3).ToArray();
  6307. // datas = datas.Concat(data4).ToArray();
  6308. // datas = datas.Concat(data5).ToArray();
  6309. // datas = datas.Concat(data6).ToArray();
  6310. // datas = datas.Concat(data7).ToArray();
  6311. // datas = datas.Concat(data8).ToArray();
  6312. // datas = datas.Concat(data9).ToArray();
  6313. // datas = datas.Concat(data10).ToArray();
  6314. // // 载具下线装备(弹夹上线)
  6315. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  6316. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  6317. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  6318. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  6319. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  6320. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  6321. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  6322. // s4PLCData["d1MES_FLAG"] = datas[65];
  6323. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  6324. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  6325. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  6326. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  6327. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  6328. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  6329. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  6330. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  6331. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  6332. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  6333. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  6334. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  6335. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  6336. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  6337. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  6338. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  6339. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  6340. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  6341. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  6342. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  6343. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  6344. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  6345. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  6346. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  6347. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  6348. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  6349. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  6350. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  6351. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  6352. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  6353. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  6354. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  6355. // s4PLCData["d1Result"] = datas[386];
  6356. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  6357. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  6358. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  6359. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  6360. // s4PLCData["d1OEEType"] = datas[419];
  6361. // // 桁架(查询标机中弹夹的状态)
  6362. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  6363. // s4PLCData["d2BulletclipStates"] = datas[431];
  6364. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  6365. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  6366. // // 真空标机
  6367. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  6368. // s4PLCData["d3MES_FLAG"] = datas[463];
  6369. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  6370. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  6371. // s4PLCData["d3Result"] = datas[484];
  6372. // s4PLCData["d3Type"] = datas[485];
  6373. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  6374. // s4PLCData["d4MES_FLAG"] = datas[496];
  6375. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  6376. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  6377. // s4PLCData["d4Result"] = datas[517];
  6378. // s4PLCData["d4Type"] = datas[518];
  6379. // // 载具上线装备(弹夹下线)
  6380. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  6381. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  6382. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  6383. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  6384. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  6385. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  6386. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  6387. // s4PLCData["d5MES_FLAG"] = datas[591];
  6388. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  6389. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  6390. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  6391. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  6392. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  6393. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  6394. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  6395. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  6396. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  6397. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  6398. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  6399. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  6400. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  6401. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  6402. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  6403. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  6404. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  6405. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  6406. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  6407. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  6408. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  6409. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  6410. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  6411. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  6412. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  6413. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  6414. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  6415. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  6416. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  6417. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  6418. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  6419. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  6420. // s4PLCData["d5Result"] = datas[912];
  6421. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  6422. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  6423. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  6424. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  6425. // s4PLCData["d5OEEType"] = datas[945];
  6426. // #endregion 一次性读取所有数据
  6427. // stopwatch2.Stop();
  6428. // #region 回写操作,写后清空flag
  6429. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  6430. // #endregion 回写操作,写后清空flag
  6431. // // N801A-S4_1 弹夹扫码
  6432. // #region N801A-S4_1 弹夹扫码
  6433. // try
  6434. // {
  6435. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  6436. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  6437. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  6438. // {
  6439. // if (d1BulletclipScanCode == 1) // 0->1
  6440. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6441. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  6442. // }
  6443. // }
  6444. // catch (Exception ex)
  6445. // {
  6446. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  6447. // string str = ex.StackTrace;
  6448. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6449. // }
  6450. // #endregion N801A-S4_1 弹夹扫码
  6451. // // N801A-S4_1 载具扫码
  6452. // #region N801A-S4_1 载具扫码
  6453. // try
  6454. // {
  6455. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  6456. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  6457. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  6458. // {
  6459. // if (d1VehicleScanCode == 1) // 0->1
  6460. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6461. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  6462. // }
  6463. // }
  6464. // catch (Exception ex)
  6465. // {
  6466. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  6467. // string str = ex.StackTrace;
  6468. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6469. // }
  6470. // #endregion N801A-S4_1 载具扫码
  6471. // // N801A-S4_1 出站接口
  6472. // #region N801A-S4_1 出站接口
  6473. // try
  6474. // {
  6475. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  6476. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  6477. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  6478. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  6479. // {
  6480. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  6481. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6482. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  6483. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  6484. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  6485. // }
  6486. // }
  6487. // catch (Exception ex)
  6488. // {
  6489. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  6490. // string str = ex.StackTrace;
  6491. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6492. // }
  6493. // #endregion N801A-S4_1 出站接口
  6494. // // N801A-S4_1 节拍接口
  6495. // #region N801A-S4_1 节拍接口
  6496. // try
  6497. // {
  6498. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  6499. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  6500. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  6501. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  6502. // {
  6503. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  6504. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6505. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  6506. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  6507. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  6508. // }
  6509. // }
  6510. // catch (Exception ex)
  6511. // {
  6512. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  6513. // string str = ex.StackTrace;
  6514. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6515. // }
  6516. // #endregion N801A-S4_1 节拍接口
  6517. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  6518. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  6519. // try
  6520. // {
  6521. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  6522. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  6523. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  6524. // {
  6525. // if (d2BulletclipScanCode == 1) // 0->1
  6526. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  6527. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  6528. // }
  6529. // }
  6530. // catch (Exception ex)
  6531. // {
  6532. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  6533. // string str = ex.StackTrace;
  6534. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6535. // }
  6536. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  6537. // // N801A-S4_3 真空标机1 数据
  6538. // #region N801A-S4_3 真空标机1
  6539. // try
  6540. // {
  6541. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  6542. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  6543. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  6544. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  6545. // {
  6546. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  6547. // {
  6548. // int stationType = (int)s4PLCData["d3Type"];
  6549. // if (stationType == 1)
  6550. // {
  6551. // // S4_3进站接口
  6552. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  6553. // }
  6554. // else if (stationType == 2)
  6555. // {
  6556. // // S4_3出站接口
  6557. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  6558. // }
  6559. // }
  6560. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  6561. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  6562. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  6563. // }
  6564. // }
  6565. // catch (Exception ex)
  6566. // {
  6567. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  6568. // string str = ex.StackTrace;
  6569. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6570. // }
  6571. // #endregion N801A-S4_3 真空标机1
  6572. // // N801A-S4_4 真空标机2 数据
  6573. // #region N801A-S4_4 真空标机2
  6574. // try
  6575. // {
  6576. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  6577. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  6578. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  6579. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  6580. // {
  6581. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  6582. // {
  6583. // int stationType = (int)s4PLCData["d4Type"];
  6584. // if (stationType == 1)
  6585. // {
  6586. // // S4_4进站接口
  6587. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  6588. // }
  6589. // else if (stationType == 2)
  6590. // {
  6591. // // S4_4出站接口
  6592. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  6593. // }
  6594. // }
  6595. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  6596. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  6597. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  6598. // }
  6599. // }
  6600. // catch (Exception ex)
  6601. // {
  6602. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  6603. // string str = ex.StackTrace;
  6604. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6605. // }
  6606. // #endregion N801A-S4_4 真空标机2
  6607. // // N801A-S4_5 弹夹扫码 数据
  6608. // #region N801A-S4_5 弹夹扫码
  6609. // try
  6610. // {
  6611. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  6612. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  6613. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  6614. // {
  6615. // if (d5BulletclipScanCode == 1) // 0->1
  6616. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  6617. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  6618. // }
  6619. // }
  6620. // catch (Exception ex)
  6621. // {
  6622. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  6623. // string str = ex.StackTrace;
  6624. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6625. // }
  6626. // #endregion N801A-S4_5 弹夹扫码
  6627. // // N801A-S4_5 载具扫码 数据
  6628. // #region N801A-S4_5 载具扫码
  6629. // try
  6630. // {
  6631. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  6632. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  6633. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  6634. // {
  6635. // if (d5VehicleScanCode == 1) // 0->1
  6636. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  6637. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  6638. // }
  6639. // }
  6640. // catch (Exception ex)
  6641. // {
  6642. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  6643. // string str = ex.StackTrace;
  6644. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6645. // }
  6646. // #endregion N801A-S4_5 载具扫码
  6647. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  6648. // #region N801A-S4_5 出站接口
  6649. // try
  6650. // {
  6651. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  6652. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  6653. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  6654. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  6655. // {
  6656. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  6657. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  6658. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  6659. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  6660. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  6661. // }
  6662. // }
  6663. // catch (Exception ex)
  6664. // {
  6665. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  6666. // string str = ex.StackTrace;
  6667. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6668. // }
  6669. // #endregion N801A-S4_5 出站接口
  6670. // // N801A-S4_5 节拍接口 数据
  6671. // #region N801A-S4_5 节拍接口
  6672. // try
  6673. // {
  6674. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  6675. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  6676. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  6677. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  6678. // {
  6679. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  6680. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  6681. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  6682. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  6683. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  6684. // }
  6685. // }
  6686. // catch (Exception ex)
  6687. // {
  6688. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  6689. // string str = ex.StackTrace;
  6690. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6691. // }
  6692. // #endregion N801A-S4_5 节拍接口
  6693. // #region 心跳
  6694. // try
  6695. // {
  6696. // short states = 0;
  6697. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  6698. // }
  6699. // catch (Exception ex)
  6700. // {
  6701. // string str = ex.StackTrace;
  6702. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6703. // }
  6704. // #endregion 心跳
  6705. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6706. // stopwatch1.Stop();
  6707. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  6708. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6709. // }
  6710. // else
  6711. // {
  6712. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6713. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  6714. // Funs[plcNo].Connect();
  6715. // }
  6716. // }
  6717. // catch (Exception ex)
  6718. // {
  6719. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6720. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  6721. // Funs[plcNo].ReConnect();
  6722. // }
  6723. // Thread.Sleep(IntervalReadPLC);
  6724. // }
  6725. //}
  6726. /// <summary>
  6727. /// [S4] 取放桁架 - S4_1弹夹扫码
  6728. /// </summary>
  6729. /// <param name="plcNo">PLC编号</param>
  6730. /// <param name="stationNameStr">工站全称</param>
  6731. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  6732. {
  6733. Stopwatch stopwatch1 = new Stopwatch();
  6734. Stopwatch stopwatch2 = new Stopwatch();
  6735. try
  6736. {
  6737. stopwatch1.Start();
  6738. // ZS 弹夹扫码
  6739. string d1BulletclipCode = " "; // 扫到的码
  6740. short d1BulletclipScanCode = 2;
  6741. stopwatch2.Start();
  6742. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  6743. //// MES_Flag
  6744. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  6745. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6746. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  6747. writeToPLC_Flag.Adress = 2002;
  6748. writeToPLC_Flag.Value = d1BulletclipScanCode;
  6749. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  6750. {
  6751. Name = "d1BulletclipCode",
  6752. Adress = 2003,
  6753. ValueType = PLCValueType.String,
  6754. ValueTypeStrLength = 20,
  6755. Value = d1BulletclipCode
  6756. });
  6757. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  6758. stopwatch2.Stop();
  6759. }
  6760. catch (Exception ex)
  6761. {
  6762. string str = ex.StackTrace;
  6763. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6764. stopwatch2.Start();
  6765. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  6766. //// MES_Flag
  6767. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  6768. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6769. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  6770. writeToPLC_Flag.Adress = 2002;
  6771. writeToPLC_Flag.Value = (short)6;
  6772. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  6773. {
  6774. Name = "d1BulletclipCode",
  6775. Adress = 2003,
  6776. ValueType = PLCValueType.String,
  6777. ValueTypeStrLength = 20,
  6778. Value = " "
  6779. });
  6780. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  6781. stopwatch2.Stop();
  6782. }
  6783. stopwatch1.Stop();
  6784. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6785. }
  6786. /// <summary>
  6787. /// [S4] 取放桁架 - S4_1载具扫码
  6788. /// </summary>
  6789. /// <param name="plcNo">PLC编号</param>
  6790. /// <param name="stationNameStr">工站全称</param>
  6791. private void S4_1载具扫码(int plcNo, string stationNameStr)
  6792. {
  6793. Stopwatch stopwatch1 = new Stopwatch();
  6794. Stopwatch stopwatch2 = new Stopwatch();
  6795. try
  6796. {
  6797. stopwatch1.Start();
  6798. // ZS 载具扫码
  6799. string d1VehicleCode = ""; // 扫到的码
  6800. short d1VehicleScanCode = 2;
  6801. #region 进站
  6802. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  6803. {
  6804. #region 查询载具上的产品信息
  6805. string cavityData = string.Empty;
  6806. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  6807. if (string.IsNullOrEmpty(cavityData))
  6808. cavityData = "";
  6809. if (snResult != 0)
  6810. {
  6811. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6812. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  6813. writeToPLC_Flag1.Adress = 2033;
  6814. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  6815. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6816. {
  6817. Name = "d1VehicleCode",
  6818. Adress = 2034,
  6819. ValueType = PLCValueType.String,
  6820. ValueTypeStrLength = 20,
  6821. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  6822. });
  6823. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  6824. stopwatch1.Stop();
  6825. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6826. return;
  6827. }
  6828. string[] cavitySNs = cavityData.Split('.');
  6829. string partNo = "";
  6830. if (cavitySNs != null && cavitySNs.Length >= 1)
  6831. {
  6832. partNo = cavitySNs[0];
  6833. }
  6834. #endregion 查询载具上的产品信息
  6835. List<TestItem> item = new List<TestItem>();
  6836. item.Add(new TestItem()
  6837. {
  6838. Parameter_name = "载具码",
  6839. Parameter_value = d1VehicleCode,
  6840. });
  6841. item.Add(new TestItem()
  6842. {
  6843. Parameter_name = "载具穴号",
  6844. Parameter_value = "1",
  6845. });
  6846. stopwatch2.Start();
  6847. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  6848. stopwatch2.Stop();
  6849. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  6850. }
  6851. #endregion 进站
  6852. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  6853. //// MES_Flag
  6854. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  6855. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6856. writeToPLC_Flag.Name = "d1VehicleScanCode";
  6857. writeToPLC_Flag.Adress = 2033;
  6858. writeToPLC_Flag.Value = d1VehicleScanCode;
  6859. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6860. {
  6861. Name = "d1VehicleCode",
  6862. Adress = 2034,
  6863. ValueType = PLCValueType.String,
  6864. ValueTypeStrLength = 20,
  6865. Value = d1VehicleCode
  6866. });
  6867. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  6868. }
  6869. catch (Exception ex)
  6870. {
  6871. string str = ex.StackTrace;
  6872. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6873. stopwatch2.Start();
  6874. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  6875. //// MES_Flag
  6876. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  6877. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6878. writeToPLC_Flag.Name = "d1VehicleScanCode";
  6879. writeToPLC_Flag.Adress = 2033;
  6880. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  6881. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6882. {
  6883. Name = "d1VehicleCode",
  6884. Adress = 2034,
  6885. ValueType = PLCValueType.String,
  6886. ValueTypeStrLength = 20,
  6887. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  6888. });
  6889. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  6890. stopwatch2.Stop();
  6891. }
  6892. stopwatch1.Stop();
  6893. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6894. }
  6895. // 上次采集到的SN
  6896. //private string sn_S4_1出站接口 = string.Empty;
  6897. /// <summary>
  6898. /// [S4] 取放桁架 - S4_1出站接口
  6899. /// </summary>
  6900. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  6901. {
  6902. Stopwatch stopwatch1 = new Stopwatch();
  6903. Stopwatch stopwatch2 = new Stopwatch();
  6904. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6905. string stationNameStr = stationCode + stationName;
  6906. string processItem = stationName; // 测试项目
  6907. try
  6908. {
  6909. stopwatch1.Start();
  6910. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6911. //string batch_num = GlobalContext.BatchNumber; // 批次号
  6912. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6913. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6914. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  6915. sn = sn.Replace("\0", "");
  6916. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  6917. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  6918. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  6919. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  6920. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  6921. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  6922. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  6923. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  6924. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  6925. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  6926. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  6927. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  6928. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  6929. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  6930. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  6931. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  6932. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  6933. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  6934. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  6935. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  6936. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  6937. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  6938. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  6939. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  6940. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  6941. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  6942. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  6943. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  6944. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  6945. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  6946. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  6947. bool pass = d1Result == 1;
  6948. // 存 载具SN列表
  6949. List<string> vehicleCodes = new List<string>()
  6950. {
  6951. d1VehicleCode1,d1VehicleCode2,d1VehicleCode3,d1VehicleCode4,d1VehicleCode5,
  6952. d1VehicleCode6,d1VehicleCode7,d1VehicleCode8,d1VehicleCode9,d1VehicleCode10,
  6953. d1VehicleCode11,d1VehicleCode12,d1VehicleCode13,d1VehicleCode14,d1VehicleCode15
  6954. };
  6955. // 统一查 产品SN列表
  6956. List<string> partNos = new List<string>();
  6957. foreach (string vehicleCode in vehicleCodes)
  6958. {
  6959. if (string.IsNullOrEmpty(vehicleCode))
  6960. partNos.Add("");
  6961. else
  6962. {
  6963. string partNo = "";
  6964. #region 查询载具上的产品信息
  6965. string cavityData = string.Empty;
  6966. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  6967. if (string.IsNullOrEmpty(cavityData))
  6968. cavityData = "";
  6969. if (snResult != 0)
  6970. {
  6971. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6972. writeToPLC_Flag1.Name = "d1MES_FLAG";
  6973. writeToPLC_Flag1.Adress = 2065;
  6974. writeToPLC_Flag1.Value = (short)4;
  6975. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  6976. stopwatch1.Stop();
  6977. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6978. return;
  6979. }
  6980. string[] cavitySNs = cavityData.Split('.');
  6981. if (cavitySNs != null && cavitySNs.Length >= 1)
  6982. partNo = cavitySNs[0];
  6983. #endregion 查询载具上的产品信息
  6984. partNos.Add(partNo);
  6985. }
  6986. }
  6987. // 统一上传
  6988. stopwatch2.Start();
  6989. List<int> results = new List<int>();
  6990. for (int i = 0; i < partNos.Count; i++)
  6991. {
  6992. string index = (i + 1).ToString(); // 弹夹穴号
  6993. if (string.IsNullOrEmpty(partNos[i]))
  6994. results.Add(1);
  6995. else
  6996. {
  6997. List<TestItem> items1 = new List<TestItem>();
  6998. items1.Add(new TestItem()
  6999. {
  7000. Parameter_name = "弹夹码",
  7001. Parameter_value = sn,
  7002. Parameter_unit = ""
  7003. });
  7004. items1.Add(new TestItem()
  7005. {
  7006. Parameter_name = "弹夹穴号",
  7007. Parameter_value = index,
  7008. Parameter_unit = ""
  7009. });
  7010. items1.Add(new TestItem()
  7011. {
  7012. Parameter_name = "载具码",
  7013. Parameter_value = vehicleCodes[i],
  7014. Parameter_unit = ""
  7015. });
  7016. items1.Add(new TestItem()
  7017. {
  7018. Parameter_name = "载具穴号",
  7019. Parameter_value = "1",
  7020. Parameter_unit = ""
  7021. });
  7022. items1.Add(new TestItem()
  7023. {
  7024. Parameter_name = "产品结果",
  7025. Parameter_value = d1Result == 1 ? "OK" : "NG",
  7026. Parameter_unit = ""
  7027. });
  7028. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7029. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  7030. results.Add(result1);
  7031. }
  7032. }
  7033. short result = 0;
  7034. if (results.All(a => a == 1))
  7035. result = 1;
  7036. else if (results.Contains(3))
  7037. result = 3;
  7038. else if (results.Contains(2))
  7039. result = 2;
  7040. else if (results.Contains(4))
  7041. result = 4;
  7042. else
  7043. result = 4;
  7044. stopwatch2.Stop();
  7045. #region 存储绑定数据到 边线MES系统中
  7046. if (result == 1)
  7047. {
  7048. string data = string.Join(".", vehicleCodes);
  7049. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7050. if (resultMesR != 0)
  7051. {
  7052. result = 4;
  7053. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  7054. }
  7055. }
  7056. #endregion 存储绑定数据到 边线MES系统中
  7057. // MES_Flag 为4MES报错
  7058. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7059. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7060. writeToPLC_Flag.Name = "d1MES_FLAG";
  7061. writeToPLC_Flag.Adress = 2065;
  7062. writeToPLC_Flag.Value = result;
  7063. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7064. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7065. }
  7066. catch (Exception ex)
  7067. {
  7068. stopwatch2.Restart();
  7069. // MES_Flag 为4上位机报错
  7070. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  7071. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7072. writeToPLC_Flag.Name = "d1MES_FLAG";
  7073. writeToPLC_Flag.Adress = 2065;
  7074. writeToPLC_Flag.Value = (short)4;
  7075. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7076. stopwatch2.Stop();
  7077. string str = ex.StackTrace;
  7078. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7079. }
  7080. stopwatch1.Stop();
  7081. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7082. }
  7083. /// <summary>
  7084. /// [S4] 取放桁架 - S4_1节拍接口
  7085. /// </summary>
  7086. /// <param name="plcNo">PLC编号</param>
  7087. /// <param name="stationNameStr">工站全称</param>
  7088. private void S4_1节拍接口(int plcNo, string stationNameStr)
  7089. {
  7090. Stopwatch stopwatch1 = new Stopwatch();
  7091. Stopwatch stopwatch2 = new Stopwatch();
  7092. string resultStr = string.Empty;
  7093. try
  7094. {
  7095. stopwatch1.Start();
  7096. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  7097. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  7098. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  7099. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7100. if (!actionBool)
  7101. {
  7102. stopwatch2.Start();
  7103. // MES_Flag
  7104. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7105. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7106. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7107. writeToPLC_Flag1.Adress = 2398;
  7108. writeToPLC_Flag1.Value = (short)4;
  7109. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7110. stopwatch2.Stop();
  7111. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7112. return;
  7113. }
  7114. string d1OEEPartNo = string.Empty; // 物料码
  7115. if (string.IsNullOrEmpty(d1OEEProductSN))
  7116. {
  7117. stopwatch2.Start();
  7118. // MES_Flag
  7119. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7120. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7121. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7122. writeToPLC_Flag1.Adress = 2398;
  7123. writeToPLC_Flag1.Value = (short)1;
  7124. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7125. stopwatch2.Stop();
  7126. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7127. return;
  7128. }
  7129. else
  7130. { // 查产品SN ZS
  7131. d1OEEPartNo = "Test";
  7132. }
  7133. short d1OEEMES_FLAG = 0;
  7134. // 上传OEE
  7135. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  7136. d1OEEMES_FLAG = result.Item1;
  7137. resultStr = result.Item2;
  7138. stopwatch2.Start();
  7139. // MES_Flag
  7140. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7141. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7142. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7143. writeToPLC_Flag.Adress = 2398;
  7144. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  7145. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7146. stopwatch2.Stop();
  7147. }
  7148. catch (Exception ex)
  7149. {
  7150. string str = ex.StackTrace;
  7151. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7152. // MES_Flag
  7153. stopwatch2.Start();
  7154. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7155. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7156. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7157. writeToPLC_Flag.Adress = 2398;
  7158. writeToPLC_Flag.Value = (short)4;
  7159. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7160. stopwatch2.Stop();
  7161. }
  7162. stopwatch1.Stop();
  7163. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7164. }
  7165. /// <summary>
  7166. /// [S4] 取放桁架 - S4_2桁架
  7167. /// </summary>
  7168. /// <param name="plcNo">PLC编号</param>
  7169. /// <param name="stationNameStr">工站全称</param>
  7170. private void S4_2桁架(int plcNo, string stationNameStr)
  7171. {
  7172. Stopwatch stopwatch1 = new Stopwatch();
  7173. Stopwatch stopwatch2 = new Stopwatch();
  7174. try
  7175. {
  7176. stopwatch1.Start();
  7177. // ZS 弹夹扫码
  7178. string d2BulletclipCode = " "; // 扫到的码
  7179. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  7180. short d2BulletclipScanCode = 2;
  7181. stopwatch2.Start();
  7182. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  7183. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  7184. //// MES_Flag
  7185. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7186. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7187. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7188. writeToPLC_Flag.Adress = 2430;
  7189. writeToPLC_Flag.Value = d2BulletclipScanCode;
  7190. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7191. {
  7192. Name = "d2BulletclipCode",
  7193. Adress = 2432,
  7194. ValueType = PLCValueType.String,
  7195. ValueTypeStrLength = 20,
  7196. Value = d2BulletclipCode
  7197. });
  7198. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7199. {
  7200. Name = "d2BulletclipStates",
  7201. Adress = 2431,
  7202. ValueType = PLCValueType.Short,
  7203. Value = d2BulletclipStates
  7204. });
  7205. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7206. stopwatch2.Stop();
  7207. }
  7208. catch (Exception ex)
  7209. {
  7210. string str = ex.StackTrace;
  7211. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7212. stopwatch2.Start();
  7213. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  7214. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  7215. // MES_Flag
  7216. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7217. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7218. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7219. writeToPLC_Flag.Adress = 2430;
  7220. writeToPLC_Flag.Value = (short)6;
  7221. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7222. {
  7223. Name = "d2BulletclipCode",
  7224. Adress = 2432,
  7225. ValueType = PLCValueType.String,
  7226. ValueTypeStrLength = 20,
  7227. Value = " "
  7228. });
  7229. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7230. {
  7231. Name = "d2BulletclipStates",
  7232. Adress = 2431,
  7233. ValueType = PLCValueType.Short,
  7234. Value = (short)0
  7235. });
  7236. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7237. stopwatch2.Stop();
  7238. }
  7239. stopwatch1.Stop();
  7240. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7241. }
  7242. // 上次采集到的SN
  7243. //private string sn_S4_3进站接口 = string.Empty;
  7244. /// <summary>
  7245. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  7246. /// </summary>
  7247. private void S4_3进站接口(int plcNo, string stationNameStr)
  7248. {
  7249. Stopwatch stopwatch1 = new Stopwatch();
  7250. Stopwatch stopwatch2 = new Stopwatch();
  7251. try
  7252. {
  7253. stopwatch1.Start();
  7254. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7255. sn = sn.Replace("\0", "");
  7256. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7257. #region 查询15个载具码
  7258. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7259. string vehicleData = string.Empty;
  7260. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7261. if (string.IsNullOrEmpty(vehicleData))
  7262. vehicleData = "";
  7263. if (snResult != 0)
  7264. {
  7265. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7266. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7267. writeToPLC_Flag1.Adress = 2463;
  7268. writeToPLC_Flag1.Value = (short)4;
  7269. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7270. stopwatch1.Stop();
  7271. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7272. return;
  7273. }
  7274. string[] cavitySNs = vehicleData.Split('.');
  7275. if (cavitySNs != null && cavitySNs.Length > 0)
  7276. {
  7277. for (int i = 0; i < cavitySNs.Length; i++)
  7278. {
  7279. if (string.IsNullOrEmpty(cavitySNs[i]))
  7280. vehicleCodes.Add("");
  7281. else
  7282. vehicleCodes.Add(cavitySNs[i]);
  7283. }
  7284. }
  7285. #endregion 查询15个载具码
  7286. #region 查询15个产品SN
  7287. List<string> portNos = new List<string>(); // 15个产品SN
  7288. foreach (string vehicleCode in vehicleCodes)
  7289. {
  7290. if (string.IsNullOrEmpty(vehicleCode))
  7291. portNos.Add("");
  7292. else
  7293. {
  7294. // 查询
  7295. string cavityData = string.Empty;
  7296. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7297. if (string.IsNullOrEmpty(cavityData))
  7298. cavityData = "";
  7299. if (snResult1 != 0)
  7300. {
  7301. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7302. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7303. writeToPLC_Flag1.Adress = 2463;
  7304. writeToPLC_Flag1.Value = (short)4;
  7305. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7306. stopwatch1.Stop();
  7307. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7308. return;
  7309. }
  7310. string[] partSNs = cavityData.Split('.');
  7311. if (partSNs != null && partSNs.Length >= 1)
  7312. portNos.Add(partSNs[0]);
  7313. else
  7314. portNos.Add("");
  7315. }
  7316. }
  7317. #endregion 查询15个产品SN
  7318. // 调用MES进站(最多15个)
  7319. stopwatch2.Start();
  7320. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  7321. for (int i = 0; i < vehicleCodes.Count; i++)
  7322. {
  7323. // 循环进站
  7324. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  7325. {
  7326. // 产品SN(物料码)校验
  7327. string portNo = portNos[i];
  7328. List<TestItem> item = new List<TestItem>();
  7329. item.Add(new TestItem()
  7330. {
  7331. Parameter_name = "弹夹码",
  7332. Parameter_value = sn,
  7333. });
  7334. item.Add(new TestItem()
  7335. {
  7336. Parameter_name = "弹夹穴位",
  7337. Parameter_value = (i + 1).ToString(),
  7338. });
  7339. item.Add(new TestItem()
  7340. {
  7341. Parameter_name = "载具码",
  7342. Parameter_value = vehicleCodes[i],
  7343. });
  7344. item.Add(new TestItem()
  7345. {
  7346. Parameter_name = "载具穴号",
  7347. Parameter_value = "1",
  7348. });
  7349. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  7350. }
  7351. }
  7352. stopwatch2.Stop();
  7353. short result = 0;
  7354. bool haveMesWarn = results.Contains(5);
  7355. bool havePCWarn = results.Contains(6);
  7356. if (haveMesWarn)
  7357. result = 2; // 5->2
  7358. else if (havePCWarn)
  7359. result = 6; // 6->4
  7360. else
  7361. result = 1;
  7362. // MES_Flag 为4MES报错
  7363. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7364. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7365. writeToPLC_Flag.Name = "d3MES_FLAG";
  7366. writeToPLC_Flag.Adress = 2463;
  7367. writeToPLC_Flag.Value = result;
  7368. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7369. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7370. }
  7371. catch (Exception ex)
  7372. {
  7373. stopwatch2.Stop();
  7374. // MES_Flag 为4上位机报错
  7375. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7376. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7377. writeToPLC_Flag.Name = "d3MES_FLAG";
  7378. writeToPLC_Flag.Adress = 2463;
  7379. writeToPLC_Flag.Value = (short)4;
  7380. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7381. string str = ex.StackTrace;
  7382. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7383. }
  7384. stopwatch1.Stop();
  7385. AddMessage(LogType.Info, stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7386. }
  7387. // 上次采集到的SN
  7388. //private string sn_S4_3出站接口 = string.Empty;
  7389. /// <summary>
  7390. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  7391. /// </summary>
  7392. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  7393. {
  7394. Stopwatch stopwatch1 = new Stopwatch();
  7395. Stopwatch stopwatch2 = new Stopwatch();
  7396. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7397. string stationNameStr = stationCode + stationName;
  7398. string processItem = stationName; // 测试项目
  7399. try
  7400. {
  7401. stopwatch1.Start();
  7402. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7403. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7404. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7405. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7406. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7407. sn = sn.Replace("\0", "");
  7408. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7409. bool isPass = d3Result == 1; // 产品结果 bool
  7410. #region 查询15个载具码
  7411. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7412. string vehicleData = string.Empty;
  7413. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7414. if (string.IsNullOrEmpty(vehicleData))
  7415. vehicleData = "";
  7416. if (snResult1 != 0)
  7417. {
  7418. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7419. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7420. writeToPLC_Flag1.Adress = 2463;
  7421. writeToPLC_Flag1.Value = (short)4;
  7422. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7423. stopwatch1.Stop();
  7424. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7425. return;
  7426. }
  7427. string[] cavitySNs = vehicleData.Split('.');
  7428. if (cavitySNs != null && cavitySNs.Length > 0)
  7429. {
  7430. for (int i = 0; i < cavitySNs.Length; i++)
  7431. {
  7432. if (string.IsNullOrEmpty(cavitySNs[i]))
  7433. vehicleCodes.Add("");
  7434. else
  7435. vehicleCodes.Add(cavitySNs[i]);
  7436. }
  7437. }
  7438. #endregion 查询15个载具码
  7439. // 统一查 产品SN列表
  7440. List<string> partNos = new List<string>();
  7441. foreach (string vehicleCode in vehicleCodes)
  7442. {
  7443. if (string.IsNullOrEmpty(vehicleCode))
  7444. partNos.Add("");
  7445. else
  7446. {
  7447. string partNo = "";
  7448. #region 查询载具上的产品信息
  7449. string cavityData = string.Empty;
  7450. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7451. if (string.IsNullOrEmpty(cavityData))
  7452. cavityData = "";
  7453. if (snResult != 0)
  7454. {
  7455. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7456. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7457. writeToPLC_Flag1.Adress = 2463;
  7458. writeToPLC_Flag1.Value = (short)4;
  7459. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7460. stopwatch1.Stop();
  7461. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7462. return;
  7463. }
  7464. string[] partSNs = cavityData.Split('.');
  7465. if (partSNs != null && partSNs.Length >= 1)
  7466. partNo = partSNs[0];
  7467. #endregion 查询载具上的产品信息
  7468. partNos.Add(partNo);
  7469. }
  7470. }
  7471. // 统一上传 - 调用MES出站
  7472. stopwatch2.Start();
  7473. List<int> results = new List<int>();
  7474. for (int i = 0; i < partNos.Count; i++)
  7475. {
  7476. string index = (i + 1).ToString(); // 弹夹穴号
  7477. if (string.IsNullOrEmpty(partNos[i]))
  7478. results.Add(1);
  7479. else
  7480. {
  7481. List<TestItem> items1 = new List<TestItem>();
  7482. items1.Add(new TestItem()
  7483. {
  7484. Parameter_name = "弹夹码",
  7485. Parameter_value = sn,
  7486. Parameter_unit = ""
  7487. });
  7488. items1.Add(new TestItem()
  7489. {
  7490. Parameter_name = "弹夹穴号",
  7491. Parameter_value = index,
  7492. Parameter_unit = ""
  7493. });
  7494. items1.Add(new TestItem()
  7495. {
  7496. Parameter_name = "载具码",
  7497. Parameter_value = vehicleCodes[i],
  7498. Parameter_unit = ""
  7499. });
  7500. items1.Add(new TestItem()
  7501. {
  7502. Parameter_name = "载具穴号",
  7503. Parameter_value = "1",
  7504. Parameter_unit = ""
  7505. });
  7506. items1.Add(new TestItem()
  7507. {
  7508. Parameter_name = "产品结果",
  7509. Parameter_value = d3Result == 1 ? "OK" : "NG",
  7510. Parameter_unit = ""
  7511. });
  7512. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7513. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  7514. results.Add(result1);
  7515. }
  7516. }
  7517. short result = 0;
  7518. if (results.All(a => a == 1))
  7519. result = 1;
  7520. else if (results.Contains(3))
  7521. result = 3;
  7522. else if (results.Contains(2))
  7523. result = 2;
  7524. else if (results.Contains(4))
  7525. result = 4;
  7526. else
  7527. result = 4;
  7528. stopwatch2.Stop();
  7529. // MES_Flag 为4MES报错
  7530. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7531. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7532. writeToPLC_Flag.Name = "d3MES_FLAG";
  7533. writeToPLC_Flag.Adress = 2463;
  7534. writeToPLC_Flag.Value = result;
  7535. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7536. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7537. }
  7538. catch (Exception ex)
  7539. {
  7540. stopwatch2.Restart();
  7541. // MES_Flag 为4上位机报错
  7542. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7543. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7544. writeToPLC_Flag.Name = "d3MES_FLAG";
  7545. writeToPLC_Flag.Adress = 2463;
  7546. writeToPLC_Flag.Value = (short)4;
  7547. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7548. string str = ex.StackTrace;
  7549. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7550. stopwatch2.Stop();
  7551. }
  7552. stopwatch1.Stop();
  7553. AddMessage(LogType.Info, stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7554. }
  7555. // 上次采集到的SN
  7556. //private string sn_S4_4进站接口 = string.Empty;
  7557. /// <summary>
  7558. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  7559. /// </summary>
  7560. private void S4_4进站接口(int plcNo, string stationNameStr)
  7561. {
  7562. Stopwatch stopwatch1 = new Stopwatch();
  7563. Stopwatch stopwatch2 = new Stopwatch();
  7564. try
  7565. {
  7566. stopwatch1.Start();
  7567. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  7568. sn = sn.Replace("\0", "");
  7569. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  7570. #region 查询15个载具码
  7571. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7572. string vehicleData = string.Empty;
  7573. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7574. if (string.IsNullOrEmpty(vehicleData))
  7575. vehicleData = "";
  7576. if (snResult != 0)
  7577. {
  7578. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7579. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7580. writeToPLC_Flag1.Adress = 2463;
  7581. writeToPLC_Flag1.Value = (short)4;
  7582. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7583. stopwatch1.Stop();
  7584. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7585. return;
  7586. }
  7587. string[] cavitySNs = vehicleData.Split('.');
  7588. if (cavitySNs != null && cavitySNs.Length > 0)
  7589. {
  7590. for (int i = 0; i < cavitySNs.Length; i++)
  7591. {
  7592. if (string.IsNullOrEmpty(cavitySNs[i]))
  7593. vehicleCodes.Add("");
  7594. else
  7595. vehicleCodes.Add(cavitySNs[i]);
  7596. }
  7597. }
  7598. #endregion 查询15个载具码
  7599. #region 查询15个产品SN
  7600. List<string> portNos = new List<string>(); // 15个产品SN
  7601. foreach (string vehicleCode in vehicleCodes)
  7602. {
  7603. if (string.IsNullOrEmpty(vehicleCode))
  7604. portNos.Add("");
  7605. else
  7606. {
  7607. // 查询
  7608. string cavityData = string.Empty;
  7609. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7610. if (string.IsNullOrEmpty(cavityData))
  7611. cavityData = "";
  7612. if (snResult1 != 0)
  7613. {
  7614. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7615. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7616. writeToPLC_Flag1.Adress = 2463;
  7617. writeToPLC_Flag1.Value = (short)4;
  7618. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7619. stopwatch1.Stop();
  7620. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7621. return;
  7622. }
  7623. string[] partSNs = cavityData.Split('.');
  7624. if (partSNs != null && partSNs.Length >= 1)
  7625. portNos.Add(partSNs[0]);
  7626. else
  7627. portNos.Add("");
  7628. }
  7629. }
  7630. #endregion 查询15个产品SN
  7631. // 调用MES进站(最多15个)
  7632. stopwatch2.Start();
  7633. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  7634. for (int i = 0; i < vehicleCodes.Count; i++)
  7635. {
  7636. // 循环进站
  7637. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  7638. {
  7639. // 产品SN(物料码)校验
  7640. string portNo = portNos[i];
  7641. List<TestItem> item = new List<TestItem>();
  7642. item.Add(new TestItem()
  7643. {
  7644. Parameter_name = "弹夹码",
  7645. Parameter_value = sn,
  7646. });
  7647. item.Add(new TestItem()
  7648. {
  7649. Parameter_name = "弹夹穴位",
  7650. Parameter_value = (i + 1).ToString(),
  7651. });
  7652. item.Add(new TestItem()
  7653. {
  7654. Parameter_name = "载具码",
  7655. Parameter_value = vehicleCodes[i],
  7656. });
  7657. item.Add(new TestItem()
  7658. {
  7659. Parameter_name = "载具穴号",
  7660. Parameter_value = "1",
  7661. });
  7662. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  7663. }
  7664. }
  7665. stopwatch2.Stop();
  7666. short result = 0;
  7667. bool haveMesWarn = results.Contains(5);
  7668. bool havePCWarn = results.Contains(6);
  7669. if (haveMesWarn)
  7670. result = 2; // 5->2
  7671. else if (havePCWarn)
  7672. result = 6; // 6->4
  7673. else
  7674. result = 1;
  7675. // MES_Flag 为4MES报错
  7676. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7677. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7678. writeToPLC_Flag.Name = "d4MES_FLAG";
  7679. writeToPLC_Flag.Adress = 2496;
  7680. writeToPLC_Flag.Value = result;
  7681. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  7682. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7683. }
  7684. catch (Exception ex)
  7685. {
  7686. stopwatch2.Stop();
  7687. // MES_Flag 为4上位机报错
  7688. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  7689. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7690. writeToPLC_Flag.Name = "d4MES_FLAG";
  7691. writeToPLC_Flag.Adress = 2496;
  7692. writeToPLC_Flag.Value = (short)4;
  7693. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  7694. string str = ex.StackTrace;
  7695. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7696. }
  7697. stopwatch1.Stop();
  7698. AddMessage(LogType.Info, stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7699. }
  7700. // 上次采集到的SN
  7701. //private string sn_S4_4出站接口 = string.Empty;
  7702. /// <summary>
  7703. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  7704. /// </summary>
  7705. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  7706. {
  7707. Stopwatch stopwatch1 = new Stopwatch();
  7708. Stopwatch stopwatch2 = new Stopwatch();
  7709. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7710. string stationNameStr = stationCode + stationName;
  7711. string processItem = stationName; // 测试项目
  7712. try
  7713. {
  7714. stopwatch1.Start();
  7715. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7716. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7717. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7718. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7719. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  7720. sn = sn.Replace("\0", "");
  7721. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  7722. bool isPass = d4Result == 1; // 产品结果 bool
  7723. #region 查询15个载具码
  7724. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7725. string vehicleData = string.Empty;
  7726. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7727. if (string.IsNullOrEmpty(vehicleData))
  7728. vehicleData = "";
  7729. if (snResult1 != 0)
  7730. {
  7731. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7732. writeToPLC_Flag1.Name = "d4MES_FLAG";
  7733. writeToPLC_Flag1.Adress = 2496;
  7734. writeToPLC_Flag1.Value = (short)4;
  7735. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  7736. stopwatch1.Stop();
  7737. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7738. return;
  7739. }
  7740. string[] cavitySNs = vehicleData.Split('.');
  7741. if (cavitySNs != null && cavitySNs.Length > 0)
  7742. {
  7743. for (int i = 0; i < cavitySNs.Length; i++)
  7744. {
  7745. if (string.IsNullOrEmpty(cavitySNs[i]))
  7746. vehicleCodes.Add("");
  7747. else
  7748. vehicleCodes.Add(cavitySNs[i]);
  7749. }
  7750. }
  7751. #endregion 查询15个载具码
  7752. // 统一查 产品SN列表
  7753. List<string> partNos = new List<string>();
  7754. foreach (string vehicleCode in vehicleCodes)
  7755. {
  7756. if (string.IsNullOrEmpty(vehicleCode))
  7757. partNos.Add("");
  7758. else
  7759. {
  7760. string partNo = "";
  7761. #region 查询载具上的产品信息
  7762. string cavityData = string.Empty;
  7763. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7764. if (string.IsNullOrEmpty(cavityData))
  7765. cavityData = "";
  7766. if (snResult != 0)
  7767. {
  7768. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7769. writeToPLC_Flag1.Name = "d4MES_FLAG";
  7770. writeToPLC_Flag1.Adress = 2496;
  7771. writeToPLC_Flag1.Value = (short)4;
  7772. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  7773. stopwatch1.Stop();
  7774. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7775. return;
  7776. }
  7777. string[] partSNs = cavityData.Split('.');
  7778. if (partSNs != null && partSNs.Length >= 1)
  7779. partNo = partSNs[0];
  7780. #endregion 查询载具上的产品信息
  7781. partNos.Add(partNo);
  7782. }
  7783. }
  7784. // 调用MES出站
  7785. stopwatch2.Start();
  7786. // 统一上传
  7787. List<int> results = new List<int>();
  7788. for (int i = 0; i < partNos.Count; i++)
  7789. {
  7790. string index = (i + 1).ToString(); // 弹夹穴号
  7791. if (string.IsNullOrEmpty(partNos[i]))
  7792. results.Add(1);
  7793. else
  7794. {
  7795. List<TestItem> items1 = new List<TestItem>();
  7796. items1.Add(new TestItem()
  7797. {
  7798. Parameter_name = "弹夹码",
  7799. Parameter_value = sn,
  7800. Parameter_unit = ""
  7801. });
  7802. items1.Add(new TestItem()
  7803. {
  7804. Parameter_name = "弹夹穴号",
  7805. Parameter_value = index,
  7806. Parameter_unit = ""
  7807. });
  7808. items1.Add(new TestItem()
  7809. {
  7810. Parameter_name = "载具码",
  7811. Parameter_value = vehicleCodes[i],
  7812. Parameter_unit = ""
  7813. });
  7814. items1.Add(new TestItem()
  7815. {
  7816. Parameter_name = "载具穴号",
  7817. Parameter_value = "1",
  7818. Parameter_unit = ""
  7819. });
  7820. items1.Add(new TestItem()
  7821. {
  7822. Parameter_name = "产品结果",
  7823. Parameter_value = d4Result == 1 ? "OK" : "NG",
  7824. Parameter_unit = ""
  7825. });
  7826. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7827. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  7828. results.Add(result1);
  7829. }
  7830. }
  7831. short result = 0;
  7832. if (results.All(a => a == 1))
  7833. result = 1;
  7834. else if (results.Contains(3))
  7835. result = 3;
  7836. else if (results.Contains(2))
  7837. result = 2;
  7838. else if (results.Contains(4))
  7839. result = 4;
  7840. else
  7841. result = 4;
  7842. stopwatch2.Stop();
  7843. // MES_Flag 为4MES报错
  7844. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7845. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7846. writeToPLC_Flag.Name = "d4MES_FLAG";
  7847. writeToPLC_Flag.Adress = 2496;
  7848. writeToPLC_Flag.Value = result;
  7849. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  7850. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7851. }
  7852. catch (Exception ex)
  7853. {
  7854. stopwatch2.Restart();
  7855. // MES_Flag 为4上位机报错
  7856. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  7857. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7858. writeToPLC_Flag.Name = "d4MES_FLAG";
  7859. writeToPLC_Flag.Adress = 2496;
  7860. writeToPLC_Flag.Value = (short)4;
  7861. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  7862. string str = ex.StackTrace;
  7863. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7864. stopwatch2.Stop();
  7865. }
  7866. stopwatch1.Stop();
  7867. AddMessage(LogType.Info, stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7868. }
  7869. /// <summary>
  7870. /// [S4] 取放桁架 - S4_5弹夹扫码
  7871. /// </summary>
  7872. /// <param name="plcNo">PLC编号</param>
  7873. /// <param name="stationNameStr">工站全称</param>
  7874. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  7875. {
  7876. Stopwatch stopwatch1 = new Stopwatch();
  7877. Stopwatch stopwatch2 = new Stopwatch();
  7878. try
  7879. {
  7880. stopwatch1.Start();
  7881. // ZS 弹夹扫码
  7882. string d5BulletclipCode = " "; // 扫到的码
  7883. short d5BulletclipScanCode = 2;
  7884. stopwatch2.Start();
  7885. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  7886. //// MES_Flag
  7887. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7888. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7889. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  7890. writeToPLC_Flag.Adress = 2528;
  7891. writeToPLC_Flag.Value = d5BulletclipScanCode;
  7892. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  7893. {
  7894. Name = "d5BulletclipCode",
  7895. Adress = 2529,
  7896. ValueType = PLCValueType.String,
  7897. ValueTypeStrLength = 20,
  7898. Value = d5BulletclipCode
  7899. });
  7900. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  7901. stopwatch2.Stop();
  7902. }
  7903. catch (Exception ex)
  7904. {
  7905. string str = ex.StackTrace;
  7906. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7907. stopwatch2.Start();
  7908. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  7909. //// MES_Flag
  7910. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  7911. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7912. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  7913. writeToPLC_Flag.Adress = 2528;
  7914. writeToPLC_Flag.Value = (short)6;
  7915. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  7916. {
  7917. Name = "d5BulletclipCode",
  7918. Adress = 2529,
  7919. ValueType = PLCValueType.String,
  7920. ValueTypeStrLength = 20,
  7921. Value = " "
  7922. });
  7923. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  7924. stopwatch2.Stop();
  7925. }
  7926. stopwatch1.Stop();
  7927. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7928. }
  7929. /// <summary>
  7930. /// [S4] 取放桁架 - S4_5载具扫码
  7931. /// </summary>
  7932. /// <param name="plcNo">PLC编号</param>
  7933. /// <param name="stationNameStr">工站全称</param>
  7934. private void S4_5载具扫码(int plcNo, string stationNameStr)
  7935. {
  7936. Stopwatch stopwatch1 = new Stopwatch();
  7937. Stopwatch stopwatch2 = new Stopwatch();
  7938. try
  7939. {
  7940. stopwatch1.Start();
  7941. // ZS 载具扫码
  7942. string d5VehicleCode = " "; // 扫到的码
  7943. short d5VehicleScanCode = 2;
  7944. #region 进站
  7945. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  7946. {
  7947. // 查产品SN
  7948. #region 查询载具上的产品信息
  7949. string cavityData = string.Empty;
  7950. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  7951. if (string.IsNullOrEmpty(cavityData))
  7952. cavityData = "";
  7953. if (snResult != 0)
  7954. {
  7955. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7956. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  7957. writeToPLC_Flag1.Adress = 2559;
  7958. writeToPLC_Flag1.Value = (short)6;
  7959. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  7960. {
  7961. Name = "d5VehicleCode",
  7962. Adress = 2560,
  7963. ValueType = PLCValueType.String,
  7964. ValueTypeStrLength = 20,
  7965. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7966. });
  7967. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  7968. stopwatch1.Stop();
  7969. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7970. return;
  7971. }
  7972. string[] cavitySNs = cavityData.Split('.');
  7973. string partNo = "";
  7974. if (cavitySNs != null && cavitySNs.Length >= 1)
  7975. {
  7976. partNo = cavitySNs[0];
  7977. }
  7978. #endregion 查询载具上的产品信息
  7979. List<TestItem> item = new List<TestItem>();
  7980. item.Add(new TestItem()
  7981. {
  7982. Parameter_name = "载具码",
  7983. Parameter_value = d5VehicleCode,
  7984. });
  7985. item.Add(new TestItem()
  7986. {
  7987. Parameter_name = "载具穴号",
  7988. Parameter_value = "1",
  7989. });
  7990. stopwatch2.Start();
  7991. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  7992. stopwatch2.Stop();
  7993. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  7994. }
  7995. #endregion 进站
  7996. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  7997. //// MES_Flag
  7998. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7999. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8000. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8001. writeToPLC_Flag.Adress = 2559;
  8002. writeToPLC_Flag.Value = d5VehicleScanCode;
  8003. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8004. {
  8005. Name = "d5VehicleCode",
  8006. Adress = 2560,
  8007. ValueType = PLCValueType.String,
  8008. ValueTypeStrLength = 20,
  8009. Value = d5VehicleCode
  8010. });
  8011. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8012. }
  8013. catch (Exception ex)
  8014. {
  8015. string str = ex.StackTrace;
  8016. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8017. stopwatch2.Start();
  8018. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  8019. //// MES_Flag
  8020. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  8021. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8022. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8023. writeToPLC_Flag.Adress = 2559;
  8024. writeToPLC_Flag.Value = (short)6;
  8025. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8026. {
  8027. Name = "d5VehicleCode",
  8028. Adress = 2560,
  8029. ValueType = PLCValueType.String,
  8030. ValueTypeStrLength = 20,
  8031. Value = " "
  8032. });
  8033. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8034. stopwatch2.Stop();
  8035. }
  8036. stopwatch1.Stop();
  8037. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8038. }
  8039. // 上次采集到的SN
  8040. //private string sn_S4_5出站接口 = string.Empty;
  8041. /// <summary>
  8042. /// [S4] 取放桁架 - S4_5出站接口
  8043. /// </summary>
  8044. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  8045. {
  8046. Stopwatch stopwatch1 = new Stopwatch();
  8047. Stopwatch stopwatch2 = new Stopwatch();
  8048. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8049. string stationNameStr = stationCode + stationName;
  8050. string processItem = stationName; // 测试项目
  8051. try
  8052. {
  8053. stopwatch1.Start();
  8054. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8055. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8056. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8057. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8058. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  8059. sn = sn.Replace("\0", "");
  8060. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  8061. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  8062. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  8063. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  8064. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  8065. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  8066. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  8067. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  8068. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  8069. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  8070. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  8071. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  8072. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  8073. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  8074. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  8075. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  8076. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  8077. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  8078. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  8079. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  8080. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  8081. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  8082. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  8083. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  8084. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  8085. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  8086. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  8087. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  8088. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  8089. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  8090. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  8091. bool pass = d5Result == 1;
  8092. // 存 载具SN列表
  8093. List<string> vehicleCodes = new List<string>()
  8094. {
  8095. d5VehicleCode1,d5VehicleCode2,d5VehicleCode3,d5VehicleCode4,d5VehicleCode5,
  8096. d5VehicleCode6,d5VehicleCode7,d5VehicleCode8,d5VehicleCode9,d5VehicleCode10,
  8097. d5VehicleCode11,d5VehicleCode12,d5VehicleCode13,d5VehicleCode14,d5VehicleCode15
  8098. };
  8099. // 统一查 产品SN列表
  8100. List<string> partNos = new List<string>();
  8101. foreach (string vehicleCode in vehicleCodes)
  8102. {
  8103. if (string.IsNullOrEmpty(vehicleCode))
  8104. partNos.Add("");
  8105. else
  8106. {
  8107. string partNo = "";
  8108. #region 查询载具上的产品信息
  8109. string cavityData = string.Empty;
  8110. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8111. if (string.IsNullOrEmpty(cavityData))
  8112. cavityData = "";
  8113. if (snResult != 0)
  8114. {
  8115. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8116. writeToPLC_Flag1.Name = "d5MES_FLAG";
  8117. writeToPLC_Flag1.Adress = 2591;
  8118. writeToPLC_Flag1.Value = (short)4;
  8119. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  8120. stopwatch1.Stop();
  8121. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8122. return;
  8123. }
  8124. string[] cavitySNs = cavityData.Split('.');
  8125. if (cavitySNs != null && cavitySNs.Length >= 1)
  8126. partNo = cavitySNs[0];
  8127. #endregion 查询载具上的产品信息
  8128. partNos.Add(partNo);
  8129. }
  8130. }
  8131. // 统一上传
  8132. stopwatch2.Start();
  8133. List<int> results = new List<int>();
  8134. for (int i = 0; i < partNos.Count; i++)
  8135. {
  8136. string index = (i + 1).ToString(); // 弹夹穴号
  8137. if (string.IsNullOrEmpty(partNos[i]))
  8138. results.Add(1);
  8139. else
  8140. {
  8141. List<TestItem> items1 = new List<TestItem>();
  8142. items1.Add(new TestItem()
  8143. {
  8144. Parameter_name = "弹夹码",
  8145. Parameter_value = sn,
  8146. Parameter_unit = ""
  8147. });
  8148. items1.Add(new TestItem()
  8149. {
  8150. Parameter_name = "弹夹穴号",
  8151. Parameter_value = index,
  8152. Parameter_unit = ""
  8153. });
  8154. items1.Add(new TestItem()
  8155. {
  8156. Parameter_name = "载具码",
  8157. Parameter_value = vehicleCodes[i],
  8158. Parameter_unit = ""
  8159. });
  8160. items1.Add(new TestItem()
  8161. {
  8162. Parameter_name = "载具穴号",
  8163. Parameter_value = "1",
  8164. Parameter_unit = ""
  8165. });
  8166. items1.Add(new TestItem()
  8167. {
  8168. Parameter_name = "产品结果",
  8169. Parameter_value = d5Result == 1 ? "OK" : "NG",
  8170. Parameter_unit = ""
  8171. });
  8172. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8173. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  8174. results.Add(result1);
  8175. }
  8176. }
  8177. short result = 0;
  8178. if (results.All(a => a == 1))
  8179. result = 1;
  8180. else if (results.Contains(3))
  8181. result = 3;
  8182. else if (results.Contains(2))
  8183. result = 2;
  8184. else if (results.Contains(4))
  8185. result = 4;
  8186. else
  8187. result = 4;
  8188. stopwatch2.Stop();
  8189. #region 存储绑定数据到 边线MES系统中
  8190. if (result == 1)
  8191. {
  8192. // 删除绑定信息
  8193. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  8194. if (resultMesR != 0)
  8195. {
  8196. result = 4;
  8197. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  8198. }
  8199. }
  8200. #endregion 存储绑定数据到 边线MES系统中
  8201. // MES_Flag 为4MES报错
  8202. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8203. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8204. writeToPLC_Flag.Name = "d5MES_FLAG";
  8205. writeToPLC_Flag.Adress = 2591;
  8206. writeToPLC_Flag.Value = result;
  8207. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8208. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8209. }
  8210. catch (Exception ex)
  8211. {
  8212. stopwatch2.Restart();
  8213. // MES_Flag 为4上位机报错
  8214. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  8215. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8216. writeToPLC_Flag.Name = "d5MES_FLAG";
  8217. writeToPLC_Flag.Adress = 2591;
  8218. writeToPLC_Flag.Value = (short)4;
  8219. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8220. stopwatch2.Stop();
  8221. string str = ex.StackTrace;
  8222. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8223. }
  8224. stopwatch1.Stop();
  8225. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8226. }
  8227. /// <summary>
  8228. /// [S4] 取放桁架 - S4_5节拍接口
  8229. /// </summary>
  8230. /// <param name="plcNo">PLC编号</param>
  8231. /// <param name="stationNameStr">工站全称</param>
  8232. private void S4_5节拍接口(int plcNo, string stationNameStr)
  8233. {
  8234. Stopwatch stopwatch1 = new Stopwatch();
  8235. Stopwatch stopwatch2 = new Stopwatch();
  8236. string resultStr = string.Empty;
  8237. try
  8238. {
  8239. stopwatch1.Start();
  8240. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  8241. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  8242. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  8243. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8244. if (!actionBool)
  8245. {
  8246. stopwatch2.Start();
  8247. // MES_Flag
  8248. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  8249. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8250. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8251. writeToPLC_Flag1.Adress = 2924;
  8252. writeToPLC_Flag1.Value = (short)4;
  8253. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8254. stopwatch2.Stop();
  8255. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8256. return;
  8257. }
  8258. string d5OEEPartNo = string.Empty; // 物料码
  8259. if (string.IsNullOrEmpty(d5OEEProductSN))
  8260. {
  8261. stopwatch2.Start();
  8262. // MES_Flag
  8263. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8264. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8265. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8266. writeToPLC_Flag1.Adress = 2924;
  8267. writeToPLC_Flag1.Value = (short)1;
  8268. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8269. stopwatch2.Stop();
  8270. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8271. return;
  8272. }
  8273. else
  8274. { // 查产品SN
  8275. d5OEEPartNo = "Test"; // ZS
  8276. }
  8277. short d5OEEMES_FLAG = 0;
  8278. // 上传OEE
  8279. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  8280. d5OEEMES_FLAG = result.Item1;
  8281. resultStr = result.Item2;
  8282. stopwatch2.Start();
  8283. // MES_Flag
  8284. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8285. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8286. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8287. writeToPLC_Flag.Adress = 2924;
  8288. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  8289. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8290. stopwatch2.Stop();
  8291. }
  8292. catch (Exception ex)
  8293. {
  8294. string str = ex.StackTrace;
  8295. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8296. // MES_Flag
  8297. stopwatch2.Start();
  8298. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  8299. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8300. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8301. writeToPLC_Flag.Adress = 2924;
  8302. writeToPLC_Flag.Value = (short)4;
  8303. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8304. stopwatch2.Stop();
  8305. }
  8306. stopwatch1.Stop();
  8307. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8308. }
  8309. #endregion [S4] 取放桁架
  8310. #endregion PLC4 刘果段
  8311. #region PLC5 张超凡
  8312. #region [S5] Tray盘下料装备
  8313. /// <summary>
  8314. /// S5工位的数据- 触发信号上次的值
  8315. /// </summary>
  8316. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  8317. /// <summary>
  8318. /// S5工位的数据(含触发信号)
  8319. /// </summary>
  8320. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  8321. /// <summary>
  8322. /// S5工位的数据- 回写点位
  8323. /// </summary>
  8324. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8325. /// <summary>
  8326. /// [S5] Tray盘下料装备
  8327. /// </summary>
  8328. /// <param name="plcNo">PLC编号</param>
  8329. //private void ReadStation_S5(int plcNo)
  8330. //{
  8331. // // [S1] Tray盘上料装备
  8332. // // [S2] FCT
  8333. // // [S3] 值板机
  8334. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8335. // // [S5] Tray盘下料装备
  8336. // /// 上位机心跳
  8337. // /// 获取设备报警数据与状态信息
  8338. // string stationCode = "[S5]";
  8339. // string stationName = "Tray盘下料装备";
  8340. // string stationNameStr = stationCode + stationName;
  8341. // #region 创建字典
  8342. // // 触发信号字典 赋值
  8343. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8344. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8345. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8346. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8347. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  8348. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8349. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  8350. // // PLC数据字典 赋值
  8351. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8352. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  8353. // s5PLCData.Add("e1ProductSN_Check", ""); //
  8354. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8355. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  8356. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  8357. // s5PLCData.Add("e1PartNo", ""); // 物料码
  8358. // s5PLCData.Add("e1Result", 0); // 产品结果
  8359. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8360. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  8361. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  8362. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  8363. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8364. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  8365. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  8366. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8367. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  8368. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  8369. // #endregion 创建字典
  8370. // while (IsRun)
  8371. // {
  8372. // try
  8373. // {
  8374. // if (!GlobalContext._IsCon_Funs5)
  8375. // {
  8376. // UpdatePLCMonitor(1, plcNo, 0);
  8377. // continue;
  8378. // }
  8379. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8380. // {
  8381. // Stopwatch stopwatch1 = new Stopwatch();
  8382. // Stopwatch stopwatch2 = new Stopwatch();
  8383. // stopwatch1.Start();
  8384. // stopwatch2.Start();
  8385. // #region 一次性读取所有数据
  8386. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8387. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  8388. // int[] datas = data1.Concat(data2).ToArray();
  8389. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  8390. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  8391. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8392. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  8393. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  8394. // s5PLCData["e1MES_FLAG"] = datas[35];
  8395. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  8396. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  8397. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  8398. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  8399. // s5PLCData["e1Result"] = datas[76];
  8400. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  8401. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  8402. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  8403. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  8404. // s5PLCData["e1OEEType"] = datas[109];
  8405. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  8406. // s5PLCData["e1AGVUpStart"] = datas[121];
  8407. // s5PLCData["e1AGVUpEnd"] = datas[122];
  8408. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  8409. // s5PLCData["e1AGVDownStart"] = datas[134];
  8410. // s5PLCData["e1AGVDownEnd"] = datas[135];
  8411. // #endregion 一次性读取所有数据
  8412. // stopwatch2.Stop();
  8413. // #region 回写操作,写后清空flag
  8414. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  8415. // #endregion 回写操作,写后清空flag
  8416. // #region 进站校验
  8417. // try
  8418. // {
  8419. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  8420. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  8421. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  8422. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  8423. // {
  8424. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  8425. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8426. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  8427. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8428. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  8429. // }
  8430. // }
  8431. // catch (Exception ex)
  8432. // {
  8433. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8434. // string str = ex.StackTrace;
  8435. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8436. // }
  8437. // #endregion 进站校验
  8438. // #region 出站接口
  8439. // try
  8440. // {
  8441. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  8442. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  8443. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  8444. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  8445. // {
  8446. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  8447. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8448. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  8449. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  8450. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  8451. // }
  8452. // }
  8453. // catch (Exception ex)
  8454. // {
  8455. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  8456. // string str = ex.StackTrace;
  8457. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8458. // }
  8459. // #endregion 出站接口
  8460. // #region 节拍接口
  8461. // try
  8462. // {
  8463. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  8464. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  8465. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  8466. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  8467. // {
  8468. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  8469. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8470. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  8471. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  8472. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  8473. // }
  8474. // }
  8475. // catch (Exception ex)
  8476. // {
  8477. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  8478. // string str = ex.StackTrace;
  8479. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8480. // }
  8481. // #endregion 节拍接口
  8482. // #region AGV上料
  8483. // // AGV上料叫AGV信号
  8484. // try
  8485. // {
  8486. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  8487. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  8488. // if (e1AGVUpCall != e1AGVUpCallOld)
  8489. // {
  8490. // if (e1AGVUpCall == 1) // 0->1
  8491. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  8492. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  8493. // }
  8494. // }
  8495. // catch (Exception ex)
  8496. // {
  8497. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  8498. // string str = ex.StackTrace;
  8499. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8500. // }
  8501. // // AGV上料完成信号
  8502. // try
  8503. // {
  8504. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  8505. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  8506. // if (e1AGVUpEnd != e1AGVUpEndOld)
  8507. // {
  8508. // if (e1AGVUpEnd == 1) // 0->1
  8509. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  8510. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  8511. // }
  8512. // }
  8513. // catch (Exception ex)
  8514. // {
  8515. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  8516. // string str = ex.StackTrace;
  8517. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8518. // }
  8519. // #endregion AGV上料
  8520. // #region AGV下料
  8521. // // AGV下料叫agv信号
  8522. // try
  8523. // {
  8524. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  8525. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  8526. // if (e1AGVDownCall != e1AGVDownCallOld)
  8527. // {
  8528. // if (e1AGVDownCall == 1) // 0->1
  8529. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  8530. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  8531. // }
  8532. // }
  8533. // catch (Exception ex)
  8534. // {
  8535. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  8536. // string str = ex.StackTrace;
  8537. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8538. // }
  8539. // // AGV下料完成信号
  8540. // try
  8541. // {
  8542. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  8543. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  8544. // if (e1AGVDownEnd != e1AGVDownEndOld)
  8545. // {
  8546. // if (e1AGVDownEnd == 1) // 0->1
  8547. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  8548. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  8549. // }
  8550. // }
  8551. // catch (Exception ex)
  8552. // {
  8553. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  8554. // string str = ex.StackTrace;
  8555. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8556. // }
  8557. // #endregion AGV下料
  8558. // #region 心跳
  8559. // try
  8560. // {
  8561. // short states = 0;
  8562. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  8563. // }
  8564. // catch (Exception ex)
  8565. // {
  8566. // string str = ex.StackTrace;
  8567. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8568. // }
  8569. // #endregion 心跳
  8570. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  8571. // stopwatch1.Stop();
  8572. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  8573. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  8574. // }
  8575. // else
  8576. // {
  8577. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8578. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  8579. // Funs[plcNo].Connect();
  8580. // }
  8581. // }
  8582. // catch (Exception ex)
  8583. // {
  8584. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8585. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  8586. // Funs[plcNo].ReConnect();
  8587. // }
  8588. // Thread.Sleep(IntervalReadPLC);
  8589. // }
  8590. //}
  8591. /// <summary>
  8592. /// [S5] Tray盘下料装备 - 进站校验
  8593. /// </summary>
  8594. /// <param name="plcNo">PLC编号</param>
  8595. /// <param name="stationNameStr">工站全称</param>
  8596. private void S5进站校验(int plcNo, string stationNameStr)
  8597. {
  8598. Stopwatch stopwatch1 = new Stopwatch();
  8599. Stopwatch stopwatch2 = new Stopwatch();
  8600. try
  8601. {
  8602. stopwatch1.Start();
  8603. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  8604. sn = sn.Replace("\0", "");
  8605. // 获取产品SN By 载具码
  8606. #region 查询载具上的产品信息
  8607. string cavityData = string.Empty;
  8608. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  8609. if (string.IsNullOrEmpty(cavityData))
  8610. cavityData = "";
  8611. if (snResult != 0)
  8612. {
  8613. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8614. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  8615. writeToPLC_Flag1.Adress = 2003;
  8616. writeToPLC_Flag1.Value = (short)6;
  8617. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  8618. stopwatch1.Stop();
  8619. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8620. return;
  8621. }
  8622. string[] cavitySNs = cavityData.Split('.');
  8623. string partNo = string.Empty;
  8624. if (cavitySNs != null && cavitySNs.Length >= 1)
  8625. partNo = cavitySNs[0];
  8626. #endregion 查询载具上的产品信息
  8627. // 产品SN(物料码)校验
  8628. List<TestItem> item = new List<TestItem>();
  8629. item.Add(new TestItem()
  8630. {
  8631. Parameter_name = "载具码",
  8632. Parameter_value = sn,
  8633. });
  8634. item.Add(new TestItem()
  8635. {
  8636. Parameter_name = "载具穴号",
  8637. Parameter_value = "1",
  8638. });
  8639. stopwatch2.Start();
  8640. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  8641. stopwatch2.Stop();
  8642. short e1MES_FLAG_Check = (short)result;
  8643. // MES_Flag
  8644. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8645. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8646. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  8647. writeToPLC_Flag.Adress = 2003;
  8648. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  8649. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  8650. }
  8651. catch (Exception ex)
  8652. {
  8653. string str = ex.StackTrace;
  8654. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8655. // MES_Flag
  8656. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8657. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8658. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  8659. writeToPLC_Flag.Adress = 2003;
  8660. writeToPLC_Flag.Value = (short)6;
  8661. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  8662. }
  8663. stopwatch1.Stop();
  8664. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8665. }
  8666. /// <summary>
  8667. /// [S5] Tray盘下料装备 - 出站接口
  8668. /// </summary>
  8669. /// <param name="plcNo"></param>
  8670. /// <param name="stationCode"></param>
  8671. /// <param name="stationName"></param>
  8672. private void S5出站接口(int plcNo, string stationCode, string stationName)
  8673. {
  8674. Stopwatch stopwatch1 = new Stopwatch();
  8675. Stopwatch stopwatch2 = new Stopwatch();
  8676. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8677. string stationNameStr = stationCode + stationName;
  8678. string processItem = stationName; // 测试项目
  8679. try
  8680. {
  8681. stopwatch1.Start();
  8682. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8683. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8684. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8685. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8686. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  8687. sn = sn.Replace("\0", "");
  8688. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  8689. //partNo = partNo.Replace("\0", "");
  8690. #region 查询载具上的产品信息
  8691. string cavityData = string.Empty;
  8692. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  8693. if (string.IsNullOrEmpty(cavityData))
  8694. cavityData = "";
  8695. if (snResult != 0)
  8696. {
  8697. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8698. writeToPLC_Flag1.Name = "e1MES_FLAG";
  8699. writeToPLC_Flag1.Adress = 2035;
  8700. writeToPLC_Flag1.Value = (short)4;
  8701. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  8702. stopwatch1.Stop();
  8703. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8704. return;
  8705. }
  8706. string[] cavitySNs = cavityData.Split('.');
  8707. string partNo = string.Empty;
  8708. if (cavitySNs != null && cavitySNs.Length >= 1)
  8709. partNo = cavitySNs[0];
  8710. #endregion 查询载具上的产品信息
  8711. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  8712. bool pass = e1Result == 1;
  8713. stopwatch2.Start();
  8714. // 上传MES
  8715. List<TestItem> items = new List<TestItem>();
  8716. items.Add(new TestItem()
  8717. {
  8718. Parameter_name = "载具码",
  8719. Parameter_value = sn,
  8720. Parameter_unit = ""
  8721. });
  8722. items.Add(new TestItem()
  8723. {
  8724. Parameter_name = "载具穴号",
  8725. Parameter_value = "1",
  8726. Parameter_unit = ""
  8727. });
  8728. items.Add(new TestItem()
  8729. {
  8730. Parameter_name = "产品结果",
  8731. Parameter_value = e1Result == 1 ? "OK" : "NG",
  8732. Parameter_unit = ""
  8733. });
  8734. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  8735. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  8736. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  8737. short result = result1 == 1 ? (short)1 : (short)3;
  8738. stopwatch2.Stop();
  8739. #region 存储绑定数据到 边线MES系统中
  8740. if (result == 1)
  8741. {
  8742. // 删除绑定信息
  8743. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  8744. if (resultMesR != 0)
  8745. {
  8746. result = 4;
  8747. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  8748. }
  8749. }
  8750. #endregion 存储绑定数据到 边线MES系统中
  8751. // MES_Flag 为MES报错
  8752. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8753. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  8754. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8755. writeToPLC_Flag.Name = "e1MES_FLAG";
  8756. writeToPLC_Flag.Adress = 2035;
  8757. writeToPLC_Flag.Value = result;
  8758. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  8759. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8760. }
  8761. catch (Exception ex)
  8762. {
  8763. stopwatch2.Restart();
  8764. // MES_Flag 为4上位机报错
  8765. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  8766. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8767. writeToPLC_Flag.Name = "e1MES_FLAG";
  8768. writeToPLC_Flag.Adress = 2035;
  8769. writeToPLC_Flag.Value = (short)4;
  8770. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  8771. stopwatch2.Stop();
  8772. string str = ex.StackTrace;
  8773. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8774. }
  8775. stopwatch1.Stop();
  8776. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8777. }
  8778. /// <summary>
  8779. /// [S5] Tray盘下料装备 - 节拍接口
  8780. /// </summary>
  8781. /// <param name="plcNo">PLC编号</param>
  8782. /// <param name="stationNameStr">工站全称</param>
  8783. private void S5节拍接口(int plcNo, string stationNameStr)
  8784. {
  8785. Stopwatch stopwatch1 = new Stopwatch();
  8786. Stopwatch stopwatch2 = new Stopwatch();
  8787. string resultStr = string.Empty;
  8788. try
  8789. {
  8790. stopwatch1.Start();
  8791. string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  8792. string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  8793. e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  8794. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8795. if (!actionBool)
  8796. {
  8797. stopwatch2.Start();
  8798. // MES_Flag
  8799. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8800. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8801. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  8802. writeToPLC_Flag1.Adress = 2088;
  8803. writeToPLC_Flag1.Value = (short)4;
  8804. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  8805. stopwatch2.Stop();
  8806. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8807. return;
  8808. }
  8809. string e1OEEPartNo = string.Empty; // 物料码
  8810. if (string.IsNullOrEmpty(e1OEEProductSN))
  8811. {
  8812. stopwatch2.Start();
  8813. // MES_Flag
  8814. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8815. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8816. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  8817. writeToPLC_Flag1.Adress = 2088;
  8818. writeToPLC_Flag1.Value = (short)1;
  8819. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  8820. stopwatch2.Stop();
  8821. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8822. return;
  8823. }
  8824. else
  8825. { // 查产品SN
  8826. e1OEEPartNo = "Test"; // ZS
  8827. }
  8828. short e1OEEMES_FLAG = 0;
  8829. // 上传OEE
  8830. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  8831. e1OEEMES_FLAG = result.Item1;
  8832. resultStr = result.Item2;
  8833. stopwatch2.Start();
  8834. // MES_Flag
  8835. //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8836. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8837. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  8838. writeToPLC_Flag.Adress = 2088;
  8839. writeToPLC_Flag.Value = e1OEEMES_FLAG;
  8840. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  8841. stopwatch2.Stop();
  8842. }
  8843. catch (Exception ex)
  8844. {
  8845. string str = ex.StackTrace;
  8846. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8847. // MES_Flag
  8848. stopwatch2.Start();
  8849. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  8850. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8851. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  8852. writeToPLC_Flag.Adress = 2088;
  8853. writeToPLC_Flag.Value = (short)4;
  8854. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  8855. stopwatch2.Stop();
  8856. }
  8857. stopwatch1.Stop();
  8858. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8859. }
  8860. /// <summary>
  8861. /// [S5] Tray盘下料装备 - AGV上料叫agv
  8862. /// </summary>
  8863. /// <param name="plcNo">PLC编号</param>
  8864. /// <param name="stationNameStr">工站全称</param>
  8865. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  8866. {
  8867. Stopwatch stopwatch1 = new Stopwatch();
  8868. Stopwatch stopwatch2 = new Stopwatch();
  8869. try
  8870. {
  8871. stopwatch1.Start();
  8872. // ZS 呼叫AGV
  8873. short e1AGVUpCall = 2;
  8874. stopwatch2.Start();
  8875. // e1AGVUpCall
  8876. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  8877. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8878. writeToPLC_Flag.Name = "e1AGVUpCall";
  8879. writeToPLC_Flag.Adress = 2120;
  8880. writeToPLC_Flag.Value = e1AGVUpCall;
  8881. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  8882. stopwatch2.Stop();
  8883. }
  8884. catch (Exception ex)
  8885. {
  8886. string str = ex.StackTrace;
  8887. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8888. // e1AGVUpCall
  8889. stopwatch2.Start();
  8890. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  8891. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8892. writeToPLC_Flag.Name = "e1AGVUpCall";
  8893. writeToPLC_Flag.Adress = 2120;
  8894. writeToPLC_Flag.Value = (short)4;
  8895. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  8896. stopwatch2.Stop();
  8897. }
  8898. stopwatch1.Stop();
  8899. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8900. }
  8901. /// <summary>
  8902. /// [S5] Tray盘下料装备 - AGV上料完成
  8903. /// </summary>
  8904. /// <param name="plcNo">PLC编号</param>
  8905. /// <param name="stationNameStr">工站全称</param>
  8906. private void S5AGV上料完成(int plcNo, string stationNameStr)
  8907. {
  8908. Stopwatch stopwatch1 = new Stopwatch();
  8909. Stopwatch stopwatch2 = new Stopwatch();
  8910. try
  8911. {
  8912. stopwatch1.Start();
  8913. // ZS AGV上料完成,让小车离开
  8914. short e1AGVUpEnd = 2;
  8915. stopwatch2.Start();
  8916. // e1AGVUpEnd
  8917. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  8918. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8919. writeToPLC_Flag.Name = "e1AGVUpEnd";
  8920. writeToPLC_Flag.Adress = 2122;
  8921. writeToPLC_Flag.Value = e1AGVUpEnd;
  8922. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  8923. stopwatch2.Stop();
  8924. }
  8925. catch (Exception ex)
  8926. {
  8927. string str = ex.StackTrace;
  8928. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8929. // e1AGVUpEnd
  8930. stopwatch2.Start();
  8931. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  8932. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8933. writeToPLC_Flag.Name = "e1AGVUpEnd";
  8934. writeToPLC_Flag.Adress = 2122;
  8935. writeToPLC_Flag.Value = (short)4;
  8936. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  8937. stopwatch2.Stop();
  8938. }
  8939. stopwatch1.Stop();
  8940. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8941. }
  8942. /// <summary>
  8943. /// [S5] Tray盘下料装备 - AGV下料叫agv
  8944. /// </summary>
  8945. /// <param name="plcNo">PLC编号</param>
  8946. /// <param name="stationNameStr">工站全称</param>
  8947. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  8948. {
  8949. Stopwatch stopwatch1 = new Stopwatch();
  8950. Stopwatch stopwatch2 = new Stopwatch();
  8951. try
  8952. {
  8953. stopwatch1.Start();
  8954. // ZS 呼叫AGV
  8955. short e1AGVDownCall = 2;
  8956. stopwatch2.Start();
  8957. // e1AGVDownCall
  8958. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  8959. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8960. writeToPLC_Flag.Name = "e1AGVDownCall";
  8961. writeToPLC_Flag.Adress = 2133;
  8962. writeToPLC_Flag.Value = e1AGVDownCall;
  8963. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  8964. stopwatch2.Stop();
  8965. }
  8966. catch (Exception ex)
  8967. {
  8968. string str = ex.StackTrace;
  8969. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8970. // e1AGVDownCall
  8971. stopwatch2.Start();
  8972. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  8973. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8974. writeToPLC_Flag.Name = "e1AGVDownCall";
  8975. writeToPLC_Flag.Adress = 2133;
  8976. writeToPLC_Flag.Value = (short)4;
  8977. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  8978. stopwatch2.Stop();
  8979. }
  8980. stopwatch1.Stop();
  8981. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8982. }
  8983. /// <summary>
  8984. /// [S5] Tray盘下料装备 - AGV下料完成
  8985. /// </summary>
  8986. /// <param name="plcNo">PLC编号</param>
  8987. /// <param name="stationNameStr">工站全称</param>
  8988. private void S5AGV下料完成(int plcNo, string stationNameStr)
  8989. {
  8990. Stopwatch stopwatch1 = new Stopwatch();
  8991. Stopwatch stopwatch2 = new Stopwatch();
  8992. try
  8993. {
  8994. stopwatch1.Start();
  8995. // ZS AGV上料完成,让小车离开
  8996. short e1AGVDownEnd = 2;
  8997. stopwatch2.Start();
  8998. // e1AGVDownEnd
  8999. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9000. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9001. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9002. writeToPLC_Flag.Adress = 2135;
  9003. writeToPLC_Flag.Value = e1AGVDownEnd;
  9004. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9005. stopwatch2.Stop();
  9006. }
  9007. catch (Exception ex)
  9008. {
  9009. string str = ex.StackTrace;
  9010. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9011. // e1AGVDownEnd
  9012. stopwatch2.Start();
  9013. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9014. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9015. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9016. writeToPLC_Flag.Adress = 2135;
  9017. writeToPLC_Flag.Value = (short)4;
  9018. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9019. stopwatch2.Stop();
  9020. }
  9021. stopwatch1.Stop();
  9022. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9023. }
  9024. #endregion [S5] Tray盘下料装备
  9025. #endregion PLC5 张超凡
  9026. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  9027. /// <summary>
  9028. /// PLC读取到的数据 -添加数据
  9029. /// </summary>
  9030. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  9031. {
  9032. if (sxPlcData.ContainsKey(newKey))
  9033. sxPlcData[newKey] = newValue;
  9034. else
  9035. sxPlcData.Add(newKey, newValue);
  9036. }
  9037. /// <summary>
  9038. /// PLC需要写入的数据 -添加数据
  9039. /// </summary>
  9040. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey, WriteToPLC_Flag newValue)
  9041. {
  9042. if (sxPLCWriteData.ContainsKey(newKey))
  9043. sxPLCWriteData[newKey] = newValue;
  9044. else
  9045. sxPLCWriteData.Add(newKey, newValue);
  9046. }
  9047. /// <summary>
  9048. /// PLC回写操作,写后清空flag
  9049. /// </summary>
  9050. /// <param name="modbusClient">modbus对象</param>
  9051. /// <param name="pLCReadDatas">读取到的数据字典</param>
  9052. /// <param name="pLCWriteDatas">需要写入的数据</param>
  9053. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas, ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  9054. {
  9055. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  9056. {
  9057. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  9058. for (int i = 0; i < pLCWriteDatas.Count; i++)
  9059. {
  9060. string mesFlagName = pLCWriteDatas[i].Name;
  9061. int mesFlagAdress = pLCWriteDatas[i].Adress;
  9062. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  9063. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  9064. {
  9065. // 先回写数据
  9066. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  9067. for (int j = 0; j < writeToPLCDatas.Count; j++)
  9068. {
  9069. int mesDataAdress = writeToPLCDatas[j].Adress;
  9070. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  9071. switch (mesDataType)
  9072. {
  9073. case PLCValueType.Short:
  9074. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  9075. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  9076. break;
  9077. case PLCValueType.String:
  9078. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  9079. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  9080. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr, mesDataValueStrLength);
  9081. break;
  9082. }
  9083. }
  9084. // 再回写信号
  9085. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  9086. // 存储读取数据的字典
  9087. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  9088. // 存储写入数据的字典 - 清空写入值
  9089. pLCWriteDatas[i].Value = (short)0;
  9090. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  9091. }
  9092. }
  9093. }
  9094. }
  9095. /// <summary>
  9096. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  9097. /// </summary>
  9098. /// <param name="no">3</param>
  9099. /// <param name="stationCode">设备编号</param>
  9100. /// <param name="stationNameStr">设备名称</param>
  9101. /// <param name="plcOrder">车间订单号</param>
  9102. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  9103. {
  9104. try
  9105. {
  9106. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  9107. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  9108. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  9109. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  9110. int result1 = 0;
  9111. switch (stationCode)
  9112. {
  9113. case 2:
  9114. case 3:
  9115. case 4:
  9116. case 6:
  9117. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  9118. break;
  9119. case 102:
  9120. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  9121. break;
  9122. case 103:
  9123. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  9124. break;
  9125. case 104:
  9126. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  9127. break;
  9128. case 106:
  9129. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  9130. break;
  9131. default:
  9132. // MES_Flag 为“6未找到正确设备编号”
  9133. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  9134. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  9135. return;
  9136. }
  9137. short result = result1 == 1 ? (short)1 : (short)2;
  9138. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  9139. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  9140. }
  9141. catch (Exception ex)
  9142. {
  9143. // MES_Flag 为2上位机报错
  9144. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  9145. string str = ex.StackTrace;
  9146. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9147. }
  9148. }
  9149. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  9150. #region UI刷新
  9151. /// <summary>
  9152. /// 更新商品信息的UI + 下发产品信息(SN)
  9153. /// </summary>
  9154. private void UpdateProductInfo()
  9155. {
  9156. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  9157. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  9158. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  9159. //txt_CurSupplierCode.Text = ""; // 供应商代号
  9160. }
  9161. /// <summary>
  9162. /// 更新PLC连接状态的UI
  9163. /// </summary>
  9164. /// <param name="no">PLC编号</param>
  9165. /// <param name="status">状态</param>
  9166. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  9167. {
  9168. if (this != null && !this.IsDisposed)
  9169. {
  9170. switch (imgNo)
  9171. {
  9172. case 1:
  9173. this.BeginInvoke(new Action(() =>
  9174. {
  9175. picPLC.Image = imageListState.Images[status];
  9176. }));
  9177. break;
  9178. case 2:
  9179. this.BeginInvoke(new Action(() =>
  9180. {
  9181. pictureBox2.Image = imageListState.Images[status];
  9182. }));
  9183. break;
  9184. case 3:
  9185. this.BeginInvoke(new Action(() =>
  9186. {
  9187. pictureBox3.Image = imageListState.Images[status];
  9188. }));
  9189. break;
  9190. case 4:
  9191. this.BeginInvoke(new Action(() =>
  9192. {
  9193. pictureBox4.Image = imageListState.Images[status];
  9194. }));
  9195. break;
  9196. case 5:
  9197. this.BeginInvoke(new Action(() =>
  9198. {
  9199. pictureBox5.Image = imageListState.Images[status];
  9200. }));
  9201. break;
  9202. case 6:
  9203. this.BeginInvoke(new Action(() =>
  9204. {
  9205. pictureBox6.Image = imageListState.Images[status];
  9206. }));
  9207. break;
  9208. case 7:
  9209. this.BeginInvoke(new Action(() =>
  9210. {
  9211. pictureBox7.Image = imageListState.Images[status];
  9212. }));
  9213. break;
  9214. case 8:
  9215. this.BeginInvoke(new Action(() =>
  9216. {
  9217. pictureBox8.Image = imageListState.Images[status];
  9218. }));
  9219. break;
  9220. default:
  9221. break;
  9222. }
  9223. }
  9224. Task.Run(() => // 更新PLC交互页的指示灯
  9225. {
  9226. try
  9227. {
  9228. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9229. {
  9230. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  9231. }
  9232. }
  9233. catch { }
  9234. });
  9235. }
  9236. #endregion UI刷新
  9237. #region 日志
  9238. /// <summary>
  9239. /// 添加各工位运行日志(同步至PLC交互页面)
  9240. /// </summary>
  9241. /// <param name="stationNameStr">工站名称</param>
  9242. /// <param name="logType">日志类型</param>
  9243. /// <param name="message">日志内容</param>
  9244. /// <param name="snNumber">产品数字SN</param>
  9245. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  9246. {
  9247. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")
  9248. && (message.Contains("更新整线运行数据完毕") || message.Contains("更新整线报警数据完毕"))
  9249. ))
  9250. {
  9251. AddMessage(logType, message); // 首页展示+日志记录
  9252. }
  9253. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  9254. {
  9255. StationName = stationNameStr,
  9256. SnNumber = snNumber,
  9257. Message = message,
  9258. CreateTime = DateTime.Now
  9259. };
  9260. // PLC交互页展示
  9261. Task.Run(() =>
  9262. {
  9263. try
  9264. {
  9265. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9266. {
  9267. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  9268. }
  9269. }
  9270. catch { }
  9271. });
  9272. }
  9273. /// <summary>
  9274. /// 添加运行日志
  9275. /// </summary>
  9276. /// <param name="logType">日志类型</param>
  9277. /// <param name="message">日志内容</param>
  9278. public void AddMessage(LogType logType, string message)
  9279. {
  9280. OnMessage(logType, message);
  9281. string date = DateTime.Now.ToString("yyyy/MM/dd");
  9282. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  9283. string msgShow = time + "--> " + message + "\r\n";
  9284. this.BeginInvoke(new Action(() =>
  9285. {
  9286. systemLog.Rows.Insert(0, date, time, message);
  9287. if (systemLog.Rows.Count >= 100)
  9288. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  9289. }));
  9290. }
  9291. /// <summary>
  9292. /// 添加运行日志-保存
  9293. /// </summary>
  9294. /// <param name="logType">日志类型</param>
  9295. /// <param name="message">日志内容</param>
  9296. private void OnMessage(LogType logType, string msg)
  9297. {
  9298. MessageEvent?.Invoke(logType, msg);
  9299. }
  9300. /// <summary>
  9301. /// 保存PLC写入日志
  9302. /// </summary>
  9303. /// <param name="logType"></param>
  9304. /// <param name="logValue"></param>
  9305. private void WritePLCLog(LogType logType, string logValue)
  9306. {
  9307. switch ((int)logType)
  9308. {
  9309. case 0:
  9310. _PLCLogNet.WriteDebug(logValue);
  9311. break;
  9312. case 1:
  9313. _PLCLogNet.WriteInfo(logValue);
  9314. break;
  9315. case 2:
  9316. _PLCLogNet.WriteWarn(logValue);
  9317. break;
  9318. case 3:
  9319. _PLCLogNet.WriteError(logValue);
  9320. break;
  9321. default:
  9322. _PLCLogNet.WriteFatal(logValue);
  9323. break;
  9324. }
  9325. }
  9326. /// <summary>
  9327. /// IOT Mqtt回调方法- With DataId
  9328. /// </summary>
  9329. /// <param name="id"></param>
  9330. /// <param name="v"></param>
  9331. /// <param name="dataId"></param>
  9332. public void CallbackWithDataId(string id, string msg, string dataId)
  9333. {
  9334. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  9335. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  9336. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  9337. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  9338. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  9339. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9340. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  9341. }
  9342. /// <summary>
  9343. /// AGV Mqtt回调方法- 记录Log并处理数据
  9344. /// </summary>
  9345. /// <param name="obj"></param>
  9346. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  9347. {
  9348. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9349. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  9350. // 接收到的信息
  9351. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  9352. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  9353. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  9354. {
  9355. }
  9356. }
  9357. #endregion 日志
  9358. /// <summary>
  9359. /// 实例化报警字典
  9360. /// </summary>
  9361. private void InitalDicAlarm()
  9362. {
  9363. #region 第一个工站(这里未区分工位,所以下面出现的‘工位代码’使用‘线别代码’代替)
  9364. List<Alarm> keyValues1 = new List<Alarm>
  9365. {
  9366. #region 第一组报警(电机)
  9367. new Alarm { 报警类型 = "电机故障", 报警详情 = "料盘搬运_Y轴电机故障" ,关联的PLC地址 = 5100 },
  9368. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_X轴电机故障" ,关联的PLC地址 = 5101 },
  9369. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_Z轴电机故障" ,关联的PLC地址 = 5102 },
  9370. new Alarm { 报警类型 = "电机故障", 报警详情 = "载具搬运_X轴电机故障" ,关联的PLC地址 = 5103 },
  9371. new Alarm { 报警类型 = "电机故障", 报警详情 = "镭射_X轴电机故障" ,关联的PLC地址 = 5104 },
  9372. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_X轴电机故障" ,关联的PLC地址 = 5105 },
  9373. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_Z轴电机故障" ,关联的PLC地址 = 5106 },
  9374. new Alarm { 报警类型 = "电机故障", 报警详情 = "下相机_X轴电机故障" ,关联的PLC地址 = 5107 },
  9375. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_Y轴电机故障" ,关联的PLC地址 = 5108 },
  9376. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_X轴电机故障" ,关联的PLC地址 = 5109 },
  9377. #endregion 第一组报警(电机)
  9378. #region 第二组报警(气缸)
  9379. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料进退气缸故障" ,关联的PLC地址 = 5200 },
  9380. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料升降气缸故障" ,关联的PLC地址 = 5201 },
  9381. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓顶升气缸故障" ,关联的PLC地址 = 5202 },
  9382. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体取料夹爪气缸故障" ,关联的PLC地址 = 5203 },
  9383. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料仓顶升气缸故障" ,关联的PLC地址 = 5204 },
  9384. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料平移气缸故障" ,关联的PLC地址 = 5205 },
  9385. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料升降气缸故障" ,关联的PLC地址 = 5206 },
  9386. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料夹爪气缸故障" ,关联的PLC地址 = 5207 },
  9387. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料旋转气缸故障" ,关联的PLC地址 = 5208 },
  9388. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装平移气缸故障" ,关联的PLC地址 = 5209 },
  9389. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装升降气缸故障" ,关联的PLC地址 = 5210 },
  9390. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装夹爪气缸故障" ,关联的PLC地址 = 5211 },
  9391. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装撑开气缸故障" ,关联的PLC地址 = 5212 },
  9392. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸1故障" ,关联的PLC地址 = 5213 },
  9393. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸2故障" ,关联的PLC地址 = 5214 },
  9394. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具下料移载气缸故障" ,关联的PLC地址 = 5215 },
  9395. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具侧推气缸故障" ,关联的PLC地址 = 5216 },
  9396. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具回流气缸故障" ,关联的PLC地址 = 5217 },
  9397. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2压料气缸故障" ,关联的PLC地址 = 5218 },
  9398. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2电测气缸故障" ,关联的PLC地址 = 5219 },
  9399. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2气密气缸故障" ,关联的PLC地址 = 5220 },
  9400. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3下压气缸故障" ,关联的PLC地址 = 5221 },
  9401. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3上顶气缸故障" ,关联的PLC地址 = 5222 },
  9402. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位5相机升降气缸故障" ,关联的PLC地址 = 5223 },
  9403. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组升降气缸故障" ,关联的PLC地址 = 5224 },
  9404. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸1故障" ,关联的PLC地址 = 5225 },
  9405. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸2故障" ,关联的PLC地址 = 5226 },
  9406. new Alarm { 报警类型 = "气缸故障", 报警详情 = "机械手夹爪气缸故障" ,关联的PLC地址 = 5227 },
  9407. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位4:镭射压料气缸故障" ,关联的PLC地址 = 5228 },
  9408. #endregion 第二组报警(气缸)
  9409. #region 第三组报警(其他故障)
  9410. new Alarm { 报警类型 = "其他故障", 报警详情 = "上料处缺料报警" ,关联的PLC地址 = 5300 },
  9411. new Alarm { 报警类型 = "其他故障", 报警详情 = "震盘缺料报警" ,关联的PLC地址 = 5301 },
  9412. new Alarm { 报警类型 = "其他故障", 报警详情 = "成品仓料满报警" ,关联的PLC地址 = 5302 },
  9413. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照超时报警" ,关联的PLC地址 = 5303 },
  9414. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照NG报警" ,关联的PLC地址 = 5304 },
  9415. new Alarm { 报警类型 = "其他故障", 报警详情 = "玻璃门打开报警" ,关联的PLC地址 = 5305 },
  9416. #endregion 第三组报警(其他故障)
  9417. };
  9418. DicAlarms_Cur.Add(GlobalContext.LineCode, keyValues1); // 这里使用线体代替工位
  9419. #endregion 第一个工站(这里使用线体代替工位)
  9420. # region 第二个工站-原来的写法(废弃)
  9421. //keyValues = new Dictionary<int, AlarmData[]>();
  9422. ////1
  9423. //dicAlarmName = new Dictionary<int, Alarm>();
  9424. //dicAlarmName.Add(0, new Alarm { Name = "M01衬套组模组X电机报警" });
  9425. //dicAlarmName.Add(1, new Alarm { Name = "M02衬套组模组Y电机报警" });
  9426. //dicAlarmName.Add(2, new Alarm { Name = "M03衬套组模组Z电机报警" });
  9427. //dicAlarmName.Add(3, new Alarm { Name = "M04衬套组模组U电机报警" });
  9428. //dicAlarmName.Add(4, new Alarm { Name = "M05外流线皮带电机报警" });
  9429. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9430. //for (int i = 0; i < dicAlarmName.Count; i++)
  9431. //{
  9432. // alarmDatas[i] = new AlarmData();
  9433. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9434. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9435. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9436. // alarmDatas[i].AlarmType = 1;
  9437. //}
  9438. //keyValues.Add(1, alarmDatas);
  9439. ////2
  9440. //dicAlarmName = new Dictionary<int, Alarm>();
  9441. //dicAlarmName.Add(0, new Alarm { Name = "C01定位气缸故障" });
  9442. //dicAlarmName.Add(1, new Alarm { Name = "C02左推料气缸故障" });
  9443. //dicAlarmName.Add(2, new Alarm { Name = "C03右推料气缸故障" });
  9444. //dicAlarmName.Add(3, new Alarm { Name = "C04左压料气缸故障" });
  9445. //dicAlarmName.Add(4, new Alarm { Name = "C05右压料气缸故障" });
  9446. //dicAlarmName.Add(5, new Alarm { Name = "C06切料气缸故障" });
  9447. //dicAlarmName.Add(6, new Alarm { Name = "C07左入料吹气气缸故障" });
  9448. //dicAlarmName.Add(7, new Alarm { Name = "C08右入料吹气气缸故障" });
  9449. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9450. //for (int i = 0; i < dicAlarmName.Count; i++)
  9451. //{
  9452. // alarmDatas[i] = new AlarmData();
  9453. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9454. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9455. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9456. // alarmDatas[i].AlarmType = 2;
  9457. //}
  9458. //keyValues.Add(2, alarmDatas);
  9459. ////3
  9460. //dicAlarmName = new Dictionary<int, Alarm>();
  9461. //dicAlarmName.Add(0, new Alarm { Name = "安全门报警" });
  9462. //dicAlarmName.Add(1, new Alarm { Name = "联机通信故障" });
  9463. //dicAlarmName.Add(2, new Alarm { Name = "连续NG报警" });
  9464. //dicAlarmName.Add(3, new Alarm { Name = "合格率低于设定值报警" });
  9465. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9466. //for (int i = 0; i < dicAlarmName.Count; i++)
  9467. //{
  9468. // alarmDatas[i] = new AlarmData();
  9469. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-3";
  9470. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9471. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9472. // alarmDatas[i].AlarmType = 3;
  9473. //}
  9474. //keyValues.Add(3, alarmDatas);
  9475. //DicAlarms.Add(2, keyValues);
  9476. #endregion 第二个工站-原来的写法(废弃)
  9477. }
  9478. }
  9479. }