Form_Home.cs 672 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using Microsoft.Win32;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using HslCommunication.LogNet;
  13. using MainForm.FaForm;
  14. using Sunny.UI;
  15. using MainForm.ClassFile.XiaomiAPI;
  16. using System.Diagnostics;
  17. using MainForm.Models;
  18. using SqlSugar;
  19. using EasyModbus;
  20. using ModBusClientSimple.Util;
  21. using csharp_networkprotocol_hpsocket;
  22. using MqttnetServerWin;
  23. using Sunny.UI.Win32;
  24. using MainForm.ClassFile.XiaomiAPI_AGV;
  25. using MainForm.ClassFile.XiaomiAPI_RouteCom;
  26. using HslCommunication.Controls;
  27. using EIP_Protocol;
  28. using MainForm.ClassFile.XiaomiAPI_MES;
  29. using NPOI.Util;
  30. using static MainForm.SQLHelper;
  31. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
  32. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
  33. using MainForm.ClassFile.ProjectClass;
  34. using CommonLib;
  35. using Org.BouncyCastle.Asn1.IsisMtt;
  36. using System.Web.Services.Description;
  37. using System.Numerics;
  38. using MathNet.Numerics.RootFinding;
  39. using HslCommunication.Enthernet;
  40. using BZFAStandardLib;
  41. /*
  42. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  43. */
  44. namespace MainForm
  45. {
  46. /// <summary>
  47. /// 记录日志的委托
  48. /// </summary>
  49. /// <param name="logType">日志类型</param>
  50. /// <param name="message">日志信息</param>
  51. public delegate void HomeMessageHandler(LogType logType, string message);
  52. /// <summary>
  53. /// 主页窗体
  54. /// </summary>
  55. public partial class Form_Home : Form
  56. {
  57. #region 常量
  58. //文本常量
  59. private const string Head = "开始采集";
  60. private const string Tail = "采集完成";
  61. private const string Body = "工位出站数据";
  62. private const string BodyCheck = "工位点检数据";
  63. private const string BodyRun = "整线运行数据";
  64. private const string BodyAlarm = "整线报警数据";
  65. #endregion 常量
  66. #region 变量
  67. /// <summary>
  68. /// 委托-记录日志的方法
  69. /// </summary>
  70. public event HomeMessageHandler MessageEvent;
  71. /// <summary>
  72. /// 日志接口
  73. /// </summary>
  74. ILogNet _PLCLogNet;
  75. /// <summary>
  76. /// 用于记录IOT MQTT日志
  77. /// </summary>
  78. ILogNet _IOTMqttLogNet;
  79. /// <summary>
  80. /// 用于记录AGV MQTT日志
  81. /// </summary>
  82. ILogNet _AGVMqttLogNet;
  83. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  84. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  85. // 间隔时间
  86. private int IntervalReadPLC = 300; //ms 读PLC
  87. private int IntervalMonitorMES = 1000; //ms MES心跳
  88. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  89. // 软件状态
  90. private bool IsRun = true;
  91. #region PLC 与 TCP对象
  92. // 定义一个字典,存plc对象(通讯)
  93. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  94. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  95. // 定义TCPClient对象列表
  96. Dictionary<int, HPSocket_TcpClientHelper>
  97. _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  98. // 定义MQTTHelper对象
  99. MQTTHelper _MQTTHelper = new MQTTHelper();
  100. #endregion PLC 与 TCP对象
  101. /// <summary>
  102. /// 上次的设备运行信息
  103. /// </summary>
  104. private string lineWorkingData1_OldStr = string.Empty;
  105. /// <summary>
  106. /// 设备报警字典-当前结果
  107. /// Dictionary<工位代码,List<报警信息>>
  108. /// </summary>
  109. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  110. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  111. /// <summary>
  112. /// 单机用-设备状态
  113. /// </summary>
  114. //XiaomiDeviceState xmDeviceState = XiaomiDeviceState.Uninitialized;
  115. XiaomiDeviceStateData xmDeviceStateData = new XiaomiDeviceStateData();
  116. #endregion 变量
  117. #region 窗体基础事件
  118. /// <summary>
  119. /// 初始化
  120. /// </summary>
  121. public Form_Home()
  122. {
  123. InitializeComponent();
  124. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  125. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  126. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  127. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  128. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  129. }
  130. /// <summary>
  131. /// 窗体加载事件
  132. /// </summary>
  133. private void Form_Home_Load(object sender, EventArgs e)
  134. {
  135. try
  136. {
  137. AddMessage(LogType.Info, "开始初始化程序");
  138. InitalDicAlarm(); // 实例化报警字典
  139. //组建plc对象字典
  140. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  141. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  142. if (GlobalContext.IsUsePLC1)
  143. FunsEip.Add(1,
  144. new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  145. if (GlobalContext.IsUsePLC2)
  146. //Funs.Add(2, new ModbusClientHelper(GlobalContext.Machine2Address, GlobalContext.MachinePort, 2001)); // FCT(板测),
  147. FunsEip.Add(2,
  148. new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  149. if (GlobalContext.IsUsePLC3)
  150. FunsEip.Add(3,
  151. new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  152. if (GlobalContext.IsUsePLC4)
  153. FunsEip.Add(4,
  154. new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  155. if (GlobalContext.IsUsePLC5)
  156. FunsEip.Add(5,
  157. new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  158. if (GlobalContext.IsUsePLC6)
  159. FunsEip.Add(6,
  160. new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  161. if (GlobalContext.IsUsePLC7)
  162. FunsEip.Add(7,
  163. new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  164. if (GlobalContext.IsUsePLC8)
  165. FunsEip.Add(8,
  166. new Inovance_EIP(GlobalContext.PC8Address,
  167. GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  168. if (GlobalContext.IsUsePLC9)
  169. FunsEip.Add(9,
  170. new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  171. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  172. {
  173. if (plcEIP != null)
  174. {
  175. try
  176. {
  177. (int, string) result = plcEIP.Connect();
  178. }
  179. catch (Exception ex)
  180. {
  181. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  182. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
  183. MessageBoxOptions.ServiceNotification);
  184. }
  185. }
  186. }
  187. /*
  188. //plc1Alarm.Connect();
  189. foreach (ModbusClientHelper modbusClient in Funs.Values)
  190. {
  191. if (modbusClient != null)
  192. {
  193. try
  194. {
  195. modbusClient.Connect();
  196. }
  197. catch (Exception ex)
  198. {
  199. MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
  200. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  201. }
  202. }
  203. }
  204. */
  205. // 采集任务
  206. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  207. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  208. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  209. if (GlobalContext.IsUsePLC1)
  210. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  211. if (GlobalContext.IsUsePLC2)
  212. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  213. if (GlobalContext.IsUsePLC3)
  214. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  215. if (GlobalContext.IsUsePLC4)
  216. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  217. if (GlobalContext.IsUsePLC5)
  218. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  219. if (GlobalContext.IsUsePLC6)
  220. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  221. if (GlobalContext.IsUsePLC7)
  222. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  223. if (GlobalContext.IsUsePLC8)
  224. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  225. if (GlobalContext.IsUsePLC9)
  226. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  227. #region 初始化
  228. try
  229. {
  230. // 开启边线MES(绑定/查询数据)
  231. //int mesRoute = XiaomiMES_RouteCommunication.Init();
  232. //if (mesRoute == 0)
  233. //{
  234. // //picMESStatus.Image = imageListState.Images[1];
  235. // //GlobalContext.MESIsConnect = true;
  236. // AddMessage(LogType.Info, "小米MES边线初始连接成功!");
  237. //}
  238. //else
  239. //{
  240. // //picMESStatus.Image = imageListState.Images[0];
  241. // //GlobalContext.MESIsConnect = false;
  242. // AddMessage(LogType.Info, $"小米MES边线初始连接失败!");
  243. //}
  244. // 开启MES(Http)
  245. if (GlobalContext.IsUseMES)
  246. {
  247. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  248. if (mesret)
  249. {
  250. picMESStatus.Image = imageListState.Images[1];
  251. GlobalContext.MESIsConnect = true;
  252. AddMessage(LogType.Info, "小米MES初始连接成功!");
  253. }
  254. else
  255. {
  256. picMESStatus.Image = imageListState.Images[0];
  257. GlobalContext.MESIsConnect = false;
  258. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  259. }
  260. }
  261. // 开启IOT(MQTT)
  262. if (GlobalContext.IsUseIot)
  263. {
  264. string addr = GlobalContext.MQTTServerHost;
  265. int port = GlobalContext.MQTTServerPort;
  266. //生产环境需要修改
  267. int qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666,
  268. GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  269. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult;
  270. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  271. {
  272. picIot.Image = imageListState.Images[1];
  273. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  274. // 设置回调函数
  275. //XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  276. // 配置参数
  277. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  278. // fds
  279. param.parameter.fds.address = "http://file-cm.be.mi.com/file/x5/file/upload/mqtt";
  280. param.parameter.fds.appId = "Auto-Soft";
  281. param.parameter.fds.appKey = "d11ec2b9-0e7a-4086-a80c-a1ec716e0896";
  282. // mes
  283. param.parameter.mes.address = GlobalContext.ServerIp;
  284. param.parameter.mes.appId = GlobalContext.MESAppId;
  285. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  286. // mqtt
  287. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  288. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  289. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  290. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  291. // 设备配置
  292. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  293. if (GlobalContext.IsUsePLC1)
  294. {
  295. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  296. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  297. }
  298. if (GlobalContext.IsUsePLC2)
  299. {
  300. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  301. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  302. }
  303. if (GlobalContext.IsUsePLC3)
  304. {
  305. param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
  306. //param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
  307. }
  308. if (GlobalContext.IsUsePLC4)
  309. {
  310. param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
  311. param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
  312. }
  313. if (GlobalContext.IsUsePLC5)
  314. {
  315. param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
  316. param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
  317. }
  318. if (GlobalContext.IsUsePLC6)
  319. {
  320. param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
  321. param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
  322. }
  323. if (GlobalContext.IsUsePLC7)
  324. {
  325. param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  326. //param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  327. }
  328. if (GlobalContext.IsUsePLC8)
  329. {
  330. param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
  331. param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
  332. }
  333. if (GlobalContext.IsUsePLC9)
  334. {
  335. param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
  336. param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
  337. }
  338. param.parameter.equipment.project = GlobalContext.Project_Code;
  339. param.parameter.equipment.productMode = "debug";
  340. //
  341. param.parameter.other.logLevel = 0;
  342. param.parameter.other.LogPath = GlobalContext.WorkLogDir;
  343. XiaomiMqttClient_Extend.ParameterConfig(param);
  344. }
  345. else
  346. {
  347. picIot.Image = imageListState.Images[0];
  348. AddMessage(LogType.Info,
  349. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  350. }
  351. }
  352. // 开启AGV(Http与MQTT)
  353. if (GlobalContext.IsUseAGV)
  354. {
  355. // AGV HTTP
  356. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  357. if (mesret1)
  358. {
  359. picAgvHttp.Image = imageListState.Images[1];
  360. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  361. }
  362. else
  363. {
  364. picAgvHttp.Image = imageListState.Images[0];
  365. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  366. }
  367. string agvMqttIp = GlobalContext.MQTTServerHost;
  368. int agvMqttPort = GlobalContext.MQTTServerPort;
  369. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  370. ResultData_MQTT result_MQTT = _MQTTHelper
  371. .CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  372. // AGV MQTT
  373. if (result_MQTT.ResultCode == 1)
  374. {
  375. picAgvMqtt.Image = imageListState.Images[1];
  376. GlobalContext.AGVMQTTIsConnect = true;
  377. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  378. ResultData_MQTT result =
  379. XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  380. AddMessage(LogType.Info,
  381. $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  382. }
  383. else
  384. {
  385. picAgvMqtt.Image = imageListState.Images[0];
  386. GlobalContext.AGVMQTTIsConnect = false;
  387. AddMessage(LogType.Info,
  388. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  389. }
  390. }
  391. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  392. Task.Run(MonitorMESConnect);
  393. // 查询PLC连接状态
  394. foreach (int plcNo in FunsEip.Keys)
  395. {
  396. bool connected = FunsEip[plcNo].IsConnected;
  397. if (connected)
  398. {
  399. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  400. AddMessage(LogType.Info, msg);
  401. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  402. }
  403. else
  404. {
  405. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  406. AddMessage(LogType.Info, msg);
  407. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  408. }
  409. }
  410. // PLC4时 初始化扫码器TCP
  411. //if (GlobalContext.IsUsePLC4)
  412. // HpTCPClientInit();
  413. // 开启PLC的业务处理线程-监听PLC点位+状态
  414. foreach (Task task in TaskReadProcess)
  415. {
  416. if (task != null)
  417. task.Start();
  418. }
  419. //// 开启iot的线程
  420. TaskReadAlarm.Start();
  421. ////下传MES信息给1工位(先判断下plc对象数量)
  422. //if (Funs.Count > 1)
  423. // DownLoadProductInfo(1);
  424. if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  425. {
  426. uiLabel1.Text = "设备状态(左):";
  427. uiLabel2.Text = "设备状态(右):";
  428. uiLabel3.Visible = true;
  429. uiLabel2.Visible = true;
  430. }
  431. AddMessage(LogType.Info, "程序初始化完成");
  432. }
  433. catch (Exception ex)
  434. {
  435. string str = ex.StackTrace;
  436. this.BeginInvoke(new Action(() =>
  437. {
  438. AddMessage(LogType.Error,
  439. "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  440. str.Length - str.LastIndexOf("\\") - 1));
  441. }));
  442. }
  443. #endregion
  444. }
  445. catch (Exception ex)
  446. {
  447. string str = ex.StackTrace;
  448. OnMessage(LogType.Info,
  449. "主窗体的首页初始化出错!异常位置:" +
  450. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" +
  451. ex.Message.ToString());
  452. if (ex.Message != null && ex.Message.Contains("timed out"))
  453. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  454. else
  455. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  456. }
  457. }
  458. /// <summary>
  459. /// 窗体关闭事件
  460. /// </summary>
  461. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  462. {
  463. Closed2();
  464. }
  465. public void Closed2()
  466. {
  467. try
  468. {
  469. IsRun = false;
  470. Thread.Sleep(IntervalReadPLC);
  471. // 断开TCP
  472. int count = _HPSocket_TcpClients.Count();
  473. for (int i = 0; i < count; i++)
  474. {
  475. try
  476. {
  477. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  478. {
  479. _HPSocket_TcpClients[i].Stop();
  480. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  481. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  482. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  483. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  484. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  485. }
  486. }
  487. catch
  488. {
  489. }
  490. }
  491. // 关闭Iot
  492. try
  493. {
  494. XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath,
  495. GlobalContext.MqttServerName);
  496. }
  497. catch
  498. {
  499. }
  500. // 关闭AGV Mqtt
  501. try
  502. {
  503. _MQTTHelper.DisconnectAsync_Client().Wait();
  504. }
  505. catch
  506. {
  507. }
  508. }
  509. catch
  510. {
  511. }
  512. }
  513. #endregion 窗体基础事件
  514. #region 监控MES状态
  515. /// <summary>
  516. /// 监控MES连接状态
  517. /// </summary>
  518. private void MonitorMESConnect()
  519. {
  520. while (IsRun) // 运行被控线程
  521. {
  522. try
  523. {
  524. // 开启MES(Http)
  525. if (GlobalContext.IsUseMES)
  526. {
  527. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  528. if (mesret)
  529. {
  530. picMESStatus.Image = imageListState.Images[1];
  531. GlobalContext.MESIsConnect = true;
  532. }
  533. else
  534. {
  535. picMESStatus.Image = imageListState.Images[0];
  536. GlobalContext.MESIsConnect = false;
  537. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  538. }
  539. }
  540. // 开启IOT(MQTT)
  541. if (GlobalContext.IsUseIot)
  542. {
  543. bool iIot = XiaomiMqttClient.IsOpen;
  544. if (iIot)
  545. picIot.Image = imageListState.Images[1];
  546. else
  547. {
  548. picIot.Image = imageListState.Images[0];
  549. OnMessage(LogType.Info,
  550. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  551. }
  552. }
  553. // 开启AGV(Http与MQTT)
  554. if (GlobalContext.IsUseAGV)
  555. {
  556. // AGV Http
  557. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  558. if (mesret1)
  559. picAgvHttp.Image = imageListState.Images[1];
  560. else
  561. {
  562. picAgvHttp.Image = imageListState.Images[0];
  563. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  564. }
  565. // AGV MQTT
  566. if (GlobalContext.AGVMQTTIsConnect)
  567. picAgvMqtt.Image = imageListState.Images[1];
  568. else
  569. {
  570. picAgvMqtt.Image = imageListState.Images[0];
  571. OnMessage(LogType.Info,
  572. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  573. }
  574. }
  575. }
  576. catch (Exception ex)
  577. {
  578. string str = ex.StackTrace;
  579. AddMessage(LogType.Error,
  580. "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  581. str.Length - str.LastIndexOf("\\") - 1));
  582. }
  583. Thread.Sleep(IntervalMonitorMES);
  584. }
  585. }
  586. #endregion 监控MES连接状态
  587. #region 采集设备状态、运行数据、报警数据
  588. /// <summary>
  589. /// 请求设备状态 5000
  590. /// </summary>
  591. /// <param name="no">1</param>
  592. /// <param name="stationNameStr"></param>
  593. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  594. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  595. {
  596. try
  597. {
  598. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  599. {
  600. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  601. return result;
  602. }
  603. else
  604. {
  605. return 0;
  606. }
  607. }
  608. catch (Exception ex)
  609. {
  610. string str = ex.StackTrace;
  611. AddMessage_Station(stationNameStr, LogType.Error,
  612. "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  613. str.Length - str.LastIndexOf("\\") - 1));
  614. return 0;
  615. }
  616. }
  617. /// <summary>
  618. /// 检查是否可采集点检数据 - 不取新值
  619. /// 5000不为1时可点检
  620. /// </summary>
  621. /// <returns></returns>
  622. public bool CheckCanSpotcheck1(int deviceState)
  623. {
  624. //return true;
  625. //D5000 = 1,代表设备控制状态处于运行状态
  626. //D5000 = 2, 代表设备控制状态处于故障状态
  627. //D5000 = 3,代表设备控制状态处于缺料状态
  628. //D5000 = 4, 代表设备控制状态处于待机状态
  629. //D5000 = 5,代表设备控制状态处于维修状态
  630. return deviceState != 1;
  631. }
  632. /// <summary>
  633. /// 检查是否可采集产品数据 - 不取新值
  634. /// </summary>
  635. /// <returns></returns>
  636. public bool CheckCanCollData(int deviceState)
  637. {
  638. return deviceState == 0; // 点检时该值不为0
  639. }
  640. /// <summary>
  641. /// 采集到的设备状态
  642. /// </summary>
  643. private string _DeviceStates = "未知状态";
  644. private string _DeviceStates_Old = "未知状态";
  645. private string _DeviceStates2 = "未知状态";
  646. private string _DeviceStates_Old2 = "未知状态";
  647. /// <summary>
  648. /// 获取设备报警数据与获取设备运行信息
  649. /// </summary>
  650. private async void ReadAlarmAllPLC()
  651. {
  652. // [S1] Tray盘上料装备(板测)
  653. // [S2] FCT(板测)
  654. // [S3] 值板机
  655. // [S4] 取放桁架
  656. // [S5] Tray盘下料装备
  657. /// 上位机心跳
  658. /// 获取设备报警数据与状态信息
  659. string stationNameStr = "获取设备报警数据与状态信息";
  660. // 已连接到PLC
  661. while (IsRun)
  662. {
  663. try
  664. {
  665. //if (!GlobalContext._IsCon_plc1Alarm)
  666. //{
  667. // UpdatePLCMonitor(1, -2, 0);
  668. // continue;
  669. //}
  670. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  671. {
  672. if (plcEIP != null)
  673. {
  674. if (plcEIP.IsConnected)
  675. {
  676. #region 主页展示设备运行状态并上传到IOT中,有双工位left就是左工位,没有双工位left就是单工位
  677. switch (xmDeviceStateData.left)
  678. {
  679. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  680. _DeviceStates = "未初始化状态";
  681. lblDeviceStates.Text = _DeviceStates;
  682. break;
  683. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  684. _DeviceStates = "初始化状态";
  685. lblDeviceStates.Text = _DeviceStates;
  686. break;
  687. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  688. _DeviceStates = "初始化完成状态";
  689. lblDeviceStates.Text = _DeviceStates;
  690. break;
  691. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  692. _DeviceStates = "运行状态";
  693. lblDeviceStates.Text = _DeviceStates;
  694. break;
  695. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  696. _DeviceStates = "暂停状态";
  697. lblDeviceStates.Text = _DeviceStates;
  698. break;
  699. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  700. _DeviceStates = "故障状态";
  701. lblDeviceStates.Text = _DeviceStates;
  702. break;
  703. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  704. _DeviceStates = "警报状态";
  705. lblDeviceStates.Text = _DeviceStates;
  706. break;
  707. }
  708. if (!_DeviceStates.Equals(_DeviceStates_Old))
  709. {
  710. var iotResult =
  711. SaveDeviceStateData(stationNameStr, xmDeviceStateData.left, "left"); // 上传+保存
  712. if (iotResult.Item1 == 1)
  713. {
  714. _DeviceStates_Old = _DeviceStates;
  715. AddMessage_Station(stationNameStr, LogType.Info,
  716. stationNameStr + $"_上传设备状态到Iot成功!");
  717. }
  718. else
  719. AddMessage_Station(stationNameStr, LogType.Info,
  720. stationNameStr +
  721. $"_上传设备状态到Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  722. }
  723. #endregion 主页展示设备运行状态并上传到IOT中
  724. #region 右工位
  725. if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  726. {
  727. switch (xmDeviceStateData.right)
  728. {
  729. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  730. _DeviceStates2 = "未初始化状态";
  731. lblDeviceStates.Text = _DeviceStates2;
  732. break;
  733. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  734. _DeviceStates2 = "初始化状态";
  735. lblDeviceStates.Text = _DeviceStates2;
  736. break;
  737. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  738. _DeviceStates2 = "初始化完成状态";
  739. lblDeviceStates.Text = _DeviceStates2;
  740. break;
  741. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  742. _DeviceStates2 = "运行状态";
  743. lblDeviceStates.Text = _DeviceStates2;
  744. break;
  745. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  746. _DeviceStates2 = "暂停状态";
  747. lblDeviceStates.Text = _DeviceStates2;
  748. break;
  749. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  750. _DeviceStates2 = "故障状态";
  751. lblDeviceStates.Text = _DeviceStates2;
  752. break;
  753. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  754. _DeviceStates2 = "警报状态";
  755. lblDeviceStates.Text = _DeviceStates2;
  756. break;
  757. }
  758. if (!_DeviceStates2.Equals(_DeviceStates_Old2))
  759. {
  760. var iotResult = SaveDeviceStateData(stationNameStr, xmDeviceStateData.left,
  761. "right"); // 上传+保存
  762. if (iotResult.Item1 == 1)
  763. {
  764. _DeviceStates_Old2 = _DeviceStates2;
  765. AddMessage_Station(stationNameStr, LogType.Info,
  766. stationNameStr + $"_上传设备状态到Iot成功!");
  767. }
  768. else
  769. AddMessage_Station(stationNameStr, LogType.Info,
  770. stationNameStr +
  771. $"_上传设备状态到Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  772. }
  773. }
  774. #endregion 右工位
  775. }
  776. }
  777. }
  778. //if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  779. //{
  780. // DateTime dtNow = DateTime.Now;
  781. // //#region 获取设备运行信息
  782. // //try
  783. // //{
  784. // // LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  785. // // lineWorkingData1.GUID = Guid.NewGuid().ToString();
  786. // // lineWorkingData1.LineName = GlobalContext.LineCode;
  787. // // //
  788. // // lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  789. // // lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  790. // // lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  791. // // lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  792. // // lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  793. // // lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  794. // // lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  795. // // lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  796. // // lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  797. // // lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  798. // // lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  799. // // lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  800. // // lineWorkingData1.CreateTime = DateTime.Now;
  801. // // string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  802. // // // UI展示-展示到设备状态页
  803. // // if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  804. // // {
  805. // // // 查询数据库最新一条数据,确定是不是更新
  806. // // string qSql = @"SELECT top(1) [GUID]
  807. // // ,[LineName]
  808. // // ,[BootTimeLong]
  809. // // ,[NormalTimeLong]
  810. // // ,[StandbyTimeLong]
  811. // // ,[FaultTimeLong]
  812. // // ,[MaterialShortageTimeLong]
  813. // // ,[MaintenanceTimeLong]
  814. // // ,[FaultNumber]
  815. // // ,[OutputNumber]
  816. // // ,[QualifiedNumber]
  817. // // ,[QualifiedRate]
  818. // // ,[DesignRhythm]
  819. // // ,[RealityRhythm]
  820. // // ,[CreateTime]
  821. // // FROM [LineWorkingData]
  822. // // where [CreateTime] > '{0}'
  823. // // and [LineName]='{1}'
  824. // // order by [CreateTime] desc
  825. // // ";
  826. // // qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  827. // // var ds = SQLHelper_New.Query(qSql, null);
  828. // // if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  829. // // {
  830. // // var dataDBlast = new LineWorkingData_ThisTime();
  831. // // dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  832. // // dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  833. // // dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  834. // // dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  835. // // if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  836. // // {
  837. // // dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  838. // // dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  839. // // dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  840. // // dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  841. // // dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  842. // // dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  843. // // dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  844. // // dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  845. // // dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  846. // // dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  847. // // dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  848. // // dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  849. // // string usql = dataDBlast.ToStringUpdate();
  850. // // SQLHelper_New.ExecuteSQL(usql, null);
  851. // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  852. // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  853. // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  854. // // }
  855. // // }
  856. // // else
  857. // // {
  858. // // // 插入
  859. // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  860. // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  861. // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  862. // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  863. // // }
  864. // // }
  865. // // else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  866. // // {
  867. // // LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  868. // // //// 本次开机设备运行情况
  869. // // //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  870. // // //Task.Run(() =>
  871. // // //{
  872. // // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  873. // // // {
  874. // // // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  875. // // // }
  876. // // //});
  877. // // // 本日设备运行情况
  878. // // // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  879. // // if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  880. // // {
  881. // // // 更新
  882. // // lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  883. // // lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  884. // // lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  885. // // lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  886. // // lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  887. // // lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  888. // // lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  889. // // lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  890. // // lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  891. // // lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  892. // // lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  893. // // lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  894. // // SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  895. // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  896. // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  897. // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  898. // // }
  899. // // else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  900. // // {
  901. // // // 插入
  902. // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  903. // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  904. // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  905. // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  906. // // }
  907. // // await Task.Run(() =>
  908. // // {
  909. // // try
  910. // // {
  911. // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  912. // // {
  913. // // Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  914. // // }
  915. // // }
  916. // // catch { }
  917. // // });
  918. // // }
  919. // //}
  920. // //catch (Exception ex)
  921. // //{
  922. // // string str = ex.StackTrace;
  923. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  924. // //}
  925. // //#endregion 获取设备运行信息
  926. // #region 报警数据
  927. // try
  928. // {
  929. // List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  930. // bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  931. // // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  932. // var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  933. // for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  934. // {
  935. // short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  936. // dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  937. // if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  938. // {
  939. // isNeedUpdUI = true; // 需要更新历史报警UI信息
  940. // // 记录
  941. // dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  942. // switch (dicAlarms_Cur_PLC1[i].是否报警)
  943. // {
  944. // case true: // 报警
  945. // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  946. // {
  947. // GUID = Guid.NewGuid().ToString(),
  948. // LineName = GlobalContext.LineCode, // 线体
  949. // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  950. // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  951. // StartTime = dtNow // 开始时间
  952. // };
  953. // // 传输到页面
  954. // deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  955. // {
  956. // 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  957. // 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  958. // 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  959. // 开始时间 = dtNow
  960. // });
  961. // // 新增到数据库
  962. // var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  963. // SaveAlarmDataByDB(stationNameStr, data1, false);
  964. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  965. // break;
  966. // case false: // 消除报警
  967. // if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  968. // {
  969. // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  970. // {
  971. // GUID = Guid.NewGuid().ToString(),
  972. // LineName = GlobalContext.LineCode, // 线体
  973. // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  974. // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  975. // StartTime = dtNow, // 开始时间
  976. // EndTime = dtNow, // 开始时间
  977. // PersistTime = 1, // 耗时1s
  978. // };
  979. // // 新增
  980. // var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  981. // SaveAlarmDataByDB(stationNameStr, data2, false);
  982. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  983. // }
  984. // else
  985. // {
  986. // dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  987. // dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  988. // - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  989. // // 修改
  990. // var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  991. // SaveAlarmDataByDB(stationNameStr, data3, true);
  992. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  993. // }
  994. // break;
  995. // default:
  996. // break;
  997. // }
  998. // }
  999. // }
  1000. // DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  1001. // // 有新报警则更新
  1002. // if (isNeedUpdUI)
  1003. // {
  1004. // // UI展示 - 展示到设备状态页
  1005. // await Task.Run(() =>
  1006. // {
  1007. // try
  1008. // {
  1009. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  1010. // {
  1011. // Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  1012. // if (Form_Main.formDevAlarm.Visible)
  1013. // {
  1014. // Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  1015. // }
  1016. // }
  1017. // }
  1018. // catch { }
  1019. // });
  1020. // }
  1021. // }
  1022. // catch (Exception ex)
  1023. // {
  1024. // string str = ex.StackTrace;
  1025. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1026. // }
  1027. // #endregion 报警数据
  1028. // UpdatePLCMonitor(1, -2, 1);
  1029. //}
  1030. //else
  1031. //{
  1032. // UpdatePLCMonitor(1, -2, 0);
  1033. //}
  1034. }
  1035. catch (Exception ex)
  1036. {
  1037. //AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1038. AddMessage_Station(stationNameStr, LogType.Error,
  1039. $"PLC1_{stationNameStr}_采集运行数据与报警数据出错!错误信息:" + ex.Message.ToString());
  1040. }
  1041. Thread.Sleep(IntervalAlarm);
  1042. }
  1043. }
  1044. #endregion 轮询PLC
  1045. #region 下发订单信息
  1046. ///// <summary>
  1047. ///// 壳体上料(下发工单)的交互逻辑
  1048. ///// </summary>
  1049. ///// <param name="no"></param>
  1050. ///// <exception cref="NotImplementedException"></exception>
  1051. //private void ReadStation_DownOrderInfo(int plcNo)
  1052. //{
  1053. // // [S1] Tray盘上料装备(板测)
  1054. // // [S2] FCT(板测)
  1055. // // [S3] 值板机
  1056. // // [S4] 取放桁架
  1057. // // [S5] Tray盘下料装备
  1058. // /// 上位机心跳
  1059. // /// 获取设备报警数据与状态信息
  1060. // string stationNameStr = "[S0]壳体上料";
  1061. // while (IsRun)
  1062. // {
  1063. // try
  1064. // {
  1065. // if (!GlobalContext._IsCon_Funs1)
  1066. // {
  1067. // UpdatePLCMonitor(plcNo, 0);
  1068. // continue;
  1069. // }
  1070. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  1071. // {
  1072. // #region 壳体上料(下发工单)
  1073. // try
  1074. // {
  1075. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  1076. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  1077. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  1078. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  1079. // // 重置数据和信号
  1080. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  1081. // {
  1082. // // 清空写给PLC的数据
  1083. // int[] i497 = new int[1] { 0 };
  1084. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  1085. // // MES_Flag重置为0
  1086. // int[] i500 = new int[1] { 0 };
  1087. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  1088. // }
  1089. // }
  1090. // catch (Exception ex)
  1091. // {
  1092. // string str = ex.StackTrace;
  1093. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1094. // }
  1095. // #endregion 壳体上料(下发工单)
  1096. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1097. // }
  1098. // else
  1099. // {
  1100. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  1101. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1102. //
  1103. // Funs[plcNo].Connect();
  1104. // }
  1105. // }
  1106. // catch (Exception ex)
  1107. // {
  1108. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  1109. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1110. //
  1111. // Funs[plcNo].ReConnect();
  1112. // }
  1113. // Thread.Sleep(IntervalReadPLC);
  1114. // }
  1115. //}
  1116. ///// <summary>
  1117. ///// 下发订单信息到PLC
  1118. ///// </summary>
  1119. ///// <param name="no">PLC编号</param>
  1120. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  1121. //{
  1122. // try
  1123. // {
  1124. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  1125. // {
  1126. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  1127. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  1128. // }
  1129. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  1130. // }
  1131. // catch (Exception ex)
  1132. // {
  1133. // string str = ex.StackTrace;
  1134. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1135. // }
  1136. //}
  1137. /// <summary>
  1138. /// 下发清料信号
  1139. /// </summary>
  1140. /// <param name="no">PLC编号</param>
  1141. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  1142. {
  1143. try
  1144. {
  1145. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  1146. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  1147. return true;
  1148. }
  1149. catch (Exception ex)
  1150. {
  1151. string str = ex.StackTrace;
  1152. AddMessage_Station(stationNameStr, LogType.Error,
  1153. "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  1154. str.Length - str.LastIndexOf("\\") - 1));
  1155. return false;
  1156. }
  1157. }
  1158. #endregion 下发订单信息
  1159. #region Xiaomi 贲流
  1160. #region 公共方法
  1161. private static bool ProgressState = false;
  1162. private static readonly object lockObj = new object(); // 锁对象
  1163. private static bool isCollectingFlagLeft;
  1164. private static bool isCollectingFlagRight;
  1165. /// <summary>
  1166. /// float[]转为string
  1167. /// </summary>
  1168. public string FloatArrayToString(float[] nScrewResults)
  1169. {
  1170. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  1171. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  1172. }
  1173. /// <summary>
  1174. /// short[]转为string
  1175. /// </summary>
  1176. public string ShortArrayToString(short[] nScrewResults)
  1177. {
  1178. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  1179. return string.Join(",", nScrewResults);
  1180. }
  1181. /// <summary>
  1182. /// 写入PLC重复三次
  1183. /// </summary>
  1184. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount,
  1185. T inObj)
  1186. {
  1187. int i = 0;
  1188. int nRet = 0;
  1189. string strRet = "";
  1190. try
  1191. {
  1192. while (i < 3) // 最多上传三次
  1193. {
  1194. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  1195. if (nRet == 0) //成功
  1196. {
  1197. break;
  1198. }
  1199. else
  1200. {
  1201. AddMessage_Station(stationNameStr, LogType.Error,
  1202. $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1203. i++;
  1204. }
  1205. }
  1206. return (nRet, strRet);
  1207. }
  1208. catch (Exception ex)
  1209. {
  1210. return (1, ex.Message);
  1211. }
  1212. }
  1213. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes,
  1214. short[] nScrewOrders, short[] nScrewResults)
  1215. {
  1216. try
  1217. {
  1218. // 获取当前日期
  1219. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1220. // 构建保存路径
  1221. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  1222. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction, "螺丝Mes数据");
  1223. // 确保目录存在
  1224. Directory.CreateDirectory(savePath);
  1225. // 文件名
  1226. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  1227. string filePath = Path.Combine(savePath, fileName);
  1228. // 确保不会超出数组长度,只取前14个或数组的实际长度
  1229. int count = Math.Min(14, fScrewTimes.Length);
  1230. using (StreamWriter sw = new StreamWriter(filePath))
  1231. {
  1232. for (int i = 0; i < count; i++)
  1233. {
  1234. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  1235. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  1236. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  1237. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  1238. sw.WriteLine(); // 空行分隔不同螺丝的信息
  1239. }
  1240. }
  1241. return (0, "");
  1242. }
  1243. catch (Exception ex)
  1244. {
  1245. return (1, ex.Message);
  1246. }
  1247. }
  1248. public Dictionary<string, string> GetLastLineCompensation(string path, string direction, string sn)
  1249. {
  1250. // 创建字典存储补偿点及其对应的值
  1251. Dictionary<string, string> compensationDict = new Dictionary<string, string>();
  1252. try
  1253. {
  1254. //string path = GlobalContext.MESLaserRPath;
  1255. // 获取当前日期并格式化为 "yyyy-MM-dd" 格式
  1256. string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
  1257. string filename = $"Laser-{currentDate}-W0.txt";
  1258. // 拼接完整路径
  1259. string fullPath = Path.Combine(path, filename);
  1260. string lastNonEmptyLine = "";
  1261. // 判断文件是否存在
  1262. if (File.Exists(fullPath))
  1263. {
  1264. //读取文件内容
  1265. string[] lines = File.ReadAllLines(fullPath);
  1266. // 获取最后一行数据(忽略标题行)
  1267. if (lines.Length > 1)
  1268. {
  1269. string lastLine = "";
  1270. for (int i = lines.Length - 1; i > 0; i--)
  1271. {
  1272. if (!string.IsNullOrEmpty(lines[i]))
  1273. {
  1274. lastLine = lines[i];
  1275. break;
  1276. }
  1277. }
  1278. // 将最后一行按逗号分隔
  1279. string[] values = lastLine.Split(',');
  1280. values[1] = sn;
  1281. string key = "三点激光_" + direction; // 构造键名
  1282. string value = string.Join(",", values); // 获取值并去除多余空格
  1283. compensationDict[key] = value;
  1284. //// 提取“1点补偿”到“6点补偿”的值
  1285. //for (int i = 2; i <= 7 && i < values.Length; i++) // 从索引2开始,最多提取6个值
  1286. //{
  1287. // string key = $"{i - 1}点补偿"; // 构造键名
  1288. // string value = values[i].Trim(); // 获取值并去除多余空格
  1289. // compensationDict[key] = value;
  1290. //}
  1291. }
  1292. }
  1293. else
  1294. {
  1295. Console.WriteLine($"文件不存在: {fullPath}");
  1296. }
  1297. }
  1298. catch (Exception ex)
  1299. {
  1300. // 捕获异常并输出错误信息
  1301. Console.WriteLine($"发生错误: {ex.Message}");
  1302. }
  1303. return compensationDict;
  1304. }
  1305. /// <summary>
  1306. /// 调用进站接口并保存进站数据
  1307. /// </summary>
  1308. /// <param name="stationNameStr">工站信息</param>
  1309. /// <param name="workorder_code">工单号</param>
  1310. /// <param name="mtltmrk">型号(物料号)</param>
  1311. /// <param name="sn">产品SN</param>
  1312. /// <param name="items">进站数据</param>
  1313. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1314. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn,
  1315. List<TestItem> items, string MachineId, string StationId)
  1316. {
  1317. int result = 0;
  1318. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1319. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1320. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1321. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1322. inRequest_Body.clientTime =
  1323. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1324. inRequest_Body.unitSn = sn; // 产品SN
  1325. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1326. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1327. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1328. StationIn stationIn = new StationIn()
  1329. {
  1330. Workorder_code = workorder_code, // 车间订单号
  1331. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1332. Sn = sn, // SN
  1333. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1334. Parameter_values = items, // 进站数据
  1335. Write_user = inRequest_Body.userId, // 员工Id
  1336. Test_time = inRequest_Body.clientTime // 进站时间
  1337. };
  1338. // 本地数据
  1339. string sql = stationIn.ToStringInsert(0);
  1340. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1341. result = ret == "成功" ? 1 : 6;
  1342. //await Task.Delay(200);
  1343. // 上传MES
  1344. if (GlobalContext.IsSendStationIn)
  1345. {
  1346. try
  1347. {
  1348. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1349. string mesRet = string.Empty;
  1350. int i = 0;
  1351. while (i < 2) // 1009会多次尝试上传
  1352. {
  1353. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1354. if (response != null && response.header.code == "200")
  1355. break;
  1356. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1357. i++;
  1358. i++;
  1359. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1360. // 记录失败原因
  1361. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + json_Body);
  1362. }
  1363. if (response?.header?.code == "200")
  1364. {
  1365. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1366. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1367. result = ret_Upd == "成功" ? 1 : 6;
  1368. AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功");
  1369. }
  1370. else
  1371. {
  1372. result = 5;
  1373. AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1374. }
  1375. string sql_response =
  1376. stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1377. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1378. }
  1379. catch (Exception ex)
  1380. {
  1381. result = 6;
  1382. string str = ex.StackTrace;
  1383. AddMessage_Station(stationNameStr, LogType.Error,
  1384. $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1385. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1386. }
  1387. }
  1388. return result;
  1389. }
  1390. /// <summary>
  1391. /// 选择如何记录出站数据
  1392. /// </summary>
  1393. /// <param name="items">出站数据</param>
  1394. /// <param name="equipmentCode">设备编号</param>
  1395. /// <param name="processItem">测试项目</param>
  1396. /// <param name="workorder_code">车间订单号</param>
  1397. /// <param name="batch_num">批次号</param>
  1398. /// <param name="mtltmrk">型号</param>
  1399. /// <param name="proDate">日期</param>
  1400. /// <param name="supplierCode">供应商代码</param>
  1401. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1402. /// <returns>上传成功时返回1;失败返回0</returns>
  1403. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode,
  1404. string processItem,
  1405. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1406. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId,
  1407. string StationId, string PartBarcode, string direction = "")
  1408. {
  1409. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num,
  1410. mtltmrk,
  1411. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode, direction);
  1412. }
  1413. /// <summary>
  1414. /// 添加出站数据(提交到MES+本地保存到数据库)
  1415. /// </summary>
  1416. /// <param name="items">出站数据</param>
  1417. /// <param name="equipmentCode">设备编号</param>
  1418. /// <param name="processItem">测试项目</param>
  1419. /// <param name="workorder_code">车间订单号</param>
  1420. /// <param name="batch_num">批次号</param>
  1421. /// <param name="mtltmrk">型号</param>
  1422. /// <param name="proDate">日期</param>
  1423. /// <param name="supplierCode">供应商代码</param>
  1424. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1425. /// <returns>上传成功时返回1;失败返回0</returns>
  1426. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1427. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1428. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot,
  1429. string machineId, string stationId, string partBarcode, string direction = "")
  1430. {
  1431. int upload = 0;
  1432. int result = 0;
  1433. ProcessData processData = new ProcessData()
  1434. {
  1435. Equipment_code = equipmentCode,
  1436. Workorder_code = workorder_code,
  1437. Batch_number = batch_num,
  1438. Sn = sn, // SN
  1439. Testitem = processItem,
  1440. Parameter_values = items,
  1441. Write_user = GlobalContext.CurrentUser,
  1442. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1443. };
  1444. // 本地数据
  1445. string sql = processData.ToStringInsert(upload);
  1446. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1447. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1448. // 上传MES
  1449. if (GlobalContext.IsSendProcessData)
  1450. {
  1451. try
  1452. {
  1453. string id = processData.ID.Copy();
  1454. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1455. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1456. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1457. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1458. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1459. outRequest_Body.unitSn = sn; // 产品SN
  1460. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1461. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1462. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1463. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1464. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1465. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1466. if (!string.IsNullOrEmpty(partBarcode))
  1467. {
  1468. outRequest_Body.unitData.keyMaterial.Add(
  1469. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1470. {
  1471. bindSort = 1,
  1472. materialSn = partBarcode
  1473. }); // 设备数据 - 部件码
  1474. }
  1475. //OP30站读txt数据
  1476. if (stationNameStr.Contains("OP30"))
  1477. {
  1478. string path = "";
  1479. if (direction == "Left")
  1480. path = GlobalContext.MESLaserLPath;
  1481. else
  1482. path = GlobalContext.MESLaserRPath;
  1483. //字典存储数据
  1484. Dictionary<string, string> compensationDict = GetLastLineCompensation(path, direction, sn);
  1485. foreach (var kvp in compensationDict)
  1486. {
  1487. outRequest_Body.unitData.processData.Add(
  1488. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1489. {
  1490. dataName = kvp.Key.ToString(),
  1491. dataValue = kvp.Value.ToString()
  1492. });
  1493. }
  1494. }
  1495. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1496. if (GlobalContext.IsSendProcessData)
  1497. {
  1498. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1499. string mesRet = string.Empty;
  1500. int i = 0;
  1501. while (i < 2) // 1009会多次尝试上传
  1502. {
  1503. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1504. if (response != null && response.header.code == "200")
  1505. {
  1506. OnMessage(LogType.Error,
  1507. "上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" +
  1508. JsonConvert.SerializeObject(response.body));
  1509. break;
  1510. }
  1511. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1512. i++;
  1513. i++;
  1514. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1515. // 记录失败原因
  1516. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1517. }
  1518. if (response?.header?.code == "200")
  1519. {
  1520. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1521. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1522. result = 1;
  1523. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1524. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1525. }
  1526. else
  1527. {
  1528. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1529. }
  1530. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(
  1531. JsonConvert.SerializeObject(outRequest_Body),
  1532. JsonConvert.SerializeObject(response), id);
  1533. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1534. }
  1535. }
  1536. catch (Exception ex)
  1537. {
  1538. string str = ex.StackTrace;
  1539. AddMessage_Station(stationNameStr, LogType.Error,
  1540. $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1541. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1542. }
  1543. }
  1544. return result;
  1545. }
  1546. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1547. //{
  1548. // Stopwatch stopwatch = new Stopwatch();
  1549. // stopwatch.Start();
  1550. // try
  1551. // {
  1552. // // 初始化 AtlasScrew 实例
  1553. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1554. // atlasScrew1.Initial();
  1555. // // 存储结果的列表
  1556. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1557. // // 存储角度和扭力的字符串列表
  1558. // List<string> angleStrs = new List<string>();
  1559. // List<string> torqueStrs = new List<string>();
  1560. // // 上一次获取的数据
  1561. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1562. // while (isExitAtlasLeft) // 检查是否收集数据
  1563. // {
  1564. // // 获取当前数据
  1565. // var currentResult = atlasScrew1.GetResults();
  1566. // // 判断是否为新数据
  1567. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1568. // {
  1569. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1570. // // 更新角度和扭力的字符串列表
  1571. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1572. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1573. // // 计算角度、扭力、起始扭力和最大扭力
  1574. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1575. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1576. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1577. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1578. // // 将新数据添加到结果列表
  1579. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1580. // // 更新上一次获取的数据
  1581. // lastResult = currentResult;
  1582. // }
  1583. // // 等待一段时间后再次检查
  1584. // Thread.Sleep(20); // 轮询间隔时间
  1585. // // 如果触发了出站,则退出循环
  1586. // if (!isExitAtlasLeft)
  1587. // {
  1588. // break;
  1589. // }
  1590. // }
  1591. // // 生成文件名
  1592. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1593. // // 写入数据到文件
  1594. // using (StreamWriter writer = new StreamWriter(fileName))
  1595. // {
  1596. // // 写入标题行
  1597. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1598. // // 写入每一行数据
  1599. // foreach (var result in results)
  1600. // {
  1601. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1602. // }
  1603. // }
  1604. // stopwatch.Stop();
  1605. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1606. // }
  1607. // catch (Exception ex)
  1608. // {
  1609. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1610. // }
  1611. // finally
  1612. // {
  1613. // // 重置标志变量
  1614. // isExitAtlasLeft = false;
  1615. // }
  1616. //}
  1617. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1618. //{
  1619. // Stopwatch stopwatch = new Stopwatch();
  1620. // stopwatch.Start();
  1621. // try
  1622. // {
  1623. // // 初始化 AtlasScrew 实例
  1624. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1625. // atlasScrew2.Initial();
  1626. // // 存储结果的列表
  1627. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1628. // // 上一次获取的数据
  1629. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1630. // while (isExitAtlasRight) // 检查是否收集数据
  1631. // {
  1632. // // 获取当前数据
  1633. // var currentResult = atlasScrew2.GetResults();
  1634. // // 判断是否为新数据
  1635. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1636. // {
  1637. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1638. // // 将新数据写入PLC
  1639. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1640. // // 将新数据添加到结果列表
  1641. // results.Add(currentResult);
  1642. // // 更新上一次获取的数据
  1643. // lastResult = currentResult;
  1644. // }
  1645. // // 等待一段时间后再次检查
  1646. // Thread.Sleep(20); // 轮询间隔时间
  1647. // // 如果触发了出站,则退出循环
  1648. // if (!isExitAtlasRight)
  1649. // {
  1650. // break;
  1651. // }
  1652. // }
  1653. // // 将所有数据写入文件
  1654. // //WriteDataToFile(sn, direction, results);
  1655. // stopwatch.Stop();
  1656. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1657. // }
  1658. // catch (Exception ex)
  1659. // {
  1660. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1661. // }
  1662. // finally
  1663. // {
  1664. // // 重置标志变量
  1665. // isExitAtlasRight = false;
  1666. // }
  1667. //}
  1668. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1669. {
  1670. Stopwatch stopwatch = new Stopwatch();
  1671. stopwatch.Start();
  1672. int nRet = 0;
  1673. string strRet = "";
  1674. try
  1675. {
  1676. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1677. while (isCollectingFlagLeft)
  1678. {
  1679. // 从缓存中获取所有未处理的数据
  1680. var cachedData = atlasScrew.GetCachedDataLeft();
  1681. foreach (var currentResult in cachedData)
  1682. {
  1683. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1684. {
  1685. continue; // 跳过无效数据
  1686. }
  1687. OnMessage(LogType.Info,
  1688. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1689. // 写入PLC
  1690. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1691. {
  1692. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1693. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1694. };
  1695. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1696. if (nRet != 0)
  1697. {
  1698. OnMessage(LogType.Info,
  1699. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1700. }
  1701. else
  1702. {
  1703. OnMessage(LogType.Info,
  1704. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1705. }
  1706. // 构建保存路径
  1707. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1708. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1709. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1710. Directory.CreateDirectory(savePath); // 确保目录存在
  1711. // 构建文件名(以 SN + 序号命名)
  1712. string fileName = $"{sn}_{fileCounter}.txt";
  1713. string filePath = Path.Combine(savePath, fileName);
  1714. // 写入文件
  1715. using (StreamWriter writer = new StreamWriter(filePath))
  1716. {
  1717. writer.WriteLine("精度, 扭力");
  1718. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1719. for (int i = 0;
  1720. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  1721. i++)
  1722. {
  1723. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1724. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1725. writer.WriteLine($"{precision}, {torque}");
  1726. }
  1727. }
  1728. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1729. // 增加文件计数器
  1730. fileCounter++;
  1731. }
  1732. // 如果没有更多数据,则短暂休眠以节省资源
  1733. if (!cachedData.Any())
  1734. {
  1735. Thread.Sleep(10); // 根据需要调整休眠时间
  1736. }
  1737. // 如果触发了出站,则退出循环
  1738. if (!isCollectingFlagLeft)
  1739. {
  1740. break;
  1741. }
  1742. }
  1743. stopwatch.Stop();
  1744. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1745. }
  1746. catch (Exception ex)
  1747. {
  1748. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1749. }
  1750. finally
  1751. {
  1752. isCollectingFlagLeft = false;
  1753. }
  1754. }
  1755. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1756. {
  1757. Stopwatch stopwatch = new Stopwatch();
  1758. stopwatch.Start();
  1759. int nRet = 0;
  1760. string strRet = "";
  1761. try
  1762. {
  1763. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1764. while (isCollectingFlagRight)
  1765. {
  1766. // 从缓存中获取所有未处理的数据
  1767. var cachedData = atlasScrew.GetCachedDataLeft();
  1768. foreach (var currentResult in cachedData)
  1769. {
  1770. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1771. {
  1772. continue; // 跳过无效数据
  1773. }
  1774. OnMessage(LogType.Info,
  1775. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1776. // 写入PLC
  1777. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1778. {
  1779. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1780. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1781. };
  1782. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1783. if (nRet != 0)
  1784. {
  1785. OnMessage(LogType.Info,
  1786. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1787. }
  1788. else
  1789. {
  1790. OnMessage(LogType.Info,
  1791. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1792. }
  1793. // 构建保存路径
  1794. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1795. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1796. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1797. Directory.CreateDirectory(savePath); // 确保目录存在
  1798. // 构建文件名(以 SN + 序号命名)
  1799. string fileName = $"{sn}_{fileCounter}.txt";
  1800. string filePath = Path.Combine(savePath, fileName);
  1801. // 写入文件
  1802. using (StreamWriter writer = new StreamWriter(filePath))
  1803. {
  1804. writer.WriteLine("精度, 扭力");
  1805. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1806. for (int i = 0;
  1807. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  1808. i++)
  1809. {
  1810. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1811. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1812. writer.WriteLine($"{precision}, {torque}");
  1813. }
  1814. }
  1815. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1816. // 增加文件计数器
  1817. fileCounter++;
  1818. }
  1819. // 如果没有更多数据,则短暂休眠以节省资源
  1820. if (!cachedData.Any())
  1821. {
  1822. Thread.Sleep(10); // 根据需要调整休眠时间
  1823. }
  1824. // 如果触发了出站,则退出循环
  1825. if (!isCollectingFlagRight)
  1826. {
  1827. break;
  1828. }
  1829. }
  1830. stopwatch.Stop();
  1831. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1832. }
  1833. catch (Exception ex)
  1834. {
  1835. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1836. }
  1837. finally
  1838. {
  1839. isCollectingFlagRight = false;
  1840. }
  1841. }
  1842. #endregion
  1843. #region S1
  1844. /// <summary>
  1845. /// [S1] 壳体清洁上料装备
  1846. /// </summary>
  1847. /// <param name="plcNo">PLC编号</param>
  1848. private void ReadStation_S1(int plcNo)
  1849. {
  1850. string stationCode = "[OP10]";
  1851. string stationName = "壳体清洁上料";
  1852. string stationNameStr = stationCode + stationName;
  1853. string tagBaseName = "g_OP10_MES"; //标签变量名称
  1854. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1855. string tagAgvCommName = "agvCommFrmPC";
  1856. string tagBarsetName = "BarcodeSet";
  1857. // 触发信号字典
  1858. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  1859. s1PLCSignal_Old.Add("a1OEEType", 0); // 节拍类型(plc写入)
  1860. // PLC数据字典 赋值
  1861. s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  1862. s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  1863. s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  1864. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  1865. (int, string) result;
  1866. while (true)
  1867. {
  1868. try
  1869. {
  1870. if (!GlobalContext._IsCon_Funs1)
  1871. {
  1872. UpdatePLCMonitor(1, plcNo, 0);
  1873. continue;
  1874. }
  1875. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1876. {
  1877. Stopwatch stopwatch1 = new Stopwatch();
  1878. Stopwatch stopwatch2 = new Stopwatch();
  1879. stopwatch1.Start();
  1880. stopwatch2.Start();
  1881. #region 一次性读取所有数据
  1882. // 一次性读取所有数据
  1883. result = FunsEip[plcNo]
  1884. .Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  1885. if (result.Item1 != 0)
  1886. {
  1887. //richTextBox1.AppendText("\n" + strRet);
  1888. }
  1889. else
  1890. {
  1891. //richTextBox1.AppendText("\n" + "读取成功");
  1892. //设备状态
  1893. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  1894. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  1895. ? XiaomiDeviceState.Unknown
  1896. : (XiaomiDeviceState)xmDeviceStateInt;
  1897. s1PLCData["a1OEEPartNo"] =
  1898. stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  1899. s1PLCData["a1OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  1900. s1PLCData["a1OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  1901. }
  1902. #endregion 一次性读取所有数据
  1903. stopwatch2.Stop();
  1904. #region 进站
  1905. try
  1906. {
  1907. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1908. {
  1909. lock (lockObj)
  1910. {
  1911. if (!ProgressState)
  1912. {
  1913. ProgressState = true;
  1914. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData,
  1915. tagBaseName + "." + tagMesCommName, out ProgressState));
  1916. }
  1917. }
  1918. }
  1919. }
  1920. catch (Exception ex)
  1921. {
  1922. ProgressState = false;
  1923. string str = ex.StackTrace;
  1924. AddMessage_Station(stationNameStr, LogType.Error,
  1925. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  1926. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1927. }
  1928. #endregion 进站
  1929. #region 出站
  1930. try
  1931. {
  1932. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1933. {
  1934. lock (lockObj)
  1935. {
  1936. if (!ProgressState)
  1937. {
  1938. ProgressState = true;
  1939. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData,
  1940. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  1941. out ProgressState));
  1942. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  1943. }
  1944. }
  1945. }
  1946. }
  1947. catch (Exception ex)
  1948. {
  1949. ProgressState = false;
  1950. string str = ex.StackTrace;
  1951. AddMessage_Station(stationNameStr, LogType.Error,
  1952. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  1953. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1954. }
  1955. #endregion 出站
  1956. #region 节拍接口
  1957. try
  1958. {
  1959. int a10EEType = (int)s1PLCData["a10EEType"];
  1960. int a10EETypeGOld = (int)s1PLCSignal_Old["a10EEType"];
  1961. //若设备紧急复原后节拍重置
  1962. if (a10EEType == 1)
  1963. {
  1964. a10EETypeGOld = 0;
  1965. }
  1966. if (a10EEType != a10EETypeGOld)
  1967. {
  1968. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  1969. if ((a10EETypeGOld == 1 && a10EEType != 2) || (a10EETypeGOld == 3 && a10EEType != 4) ||
  1970. (a10EETypeGOld == 5 && a10EEType != 6))
  1971. {
  1972. //写入PLC
  1973. stPLC_MesData.iotData.beatReturn = 2; //NG
  1974. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  1975. AddMessage(LogType.Info,
  1976. stationNameStr +
  1977. $"_节拍接口-- 设备本次上传节拍[{a10EEType}],未上传节拍[{a10EETypeGOld}]的结束信号,请检查;总用时" +
  1978. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  1979. "ms");
  1980. return;
  1981. }
  1982. else
  1983. {
  1984. Task.Run(() =>
  1985. S1节拍接口(plcNo, stationNameStr, tagBaseName,
  1986. stPLC_MesData.iotData)); // MreTasks[4].Set();
  1987. }
  1988. s1PLCSignal_Old["a10EEType"] = s1PLCData["a10EEType"];
  1989. }
  1990. }
  1991. catch (Exception ex)
  1992. {
  1993. string str = ex.StackTrace;
  1994. AddMessage_Station(stationNameStr, LogType.Error,
  1995. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  1996. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1997. }
  1998. #endregion
  1999. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2000. stopwatch1.Stop();
  2001. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2002. }
  2003. else
  2004. {
  2005. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2006. AddMessage_Station(stationNameStr, LogType.Info,
  2007. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2008. FunsEip[plcNo].Connect(); // 重连
  2009. }
  2010. }
  2011. catch (Exception ex)
  2012. {
  2013. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2014. AddMessage_Station(stationNameStr, LogType.Error,
  2015. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2016. }
  2017. Thread.Sleep(IntervalReadPLC);
  2018. }
  2019. }
  2020. /// <summary>
  2021. /// [S1] 壳体清洁上料 - 进站
  2022. /// </summary>
  2023. /// <param name="plcNo">PLC编号</param>
  2024. /// <param name="stationNameStr">工站全称</param>
  2025. /// <param name="stPLC_MesData"></param>
  2026. /// <param name="tagMesCommName"></param>
  2027. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  2028. out bool ProgressState)
  2029. {
  2030. Stopwatch stopwatch1 = new Stopwatch();
  2031. Stopwatch stopwatch2 = new Stopwatch();
  2032. try
  2033. {
  2034. stopwatch1.Start();
  2035. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2036. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  2037. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2038. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  2039. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  2040. if (string.IsNullOrEmpty(sn))
  2041. {
  2042. ProgressState = false;
  2043. return;
  2044. }
  2045. //正式生产就用PLC中取的
  2046. //sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;
  2047. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  2048. sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2049. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2050. //绑定载具和产品
  2051. ResponseMessage message = new ResponseMessage();
  2052. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  2053. if (message.result == false)
  2054. {
  2055. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  2056. }
  2057. // 产品SN进站
  2058. List<TestItem> item = new List<TestItem>();
  2059. stopwatch2.Start();
  2060. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  2061. item, MachineId, StationId);
  2062. stopwatch2.Stop();
  2063. //指令执行结果 1:OK 110:失败
  2064. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2065. //进站结果写入PLC
  2066. CommandFromPLC resultToPlC = new CommandFromPLC();
  2067. resultToPlC.cmd = 0;
  2068. resultToPlC.cmdParam = 0;
  2069. resultToPlC.cmdResult = mesResultFrmWeb;
  2070. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2071. }
  2072. catch (Exception ex)
  2073. {
  2074. string str = ex.StackTrace;
  2075. AddMessage(LogType.Error,
  2076. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  2077. str.Length - str.LastIndexOf("\\") - 1));
  2078. CommandFromPLC resultToPlC = new CommandFromPLC();
  2079. resultToPlC.cmd = 0;
  2080. resultToPlC.cmdParam = 0; //指令参数
  2081. resultToPlC.cmdResult = 110;
  2082. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2083. }
  2084. stopwatch1.Stop();
  2085. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2086. AddMessage(LogType.Info,
  2087. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  2088. stopwatch2.ElapsedMilliseconds + "ms");
  2089. ProgressState = false;
  2090. }
  2091. /// <summary>
  2092. /// [S1] 壳体清洁上料 - 出站接口
  2093. /// </summary>
  2094. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  2095. string stationCode, string stationName, out bool ProgressState)
  2096. {
  2097. Stopwatch stopwatch1 = new Stopwatch();
  2098. Stopwatch stopwatch2 = new Stopwatch();
  2099. try
  2100. {
  2101. stopwatch1.Start();
  2102. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2103. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2104. string processItem = stationName; // 项目
  2105. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2106. string supplierCode = ""; // 供应商代码
  2107. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  2108. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  2109. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  2110. string sn = string.Empty;
  2111. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2112. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  2113. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  2114. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2115. //a1Result = 1;
  2116. bool pass = a1Result == 1;
  2117. //根据载具码获取产品码
  2118. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2119. if (string.IsNullOrEmpty(strProductBarcode))
  2120. {
  2121. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2122. }
  2123. sn = strProductBarcode;
  2124. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2125. List<TestItem> items = new List<TestItem>();
  2126. items.Add(new TestItem()
  2127. {
  2128. Parameter_name = "载具码",
  2129. Parameter_value = CarrierBarcode,
  2130. Parameter_unit = ""
  2131. });
  2132. items.Add(new TestItem()
  2133. {
  2134. Parameter_name = "产品码",
  2135. Parameter_value = sn,
  2136. Parameter_unit = ""
  2137. });
  2138. //出站接口
  2139. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2140. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  2141. MachineId, StationId, "");
  2142. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2143. stopwatch2.Start();
  2144. //进站结果写入PLC
  2145. CommandFromPLC resultToPlC = new CommandFromPLC();
  2146. resultToPlC.cmd = 0;
  2147. resultToPlC.cmdParam = 0; //指令参数
  2148. resultToPlC.cmdResult = mesResultFrmWeb;
  2149. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2150. stopwatch2.Stop();
  2151. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2152. //保存PLC返回MES数据到本地
  2153. ResponseMessage message = new ResponseMessage();
  2154. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  2155. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress,
  2156. stPLC_MesData.mesData.fCleanSpeed,
  2157. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime,
  2158. stPLC_MesData.mesData.nCleanCount,
  2159. stPLC_MesData.mesData.nRemainCount);
  2160. if (message.result == false)
  2161. {
  2162. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2163. }
  2164. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  2165. }
  2166. catch (Exception ex)
  2167. {
  2168. stopwatch2.Start();
  2169. CommandFromPLC resultToPlC = new CommandFromPLC();
  2170. resultToPlC.cmd = 0;
  2171. resultToPlC.cmdParam = 0; //指令参数
  2172. resultToPlC.cmdResult = 110;
  2173. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2174. stopwatch2.Stop();
  2175. string str = ex.StackTrace;
  2176. AddMessage(LogType.Error,
  2177. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  2178. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2179. }
  2180. stopwatch1.Stop();
  2181. AddMessage(LogType.Info,
  2182. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  2183. stopwatch2.ElapsedMilliseconds + "ms");
  2184. ProgressState = false;
  2185. }
  2186. #endregion
  2187. #region S2
  2188. /// <summary>
  2189. /// [S2] 上盖板上料装备
  2190. /// </summary>
  2191. /// <param name="plcNo">PLC编号</param>
  2192. private void ReadStation_S2(int plcNo)
  2193. {
  2194. string stationCode = "[OP20]";
  2195. string stationName = "上盖板上料装备";
  2196. string stationNameStr = stationCode + stationName;
  2197. string tagBaseName = "g_OP20_MES"; //标签变量名称
  2198. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2199. string tagAgvCommName = "agvCommFrmPC";
  2200. string tagBarsetName = "BarcodeSet";
  2201. // 触发信号字典
  2202. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2203. s2PLCSignal_Old.Add("a2OEEType", 0); // 节拍类型(plc写入)
  2204. // PLC数据字典 赋值
  2205. s2PLCData.Add("a2OEEType", 0); // 节拍类型(plc写入)
  2206. s2PLCData.Add("a2OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  2207. s2PLCData.Add("a2OEEVehicleCode", ""); // 载具SN
  2208. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  2209. IoT_DataSet_t iot_data;
  2210. (int, string) result;
  2211. while (true)
  2212. {
  2213. try
  2214. {
  2215. if (!GlobalContext._IsCon_Funs2)
  2216. {
  2217. UpdatePLCMonitor(1, plcNo, 0);
  2218. continue;
  2219. }
  2220. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2221. {
  2222. Stopwatch stopwatch1 = new Stopwatch();
  2223. Stopwatch stopwatch2 = new Stopwatch();
  2224. stopwatch1.Start();
  2225. stopwatch2.Start();
  2226. #region 一次性读取所有数据
  2227. // 一次性读取所有数据
  2228. result = FunsEip[plcNo]
  2229. .Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2230. if (result.Item1 != 0)
  2231. {
  2232. //richTextBox1.AppendText("\n" + strRet);
  2233. }
  2234. else
  2235. {
  2236. //richTextBox1.AppendText("\n" + "读取成功");
  2237. //设备状态
  2238. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  2239. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  2240. ? XiaomiDeviceState.Unknown
  2241. : (XiaomiDeviceState)xmDeviceStateInt;
  2242. s2PLCData["a2OEEPartNo"] =
  2243. stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  2244. s2PLCData["a2OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  2245. s2PLCData["a2OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  2246. }
  2247. #endregion 一次性读取所有数据
  2248. stopwatch2.Stop();
  2249. #region 进站
  2250. try
  2251. {
  2252. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2253. {
  2254. lock (lockObj)
  2255. {
  2256. if (!ProgressState)
  2257. {
  2258. ProgressState = true;
  2259. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData,
  2260. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  2261. out ProgressState));
  2262. }
  2263. }
  2264. }
  2265. }
  2266. catch (Exception ex)
  2267. {
  2268. ProgressState = false;
  2269. string str = ex.StackTrace;
  2270. AddMessage_Station(stationNameStr, LogType.Error,
  2271. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2272. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2273. }
  2274. #endregion 进站
  2275. #region 出站
  2276. try
  2277. {
  2278. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2279. {
  2280. lock (lockObj)
  2281. {
  2282. if (!ProgressState)
  2283. {
  2284. ProgressState = true;
  2285. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData,
  2286. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  2287. out ProgressState));
  2288. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  2289. }
  2290. }
  2291. }
  2292. }
  2293. catch (Exception ex)
  2294. {
  2295. ProgressState = false;
  2296. string str = ex.StackTrace;
  2297. AddMessage_Station(stationNameStr, LogType.Error,
  2298. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2299. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2300. }
  2301. #endregion 出站
  2302. #region 节拍接口
  2303. try
  2304. {
  2305. int a20EEType = (int)s2PLCData["a20EEType"];
  2306. int a20EETypeGOld = (int)s2PLCSignal_Old["a20EEType"];
  2307. //若设备紧急复原后节拍重置
  2308. if (a20EEType == 1)
  2309. {
  2310. a20EETypeGOld = 0;
  2311. }
  2312. if (a20EEType != a20EETypeGOld)
  2313. {
  2314. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  2315. if ((a20EETypeGOld == 1 && a20EEType != 2) || (a20EETypeGOld == 3 && a20EEType != 4) ||
  2316. (a20EETypeGOld == 5 && a20EEType != 6))
  2317. {
  2318. //写入PLC
  2319. stPLC_MesData.iotData.beatReturn = 2; //NG
  2320. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  2321. AddMessage(LogType.Info,
  2322. stationNameStr +
  2323. $"_节拍接口-- 设备本次上传节拍[{a20EEType}],未上传节拍[{a20EETypeGOld}]的结束信号,请检查;总用时" +
  2324. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  2325. "ms");
  2326. return;
  2327. }
  2328. else
  2329. {
  2330. Task.Run(() =>
  2331. S2节拍接口(plcNo, stationNameStr, tagBaseName,
  2332. stPLC_MesData.iotData)); // MreTasks[4].Set();
  2333. }
  2334. s2PLCSignal_Old["a20EEType"] = s2PLCData["a20EEType"];
  2335. }
  2336. }
  2337. catch (Exception ex)
  2338. {
  2339. string str = ex.StackTrace;
  2340. AddMessage_Station(stationNameStr, LogType.Error,
  2341. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  2342. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2343. }
  2344. #endregion
  2345. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2346. stopwatch1.Stop();
  2347. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2348. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2349. }
  2350. else
  2351. {
  2352. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2353. AddMessage_Station(stationNameStr, LogType.Info,
  2354. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2355. FunsEip[plcNo].Connect();
  2356. }
  2357. }
  2358. catch (Exception ex)
  2359. {
  2360. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2361. AddMessage_Station(stationNameStr, LogType.Error,
  2362. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2363. //Funs[plcNo].ReConnect();
  2364. }
  2365. Thread.Sleep(IntervalReadPLC);
  2366. }
  2367. }
  2368. /// <summary>
  2369. /// [S2] 上盖板上料装备
  2370. /// </summary>
  2371. /// <param name="plcNo">PLC编号</param>
  2372. /// <param name="stationNameStr">工站全称</param>
  2373. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  2374. string tagBarsetName, out bool ProgressState)
  2375. {
  2376. Stopwatch stopwatch1 = new Stopwatch();
  2377. Stopwatch stopwatch2 = new Stopwatch();
  2378. try
  2379. {
  2380. stopwatch1.Start();
  2381. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2382. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  2383. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2384. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  2385. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  2386. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2387. //根据载具码获取产品码
  2388. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2389. if (string.IsNullOrEmpty(strProductBarcode))
  2390. {
  2391. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2392. }
  2393. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  2394. //if (sn != strProductBarcode)
  2395. //{
  2396. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  2397. //}
  2398. sn = strProductBarcode;
  2399. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2400. // 产品SN(物料码)校验
  2401. List<TestItem> item = new List<TestItem>();
  2402. stopwatch2.Start();
  2403. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  2404. item, MachineId, StationId);
  2405. stopwatch2.Stop();
  2406. //指令执行结果 1:OK 110:失败
  2407. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2408. //进站结果写入PLC
  2409. CommandFromPLC resultToPlC = new CommandFromPLC();
  2410. resultToPlC.cmd = 0;
  2411. resultToPlC.cmdParam = 0; //指令参数
  2412. resultToPlC.cmdResult = mesResultFrmWeb;
  2413. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2414. }
  2415. catch (Exception ex)
  2416. {
  2417. string str = ex.StackTrace;
  2418. AddMessage(LogType.Error,
  2419. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  2420. str.Length - str.LastIndexOf("\\") - 1));
  2421. CommandFromPLC resultToPlC = new CommandFromPLC();
  2422. resultToPlC.cmd = 0;
  2423. resultToPlC.cmdParam = 0; //指令参数
  2424. resultToPlC.cmdResult = 110;
  2425. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2426. }
  2427. stopwatch1.Stop();
  2428. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2429. AddMessage(LogType.Info,
  2430. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  2431. stopwatch2.ElapsedMilliseconds + "ms");
  2432. ProgressState = false;
  2433. }
  2434. /// <summary>
  2435. /// [S2] 上盖板上料装备 - 出站接口
  2436. /// </summary>
  2437. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  2438. string stationCode, string stationName, out bool ProgressState)
  2439. {
  2440. Stopwatch stopwatch1 = new Stopwatch();
  2441. Stopwatch stopwatch2 = new Stopwatch();
  2442. try
  2443. {
  2444. stopwatch1.Start();
  2445. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2446. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2447. string processItem = stationName; // 测试项目
  2448. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2449. string supplierCode = ""; // 供应商代码
  2450. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2451. string batch_num = GlobalContext.BatchNumber; // 批次号
  2452. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2453. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2454. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2455. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  2456. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  2457. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  2458. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2459. bool pass = a1Result == 1;
  2460. //根据载具码获取产品码
  2461. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2462. if (string.IsNullOrEmpty(strProductBarcode))
  2463. {
  2464. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2465. }
  2466. sn = strProductBarcode;
  2467. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2468. List<TestItem> items = new List<TestItem>();
  2469. items.Add(new TestItem()
  2470. {
  2471. Parameter_name = "载具码",
  2472. Parameter_value = CarrierBarcode,
  2473. Parameter_unit = ""
  2474. });
  2475. items.Add(new TestItem()
  2476. {
  2477. Parameter_name = "产品码",
  2478. Parameter_value = sn,
  2479. Parameter_unit = ""
  2480. });
  2481. items.Add(new TestItem()
  2482. {
  2483. Parameter_name = "部件码",
  2484. Parameter_value = PartBarcode,
  2485. Parameter_unit = ""
  2486. });
  2487. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2488. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  2489. MachineId, StationId, PartBarcode);
  2490. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2491. stopwatch2.Start();
  2492. //进站结果写入PLC
  2493. CommandFromPLC resultToPlC = new CommandFromPLC();
  2494. resultToPlC.cmd = 0;
  2495. resultToPlC.cmdParam = 0; //指令参数
  2496. resultToPlC.cmdResult = mesResultFrmWeb;
  2497. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2498. stopwatch2.Stop();
  2499. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2500. //保存PLC返回MES数据到本地
  2501. ResponseMessage message = new ResponseMessage();
  2502. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  2503. stPLC_MesData.mesData.nRemainCount);
  2504. if (message.result == false)
  2505. {
  2506. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2507. }
  2508. if (!string.IsNullOrEmpty(PartBarcode))
  2509. {
  2510. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  2511. if (message.result == false)
  2512. {
  2513. AddMessage(LogType.Error, message.text);
  2514. }
  2515. }
  2516. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2517. }
  2518. catch (Exception ex)
  2519. {
  2520. stopwatch2.Start();
  2521. CommandFromPLC resultToPlC = new CommandFromPLC();
  2522. resultToPlC.cmd = 0;
  2523. resultToPlC.cmdParam = 0; //指令参数
  2524. resultToPlC.cmdResult = 110;
  2525. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2526. stopwatch2.Stop();
  2527. string str = ex.StackTrace;
  2528. AddMessage(LogType.Error,
  2529. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  2530. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2531. }
  2532. stopwatch1.Stop();
  2533. AddMessage(LogType.Info,
  2534. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  2535. stopwatch2.ElapsedMilliseconds + "ms");
  2536. ProgressState = false;
  2537. }
  2538. #endregion
  2539. #region S3
  2540. /// <summary>
  2541. /// [S3] 点散热胶装备
  2542. /// </summary>
  2543. /// <param name="plcNo">PLC编号</param>
  2544. private void ReadStation_S3(int plcNo)
  2545. {
  2546. string stationCode = "[OP30]";
  2547. string stationName = "点散热胶装备";
  2548. string stationNameStr = stationCode + stationName;
  2549. string tagBaseName = "g_OP30_MES"; //标签变量名称
  2550. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2551. string tagAgvCommName = "agvCommFrmPC";
  2552. string tagBarsetName = "BarcodeSet";
  2553. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  2554. (int, string) result;
  2555. #region 创建字典
  2556. // 触发信号字典 赋值
  2557. s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2558. s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2559. s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2560. s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2561. s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2562. // PLC数据字典 赋值
  2563. s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2564. s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  2565. s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2566. s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2567. s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  2568. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2569. s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2570. s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2571. s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  2572. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2573. s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  2574. s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  2575. s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  2576. s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2577. s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  2578. s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  2579. //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  2580. s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2581. s3PLCData.Add("c1Result", 0); // 产品结果
  2582. s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2583. s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  2584. s3PLCData.Add("c1OEEProductSN", ""); // 产品SN(载具SN)
  2585. s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  2586. #endregion 创建字典
  2587. while (true)
  2588. {
  2589. try
  2590. {
  2591. if (!GlobalContext._IsCon_Funs2)
  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]
  2605. .Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2606. if (result.Item1 != 0)
  2607. {
  2608. //richTextBox1.AppendText("\n" + strRet);
  2609. }
  2610. else
  2611. {
  2612. //richTextBox1.AppendText("\n" + "读取成功");
  2613. //int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  2614. //int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  2615. int xmDeviceStateInt_L = 1;
  2616. int xmDeviceStateInt_R = 2;
  2617. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  2618. ? XiaomiDeviceState.Unknown
  2619. : (XiaomiDeviceState)xmDeviceStateInt_L;
  2620. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  2621. ? XiaomiDeviceState.Unknown
  2622. : (XiaomiDeviceState)xmDeviceStateInt_R;
  2623. }
  2624. #endregion 一次性读取所有数据
  2625. stopwatch2.Stop();
  2626. #region 左边进站
  2627. try
  2628. {
  2629. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2630. {
  2631. lock (lockObj)
  2632. {
  2633. if (!ProgressState)
  2634. {
  2635. ProgressState = true;
  2636. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left,
  2637. tagBaseName + ".Left." + tagMesCommName,
  2638. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  2639. }
  2640. }
  2641. }
  2642. }
  2643. catch (Exception ex)
  2644. {
  2645. ProgressState = false;
  2646. string str = ex.StackTrace;
  2647. AddMessage_Station(stationNameStr, LogType.Error,
  2648. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2649. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2650. }
  2651. #endregion 左边进站
  2652. #region 左边出站
  2653. try
  2654. {
  2655. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2656. {
  2657. lock (lockObj)
  2658. {
  2659. if (!ProgressState)
  2660. {
  2661. ProgressState = true;
  2662. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left,
  2663. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  2664. out ProgressState));
  2665. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  2666. }
  2667. }
  2668. }
  2669. }
  2670. catch (Exception ex)
  2671. {
  2672. ProgressState = false;
  2673. string str = ex.StackTrace;
  2674. AddMessage_Station(stationNameStr, LogType.Error,
  2675. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2676. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2677. }
  2678. #endregion 左边出站
  2679. #region 右边进站
  2680. try
  2681. {
  2682. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2683. {
  2684. lock (lockObj)
  2685. {
  2686. if (!ProgressState)
  2687. {
  2688. ProgressState = true;
  2689. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right,
  2690. tagBaseName + ".Right." + tagMesCommName,
  2691. tagBaseName + ".Right." + tagBarsetName, "Right", out ProgressState));
  2692. }
  2693. }
  2694. }
  2695. }
  2696. catch (Exception ex)
  2697. {
  2698. ProgressState = false;
  2699. string str = ex.StackTrace;
  2700. AddMessage_Station(stationNameStr, LogType.Error,
  2701. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2702. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2703. }
  2704. #endregion 右边进站
  2705. #region 右边出站
  2706. try
  2707. {
  2708. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2709. {
  2710. lock (lockObj)
  2711. {
  2712. if (!ProgressState)
  2713. {
  2714. ProgressState = true;
  2715. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right,
  2716. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  2717. out ProgressState));
  2718. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  2719. }
  2720. }
  2721. }
  2722. }
  2723. catch (Exception ex)
  2724. {
  2725. string str = ex.StackTrace;
  2726. AddMessage_Station(stationNameStr, LogType.Error,
  2727. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2728. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2729. }
  2730. #endregion 右边出站
  2731. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2732. stopwatch1.Stop();
  2733. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2734. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2735. }
  2736. else
  2737. {
  2738. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2739. AddMessage_Station(stationNameStr, LogType.Info,
  2740. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2741. FunsEip[plcNo].Connect();
  2742. }
  2743. }
  2744. catch (Exception ex)
  2745. {
  2746. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2747. AddMessage_Station(stationNameStr, LogType.Error,
  2748. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2749. //Funs[plcNo].ReConnect();
  2750. }
  2751. Thread.Sleep(IntervalReadPLC);
  2752. }
  2753. }
  2754. /// <summary>
  2755. /// [S3] 点散热胶装备 - 进站
  2756. /// </summary>
  2757. /// <param name="plcNo">PLC编号</param>
  2758. /// <param name="stationNameStr">工站全称</param>
  2759. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  2760. string tagBarsetName, string direction, out bool ProgressState)
  2761. {
  2762. Stopwatch stopwatch1 = new Stopwatch();
  2763. Stopwatch stopwatch2 = new Stopwatch();
  2764. try
  2765. {
  2766. stopwatch1.Start();
  2767. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  2768. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2769. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  2770. string StationId = string.Empty;
  2771. if (direction == "Left")
  2772. {
  2773. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2774. }
  2775. if (direction == "Right")
  2776. {
  2777. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2778. }
  2779. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2780. //载具码验证产品码
  2781. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2782. if (string.IsNullOrEmpty(strProductBarcode))
  2783. {
  2784. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2785. }
  2786. sn = strProductBarcode;
  2787. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  2788. // 产品SN(物料码)校验
  2789. List<TestItem> item = new List<TestItem>();
  2790. stopwatch2.Start();
  2791. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  2792. item, MachineId, StationId);
  2793. stopwatch2.Stop();
  2794. //指令执行结果 1:OK 110:失败
  2795. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2796. //进站结果写入PLC
  2797. CommandFromPLC resultToPlC = new CommandFromPLC();
  2798. resultToPlC.cmd = 0;
  2799. resultToPlC.cmdParam = 0; //指令参数
  2800. resultToPlC.cmdResult = mesResultFrmWeb;
  2801. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2802. }
  2803. catch (Exception ex)
  2804. {
  2805. string str = ex.StackTrace;
  2806. AddMessage(LogType.Error,
  2807. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  2808. str.Length - str.LastIndexOf("\\") - 1));
  2809. CommandFromPLC resultToPlC = new CommandFromPLC();
  2810. resultToPlC.cmd = 0;
  2811. resultToPlC.cmdParam = 0; //指令参数
  2812. resultToPlC.cmdResult = 110;
  2813. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2814. }
  2815. stopwatch1.Stop();
  2816. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  2817. AddMessage(LogType.Info,
  2818. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  2819. stopwatch2.ElapsedMilliseconds + "ms");
  2820. ProgressState = false;
  2821. }
  2822. /// <summary>
  2823. /// [S3] 点散热胶装备 - 出站
  2824. /// </summary>
  2825. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  2826. string stationCode, string stationName, string direction, out bool ProgressState)
  2827. {
  2828. Stopwatch stopwatch1 = new Stopwatch();
  2829. Stopwatch stopwatch2 = new Stopwatch();
  2830. try
  2831. {
  2832. stopwatch1.Start();
  2833. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  2834. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2835. string processItem = stationName; // 测试项目
  2836. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2837. string supplierCode = ""; // 供应商代码
  2838. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2839. string batch_num = GlobalContext.BatchNumber; // 批次号
  2840. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2841. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2842. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2843. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  2844. string StationId = string.Empty;
  2845. if (direction == "Left")
  2846. {
  2847. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2848. }
  2849. if (direction == "Right")
  2850. {
  2851. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2852. }
  2853. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2854. bool pass = a1Result == 1;
  2855. //根据载具码获取产品码
  2856. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2857. if (string.IsNullOrEmpty(strProductBarcode))
  2858. {
  2859. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2860. }
  2861. sn = strProductBarcode;
  2862. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2863. List<TestItem> items = new List<TestItem>();
  2864. items.Add(new TestItem()
  2865. {
  2866. Parameter_name = "载具码",
  2867. Parameter_value = CarrierBarcode,
  2868. Parameter_unit = ""
  2869. });
  2870. items.Add(new TestItem()
  2871. {
  2872. Parameter_name = "产品码",
  2873. Parameter_value = sn,
  2874. Parameter_unit = ""
  2875. });
  2876. int result1 = 1;
  2877. //if (direction == "Right")
  2878. //{
  2879. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2880. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  2881. MachineId, StationId, "", direction);
  2882. //}
  2883. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2884. stopwatch2.Start();
  2885. //进站结果写入PLC
  2886. CommandFromPLC resultToPlC = new CommandFromPLC();
  2887. resultToPlC.cmd = 0;
  2888. resultToPlC.cmdParam = 0; //指令参数
  2889. resultToPlC.cmdResult = mesResultFrmWeb;
  2890. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2891. stopwatch2.Stop();
  2892. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  2893. //保存PLC返回MES数据到本地
  2894. ResponseMessage message = new ResponseMessage();
  2895. if (direction == "Left")
  2896. {
  2897. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2898. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2899. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2900. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2901. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2902. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2903. if (message.result == false)
  2904. {
  2905. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2906. }
  2907. }
  2908. if (direction == "Right")
  2909. {
  2910. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2911. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2912. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2913. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2914. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2915. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2916. if (message.result == false)
  2917. {
  2918. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2919. }
  2920. }
  2921. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2922. }
  2923. catch (Exception ex)
  2924. {
  2925. stopwatch2.Start();
  2926. CommandFromPLC resultToPlC = new CommandFromPLC();
  2927. resultToPlC.cmd = 0;
  2928. resultToPlC.cmdParam = 0; //指令参数
  2929. resultToPlC.cmdResult = 110;
  2930. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2931. stopwatch2.Stop();
  2932. string str = ex.StackTrace;
  2933. AddMessage(LogType.Error,
  2934. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  2935. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2936. }
  2937. stopwatch1.Stop();
  2938. AddMessage(LogType.Info,
  2939. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  2940. stopwatch2.ElapsedMilliseconds + "ms");
  2941. ProgressState = false;
  2942. }
  2943. #endregion S3
  2944. #region S4
  2945. /// <summary>
  2946. /// [S4] 点胶检测设备
  2947. /// </summary>
  2948. /// <param name="plcNo">PLC编号</param>
  2949. private void ReadStation_S4(int plcNo)
  2950. {
  2951. string stationCode = "[OP40]";
  2952. string stationName = "胶线检测";
  2953. string stationNameStr = stationCode + stationName;
  2954. string tagBaseName = "g_OP40_MES"; //标签变量名称
  2955. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2956. string tagAgvCommName = "agvCommFrmPC";
  2957. string tagBarsetName = "BarcodeSet";
  2958. // 触发信号字典
  2959. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2960. s4PLCSignal_Old.Add("a4OEEType", 0); // 节拍类型(plc写入)
  2961. // PLC数据字典 赋值
  2962. s4PLCData.Add("a4OEEType", 0); // 节拍类型(plc写入)
  2963. s4PLCData.Add("a4OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  2964. s4PLCData.Add("a4OEEVehicleCode", ""); // 载具SN
  2965. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  2966. (int, string) result;
  2967. while (true)
  2968. {
  2969. try
  2970. {
  2971. if (!GlobalContext._IsCon_Funs1)
  2972. {
  2973. UpdatePLCMonitor(1, plcNo, 0);
  2974. continue;
  2975. }
  2976. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2977. {
  2978. Stopwatch stopwatch1 = new Stopwatch();
  2979. Stopwatch stopwatch2 = new Stopwatch();
  2980. stopwatch1.Start();
  2981. stopwatch2.Start();
  2982. #region 一次性读取所有数据
  2983. // 一次性读取所有数据
  2984. result = FunsEip[plcNo]
  2985. .Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2986. if (result.Item1 != 0)
  2987. {
  2988. //richTextBox1.AppendText("\n" + strRet);
  2989. }
  2990. else
  2991. {
  2992. //richTextBox1.AppendText("\n" + "读取成功");
  2993. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  2994. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  2995. ? XiaomiDeviceState.Unknown
  2996. : (XiaomiDeviceState)xmDeviceStateInt;
  2997. s4PLCData["a4OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  2998. s4PLCData["a4OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  2999. s4PLCData["a4OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  3000. }
  3001. #endregion 一次性读取所有数据
  3002. stopwatch2.Stop();
  3003. #region 进站
  3004. try
  3005. {
  3006. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3007. {
  3008. lock (lockObj)
  3009. {
  3010. if (!ProgressState)
  3011. {
  3012. ProgressState = true;
  3013. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData,
  3014. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  3015. out ProgressState));
  3016. }
  3017. }
  3018. }
  3019. }
  3020. catch (Exception ex)
  3021. {
  3022. ProgressState = false;
  3023. string str = ex.StackTrace;
  3024. AddMessage_Station(stationNameStr, LogType.Error,
  3025. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3026. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3027. }
  3028. #endregion 进站
  3029. #region 出站
  3030. try
  3031. {
  3032. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3033. {
  3034. lock (lockObj)
  3035. {
  3036. if (!ProgressState)
  3037. {
  3038. ProgressState = true;
  3039. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData,
  3040. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  3041. out ProgressState));
  3042. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3043. }
  3044. }
  3045. }
  3046. }
  3047. catch (Exception ex)
  3048. {
  3049. string str = ex.StackTrace;
  3050. AddMessage_Station(stationNameStr, LogType.Error,
  3051. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3052. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3053. }
  3054. #endregion 出站
  3055. #region 节拍接口
  3056. try
  3057. {
  3058. int a40EEType = (int)s4PLCData["a40EEType"];
  3059. int a40EETypeGOld = (int)s4PLCSignal_Old["a40EEType"];
  3060. //若设备紧急复原后节拍重置
  3061. if (a40EEType == 1)
  3062. {
  3063. a40EETypeGOld = 0;
  3064. }
  3065. if (a40EEType != a40EETypeGOld)
  3066. {
  3067. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  3068. if ((a40EETypeGOld == 1 && a40EEType != 2) || (a40EETypeGOld == 3 && a40EEType != 4) ||
  3069. (a40EETypeGOld == 5 && a40EEType != 6))
  3070. {
  3071. //写入PLC
  3072. stPLC_MesData.iotData.beatReturn = 2; //NG
  3073. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  3074. AddMessage(LogType.Info,
  3075. stationNameStr +
  3076. $"_节拍接口-- 设备本次上传节拍[{a40EEType}],未上传节拍[{a40EETypeGOld}]的结束信号,请检查;总用时" +
  3077. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  3078. "ms");
  3079. return;
  3080. }
  3081. else
  3082. {
  3083. Task.Run(() =>
  3084. S4节拍接口(plcNo, stationNameStr, tagBaseName,
  3085. stPLC_MesData.iotData)); // MreTasks[4].Set();
  3086. }
  3087. s4PLCSignal_Old["a40EEType"] = s4PLCData["a40EEType"];
  3088. }
  3089. }
  3090. catch (Exception ex)
  3091. {
  3092. string str = ex.StackTrace;
  3093. AddMessage_Station(stationNameStr, LogType.Error,
  3094. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3095. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3096. }
  3097. #endregion
  3098. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3099. stopwatch1.Stop();
  3100. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3101. }
  3102. else
  3103. {
  3104. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3105. AddMessage_Station(stationNameStr, LogType.Info,
  3106. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3107. FunsEip[plcNo].Connect(); // 重连
  3108. }
  3109. }
  3110. catch (Exception ex)
  3111. {
  3112. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3113. AddMessage_Station(stationNameStr, LogType.Error,
  3114. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3115. }
  3116. Thread.Sleep(IntervalReadPLC);
  3117. }
  3118. }
  3119. /// <summary>
  3120. /// [S4] 点胶检测设备 - 进站
  3121. /// </summary>
  3122. /// <param name="plcNo">PLC编号</param>
  3123. /// <param name="stationNameStr">工站全称</param>
  3124. /// <param name="stPLC_MesData"></param>
  3125. /// <param name="tagMesCommName"></param>
  3126. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  3127. string tagBarsetName, out bool ProgressState)
  3128. {
  3129. Stopwatch stopwatch1 = new Stopwatch();
  3130. Stopwatch stopwatch2 = new Stopwatch();
  3131. try
  3132. {
  3133. stopwatch1.Start();
  3134. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3135. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3136. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  3137. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  3138. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3139. //载具码验证产品码
  3140. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3141. if (string.IsNullOrEmpty(strProductBarcode))
  3142. {
  3143. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3144. }
  3145. sn = strProductBarcode;
  3146. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3147. // 产品SN(物料码)校验
  3148. List<TestItem> item = new List<TestItem>();
  3149. stopwatch2.Start();
  3150. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3151. item, MachineId, StationId);
  3152. stopwatch2.Stop();
  3153. //指令执行结果 1:OK 110:失败
  3154. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3155. //进站结果写入PLC
  3156. CommandFromPLC resultToPlC = new CommandFromPLC();
  3157. resultToPlC.cmd = 0;
  3158. resultToPlC.cmdParam = 0; //指令参数
  3159. resultToPlC.cmdResult = mesResultFrmWeb;
  3160. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3161. }
  3162. catch (Exception ex)
  3163. {
  3164. string str = ex.StackTrace;
  3165. AddMessage(LogType.Error,
  3166. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3167. str.Length - str.LastIndexOf("\\") - 1));
  3168. CommandFromPLC resultToPlC = new CommandFromPLC();
  3169. resultToPlC.cmd = 0;
  3170. resultToPlC.cmdParam = 0; //指令参数
  3171. resultToPlC.cmdResult = 110;
  3172. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3173. }
  3174. stopwatch1.Stop();
  3175. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3176. AddMessage(LogType.Info,
  3177. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3178. stopwatch2.ElapsedMilliseconds + "ms");
  3179. ProgressState = false;
  3180. }
  3181. /// <summary>
  3182. /// [S4] 点胶检测设备 - 出站接口
  3183. /// </summary>
  3184. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  3185. string stationCode, string stationName, out bool ProgressState)
  3186. {
  3187. Stopwatch stopwatch1 = new Stopwatch();
  3188. Stopwatch stopwatch2 = new Stopwatch();
  3189. try
  3190. {
  3191. stopwatch1.Start();
  3192. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3193. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3194. string processItem = stationName; // 测试项目
  3195. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3196. string supplierCode = ""; // 供应商代码
  3197. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3198. string batch_num = GlobalContext.BatchNumber; // 批次号
  3199. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3200. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3201. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3202. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  3203. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  3204. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3205. bool pass = a1Result == 1;
  3206. //根据载具码获取产品码
  3207. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3208. if (string.IsNullOrEmpty(strProductBarcode))
  3209. {
  3210. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3211. }
  3212. sn = strProductBarcode;
  3213. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3214. List<TestItem> items = new List<TestItem>();
  3215. items.Add(new TestItem()
  3216. {
  3217. Parameter_name = "载具码",
  3218. Parameter_value = CarrierBarcode,
  3219. Parameter_unit = ""
  3220. });
  3221. items.Add(new TestItem()
  3222. {
  3223. Parameter_name = "产品码",
  3224. Parameter_value = sn,
  3225. Parameter_unit = ""
  3226. });
  3227. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3228. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  3229. MachineId, StationId, "");
  3230. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3231. stopwatch2.Start();
  3232. //进站结果写入PLC
  3233. CommandFromPLC resultToPlC = new CommandFromPLC();
  3234. resultToPlC.cmd = 0;
  3235. resultToPlC.cmdParam = 0; //指令参数
  3236. resultToPlC.cmdResult = mesResultFrmWeb;
  3237. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3238. stopwatch2.Stop();
  3239. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3240. //保存PLC返回MES数据到本地
  3241. ResponseMessage message = new ResponseMessage();
  3242. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  3243. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  3244. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  3245. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  3246. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  3247. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  3248. if (message.result == false)
  3249. {
  3250. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3251. }
  3252. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3253. }
  3254. catch (Exception ex)
  3255. {
  3256. stopwatch2.Start();
  3257. CommandFromPLC resultToPlC = new CommandFromPLC();
  3258. resultToPlC.cmd = 0;
  3259. resultToPlC.cmdParam = 0; //指令参数
  3260. resultToPlC.cmdResult = 110;
  3261. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3262. stopwatch2.Stop();
  3263. string str = ex.StackTrace;
  3264. AddMessage(LogType.Error,
  3265. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3266. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3267. }
  3268. stopwatch1.Stop();
  3269. AddMessage(LogType.Info,
  3270. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3271. stopwatch2.ElapsedMilliseconds + "ms");
  3272. ProgressState = false;
  3273. }
  3274. private void S4节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  3275. {
  3276. Stopwatch stopwatch1 = new Stopwatch();
  3277. Stopwatch stopwatch2 = new Stopwatch();
  3278. string resultStr = string.Empty;
  3279. try
  3280. {
  3281. stopwatch1.Start();
  3282. string oEEType = ((int)s1PLCData["a4OEEType"]).ToString(); // 节拍类型(plc写入)
  3283. string a40EEPartNo = (string)s1PLCData["a40EEPartNo"]; // 物料码
  3284. a40EEPartNo = a40EEPartNo.Replace("\0", "");
  3285. string a50EEVehicleCode = (string)s1PLCData["a50EEVehicleCode"]; // 载具SN
  3286. a50EEVehicleCode = a50EEVehicleCode.Replace("\0", "");
  3287. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  3288. if (!actionBool)
  3289. {
  3290. stopwatch2.Start();
  3291. //写入PLC
  3292. iot_data.beatReturn = 2; //NG
  3293. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3294. stopwatch2.Stop();
  3295. AddMessage(LogType.Info,
  3296. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  3297. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3298. return;
  3299. }
  3300. //作业开始后要有物料和载具信息
  3301. if (string.IsNullOrEmpty(a40EEPartNo) && string.IsNullOrEmpty(a50EEVehicleCode) &&
  3302. Convert.ToInt32(oEEType) > 2)
  3303. {
  3304. stopwatch2.Start();
  3305. //写入PLC
  3306. iot_data.beatReturn = 2; //NG
  3307. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3308. stopwatch2.Stop();
  3309. AddMessage_Station(stationNameStr, LogType.Info,
  3310. stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  3311. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3312. return;
  3313. }
  3314. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a40EEPartNo))
  3315. {
  3316. stopwatch2.Start();
  3317. //写入PLC
  3318. iot_data.beatReturn = 2; //NG
  3319. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3320. stopwatch2.Stop();
  3321. AddMessage_Station(stationNameStr, LogType.Info,
  3322. stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  3323. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3324. return;
  3325. }
  3326. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a50EEVehicleCode))
  3327. {
  3328. stopwatch2.Start();
  3329. //写入PLC
  3330. iot_data.beatReturn = 2; //NG
  3331. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3332. stopwatch2.Stop();
  3333. AddMessage_Station(stationNameStr, LogType.Info,
  3334. stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  3335. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3336. return;
  3337. }
  3338. short _result = 0;
  3339. // 上传OEE
  3340. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a40EEPartNo, a50EEVehicleCode);
  3341. _result = result.Item1;
  3342. resultStr = result.Item2;
  3343. if (_result == 1)
  3344. {
  3345. stopwatch2.Start();
  3346. //写入PLC
  3347. iot_data.beatReturn = 1; //OK
  3348. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3349. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  3350. stopwatch2.Stop();
  3351. }
  3352. else
  3353. {
  3354. stopwatch2.Start();
  3355. //写入PLC
  3356. iot_data.beatReturn = 2; //NG
  3357. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3358. stopwatch2.Stop();
  3359. AddMessage_Station(stationNameStr, LogType.Error,
  3360. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  3361. }
  3362. }
  3363. catch (Exception ex)
  3364. {
  3365. string str = ex.StackTrace;
  3366. AddMessage_Station(stationNameStr, LogType.Error,
  3367. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  3368. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3369. // MES_Flag
  3370. stopwatch2.Start();
  3371. //写入PLC
  3372. iot_data.beatReturn = 2; //NG
  3373. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3374. stopwatch2.Stop();
  3375. }
  3376. stopwatch1.Stop();
  3377. AddMessage(LogType.Info,
  3378. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3379. stopwatch2.ElapsedMilliseconds + "ms");
  3380. }
  3381. #endregion
  3382. #region S5
  3383. /// <summary>
  3384. /// [S5] 点胶检测设备
  3385. /// </summary>
  3386. /// <param name="plcNo">PLC编号</param>
  3387. private void ReadStation_S5(int plcNo)
  3388. {
  3389. string stationCode = "[OP50]";
  3390. string stationName = "ADD板上料组装装备";
  3391. string stationNameStr = stationCode + stationName;
  3392. string tagBaseName = "g_OP50_MES"; //标签变量名称
  3393. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3394. string tagAgvCommName = "agvCommFrmPC";
  3395. string tagBarsetName = "BarcodeSet";
  3396. // 触发信号字典
  3397. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  3398. s5PLCSignal_Old.Add("a5OEEType", 0); // 节拍类型(plc写入)
  3399. // PLC数据字典 赋值
  3400. s5PLCData.Add("a5OEEType", 0); // 节拍类型(plc写入)
  3401. s5PLCData.Add("a5OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  3402. s5PLCData.Add("a5OEEVehicleCode", ""); // 载具SN
  3403. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  3404. (int, string) result;
  3405. while (true)
  3406. {
  3407. try
  3408. {
  3409. if (!GlobalContext._IsCon_Funs1)
  3410. {
  3411. UpdatePLCMonitor(1, plcNo, 0);
  3412. continue;
  3413. }
  3414. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3415. {
  3416. Stopwatch stopwatch1 = new Stopwatch();
  3417. Stopwatch stopwatch2 = new Stopwatch();
  3418. stopwatch1.Start();
  3419. stopwatch2.Start();
  3420. #region 一次性读取所有数据
  3421. // 一次性读取所有数据
  3422. result = FunsEip[plcNo]
  3423. .Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3424. if (result.Item1 != 0)
  3425. {
  3426. //richTextBox1.AppendText("\n" + strRet);
  3427. }
  3428. else
  3429. {
  3430. //richTextBox1.AppendText("\n" + "读取成功");
  3431. //richTextBox1.AppendText("\n" + "读取成功");
  3432. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  3433. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  3434. ? XiaomiDeviceState.Unknown
  3435. : (XiaomiDeviceState)xmDeviceStateInt;
  3436. s5PLCData["a5OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  3437. s5PLCData["a5OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  3438. s5PLCData["a5OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  3439. }
  3440. #endregion 一次性读取所有数据
  3441. stopwatch2.Stop();
  3442. #region 进站
  3443. try
  3444. {
  3445. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3446. {
  3447. lock (lockObj)
  3448. {
  3449. if (!ProgressState)
  3450. {
  3451. ProgressState = true;
  3452. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData,
  3453. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  3454. out ProgressState));
  3455. }
  3456. }
  3457. }
  3458. }
  3459. catch (Exception ex)
  3460. {
  3461. ProgressState = false;
  3462. string str = ex.StackTrace;
  3463. AddMessage_Station(stationNameStr, LogType.Error,
  3464. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3465. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3466. }
  3467. #endregion 进站
  3468. #region 出站
  3469. try
  3470. {
  3471. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3472. {
  3473. lock (lockObj)
  3474. {
  3475. if (!ProgressState)
  3476. {
  3477. ProgressState = true;
  3478. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData,
  3479. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  3480. out ProgressState));
  3481. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3482. }
  3483. }
  3484. }
  3485. }
  3486. catch (Exception ex)
  3487. {
  3488. ProgressState = false;
  3489. string str = ex.StackTrace;
  3490. AddMessage_Station(stationNameStr, LogType.Error,
  3491. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3492. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3493. }
  3494. #endregion 出站
  3495. #region 节拍接口
  3496. try
  3497. {
  3498. int a50EEType = (int)s5PLCData["a50EEType"];
  3499. int a50EETypeGOld = (int)s5PLCSignal_Old["a50EEType"];
  3500. //若设备紧急复原后节拍重置
  3501. if (a50EEType == 1)
  3502. {
  3503. a50EETypeGOld = 0;
  3504. }
  3505. if (a50EEType != a50EETypeGOld)
  3506. {
  3507. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  3508. if ((a50EETypeGOld == 1 && a50EEType != 2) || (a50EETypeGOld == 3 && a50EEType != 4) ||
  3509. (a50EETypeGOld == 5 && a50EEType != 6))
  3510. {
  3511. //写入PLC
  3512. stPLC_MesData.iotData.beatReturn = 2; //NG
  3513. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  3514. AddMessage(LogType.Info,
  3515. stationNameStr +
  3516. $"_节拍接口-- 设备本次上传节拍[{a50EEType}],未上传节拍[{a50EETypeGOld}]的结束信号,请检查;总用时" +
  3517. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  3518. "ms");
  3519. return;
  3520. }
  3521. else
  3522. {
  3523. Task.Run(() =>
  3524. S5节拍接口(plcNo, stationNameStr, tagBaseName,
  3525. stPLC_MesData.iotData)); // MreTasks[4].Set();
  3526. }
  3527. s5PLCSignal_Old["a50EEType"] = s5PLCData["a50EEType"];
  3528. }
  3529. }
  3530. catch (Exception ex)
  3531. {
  3532. string str = ex.StackTrace;
  3533. AddMessage_Station(stationNameStr, LogType.Error,
  3534. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3535. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3536. }
  3537. #endregion
  3538. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3539. stopwatch1.Stop();
  3540. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3541. }
  3542. else
  3543. {
  3544. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3545. AddMessage_Station(stationNameStr, LogType.Info,
  3546. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3547. FunsEip[plcNo].Connect(); // 重连
  3548. }
  3549. }
  3550. catch (Exception ex)
  3551. {
  3552. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3553. AddMessage_Station(stationNameStr, LogType.Error,
  3554. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3555. }
  3556. Thread.Sleep(IntervalReadPLC);
  3557. }
  3558. }
  3559. /// <summary>
  3560. /// [S5] 点胶检测设备 - 进站
  3561. /// </summary>
  3562. /// <param name="plcNo">PLC编号</param>
  3563. /// <param name="stationNameStr">工站全称</param>
  3564. /// <param name="stPLC_MesData"></param>
  3565. /// <param name="tagMesCommName"></param>
  3566. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  3567. string tagBarsetName, out bool ProgressState)
  3568. {
  3569. Stopwatch stopwatch1 = new Stopwatch();
  3570. Stopwatch stopwatch2 = new Stopwatch();
  3571. try
  3572. {
  3573. stopwatch1.Start();
  3574. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3575. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3576. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  3577. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  3578. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  3579. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3580. //载具码验证产品码 //载具码验证产品码
  3581. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3582. if (string.IsNullOrEmpty(strProductBarcode))
  3583. {
  3584. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3585. }
  3586. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  3587. //if (sn != strProductBarcode)
  3588. //{
  3589. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  3590. //}
  3591. sn = strProductBarcode;
  3592. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3593. // 产品SN(物料码)校验
  3594. List<TestItem> item = new List<TestItem>();
  3595. stopwatch2.Start();
  3596. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3597. item, MachineId, StationId);
  3598. stopwatch2.Stop();
  3599. //指令执行结果 1:OK 110:失败
  3600. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3601. //进站结果写入PLC
  3602. CommandFromPLC resultToPlC = new CommandFromPLC();
  3603. resultToPlC.cmd = 0;
  3604. resultToPlC.cmdParam = 0; //指令参数
  3605. resultToPlC.cmdResult = mesResultFrmWeb;
  3606. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3607. }
  3608. catch (Exception ex)
  3609. {
  3610. string str = ex.StackTrace;
  3611. AddMessage(LogType.Error,
  3612. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3613. str.Length - str.LastIndexOf("\\") - 1));
  3614. CommandFromPLC resultToPlC = new CommandFromPLC();
  3615. resultToPlC.cmd = 0;
  3616. resultToPlC.cmdParam = 0; //指令参数
  3617. resultToPlC.cmdResult = 110;
  3618. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3619. }
  3620. stopwatch1.Stop();
  3621. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3622. AddMessage(LogType.Info,
  3623. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3624. stopwatch2.ElapsedMilliseconds + "ms");
  3625. ProgressState = false;
  3626. }
  3627. /// <summary>
  3628. /// [S5] 点胶检测设备 - 出站接口
  3629. /// </summary>
  3630. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  3631. string stationCode, string stationName, out bool ProgressState)
  3632. {
  3633. Stopwatch stopwatch1 = new Stopwatch();
  3634. Stopwatch stopwatch2 = new Stopwatch();
  3635. try
  3636. {
  3637. stopwatch1.Start();
  3638. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3639. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3640. string processItem = stationName; // 测试项目
  3641. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3642. string supplierCode = ""; // 供应商代码
  3643. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3644. string batch_num = GlobalContext.BatchNumber; // 批次号
  3645. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3646. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3647. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
  3648. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3649. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  3650. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  3651. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3652. bool pass = a1Result == 1;
  3653. //根据载具码获取产品码
  3654. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3655. if (string.IsNullOrEmpty(strProductBarcode))
  3656. {
  3657. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3658. }
  3659. sn = strProductBarcode;
  3660. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3661. List<TestItem> items = new List<TestItem>();
  3662. items.Add(new TestItem()
  3663. {
  3664. Parameter_name = "载具码",
  3665. Parameter_value = CarrierBarcode,
  3666. Parameter_unit = ""
  3667. });
  3668. items.Add(new TestItem()
  3669. {
  3670. Parameter_name = "产品码",
  3671. Parameter_value = sn,
  3672. Parameter_unit = ""
  3673. });
  3674. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3675. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  3676. MachineId, StationId, PartBarcode);
  3677. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3678. stopwatch2.Start();
  3679. //进站结果写入PLC
  3680. CommandFromPLC resultToPlC = new CommandFromPLC();
  3681. resultToPlC.cmd = 0;
  3682. resultToPlC.cmdParam = 0; //指令参数
  3683. resultToPlC.cmdResult = mesResultFrmWeb;
  3684. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3685. stopwatch2.Stop();
  3686. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3687. //保存PLC返回MES数据到本地
  3688. ResponseMessage message = new ResponseMessage();
  3689. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  3690. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB,
  3691. stPLC_MesData.mesData.nRemainCount, "");
  3692. if (message.result == false)
  3693. {
  3694. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3695. }
  3696. //保存部件码信息
  3697. if (!string.IsNullOrEmpty(PartBarcode))
  3698. {
  3699. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  3700. if (message.result == false)
  3701. {
  3702. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  3703. }
  3704. }
  3705. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3706. }
  3707. catch (Exception ex)
  3708. {
  3709. stopwatch2.Start();
  3710. CommandFromPLC resultToPlC = new CommandFromPLC();
  3711. resultToPlC.cmd = 0;
  3712. resultToPlC.cmdParam = 0; //指令参数
  3713. resultToPlC.cmdResult = 110;
  3714. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3715. stopwatch2.Stop();
  3716. string str = ex.StackTrace;
  3717. AddMessage(LogType.Error,
  3718. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3719. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3720. }
  3721. stopwatch1.Stop();
  3722. AddMessage(LogType.Info,
  3723. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3724. stopwatch2.ElapsedMilliseconds + "ms");
  3725. ProgressState = false;
  3726. }
  3727. private void S5节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  3728. {
  3729. Stopwatch stopwatch1 = new Stopwatch();
  3730. Stopwatch stopwatch2 = new Stopwatch();
  3731. string resultStr = string.Empty;
  3732. try
  3733. {
  3734. stopwatch1.Start();
  3735. string oEEType = ((int)s1PLCData["a5OEEType"]).ToString(); // 节拍类型(plc写入)
  3736. string a50EEPartNo = (string)s1PLCData["a50EEPartNo"]; // 物料码
  3737. a50EEPartNo = a50EEPartNo.Replace("\0", "");
  3738. string a40EEVehicleCode = (string)s1PLCData["a40EEVehicleCode"]; // 载具SN
  3739. a40EEVehicleCode = a40EEVehicleCode.Replace("\0", "");
  3740. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  3741. if (!actionBool)
  3742. {
  3743. stopwatch2.Start();
  3744. //写入PLC
  3745. iot_data.beatReturn = 2; //NG
  3746. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3747. stopwatch2.Stop();
  3748. AddMessage(LogType.Info,
  3749. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  3750. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3751. return;
  3752. }
  3753. //作业开始后要有物料和载具信息
  3754. if (string.IsNullOrEmpty(a50EEPartNo) && string.IsNullOrEmpty(a40EEVehicleCode) &&
  3755. Convert.ToInt32(oEEType) > 2)
  3756. {
  3757. stopwatch2.Start();
  3758. //写入PLC
  3759. iot_data.beatReturn = 2; //NG
  3760. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3761. stopwatch2.Stop();
  3762. AddMessage_Station(stationNameStr, LogType.Info,
  3763. stationNameStr + $"_[{a40EEVehicleCode}][{a50EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  3764. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3765. return;
  3766. }
  3767. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a50EEPartNo))
  3768. {
  3769. stopwatch2.Start();
  3770. //写入PLC
  3771. iot_data.beatReturn = 2; //NG
  3772. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3773. stopwatch2.Stop();
  3774. AddMessage_Station(stationNameStr, LogType.Info,
  3775. stationNameStr + $"_[{a40EEVehicleCode}][{a50EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  3776. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3777. return;
  3778. }
  3779. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a40EEVehicleCode))
  3780. {
  3781. stopwatch2.Start();
  3782. //写入PLC
  3783. iot_data.beatReturn = 2; //NG
  3784. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3785. stopwatch2.Stop();
  3786. AddMessage_Station(stationNameStr, LogType.Info,
  3787. stationNameStr + $"_[{a40EEVehicleCode}][{a50EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  3788. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3789. return;
  3790. }
  3791. short _result = 0;
  3792. // 上传OEE
  3793. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a50EEPartNo, a40EEVehicleCode);
  3794. _result = result.Item1;
  3795. resultStr = result.Item2;
  3796. if (_result == 1)
  3797. {
  3798. stopwatch2.Start();
  3799. //写入PLC
  3800. iot_data.beatReturn = 1; //OK
  3801. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3802. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  3803. stopwatch2.Stop();
  3804. }
  3805. else
  3806. {
  3807. stopwatch2.Start();
  3808. //写入PLC
  3809. iot_data.beatReturn = 2; //NG
  3810. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3811. stopwatch2.Stop();
  3812. AddMessage_Station(stationNameStr, LogType.Error,
  3813. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  3814. }
  3815. }
  3816. catch (Exception ex)
  3817. {
  3818. string str = ex.StackTrace;
  3819. AddMessage_Station(stationNameStr, LogType.Error,
  3820. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  3821. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3822. // MES_Flag
  3823. stopwatch2.Start();
  3824. //写入PLC
  3825. iot_data.beatReturn = 2; //NG
  3826. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3827. stopwatch2.Stop();
  3828. }
  3829. stopwatch1.Stop();
  3830. AddMessage(LogType.Info,
  3831. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3832. stopwatch2.ElapsedMilliseconds + "ms");
  3833. }
  3834. #endregion
  3835. #region S6
  3836. private Dictionary<string, object> s6PLCData = new Dictionary<string, object>();
  3837. private Dictionary<string, object> s6PLCSignal_Old = new Dictionary<string, object>();
  3838. /// <summary>
  3839. /// [S6] 顶盖装配设备
  3840. /// </summary>
  3841. /// <param name="plcNo">PLC编号</param>
  3842. private void ReadStation_S6(int plcNo)
  3843. {
  3844. string stationCode = "[OP60]";
  3845. string stationName = "组上盖板";
  3846. string stationNameStr = stationCode + stationName;
  3847. string tagBaseName = "g_OP60_MES"; //标签变量名称
  3848. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3849. string tagAgvCommName = "agvCommFrmPC";
  3850. string tagBarsetName = "BarcodeSet";
  3851. // 触发信号字典
  3852. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  3853. s6PLCSignal_Old.Add("a6OEEType", 0); // 节拍类型(plc写入)
  3854. // PLC数据字典 赋值
  3855. s6PLCData.Add("a6OEEType", 0); // 节拍类型(plc写入)
  3856. s6PLCData.Add("a6OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  3857. s6PLCData.Add("a6OEEVehicleCode", ""); // 载具SN
  3858. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  3859. (int, string) result;
  3860. while (true)
  3861. {
  3862. try
  3863. {
  3864. if (!GlobalContext._IsCon_Funs1)
  3865. {
  3866. UpdatePLCMonitor(1, plcNo, 0);
  3867. continue;
  3868. }
  3869. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3870. {
  3871. Stopwatch stopwatch1 = new Stopwatch();
  3872. Stopwatch stopwatch2 = new Stopwatch();
  3873. stopwatch1.Start();
  3874. stopwatch2.Start();
  3875. #region 一次性读取所有数据
  3876. // 一次性读取所有数据
  3877. result = FunsEip[plcNo]
  3878. .Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3879. if (result.Item1 != 0)
  3880. {
  3881. //richTextBox1.AppendText("\n" + strRet);
  3882. }
  3883. else
  3884. {
  3885. //richTextBox1.AppendText("\n" + "读取成功");
  3886. //richTextBox1.AppendText("\n" + "读取成功");
  3887. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  3888. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  3889. ? XiaomiDeviceState.Unknown
  3890. : (XiaomiDeviceState)xmDeviceStateInt;
  3891. s6PLCData["a6OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  3892. s6PLCData["a6OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  3893. s6PLCData["a6OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  3894. }
  3895. #endregion 一次性读取所有数据
  3896. stopwatch2.Stop();
  3897. #region 进站
  3898. try
  3899. {
  3900. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3901. {
  3902. lock (lockObj)
  3903. {
  3904. if (!ProgressState)
  3905. {
  3906. ProgressState = true;
  3907. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData,
  3908. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  3909. out ProgressState));
  3910. }
  3911. }
  3912. }
  3913. }
  3914. catch (Exception ex)
  3915. {
  3916. ProgressState = false;
  3917. string str = ex.StackTrace;
  3918. AddMessage_Station(stationNameStr, LogType.Error,
  3919. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3920. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3921. }
  3922. #endregion 进站
  3923. #region 出站
  3924. try
  3925. {
  3926. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3927. {
  3928. lock (lockObj)
  3929. {
  3930. if (!ProgressState)
  3931. {
  3932. ProgressState = true;
  3933. ;
  3934. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData,
  3935. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  3936. out ProgressState));
  3937. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3938. }
  3939. }
  3940. }
  3941. }
  3942. catch (Exception ex)
  3943. {
  3944. ProgressState = false;
  3945. string str = ex.StackTrace;
  3946. AddMessage_Station(stationNameStr, LogType.Error,
  3947. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3948. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3949. }
  3950. #endregion 出站
  3951. #region 节拍接口
  3952. try
  3953. {
  3954. int a60EEType = (int)s6PLCData["a60EEType"];
  3955. int a60EETypeGOld = (int)s6PLCSignal_Old["a60EEType"];
  3956. //若设备紧急复原后节拍重置
  3957. if (a60EEType == 1)
  3958. {
  3959. a60EETypeGOld = 0;
  3960. }
  3961. if (a60EEType != a60EETypeGOld)
  3962. {
  3963. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  3964. if ((a60EETypeGOld == 1 && a60EEType != 2) || (a60EETypeGOld == 3 && a60EEType != 4) ||
  3965. (a60EETypeGOld == 5 && a60EEType != 6))
  3966. {
  3967. //写入PLC
  3968. stPLC_MesData.iotData.beatReturn = 2; //NG
  3969. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  3970. AddMessage(LogType.Info,
  3971. stationNameStr +
  3972. $"_节拍接口-- 设备本次上传节拍[{a60EEType}],未上传节拍[{a60EETypeGOld}]的结束信号,请检查;总用时" +
  3973. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  3974. "ms");
  3975. return;
  3976. }
  3977. else
  3978. {
  3979. Task.Run(() =>
  3980. S6节拍接口(plcNo, stationNameStr, tagBaseName,
  3981. stPLC_MesData.iotData)); // MreTasks[4].Set();
  3982. }
  3983. s6PLCSignal_Old["a60EEType"] = s6PLCData["a60EEType"];
  3984. }
  3985. }
  3986. catch (Exception ex)
  3987. {
  3988. string str = ex.StackTrace;
  3989. AddMessage_Station(stationNameStr, LogType.Error,
  3990. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3991. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3992. }
  3993. #endregion
  3994. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3995. stopwatch1.Stop();
  3996. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3997. }
  3998. else
  3999. {
  4000. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4001. AddMessage_Station(stationNameStr, LogType.Info,
  4002. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4003. FunsEip[plcNo].Connect(); // 重连
  4004. }
  4005. }
  4006. catch (Exception ex)
  4007. {
  4008. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4009. AddMessage_Station(stationNameStr, LogType.Error,
  4010. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4011. }
  4012. Thread.Sleep(IntervalReadPLC);
  4013. }
  4014. }
  4015. /// <summary>
  4016. /// [S6] 顶盖装配设备 - 进站
  4017. /// </summary>
  4018. /// <param name="plcNo">PLC编号</param>
  4019. /// <param name="stationNameStr">工站全称</param>
  4020. /// <param name="stPLC_MesData"></param>
  4021. /// <param name="tagMesCommName"></param>
  4022. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  4023. string tagBarsetName, out bool ProgressState)
  4024. {
  4025. Stopwatch stopwatch1 = new Stopwatch();
  4026. Stopwatch stopwatch2 = new Stopwatch();
  4027. try
  4028. {
  4029. stopwatch1.Start();
  4030. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4031. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4032. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  4033. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  4034. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4035. //载具码验证产品码
  4036. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4037. if (string.IsNullOrEmpty(strProductBarcode))
  4038. {
  4039. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4040. }
  4041. sn = strProductBarcode;
  4042. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4043. // 产品SN(物料码)校验
  4044. List<TestItem> item = new List<TestItem>();
  4045. stopwatch2.Start();
  4046. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  4047. item, MachineId, StationId);
  4048. stopwatch2.Stop();
  4049. //指令执行结果 1:OK 110:失败
  4050. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4051. //进站结果写入PLC
  4052. CommandFromPLC resultToPlC = new CommandFromPLC();
  4053. resultToPlC.cmd = 0;
  4054. resultToPlC.cmdParam = 0; //指令参数
  4055. resultToPlC.cmdResult = mesResultFrmWeb;
  4056. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4057. }
  4058. catch (Exception ex)
  4059. {
  4060. string str = ex.StackTrace;
  4061. AddMessage(LogType.Error,
  4062. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4063. str.Length - str.LastIndexOf("\\") - 1));
  4064. CommandFromPLC resultToPlC = new CommandFromPLC();
  4065. resultToPlC.cmd = 0;
  4066. resultToPlC.cmdParam = 0; //指令参数
  4067. resultToPlC.cmdResult = 110;
  4068. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4069. }
  4070. stopwatch1.Stop();
  4071. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4072. AddMessage(LogType.Info,
  4073. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4074. stopwatch2.ElapsedMilliseconds + "ms");
  4075. ProgressState = false;
  4076. }
  4077. /// <summary>
  4078. /// [S6] 顶盖装配设备 - 出站接口
  4079. /// </summary>
  4080. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  4081. string stationCode, string stationName, out bool ProgressState)
  4082. {
  4083. Stopwatch stopwatch1 = new Stopwatch();
  4084. Stopwatch stopwatch2 = new Stopwatch();
  4085. try
  4086. {
  4087. stopwatch1.Start();
  4088. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4089. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4090. string processItem = stationName; // 测试项目
  4091. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4092. string supplierCode = ""; // 供应商代码
  4093. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4094. string batch_num = GlobalContext.BatchNumber; // 批次号
  4095. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4096. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4097. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4098. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  4099. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  4100. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4101. bool pass = a1Result == 1;
  4102. //根据载具码获取产品码
  4103. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4104. if (string.IsNullOrEmpty(strProductBarcode))
  4105. {
  4106. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4107. }
  4108. sn = strProductBarcode;
  4109. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4110. List<TestItem> items = new List<TestItem>();
  4111. items.Add(new TestItem()
  4112. {
  4113. Parameter_name = "载具码",
  4114. Parameter_value = CarrierBarcode,
  4115. Parameter_unit = ""
  4116. });
  4117. items.Add(new TestItem()
  4118. {
  4119. Parameter_name = "产品码",
  4120. Parameter_value = sn,
  4121. Parameter_unit = ""
  4122. });
  4123. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4124. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  4125. MachineId, StationId, "");
  4126. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4127. stopwatch2.Start();
  4128. //进站结果写入PLC
  4129. CommandFromPLC resultToPlC = new CommandFromPLC();
  4130. resultToPlC.cmd = 0;
  4131. resultToPlC.cmdParam = 0; //指令参数
  4132. resultToPlC.cmdResult = mesResultFrmWeb;
  4133. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4134. stopwatch2.Stop();
  4135. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4136. //保存PLC返回MES数据到本地
  4137. ResponseMessage message = new ResponseMessage();
  4138. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  4139. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  4140. if (message.result == false)
  4141. {
  4142. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4143. }
  4144. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4145. }
  4146. catch (Exception ex)
  4147. {
  4148. stopwatch2.Start();
  4149. CommandFromPLC resultToPlC = new CommandFromPLC();
  4150. resultToPlC.cmd = 0;
  4151. resultToPlC.cmdParam = 0; //指令参数
  4152. resultToPlC.cmdResult = 110;
  4153. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4154. stopwatch2.Stop();
  4155. string str = ex.StackTrace;
  4156. AddMessage(LogType.Error,
  4157. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4158. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4159. }
  4160. stopwatch1.Stop();
  4161. AddMessage(LogType.Info,
  4162. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4163. stopwatch2.ElapsedMilliseconds + "ms");
  4164. ProgressState = false;
  4165. }
  4166. private void S6节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  4167. {
  4168. Stopwatch stopwatch1 = new Stopwatch();
  4169. Stopwatch stopwatch2 = new Stopwatch();
  4170. string resultStr = string.Empty;
  4171. try
  4172. {
  4173. stopwatch1.Start();
  4174. string oEEType = ((int)s1PLCData["a6OEEType"]).ToString(); // 节拍类型(plc写入)
  4175. string a60EEPartNo = (string)s1PLCData["a60EEPartNo"]; // 物料码
  4176. a60EEPartNo = a60EEPartNo.Replace("\0", "");
  4177. string a60EEVehicleCode = (string)s1PLCData["a60EEVehicleCode"]; // 载具SN
  4178. a60EEVehicleCode = a60EEVehicleCode.Replace("\0", "");
  4179. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4180. if (!actionBool)
  4181. {
  4182. stopwatch2.Start();
  4183. //写入PLC
  4184. iot_data.beatReturn = 2; //NG
  4185. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4186. stopwatch2.Stop();
  4187. AddMessage(LogType.Info,
  4188. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  4189. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4190. return;
  4191. }
  4192. //作业开始后要有物料和载具信息
  4193. if (string.IsNullOrEmpty(a60EEPartNo) && string.IsNullOrEmpty(a60EEVehicleCode) &&
  4194. Convert.ToInt32(oEEType) > 2)
  4195. {
  4196. stopwatch2.Start();
  4197. //写入PLC
  4198. iot_data.beatReturn = 2; //NG
  4199. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4200. stopwatch2.Stop();
  4201. AddMessage_Station(stationNameStr, LogType.Info,
  4202. stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  4203. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4204. return;
  4205. }
  4206. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a60EEPartNo))
  4207. {
  4208. stopwatch2.Start();
  4209. //写入PLC
  4210. iot_data.beatReturn = 2; //NG
  4211. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4212. stopwatch2.Stop();
  4213. AddMessage_Station(stationNameStr, LogType.Info,
  4214. stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  4215. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4216. return;
  4217. }
  4218. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a60EEVehicleCode))
  4219. {
  4220. stopwatch2.Start();
  4221. //写入PLC
  4222. iot_data.beatReturn = 2; //NG
  4223. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4224. stopwatch2.Stop();
  4225. AddMessage_Station(stationNameStr, LogType.Info,
  4226. stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  4227. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4228. return;
  4229. }
  4230. short _result = 0;
  4231. // 上传OEE
  4232. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a60EEPartNo, a60EEVehicleCode);
  4233. _result = result.Item1;
  4234. resultStr = result.Item2;
  4235. if (_result == 1)
  4236. {
  4237. stopwatch2.Start();
  4238. //写入PLC
  4239. iot_data.beatReturn = 1; //OK
  4240. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4241. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  4242. stopwatch2.Stop();
  4243. }
  4244. else
  4245. {
  4246. stopwatch2.Start();
  4247. //写入PLC
  4248. iot_data.beatReturn = 2; //NG
  4249. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4250. stopwatch2.Stop();
  4251. AddMessage_Station(stationNameStr, LogType.Error,
  4252. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  4253. }
  4254. }
  4255. catch (Exception ex)
  4256. {
  4257. string str = ex.StackTrace;
  4258. AddMessage_Station(stationNameStr, LogType.Error,
  4259. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  4260. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4261. // MES_Flag
  4262. stopwatch2.Start();
  4263. //写入PLC
  4264. iot_data.beatReturn = 2; //NG
  4265. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4266. stopwatch2.Stop();
  4267. }
  4268. stopwatch1.Stop();
  4269. AddMessage(LogType.Info,
  4270. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4271. stopwatch2.ElapsedMilliseconds + "ms");
  4272. }
  4273. #endregion
  4274. #region S7
  4275. /// <summary>
  4276. /// [S7] 锁螺丝设备
  4277. /// </summary>
  4278. /// <param name="plcNo">PLC编号</param>
  4279. private void ReadStation_S7(int plcNo)
  4280. {
  4281. string stationCode = "[OP70]";
  4282. string stationName = "上盖板锁螺丝";
  4283. string stationNameStr = stationCode + stationName;
  4284. string tagBaseName = "g_OP70_MES"; //标签变量名称
  4285. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4286. string tagAgvCommName = "agvCommFrmPC";
  4287. string tagBarsetName = "BarcodeSet";
  4288. string tagScrewDataset = "screwDataset";
  4289. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  4290. (int, string) result;
  4291. AtlasScrew atlasScrewLeft = new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort,
  4292. 3000, 3000, "Left");
  4293. atlasScrewLeft.Initial();
  4294. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort,
  4295. 3000, 3000, "Right");
  4296. atlasScrewRight.Initial();
  4297. while (true)
  4298. {
  4299. try
  4300. {
  4301. if (!GlobalContext._IsCon_Funs1)
  4302. {
  4303. UpdatePLCMonitor(1, plcNo, 0);
  4304. continue;
  4305. }
  4306. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4307. {
  4308. Stopwatch stopwatch1 = new Stopwatch();
  4309. Stopwatch stopwatch2 = new Stopwatch();
  4310. stopwatch1.Start();
  4311. stopwatch2.Start();
  4312. #region 一次性读取所有数据
  4313. // 一次性读取所有数据
  4314. result = FunsEip[plcNo]
  4315. .Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4316. if (result.Item1 != 0)
  4317. {
  4318. //richTextBox1.AppendText("\n" + strRet);
  4319. }
  4320. else
  4321. {
  4322. //richTextBox1.AppendText("\n" + "读取成功");
  4323. }
  4324. #endregion 一次性读取所有数据
  4325. stopwatch2.Stop();
  4326. #region 左边进站
  4327. try
  4328. {
  4329. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4330. {
  4331. lock (lockObj)
  4332. {
  4333. if (!ProgressState)
  4334. {
  4335. ProgressState = true;
  4336. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left,
  4337. tagBaseName + ".Left." + tagMesCommName,
  4338. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState,
  4339. atlasScrewLeft));
  4340. }
  4341. }
  4342. }
  4343. }
  4344. catch (Exception ex)
  4345. {
  4346. ProgressState = false;
  4347. string str = ex.StackTrace;
  4348. AddMessage_Station(stationNameStr, LogType.Error,
  4349. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4350. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4351. }
  4352. #endregion 左边进站
  4353. #region 左边出站
  4354. try
  4355. {
  4356. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4357. {
  4358. lock (lockObj)
  4359. {
  4360. if (!ProgressState)
  4361. {
  4362. ProgressState = true;
  4363. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left,
  4364. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  4365. out ProgressState));
  4366. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  4367. }
  4368. }
  4369. }
  4370. }
  4371. catch (Exception ex)
  4372. {
  4373. ProgressState = false;
  4374. string str = ex.StackTrace;
  4375. AddMessage_Station(stationNameStr, LogType.Error,
  4376. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4377. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4378. }
  4379. #endregion 左边出站
  4380. #region 右边进站
  4381. try
  4382. {
  4383. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4384. {
  4385. lock (lockObj)
  4386. {
  4387. if (!ProgressState)
  4388. {
  4389. ProgressState = true;
  4390. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right,
  4391. tagBaseName + ".Right." + tagMesCommName,
  4392. tagBaseName + ".Right" + tagBarsetName, "Right", out ProgressState,
  4393. atlasScrewRight));
  4394. }
  4395. }
  4396. }
  4397. }
  4398. catch (Exception ex)
  4399. {
  4400. ProgressState = false;
  4401. string str = ex.StackTrace;
  4402. AddMessage_Station(stationNameStr, LogType.Error,
  4403. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4404. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4405. }
  4406. #endregion 右边进站
  4407. #region 右边出站
  4408. try
  4409. {
  4410. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4411. {
  4412. lock (lockObj)
  4413. {
  4414. if (!ProgressState)
  4415. {
  4416. ProgressState = true;
  4417. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right,
  4418. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  4419. out ProgressState));
  4420. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  4421. }
  4422. }
  4423. }
  4424. }
  4425. catch (Exception ex)
  4426. {
  4427. ProgressState = false;
  4428. string str = ex.StackTrace;
  4429. AddMessage_Station(stationNameStr, LogType.Error,
  4430. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4431. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4432. }
  4433. #endregion 右边出站
  4434. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4435. stopwatch1.Stop();
  4436. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4437. }
  4438. else
  4439. {
  4440. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4441. AddMessage_Station(stationNameStr, LogType.Info,
  4442. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4443. FunsEip[plcNo].Connect(); // 重连
  4444. }
  4445. }
  4446. catch (Exception ex)
  4447. {
  4448. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4449. AddMessage_Station(stationNameStr, LogType.Error,
  4450. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4451. }
  4452. Thread.Sleep(IntervalReadPLC);
  4453. }
  4454. }
  4455. /// <summary>
  4456. /// [S7] 锁螺丝设备 - 进站
  4457. /// </summary>
  4458. /// <param name="plcNo">PLC编号</param>
  4459. /// <param name="stationNameStr">工站全称</param>
  4460. /// <param name="stPLC_MesData"></param>
  4461. /// <param name="tagMesCommName"></param>
  4462. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  4463. string tagBarsetName, string direction, out bool ProgressState, AtlasScrew atlasScrew)
  4464. {
  4465. Stopwatch stopwatch1 = new Stopwatch();
  4466. Stopwatch stopwatch2 = new Stopwatch();
  4467. string atlasSn = string.Empty;
  4468. try
  4469. {
  4470. stopwatch1.Start();
  4471. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  4472. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4473. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  4474. string StationId = string.Empty; // 工位ID(可配置)
  4475. if (direction == "Left")
  4476. {
  4477. StationId = GlobalContext.S7_StationId_1;
  4478. }
  4479. if (direction == "Right")
  4480. {
  4481. StationId = GlobalContext.S7_StationId_2;
  4482. }
  4483. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4484. //载具码验证产品码
  4485. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4486. if (string.IsNullOrEmpty(strProductBarcode))
  4487. {
  4488. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4489. }
  4490. sn = strProductBarcode;
  4491. atlasSn = strProductBarcode;
  4492. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4493. if (direction == "Left")
  4494. {
  4495. isCollectingFlagLeft = false; //采集螺丝数据结束
  4496. }
  4497. if (direction == "Right")
  4498. {
  4499. isCollectingFlagRight = false; //采集螺丝数据结束
  4500. }
  4501. // 产品SN(物料码)校验
  4502. List<TestItem> item = new List<TestItem>();
  4503. stopwatch2.Start();
  4504. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  4505. item, MachineId, StationId);
  4506. stopwatch2.Stop();
  4507. //指令执行结果 1:OK 110:失败
  4508. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4509. //进站结果写入PLC
  4510. CommandFromPLC resultToPlC = new CommandFromPLC();
  4511. resultToPlC.cmd = 0;
  4512. resultToPlC.cmdParam = 0; //指令参数
  4513. resultToPlC.cmdResult = mesResultFrmWeb;
  4514. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4515. }
  4516. catch (Exception ex)
  4517. {
  4518. string str = ex.StackTrace;
  4519. AddMessage(LogType.Error,
  4520. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4521. str.Length - str.LastIndexOf("\\") - 1));
  4522. CommandFromPLC resultToPlC = new CommandFromPLC();
  4523. resultToPlC.cmd = 0;
  4524. resultToPlC.cmdParam = 0; //指令参数
  4525. resultToPlC.cmdResult = 110;
  4526. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4527. }
  4528. stopwatch1.Stop();
  4529. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  4530. AddMessage(LogType.Info,
  4531. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4532. stopwatch2.ElapsedMilliseconds + "ms");
  4533. ProgressState = false;
  4534. //开始采集螺丝数据
  4535. if (direction == "Left")
  4536. {
  4537. isCollectingFlagLeft = true;
  4538. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  4539. }
  4540. if (direction == "Right")
  4541. {
  4542. isCollectingFlagRight = true;
  4543. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  4544. }
  4545. }
  4546. /// <summary>
  4547. /// [S7] 锁螺丝设备 - 出站
  4548. /// </summary>
  4549. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  4550. string stationCode, string stationName, string direction, out bool ProgressState)
  4551. {
  4552. Stopwatch stopwatch1 = new Stopwatch();
  4553. Stopwatch stopwatch2 = new Stopwatch();
  4554. try
  4555. {
  4556. stopwatch1.Start();
  4557. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  4558. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4559. string processItem = stationName; // 测试项目
  4560. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4561. string supplierCode = ""; // 供应商代码
  4562. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4563. string batch_num = GlobalContext.BatchNumber; // 批次号
  4564. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4565. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4566. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4567. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  4568. string StationId = string.Empty; // 工位ID(可配置)
  4569. if (direction == "Left")
  4570. {
  4571. StationId = GlobalContext.S7_StationId_1;
  4572. }
  4573. if (direction == "Right")
  4574. {
  4575. StationId = GlobalContext.S7_StationId_2;
  4576. }
  4577. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4578. a1Result = 1;
  4579. bool pass = a1Result == 1;
  4580. //根据载具码获取产品码
  4581. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4582. if (string.IsNullOrEmpty(strProductBarcode))
  4583. {
  4584. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4585. }
  4586. sn = strProductBarcode;
  4587. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4588. List<TestItem> items = new List<TestItem>();
  4589. items.Add(new TestItem()
  4590. {
  4591. Parameter_name = "载具码",
  4592. Parameter_value = CarrierBarcode,
  4593. Parameter_unit = ""
  4594. });
  4595. items.Add(new TestItem()
  4596. {
  4597. Parameter_name = "产品码",
  4598. Parameter_value = sn,
  4599. Parameter_unit = ""
  4600. });
  4601. int result1 = 1;
  4602. if (direction == "Right")
  4603. {
  4604. SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4605. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  4606. MachineId, StationId, "");
  4607. }
  4608. //if (direction == "Left")
  4609. //{
  4610. // isCollectingFlagLeft = false;//采集螺丝数据结束
  4611. //}
  4612. //if (direction == "Right")
  4613. //{
  4614. // isCollectingFlagRight = false;//采集螺丝数据结束
  4615. //}
  4616. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4617. stopwatch2.Start();
  4618. //进站结果写入PLC
  4619. CommandFromPLC resultToPlC = new CommandFromPLC();
  4620. resultToPlC.cmd = 0;
  4621. resultToPlC.cmdParam = 0; //指令参数
  4622. resultToPlC.cmdResult = mesResultFrmWeb;
  4623. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4624. stopwatch2.Stop();
  4625. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  4626. //保存PLC返回MES数据到本地
  4627. ResponseMessage message = new ResponseMessage();
  4628. if (direction == "Left")
  4629. {
  4630. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  4631. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  4632. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  4633. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  4634. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  4635. if (message.result == false)
  4636. {
  4637. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  4638. }
  4639. }
  4640. if (direction == "Right")
  4641. {
  4642. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  4643. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  4644. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  4645. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  4646. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  4647. if (message.result == false)
  4648. {
  4649. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  4650. }
  4651. }
  4652. //保存螺丝数据到txt
  4653. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes,
  4654. stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  4655. if (result.Item1 != 0)
  4656. {
  4657. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  4658. }
  4659. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_保存加工数据到本地成功");
  4660. }
  4661. catch (Exception ex)
  4662. {
  4663. stopwatch2.Start();
  4664. CommandFromPLC resultToPlC = new CommandFromPLC();
  4665. resultToPlC.cmd = 0;
  4666. resultToPlC.cmdParam = 0; //指令参数
  4667. resultToPlC.cmdResult = 110;
  4668. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4669. stopwatch2.Stop();
  4670. string str = ex.StackTrace;
  4671. AddMessage(LogType.Error,
  4672. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4673. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4674. }
  4675. stopwatch1.Stop();
  4676. AddMessage(LogType.Info,
  4677. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4678. stopwatch2.ElapsedMilliseconds + "ms");
  4679. ProgressState = false;
  4680. }
  4681. private void S7节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  4682. {
  4683. Stopwatch stopwatch1 = new Stopwatch();
  4684. Stopwatch stopwatch2 = new Stopwatch();
  4685. string resultStr = string.Empty;
  4686. try
  4687. {
  4688. stopwatch1.Start();
  4689. string oEEType = ((int)s1PLCData["a7OEEType"]).ToString(); // 节拍类型(plc写入)
  4690. string a7OEEPartNo = (string)s1PLCData["a7OEEPartNo"]; // 物料码
  4691. a7OEEPartNo = a7OEEPartNo.Replace("\0", "");
  4692. string a7OEEVehicleCode = (string)s1PLCData["a7OEEVehicleCode"]; // 载具SN
  4693. a7OEEVehicleCode = a7OEEVehicleCode.Replace("\0", "");
  4694. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4695. if (!actionBool)
  4696. {
  4697. stopwatch2.Start();
  4698. //写入PLC
  4699. iot_data.beatReturn = 2; //NG
  4700. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4701. stopwatch2.Stop();
  4702. AddMessage(LogType.Info,
  4703. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  4704. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4705. return;
  4706. }
  4707. //作业开始后要有物料和载具信息
  4708. if (string.IsNullOrEmpty(a7OEEPartNo) && string.IsNullOrEmpty(a7OEEVehicleCode) &&
  4709. Convert.ToInt32(oEEType) > 2)
  4710. {
  4711. stopwatch2.Start();
  4712. //写入PLC
  4713. iot_data.beatReturn = 2; //NG
  4714. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4715. stopwatch2.Stop();
  4716. AddMessage_Station(stationNameStr, LogType.Info,
  4717. stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  4718. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4719. return;
  4720. }
  4721. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a7OEEPartNo))
  4722. {
  4723. stopwatch2.Start();
  4724. //写入PLC
  4725. iot_data.beatReturn = 2; //NG
  4726. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4727. stopwatch2.Stop();
  4728. AddMessage_Station(stationNameStr, LogType.Info,
  4729. stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  4730. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4731. return;
  4732. }
  4733. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a7OEEVehicleCode))
  4734. {
  4735. stopwatch2.Start();
  4736. //写入PLC
  4737. iot_data.beatReturn = 2; //NG
  4738. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4739. stopwatch2.Stop();
  4740. AddMessage_Station(stationNameStr, LogType.Info,
  4741. stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  4742. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4743. return;
  4744. }
  4745. short _result = 0;
  4746. // 上传OEE
  4747. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a7OEEPartNo, a7OEEVehicleCode);
  4748. _result = result.Item1;
  4749. resultStr = result.Item2;
  4750. if (_result == 1)
  4751. {
  4752. stopwatch2.Start();
  4753. //写入PLC
  4754. iot_data.beatReturn = 1; //OK
  4755. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4756. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  4757. stopwatch2.Stop();
  4758. }
  4759. else
  4760. {
  4761. stopwatch2.Start();
  4762. //写入PLC
  4763. iot_data.beatReturn = 2; //NG
  4764. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4765. stopwatch2.Stop();
  4766. AddMessage_Station(stationNameStr, LogType.Error,
  4767. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  4768. }
  4769. }
  4770. catch (Exception ex)
  4771. {
  4772. string str = ex.StackTrace;
  4773. AddMessage_Station(stationNameStr, LogType.Error,
  4774. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  4775. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4776. // MES_Flag
  4777. stopwatch2.Start();
  4778. //写入PLC
  4779. iot_data.beatReturn = 2; //NG
  4780. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4781. stopwatch2.Stop();
  4782. }
  4783. stopwatch1.Stop();
  4784. AddMessage(LogType.Info,
  4785. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4786. stopwatch2.ElapsedMilliseconds + "ms");
  4787. }
  4788. #endregion
  4789. #region S8
  4790. private Dictionary<string, object> s8PLCData = new Dictionary<string, object>();
  4791. private Dictionary<string, object> s8PLCSignal_Old = new Dictionary<string, object>();
  4792. /// <summary>
  4793. /// [S8] 3D螺丝高度检测设备
  4794. /// </summary>
  4795. /// <param name="plcNo">PLC编号</param>
  4796. private void ReadStation_S8(int plcNo)
  4797. {
  4798. string stationCode = "[OP80]";
  4799. string stationName = "NG下料";
  4800. string stationNameStr = stationCode + stationName;
  4801. string tagBaseName = "g_OP80_MES"; //标签变量名称
  4802. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4803. string tagAgvCommName = "agvCommFrmPC";
  4804. string tagBarsetName = "BarcodeSet";
  4805. // 触发信号字典
  4806. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4807. s8PLCSignal_Old.Add("a8OEEType", 0); // 节拍类型(plc写入)
  4808. // PLC数据字典 赋值
  4809. s8PLCData.Add("a8OEEType", 0); // 节拍类型(plc写入)
  4810. s8PLCData.Add("a8OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4811. s8PLCData.Add("a8OEEVehicleCode", ""); // 载具SN
  4812. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  4813. (int, string) result;
  4814. while (true)
  4815. {
  4816. try
  4817. {
  4818. if (!GlobalContext._IsCon_Funs1)
  4819. {
  4820. UpdatePLCMonitor(1, plcNo, 0);
  4821. continue;
  4822. }
  4823. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4824. {
  4825. Stopwatch stopwatch1 = new Stopwatch();
  4826. Stopwatch stopwatch2 = new Stopwatch();
  4827. stopwatch1.Start();
  4828. stopwatch2.Start();
  4829. #region 一次性读取所有数据
  4830. // 一次性读取所有数据
  4831. result = FunsEip[plcNo]
  4832. .Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4833. if (result.Item1 != 0)
  4834. {
  4835. //richTextBox1.AppendText("\n" + strRet);
  4836. }
  4837. else
  4838. {
  4839. //richTextBox1.AppendText("\n" + "读取成功");
  4840. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  4841. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  4842. ? XiaomiDeviceState.Unknown
  4843. : (XiaomiDeviceState)xmDeviceStateInt;
  4844. s8PLCData["a8OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  4845. s8PLCData["a8OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  4846. s8PLCData["a8OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  4847. }
  4848. #endregion 一次性读取所有数据
  4849. stopwatch2.Stop();
  4850. #region 进站
  4851. try
  4852. {
  4853. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4854. {
  4855. lock (lockObj)
  4856. {
  4857. if (!ProgressState)
  4858. {
  4859. ProgressState = true;
  4860. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData,
  4861. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  4862. out ProgressState));
  4863. }
  4864. }
  4865. }
  4866. }
  4867. catch (Exception ex)
  4868. {
  4869. ProgressState = false;
  4870. string str = ex.StackTrace;
  4871. AddMessage_Station(stationNameStr, LogType.Error,
  4872. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4873. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4874. }
  4875. #endregion 进站
  4876. #region 出站
  4877. try
  4878. {
  4879. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4880. {
  4881. lock (lockObj)
  4882. {
  4883. if (!ProgressState)
  4884. {
  4885. ProgressState = true;
  4886. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData,
  4887. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4888. out ProgressState));
  4889. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4890. }
  4891. }
  4892. }
  4893. }
  4894. catch (Exception ex)
  4895. {
  4896. ProgressState = false;
  4897. string str = ex.StackTrace;
  4898. AddMessage_Station(stationNameStr, LogType.Error,
  4899. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4900. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4901. }
  4902. #endregion 出站
  4903. #region 节拍接口
  4904. try
  4905. {
  4906. int a80EEType = (int)s9PLCData["a80EEType"];
  4907. int a80EETypeGOld = (int)s9PLCSignal_Old["a80EEType"];
  4908. //若设备紧急复原后节拍重置
  4909. if (a80EEType == 1)
  4910. {
  4911. a80EETypeGOld = 0;
  4912. }
  4913. if (a80EEType != a80EETypeGOld)
  4914. {
  4915. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  4916. if ((a80EETypeGOld == 1 && a80EEType != 2) || (a80EETypeGOld == 3 && a80EEType != 4) ||
  4917. (a80EETypeGOld == 5 && a80EEType != 6))
  4918. {
  4919. //写入PLC
  4920. stPLC_MesData.iotData.beatReturn = 2; //NG
  4921. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  4922. AddMessage(LogType.Info,
  4923. stationNameStr +
  4924. $"_节拍接口-- 设备本次上传节拍[{a80EEType}],未上传节拍[{a80EETypeGOld}]的结束信号,请检查;总用时" +
  4925. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  4926. "ms");
  4927. return;
  4928. }
  4929. else
  4930. {
  4931. Task.Run(() =>
  4932. S8节拍接口(plcNo, stationNameStr, tagBaseName,
  4933. stPLC_MesData.iotData)); // MreTasks[4].Set();
  4934. }
  4935. s8PLCSignal_Old["a80EEType"] = s8PLCData["a80EEType"];
  4936. }
  4937. }
  4938. catch (Exception ex)
  4939. {
  4940. string str = ex.StackTrace;
  4941. AddMessage_Station(stationNameStr, LogType.Error,
  4942. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4943. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4944. }
  4945. #endregion
  4946. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4947. stopwatch1.Stop();
  4948. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4949. }
  4950. else
  4951. {
  4952. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4953. AddMessage_Station(stationNameStr, LogType.Info,
  4954. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4955. FunsEip[plcNo].Connect(); // 重连
  4956. }
  4957. }
  4958. catch (Exception ex)
  4959. {
  4960. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4961. AddMessage_Station(stationNameStr, LogType.Error,
  4962. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4963. }
  4964. Thread.Sleep(IntervalReadPLC);
  4965. }
  4966. }
  4967. /// <summary>
  4968. /// [S8] 3D螺丝高度检测设备 - 进站
  4969. /// </summary>
  4970. /// <param name="plcNo">PLC编号</param>
  4971. /// <param name="stationNameStr">工站全称</param>
  4972. /// <param name="stPLC_MesData"></param>
  4973. /// <param name="tagMesCommName"></param>
  4974. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  4975. string tagBarsetName, out bool ProgressState)
  4976. {
  4977. Stopwatch stopwatch1 = new Stopwatch();
  4978. Stopwatch stopwatch2 = new Stopwatch();
  4979. try
  4980. {
  4981. stopwatch1.Start();
  4982. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4983. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4984. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  4985. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  4986. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4987. //载具码验证产品码
  4988. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4989. if (string.IsNullOrEmpty(strProductBarcode))
  4990. {
  4991. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4992. }
  4993. sn = strProductBarcode;
  4994. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4995. // 产品SN(物料码)校验
  4996. List<TestItem> item = new List<TestItem>();
  4997. stopwatch2.Start();
  4998. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  4999. item, MachineId, StationId);
  5000. stopwatch2.Stop();
  5001. //指令执行结果 1:OK 110:失败
  5002. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5003. //进站结果写入PLC
  5004. CommandFromPLC resultToPlC = new CommandFromPLC();
  5005. resultToPlC.cmd = 0;
  5006. resultToPlC.cmdParam = 0; //指令参数
  5007. resultToPlC.cmdResult = mesResultFrmWeb;
  5008. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5009. }
  5010. catch (Exception ex)
  5011. {
  5012. string str = ex.StackTrace;
  5013. AddMessage(LogType.Error,
  5014. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  5015. str.Length - str.LastIndexOf("\\") - 1));
  5016. CommandFromPLC resultToPlC = new CommandFromPLC();
  5017. resultToPlC.cmd = 0;
  5018. resultToPlC.cmdParam = 0; //指令参数
  5019. resultToPlC.cmdResult = 110;
  5020. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5021. }
  5022. stopwatch1.Stop();
  5023. AddMessage(LogType.Info,
  5024. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5025. stopwatch2.ElapsedMilliseconds + "ms");
  5026. ProgressState = false;
  5027. }
  5028. /// <summary>
  5029. /// [S8] 3D螺丝高度检测设备 - 出站接口
  5030. /// </summary>
  5031. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  5032. string stationCode, string stationName, out bool ProgressState)
  5033. {
  5034. Stopwatch stopwatch1 = new Stopwatch();
  5035. Stopwatch stopwatch2 = new Stopwatch();
  5036. try
  5037. {
  5038. stopwatch1.Start();
  5039. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  5040. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5041. string processItem = stationName; // 测试项目
  5042. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5043. string supplierCode = ""; // 供应商代码
  5044. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5045. string batch_num = GlobalContext.BatchNumber; // 批次号
  5046. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5047. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5048. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5049. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  5050. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  5051. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5052. bool pass = a1Result == 1;
  5053. //根据载具码获取产品码
  5054. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5055. if (string.IsNullOrEmpty(strProductBarcode))
  5056. {
  5057. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  5058. }
  5059. sn = strProductBarcode;
  5060. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  5061. List<TestItem> items = new List<TestItem>();
  5062. items.Add(new TestItem()
  5063. {
  5064. Parameter_name = "载具码",
  5065. Parameter_value = CarrierBarcode,
  5066. Parameter_unit = ""
  5067. });
  5068. items.Add(new TestItem()
  5069. {
  5070. Parameter_name = "产品码",
  5071. Parameter_value = sn,
  5072. Parameter_unit = ""
  5073. });
  5074. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  5075. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  5076. MachineId, StationId, "");
  5077. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5078. stopwatch2.Start();
  5079. //进站结果写入PLC
  5080. CommandFromPLC resultToPlC = new CommandFromPLC();
  5081. resultToPlC.cmd = 0;
  5082. resultToPlC.cmdParam = 0; //指令参数
  5083. resultToPlC.cmdResult = mesResultFrmWeb;
  5084. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5085. stopwatch2.Stop();
  5086. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  5087. //保存PLC返回MES数据到本地
  5088. ResponseMessage message = new ResponseMessage();
  5089. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  5090. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  5091. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  5092. if (message.result == false)
  5093. {
  5094. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  5095. }
  5096. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  5097. }
  5098. catch (Exception ex)
  5099. {
  5100. stopwatch2.Start();
  5101. CommandFromPLC resultToPlC = new CommandFromPLC();
  5102. resultToPlC.cmd = 0;
  5103. resultToPlC.cmdParam = 0; //指令参数
  5104. resultToPlC.cmdResult = 110;
  5105. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5106. stopwatch2.Stop();
  5107. string str = ex.StackTrace;
  5108. AddMessage(LogType.Error,
  5109. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5110. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5111. }
  5112. stopwatch1.Stop();
  5113. AddMessage(LogType.Info,
  5114. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5115. stopwatch2.ElapsedMilliseconds + "ms");
  5116. ProgressState = false;
  5117. }
  5118. private void S8节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  5119. {
  5120. Stopwatch stopwatch1 = new Stopwatch();
  5121. Stopwatch stopwatch2 = new Stopwatch();
  5122. string resultStr = string.Empty;
  5123. try
  5124. {
  5125. stopwatch1.Start();
  5126. string oEEType = ((int)s1PLCData["a8OEEType"]).ToString(); // 节拍类型(plc写入)
  5127. string a80EEPartNo = (string)s1PLCData["a80EEPartNo"]; // 物料码
  5128. a80EEPartNo = a80EEPartNo.Replace("\0", "");
  5129. string a80EEVehicleCode = (string)s1PLCData["a80EEVehicleCode"]; // 载具SN
  5130. a80EEVehicleCode = a80EEVehicleCode.Replace("\0", "");
  5131. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5132. if (!actionBool)
  5133. {
  5134. stopwatch2.Start();
  5135. //写入PLC
  5136. iot_data.beatReturn = 2; //NG
  5137. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5138. stopwatch2.Stop();
  5139. AddMessage(LogType.Info,
  5140. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  5141. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5142. return;
  5143. }
  5144. //作业开始后要有物料和载具信息
  5145. if (string.IsNullOrEmpty(a80EEPartNo) && string.IsNullOrEmpty(a80EEVehicleCode) &&
  5146. Convert.ToInt32(oEEType) > 2)
  5147. {
  5148. stopwatch2.Start();
  5149. //写入PLC
  5150. iot_data.beatReturn = 2; //NG
  5151. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5152. stopwatch2.Stop();
  5153. AddMessage_Station(stationNameStr, LogType.Info,
  5154. stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  5155. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5156. return;
  5157. }
  5158. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a80EEPartNo))
  5159. {
  5160. stopwatch2.Start();
  5161. //写入PLC
  5162. iot_data.beatReturn = 2; //NG
  5163. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5164. stopwatch2.Stop();
  5165. AddMessage_Station(stationNameStr, LogType.Info,
  5166. stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  5167. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5168. return;
  5169. }
  5170. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a80EEVehicleCode))
  5171. {
  5172. stopwatch2.Start();
  5173. //写入PLC
  5174. iot_data.beatReturn = 2; //NG
  5175. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5176. stopwatch2.Stop();
  5177. AddMessage_Station(stationNameStr, LogType.Info,
  5178. stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  5179. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5180. return;
  5181. }
  5182. short _result = 0;
  5183. // 上传OEE
  5184. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a80EEPartNo, a80EEVehicleCode);
  5185. _result = result.Item1;
  5186. resultStr = result.Item2;
  5187. if (_result == 1)
  5188. {
  5189. stopwatch2.Start();
  5190. //写入PLC
  5191. iot_data.beatReturn = 1; //OK
  5192. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5193. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  5194. stopwatch2.Stop();
  5195. }
  5196. else
  5197. {
  5198. stopwatch2.Start();
  5199. //写入PLC
  5200. iot_data.beatReturn = 2; //NG
  5201. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5202. stopwatch2.Stop();
  5203. AddMessage_Station(stationNameStr, LogType.Error,
  5204. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  5205. }
  5206. }
  5207. catch (Exception ex)
  5208. {
  5209. string str = ex.StackTrace;
  5210. AddMessage_Station(stationNameStr, LogType.Error,
  5211. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  5212. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5213. // MES_Flag
  5214. stopwatch2.Start();
  5215. //写入PLC
  5216. iot_data.beatReturn = 2; //NG
  5217. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5218. stopwatch2.Stop();
  5219. }
  5220. stopwatch1.Stop();
  5221. AddMessage(LogType.Info,
  5222. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5223. stopwatch2.ElapsedMilliseconds + "ms");
  5224. }
  5225. #endregion
  5226. #region S9
  5227. private Dictionary<string, object> s9PLCData = new Dictionary<string, object>();
  5228. private Dictionary<string, object> s9PLCSignal_Old = new Dictionary<string, object>();
  5229. /// <summary>
  5230. /// [S9] 下料设备
  5231. /// </summary>
  5232. /// <param name="plcNo">PLC编号</param>
  5233. private void ReadStation_S9(int plcNo)
  5234. {
  5235. string stationCode = "[OP90]";
  5236. string stationName = "半成品下料";
  5237. string stationNameStr = stationCode + stationName;
  5238. string tagBaseName = "g_OP90_MES"; //标签变量名称
  5239. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5240. string tagAgvCommName = "agvCommFrmPC";
  5241. string tagBarsetName = "BarcodeSet";
  5242. // 触发信号字典
  5243. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5244. s9PLCSignal_Old.Add("a9OEEType", 0); // 节拍类型(plc写入)
  5245. // PLC数据字典 赋值
  5246. s9PLCData.Add("a9OEEType", 0); // 节拍类型(plc写入)
  5247. s9PLCData.Add("a9OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  5248. s9PLCData.Add("a9OEEVehicleCode", ""); // 载具SN
  5249. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  5250. (int, string) result;
  5251. while (true)
  5252. {
  5253. try
  5254. {
  5255. if (!GlobalContext._IsCon_Funs1)
  5256. {
  5257. UpdatePLCMonitor(1, plcNo, 0);
  5258. continue;
  5259. }
  5260. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5261. {
  5262. Stopwatch stopwatch1 = new Stopwatch();
  5263. Stopwatch stopwatch2 = new Stopwatch();
  5264. stopwatch1.Start();
  5265. stopwatch2.Start();
  5266. #region 一次性读取所有数据
  5267. // 一次性读取所有数据
  5268. result = FunsEip[plcNo]
  5269. .Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  5270. if (result.Item1 != 0)
  5271. {
  5272. //richTextBox1.AppendText("\n" + strRet);
  5273. }
  5274. else
  5275. {
  5276. //richTextBox1.AppendText("\n" + "读取成功");
  5277. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  5278. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  5279. ? XiaomiDeviceState.Unknown
  5280. : (XiaomiDeviceState)xmDeviceStateInt;
  5281. s9PLCData["a9OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  5282. s9PLCData["a9OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  5283. s9PLCData["a9OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  5284. }
  5285. #endregion 一次性读取所有数据
  5286. stopwatch2.Stop();
  5287. #region 进站
  5288. try
  5289. {
  5290. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5291. {
  5292. lock (lockObj)
  5293. {
  5294. if (!ProgressState)
  5295. {
  5296. ProgressState = true;
  5297. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData,
  5298. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  5299. out ProgressState));
  5300. }
  5301. }
  5302. }
  5303. }
  5304. catch (Exception ex)
  5305. {
  5306. ProgressState = false;
  5307. string str = ex.StackTrace;
  5308. AddMessage_Station(stationNameStr, LogType.Error,
  5309. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5310. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5311. }
  5312. #endregion 进站
  5313. #region 出站
  5314. try
  5315. {
  5316. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5317. {
  5318. lock (lockObj)
  5319. {
  5320. if (!ProgressState)
  5321. {
  5322. ProgressState = true;
  5323. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData,
  5324. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  5325. out ProgressState));
  5326. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  5327. }
  5328. }
  5329. }
  5330. }
  5331. catch (Exception ex)
  5332. {
  5333. ProgressState = false;
  5334. string str = ex.StackTrace;
  5335. AddMessage_Station(stationNameStr, LogType.Error,
  5336. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5337. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5338. }
  5339. #endregion 出站
  5340. #region 节拍接口
  5341. try
  5342. {
  5343. int a90EEType = (int)s9PLCData["a90EEType"];
  5344. int a90EETypeGOld = (int)s9PLCSignal_Old["a90EEType"];
  5345. //若设备紧急复原后节拍重置
  5346. if (a90EEType == 1)
  5347. {
  5348. a90EETypeGOld = 0;
  5349. }
  5350. if (a90EEType != a90EETypeGOld)
  5351. {
  5352. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  5353. if ((a90EETypeGOld == 1 && a90EEType != 2) || (a90EETypeGOld == 3 && a90EEType != 4) ||
  5354. (a90EETypeGOld == 5 && a90EEType != 6))
  5355. {
  5356. //写入PLC
  5357. stPLC_MesData.iotData.beatReturn = 2; //NG
  5358. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  5359. AddMessage(LogType.Info,
  5360. stationNameStr +
  5361. $"_节拍接口-- 设备本次上传节拍[{a90EEType}],未上传节拍[{a90EETypeGOld}]的结束信号,请检查;总用时" +
  5362. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  5363. "ms");
  5364. return;
  5365. }
  5366. else
  5367. {
  5368. Task.Run(() =>
  5369. S9节拍接口(plcNo, stationNameStr, tagBaseName,
  5370. stPLC_MesData.iotData)); // MreTasks[4].Set();
  5371. }
  5372. s9PLCSignal_Old["a90EEType"] = s9PLCData["a90EEType"];
  5373. }
  5374. }
  5375. catch (Exception ex)
  5376. {
  5377. string str = ex.StackTrace;
  5378. AddMessage_Station(stationNameStr, LogType.Error,
  5379. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  5380. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5381. }
  5382. #endregion
  5383. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5384. stopwatch1.Stop();
  5385. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5386. }
  5387. else
  5388. {
  5389. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5390. AddMessage_Station(stationNameStr, LogType.Info,
  5391. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5392. FunsEip[plcNo].Connect(); // 重连
  5393. }
  5394. }
  5395. catch (Exception ex)
  5396. {
  5397. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5398. AddMessage_Station(stationNameStr, LogType.Error,
  5399. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5400. }
  5401. Thread.Sleep(IntervalReadPLC);
  5402. }
  5403. }
  5404. /// <summary>
  5405. /// [S9] 下料设备 - 进站
  5406. /// </summary>
  5407. /// <param name="plcNo">PLC编号</param>
  5408. /// <param name="stationNameStr">工站全称</param>
  5409. /// <param name="stPLC_MesData"></param>
  5410. /// <param name="tagMesCommName"></param>
  5411. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  5412. string tagBarsetName, out bool ProgressState)
  5413. {
  5414. Stopwatch stopwatch1 = new Stopwatch();
  5415. Stopwatch stopwatch2 = new Stopwatch();
  5416. try
  5417. {
  5418. stopwatch1.Start();
  5419. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  5420. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5421. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  5422. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  5423. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  5424. //载具码验证产品码
  5425. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  5426. if (string.IsNullOrEmpty(strProductBarcode))
  5427. {
  5428. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  5429. }
  5430. sn = strProductBarcode;
  5431. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5432. // 产品SN(物料码)校验
  5433. List<TestItem> item = new List<TestItem>();
  5434. stopwatch2.Start();
  5435. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  5436. item, MachineId, StationId);
  5437. stopwatch2.Stop();
  5438. //指令执行结果 1:OK 110:失败
  5439. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5440. //进站结果写入PLC
  5441. CommandFromPLC resultToPlC = new CommandFromPLC();
  5442. resultToPlC.cmd = 0;
  5443. resultToPlC.cmdParam = 0; //指令参数
  5444. resultToPlC.cmdResult = mesResultFrmWeb;
  5445. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5446. }
  5447. catch (Exception ex)
  5448. {
  5449. string str = ex.StackTrace;
  5450. AddMessage(LogType.Error,
  5451. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  5452. str.Length - str.LastIndexOf("\\") - 1));
  5453. CommandFromPLC resultToPlC = new CommandFromPLC();
  5454. resultToPlC.cmd = 0;
  5455. resultToPlC.cmdParam = 0; //指令参数
  5456. resultToPlC.cmdResult = 110;
  5457. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5458. }
  5459. stopwatch1.Stop();
  5460. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  5461. AddMessage(LogType.Info,
  5462. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5463. stopwatch2.ElapsedMilliseconds + "ms");
  5464. ProgressState = false;
  5465. }
  5466. /// <summary>
  5467. /// [S9] 下料设备 - 出站接口
  5468. /// </summary>
  5469. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  5470. string stationCode, string stationName, out bool ProgressState)
  5471. {
  5472. Stopwatch stopwatch1 = new Stopwatch();
  5473. Stopwatch stopwatch2 = new Stopwatch();
  5474. try
  5475. {
  5476. stopwatch1.Start();
  5477. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  5478. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5479. string processItem = stationName; // 测试项目
  5480. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5481. string supplierCode = ""; // 供应商代码
  5482. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5483. string batch_num = GlobalContext.BatchNumber; // 批次号
  5484. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5485. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5486. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5487. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  5488. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  5489. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5490. bool pass = a1Result == 1;
  5491. //根据载具码获取产品码
  5492. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5493. if (string.IsNullOrEmpty(strProductBarcode))
  5494. {
  5495. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  5496. }
  5497. sn = strProductBarcode;
  5498. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  5499. List<TestItem> items = new List<TestItem>();
  5500. items.Add(new TestItem()
  5501. {
  5502. Parameter_name = "载具码",
  5503. Parameter_value = CarrierBarcode,
  5504. Parameter_unit = ""
  5505. });
  5506. items.Add(new TestItem()
  5507. {
  5508. Parameter_name = "产品码",
  5509. Parameter_value = sn,
  5510. Parameter_unit = ""
  5511. });
  5512. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  5513. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  5514. MachineId, StationId, "");
  5515. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5516. stopwatch2.Start();
  5517. //进站结果写入PLC
  5518. CommandFromPLC resultToPlC = new CommandFromPLC();
  5519. resultToPlC.cmd = 0;
  5520. resultToPlC.cmdParam = 0; //指令参数
  5521. resultToPlC.cmdResult = mesResultFrmWeb;
  5522. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5523. stopwatch2.Stop();
  5524. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  5525. //保存PLC返回MES数据到本地
  5526. ResponseMessage message = new ResponseMessage();
  5527. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  5528. stPLC_MesData.mesData.nRemainCount);
  5529. if (message.result == false)
  5530. {
  5531. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  5532. }
  5533. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  5534. if (result1 == 1)
  5535. {
  5536. //载具码解除绑定
  5537. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  5538. if (message.result == false)
  5539. {
  5540. AddMessage(LogType.Error, message.text);
  5541. }
  5542. }
  5543. }
  5544. catch (Exception ex)
  5545. {
  5546. stopwatch2.Start();
  5547. CommandFromPLC resultToPlC = new CommandFromPLC();
  5548. resultToPlC.cmd = 0;
  5549. resultToPlC.cmdParam = 0; //指令参数
  5550. resultToPlC.cmdResult = 110;
  5551. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5552. stopwatch2.Stop();
  5553. string str = ex.StackTrace;
  5554. AddMessage(LogType.Error,
  5555. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5556. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5557. }
  5558. stopwatch1.Stop();
  5559. AddMessage(LogType.Info,
  5560. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5561. stopwatch2.ElapsedMilliseconds + "ms");
  5562. ProgressState = false;
  5563. }
  5564. private void S9节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  5565. {
  5566. Stopwatch stopwatch1 = new Stopwatch();
  5567. Stopwatch stopwatch2 = new Stopwatch();
  5568. string resultStr = string.Empty;
  5569. try
  5570. {
  5571. stopwatch1.Start();
  5572. string oEEType = ((int)s1PLCData["a9OEEType"]).ToString(); // 节拍类型(plc写入)
  5573. string a90EEPartNo = (string)s1PLCData["a90EEPartNo"]; // 物料码
  5574. a90EEPartNo = a90EEPartNo.Replace("\0", "");
  5575. string a90EEVehicleCode = (string)s1PLCData["a90EEVehicleCode"]; // 载具SN
  5576. a90EEVehicleCode = a90EEVehicleCode.Replace("\0", "");
  5577. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5578. if (!actionBool)
  5579. {
  5580. stopwatch2.Start();
  5581. //写入PLC
  5582. iot_data.beatReturn = 2; //NG
  5583. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5584. stopwatch2.Stop();
  5585. AddMessage(LogType.Info,
  5586. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  5587. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5588. return;
  5589. }
  5590. //作业开始后要有物料和载具信息
  5591. if (string.IsNullOrEmpty(a90EEPartNo) && string.IsNullOrEmpty(a90EEVehicleCode) &&
  5592. Convert.ToInt32(oEEType) > 2)
  5593. {
  5594. stopwatch2.Start();
  5595. //写入PLC
  5596. iot_data.beatReturn = 2; //NG
  5597. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5598. stopwatch2.Stop();
  5599. AddMessage_Station(stationNameStr, LogType.Info,
  5600. stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  5601. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5602. return;
  5603. }
  5604. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a90EEPartNo))
  5605. {
  5606. stopwatch2.Start();
  5607. //写入PLC
  5608. iot_data.beatReturn = 2; //NG
  5609. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5610. stopwatch2.Stop();
  5611. AddMessage_Station(stationNameStr, LogType.Info,
  5612. stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  5613. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5614. return;
  5615. }
  5616. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a90EEVehicleCode))
  5617. {
  5618. stopwatch2.Start();
  5619. //写入PLC
  5620. iot_data.beatReturn = 2; //NG
  5621. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5622. stopwatch2.Stop();
  5623. AddMessage_Station(stationNameStr, LogType.Info,
  5624. stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  5625. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5626. return;
  5627. }
  5628. short _result = 0;
  5629. // 上传OEE
  5630. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a90EEPartNo, a90EEVehicleCode);
  5631. _result = result.Item1;
  5632. resultStr = result.Item2;
  5633. if (_result == 1)
  5634. {
  5635. stopwatch2.Start();
  5636. //写入PLC
  5637. iot_data.beatReturn = 1; //OK
  5638. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5639. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  5640. stopwatch2.Stop();
  5641. }
  5642. else
  5643. {
  5644. stopwatch2.Start();
  5645. //写入PLC
  5646. iot_data.beatReturn = 2; //NG
  5647. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5648. stopwatch2.Stop();
  5649. AddMessage_Station(stationNameStr, LogType.Error,
  5650. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  5651. }
  5652. }
  5653. catch (Exception ex)
  5654. {
  5655. string str = ex.StackTrace;
  5656. AddMessage_Station(stationNameStr, LogType.Error,
  5657. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  5658. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5659. // MES_Flag
  5660. stopwatch2.Start();
  5661. //写入PLC
  5662. iot_data.beatReturn = 2; //NG
  5663. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5664. stopwatch2.Stop();
  5665. }
  5666. stopwatch1.Stop();
  5667. AddMessage(LogType.Info,
  5668. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5669. stopwatch2.ElapsedMilliseconds + "ms");
  5670. }
  5671. #endregion
  5672. #endregion Xiaomi
  5673. #region PLC1 张超凡
  5674. #region [S1] Tray盘上料装备(板测)
  5675. /// <summary>
  5676. /// S1工位的数据- 触发信号上次的值
  5677. /// </summary>
  5678. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  5679. /// <summary>
  5680. /// S1工位的数据(含触发信号)
  5681. /// </summary>
  5682. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  5683. /// <summary>
  5684. /// S1工位的数据- 回写点位
  5685. /// </summary>
  5686. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5687. ///// <summary>
  5688. ///// 触发信号
  5689. ///// </summary>
  5690. //private ManualResetEvent[] MreTasks;
  5691. /// <summary>
  5692. /// [S1] Tray盘上料装备(板测)
  5693. /// </summary>
  5694. /// <param name="plcNo">PLC编号</param>
  5695. //private void ReadStation_S1(int plcNo)
  5696. //{
  5697. // // [S1] Tray盘上料装备
  5698. // // [S2] FCT
  5699. // // [S3] 值板机
  5700. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5701. // // [S5] Tray盘下料装备
  5702. // string stationCode = "[S1]";
  5703. // string stationName = "Tray盘上料装备";
  5704. // string stationNameStr = stationCode + stationName;
  5705. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  5706. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  5707. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  5708. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  5709. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5710. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  5711. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5712. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  5713. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  5714. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  5715. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  5716. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  5717. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  5718. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  5719. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  5720. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  5721. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  5722. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  5723. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5724. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  5725. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  5726. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  5727. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  5728. // s1PLCData.Add("a1Result", 0); // 产品结果
  5729. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  5730. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  5731. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  5732. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  5733. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  5734. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5735. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  5736. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  5737. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  5738. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  5739. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  5740. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  5741. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  5742. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  5743. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  5744. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  5745. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  5746. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  5747. // while (IsRun)
  5748. // {
  5749. // try
  5750. // {
  5751. // if (!GlobalContext._IsCon_Funs1)
  5752. // {
  5753. // UpdatePLCMonitor(1, plcNo, 0);
  5754. // continue;
  5755. // }
  5756. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5757. // {
  5758. // Stopwatch stopwatch1 = new Stopwatch();
  5759. // Stopwatch stopwatch2 = new Stopwatch();
  5760. // stopwatch1.Start();
  5761. // stopwatch2.Start();
  5762. // #region 一次性读取所有数据
  5763. // // 一次性读取所有数据
  5764. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  5765. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  5766. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  5767. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  5768. // int[] datas = data1.Concat(data2).ToArray();
  5769. // datas = datas.Concat(data3).ToArray();
  5770. // datas = datas.Concat(data4).ToArray();
  5771. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  5772. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  5773. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  5774. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  5775. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  5776. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  5777. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  5778. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  5779. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  5780. // s1PLCData["a1MES_FLAG"] = datas[109];
  5781. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  5782. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  5783. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  5784. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  5785. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  5786. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  5787. // s1PLCData["a1Result"] = datas[170];
  5788. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  5789. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  5790. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  5791. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  5792. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  5793. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  5794. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  5795. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  5796. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  5797. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  5798. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  5799. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  5800. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  5801. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  5802. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  5803. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  5804. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  5805. // s1PLCData["a1AGVUpStart"] = datas[308];
  5806. // s1PLCData["a1AGVUpEnd"] = datas[309];
  5807. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  5808. // s1PLCData["a1AGVDownStart"] = datas[321];
  5809. // s1PLCData["a1AGVDownEnd"] = datas[322];
  5810. // #endregion 一次性读取所有数据
  5811. // stopwatch2.Stop();
  5812. // #region 回写操作,写后清空flag
  5813. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  5814. // #endregion 回写操作,写后清空flag
  5815. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  5816. // try
  5817. // {
  5818. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  5819. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  5820. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  5821. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  5822. // {
  5823. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  5824. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  5825. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  5826. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5827. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  5828. // }
  5829. // }
  5830. // catch (Exception ex)
  5831. // {
  5832. // // 6代表上位机报警
  5833. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  5834. // string str = ex.StackTrace;
  5835. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5836. // }
  5837. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  5838. // #region 上料进站校验
  5839. // try
  5840. // {
  5841. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  5842. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  5843. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  5844. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  5845. // {
  5846. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  5847. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5848. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  5849. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  5850. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  5851. // }
  5852. // }
  5853. // catch (Exception ex)
  5854. // {
  5855. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5856. // string str = ex.StackTrace;
  5857. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5858. // }
  5859. // #endregion 上料进站校验
  5860. // #region Tray盘上料装备-出站接口
  5861. // try
  5862. // {
  5863. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  5864. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  5865. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  5866. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  5867. // {
  5868. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  5869. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5870. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  5871. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  5872. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  5873. // }
  5874. // }
  5875. // catch (Exception ex)
  5876. // {
  5877. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  5878. // string str = ex.StackTrace;
  5879. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5880. // }
  5881. // #endregion Tray盘上料装备-出站接口
  5882. // #region Tray盘上料装备-将SN发给ICT标机
  5883. // try
  5884. // {
  5885. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  5886. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  5887. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  5888. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  5889. // {
  5890. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  5891. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  5892. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  5893. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  5894. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  5895. // }
  5896. // }
  5897. // catch (Exception ex)
  5898. // {
  5899. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  5900. // string str = ex.StackTrace;
  5901. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5902. // }
  5903. // #endregion Tray盘上料装备-将SN发给ICT标机
  5904. // #region Tray盘上料装备-点检数据
  5905. // //try
  5906. // //{
  5907. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  5908. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  5909. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  5910. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  5911. // // if (pLC_Flag && !mES_Flag) // 1 0
  5912. // // {
  5913. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  5914. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  5915. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  5916. // // }
  5917. // // else if (!pLC_Flag && mES_Flag) // 0 1
  5918. // // {
  5919. // // // 清空写给PLC的数据
  5920. // // // MES_Flag重置为0
  5921. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  5922. // // }
  5923. // //}
  5924. // //catch (Exception ex)
  5925. // //{
  5926. // // // MES_Flag 为2上位机报错
  5927. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  5928. // // string str = ex.StackTrace;
  5929. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5930. // //}
  5931. // #endregion Tray盘上料装备-点检数据
  5932. // #region 节拍接口
  5933. // try
  5934. // {
  5935. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  5936. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  5937. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  5938. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  5939. // {
  5940. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  5941. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5942. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  5943. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  5944. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  5945. // }
  5946. // }
  5947. // catch (Exception ex)
  5948. // {
  5949. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  5950. // string str = ex.StackTrace;
  5951. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5952. // }
  5953. // #endregion 节拍接口
  5954. // #region AGV上料
  5955. // // AGV上料叫AGV信号
  5956. // try
  5957. // {
  5958. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  5959. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  5960. // if (a1AGVUpCall != a1AGVUpCallOld)
  5961. // {
  5962. // if (a1AGVUpCall == 1) // 0->1
  5963. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  5964. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  5965. // }
  5966. // }
  5967. // catch (Exception ex)
  5968. // {
  5969. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  5970. // string str = ex.StackTrace;
  5971. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5972. // }
  5973. // // AGV上料完成信号
  5974. // try
  5975. // {
  5976. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  5977. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  5978. // if (a1AGVUpEnd != a1AGVUpEndOld)
  5979. // {
  5980. // if (a1AGVUpEnd == 1) // 0->1
  5981. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  5982. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  5983. // }
  5984. // }
  5985. // catch (Exception ex)
  5986. // {
  5987. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  5988. // string str = ex.StackTrace;
  5989. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5990. // }
  5991. // #endregion AGV上料
  5992. // #region AGV下料
  5993. // // AGV下料叫agv信号
  5994. // try
  5995. // {
  5996. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  5997. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  5998. // if (a1AGVDownCall != a1AGVDownCallOld)
  5999. // {
  6000. // if (a1AGVDownCall == 1) // 0->1
  6001. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  6002. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  6003. // }
  6004. // }
  6005. // catch (Exception ex)
  6006. // {
  6007. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  6008. // string str = ex.StackTrace;
  6009. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6010. // }
  6011. // // AGV下料完成信号
  6012. // try
  6013. // {
  6014. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  6015. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  6016. // if (a1AGVDownEnd != a1AGVDownEndOld)
  6017. // {
  6018. // if (a1AGVDownEnd == 1) // 0->1
  6019. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  6020. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  6021. // }
  6022. // }
  6023. // catch (Exception ex)
  6024. // {
  6025. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  6026. // string str = ex.StackTrace;
  6027. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6028. // }
  6029. // #endregion AGV下料
  6030. // #region 心跳
  6031. // try
  6032. // {
  6033. // short states = 0;
  6034. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  6035. // }
  6036. // catch (Exception ex)
  6037. // {
  6038. // string str = ex.StackTrace;
  6039. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6040. // }
  6041. // #endregion 心跳
  6042. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6043. // stopwatch1.Stop();
  6044. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  6045. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6046. // }
  6047. // else
  6048. // {
  6049. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6050. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6051. // Funs[plcNo].Connect(); // 重连
  6052. // }
  6053. // }
  6054. // catch (Exception ex)
  6055. // {
  6056. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6057. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6058. // Funs[plcNo].ReConnect();
  6059. // }
  6060. // Thread.Sleep(IntervalReadPLC);
  6061. // }
  6062. //}
  6063. /// <summary>
  6064. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  6065. /// </summary>
  6066. /// <param name="plcNo">PLC编号</param>
  6067. /// <param name="stationNameStr">工站全称</param>
  6068. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  6069. {
  6070. Stopwatch stopwatch1 = new Stopwatch();
  6071. Stopwatch stopwatch2 = new Stopwatch();
  6072. try
  6073. {
  6074. stopwatch1.Start();
  6075. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  6076. sn = sn.Replace("\0", "");
  6077. #region 查询载具上的产品信息
  6078. string cavityData = string.Empty;
  6079. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6080. if (string.IsNullOrEmpty(cavityData))
  6081. cavityData = "";
  6082. if (snResult != 0)
  6083. {
  6084. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6085. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  6086. writeToPLC_Flag1.Adress = 2003;
  6087. writeToPLC_Flag1.Value = (short)6;
  6088. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  6089. stopwatch1.Stop();
  6090. AddMessage(LogType.Info,
  6091. stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  6092. "ms");
  6093. return;
  6094. }
  6095. #endregion 查询载具上的产品信息
  6096. string[] cavitySNs = cavityData.Split('.');
  6097. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  6098. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  6099. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  6100. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  6101. if (cavitySNs != null && cavitySNs.Length >= 2)
  6102. {
  6103. a1CavitySN1_VehicleStates = cavitySNs[0];
  6104. a1CavitySN2_VehicleStates = cavitySNs[1];
  6105. a1CavityResult1_VehicleStates = 2;
  6106. a1CavityResult2_VehicleStates = 2;
  6107. }
  6108. if (a1CavitySN1_VehicleStates == "假产品")
  6109. a1CavityResult1_VehicleStates = 3;
  6110. if (a1CavitySN2_VehicleStates == "假产品")
  6111. a1CavityResult2_VehicleStates = 3;
  6112. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6113. // 回写
  6114. stopwatch2.Start();
  6115. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  6116. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  6117. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  6118. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  6119. //// MES_Flag
  6120. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  6121. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6122. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  6123. writeToPLC_Flag.Adress = 2003;
  6124. writeToPLC_Flag.Value = mES_Flag;
  6125. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  6126. {
  6127. Name = "a1CavitySN1_VehicleStates",
  6128. Adress = 2024,
  6129. ValueType = PLCValueType.String,
  6130. ValueTypeStrLength = 20,
  6131. Value = a1CavitySN1_VehicleStates
  6132. });
  6133. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  6134. {
  6135. Name = "a1CavitySN2_VehicleStates",
  6136. Adress = 2044,
  6137. ValueType = PLCValueType.String,
  6138. ValueTypeStrLength = 20,
  6139. Value = a1CavitySN2_VehicleStates
  6140. });
  6141. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  6142. {
  6143. Name = "a1CavityResult1_VehicleStates",
  6144. Adress = 2064,
  6145. ValueType = PLCValueType.Short,
  6146. Value = a1CavityResult1_VehicleStates
  6147. });
  6148. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  6149. {
  6150. Name = "a1CavityResult2_VehicleStates",
  6151. Adress = 2065,
  6152. ValueType = PLCValueType.Short,
  6153. Value = a1CavityResult2_VehicleStates
  6154. });
  6155. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  6156. stopwatch2.Stop();
  6157. }
  6158. catch (Exception ex)
  6159. {
  6160. string str = ex.StackTrace;
  6161. AddMessage_Station(stationNameStr, LogType.Error,
  6162. $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" +
  6163. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6164. // MES_Flag
  6165. stopwatch2.Start();
  6166. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6167. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6168. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  6169. writeToPLC_Flag.Adress = 2003;
  6170. writeToPLC_Flag.Value = (short)6;
  6171. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  6172. stopwatch2.Stop();
  6173. }
  6174. stopwatch1.Stop();
  6175. AddMessage(LogType.Info,
  6176. stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6177. stopwatch2.ElapsedMilliseconds + "ms");
  6178. }
  6179. /// <summary>
  6180. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  6181. /// </summary>
  6182. /// <param name="plcNo">PLC编号</param>
  6183. /// <param name="stationNameStr">工站全称</param>
  6184. private void S1上料进站校验(int plcNo, string stationNameStr)
  6185. {
  6186. Stopwatch stopwatch1 = new Stopwatch();
  6187. Stopwatch stopwatch2 = new Stopwatch();
  6188. try
  6189. {
  6190. stopwatch1.Start();
  6191. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  6192. sn = sn.Replace("\0", "");
  6193. // 保存进站数据+调用进站MES接口
  6194. List<TestItem> item = new List<TestItem>();
  6195. stopwatch2.Start();
  6196. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  6197. item, out string errorMsg);
  6198. stopwatch2.Stop();
  6199. short a1MES_FLAG_Check = (short)result;
  6200. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6201. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6202. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  6203. writeToPLC_Flag.Adress = 2077;
  6204. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  6205. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  6206. }
  6207. catch (Exception ex)
  6208. {
  6209. string str = ex.StackTrace;
  6210. AddMessage_Station(stationNameStr, LogType.Error,
  6211. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  6212. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6213. // MES_Flag
  6214. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  6215. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6216. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  6217. writeToPLC_Flag.Adress = 2077;
  6218. writeToPLC_Flag.Value = (short)6;
  6219. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  6220. }
  6221. stopwatch1.Stop();
  6222. AddMessage(LogType.Info,
  6223. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  6224. stopwatch2.ElapsedMilliseconds + "ms");
  6225. }
  6226. /// <summary>
  6227. /// [S1] Tray盘上料装备(板测)- 出站接口
  6228. /// </summary>
  6229. /// <param name="plcNo"></param>
  6230. /// <param name="stationCode"></param>
  6231. /// <param name="stationName"></param>
  6232. private void S1出站接口(int plcNo, string stationCode, string stationName)
  6233. {
  6234. Stopwatch stopwatch1 = new Stopwatch();
  6235. Stopwatch stopwatch2 = new Stopwatch();
  6236. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6237. string stationNameStr = stationCode + stationName;
  6238. string processItem = stationName; // 测试项目
  6239. try
  6240. {
  6241. stopwatch1.Start();
  6242. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6243. //string batch_num = GlobalContext.BatchNumber; // 批次号
  6244. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6245. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6246. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  6247. sn = sn.Replace("\0", "");
  6248. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  6249. partNo1 = partNo1.Replace("\0", "");
  6250. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  6251. partNo2 = partNo2.Replace("\0", "");
  6252. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  6253. bool pass = a1Result == 1;
  6254. stopwatch2.Start();
  6255. // 产品1
  6256. List<TestItem> items = new List<TestItem>();
  6257. items.Add(new TestItem()
  6258. {
  6259. Parameter_name = "载具码",
  6260. Parameter_value = sn,
  6261. Parameter_unit = ""
  6262. });
  6263. items.Add(new TestItem()
  6264. {
  6265. Parameter_name = "载具穴号",
  6266. Parameter_value = "1",
  6267. Parameter_unit = ""
  6268. });
  6269. items.Add(new TestItem()
  6270. {
  6271. Parameter_name = "产品结果",
  6272. Parameter_value = a1Result == 1 ? "OK" : "NG",
  6273. Parameter_unit = ""
  6274. });
  6275. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6276. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  6277. // 产品2
  6278. items = new List<TestItem>();
  6279. items.Add(new TestItem()
  6280. {
  6281. Parameter_name = "载具码",
  6282. Parameter_value = sn,
  6283. Parameter_unit = ""
  6284. });
  6285. items.Add(new TestItem()
  6286. {
  6287. Parameter_name = "载具穴号",
  6288. Parameter_value = "2",
  6289. Parameter_unit = ""
  6290. });
  6291. items.Add(new TestItem()
  6292. {
  6293. Parameter_name = "产品结果",
  6294. Parameter_value = a1Result == 1 ? "OK" : "NG",
  6295. Parameter_unit = ""
  6296. });
  6297. int result2 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6298. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  6299. short result = 0;
  6300. List<int> results = new List<int>() { result1, result2 };
  6301. if (result1 == 1 && result2 == 1)
  6302. result = 1;
  6303. else if (results.Contains(3))
  6304. result = 3;
  6305. else if (results.Contains(2))
  6306. result = 2;
  6307. else if (results.Contains(4))
  6308. result = 4;
  6309. else
  6310. result = 4;
  6311. stopwatch2.Stop();
  6312. #region 存储绑定数据到 边线MES系统中
  6313. if (result == 1)
  6314. {
  6315. string data = string.Concat(partNo1, ".", partNo2);
  6316. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  6317. if (resultMesR != 0)
  6318. {
  6319. result = 4;
  6320. AddMessage_Station(stationNameStr, LogType.Error,
  6321. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  6322. }
  6323. }
  6324. #endregion 存储绑定数据到 边线MES系统中
  6325. // MES_Flag 为MES报错
  6326. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6327. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  6328. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6329. writeToPLC_Flag.Name = "a1MES_FLAG";
  6330. writeToPLC_Flag.Adress = 2109;
  6331. writeToPLC_Flag.Value = result;
  6332. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  6333. OnMessage(LogType.Debug,
  6334. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  6335. }
  6336. catch (Exception ex)
  6337. {
  6338. stopwatch2.Restart();
  6339. // MES_Flag 为4上位机报错
  6340. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  6341. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6342. writeToPLC_Flag.Name = "a1MES_FLAG";
  6343. writeToPLC_Flag.Adress = 2109;
  6344. writeToPLC_Flag.Value = (short)4;
  6345. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  6346. stopwatch2.Stop();
  6347. string str = ex.StackTrace;
  6348. AddMessage_Station(stationNameStr, LogType.Error,
  6349. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  6350. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6351. }
  6352. stopwatch1.Stop();
  6353. AddMessage(LogType.Info,
  6354. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  6355. stopwatch2.ElapsedMilliseconds + "ms");
  6356. }
  6357. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  6358. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  6359. //{
  6360. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6361. // string stationNameStr = stationCode + stationName;
  6362. // string processItem = stationName; // 测试项目
  6363. // try
  6364. // {
  6365. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6366. // string accno = "1"; // 工序编号
  6367. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  6368. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  6369. // List<OneCheckItem> items = new List<OneCheckItem>()
  6370. // {
  6371. // new OneCheckItem()
  6372. // {
  6373. // Onecheck_name="胶圈装配行程设定上限",
  6374. // Onecheck_content="上限值",
  6375. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  6376. // },
  6377. // };
  6378. // OneCheckData oneCheckData = new OneCheckData()
  6379. // {
  6380. // Line_code = GlobalContext.LineCode,
  6381. // Line_name = GlobalContext.LineName,
  6382. // Equipment_code = equipmentCode,
  6383. // Equipment_name = equipmentCode,
  6384. // Workorder_code = workorder_code,
  6385. // Procedure_code = accno,
  6386. // Procedure_name = processItem,
  6387. // Oneckeck_values = items,
  6388. // Onecheck_empcode = "",
  6389. // Onecheck_empname = "",
  6390. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  6391. // };
  6392. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  6393. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  6394. // short result = result1 == 1 ? (short)1 : (short)2;
  6395. // // MES_Flag 为4MES报错
  6396. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  6397. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  6398. // }
  6399. // catch (Exception ex)
  6400. // {
  6401. // // MES_Flag 为2上位机报错
  6402. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  6403. // string str = ex.StackTrace;
  6404. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6405. // }
  6406. //}
  6407. // ReadStation_S1_2 节拍接口+AGV
  6408. /// <summary>
  6409. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  6410. /// </summary>
  6411. /// <param name="plcNo">PLC编号</param>
  6412. /// <param name="stationNameStr">工站全称</param>
  6413. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  6414. {
  6415. Stopwatch stopwatch1 = new Stopwatch();
  6416. Stopwatch stopwatch2 = new Stopwatch();
  6417. try
  6418. {
  6419. stopwatch1.Start();
  6420. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  6421. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  6422. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  6423. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  6424. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  6425. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  6426. // ZS 将SN发给ICT标机(串口)
  6427. short a1MES_FLAG_ICT = 1;
  6428. stopwatch2.Start();
  6429. // MES_Flag
  6430. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  6431. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6432. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  6433. writeToPLC_Flag.Adress = 2182;
  6434. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  6435. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  6436. stopwatch2.Stop();
  6437. }
  6438. catch (Exception ex)
  6439. {
  6440. string str = ex.StackTrace;
  6441. AddMessage_Station(stationNameStr, LogType.Error,
  6442. $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" +
  6443. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6444. stopwatch2.Start();
  6445. // MES_Flag
  6446. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  6447. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6448. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  6449. writeToPLC_Flag.Adress = 2182;
  6450. writeToPLC_Flag.Value = (short)4;
  6451. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  6452. stopwatch2.Stop();
  6453. }
  6454. stopwatch1.Stop();
  6455. AddMessage(LogType.Info,
  6456. stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6457. stopwatch2.ElapsedMilliseconds + "ms");
  6458. }
  6459. /// <summary>
  6460. /// [S1] Tray盘上料装备(板测)- 节拍接口
  6461. /// </summary>
  6462. /// <param name="plcNo">PLC编号</param>
  6463. /// <param name="stationNameStr">工站全称</param>
  6464. private void S1节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  6465. {
  6466. Stopwatch stopwatch1 = new Stopwatch();
  6467. Stopwatch stopwatch2 = new Stopwatch();
  6468. string resultStr = string.Empty;
  6469. try
  6470. {
  6471. stopwatch1.Start();
  6472. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  6473. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  6474. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  6475. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  6476. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  6477. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6478. if (!actionBool)
  6479. {
  6480. stopwatch2.Start();
  6481. //写入PLC
  6482. iot_data.beatReturn = 2; //NG
  6483. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6484. stopwatch2.Stop();
  6485. AddMessage(LogType.Info,
  6486. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  6487. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6488. return;
  6489. }
  6490. //作业开始后要有物料和载具信息
  6491. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode) &&
  6492. Convert.ToInt32(oEEType) > 2)
  6493. {
  6494. stopwatch2.Start();
  6495. //写入PLC
  6496. iot_data.beatReturn = 2; //NG
  6497. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6498. stopwatch2.Stop();
  6499. AddMessage_Station(stationNameStr, LogType.Info,
  6500. stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  6501. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6502. return;
  6503. }
  6504. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a1OEEPartNo))
  6505. {
  6506. stopwatch2.Start();
  6507. //写入PLC
  6508. iot_data.beatReturn = 2; //NG
  6509. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6510. stopwatch2.Stop();
  6511. AddMessage_Station(stationNameStr, LogType.Info,
  6512. stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  6513. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6514. return;
  6515. }
  6516. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a1OEEVehicleCode))
  6517. {
  6518. stopwatch2.Start();
  6519. //写入PLC
  6520. iot_data.beatReturn = 2; //NG
  6521. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6522. stopwatch2.Stop();
  6523. AddMessage_Station(stationNameStr, LogType.Info,
  6524. stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  6525. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6526. return;
  6527. }
  6528. short _result = 0;
  6529. // 上传OEE
  6530. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  6531. _result = result.Item1;
  6532. resultStr = result.Item2;
  6533. if (_result == 1)
  6534. {
  6535. stopwatch2.Start();
  6536. //写入PLC
  6537. iot_data.beatReturn = 1; //OK
  6538. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6539. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  6540. stopwatch2.Stop();
  6541. }
  6542. else {
  6543. stopwatch2.Start();
  6544. //写入PLC
  6545. iot_data.beatReturn = 2; //NG
  6546. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6547. stopwatch2.Stop();
  6548. AddMessage_Station(stationNameStr, LogType.Error,
  6549. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr );
  6550. }
  6551. }
  6552. catch (Exception ex)
  6553. {
  6554. string str = ex.StackTrace;
  6555. AddMessage_Station(stationNameStr, LogType.Error,
  6556. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  6557. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6558. // MES_Flag
  6559. stopwatch2.Start();
  6560. //写入PLC
  6561. iot_data.beatReturn = 2; //NG
  6562. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6563. stopwatch2.Stop();
  6564. }
  6565. stopwatch1.Stop();
  6566. AddMessage(LogType.Info,
  6567. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6568. stopwatch2.ElapsedMilliseconds + "ms");
  6569. }
  6570. /// <summary>
  6571. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  6572. /// </summary>
  6573. /// <param name="plcNo">PLC编号</param>
  6574. /// <param name="stationNameStr">工站全称</param>
  6575. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  6576. {
  6577. Stopwatch stopwatch1 = new Stopwatch();
  6578. Stopwatch stopwatch2 = new Stopwatch();
  6579. try
  6580. {
  6581. stopwatch1.Start();
  6582. // ZS 呼叫AGV
  6583. short a1AGVUpCall = 2;
  6584. stopwatch2.Start();
  6585. // a1AGVUpCall
  6586. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  6587. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6588. writeToPLC_Flag.Name = "a1AGVUpCall";
  6589. writeToPLC_Flag.Adress = 2307;
  6590. writeToPLC_Flag.Value = a1AGVUpCall;
  6591. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  6592. stopwatch2.Stop();
  6593. }
  6594. catch (Exception ex)
  6595. {
  6596. string str = ex.StackTrace;
  6597. AddMessage_Station(stationNameStr, LogType.Error,
  6598. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  6599. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6600. // a1AGVUpCall
  6601. stopwatch2.Start();
  6602. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  6603. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6604. writeToPLC_Flag.Name = "a1AGVUpCall";
  6605. writeToPLC_Flag.Adress = 2307;
  6606. writeToPLC_Flag.Value = (short)4;
  6607. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  6608. stopwatch2.Stop();
  6609. }
  6610. stopwatch1.Stop();
  6611. AddMessage(LogType.Info,
  6612. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6613. stopwatch2.ElapsedMilliseconds + "ms");
  6614. }
  6615. /// <summary>
  6616. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  6617. /// </summary>
  6618. /// <param name="plcNo">PLC编号</param>
  6619. /// <param name="stationNameStr">工站全称</param>
  6620. private void S1AGV上料完成(int plcNo, string stationNameStr)
  6621. {
  6622. Stopwatch stopwatch1 = new Stopwatch();
  6623. Stopwatch stopwatch2 = new Stopwatch();
  6624. try
  6625. {
  6626. stopwatch1.Start();
  6627. // ZS AGV上料完成,让小车离开
  6628. short a1AGVUpEnd = 2;
  6629. stopwatch2.Start();
  6630. // a1AGVUpEnd
  6631. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  6632. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6633. writeToPLC_Flag.Name = "a1AGVUpEnd";
  6634. writeToPLC_Flag.Adress = 2309;
  6635. writeToPLC_Flag.Value = a1AGVUpEnd;
  6636. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  6637. stopwatch2.Stop();
  6638. }
  6639. catch (Exception ex)
  6640. {
  6641. string str = ex.StackTrace;
  6642. AddMessage_Station(stationNameStr, LogType.Error,
  6643. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  6644. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6645. // a1AGVUpEnd
  6646. stopwatch2.Start();
  6647. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  6648. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6649. writeToPLC_Flag.Name = "a1AGVUpEnd";
  6650. writeToPLC_Flag.Adress = 2309;
  6651. writeToPLC_Flag.Value = (short)4;
  6652. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  6653. stopwatch2.Stop();
  6654. }
  6655. stopwatch1.Stop();
  6656. AddMessage(LogType.Info,
  6657. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6658. stopwatch2.ElapsedMilliseconds + "ms");
  6659. }
  6660. /// <summary>
  6661. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  6662. /// </summary>
  6663. /// <param name="plcNo">PLC编号</param>
  6664. /// <param name="stationNameStr">工站全称</param>
  6665. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  6666. {
  6667. Stopwatch stopwatch1 = new Stopwatch();
  6668. Stopwatch stopwatch2 = new Stopwatch();
  6669. try
  6670. {
  6671. stopwatch1.Start();
  6672. // ZS 呼叫AGV
  6673. short a1AGVDownCall = 2;
  6674. stopwatch2.Start();
  6675. // a1AGVDownCall
  6676. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  6677. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6678. writeToPLC_Flag.Name = "a1AGVDownCall";
  6679. writeToPLC_Flag.Adress = 2320;
  6680. writeToPLC_Flag.Value = a1AGVDownCall;
  6681. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  6682. stopwatch2.Stop();
  6683. }
  6684. catch (Exception ex)
  6685. {
  6686. string str = ex.StackTrace;
  6687. AddMessage_Station(stationNameStr, LogType.Error,
  6688. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  6689. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6690. // a1AGVDownCall
  6691. stopwatch2.Start();
  6692. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  6693. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6694. writeToPLC_Flag.Name = "a1AGVDownCall";
  6695. writeToPLC_Flag.Adress = 2320;
  6696. writeToPLC_Flag.Value = (short)4;
  6697. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  6698. stopwatch2.Stop();
  6699. }
  6700. stopwatch1.Stop();
  6701. AddMessage(LogType.Info,
  6702. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6703. stopwatch2.ElapsedMilliseconds + "ms");
  6704. }
  6705. /// <summary>
  6706. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  6707. /// </summary>
  6708. /// <param name="plcNo">PLC编号</param>
  6709. /// <param name="stationNameStr">工站全称</param>
  6710. private void S1AGV下料完成(int plcNo, string stationNameStr)
  6711. {
  6712. Stopwatch stopwatch1 = new Stopwatch();
  6713. Stopwatch stopwatch2 = new Stopwatch();
  6714. try
  6715. {
  6716. stopwatch1.Start();
  6717. // ZS AGV上料完成,让小车离开
  6718. short a1AGVDownEnd = 2;
  6719. stopwatch2.Start();
  6720. // a1AGVDownEnd
  6721. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  6722. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6723. writeToPLC_Flag.Name = "a1AGVDownEnd";
  6724. writeToPLC_Flag.Adress = 2322;
  6725. writeToPLC_Flag.Value = a1AGVDownEnd;
  6726. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  6727. stopwatch2.Stop();
  6728. }
  6729. catch (Exception ex)
  6730. {
  6731. string str = ex.StackTrace;
  6732. AddMessage_Station(stationNameStr, LogType.Error,
  6733. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  6734. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6735. // a1AGVDownEnd
  6736. stopwatch2.Start();
  6737. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  6738. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6739. writeToPLC_Flag.Name = "a1AGVDownEnd";
  6740. writeToPLC_Flag.Adress = 2322;
  6741. writeToPLC_Flag.Value = (short)4;
  6742. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  6743. stopwatch2.Stop();
  6744. }
  6745. stopwatch1.Stop();
  6746. AddMessage(LogType.Info,
  6747. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6748. stopwatch2.ElapsedMilliseconds + "ms");
  6749. }
  6750. #endregion [S1] Tray盘上料装备(板测)
  6751. #endregion PLC1 张超凡
  6752. #region PLC2 李晓奇
  6753. #region [S2] FCT(板测)
  6754. /// <summary>
  6755. /// S2工位的数据- 触发信号上次的值
  6756. /// </summary>
  6757. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  6758. /// <summary>
  6759. /// S2工位的数据(含触发信号)
  6760. /// </summary>
  6761. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  6762. /// <summary>
  6763. /// S2工位的数据- 回写点位
  6764. /// </summary>
  6765. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6766. /// <summary>
  6767. /// [S2] FCT(板测)
  6768. /// </summary>
  6769. /// <param name="plcNo">PLC编号</param>
  6770. //private void ReadStation_S2(int plcNo)
  6771. //{
  6772. // // [S1] Tray盘上料装备
  6773. // // [S2] FCT
  6774. // // [S3] 值板机
  6775. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6776. // // [S5] Tray盘下料装备
  6777. // /// 上位机心跳
  6778. // /// 获取设备报警数据与状态信息
  6779. // string stationCode = "[S2]";
  6780. // string stationName = "FCT";
  6781. // string stationNameStr = stationCode + stationName;
  6782. // #region 创建字典
  6783. // // 触发信号字典 赋值
  6784. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  6785. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  6786. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6787. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6788. // // PLC数据字典 赋值
  6789. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  6790. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  6791. // s2PLCData.Add("b1ProductSN_Check", 0);
  6792. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  6793. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  6794. // s2PLCData.Add("b1ProductSN_Unbind", "");
  6795. // s2PLCData.Add("b1ProductSN_Bind", "");
  6796. // s2PLCData.Add("b1Part1SN_Bind", "");
  6797. // s2PLCData.Add("b1Part2SN_Bind", "");
  6798. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  6799. // s2PLCData.Add("b1MES_FLAG", 0);
  6800. // s2PLCData.Add("b1ProductSN", 0);
  6801. // s2PLCData.Add("b1Part1Result", 0);
  6802. // s2PLCData.Add("b1Part2Result", 0);
  6803. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  6804. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  6805. // s2PLCData.Add("b1OEEProductSN", "");
  6806. // s2PLCData.Add("b1OEEType", 0);
  6807. // #endregion 创建字典
  6808. // while (IsRun)
  6809. // {
  6810. // try
  6811. // {
  6812. // if (!GlobalContext._IsCon_Funs2)
  6813. // {
  6814. // UpdatePLCMonitor(1, plcNo, 0);
  6815. // continue;
  6816. // }
  6817. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6818. // {
  6819. // Stopwatch stopwatch1 = new Stopwatch();
  6820. // Stopwatch stopwatch2 = new Stopwatch();
  6821. // stopwatch1.Start();
  6822. // stopwatch2.Start();
  6823. // #region 一次性读取所有数据
  6824. // // 一次性读取所有数据
  6825. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  6826. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  6827. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  6828. // int[] datas = data1.Concat(data2).ToArray();
  6829. // datas = datas.Concat(data3).ToArray();
  6830. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  6831. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  6832. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  6833. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  6834. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  6835. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  6836. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  6837. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  6838. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  6839. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  6840. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  6841. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  6842. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  6843. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  6844. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  6845. // s2PLCData["b1MES_FLAG"] = datas[169];
  6846. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  6847. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  6848. // s2PLCData["b1Part1Result"] = datas[190];
  6849. // s2PLCData["b1Part2Result"] = datas[191];
  6850. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  6851. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  6852. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  6853. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  6854. // s2PLCData["b1OEEType"] = datas[224];
  6855. // #endregion 一次性读取所有数据
  6856. // stopwatch2.Stop();
  6857. // #region 回写操作,写后清空flag
  6858. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  6859. // #endregion 回写操作,写后清空flag
  6860. // #region 进站校验
  6861. // try
  6862. // {
  6863. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  6864. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  6865. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  6866. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  6867. // {
  6868. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  6869. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  6870. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  6871. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  6872. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  6873. // }
  6874. // }
  6875. // catch (Exception ex)
  6876. // {
  6877. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6878. // string str = ex.StackTrace;
  6879. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6880. // }
  6881. // #endregion 进站校验
  6882. // #region 二穴载具解绑/绑定(产品换载具)
  6883. // try
  6884. // {
  6885. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  6886. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  6887. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  6888. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  6889. // {
  6890. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  6891. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  6892. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  6893. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  6894. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  6895. // }
  6896. // }
  6897. // catch (Exception ex)
  6898. // {
  6899. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  6900. // string str = ex.StackTrace;
  6901. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6902. // }
  6903. // #endregion 二穴载具解绑/绑定(产品换载具)
  6904. // #region FCT-出站接口
  6905. // try
  6906. // {
  6907. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  6908. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  6909. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  6910. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  6911. // {
  6912. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  6913. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6914. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  6915. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  6916. // }
  6917. // }
  6918. // catch (Exception ex)
  6919. // {
  6920. // // MES_Flag 为6上位机报错
  6921. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  6922. // string str = ex.StackTrace;
  6923. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6924. // }
  6925. // #endregion FCT-出站接口
  6926. // #region 节拍接口
  6927. // try
  6928. // {
  6929. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  6930. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  6931. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  6932. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  6933. // {
  6934. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  6935. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6936. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  6937. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  6938. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  6939. // }
  6940. // }
  6941. // catch (Exception ex)
  6942. // {
  6943. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  6944. // string str = ex.StackTrace;
  6945. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6946. // }
  6947. // #endregion 节拍接口
  6948. // #region 心跳
  6949. // try
  6950. // {
  6951. // short states = 0;
  6952. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  6953. // }
  6954. // catch (Exception ex)
  6955. // {
  6956. // string str = ex.StackTrace;
  6957. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6958. // }
  6959. // #endregion 心跳
  6960. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6961. // stopwatch1.Stop();
  6962. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  6963. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6964. // }
  6965. // else
  6966. // {
  6967. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6968. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6969. // Funs[plcNo].Connect();
  6970. // }
  6971. // }
  6972. // catch (Exception ex)
  6973. // {
  6974. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6975. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6976. // Funs[plcNo].ReConnect();
  6977. // }
  6978. // Thread.Sleep(IntervalReadPLC);
  6979. // }
  6980. //}
  6981. /// <summary>
  6982. /// [S2] FCT(板测)- 进站校验
  6983. /// </summary>
  6984. /// <param name="plcNo">PLC编号</param>
  6985. /// <param name="stationNameStr">工站全称</param>
  6986. private void S2进站校验(int plcNo, string stationNameStr)
  6987. {
  6988. Stopwatch stopwatch1 = new Stopwatch();
  6989. Stopwatch stopwatch2 = new Stopwatch();
  6990. try
  6991. {
  6992. stopwatch1.Start();
  6993. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  6994. sn = sn.Replace("\0", "");
  6995. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  6996. // 查询物料码By载具码 并判断是不是假产品
  6997. string cavityData = string.Empty;
  6998. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6999. if (string.IsNullOrEmpty(cavityData))
  7000. cavityData = "";
  7001. if (snResult != 0)
  7002. {
  7003. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7004. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  7005. writeToPLC_Flag1.Adress = 2003;
  7006. writeToPLC_Flag1.Value = (short)6;
  7007. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  7008. stopwatch1.Stop();
  7009. AddMessage(LogType.Info,
  7010. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7011. return;
  7012. }
  7013. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  7014. string[] cavitySNs = cavityData.Split('.');
  7015. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  7016. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  7017. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  7018. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  7019. if (cavitySNs != null && cavitySNs.Length >= 2)
  7020. {
  7021. b1Part1SN_Check = cavitySNs[0];
  7022. b1Part2SN_Check = cavitySNs[1];
  7023. b1Part1Result_Check = 2;
  7024. b1Part2Result_Check = 2;
  7025. }
  7026. if (b1Part1SN_Check == "假产品")
  7027. b1Part1Result_Check = 3;
  7028. if (b1Part2SN_Check == "假产品")
  7029. b1Part2Result_Check = 3;
  7030. // 调用MES进站
  7031. stopwatch2.Start();
  7032. // 调用MES进站 - 产品1
  7033. List<TestItem> item;
  7034. int result1 = b1Part1Result_Check;
  7035. if (result1 != 3)
  7036. {
  7037. item = new List<TestItem>();
  7038. item.Add(new TestItem()
  7039. {
  7040. Parameter_name = "载具码",
  7041. Parameter_value = sn,
  7042. });
  7043. item.Add(new TestItem()
  7044. {
  7045. Parameter_name = "载具穴号",
  7046. Parameter_value = "1",
  7047. });
  7048. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  7049. b1Part1SN_Check, item, out string errorMsg);
  7050. }
  7051. // 调用MES进站 - 产品2
  7052. int result2 = b1Part2Result_Check;
  7053. if (result2 != 3)
  7054. {
  7055. item = new List<TestItem>();
  7056. item.Add(new TestItem()
  7057. {
  7058. Parameter_name = "载具码",
  7059. Parameter_value = sn,
  7060. });
  7061. item.Add(new TestItem()
  7062. {
  7063. Parameter_name = "载具穴号",
  7064. Parameter_value = "2",
  7065. });
  7066. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  7067. b1Part2SN_Check, item, out string errorMsg);
  7068. }
  7069. stopwatch2.Stop();
  7070. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  7071. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  7072. int result = result1;
  7073. if (result == 1)
  7074. result = result2;
  7075. short b1MES_FLAG_Check = (short)result;
  7076. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  7077. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  7078. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  7079. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  7080. //// MES_Flag
  7081. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7082. WriteToPLC_Flag
  7083. writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7084. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  7085. writeToPLC_Flag.Adress = 2003;
  7086. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  7087. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7088. {
  7089. Name = "b1Part1SN_Check",
  7090. Adress = 2024,
  7091. ValueType = PLCValueType.String,
  7092. ValueTypeStrLength = 20,
  7093. Value = b1Part1SN_Check
  7094. });
  7095. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7096. {
  7097. Name = "b1Part2SN_Check",
  7098. Adress = 2044,
  7099. ValueType = PLCValueType.String,
  7100. ValueTypeStrLength = 20,
  7101. Value = b1Part2SN_Check
  7102. });
  7103. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7104. {
  7105. Name = "b1Part1Result_Check",
  7106. Adress = 2064,
  7107. ValueType = PLCValueType.Short,
  7108. Value = b1Part1Result_Check
  7109. });
  7110. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7111. {
  7112. Name = "b1Part2Result_Check",
  7113. Adress = 2065,
  7114. ValueType = PLCValueType.Short,
  7115. Value = b1Part2Result_Check
  7116. });
  7117. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  7118. }
  7119. catch (Exception ex)
  7120. {
  7121. string str = ex.StackTrace;
  7122. AddMessage_Station(stationNameStr, LogType.Error,
  7123. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  7124. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7125. // MES_Flag
  7126. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7127. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7128. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  7129. writeToPLC_Flag.Adress = 2003;
  7130. writeToPLC_Flag.Value = (short)6;
  7131. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  7132. }
  7133. stopwatch1.Stop();
  7134. AddMessage(LogType.Info,
  7135. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  7136. stopwatch2.ElapsedMilliseconds + "ms");
  7137. }
  7138. /// <summary>
  7139. /// [S2] FCT(板测)- 二穴载具解绑绑定
  7140. /// </summary>
  7141. /// <param name="plcNo">PLC编号</param>
  7142. /// <param name="stationNameStr">工站全称</param>
  7143. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  7144. {
  7145. Stopwatch stopwatch1 = new Stopwatch();
  7146. Stopwatch stopwatch2 = new Stopwatch();
  7147. try
  7148. {
  7149. stopwatch1.Start();
  7150. // 产品换载具
  7151. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  7152. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  7153. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  7154. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  7155. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  7156. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  7157. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  7158. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  7159. stopwatch2.Start();
  7160. #region 查询载具上的产品信息
  7161. //string cavityData = string.Empty;
  7162. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  7163. //if (string.IsNullOrEmpty(cavityData))
  7164. // cavityData = "";
  7165. //if (snResult != 0)
  7166. //{
  7167. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7168. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  7169. // writeToPLC_Flag.Adress = 2077;
  7170. // writeToPLC_Flag.Value = (short)6;
  7171. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  7172. // stopwatch1.Stop();
  7173. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7174. // return;
  7175. //}
  7176. #endregion 查询载具上的产品信息
  7177. #region 解绑(边线MES系统)
  7178. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  7179. if (snResult != 0)
  7180. {
  7181. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7182. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  7183. writeToPLC_Flag1.Adress = 2077;
  7184. writeToPLC_Flag1.Value = (short)6;
  7185. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  7186. stopwatch1.Stop();
  7187. AddMessage(LogType.Info,
  7188. stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" +
  7189. stopwatch1.ElapsedMilliseconds + "ms");
  7190. return;
  7191. }
  7192. #endregion 解绑(边线MES系统)
  7193. #region 存储绑定数据到 边线MES系统中
  7194. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  7195. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  7196. if (snResult != 0)
  7197. {
  7198. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7199. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  7200. writeToPLC_Flag1.Adress = 2077;
  7201. writeToPLC_Flag1.Value = (short)6;
  7202. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  7203. stopwatch1.Stop();
  7204. AddMessage(LogType.Info,
  7205. stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" +
  7206. stopwatch1.ElapsedMilliseconds + "ms");
  7207. return;
  7208. }
  7209. #endregion 存储绑定数据到 边线MES系统中
  7210. stopwatch2.Stop();
  7211. short b1MES_FLAG_Unbind = 1;
  7212. // MES_Flag
  7213. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7214. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7215. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  7216. writeToPLC_Flag.Adress = 2077;
  7217. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  7218. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  7219. }
  7220. catch (Exception ex)
  7221. {
  7222. string str = ex.StackTrace;
  7223. AddMessage_Station(stationNameStr, LogType.Error,
  7224. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" +
  7225. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7226. // MES_Flag
  7227. stopwatch2.Start();
  7228. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7229. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7230. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  7231. writeToPLC_Flag.Adress = 2077;
  7232. writeToPLC_Flag.Value = (short)6;
  7233. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  7234. stopwatch2.Stop();
  7235. }
  7236. stopwatch1.Stop();
  7237. AddMessage(LogType.Info,
  7238. stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7239. stopwatch2.ElapsedMilliseconds + "ms");
  7240. }
  7241. //// 上次采集到的SN
  7242. //private string sn_FCT = string.Empty;
  7243. /// <summary>
  7244. /// [S2] FCT(板测)- 出站数据
  7245. /// </summary>
  7246. private void S2出站接口(int plcNo, string stationCode, string stationName)
  7247. {
  7248. Stopwatch stopwatch1 = new Stopwatch();
  7249. Stopwatch stopwatch2 = new Stopwatch();
  7250. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7251. string stationNameStr = stationCode + stationName;
  7252. string processItem = stationName; // 测试项目
  7253. try
  7254. {
  7255. stopwatch1.Start();
  7256. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7257. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7258. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7259. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7260. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  7261. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  7262. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  7263. bool pass1 = b1Part1Result == 1;
  7264. bool pass2 = b1Part2Result == 1;
  7265. #region 根据 载具SN 查 物料SN
  7266. string cavityData = string.Empty;
  7267. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  7268. if (string.IsNullOrEmpty(cavityData))
  7269. cavityData = "";
  7270. if (snResult != 0)
  7271. {
  7272. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7273. writeToPLC_Flag1.Name = "b1MES_FLAG";
  7274. writeToPLC_Flag1.Adress = 2169;
  7275. writeToPLC_Flag1.Value = (short)4;
  7276. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  7277. stopwatch1.Stop();
  7278. AddMessage(LogType.Info,
  7279. stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  7280. "ms");
  7281. return;
  7282. }
  7283. #endregion 根据 载具SN 查 物料SN
  7284. string[] cavitySNs = cavityData.Split('.');
  7285. string b1ProductSN1 = string.Empty;
  7286. string b1ProductSN2 = string.Empty;
  7287. if (cavitySNs != null && cavitySNs.Length >= 2)
  7288. {
  7289. b1ProductSN1 = cavitySNs[0];
  7290. b1ProductSN2 = cavitySNs[1];
  7291. }
  7292. stopwatch2.Start();
  7293. // 产品1
  7294. int result1 = 0;
  7295. if (b1ProductSN1 == "假产品")
  7296. result1 = 1;
  7297. else
  7298. {
  7299. List<TestItem> items1 = new List<TestItem>();
  7300. items1.Add(new TestItem()
  7301. {
  7302. Parameter_name = "载具码",
  7303. Parameter_value = b1ProductSN.ToString(),
  7304. Parameter_unit = ""
  7305. });
  7306. items1.Add(new TestItem()
  7307. {
  7308. Parameter_name = "载具穴号",
  7309. Parameter_value = "1",
  7310. Parameter_unit = ""
  7311. });
  7312. items1.Add(new TestItem()
  7313. {
  7314. Parameter_name = "产品结果",
  7315. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  7316. Parameter_unit = ""
  7317. });
  7318. result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7319. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  7320. }
  7321. // 产品2
  7322. int result2 = 0;
  7323. if (b1ProductSN1 == "假产品")
  7324. result2 = 1;
  7325. else
  7326. {
  7327. List<TestItem> items2 = new List<TestItem>();
  7328. items2.Add(new TestItem()
  7329. {
  7330. Parameter_name = "载具码",
  7331. Parameter_value = b1ProductSN.ToString(),
  7332. Parameter_unit = ""
  7333. });
  7334. items2.Add(new TestItem()
  7335. {
  7336. Parameter_name = "载具穴号",
  7337. Parameter_value = "2",
  7338. Parameter_unit = ""
  7339. });
  7340. items2.Add(new TestItem()
  7341. {
  7342. Parameter_name = "产品结果",
  7343. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  7344. Parameter_unit = ""
  7345. });
  7346. result2 = SwitctProcessData(stationNameStr, items2, equipmentCode, processItem
  7347. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  7348. }
  7349. short result = 0;
  7350. List<int> results = new List<int>() { result1, result2 };
  7351. if (result1 == 1 && result2 == 1)
  7352. result = 1;
  7353. else if (results.Contains(3))
  7354. result = 3;
  7355. else if (results.Contains(2))
  7356. result = 2;
  7357. else if (results.Contains(4))
  7358. result = 4;
  7359. else
  7360. result = 4;
  7361. stopwatch2.Stop();
  7362. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7363. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7364. writeToPLC_Flag.Name = "b1MES_FLAG";
  7365. writeToPLC_Flag.Adress = 2169;
  7366. writeToPLC_Flag.Value = result;
  7367. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  7368. OnMessage(LogType.Debug,
  7369. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7370. }
  7371. catch (Exception ex)
  7372. {
  7373. stopwatch2.Restart();
  7374. // MES_Flag 为4上位机报错
  7375. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  7376. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7377. writeToPLC_Flag.Name = "b1MES_FLAG";
  7378. writeToPLC_Flag.Adress = 2169;
  7379. writeToPLC_Flag.Value = (short)4;
  7380. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  7381. stopwatch2.Stop();
  7382. string str = ex.StackTrace;
  7383. AddMessage_Station(stationNameStr, LogType.Error,
  7384. $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  7385. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7386. }
  7387. stopwatch1.Stop();
  7388. AddMessage(LogType.Info,
  7389. stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  7390. stopwatch2.ElapsedMilliseconds + "ms");
  7391. }
  7392. /// <summary>
  7393. /// [S2] FCT(板测)- 节拍接口
  7394. /// </summary>
  7395. /// <param name="plcNo">PLC编号</param>
  7396. /// <param name="stationNameStr">工站全称</param>
  7397. private void S2节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  7398. {
  7399. Stopwatch stopwatch1 = new Stopwatch();
  7400. Stopwatch stopwatch2 = new Stopwatch();
  7401. string resultStr = string.Empty;
  7402. try
  7403. {
  7404. stopwatch1.Start();
  7405. string oEEType = ((int)s1PLCData["a2OEEType"]).ToString(); // 节拍类型(plc写入)
  7406. string a2OEEPartNo = (string)s1PLCData["a2OEEPartNo"]; // 物料码
  7407. a2OEEPartNo = a2OEEPartNo.Replace("\0", "");
  7408. string a20EEVehicleCode = (string)s1PLCData["a20EEVehicleCode"]; // 载具SN
  7409. a20EEVehicleCode = a20EEVehicleCode.Replace("\0", "");
  7410. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7411. if (!actionBool)
  7412. {
  7413. stopwatch2.Start();
  7414. //写入PLC
  7415. iot_data.beatReturn = 2; //NG
  7416. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7417. stopwatch2.Stop();
  7418. AddMessage(LogType.Info,
  7419. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  7420. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7421. return;
  7422. }
  7423. //作业开始后要有物料和载具信息
  7424. if (string.IsNullOrEmpty(a2OEEPartNo) && string.IsNullOrEmpty(a20EEVehicleCode) &&
  7425. Convert.ToInt32(oEEType) > 2)
  7426. {
  7427. stopwatch2.Start();
  7428. //写入PLC
  7429. iot_data.beatReturn = 2; //NG
  7430. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7431. stopwatch2.Stop();
  7432. AddMessage_Station(stationNameStr, LogType.Info,
  7433. stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  7434. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7435. return;
  7436. }
  7437. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a2OEEPartNo))
  7438. {
  7439. stopwatch2.Start();
  7440. //写入PLC
  7441. iot_data.beatReturn = 2; //NG
  7442. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7443. stopwatch2.Stop();
  7444. AddMessage_Station(stationNameStr, LogType.Info,
  7445. stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  7446. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7447. return;
  7448. }
  7449. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a20EEVehicleCode))
  7450. {
  7451. stopwatch2.Start();
  7452. //写入PLC
  7453. iot_data.beatReturn = 2; //NG
  7454. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7455. stopwatch2.Stop();
  7456. AddMessage_Station(stationNameStr, LogType.Info,
  7457. stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  7458. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7459. return;
  7460. }
  7461. short _result = 0;
  7462. // 上传OEE
  7463. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a2OEEPartNo, a20EEVehicleCode);
  7464. _result = result.Item1;
  7465. resultStr = result.Item2;
  7466. if (_result == 1)
  7467. {
  7468. stopwatch2.Start();
  7469. //写入PLC
  7470. iot_data.beatReturn = 1; //OK
  7471. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7472. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  7473. stopwatch2.Stop();
  7474. }
  7475. else
  7476. {
  7477. stopwatch2.Start();
  7478. //写入PLC
  7479. iot_data.beatReturn = 2; //NG
  7480. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7481. stopwatch2.Stop();
  7482. AddMessage_Station(stationNameStr, LogType.Error,
  7483. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  7484. }
  7485. }
  7486. catch (Exception ex)
  7487. {
  7488. string str = ex.StackTrace;
  7489. AddMessage_Station(stationNameStr, LogType.Error,
  7490. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  7491. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7492. // MES_Flag
  7493. stopwatch2.Start();
  7494. //写入PLC
  7495. iot_data.beatReturn = 2; //NG
  7496. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7497. stopwatch2.Stop();
  7498. }
  7499. stopwatch1.Stop();
  7500. AddMessage(LogType.Info,
  7501. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7502. stopwatch2.ElapsedMilliseconds + "ms");
  7503. }
  7504. #endregion [S2] FCT(板测)
  7505. #endregion PLC2 李晓奇
  7506. #region PLC3 刘永村
  7507. #region [S3] 值板机
  7508. /// <summary>
  7509. /// S3工位的数据- 触发信号上次的值
  7510. /// </summary>
  7511. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  7512. /// <summary>
  7513. /// S3工位的数据(含触发信号)
  7514. /// </summary>
  7515. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  7516. /// <summary>
  7517. /// S3工位的数据- 回写点位
  7518. /// </summary>
  7519. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  7520. /// <summary>
  7521. /// [S3] 值板机
  7522. /// </summary>
  7523. /// <param name="plcNo">PLC编号</param>
  7524. //private void ReadStation_S3(int plcNo)
  7525. //{
  7526. // // [S1] Tray盘上料装备
  7527. // // [S2] FCT
  7528. // // [S3] 值板机
  7529. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  7530. // // [S5] Tray盘下料装备
  7531. // /// 上位机心跳
  7532. // /// 获取设备报警数据与状态信息
  7533. // string stationCode = "[S3]";
  7534. // string stationName = "值板机";
  7535. // string stationNameStr = stationCode + stationName;
  7536. // #region 创建字典
  7537. // // 触发信号字典 赋值
  7538. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  7539. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  7540. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  7541. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  7542. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  7543. // // PLC数据字典 赋值
  7544. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  7545. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  7546. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  7547. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  7548. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  7549. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  7550. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  7551. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  7552. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  7553. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  7554. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  7555. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  7556. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  7557. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  7558. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  7559. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  7560. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  7561. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  7562. // s3PLCData.Add("c1Result", 0); // 产品结果
  7563. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  7564. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  7565. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  7566. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  7567. // #endregion 创建字典
  7568. // while (IsRun)
  7569. // {
  7570. // try
  7571. // {
  7572. // if (!GlobalContext._IsCon_Funs3)
  7573. // {
  7574. // UpdatePLCMonitor(1, plcNo, 0);
  7575. // continue;
  7576. // }
  7577. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  7578. // {
  7579. // Stopwatch stopwatch1 = new Stopwatch();
  7580. // Stopwatch stopwatch2 = new Stopwatch();
  7581. // stopwatch1.Start();
  7582. // stopwatch2.Start();
  7583. // #region 一次性读取所有数据
  7584. // // 一次性读取所有数据
  7585. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  7586. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  7587. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  7588. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  7589. // int[] datas = data1.Concat(data2).ToArray();
  7590. // datas = datas.Concat(data3).ToArray();
  7591. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  7592. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  7593. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  7594. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  7595. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  7596. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  7597. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  7598. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  7599. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  7600. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  7601. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  7602. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  7603. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  7604. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  7605. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  7606. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  7607. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  7608. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  7609. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  7610. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  7611. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  7612. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  7613. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  7614. // #endregion 一次性读取所有数据
  7615. // stopwatch2.Stop();
  7616. // #region 回写操作,写后清空flag
  7617. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  7618. // #endregion 回写操作,写后清空flag
  7619. // #region S3进站校验
  7620. // try
  7621. // {
  7622. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  7623. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  7624. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  7625. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  7626. // {
  7627. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  7628. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  7629. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  7630. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  7631. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  7632. // }
  7633. // }
  7634. // catch (Exception ex)
  7635. // {
  7636. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7637. // string str = ex.StackTrace;
  7638. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7639. // }
  7640. // #endregion S3进站校验
  7641. // #region S3二穴载具解绑
  7642. // try
  7643. // {
  7644. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  7645. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  7646. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  7647. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  7648. // {
  7649. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  7650. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  7651. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  7652. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  7653. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  7654. // }
  7655. // }
  7656. // catch (Exception ex)
  7657. // {
  7658. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  7659. // string str = ex.StackTrace;
  7660. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7661. // }
  7662. // #endregion S3二穴载具解绑
  7663. // #region S3二穴载具绑定
  7664. // try
  7665. // {
  7666. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  7667. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  7668. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  7669. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  7670. // {
  7671. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  7672. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  7673. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  7674. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  7675. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  7676. // }
  7677. // }
  7678. // catch (Exception ex)
  7679. // {
  7680. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  7681. // string str = ex.StackTrace;
  7682. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7683. // }
  7684. // #endregion S3二穴载具绑定
  7685. // #region S3出站接口(+一穴载具绑定)
  7686. // try
  7687. // {
  7688. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  7689. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  7690. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  7691. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  7692. // {
  7693. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  7694. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  7695. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  7696. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  7697. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  7698. // }
  7699. // }
  7700. // catch (Exception ex)
  7701. // {
  7702. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  7703. // string str = ex.StackTrace;
  7704. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7705. // }
  7706. // #endregion S3出站接口(+一穴载具绑定)
  7707. // #region S3节拍接口
  7708. // try
  7709. // {
  7710. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  7711. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  7712. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  7713. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  7714. // {
  7715. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  7716. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7717. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  7718. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  7719. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  7720. // }
  7721. // }
  7722. // catch (Exception ex)
  7723. // {
  7724. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  7725. // string str = ex.StackTrace;
  7726. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7727. // }
  7728. // #endregion S3节拍接口
  7729. // #region 心跳
  7730. // try
  7731. // {
  7732. // short states = 0;
  7733. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7734. // }
  7735. // catch (Exception ex)
  7736. // {
  7737. // string str = ex.StackTrace;
  7738. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7739. // }
  7740. // #endregion 心跳
  7741. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7742. // stopwatch1.Stop();
  7743. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7744. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7745. // }
  7746. // else
  7747. // {
  7748. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7749. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  7750. // Funs[plcNo].Connect();
  7751. // }
  7752. // }
  7753. // catch (Exception ex)
  7754. // {
  7755. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7756. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  7757. // Funs[plcNo].ReConnect();
  7758. // }
  7759. // Thread.Sleep(IntervalReadPLC);
  7760. // }
  7761. //}
  7762. /// <summary>
  7763. /// [S3] 值板机- 进站校验
  7764. /// </summary>
  7765. /// <param name="plcNo">PLC编号</param>
  7766. /// <param name="stationNameStr">工站全称</param>
  7767. private void S3进站校验(int plcNo, string stationNameStr)
  7768. {
  7769. Stopwatch stopwatch1 = new Stopwatch();
  7770. Stopwatch stopwatch2 = new Stopwatch();
  7771. try
  7772. {
  7773. stopwatch1.Start();
  7774. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  7775. sn = sn.Replace("\0", "");
  7776. #region 查询载具上的产品信息
  7777. string cavityData = string.Empty;
  7778. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  7779. if (string.IsNullOrEmpty(cavityData))
  7780. cavityData = "";
  7781. if (snResult != 0)
  7782. {
  7783. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7784. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  7785. writeToPLC_Flag1.Adress = 2003;
  7786. writeToPLC_Flag1.Value = (short)6;
  7787. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  7788. stopwatch1.Stop();
  7789. AddMessage(LogType.Info,
  7790. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7791. return;
  7792. }
  7793. #endregion 查询载具上的产品信息
  7794. string[] cavitySNs = cavityData.Split('.');
  7795. string part1Str = ""; // 产品1的SN码
  7796. string part2Str = ""; // 产品2的SN码
  7797. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  7798. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  7799. if (cavitySNs != null && cavitySNs.Length >= 2)
  7800. {
  7801. part1Str = cavitySNs[0];
  7802. part2Str = cavitySNs[1];
  7803. c1Part1Result_Check = 2;
  7804. c1Part2Result_Check = 2;
  7805. }
  7806. if (part1Str == "假产品")
  7807. c1Part1Result_Check = 3;
  7808. if (part2Str == "假产品")
  7809. c1Part2Result_Check = 3;
  7810. // 调用MES进站
  7811. stopwatch2.Start();
  7812. // 调用MES进站 - 产品1
  7813. List<TestItem> item;
  7814. int result1 = c1Part1Result_Check;
  7815. if (result1 != 3)
  7816. {
  7817. item = new List<TestItem>();
  7818. item.Add(new TestItem()
  7819. {
  7820. Parameter_name = "载具码",
  7821. Parameter_value = sn,
  7822. });
  7823. item.Add(new TestItem()
  7824. {
  7825. Parameter_name = "载具穴号",
  7826. Parameter_value = "1",
  7827. });
  7828. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  7829. part1Str, item, out string errorMsg);
  7830. }
  7831. // 调用MES进站 - 产品2
  7832. int result2 = c1Part2Result_Check;
  7833. if (result2 != 3)
  7834. {
  7835. item = new List<TestItem>();
  7836. item.Add(new TestItem()
  7837. {
  7838. Parameter_name = "载具码",
  7839. Parameter_value = sn,
  7840. });
  7841. item.Add(new TestItem()
  7842. {
  7843. Parameter_name = "载具穴号",
  7844. Parameter_value = "2",
  7845. });
  7846. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  7847. part2Str, item, out string errorMsg);
  7848. }
  7849. stopwatch2.Stop();
  7850. if (result1 == 2)
  7851. c1Part1Result_Check = 2;
  7852. if (result2 == 2)
  7853. c1Part2Result_Check = 2;
  7854. int result = result1;
  7855. if (result == 1)
  7856. result = result2;
  7857. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  7858. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  7859. short c1MES_FLAG_Check = (short)result;
  7860. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  7861. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  7862. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  7863. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  7864. //// MES_Flag
  7865. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7866. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7867. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  7868. writeToPLC_Flag.Adress = 2003;
  7869. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  7870. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7871. {
  7872. Name = "c1Part1Result_Check",
  7873. Adress = 2024,
  7874. ValueType = PLCValueType.Short,
  7875. Value = c1Part1Result_Check
  7876. });
  7877. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7878. {
  7879. Name = "c1Part2Result_Check",
  7880. Adress = 2025,
  7881. ValueType = PLCValueType.Short,
  7882. Value = c1Part2Result_Check
  7883. });
  7884. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7885. {
  7886. Name = "c1Part1Num_Check",
  7887. Adress = 2026,
  7888. ValueType = PLCValueType.Short,
  7889. Value = c1Part1Num_Check
  7890. });
  7891. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7892. {
  7893. Name = "c1Part2Num_Check",
  7894. Adress = 2027,
  7895. ValueType = PLCValueType.Short,
  7896. Value = c1Part2Num_Check
  7897. });
  7898. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  7899. }
  7900. catch (Exception ex)
  7901. {
  7902. string str = ex.StackTrace;
  7903. AddMessage_Station(stationNameStr, LogType.Error,
  7904. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  7905. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7906. // MES_Flag
  7907. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7908. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7909. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  7910. writeToPLC_Flag.Adress = 2003;
  7911. writeToPLC_Flag.Value = (short)6;
  7912. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  7913. }
  7914. stopwatch1.Stop();
  7915. AddMessage(LogType.Info,
  7916. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  7917. stopwatch2.ElapsedMilliseconds + "ms");
  7918. }
  7919. /// <summary>
  7920. /// [S3] 值板机 - 二穴载具解绑
  7921. /// </summary>
  7922. /// <param name="plcNo">PLC编号</param>
  7923. /// <param name="stationNameStr">工站全称</param>
  7924. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  7925. {
  7926. Stopwatch stopwatch1 = new Stopwatch();
  7927. Stopwatch stopwatch2 = new Stopwatch();
  7928. try
  7929. {
  7930. stopwatch1.Start();
  7931. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  7932. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  7933. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  7934. // 解绑
  7935. #region 查询载具上的产品信息
  7936. string cavityData = string.Empty;
  7937. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  7938. if (string.IsNullOrEmpty(cavityData))
  7939. cavityData = "";
  7940. if (snResult != 0)
  7941. {
  7942. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7943. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  7944. writeToPLC_Flag1.Adress = 2082;
  7945. writeToPLC_Flag1.Value = (short)6;
  7946. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  7947. stopwatch1.Stop();
  7948. AddMessage(LogType.Info,
  7949. stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  7950. "ms");
  7951. return;
  7952. }
  7953. #endregion 查询载具上的产品信息
  7954. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  7955. #region 解绑
  7956. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  7957. {
  7958. // 删除
  7959. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  7960. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  7961. }
  7962. else
  7963. {
  7964. string data_new = string.Join(".", cavitySNs);
  7965. // 删除再插入
  7966. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  7967. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  7968. OnMessage(LogType.Debug,
  7969. $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  7970. }
  7971. #endregion 解绑
  7972. short c1MES_FLAG_Unbind = 1;
  7973. stopwatch2.Start();
  7974. // MES_Flag
  7975. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7976. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7977. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  7978. writeToPLC_Flag.Adress = 2082;
  7979. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  7980. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  7981. stopwatch2.Stop();
  7982. }
  7983. catch (Exception ex)
  7984. {
  7985. string str = ex.StackTrace;
  7986. AddMessage_Station(stationNameStr, LogType.Error,
  7987. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" +
  7988. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7989. // MES_Flag
  7990. stopwatch2.Start();
  7991. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  7992. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7993. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  7994. writeToPLC_Flag.Adress = 2082;
  7995. writeToPLC_Flag.Value = (short)6;
  7996. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  7997. stopwatch2.Stop();
  7998. }
  7999. stopwatch1.Stop();
  8000. AddMessage(LogType.Info,
  8001. stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8002. stopwatch2.ElapsedMilliseconds + "ms");
  8003. }
  8004. /// <summary>
  8005. /// [S3] 值板机 - 二穴载具绑定
  8006. /// </summary>
  8007. /// <param name="plcNo">PLC编号</param>
  8008. /// <param name="stationNameStr">工站全称</param>
  8009. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  8010. {
  8011. Stopwatch stopwatch1 = new Stopwatch();
  8012. Stopwatch stopwatch2 = new Stopwatch();
  8013. try
  8014. {
  8015. stopwatch1.Start();
  8016. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  8017. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8018. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  8019. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  8020. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8021. stopwatch2.Start();
  8022. #region 查询载具上的产品信息
  8023. string cavityData = string.Empty;
  8024. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8025. if (string.IsNullOrEmpty(cavityData))
  8026. cavityData = "";
  8027. if (snResult != 0)
  8028. {
  8029. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8030. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  8031. writeToPLC_Flag1.Adress = 2115;
  8032. writeToPLC_Flag1.Value = (short)6;
  8033. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  8034. stopwatch1.Stop();
  8035. AddMessage(LogType.Info,
  8036. stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8037. "ms");
  8038. return;
  8039. }
  8040. #endregion 查询载具上的产品信息
  8041. // 产品换载具
  8042. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  8043. string partSn1 = "";
  8044. string partSn2 = "";
  8045. if (cavitySNs != null && cavitySNs.Length >= 2)
  8046. {
  8047. partSn1 = cavitySNs[0];
  8048. partSn2 = cavitySNs[1];
  8049. }
  8050. string data_new = string.Empty;
  8051. // 是否是两个穴位交换
  8052. if (c1CavityReverse_Bind == 1)
  8053. {
  8054. // 交换
  8055. data_new = string.Concat(partSn2, ".", partSn1);
  8056. }
  8057. else
  8058. {
  8059. // 不交换
  8060. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  8061. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  8062. cavitySNs[c1VehicleCavityFr_Bind] = "";
  8063. data_new = string.Join(".", cavitySNs);
  8064. }
  8065. // 删除再插入
  8066. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8067. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  8068. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  8069. stopwatch2.Stop();
  8070. short c1MES_FLAG_Bind = 1;
  8071. // MES_Flag
  8072. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8073. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8074. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  8075. writeToPLC_Flag.Adress = 2115;
  8076. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  8077. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  8078. }
  8079. catch (Exception ex)
  8080. {
  8081. string str = ex.StackTrace;
  8082. AddMessage_Station(stationNameStr, LogType.Error,
  8083. $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" +
  8084. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8085. // MES_Flag
  8086. stopwatch2.Start();
  8087. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  8088. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8089. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  8090. writeToPLC_Flag.Adress = 2115;
  8091. writeToPLC_Flag.Value = (short)6;
  8092. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  8093. stopwatch2.Stop();
  8094. }
  8095. stopwatch1.Stop();
  8096. AddMessage(LogType.Info,
  8097. stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8098. stopwatch2.ElapsedMilliseconds + "ms");
  8099. }
  8100. //// 上次采集到的SN
  8101. //private string sn_值板机 = string.Empty;
  8102. /// <summary>
  8103. /// [S3] 值板机 - 出站接口
  8104. /// </summary>
  8105. /// <param name="plcNo">PLC编号</param>
  8106. private void S3出站接口(int plcNo, string stationCode, string stationName)
  8107. {
  8108. Stopwatch stopwatch1 = new Stopwatch();
  8109. Stopwatch stopwatch2 = new Stopwatch();
  8110. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8111. string stationNameStr = stationCode + stationName;
  8112. string processItem = stationName; // 测试项目
  8113. try
  8114. {
  8115. stopwatch1.Start();
  8116. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8117. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8118. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8119. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8120. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  8121. sn = sn.Replace("\0", "");
  8122. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  8123. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8124. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8125. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  8126. bool pass = c1Result == 1;
  8127. // 查sn
  8128. #region 查询载具上的产品信息
  8129. string cavityData = string.Empty;
  8130. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8131. if (string.IsNullOrEmpty(cavityData))
  8132. cavityData = "";
  8133. if (snResult != 0)
  8134. {
  8135. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8136. writeToPLC_Flag1.Name = "c1MES_FLAG";
  8137. writeToPLC_Flag1.Adress = 2150;
  8138. writeToPLC_Flag1.Value = (short)4;
  8139. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  8140. stopwatch1.Stop();
  8141. AddMessage(LogType.Info,
  8142. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8143. return;
  8144. }
  8145. #endregion 查询载具上的产品信息
  8146. string[] cavitySNs = cavityData.Split('.');
  8147. string productSN = "";
  8148. if (cavitySNs != null && cavitySNs.Length >= 2)
  8149. {
  8150. productSN = cavitySNs[c1VehicleCavity];
  8151. cavitySNs[c1VehicleCavity] = "";
  8152. }
  8153. stopwatch2.Start();
  8154. List<TestItem> items = new List<TestItem>();
  8155. items.Add(new TestItem()
  8156. {
  8157. Parameter_name = "二穴载具码",
  8158. Parameter_value = c1ProductSN_Check,
  8159. Parameter_unit = ""
  8160. });
  8161. items.Add(new TestItem()
  8162. {
  8163. Parameter_name = "二穴载具穴号",
  8164. Parameter_value = c1VehicleCavity.ToString(),
  8165. Parameter_unit = ""
  8166. });
  8167. items.Add(new TestItem()
  8168. {
  8169. Parameter_name = "一穴载具码",
  8170. Parameter_value = sn,
  8171. Parameter_unit = ""
  8172. });
  8173. items.Add(new TestItem()
  8174. {
  8175. Parameter_name = "一穴载具穴号",
  8176. Parameter_value = "1",
  8177. Parameter_unit = ""
  8178. });
  8179. items.Add(new TestItem()
  8180. {
  8181. Parameter_name = "产品结果",
  8182. Parameter_value = c1Result == 1 ? "OK" : "NG",
  8183. Parameter_unit = ""
  8184. });
  8185. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  8186. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  8187. short result = (short)result1;
  8188. stopwatch2.Stop();
  8189. #region 存储绑定数据到 边线MES系统中
  8190. if (result == 1)
  8191. {
  8192. string data = string.Concat(productSN);
  8193. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  8194. if (resultMesR != 0)
  8195. {
  8196. result = 4;
  8197. AddMessage_Station(stationNameStr, LogType.Error,
  8198. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  8199. }
  8200. }
  8201. #endregion 存储绑定数据到 边线MES系统中
  8202. #region 产品从 来源载具(二穴载具)中删除
  8203. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  8204. {
  8205. // 删除
  8206. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8207. OnMessage(LogType.Debug,
  8208. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  8209. }
  8210. else
  8211. {
  8212. string data_new = string.Join(".", cavitySNs);
  8213. // 删除再插入
  8214. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8215. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  8216. OnMessage(LogType.Debug,
  8217. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  8218. }
  8219. #endregion 产品从 来源载具(二穴载具)中删除
  8220. // MES_Flag 为MES报错
  8221. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8222. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  8223. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8224. writeToPLC_Flag.Name = "c1MES_FLAG";
  8225. writeToPLC_Flag.Adress = 2150;
  8226. writeToPLC_Flag.Value = result;
  8227. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  8228. OnMessage(LogType.Debug,
  8229. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8230. }
  8231. catch (Exception ex)
  8232. {
  8233. stopwatch2.Restart();
  8234. // MES_Flag 为4上位机报错
  8235. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  8236. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8237. writeToPLC_Flag.Name = "c1MES_FLAG";
  8238. writeToPLC_Flag.Adress = 2150;
  8239. writeToPLC_Flag.Value = (short)4;
  8240. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  8241. stopwatch2.Stop();
  8242. string str = ex.StackTrace;
  8243. AddMessage_Station(stationNameStr, LogType.Error,
  8244. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  8245. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8246. }
  8247. stopwatch1.Stop();
  8248. AddMessage(LogType.Info,
  8249. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  8250. stopwatch2.ElapsedMilliseconds + "ms");
  8251. }
  8252. /// <summary>
  8253. /// [S3] 值板机- 节拍接口
  8254. /// </summary>
  8255. /// <param name="plcNo">PLC编号</param>
  8256. /// <param name="stationNameStr">工站全称</param>
  8257. private void S3节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  8258. {
  8259. Stopwatch stopwatch1 = new Stopwatch();
  8260. Stopwatch stopwatch2 = new Stopwatch();
  8261. string resultStr = string.Empty;
  8262. try
  8263. {
  8264. stopwatch1.Start();
  8265. string oEEType = ((int)s1PLCData["a3OEEType"]).ToString(); // 节拍类型(plc写入)
  8266. string a3OEEPartNo = (string)s1PLCData["a3OEEPartNo"]; // 物料码
  8267. a3OEEPartNo = a3OEEPartNo.Replace("\0", "");
  8268. string a3OEEVehicleCode = (string)s1PLCData["a3OEEVehicleCode"]; // 载具SN
  8269. a3OEEVehicleCode = a3OEEVehicleCode.Replace("\0", "");
  8270. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8271. if (!actionBool)
  8272. {
  8273. stopwatch2.Start();
  8274. //写入PLC
  8275. iot_data.beatReturn = 2; //NG
  8276. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8277. stopwatch2.Stop();
  8278. AddMessage(LogType.Info,
  8279. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  8280. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8281. return;
  8282. }
  8283. //作业开始后要有物料和载具信息
  8284. if (string.IsNullOrEmpty(a3OEEPartNo) && string.IsNullOrEmpty(a3OEEVehicleCode) &&
  8285. Convert.ToInt32(oEEType) > 2)
  8286. {
  8287. stopwatch2.Start();
  8288. //写入PLC
  8289. iot_data.beatReturn = 2; //NG
  8290. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8291. stopwatch2.Stop();
  8292. AddMessage_Station(stationNameStr, LogType.Info,
  8293. stationNameStr + $"_[{a3OEEVehicleCode}][{a3OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  8294. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8295. return;
  8296. }
  8297. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a3OEEPartNo))
  8298. {
  8299. stopwatch2.Start();
  8300. //写入PLC
  8301. iot_data.beatReturn = 2; //NG
  8302. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8303. stopwatch2.Stop();
  8304. AddMessage_Station(stationNameStr, LogType.Info,
  8305. stationNameStr + $"_[{a3OEEVehicleCode}][{a3OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  8306. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8307. return;
  8308. }
  8309. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a3OEEVehicleCode))
  8310. {
  8311. stopwatch2.Start();
  8312. //写入PLC
  8313. iot_data.beatReturn = 2; //NG
  8314. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8315. stopwatch2.Stop();
  8316. AddMessage_Station(stationNameStr, LogType.Info,
  8317. stationNameStr + $"_[{a3OEEVehicleCode}][{a3OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  8318. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8319. return;
  8320. }
  8321. short _result = 0;
  8322. // 上传OEE
  8323. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a3OEEPartNo, a3OEEVehicleCode);
  8324. _result = result.Item1;
  8325. resultStr = result.Item2;
  8326. if (_result == 1)
  8327. {
  8328. stopwatch2.Start();
  8329. //写入PLC
  8330. iot_data.beatReturn = 1; //OK
  8331. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8332. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  8333. stopwatch2.Stop();
  8334. }
  8335. else
  8336. {
  8337. stopwatch2.Start();
  8338. //写入PLC
  8339. iot_data.beatReturn = 2; //NG
  8340. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8341. stopwatch2.Stop();
  8342. AddMessage_Station(stationNameStr, LogType.Error,
  8343. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  8344. }
  8345. }
  8346. catch (Exception ex)
  8347. {
  8348. string str = ex.StackTrace;
  8349. AddMessage_Station(stationNameStr, LogType.Error,
  8350. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  8351. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8352. // MES_Flag
  8353. stopwatch2.Start();
  8354. //写入PLC
  8355. iot_data.beatReturn = 2; //NG
  8356. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8357. stopwatch2.Stop();
  8358. }
  8359. stopwatch1.Stop();
  8360. AddMessage(LogType.Info,
  8361. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8362. stopwatch2.ElapsedMilliseconds + "ms");
  8363. }
  8364. #endregion [S3] 值板机
  8365. #endregion PLC3 刘永村
  8366. #region PLC4 刘果段
  8367. #region [S4] 取放桁架
  8368. /// <summary>
  8369. /// S4工位的数据- 触发信号上次的值
  8370. /// </summary>
  8371. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  8372. /// <summary>
  8373. /// S4工位的数据(含触发信号)
  8374. /// </summary>
  8375. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  8376. /// <summary>
  8377. /// S4工位的数据- 回写点位
  8378. /// </summary>
  8379. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8380. /// <summary>
  8381. /// [S4] 取放桁架
  8382. /// </summary>
  8383. /// <param name="plcNo">PLC编号</param>
  8384. //private void ReadStation_S4(int plcNo)
  8385. //{
  8386. // // [S1] Tray盘上料装备
  8387. // // [S2] FCT
  8388. // // [S3] 值板机
  8389. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8390. // // [S5] Tray盘下料装备
  8391. // /// 上位机心跳
  8392. // /// 获取设备报警数据与状态信息
  8393. // string stationCode = "[S4_1]";
  8394. // string stationName = "载具下线装备";
  8395. // string stationNameStr = stationCode + stationName;
  8396. // string stationCode2 = "[S4_2]";
  8397. // string stationName2 = "桁架";
  8398. // string stationNameStr2 = stationCode2 + stationName2;
  8399. // string stationCode3 = "[S4_3]";
  8400. // string stationName3 = "提升机1";
  8401. // string stationNameStr3 = stationCode3 + stationName3;
  8402. // string stationCode4 = "[S4_4]";
  8403. // string stationName4 = "提升机2";
  8404. // string stationNameStr4 = stationCode4 + stationName4;
  8405. // string stationCode5 = "[S4_5]";
  8406. // string stationName5 = "载具上线装备";
  8407. // string stationNameStr5 = stationCode5 + stationName5;
  8408. // #region 创建字典
  8409. // // 触发信号字典 赋值
  8410. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  8411. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  8412. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8413. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8414. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  8415. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  8416. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  8417. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  8418. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  8419. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  8420. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8421. // // PLC数据字典 赋值
  8422. // // 载具下线装备(弹夹上线)
  8423. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  8424. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  8425. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  8426. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  8427. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8428. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  8429. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  8430. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  8431. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  8432. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  8433. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  8434. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  8435. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  8436. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  8437. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  8438. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  8439. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  8440. // s4PLCData.Add("d1Result", 0); // 产品结果
  8441. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8442. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  8443. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  8444. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  8445. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  8446. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  8447. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  8448. // // 真空标机(提升机)
  8449. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  8450. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  8451. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  8452. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  8453. // s4PLCData.Add("d3Result", 0); // 产品结果
  8454. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  8455. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  8456. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  8457. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  8458. // s4PLCData.Add("d4Result", 0); // 产品结果
  8459. // // 载具上线装备(弹夹下线)
  8460. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  8461. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  8462. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  8463. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  8464. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  8465. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  8466. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  8467. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  8468. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  8469. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  8470. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  8471. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  8472. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  8473. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  8474. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  8475. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  8476. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  8477. // s4PLCData.Add("d5Result", 0); // 产品结果
  8478. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8479. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  8480. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  8481. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  8482. // #endregion 创建字典
  8483. // while (IsRun)
  8484. // {
  8485. // try
  8486. // {
  8487. // if (!GlobalContext._IsCon_Funs4)
  8488. // {
  8489. // UpdatePLCMonitor(1, plcNo, 0);
  8490. // continue;
  8491. // }
  8492. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8493. // {
  8494. // Stopwatch stopwatch1 = new Stopwatch();
  8495. // Stopwatch stopwatch2 = new Stopwatch();
  8496. // stopwatch1.Start();
  8497. // stopwatch2.Start();
  8498. // #region 一次性读取所有数据
  8499. // // 载具下线装备(弹夹上线)
  8500. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8501. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  8502. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  8503. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  8504. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  8505. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  8506. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  8507. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  8508. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  8509. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  8510. // int[] datas = data1.Concat(data2).ToArray();
  8511. // datas = datas.Concat(data3).ToArray();
  8512. // datas = datas.Concat(data4).ToArray();
  8513. // datas = datas.Concat(data5).ToArray();
  8514. // datas = datas.Concat(data6).ToArray();
  8515. // datas = datas.Concat(data7).ToArray();
  8516. // datas = datas.Concat(data8).ToArray();
  8517. // datas = datas.Concat(data9).ToArray();
  8518. // datas = datas.Concat(data10).ToArray();
  8519. // // 载具下线装备(弹夹上线)
  8520. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  8521. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  8522. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  8523. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  8524. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  8525. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  8526. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  8527. // s4PLCData["d1MES_FLAG"] = datas[65];
  8528. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  8529. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  8530. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  8531. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  8532. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  8533. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  8534. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  8535. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  8536. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  8537. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  8538. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  8539. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  8540. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  8541. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  8542. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  8543. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  8544. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  8545. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  8546. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  8547. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  8548. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  8549. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  8550. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  8551. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  8552. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  8553. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  8554. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  8555. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  8556. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  8557. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  8558. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  8559. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  8560. // s4PLCData["d1Result"] = datas[386];
  8561. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  8562. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  8563. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  8564. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  8565. // s4PLCData["d1OEEType"] = datas[419];
  8566. // // 桁架(查询标机中弹夹的状态)
  8567. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  8568. // s4PLCData["d2BulletclipStates"] = datas[431];
  8569. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  8570. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  8571. // // 真空标机
  8572. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  8573. // s4PLCData["d3MES_FLAG"] = datas[463];
  8574. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  8575. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  8576. // s4PLCData["d3Result"] = datas[484];
  8577. // s4PLCData["d3Type"] = datas[485];
  8578. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  8579. // s4PLCData["d4MES_FLAG"] = datas[496];
  8580. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  8581. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  8582. // s4PLCData["d4Result"] = datas[517];
  8583. // s4PLCData["d4Type"] = datas[518];
  8584. // // 载具上线装备(弹夹下线)
  8585. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  8586. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  8587. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  8588. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  8589. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  8590. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  8591. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  8592. // s4PLCData["d5MES_FLAG"] = datas[591];
  8593. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  8594. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  8595. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  8596. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  8597. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  8598. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  8599. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  8600. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  8601. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  8602. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  8603. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  8604. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  8605. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  8606. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  8607. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  8608. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  8609. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  8610. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  8611. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  8612. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  8613. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  8614. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  8615. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  8616. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  8617. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  8618. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  8619. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  8620. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  8621. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  8622. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  8623. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  8624. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  8625. // s4PLCData["d5Result"] = datas[912];
  8626. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  8627. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  8628. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  8629. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  8630. // s4PLCData["d5OEEType"] = datas[945];
  8631. // #endregion 一次性读取所有数据
  8632. // stopwatch2.Stop();
  8633. // #region 回写操作,写后清空flag
  8634. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  8635. // #endregion 回写操作,写后清空flag
  8636. // // N801A-S4_1 弹夹扫码
  8637. // #region N801A-S4_1 弹夹扫码
  8638. // try
  8639. // {
  8640. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  8641. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  8642. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  8643. // {
  8644. // if (d1BulletclipScanCode == 1) // 0->1
  8645. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  8646. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  8647. // }
  8648. // }
  8649. // catch (Exception ex)
  8650. // {
  8651. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  8652. // string str = ex.StackTrace;
  8653. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8654. // }
  8655. // #endregion N801A-S4_1 弹夹扫码
  8656. // // N801A-S4_1 载具扫码
  8657. // #region N801A-S4_1 载具扫码
  8658. // try
  8659. // {
  8660. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  8661. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  8662. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  8663. // {
  8664. // if (d1VehicleScanCode == 1) // 0->1
  8665. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  8666. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  8667. // }
  8668. // }
  8669. // catch (Exception ex)
  8670. // {
  8671. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  8672. // string str = ex.StackTrace;
  8673. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8674. // }
  8675. // #endregion N801A-S4_1 载具扫码
  8676. // // N801A-S4_1 出站接口
  8677. // #region N801A-S4_1 出站接口
  8678. // try
  8679. // {
  8680. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  8681. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  8682. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  8683. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  8684. // {
  8685. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  8686. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8687. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  8688. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  8689. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  8690. // }
  8691. // }
  8692. // catch (Exception ex)
  8693. // {
  8694. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  8695. // string str = ex.StackTrace;
  8696. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8697. // }
  8698. // #endregion N801A-S4_1 出站接口
  8699. // // N801A-S4_1 节拍接口
  8700. // #region N801A-S4_1 节拍接口
  8701. // try
  8702. // {
  8703. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  8704. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  8705. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  8706. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  8707. // {
  8708. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  8709. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8710. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  8711. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  8712. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  8713. // }
  8714. // }
  8715. // catch (Exception ex)
  8716. // {
  8717. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  8718. // string str = ex.StackTrace;
  8719. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8720. // }
  8721. // #endregion N801A-S4_1 节拍接口
  8722. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  8723. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  8724. // try
  8725. // {
  8726. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  8727. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  8728. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  8729. // {
  8730. // if (d2BulletclipScanCode == 1) // 0->1
  8731. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  8732. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  8733. // }
  8734. // }
  8735. // catch (Exception ex)
  8736. // {
  8737. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  8738. // string str = ex.StackTrace;
  8739. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8740. // }
  8741. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  8742. // // N801A-S4_3 真空标机1 数据
  8743. // #region N801A-S4_3 真空标机1
  8744. // try
  8745. // {
  8746. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  8747. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  8748. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  8749. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  8750. // {
  8751. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  8752. // {
  8753. // int stationType = (int)s4PLCData["d3Type"];
  8754. // if (stationType == 1)
  8755. // {
  8756. // // S4_3进站接口
  8757. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  8758. // }
  8759. // else if (stationType == 2)
  8760. // {
  8761. // // S4_3出站接口
  8762. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  8763. // }
  8764. // }
  8765. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  8766. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  8767. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  8768. // }
  8769. // }
  8770. // catch (Exception ex)
  8771. // {
  8772. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  8773. // string str = ex.StackTrace;
  8774. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8775. // }
  8776. // #endregion N801A-S4_3 真空标机1
  8777. // // N801A-S4_4 真空标机2 数据
  8778. // #region N801A-S4_4 真空标机2
  8779. // try
  8780. // {
  8781. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  8782. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  8783. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  8784. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  8785. // {
  8786. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  8787. // {
  8788. // int stationType = (int)s4PLCData["d4Type"];
  8789. // if (stationType == 1)
  8790. // {
  8791. // // S4_4进站接口
  8792. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  8793. // }
  8794. // else if (stationType == 2)
  8795. // {
  8796. // // S4_4出站接口
  8797. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  8798. // }
  8799. // }
  8800. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  8801. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  8802. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  8803. // }
  8804. // }
  8805. // catch (Exception ex)
  8806. // {
  8807. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8808. // string str = ex.StackTrace;
  8809. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8810. // }
  8811. // #endregion N801A-S4_4 真空标机2
  8812. // // N801A-S4_5 弹夹扫码 数据
  8813. // #region N801A-S4_5 弹夹扫码
  8814. // try
  8815. // {
  8816. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  8817. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  8818. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  8819. // {
  8820. // if (d5BulletclipScanCode == 1) // 0->1
  8821. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  8822. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  8823. // }
  8824. // }
  8825. // catch (Exception ex)
  8826. // {
  8827. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  8828. // string str = ex.StackTrace;
  8829. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8830. // }
  8831. // #endregion N801A-S4_5 弹夹扫码
  8832. // // N801A-S4_5 载具扫码 数据
  8833. // #region N801A-S4_5 载具扫码
  8834. // try
  8835. // {
  8836. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  8837. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  8838. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  8839. // {
  8840. // if (d5VehicleScanCode == 1) // 0->1
  8841. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  8842. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  8843. // }
  8844. // }
  8845. // catch (Exception ex)
  8846. // {
  8847. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  8848. // string str = ex.StackTrace;
  8849. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8850. // }
  8851. // #endregion N801A-S4_5 载具扫码
  8852. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  8853. // #region N801A-S4_5 出站接口
  8854. // try
  8855. // {
  8856. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  8857. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  8858. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  8859. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  8860. // {
  8861. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  8862. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  8863. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  8864. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  8865. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  8866. // }
  8867. // }
  8868. // catch (Exception ex)
  8869. // {
  8870. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  8871. // string str = ex.StackTrace;
  8872. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8873. // }
  8874. // #endregion N801A-S4_5 出站接口
  8875. // // N801A-S4_5 节拍接口 数据
  8876. // #region N801A-S4_5 节拍接口
  8877. // try
  8878. // {
  8879. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  8880. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  8881. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  8882. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  8883. // {
  8884. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  8885. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  8886. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  8887. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  8888. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  8889. // }
  8890. // }
  8891. // catch (Exception ex)
  8892. // {
  8893. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  8894. // string str = ex.StackTrace;
  8895. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8896. // }
  8897. // #endregion N801A-S4_5 节拍接口
  8898. // #region 心跳
  8899. // try
  8900. // {
  8901. // short states = 0;
  8902. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  8903. // }
  8904. // catch (Exception ex)
  8905. // {
  8906. // string str = ex.StackTrace;
  8907. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8908. // }
  8909. // #endregion 心跳
  8910. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  8911. // stopwatch1.Stop();
  8912. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  8913. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  8914. // }
  8915. // else
  8916. // {
  8917. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8918. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  8919. // Funs[plcNo].Connect();
  8920. // }
  8921. // }
  8922. // catch (Exception ex)
  8923. // {
  8924. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8925. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  8926. // Funs[plcNo].ReConnect();
  8927. // }
  8928. // Thread.Sleep(IntervalReadPLC);
  8929. // }
  8930. //}
  8931. /// <summary>
  8932. /// [S4] 取放桁架 - S4_1弹夹扫码
  8933. /// </summary>
  8934. /// <param name="plcNo">PLC编号</param>
  8935. /// <param name="stationNameStr">工站全称</param>
  8936. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  8937. {
  8938. Stopwatch stopwatch1 = new Stopwatch();
  8939. Stopwatch stopwatch2 = new Stopwatch();
  8940. try
  8941. {
  8942. stopwatch1.Start();
  8943. // ZS 弹夹扫码
  8944. string d1BulletclipCode = " "; // 扫到的码
  8945. short d1BulletclipScanCode = 2;
  8946. stopwatch2.Start();
  8947. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  8948. //// MES_Flag
  8949. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8950. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8951. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  8952. writeToPLC_Flag.Adress = 2002;
  8953. writeToPLC_Flag.Value = d1BulletclipScanCode;
  8954. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  8955. {
  8956. Name = "d1BulletclipCode",
  8957. Adress = 2003,
  8958. ValueType = PLCValueType.String,
  8959. ValueTypeStrLength = 20,
  8960. Value = d1BulletclipCode
  8961. });
  8962. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  8963. stopwatch2.Stop();
  8964. }
  8965. catch (Exception ex)
  8966. {
  8967. string str = ex.StackTrace;
  8968. AddMessage_Station(stationNameStr, LogType.Error,
  8969. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  8970. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8971. stopwatch2.Start();
  8972. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  8973. //// MES_Flag
  8974. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  8975. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8976. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  8977. writeToPLC_Flag.Adress = 2002;
  8978. writeToPLC_Flag.Value = (short)6;
  8979. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  8980. {
  8981. Name = "d1BulletclipCode",
  8982. Adress = 2003,
  8983. ValueType = PLCValueType.String,
  8984. ValueTypeStrLength = 20,
  8985. Value = " "
  8986. });
  8987. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  8988. stopwatch2.Stop();
  8989. }
  8990. stopwatch1.Stop();
  8991. AddMessage(LogType.Info,
  8992. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8993. stopwatch2.ElapsedMilliseconds + "ms");
  8994. }
  8995. /// <summary>
  8996. /// [S4] 取放桁架 - S4_1载具扫码
  8997. /// </summary>
  8998. /// <param name="plcNo">PLC编号</param>
  8999. /// <param name="stationNameStr">工站全称</param>
  9000. private void S4_1载具扫码(int plcNo, string stationNameStr)
  9001. {
  9002. Stopwatch stopwatch1 = new Stopwatch();
  9003. Stopwatch stopwatch2 = new Stopwatch();
  9004. try
  9005. {
  9006. stopwatch1.Start();
  9007. // ZS 载具扫码
  9008. string d1VehicleCode = ""; // 扫到的码
  9009. short d1VehicleScanCode = 2;
  9010. #region 进站
  9011. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  9012. {
  9013. #region 查询载具上的产品信息
  9014. string cavityData = string.Empty;
  9015. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  9016. if (string.IsNullOrEmpty(cavityData))
  9017. cavityData = "";
  9018. if (snResult != 0)
  9019. {
  9020. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9021. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  9022. writeToPLC_Flag1.Adress = 2033;
  9023. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  9024. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9025. {
  9026. Name = "d1VehicleCode",
  9027. Adress = 2034,
  9028. ValueType = PLCValueType.String,
  9029. ValueTypeStrLength = 20,
  9030. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  9031. });
  9032. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  9033. stopwatch1.Stop();
  9034. AddMessage(LogType.Info,
  9035. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9036. "ms");
  9037. return;
  9038. }
  9039. string[] cavitySNs = cavityData.Split('.');
  9040. string partNo = "";
  9041. if (cavitySNs != null && cavitySNs.Length >= 1)
  9042. {
  9043. partNo = cavitySNs[0];
  9044. }
  9045. #endregion 查询载具上的产品信息
  9046. List<TestItem> item = new List<TestItem>();
  9047. item.Add(new TestItem()
  9048. {
  9049. Parameter_name = "载具码",
  9050. Parameter_value = d1VehicleCode,
  9051. });
  9052. item.Add(new TestItem()
  9053. {
  9054. Parameter_name = "载具穴号",
  9055. Parameter_value = "1",
  9056. });
  9057. stopwatch2.Start();
  9058. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  9059. partNo, item, out string errorMsg);
  9060. stopwatch2.Stop();
  9061. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  9062. }
  9063. #endregion 进站
  9064. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  9065. //// MES_Flag
  9066. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  9067. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9068. writeToPLC_Flag.Name = "d1VehicleScanCode";
  9069. writeToPLC_Flag.Adress = 2033;
  9070. writeToPLC_Flag.Value = d1VehicleScanCode;
  9071. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9072. {
  9073. Name = "d1VehicleCode",
  9074. Adress = 2034,
  9075. ValueType = PLCValueType.String,
  9076. ValueTypeStrLength = 20,
  9077. Value = d1VehicleCode
  9078. });
  9079. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  9080. }
  9081. catch (Exception ex)
  9082. {
  9083. string str = ex.StackTrace;
  9084. AddMessage_Station(stationNameStr, LogType.Error,
  9085. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  9086. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9087. stopwatch2.Start();
  9088. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  9089. //// MES_Flag
  9090. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  9091. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9092. writeToPLC_Flag.Name = "d1VehicleScanCode";
  9093. writeToPLC_Flag.Adress = 2033;
  9094. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  9095. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9096. {
  9097. Name = "d1VehicleCode",
  9098. Adress = 2034,
  9099. ValueType = PLCValueType.String,
  9100. ValueTypeStrLength = 20,
  9101. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  9102. });
  9103. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  9104. stopwatch2.Stop();
  9105. }
  9106. stopwatch1.Stop();
  9107. AddMessage(LogType.Info,
  9108. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9109. stopwatch2.ElapsedMilliseconds + "ms");
  9110. }
  9111. // 上次采集到的SN
  9112. //private string sn_S4_1出站接口 = string.Empty;
  9113. /// <summary>
  9114. /// [S4] 取放桁架 - S4_1出站接口
  9115. /// </summary>
  9116. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  9117. {
  9118. Stopwatch stopwatch1 = new Stopwatch();
  9119. Stopwatch stopwatch2 = new Stopwatch();
  9120. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9121. string stationNameStr = stationCode + stationName;
  9122. string processItem = stationName; // 测试项目
  9123. try
  9124. {
  9125. stopwatch1.Start();
  9126. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9127. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9128. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9129. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9130. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  9131. sn = sn.Replace("\0", "");
  9132. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  9133. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  9134. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  9135. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  9136. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  9137. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  9138. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  9139. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  9140. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  9141. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  9142. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  9143. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  9144. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  9145. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  9146. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  9147. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  9148. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  9149. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  9150. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  9151. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  9152. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  9153. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  9154. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  9155. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  9156. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  9157. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  9158. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  9159. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  9160. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  9161. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  9162. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  9163. bool pass = d1Result == 1;
  9164. // 存 载具SN列表
  9165. List<string> vehicleCodes = new List<string>()
  9166. {
  9167. d1VehicleCode1, d1VehicleCode2, d1VehicleCode3, d1VehicleCode4, d1VehicleCode5,
  9168. d1VehicleCode6, d1VehicleCode7, d1VehicleCode8, d1VehicleCode9, d1VehicleCode10,
  9169. d1VehicleCode11, d1VehicleCode12, d1VehicleCode13, d1VehicleCode14, d1VehicleCode15
  9170. };
  9171. // 统一查 产品SN列表
  9172. List<string> partNos = new List<string>();
  9173. foreach (string vehicleCode in vehicleCodes)
  9174. {
  9175. if (string.IsNullOrEmpty(vehicleCode))
  9176. partNos.Add("");
  9177. else
  9178. {
  9179. string partNo = "";
  9180. #region 查询载具上的产品信息
  9181. string cavityData = string.Empty;
  9182. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  9183. if (string.IsNullOrEmpty(cavityData))
  9184. cavityData = "";
  9185. if (snResult != 0)
  9186. {
  9187. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9188. writeToPLC_Flag1.Name = "d1MES_FLAG";
  9189. writeToPLC_Flag1.Adress = 2065;
  9190. writeToPLC_Flag1.Value = (short)4;
  9191. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  9192. stopwatch1.Stop();
  9193. AddMessage(LogType.Info,
  9194. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9195. "ms");
  9196. return;
  9197. }
  9198. string[] cavitySNs = cavityData.Split('.');
  9199. if (cavitySNs != null && cavitySNs.Length >= 1)
  9200. partNo = cavitySNs[0];
  9201. #endregion 查询载具上的产品信息
  9202. partNos.Add(partNo);
  9203. }
  9204. }
  9205. // 统一上传
  9206. stopwatch2.Start();
  9207. List<int> results = new List<int>();
  9208. for (int i = 0; i < partNos.Count; i++)
  9209. {
  9210. string index = (i + 1).ToString(); // 弹夹穴号
  9211. if (string.IsNullOrEmpty(partNos[i]))
  9212. results.Add(1);
  9213. else
  9214. {
  9215. List<TestItem> items1 = new List<TestItem>();
  9216. items1.Add(new TestItem()
  9217. {
  9218. Parameter_name = "弹夹码",
  9219. Parameter_value = sn,
  9220. Parameter_unit = ""
  9221. });
  9222. items1.Add(new TestItem()
  9223. {
  9224. Parameter_name = "弹夹穴号",
  9225. Parameter_value = index,
  9226. Parameter_unit = ""
  9227. });
  9228. items1.Add(new TestItem()
  9229. {
  9230. Parameter_name = "载具码",
  9231. Parameter_value = vehicleCodes[i],
  9232. Parameter_unit = ""
  9233. });
  9234. items1.Add(new TestItem()
  9235. {
  9236. Parameter_name = "载具穴号",
  9237. Parameter_value = "1",
  9238. Parameter_unit = ""
  9239. });
  9240. items1.Add(new TestItem()
  9241. {
  9242. Parameter_name = "产品结果",
  9243. Parameter_value = d1Result == 1 ? "OK" : "NG",
  9244. Parameter_unit = ""
  9245. });
  9246. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  9247. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  9248. results.Add(result1);
  9249. }
  9250. }
  9251. short result = 0;
  9252. if (results.All(a => a == 1))
  9253. result = 1;
  9254. else if (results.Contains(3))
  9255. result = 3;
  9256. else if (results.Contains(2))
  9257. result = 2;
  9258. else if (results.Contains(4))
  9259. result = 4;
  9260. else
  9261. result = 4;
  9262. stopwatch2.Stop();
  9263. #region 存储绑定数据到 边线MES系统中
  9264. if (result == 1)
  9265. {
  9266. string data = string.Join(".", vehicleCodes);
  9267. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  9268. if (resultMesR != 0)
  9269. {
  9270. result = 4;
  9271. AddMessage_Station(stationNameStr, LogType.Error,
  9272. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  9273. }
  9274. }
  9275. #endregion 存储绑定数据到 边线MES系统中
  9276. // MES_Flag 为4MES报错
  9277. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9278. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9279. writeToPLC_Flag.Name = "d1MES_FLAG";
  9280. writeToPLC_Flag.Adress = 2065;
  9281. writeToPLC_Flag.Value = result;
  9282. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  9283. OnMessage(LogType.Debug,
  9284. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9285. }
  9286. catch (Exception ex)
  9287. {
  9288. stopwatch2.Restart();
  9289. // MES_Flag 为4上位机报错
  9290. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  9291. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9292. writeToPLC_Flag.Name = "d1MES_FLAG";
  9293. writeToPLC_Flag.Adress = 2065;
  9294. writeToPLC_Flag.Value = (short)4;
  9295. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  9296. stopwatch2.Stop();
  9297. string str = ex.StackTrace;
  9298. AddMessage_Station(stationNameStr, LogType.Error,
  9299. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  9300. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9301. }
  9302. stopwatch1.Stop();
  9303. AddMessage(LogType.Info,
  9304. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  9305. stopwatch2.ElapsedMilliseconds + "ms");
  9306. }
  9307. /// <summary>
  9308. /// [S4] 取放桁架 - S4_1节拍接口
  9309. /// </summary>
  9310. /// <param name="plcNo">PLC编号</param>
  9311. /// <param name="stationNameStr">工站全称</param>
  9312. private void S4_1节拍接口(int plcNo, string stationNameStr)
  9313. {
  9314. Stopwatch stopwatch1 = new Stopwatch();
  9315. Stopwatch stopwatch2 = new Stopwatch();
  9316. string resultStr = string.Empty;
  9317. try
  9318. {
  9319. stopwatch1.Start();
  9320. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  9321. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  9322. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  9323. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9324. if (!actionBool)
  9325. {
  9326. stopwatch2.Start();
  9327. // MES_Flag
  9328. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9329. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9330. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  9331. writeToPLC_Flag1.Adress = 2398;
  9332. writeToPLC_Flag1.Value = (short)4;
  9333. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  9334. stopwatch2.Stop();
  9335. AddMessage(LogType.Info,
  9336. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  9337. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9338. return;
  9339. }
  9340. string d1OEEPartNo = string.Empty; // 物料码
  9341. if (string.IsNullOrEmpty(d1OEEProductSN))
  9342. {
  9343. stopwatch2.Start();
  9344. // MES_Flag
  9345. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9346. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9347. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  9348. writeToPLC_Flag1.Adress = 2398;
  9349. writeToPLC_Flag1.Value = (short)1;
  9350. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  9351. stopwatch2.Stop();
  9352. AddMessage(LogType.Info,
  9353. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9354. stopwatch2.ElapsedMilliseconds + "ms");
  9355. return;
  9356. }
  9357. else
  9358. {
  9359. // 查产品SN ZS
  9360. d1OEEPartNo = "Test";
  9361. }
  9362. short d1OEEMES_FLAG = 0;
  9363. // 上传OEE
  9364. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  9365. d1OEEMES_FLAG = result.Item1;
  9366. resultStr = result.Item2;
  9367. stopwatch2.Start();
  9368. // MES_Flag
  9369. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9370. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9371. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  9372. writeToPLC_Flag.Adress = 2398;
  9373. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  9374. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  9375. stopwatch2.Stop();
  9376. }
  9377. catch (Exception ex)
  9378. {
  9379. string str = ex.StackTrace;
  9380. AddMessage_Station(stationNameStr, LogType.Error,
  9381. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  9382. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9383. // MES_Flag
  9384. stopwatch2.Start();
  9385. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  9386. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9387. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  9388. writeToPLC_Flag.Adress = 2398;
  9389. writeToPLC_Flag.Value = (short)4;
  9390. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  9391. stopwatch2.Stop();
  9392. }
  9393. stopwatch1.Stop();
  9394. AddMessage(LogType.Info,
  9395. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9396. stopwatch2.ElapsedMilliseconds + "ms");
  9397. }
  9398. /// <summary>
  9399. /// [S4] 取放桁架 - S4_2桁架
  9400. /// </summary>
  9401. /// <param name="plcNo">PLC编号</param>
  9402. /// <param name="stationNameStr">工站全称</param>
  9403. private void S4_2桁架(int plcNo, string stationNameStr)
  9404. {
  9405. Stopwatch stopwatch1 = new Stopwatch();
  9406. Stopwatch stopwatch2 = new Stopwatch();
  9407. try
  9408. {
  9409. stopwatch1.Start();
  9410. // ZS 弹夹扫码
  9411. string d2BulletclipCode = " "; // 扫到的码
  9412. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  9413. short d2BulletclipScanCode = 2;
  9414. stopwatch2.Start();
  9415. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  9416. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  9417. //// MES_Flag
  9418. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  9419. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9420. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  9421. writeToPLC_Flag.Adress = 2430;
  9422. writeToPLC_Flag.Value = d2BulletclipScanCode;
  9423. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9424. {
  9425. Name = "d2BulletclipCode",
  9426. Adress = 2432,
  9427. ValueType = PLCValueType.String,
  9428. ValueTypeStrLength = 20,
  9429. Value = d2BulletclipCode
  9430. });
  9431. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9432. {
  9433. Name = "d2BulletclipStates",
  9434. Adress = 2431,
  9435. ValueType = PLCValueType.Short,
  9436. Value = d2BulletclipStates
  9437. });
  9438. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  9439. stopwatch2.Stop();
  9440. }
  9441. catch (Exception ex)
  9442. {
  9443. string str = ex.StackTrace;
  9444. AddMessage_Station(stationNameStr, LogType.Error,
  9445. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  9446. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9447. stopwatch2.Start();
  9448. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  9449. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  9450. // MES_Flag
  9451. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  9452. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9453. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  9454. writeToPLC_Flag.Adress = 2430;
  9455. writeToPLC_Flag.Value = (short)6;
  9456. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9457. {
  9458. Name = "d2BulletclipCode",
  9459. Adress = 2432,
  9460. ValueType = PLCValueType.String,
  9461. ValueTypeStrLength = 20,
  9462. Value = " "
  9463. });
  9464. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9465. {
  9466. Name = "d2BulletclipStates",
  9467. Adress = 2431,
  9468. ValueType = PLCValueType.Short,
  9469. Value = (short)0
  9470. });
  9471. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  9472. stopwatch2.Stop();
  9473. }
  9474. stopwatch1.Stop();
  9475. AddMessage(LogType.Info,
  9476. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9477. stopwatch2.ElapsedMilliseconds + "ms");
  9478. }
  9479. // 上次采集到的SN
  9480. //private string sn_S4_3进站接口 = string.Empty;
  9481. /// <summary>
  9482. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  9483. /// </summary>
  9484. private void S4_3进站接口(int plcNo, string stationNameStr)
  9485. {
  9486. Stopwatch stopwatch1 = new Stopwatch();
  9487. Stopwatch stopwatch2 = new Stopwatch();
  9488. try
  9489. {
  9490. stopwatch1.Start();
  9491. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  9492. sn = sn.Replace("\0", "");
  9493. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  9494. #region 查询15个载具码
  9495. List<string> vehicleCodes = new List<string>(); // 15个载具码
  9496. string vehicleData = string.Empty;
  9497. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  9498. if (string.IsNullOrEmpty(vehicleData))
  9499. vehicleData = "";
  9500. if (snResult != 0)
  9501. {
  9502. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9503. writeToPLC_Flag1.Name = "d3MES_FLAG";
  9504. writeToPLC_Flag1.Adress = 2463;
  9505. writeToPLC_Flag1.Value = (short)4;
  9506. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  9507. stopwatch1.Stop();
  9508. AddMessage(LogType.Info,
  9509. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9510. return;
  9511. }
  9512. string[] cavitySNs = vehicleData.Split('.');
  9513. if (cavitySNs != null && cavitySNs.Length > 0)
  9514. {
  9515. for (int i = 0; i < cavitySNs.Length; i++)
  9516. {
  9517. if (string.IsNullOrEmpty(cavitySNs[i]))
  9518. vehicleCodes.Add("");
  9519. else
  9520. vehicleCodes.Add(cavitySNs[i]);
  9521. }
  9522. }
  9523. #endregion 查询15个载具码
  9524. #region 查询15个产品SN
  9525. List<string> portNos = new List<string>(); // 15个产品SN
  9526. foreach (string vehicleCode in vehicleCodes)
  9527. {
  9528. if (string.IsNullOrEmpty(vehicleCode))
  9529. portNos.Add("");
  9530. else
  9531. {
  9532. // 查询
  9533. string cavityData = string.Empty;
  9534. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  9535. if (string.IsNullOrEmpty(cavityData))
  9536. cavityData = "";
  9537. if (snResult1 != 0)
  9538. {
  9539. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9540. writeToPLC_Flag1.Name = "d3MES_FLAG";
  9541. writeToPLC_Flag1.Adress = 2463;
  9542. writeToPLC_Flag1.Value = (short)4;
  9543. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  9544. stopwatch1.Stop();
  9545. AddMessage(LogType.Info,
  9546. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  9547. stopwatch1.ElapsedMilliseconds + "ms");
  9548. return;
  9549. }
  9550. string[] partSNs = cavityData.Split('.');
  9551. if (partSNs != null && partSNs.Length >= 1)
  9552. portNos.Add(partSNs[0]);
  9553. else
  9554. portNos.Add("");
  9555. }
  9556. }
  9557. #endregion 查询15个产品SN
  9558. // 调用MES进站(最多15个)
  9559. stopwatch2.Start();
  9560. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  9561. for (int i = 0; i < vehicleCodes.Count; i++)
  9562. {
  9563. // 循环进站
  9564. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  9565. {
  9566. // 产品SN(物料码)校验
  9567. string portNo = portNos[i];
  9568. List<TestItem> item = new List<TestItem>();
  9569. item.Add(new TestItem()
  9570. {
  9571. Parameter_name = "弹夹码",
  9572. Parameter_value = sn,
  9573. });
  9574. item.Add(new TestItem()
  9575. {
  9576. Parameter_name = "弹夹穴位",
  9577. Parameter_value = (i + 1).ToString(),
  9578. });
  9579. item.Add(new TestItem()
  9580. {
  9581. Parameter_name = "载具码",
  9582. Parameter_value = vehicleCodes[i],
  9583. });
  9584. item.Add(new TestItem()
  9585. {
  9586. Parameter_name = "载具穴号",
  9587. Parameter_value = "1",
  9588. });
  9589. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  9590. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  9591. }
  9592. }
  9593. stopwatch2.Stop();
  9594. short result = 0;
  9595. bool haveMesWarn = results.Contains(5);
  9596. bool havePCWarn = results.Contains(6);
  9597. if (haveMesWarn)
  9598. result = 2; // 5->2
  9599. else if (havePCWarn)
  9600. result = 6; // 6->4
  9601. else
  9602. result = 1;
  9603. // MES_Flag 为4MES报错
  9604. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9605. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9606. writeToPLC_Flag.Name = "d3MES_FLAG";
  9607. writeToPLC_Flag.Adress = 2463;
  9608. writeToPLC_Flag.Value = result;
  9609. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  9610. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  9611. }
  9612. catch (Exception ex)
  9613. {
  9614. stopwatch2.Stop();
  9615. // MES_Flag 为4上位机报错
  9616. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  9617. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9618. writeToPLC_Flag.Name = "d3MES_FLAG";
  9619. writeToPLC_Flag.Adress = 2463;
  9620. writeToPLC_Flag.Value = (short)4;
  9621. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  9622. string str = ex.StackTrace;
  9623. AddMessage_Station(stationNameStr, LogType.Error,
  9624. $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  9625. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9626. }
  9627. stopwatch1.Stop();
  9628. AddMessage(LogType.Info,
  9629. stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  9630. stopwatch2.ElapsedMilliseconds + "ms");
  9631. }
  9632. // 上次采集到的SN
  9633. //private string sn_S4_3出站接口 = string.Empty;
  9634. /// <summary>
  9635. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  9636. /// </summary>
  9637. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  9638. {
  9639. Stopwatch stopwatch1 = new Stopwatch();
  9640. Stopwatch stopwatch2 = new Stopwatch();
  9641. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9642. string stationNameStr = stationCode + stationName;
  9643. string processItem = stationName; // 测试项目
  9644. try
  9645. {
  9646. stopwatch1.Start();
  9647. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9648. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9649. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9650. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9651. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  9652. sn = sn.Replace("\0", "");
  9653. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  9654. bool isPass = d3Result == 1; // 产品结果 bool
  9655. #region 查询15个载具码
  9656. List<string> vehicleCodes = new List<string>(); // 15个载具码
  9657. string vehicleData = string.Empty;
  9658. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  9659. if (string.IsNullOrEmpty(vehicleData))
  9660. vehicleData = "";
  9661. if (snResult1 != 0)
  9662. {
  9663. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9664. writeToPLC_Flag1.Name = "d3MES_FLAG";
  9665. writeToPLC_Flag1.Adress = 2463;
  9666. writeToPLC_Flag1.Value = (short)4;
  9667. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  9668. stopwatch1.Stop();
  9669. AddMessage(LogType.Info,
  9670. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9671. return;
  9672. }
  9673. string[] cavitySNs = vehicleData.Split('.');
  9674. if (cavitySNs != null && cavitySNs.Length > 0)
  9675. {
  9676. for (int i = 0; i < cavitySNs.Length; i++)
  9677. {
  9678. if (string.IsNullOrEmpty(cavitySNs[i]))
  9679. vehicleCodes.Add("");
  9680. else
  9681. vehicleCodes.Add(cavitySNs[i]);
  9682. }
  9683. }
  9684. #endregion 查询15个载具码
  9685. // 统一查 产品SN列表
  9686. List<string> partNos = new List<string>();
  9687. foreach (string vehicleCode in vehicleCodes)
  9688. {
  9689. if (string.IsNullOrEmpty(vehicleCode))
  9690. partNos.Add("");
  9691. else
  9692. {
  9693. string partNo = "";
  9694. #region 查询载具上的产品信息
  9695. string cavityData = string.Empty;
  9696. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  9697. if (string.IsNullOrEmpty(cavityData))
  9698. cavityData = "";
  9699. if (snResult != 0)
  9700. {
  9701. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9702. writeToPLC_Flag1.Name = "d3MES_FLAG";
  9703. writeToPLC_Flag1.Adress = 2463;
  9704. writeToPLC_Flag1.Value = (short)4;
  9705. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  9706. stopwatch1.Stop();
  9707. AddMessage(LogType.Info,
  9708. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9709. "ms");
  9710. return;
  9711. }
  9712. string[] partSNs = cavityData.Split('.');
  9713. if (partSNs != null && partSNs.Length >= 1)
  9714. partNo = partSNs[0];
  9715. #endregion 查询载具上的产品信息
  9716. partNos.Add(partNo);
  9717. }
  9718. }
  9719. // 统一上传 - 调用MES出站
  9720. stopwatch2.Start();
  9721. List<int> results = new List<int>();
  9722. for (int i = 0; i < partNos.Count; i++)
  9723. {
  9724. string index = (i + 1).ToString(); // 弹夹穴号
  9725. if (string.IsNullOrEmpty(partNos[i]))
  9726. results.Add(1);
  9727. else
  9728. {
  9729. List<TestItem> items1 = new List<TestItem>();
  9730. items1.Add(new TestItem()
  9731. {
  9732. Parameter_name = "弹夹码",
  9733. Parameter_value = sn,
  9734. Parameter_unit = ""
  9735. });
  9736. items1.Add(new TestItem()
  9737. {
  9738. Parameter_name = "弹夹穴号",
  9739. Parameter_value = index,
  9740. Parameter_unit = ""
  9741. });
  9742. items1.Add(new TestItem()
  9743. {
  9744. Parameter_name = "载具码",
  9745. Parameter_value = vehicleCodes[i],
  9746. Parameter_unit = ""
  9747. });
  9748. items1.Add(new TestItem()
  9749. {
  9750. Parameter_name = "载具穴号",
  9751. Parameter_value = "1",
  9752. Parameter_unit = ""
  9753. });
  9754. items1.Add(new TestItem()
  9755. {
  9756. Parameter_name = "产品结果",
  9757. Parameter_value = d3Result == 1 ? "OK" : "NG",
  9758. Parameter_unit = ""
  9759. });
  9760. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  9761. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  9762. results.Add(result1);
  9763. }
  9764. }
  9765. short result = 0;
  9766. if (results.All(a => a == 1))
  9767. result = 1;
  9768. else if (results.Contains(3))
  9769. result = 3;
  9770. else if (results.Contains(2))
  9771. result = 2;
  9772. else if (results.Contains(4))
  9773. result = 4;
  9774. else
  9775. result = 4;
  9776. stopwatch2.Stop();
  9777. // MES_Flag 为4MES报错
  9778. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9779. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9780. writeToPLC_Flag.Name = "d3MES_FLAG";
  9781. writeToPLC_Flag.Adress = 2463;
  9782. writeToPLC_Flag.Value = result;
  9783. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  9784. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  9785. }
  9786. catch (Exception ex)
  9787. {
  9788. stopwatch2.Restart();
  9789. // MES_Flag 为4上位机报错
  9790. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  9791. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9792. writeToPLC_Flag.Name = "d3MES_FLAG";
  9793. writeToPLC_Flag.Adress = 2463;
  9794. writeToPLC_Flag.Value = (short)4;
  9795. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  9796. string str = ex.StackTrace;
  9797. AddMessage_Station(stationNameStr, LogType.Error,
  9798. $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  9799. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9800. stopwatch2.Stop();
  9801. }
  9802. stopwatch1.Stop();
  9803. AddMessage(LogType.Info,
  9804. stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  9805. stopwatch2.ElapsedMilliseconds + "ms");
  9806. }
  9807. // 上次采集到的SN
  9808. //private string sn_S4_4进站接口 = string.Empty;
  9809. /// <summary>
  9810. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  9811. /// </summary>
  9812. private void S4_4进站接口(int plcNo, string stationNameStr)
  9813. {
  9814. Stopwatch stopwatch1 = new Stopwatch();
  9815. Stopwatch stopwatch2 = new Stopwatch();
  9816. try
  9817. {
  9818. stopwatch1.Start();
  9819. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  9820. sn = sn.Replace("\0", "");
  9821. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  9822. #region 查询15个载具码
  9823. List<string> vehicleCodes = new List<string>(); // 15个载具码
  9824. string vehicleData = string.Empty;
  9825. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  9826. if (string.IsNullOrEmpty(vehicleData))
  9827. vehicleData = "";
  9828. if (snResult != 0)
  9829. {
  9830. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9831. writeToPLC_Flag1.Name = "d3MES_FLAG";
  9832. writeToPLC_Flag1.Adress = 2463;
  9833. writeToPLC_Flag1.Value = (short)4;
  9834. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  9835. stopwatch1.Stop();
  9836. AddMessage(LogType.Info,
  9837. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9838. return;
  9839. }
  9840. string[] cavitySNs = vehicleData.Split('.');
  9841. if (cavitySNs != null && cavitySNs.Length > 0)
  9842. {
  9843. for (int i = 0; i < cavitySNs.Length; i++)
  9844. {
  9845. if (string.IsNullOrEmpty(cavitySNs[i]))
  9846. vehicleCodes.Add("");
  9847. else
  9848. vehicleCodes.Add(cavitySNs[i]);
  9849. }
  9850. }
  9851. #endregion 查询15个载具码
  9852. #region 查询15个产品SN
  9853. List<string> portNos = new List<string>(); // 15个产品SN
  9854. foreach (string vehicleCode in vehicleCodes)
  9855. {
  9856. if (string.IsNullOrEmpty(vehicleCode))
  9857. portNos.Add("");
  9858. else
  9859. {
  9860. // 查询
  9861. string cavityData = string.Empty;
  9862. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  9863. if (string.IsNullOrEmpty(cavityData))
  9864. cavityData = "";
  9865. if (snResult1 != 0)
  9866. {
  9867. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9868. writeToPLC_Flag1.Name = "d3MES_FLAG";
  9869. writeToPLC_Flag1.Adress = 2463;
  9870. writeToPLC_Flag1.Value = (short)4;
  9871. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  9872. stopwatch1.Stop();
  9873. AddMessage(LogType.Info,
  9874. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  9875. stopwatch1.ElapsedMilliseconds + "ms");
  9876. return;
  9877. }
  9878. string[] partSNs = cavityData.Split('.');
  9879. if (partSNs != null && partSNs.Length >= 1)
  9880. portNos.Add(partSNs[0]);
  9881. else
  9882. portNos.Add("");
  9883. }
  9884. }
  9885. #endregion 查询15个产品SN
  9886. // 调用MES进站(最多15个)
  9887. stopwatch2.Start();
  9888. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  9889. for (int i = 0; i < vehicleCodes.Count; i++)
  9890. {
  9891. // 循环进站
  9892. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  9893. {
  9894. // 产品SN(物料码)校验
  9895. string portNo = portNos[i];
  9896. List<TestItem> item = new List<TestItem>();
  9897. item.Add(new TestItem()
  9898. {
  9899. Parameter_name = "弹夹码",
  9900. Parameter_value = sn,
  9901. });
  9902. item.Add(new TestItem()
  9903. {
  9904. Parameter_name = "弹夹穴位",
  9905. Parameter_value = (i + 1).ToString(),
  9906. });
  9907. item.Add(new TestItem()
  9908. {
  9909. Parameter_name = "载具码",
  9910. Parameter_value = vehicleCodes[i],
  9911. });
  9912. item.Add(new TestItem()
  9913. {
  9914. Parameter_name = "载具穴号",
  9915. Parameter_value = "1",
  9916. });
  9917. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  9918. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  9919. }
  9920. }
  9921. stopwatch2.Stop();
  9922. short result = 0;
  9923. bool haveMesWarn = results.Contains(5);
  9924. bool havePCWarn = results.Contains(6);
  9925. if (haveMesWarn)
  9926. result = 2; // 5->2
  9927. else if (havePCWarn)
  9928. result = 6; // 6->4
  9929. else
  9930. result = 1;
  9931. // MES_Flag 为4MES报错
  9932. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9933. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9934. writeToPLC_Flag.Name = "d4MES_FLAG";
  9935. writeToPLC_Flag.Adress = 2496;
  9936. writeToPLC_Flag.Value = result;
  9937. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  9938. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  9939. }
  9940. catch (Exception ex)
  9941. {
  9942. stopwatch2.Stop();
  9943. // MES_Flag 为4上位机报错
  9944. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  9945. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9946. writeToPLC_Flag.Name = "d4MES_FLAG";
  9947. writeToPLC_Flag.Adress = 2496;
  9948. writeToPLC_Flag.Value = (short)4;
  9949. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  9950. string str = ex.StackTrace;
  9951. AddMessage_Station(stationNameStr, LogType.Error,
  9952. $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  9953. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9954. }
  9955. stopwatch1.Stop();
  9956. AddMessage(LogType.Info,
  9957. stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  9958. stopwatch2.ElapsedMilliseconds + "ms");
  9959. }
  9960. // 上次采集到的SN
  9961. //private string sn_S4_4出站接口 = string.Empty;
  9962. /// <summary>
  9963. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  9964. /// </summary>
  9965. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  9966. {
  9967. Stopwatch stopwatch1 = new Stopwatch();
  9968. Stopwatch stopwatch2 = new Stopwatch();
  9969. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9970. string stationNameStr = stationCode + stationName;
  9971. string processItem = stationName; // 测试项目
  9972. try
  9973. {
  9974. stopwatch1.Start();
  9975. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9976. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9977. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9978. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9979. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  9980. sn = sn.Replace("\0", "");
  9981. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  9982. bool isPass = d4Result == 1; // 产品结果 bool
  9983. #region 查询15个载具码
  9984. List<string> vehicleCodes = new List<string>(); // 15个载具码
  9985. string vehicleData = string.Empty;
  9986. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  9987. if (string.IsNullOrEmpty(vehicleData))
  9988. vehicleData = "";
  9989. if (snResult1 != 0)
  9990. {
  9991. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9992. writeToPLC_Flag1.Name = "d4MES_FLAG";
  9993. writeToPLC_Flag1.Adress = 2496;
  9994. writeToPLC_Flag1.Value = (short)4;
  9995. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  9996. stopwatch1.Stop();
  9997. AddMessage(LogType.Info,
  9998. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9999. return;
  10000. }
  10001. string[] cavitySNs = vehicleData.Split('.');
  10002. if (cavitySNs != null && cavitySNs.Length > 0)
  10003. {
  10004. for (int i = 0; i < cavitySNs.Length; i++)
  10005. {
  10006. if (string.IsNullOrEmpty(cavitySNs[i]))
  10007. vehicleCodes.Add("");
  10008. else
  10009. vehicleCodes.Add(cavitySNs[i]);
  10010. }
  10011. }
  10012. #endregion 查询15个载具码
  10013. // 统一查 产品SN列表
  10014. List<string> partNos = new List<string>();
  10015. foreach (string vehicleCode in vehicleCodes)
  10016. {
  10017. if (string.IsNullOrEmpty(vehicleCode))
  10018. partNos.Add("");
  10019. else
  10020. {
  10021. string partNo = "";
  10022. #region 查询载具上的产品信息
  10023. string cavityData = string.Empty;
  10024. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10025. if (string.IsNullOrEmpty(cavityData))
  10026. cavityData = "";
  10027. if (snResult != 0)
  10028. {
  10029. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10030. writeToPLC_Flag1.Name = "d4MES_FLAG";
  10031. writeToPLC_Flag1.Adress = 2496;
  10032. writeToPLC_Flag1.Value = (short)4;
  10033. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  10034. stopwatch1.Stop();
  10035. AddMessage(LogType.Info,
  10036. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10037. "ms");
  10038. return;
  10039. }
  10040. string[] partSNs = cavityData.Split('.');
  10041. if (partSNs != null && partSNs.Length >= 1)
  10042. partNo = partSNs[0];
  10043. #endregion 查询载具上的产品信息
  10044. partNos.Add(partNo);
  10045. }
  10046. }
  10047. // 调用MES出站
  10048. stopwatch2.Start();
  10049. // 统一上传
  10050. List<int> results = new List<int>();
  10051. for (int i = 0; i < partNos.Count; i++)
  10052. {
  10053. string index = (i + 1).ToString(); // 弹夹穴号
  10054. if (string.IsNullOrEmpty(partNos[i]))
  10055. results.Add(1);
  10056. else
  10057. {
  10058. List<TestItem> items1 = new List<TestItem>();
  10059. items1.Add(new TestItem()
  10060. {
  10061. Parameter_name = "弹夹码",
  10062. Parameter_value = sn,
  10063. Parameter_unit = ""
  10064. });
  10065. items1.Add(new TestItem()
  10066. {
  10067. Parameter_name = "弹夹穴号",
  10068. Parameter_value = index,
  10069. Parameter_unit = ""
  10070. });
  10071. items1.Add(new TestItem()
  10072. {
  10073. Parameter_name = "载具码",
  10074. Parameter_value = vehicleCodes[i],
  10075. Parameter_unit = ""
  10076. });
  10077. items1.Add(new TestItem()
  10078. {
  10079. Parameter_name = "载具穴号",
  10080. Parameter_value = "1",
  10081. Parameter_unit = ""
  10082. });
  10083. items1.Add(new TestItem()
  10084. {
  10085. Parameter_name = "产品结果",
  10086. Parameter_value = d4Result == 1 ? "OK" : "NG",
  10087. Parameter_unit = ""
  10088. });
  10089. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  10090. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  10091. results.Add(result1);
  10092. }
  10093. }
  10094. short result = 0;
  10095. if (results.All(a => a == 1))
  10096. result = 1;
  10097. else if (results.Contains(3))
  10098. result = 3;
  10099. else if (results.Contains(2))
  10100. result = 2;
  10101. else if (results.Contains(4))
  10102. result = 4;
  10103. else
  10104. result = 4;
  10105. stopwatch2.Stop();
  10106. // MES_Flag 为4MES报错
  10107. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10108. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10109. writeToPLC_Flag.Name = "d4MES_FLAG";
  10110. writeToPLC_Flag.Adress = 2496;
  10111. writeToPLC_Flag.Value = result;
  10112. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10113. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10114. }
  10115. catch (Exception ex)
  10116. {
  10117. stopwatch2.Restart();
  10118. // MES_Flag 为4上位机报错
  10119. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  10120. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10121. writeToPLC_Flag.Name = "d4MES_FLAG";
  10122. writeToPLC_Flag.Adress = 2496;
  10123. writeToPLC_Flag.Value = (short)4;
  10124. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10125. string str = ex.StackTrace;
  10126. AddMessage_Station(stationNameStr, LogType.Error,
  10127. $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10128. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10129. stopwatch2.Stop();
  10130. }
  10131. stopwatch1.Stop();
  10132. AddMessage(LogType.Info,
  10133. stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10134. stopwatch2.ElapsedMilliseconds + "ms");
  10135. }
  10136. /// <summary>
  10137. /// [S4] 取放桁架 - S4_5弹夹扫码
  10138. /// </summary>
  10139. /// <param name="plcNo">PLC编号</param>
  10140. /// <param name="stationNameStr">工站全称</param>
  10141. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  10142. {
  10143. Stopwatch stopwatch1 = new Stopwatch();
  10144. Stopwatch stopwatch2 = new Stopwatch();
  10145. try
  10146. {
  10147. stopwatch1.Start();
  10148. // ZS 弹夹扫码
  10149. string d5BulletclipCode = " "; // 扫到的码
  10150. short d5BulletclipScanCode = 2;
  10151. stopwatch2.Start();
  10152. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  10153. //// MES_Flag
  10154. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10155. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10156. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  10157. writeToPLC_Flag.Adress = 2528;
  10158. writeToPLC_Flag.Value = d5BulletclipScanCode;
  10159. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10160. {
  10161. Name = "d5BulletclipCode",
  10162. Adress = 2529,
  10163. ValueType = PLCValueType.String,
  10164. ValueTypeStrLength = 20,
  10165. Value = d5BulletclipCode
  10166. });
  10167. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  10168. stopwatch2.Stop();
  10169. }
  10170. catch (Exception ex)
  10171. {
  10172. string str = ex.StackTrace;
  10173. AddMessage_Station(stationNameStr, LogType.Error,
  10174. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10175. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10176. stopwatch2.Start();
  10177. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  10178. //// MES_Flag
  10179. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  10180. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10181. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  10182. writeToPLC_Flag.Adress = 2528;
  10183. writeToPLC_Flag.Value = (short)6;
  10184. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10185. {
  10186. Name = "d5BulletclipCode",
  10187. Adress = 2529,
  10188. ValueType = PLCValueType.String,
  10189. ValueTypeStrLength = 20,
  10190. Value = " "
  10191. });
  10192. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  10193. stopwatch2.Stop();
  10194. }
  10195. stopwatch1.Stop();
  10196. AddMessage(LogType.Info,
  10197. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10198. stopwatch2.ElapsedMilliseconds + "ms");
  10199. }
  10200. /// <summary>
  10201. /// [S4] 取放桁架 - S4_5载具扫码
  10202. /// </summary>
  10203. /// <param name="plcNo">PLC编号</param>
  10204. /// <param name="stationNameStr">工站全称</param>
  10205. private void S4_5载具扫码(int plcNo, string stationNameStr)
  10206. {
  10207. Stopwatch stopwatch1 = new Stopwatch();
  10208. Stopwatch stopwatch2 = new Stopwatch();
  10209. try
  10210. {
  10211. stopwatch1.Start();
  10212. // ZS 载具扫码
  10213. string d5VehicleCode = " "; // 扫到的码
  10214. short d5VehicleScanCode = 2;
  10215. #region 进站
  10216. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  10217. {
  10218. // 查产品SN
  10219. #region 查询载具上的产品信息
  10220. string cavityData = string.Empty;
  10221. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  10222. if (string.IsNullOrEmpty(cavityData))
  10223. cavityData = "";
  10224. if (snResult != 0)
  10225. {
  10226. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10227. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  10228. writeToPLC_Flag1.Adress = 2559;
  10229. writeToPLC_Flag1.Value = (short)6;
  10230. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10231. {
  10232. Name = "d5VehicleCode",
  10233. Adress = 2560,
  10234. ValueType = PLCValueType.String,
  10235. ValueTypeStrLength = 20,
  10236. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  10237. });
  10238. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  10239. stopwatch1.Stop();
  10240. AddMessage(LogType.Info,
  10241. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10242. "ms");
  10243. return;
  10244. }
  10245. string[] cavitySNs = cavityData.Split('.');
  10246. string partNo = "";
  10247. if (cavitySNs != null && cavitySNs.Length >= 1)
  10248. {
  10249. partNo = cavitySNs[0];
  10250. }
  10251. #endregion 查询载具上的产品信息
  10252. List<TestItem> item = new List<TestItem>();
  10253. item.Add(new TestItem()
  10254. {
  10255. Parameter_name = "载具码",
  10256. Parameter_value = d5VehicleCode,
  10257. });
  10258. item.Add(new TestItem()
  10259. {
  10260. Parameter_name = "载具穴号",
  10261. Parameter_value = "1",
  10262. });
  10263. stopwatch2.Start();
  10264. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  10265. partNo, item, out string errorMsg);
  10266. stopwatch2.Stop();
  10267. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  10268. }
  10269. #endregion 进站
  10270. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  10271. //// MES_Flag
  10272. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10273. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10274. writeToPLC_Flag.Name = "d5VehicleScanCode";
  10275. writeToPLC_Flag.Adress = 2559;
  10276. writeToPLC_Flag.Value = d5VehicleScanCode;
  10277. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10278. {
  10279. Name = "d5VehicleCode",
  10280. Adress = 2560,
  10281. ValueType = PLCValueType.String,
  10282. ValueTypeStrLength = 20,
  10283. Value = d5VehicleCode
  10284. });
  10285. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  10286. }
  10287. catch (Exception ex)
  10288. {
  10289. string str = ex.StackTrace;
  10290. AddMessage_Station(stationNameStr, LogType.Error,
  10291. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10292. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10293. stopwatch2.Start();
  10294. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  10295. //// MES_Flag
  10296. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  10297. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10298. writeToPLC_Flag.Name = "d5VehicleScanCode";
  10299. writeToPLC_Flag.Adress = 2559;
  10300. writeToPLC_Flag.Value = (short)6;
  10301. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10302. {
  10303. Name = "d5VehicleCode",
  10304. Adress = 2560,
  10305. ValueType = PLCValueType.String,
  10306. ValueTypeStrLength = 20,
  10307. Value = " "
  10308. });
  10309. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  10310. stopwatch2.Stop();
  10311. }
  10312. stopwatch1.Stop();
  10313. AddMessage(LogType.Info,
  10314. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10315. stopwatch2.ElapsedMilliseconds + "ms");
  10316. }
  10317. // 上次采集到的SN
  10318. //private string sn_S4_5出站接口 = string.Empty;
  10319. /// <summary>
  10320. /// [S4] 取放桁架 - S4_5出站接口
  10321. /// </summary>
  10322. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  10323. {
  10324. Stopwatch stopwatch1 = new Stopwatch();
  10325. Stopwatch stopwatch2 = new Stopwatch();
  10326. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10327. string stationNameStr = stationCode + stationName;
  10328. string processItem = stationName; // 测试项目
  10329. try
  10330. {
  10331. stopwatch1.Start();
  10332. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10333. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10334. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10335. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10336. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  10337. sn = sn.Replace("\0", "");
  10338. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  10339. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  10340. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  10341. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  10342. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  10343. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  10344. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  10345. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  10346. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  10347. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  10348. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  10349. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  10350. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  10351. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  10352. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  10353. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  10354. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  10355. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  10356. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  10357. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  10358. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  10359. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  10360. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  10361. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  10362. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  10363. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  10364. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  10365. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  10366. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  10367. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  10368. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  10369. bool pass = d5Result == 1;
  10370. // 存 载具SN列表
  10371. List<string> vehicleCodes = new List<string>()
  10372. {
  10373. d5VehicleCode1, d5VehicleCode2, d5VehicleCode3, d5VehicleCode4, d5VehicleCode5,
  10374. d5VehicleCode6, d5VehicleCode7, d5VehicleCode8, d5VehicleCode9, d5VehicleCode10,
  10375. d5VehicleCode11, d5VehicleCode12, d5VehicleCode13, d5VehicleCode14, d5VehicleCode15
  10376. };
  10377. // 统一查 产品SN列表
  10378. List<string> partNos = new List<string>();
  10379. foreach (string vehicleCode in vehicleCodes)
  10380. {
  10381. if (string.IsNullOrEmpty(vehicleCode))
  10382. partNos.Add("");
  10383. else
  10384. {
  10385. string partNo = "";
  10386. #region 查询载具上的产品信息
  10387. string cavityData = string.Empty;
  10388. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10389. if (string.IsNullOrEmpty(cavityData))
  10390. cavityData = "";
  10391. if (snResult != 0)
  10392. {
  10393. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10394. writeToPLC_Flag1.Name = "d5MES_FLAG";
  10395. writeToPLC_Flag1.Adress = 2591;
  10396. writeToPLC_Flag1.Value = (short)4;
  10397. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  10398. stopwatch1.Stop();
  10399. AddMessage(LogType.Info,
  10400. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10401. "ms");
  10402. return;
  10403. }
  10404. string[] cavitySNs = cavityData.Split('.');
  10405. if (cavitySNs != null && cavitySNs.Length >= 1)
  10406. partNo = cavitySNs[0];
  10407. #endregion 查询载具上的产品信息
  10408. partNos.Add(partNo);
  10409. }
  10410. }
  10411. // 统一上传
  10412. stopwatch2.Start();
  10413. List<int> results = new List<int>();
  10414. for (int i = 0; i < partNos.Count; i++)
  10415. {
  10416. string index = (i + 1).ToString(); // 弹夹穴号
  10417. if (string.IsNullOrEmpty(partNos[i]))
  10418. results.Add(1);
  10419. else
  10420. {
  10421. List<TestItem> items1 = new List<TestItem>();
  10422. items1.Add(new TestItem()
  10423. {
  10424. Parameter_name = "弹夹码",
  10425. Parameter_value = sn,
  10426. Parameter_unit = ""
  10427. });
  10428. items1.Add(new TestItem()
  10429. {
  10430. Parameter_name = "弹夹穴号",
  10431. Parameter_value = index,
  10432. Parameter_unit = ""
  10433. });
  10434. items1.Add(new TestItem()
  10435. {
  10436. Parameter_name = "载具码",
  10437. Parameter_value = vehicleCodes[i],
  10438. Parameter_unit = ""
  10439. });
  10440. items1.Add(new TestItem()
  10441. {
  10442. Parameter_name = "载具穴号",
  10443. Parameter_value = "1",
  10444. Parameter_unit = ""
  10445. });
  10446. items1.Add(new TestItem()
  10447. {
  10448. Parameter_name = "产品结果",
  10449. Parameter_value = d5Result == 1 ? "OK" : "NG",
  10450. Parameter_unit = ""
  10451. });
  10452. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  10453. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  10454. results.Add(result1);
  10455. }
  10456. }
  10457. short result = 0;
  10458. if (results.All(a => a == 1))
  10459. result = 1;
  10460. else if (results.Contains(3))
  10461. result = 3;
  10462. else if (results.Contains(2))
  10463. result = 2;
  10464. else if (results.Contains(4))
  10465. result = 4;
  10466. else
  10467. result = 4;
  10468. stopwatch2.Stop();
  10469. #region 存储绑定数据到 边线MES系统中
  10470. if (result == 1)
  10471. {
  10472. // 删除绑定信息
  10473. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  10474. if (resultMesR != 0)
  10475. {
  10476. result = 4;
  10477. AddMessage_Station(stationNameStr, LogType.Error,
  10478. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  10479. }
  10480. }
  10481. #endregion 存储绑定数据到 边线MES系统中
  10482. // MES_Flag 为4MES报错
  10483. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10484. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10485. writeToPLC_Flag.Name = "d5MES_FLAG";
  10486. writeToPLC_Flag.Adress = 2591;
  10487. writeToPLC_Flag.Value = result;
  10488. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  10489. OnMessage(LogType.Debug,
  10490. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  10491. }
  10492. catch (Exception ex)
  10493. {
  10494. stopwatch2.Restart();
  10495. // MES_Flag 为4上位机报错
  10496. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  10497. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10498. writeToPLC_Flag.Name = "d5MES_FLAG";
  10499. writeToPLC_Flag.Adress = 2591;
  10500. writeToPLC_Flag.Value = (short)4;
  10501. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  10502. stopwatch2.Stop();
  10503. string str = ex.StackTrace;
  10504. AddMessage_Station(stationNameStr, LogType.Error,
  10505. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10506. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10507. }
  10508. stopwatch1.Stop();
  10509. AddMessage(LogType.Info,
  10510. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10511. stopwatch2.ElapsedMilliseconds + "ms");
  10512. }
  10513. /// <summary>
  10514. /// [S4] 取放桁架 - S4_5节拍接口
  10515. /// </summary>
  10516. /// <param name="plcNo">PLC编号</param>
  10517. /// <param name="stationNameStr">工站全称</param>
  10518. private void S4_5节拍接口(int plcNo, string stationNameStr)
  10519. {
  10520. Stopwatch stopwatch1 = new Stopwatch();
  10521. Stopwatch stopwatch2 = new Stopwatch();
  10522. string resultStr = string.Empty;
  10523. try
  10524. {
  10525. stopwatch1.Start();
  10526. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  10527. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  10528. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  10529. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  10530. if (!actionBool)
  10531. {
  10532. stopwatch2.Start();
  10533. // MES_Flag
  10534. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  10535. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10536. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  10537. writeToPLC_Flag1.Adress = 2924;
  10538. writeToPLC_Flag1.Value = (short)4;
  10539. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  10540. stopwatch2.Stop();
  10541. AddMessage(LogType.Info,
  10542. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  10543. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  10544. return;
  10545. }
  10546. string d5OEEPartNo = string.Empty; // 物料码
  10547. if (string.IsNullOrEmpty(d5OEEProductSN))
  10548. {
  10549. stopwatch2.Start();
  10550. // MES_Flag
  10551. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10552. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10553. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  10554. writeToPLC_Flag1.Adress = 2924;
  10555. writeToPLC_Flag1.Value = (short)1;
  10556. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  10557. stopwatch2.Stop();
  10558. AddMessage(LogType.Info,
  10559. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10560. stopwatch2.ElapsedMilliseconds + "ms");
  10561. return;
  10562. }
  10563. else
  10564. {
  10565. // 查产品SN
  10566. d5OEEPartNo = "Test"; // ZS
  10567. }
  10568. short d5OEEMES_FLAG = 0;
  10569. // 上传OEE
  10570. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  10571. d5OEEMES_FLAG = result.Item1;
  10572. resultStr = result.Item2;
  10573. stopwatch2.Start();
  10574. // MES_Flag
  10575. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10576. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10577. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  10578. writeToPLC_Flag.Adress = 2924;
  10579. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  10580. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  10581. stopwatch2.Stop();
  10582. }
  10583. catch (Exception ex)
  10584. {
  10585. string str = ex.StackTrace;
  10586. AddMessage_Station(stationNameStr, LogType.Error,
  10587. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  10588. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10589. // MES_Flag
  10590. stopwatch2.Start();
  10591. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  10592. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10593. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  10594. writeToPLC_Flag.Adress = 2924;
  10595. writeToPLC_Flag.Value = (short)4;
  10596. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  10597. stopwatch2.Stop();
  10598. }
  10599. stopwatch1.Stop();
  10600. AddMessage(LogType.Info,
  10601. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10602. stopwatch2.ElapsedMilliseconds + "ms");
  10603. }
  10604. #endregion [S4] 取放桁架
  10605. #endregion PLC4 刘果段
  10606. #region PLC5 张超凡
  10607. #region [S5] Tray盘下料装备
  10608. /// <summary>
  10609. /// S5工位的数据- 触发信号上次的值
  10610. /// </summary>
  10611. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  10612. /// <summary>
  10613. /// S5工位的数据(含触发信号)
  10614. /// </summary>
  10615. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  10616. /// <summary>
  10617. /// S5工位的数据- 回写点位
  10618. /// </summary>
  10619. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  10620. /// <summary>
  10621. /// [S5] Tray盘下料装备
  10622. /// </summary>
  10623. /// <param name="plcNo">PLC编号</param>
  10624. //private void ReadStation_S5(int plcNo)
  10625. //{
  10626. // // [S1] Tray盘上料装备
  10627. // // [S2] FCT
  10628. // // [S3] 值板机
  10629. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  10630. // // [S5] Tray盘下料装备
  10631. // /// 上位机心跳
  10632. // /// 获取设备报警数据与状态信息
  10633. // string stationCode = "[S5]";
  10634. // string stationName = "Tray盘下料装备";
  10635. // string stationNameStr = stationCode + stationName;
  10636. // #region 创建字典
  10637. // // 触发信号字典 赋值
  10638. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  10639. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  10640. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  10641. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  10642. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  10643. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  10644. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  10645. // // PLC数据字典 赋值
  10646. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  10647. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  10648. // s5PLCData.Add("e1ProductSN_Check", ""); //
  10649. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  10650. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  10651. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  10652. // s5PLCData.Add("e1PartNo", ""); // 物料码
  10653. // s5PLCData.Add("e1Result", 0); // 产品结果
  10654. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  10655. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  10656. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  10657. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  10658. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  10659. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  10660. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  10661. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  10662. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  10663. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  10664. // #endregion 创建字典
  10665. // while (IsRun)
  10666. // {
  10667. // try
  10668. // {
  10669. // if (!GlobalContext._IsCon_Funs5)
  10670. // {
  10671. // UpdatePLCMonitor(1, plcNo, 0);
  10672. // continue;
  10673. // }
  10674. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  10675. // {
  10676. // Stopwatch stopwatch1 = new Stopwatch();
  10677. // Stopwatch stopwatch2 = new Stopwatch();
  10678. // stopwatch1.Start();
  10679. // stopwatch2.Start();
  10680. // #region 一次性读取所有数据
  10681. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  10682. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  10683. // int[] datas = data1.Concat(data2).ToArray();
  10684. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  10685. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  10686. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  10687. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  10688. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  10689. // s5PLCData["e1MES_FLAG"] = datas[35];
  10690. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  10691. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  10692. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  10693. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  10694. // s5PLCData["e1Result"] = datas[76];
  10695. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  10696. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  10697. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  10698. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  10699. // s5PLCData["e1OEEType"] = datas[109];
  10700. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  10701. // s5PLCData["e1AGVUpStart"] = datas[121];
  10702. // s5PLCData["e1AGVUpEnd"] = datas[122];
  10703. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  10704. // s5PLCData["e1AGVDownStart"] = datas[134];
  10705. // s5PLCData["e1AGVDownEnd"] = datas[135];
  10706. // #endregion 一次性读取所有数据
  10707. // stopwatch2.Stop();
  10708. // #region 回写操作,写后清空flag
  10709. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  10710. // #endregion 回写操作,写后清空flag
  10711. // #region 进站校验
  10712. // try
  10713. // {
  10714. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  10715. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  10716. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  10717. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  10718. // {
  10719. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  10720. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  10721. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  10722. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  10723. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  10724. // }
  10725. // }
  10726. // catch (Exception ex)
  10727. // {
  10728. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  10729. // string str = ex.StackTrace;
  10730. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10731. // }
  10732. // #endregion 进站校验
  10733. // #region 出站接口
  10734. // try
  10735. // {
  10736. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  10737. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  10738. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  10739. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  10740. // {
  10741. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  10742. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  10743. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  10744. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  10745. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  10746. // }
  10747. // }
  10748. // catch (Exception ex)
  10749. // {
  10750. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  10751. // string str = ex.StackTrace;
  10752. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10753. // }
  10754. // #endregion 出站接口
  10755. // #region 节拍接口
  10756. // try
  10757. // {
  10758. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  10759. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  10760. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  10761. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  10762. // {
  10763. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  10764. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  10765. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  10766. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  10767. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  10768. // }
  10769. // }
  10770. // catch (Exception ex)
  10771. // {
  10772. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  10773. // string str = ex.StackTrace;
  10774. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10775. // }
  10776. // #endregion 节拍接口
  10777. // #region AGV上料
  10778. // // AGV上料叫AGV信号
  10779. // try
  10780. // {
  10781. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  10782. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  10783. // if (e1AGVUpCall != e1AGVUpCallOld)
  10784. // {
  10785. // if (e1AGVUpCall == 1) // 0->1
  10786. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  10787. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  10788. // }
  10789. // }
  10790. // catch (Exception ex)
  10791. // {
  10792. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  10793. // string str = ex.StackTrace;
  10794. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10795. // }
  10796. // // AGV上料完成信号
  10797. // try
  10798. // {
  10799. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  10800. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  10801. // if (e1AGVUpEnd != e1AGVUpEndOld)
  10802. // {
  10803. // if (e1AGVUpEnd == 1) // 0->1
  10804. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  10805. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  10806. // }
  10807. // }
  10808. // catch (Exception ex)
  10809. // {
  10810. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  10811. // string str = ex.StackTrace;
  10812. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10813. // }
  10814. // #endregion AGV上料
  10815. // #region AGV下料
  10816. // // AGV下料叫agv信号
  10817. // try
  10818. // {
  10819. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  10820. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  10821. // if (e1AGVDownCall != e1AGVDownCallOld)
  10822. // {
  10823. // if (e1AGVDownCall == 1) // 0->1
  10824. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  10825. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  10826. // }
  10827. // }
  10828. // catch (Exception ex)
  10829. // {
  10830. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  10831. // string str = ex.StackTrace;
  10832. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10833. // }
  10834. // // AGV下料完成信号
  10835. // try
  10836. // {
  10837. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  10838. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  10839. // if (e1AGVDownEnd != e1AGVDownEndOld)
  10840. // {
  10841. // if (e1AGVDownEnd == 1) // 0->1
  10842. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  10843. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  10844. // }
  10845. // }
  10846. // catch (Exception ex)
  10847. // {
  10848. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  10849. // string str = ex.StackTrace;
  10850. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10851. // }
  10852. // #endregion AGV下料
  10853. // #region 心跳
  10854. // try
  10855. // {
  10856. // short states = 0;
  10857. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  10858. // }
  10859. // catch (Exception ex)
  10860. // {
  10861. // string str = ex.StackTrace;
  10862. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10863. // }
  10864. // #endregion 心跳
  10865. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  10866. // stopwatch1.Stop();
  10867. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  10868. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  10869. // }
  10870. // else
  10871. // {
  10872. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  10873. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  10874. // Funs[plcNo].Connect();
  10875. // }
  10876. // }
  10877. // catch (Exception ex)
  10878. // {
  10879. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  10880. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  10881. // Funs[plcNo].ReConnect();
  10882. // }
  10883. // Thread.Sleep(IntervalReadPLC);
  10884. // }
  10885. //}
  10886. /// <summary>
  10887. /// [S5] Tray盘下料装备 - 进站校验
  10888. /// </summary>
  10889. /// <param name="plcNo">PLC编号</param>
  10890. /// <param name="stationNameStr">工站全称</param>
  10891. private void S5进站校验(int plcNo, string stationNameStr)
  10892. {
  10893. Stopwatch stopwatch1 = new Stopwatch();
  10894. Stopwatch stopwatch2 = new Stopwatch();
  10895. try
  10896. {
  10897. stopwatch1.Start();
  10898. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  10899. sn = sn.Replace("\0", "");
  10900. // 获取产品SN By 载具码
  10901. #region 查询载具上的产品信息
  10902. string cavityData = string.Empty;
  10903. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  10904. if (string.IsNullOrEmpty(cavityData))
  10905. cavityData = "";
  10906. if (snResult != 0)
  10907. {
  10908. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10909. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  10910. writeToPLC_Flag1.Adress = 2003;
  10911. writeToPLC_Flag1.Value = (short)6;
  10912. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  10913. stopwatch1.Stop();
  10914. AddMessage(LogType.Info,
  10915. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10916. return;
  10917. }
  10918. string[] cavitySNs = cavityData.Split('.');
  10919. string partNo = string.Empty;
  10920. if (cavitySNs != null && cavitySNs.Length >= 1)
  10921. partNo = cavitySNs[0];
  10922. #endregion 查询载具上的产品信息
  10923. // 产品SN(物料码)校验
  10924. List<TestItem> item = new List<TestItem>();
  10925. item.Add(new TestItem()
  10926. {
  10927. Parameter_name = "载具码",
  10928. Parameter_value = sn,
  10929. });
  10930. item.Add(new TestItem()
  10931. {
  10932. Parameter_name = "载具穴号",
  10933. Parameter_value = "1",
  10934. });
  10935. stopwatch2.Start();
  10936. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  10937. partNo, item, out string errorMsg);
  10938. stopwatch2.Stop();
  10939. short e1MES_FLAG_Check = (short)result;
  10940. // MES_Flag
  10941. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  10942. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10943. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  10944. writeToPLC_Flag.Adress = 2003;
  10945. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  10946. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  10947. }
  10948. catch (Exception ex)
  10949. {
  10950. string str = ex.StackTrace;
  10951. AddMessage_Station(stationNameStr, LogType.Error,
  10952. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  10953. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10954. // MES_Flag
  10955. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  10956. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10957. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  10958. writeToPLC_Flag.Adress = 2003;
  10959. writeToPLC_Flag.Value = (short)6;
  10960. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  10961. }
  10962. stopwatch1.Stop();
  10963. AddMessage(LogType.Info,
  10964. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  10965. stopwatch2.ElapsedMilliseconds + "ms");
  10966. }
  10967. /// <summary>
  10968. /// [S5] Tray盘下料装备 - 出站接口
  10969. /// </summary>
  10970. /// <param name="plcNo"></param>
  10971. /// <param name="stationCode"></param>
  10972. /// <param name="stationName"></param>
  10973. private void S5出站接口(int plcNo, string stationCode, string stationName)
  10974. {
  10975. Stopwatch stopwatch1 = new Stopwatch();
  10976. Stopwatch stopwatch2 = new Stopwatch();
  10977. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10978. string stationNameStr = stationCode + stationName;
  10979. string processItem = stationName; // 测试项目
  10980. try
  10981. {
  10982. stopwatch1.Start();
  10983. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10984. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10985. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10986. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10987. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  10988. sn = sn.Replace("\0", "");
  10989. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  10990. //partNo = partNo.Replace("\0", "");
  10991. #region 查询载具上的产品信息
  10992. string cavityData = string.Empty;
  10993. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  10994. if (string.IsNullOrEmpty(cavityData))
  10995. cavityData = "";
  10996. if (snResult != 0)
  10997. {
  10998. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10999. writeToPLC_Flag1.Name = "e1MES_FLAG";
  11000. writeToPLC_Flag1.Adress = 2035;
  11001. writeToPLC_Flag1.Value = (short)4;
  11002. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  11003. stopwatch1.Stop();
  11004. AddMessage(LogType.Info,
  11005. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11006. return;
  11007. }
  11008. string[] cavitySNs = cavityData.Split('.');
  11009. string partNo = string.Empty;
  11010. if (cavitySNs != null && cavitySNs.Length >= 1)
  11011. partNo = cavitySNs[0];
  11012. #endregion 查询载具上的产品信息
  11013. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  11014. bool pass = e1Result == 1;
  11015. stopwatch2.Start();
  11016. // 上传MES
  11017. List<TestItem> items = new List<TestItem>();
  11018. items.Add(new TestItem()
  11019. {
  11020. Parameter_name = "载具码",
  11021. Parameter_value = sn,
  11022. Parameter_unit = ""
  11023. });
  11024. items.Add(new TestItem()
  11025. {
  11026. Parameter_name = "载具穴号",
  11027. Parameter_value = "1",
  11028. Parameter_unit = ""
  11029. });
  11030. items.Add(new TestItem()
  11031. {
  11032. Parameter_name = "产品结果",
  11033. Parameter_value = e1Result == 1 ? "OK" : "NG",
  11034. Parameter_unit = ""
  11035. });
  11036. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  11037. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  11038. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  11039. short result = result1 == 1 ? (short)1 : (short)3;
  11040. stopwatch2.Stop();
  11041. #region 存储绑定数据到 边线MES系统中
  11042. if (result == 1)
  11043. {
  11044. // 删除绑定信息
  11045. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  11046. if (resultMesR != 0)
  11047. {
  11048. result = 4;
  11049. AddMessage_Station(stationNameStr, LogType.Error,
  11050. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  11051. }
  11052. }
  11053. #endregion 存储绑定数据到 边线MES系统中
  11054. // MES_Flag 为MES报错
  11055. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11056. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  11057. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11058. writeToPLC_Flag.Name = "e1MES_FLAG";
  11059. writeToPLC_Flag.Adress = 2035;
  11060. writeToPLC_Flag.Value = result;
  11061. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  11062. OnMessage(LogType.Debug,
  11063. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  11064. }
  11065. catch (Exception ex)
  11066. {
  11067. stopwatch2.Restart();
  11068. // MES_Flag 为4上位机报错
  11069. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  11070. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11071. writeToPLC_Flag.Name = "e1MES_FLAG";
  11072. writeToPLC_Flag.Adress = 2035;
  11073. writeToPLC_Flag.Value = (short)4;
  11074. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  11075. stopwatch2.Stop();
  11076. string str = ex.StackTrace;
  11077. AddMessage_Station(stationNameStr, LogType.Error,
  11078. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11079. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11080. }
  11081. stopwatch1.Stop();
  11082. AddMessage(LogType.Info,
  11083. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11084. stopwatch2.ElapsedMilliseconds + "ms");
  11085. }
  11086. /// <summary>
  11087. /// [S5] Tray盘下料装备 - 节拍接口
  11088. /// </summary>
  11089. /// <param name="plcNo">PLC编号</param>
  11090. /// <param name="stationNameStr">工站全称</param>
  11091. //private void S5节拍接口(int plcNo, string stationNameStr)
  11092. //{
  11093. // Stopwatch stopwatch1 = new Stopwatch();
  11094. // Stopwatch stopwatch2 = new Stopwatch();
  11095. // string resultStr = string.Empty;
  11096. // try
  11097. // {
  11098. // stopwatch1.Start();
  11099. // string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  11100. // string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  11101. // e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  11102. // bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  11103. // if (!actionBool)
  11104. // {
  11105. // stopwatch2.Start();
  11106. // // MES_Flag
  11107. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11108. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11109. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  11110. // writeToPLC_Flag1.Adress = 2088;
  11111. // writeToPLC_Flag1.Value = (short)4;
  11112. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  11113. // stopwatch2.Stop();
  11114. // AddMessage(LogType.Info,
  11115. // stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  11116. // "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  11117. // return;
  11118. // }
  11119. // string e1OEEPartNo = string.Empty; // 物料码
  11120. // if (string.IsNullOrEmpty(e1OEEProductSN))
  11121. // {
  11122. // stopwatch2.Start();
  11123. // // MES_Flag
  11124. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11125. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11126. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  11127. // writeToPLC_Flag1.Adress = 2088;
  11128. // writeToPLC_Flag1.Value = (short)1;
  11129. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  11130. // stopwatch2.Stop();
  11131. // AddMessage(LogType.Info,
  11132. // stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11133. // stopwatch2.ElapsedMilliseconds + "ms");
  11134. // return;
  11135. // }
  11136. // else
  11137. // {
  11138. // // 查产品SN
  11139. // e1OEEPartNo = "Test"; // ZS
  11140. // }
  11141. // short e1OEEMES_FLAG = 0;
  11142. // // 上传OEE
  11143. // (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  11144. // e1OEEMES_FLAG = result.Item1;
  11145. // resultStr = result.Item2;
  11146. // stopwatch2.Start();
  11147. // // MES_Flag
  11148. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11149. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11150. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  11151. // writeToPLC_Flag.Adress = 2088;
  11152. // writeToPLC_Flag.Value = e1OEEMES_FLAG;
  11153. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  11154. // stopwatch2.Stop();
  11155. // }
  11156. // catch (Exception ex)
  11157. // {
  11158. // string str = ex.StackTrace;
  11159. // AddMessage_Station(stationNameStr, LogType.Error,
  11160. // $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  11161. // str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11162. // // MES_Flag
  11163. // stopwatch2.Start();
  11164. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  11165. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11166. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  11167. // writeToPLC_Flag.Adress = 2088;
  11168. // writeToPLC_Flag.Value = (short)4;
  11169. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  11170. // stopwatch2.Stop();
  11171. // }
  11172. // stopwatch1.Stop();
  11173. // AddMessage(LogType.Info,
  11174. // stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11175. // stopwatch2.ElapsedMilliseconds + "ms");
  11176. //}
  11177. /// <summary>
  11178. /// [S5] Tray盘下料装备 - AGV上料叫agv
  11179. /// </summary>
  11180. /// <param name="plcNo">PLC编号</param>
  11181. /// <param name="stationNameStr">工站全称</param>
  11182. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  11183. {
  11184. Stopwatch stopwatch1 = new Stopwatch();
  11185. Stopwatch stopwatch2 = new Stopwatch();
  11186. try
  11187. {
  11188. stopwatch1.Start();
  11189. // ZS 呼叫AGV
  11190. short e1AGVUpCall = 2;
  11191. stopwatch2.Start();
  11192. // e1AGVUpCall
  11193. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11194. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11195. writeToPLC_Flag.Name = "e1AGVUpCall";
  11196. writeToPLC_Flag.Adress = 2120;
  11197. writeToPLC_Flag.Value = e1AGVUpCall;
  11198. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  11199. stopwatch2.Stop();
  11200. }
  11201. catch (Exception ex)
  11202. {
  11203. string str = ex.StackTrace;
  11204. AddMessage_Station(stationNameStr, LogType.Error,
  11205. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  11206. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11207. // e1AGVUpCall
  11208. stopwatch2.Start();
  11209. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  11210. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11211. writeToPLC_Flag.Name = "e1AGVUpCall";
  11212. writeToPLC_Flag.Adress = 2120;
  11213. writeToPLC_Flag.Value = (short)4;
  11214. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  11215. stopwatch2.Stop();
  11216. }
  11217. stopwatch1.Stop();
  11218. AddMessage(LogType.Info,
  11219. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11220. stopwatch2.ElapsedMilliseconds + "ms");
  11221. }
  11222. /// <summary>
  11223. /// [S5] Tray盘下料装备 - AGV上料完成
  11224. /// </summary>
  11225. /// <param name="plcNo">PLC编号</param>
  11226. /// <param name="stationNameStr">工站全称</param>
  11227. private void S5AGV上料完成(int plcNo, string stationNameStr)
  11228. {
  11229. Stopwatch stopwatch1 = new Stopwatch();
  11230. Stopwatch stopwatch2 = new Stopwatch();
  11231. try
  11232. {
  11233. stopwatch1.Start();
  11234. // ZS AGV上料完成,让小车离开
  11235. short e1AGVUpEnd = 2;
  11236. stopwatch2.Start();
  11237. // e1AGVUpEnd
  11238. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11239. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11240. writeToPLC_Flag.Name = "e1AGVUpEnd";
  11241. writeToPLC_Flag.Adress = 2122;
  11242. writeToPLC_Flag.Value = e1AGVUpEnd;
  11243. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  11244. stopwatch2.Stop();
  11245. }
  11246. catch (Exception ex)
  11247. {
  11248. string str = ex.StackTrace;
  11249. AddMessage_Station(stationNameStr, LogType.Error,
  11250. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  11251. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11252. // e1AGVUpEnd
  11253. stopwatch2.Start();
  11254. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  11255. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11256. writeToPLC_Flag.Name = "e1AGVUpEnd";
  11257. writeToPLC_Flag.Adress = 2122;
  11258. writeToPLC_Flag.Value = (short)4;
  11259. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  11260. stopwatch2.Stop();
  11261. }
  11262. stopwatch1.Stop();
  11263. AddMessage(LogType.Info,
  11264. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11265. stopwatch2.ElapsedMilliseconds + "ms");
  11266. }
  11267. /// <summary>
  11268. /// [S5] Tray盘下料装备 - AGV下料叫agv
  11269. /// </summary>
  11270. /// <param name="plcNo">PLC编号</param>
  11271. /// <param name="stationNameStr">工站全称</param>
  11272. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  11273. {
  11274. Stopwatch stopwatch1 = new Stopwatch();
  11275. Stopwatch stopwatch2 = new Stopwatch();
  11276. try
  11277. {
  11278. stopwatch1.Start();
  11279. // ZS 呼叫AGV
  11280. short e1AGVDownCall = 2;
  11281. stopwatch2.Start();
  11282. // e1AGVDownCall
  11283. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11284. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11285. writeToPLC_Flag.Name = "e1AGVDownCall";
  11286. writeToPLC_Flag.Adress = 2133;
  11287. writeToPLC_Flag.Value = e1AGVDownCall;
  11288. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  11289. stopwatch2.Stop();
  11290. }
  11291. catch (Exception ex)
  11292. {
  11293. string str = ex.StackTrace;
  11294. AddMessage_Station(stationNameStr, LogType.Error,
  11295. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  11296. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11297. // e1AGVDownCall
  11298. stopwatch2.Start();
  11299. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  11300. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11301. writeToPLC_Flag.Name = "e1AGVDownCall";
  11302. writeToPLC_Flag.Adress = 2133;
  11303. writeToPLC_Flag.Value = (short)4;
  11304. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  11305. stopwatch2.Stop();
  11306. }
  11307. stopwatch1.Stop();
  11308. AddMessage(LogType.Info,
  11309. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11310. stopwatch2.ElapsedMilliseconds + "ms");
  11311. }
  11312. /// <summary>
  11313. /// [S5] Tray盘下料装备 - AGV下料完成
  11314. /// </summary>
  11315. /// <param name="plcNo">PLC编号</param>
  11316. /// <param name="stationNameStr">工站全称</param>
  11317. private void S5AGV下料完成(int plcNo, string stationNameStr)
  11318. {
  11319. Stopwatch stopwatch1 = new Stopwatch();
  11320. Stopwatch stopwatch2 = new Stopwatch();
  11321. try
  11322. {
  11323. stopwatch1.Start();
  11324. // ZS AGV上料完成,让小车离开
  11325. short e1AGVDownEnd = 2;
  11326. stopwatch2.Start();
  11327. // e1AGVDownEnd
  11328. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11329. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11330. writeToPLC_Flag.Name = "e1AGVDownEnd";
  11331. writeToPLC_Flag.Adress = 2135;
  11332. writeToPLC_Flag.Value = e1AGVDownEnd;
  11333. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  11334. stopwatch2.Stop();
  11335. }
  11336. catch (Exception ex)
  11337. {
  11338. string str = ex.StackTrace;
  11339. AddMessage_Station(stationNameStr, LogType.Error,
  11340. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  11341. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11342. // e1AGVDownEnd
  11343. stopwatch2.Start();
  11344. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  11345. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11346. writeToPLC_Flag.Name = "e1AGVDownEnd";
  11347. writeToPLC_Flag.Adress = 2135;
  11348. writeToPLC_Flag.Value = (short)4;
  11349. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  11350. stopwatch2.Stop();
  11351. }
  11352. stopwatch1.Stop();
  11353. AddMessage(LogType.Info,
  11354. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11355. stopwatch2.ElapsedMilliseconds + "ms");
  11356. }
  11357. #endregion [S5] Tray盘下料装备
  11358. #endregion PLC5 张超凡
  11359. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  11360. /// <summary>
  11361. /// PLC读取到的数据 -添加数据
  11362. /// </summary>
  11363. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  11364. {
  11365. if (sxPlcData.ContainsKey(newKey))
  11366. sxPlcData[newKey] = newValue;
  11367. else
  11368. sxPlcData.Add(newKey, newValue);
  11369. }
  11370. /// <summary>
  11371. /// PLC需要写入的数据 -添加数据
  11372. /// </summary>
  11373. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey,
  11374. WriteToPLC_Flag newValue)
  11375. {
  11376. if (sxPLCWriteData.ContainsKey(newKey))
  11377. sxPLCWriteData[newKey] = newValue;
  11378. else
  11379. sxPLCWriteData.Add(newKey, newValue);
  11380. }
  11381. /// <summary>
  11382. /// PLC回写操作,写后清空flag
  11383. /// </summary>
  11384. /// <param name="modbusClient">modbus对象</param>
  11385. /// <param name="pLCReadDatas">读取到的数据字典</param>
  11386. /// <param name="pLCWriteDatas">需要写入的数据</param>
  11387. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas,
  11388. ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  11389. {
  11390. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  11391. {
  11392. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  11393. for (int i = 0; i < pLCWriteDatas.Count; i++)
  11394. {
  11395. string mesFlagName = pLCWriteDatas[i].Name;
  11396. int mesFlagAdress = pLCWriteDatas[i].Adress;
  11397. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  11398. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  11399. {
  11400. // 先回写数据
  11401. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  11402. for (int j = 0; j < writeToPLCDatas.Count; j++)
  11403. {
  11404. int mesDataAdress = writeToPLCDatas[j].Adress;
  11405. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  11406. switch (mesDataType)
  11407. {
  11408. case PLCValueType.Short:
  11409. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  11410. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  11411. break;
  11412. case PLCValueType.String:
  11413. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  11414. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  11415. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr,
  11416. mesDataValueStrLength);
  11417. break;
  11418. }
  11419. }
  11420. // 再回写信号
  11421. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  11422. // 存储读取数据的字典
  11423. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  11424. // 存储写入数据的字典 - 清空写入值
  11425. pLCWriteDatas[i].Value = (short)0;
  11426. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  11427. }
  11428. }
  11429. }
  11430. }
  11431. /// <summary>
  11432. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  11433. /// </summary>
  11434. /// <param name="no">3</param>
  11435. /// <param name="stationCode">设备编号</param>
  11436. /// <param name="stationNameStr">设备名称</param>
  11437. /// <param name="plcOrder">车间订单号</param>
  11438. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  11439. {
  11440. try
  11441. {
  11442. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  11443. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  11444. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  11445. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  11446. int result1 = 0;
  11447. switch (stationCode)
  11448. {
  11449. case 2:
  11450. case 3:
  11451. case 4:
  11452. case 6:
  11453. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  11454. break;
  11455. case 102:
  11456. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  11457. break;
  11458. case 103:
  11459. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  11460. break;
  11461. case 104:
  11462. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  11463. break;
  11464. case 106:
  11465. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  11466. break;
  11467. default:
  11468. // MES_Flag 为“6未找到正确设备编号”
  11469. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  11470. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  11471. return;
  11472. }
  11473. short result = result1 == 1 ? (short)1 : (short)2;
  11474. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  11475. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  11476. }
  11477. catch (Exception ex)
  11478. {
  11479. // MES_Flag 为2上位机报错
  11480. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  11481. string str = ex.StackTrace;
  11482. AddMessage_Station(stationNameStr, LogType.Error,
  11483. $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11484. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11485. }
  11486. }
  11487. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  11488. #region UI刷新
  11489. /// <summary>
  11490. /// 更新商品信息的UI + 下发产品信息(SN)
  11491. /// </summary>
  11492. private void UpdateProductInfo()
  11493. {
  11494. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  11495. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  11496. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  11497. //txt_CurSupplierCode.Text = ""; // 供应商代号
  11498. }
  11499. /// <summary>
  11500. /// 更新PLC连接状态的UI
  11501. /// </summary>
  11502. /// <param name="no">PLC编号</param>
  11503. /// <param name="status">状态</param>
  11504. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  11505. {
  11506. if (this != null && !this.IsDisposed)
  11507. {
  11508. switch (imgNo)
  11509. {
  11510. case 1:
  11511. this.BeginInvoke(new Action(() => { picPLC.Image = imageListState.Images[status]; }));
  11512. break;
  11513. case 2:
  11514. this.BeginInvoke(new Action(() => { pictureBox2.Image = imageListState.Images[status]; }));
  11515. break;
  11516. case 3:
  11517. this.BeginInvoke(new Action(() => { pictureBox3.Image = imageListState.Images[status]; }));
  11518. break;
  11519. case 4:
  11520. this.BeginInvoke(new Action(() => { pictureBox4.Image = imageListState.Images[status]; }));
  11521. break;
  11522. case 5:
  11523. this.BeginInvoke(new Action(() => { pictureBox5.Image = imageListState.Images[status]; }));
  11524. break;
  11525. case 6:
  11526. this.BeginInvoke(new Action(() => { pictureBox6.Image = imageListState.Images[status]; }));
  11527. break;
  11528. case 7:
  11529. this.BeginInvoke(new Action(() => { pictureBox7.Image = imageListState.Images[status]; }));
  11530. break;
  11531. case 8:
  11532. this.BeginInvoke(new Action(() => { pictureBox8.Image = imageListState.Images[status]; }));
  11533. break;
  11534. default:
  11535. break;
  11536. }
  11537. }
  11538. Task.Run(() => // 更新PLC交互页的指示灯
  11539. {
  11540. try
  11541. {
  11542. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  11543. {
  11544. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  11545. }
  11546. }
  11547. catch
  11548. {
  11549. }
  11550. });
  11551. }
  11552. #endregion UI刷新
  11553. #region 日志
  11554. /// <summary>
  11555. /// 添加各工位运行日志(同步至PLC交互页面)
  11556. /// </summary>
  11557. /// <param name="stationNameStr">工站名称</param>
  11558. /// <param name="logType">日志类型</param>
  11559. /// <param name="message">日志内容</param>
  11560. /// <param name="snNumber">产品数字SN</param>
  11561. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  11562. {
  11563. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")
  11564. && (message.Contains("更新整线运行数据完毕") || message.Contains("更新整线报警数据完毕"))
  11565. ))
  11566. {
  11567. AddMessage(logType, message); // 首页展示+日志记录
  11568. }
  11569. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  11570. {
  11571. StationName = stationNameStr,
  11572. SnNumber = snNumber,
  11573. Message = message,
  11574. CreateTime = DateTime.Now
  11575. };
  11576. // PLC交互页展示
  11577. Task.Run(() =>
  11578. {
  11579. try
  11580. {
  11581. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  11582. {
  11583. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  11584. }
  11585. }
  11586. catch
  11587. {
  11588. }
  11589. });
  11590. }
  11591. /// <summary>
  11592. /// 添加运行日志
  11593. /// </summary>
  11594. /// <param name="logType">日志类型</param>
  11595. /// <param name="message">日志内容</param>
  11596. public void AddMessage(LogType logType, string message)
  11597. {
  11598. OnMessage(logType, message);
  11599. string date = DateTime.Now.ToString("yyyy/MM/dd");
  11600. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  11601. string msgShow = time + "--> " + message + "\r\n";
  11602. this.BeginInvoke(new Action(() =>
  11603. {
  11604. systemLog.Rows.Insert(0, date, time, message);
  11605. if (systemLog.Rows.Count >= 100)
  11606. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  11607. }));
  11608. }
  11609. /// <summary>
  11610. /// 添加运行日志-保存
  11611. /// </summary>
  11612. /// <param name="logType">日志类型</param>
  11613. /// <param name="message">日志内容</param>
  11614. private void OnMessage(LogType logType, string msg)
  11615. {
  11616. MessageEvent?.Invoke(logType, msg);
  11617. }
  11618. /// <summary>
  11619. /// 保存PLC写入日志
  11620. /// </summary>
  11621. /// <param name="logType"></param>
  11622. /// <param name="logValue"></param>
  11623. private void WritePLCLog(LogType logType, string logValue)
  11624. {
  11625. switch ((int)logType)
  11626. {
  11627. case 0:
  11628. _PLCLogNet.WriteDebug(logValue);
  11629. break;
  11630. case 1:
  11631. _PLCLogNet.WriteInfo(logValue);
  11632. break;
  11633. case 2:
  11634. _PLCLogNet.WriteWarn(logValue);
  11635. break;
  11636. case 3:
  11637. _PLCLogNet.WriteError(logValue);
  11638. break;
  11639. default:
  11640. _PLCLogNet.WriteFatal(logValue);
  11641. break;
  11642. }
  11643. }
  11644. /// <summary>
  11645. /// IOT Mqtt回调方法- With DataId
  11646. /// </summary>
  11647. /// <param name="id"></param>
  11648. /// <param name="v"></param>
  11649. /// <param name="dataId"></param>
  11650. public void CallbackWithDataId(string id, string msg, string dataId)
  11651. {
  11652. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  11653. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  11654. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  11655. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  11656. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  11657. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  11658. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  11659. }
  11660. /// <summary>
  11661. /// AGV Mqtt回调方法- 记录Log并处理数据
  11662. /// </summary>
  11663. /// <param name="obj"></param>
  11664. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  11665. {
  11666. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  11667. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  11668. // 接收到的信息
  11669. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  11670. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  11671. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  11672. {
  11673. }
  11674. }
  11675. #endregion 日志
  11676. /// <summary>
  11677. /// 实例化报警字典
  11678. /// </summary>
  11679. private void InitalDicAlarm()
  11680. {
  11681. #region 第一个工站(这里未区分工位,所以下面出现的‘工位代码’使用‘线别代码’代替)
  11682. List<Alarm> keyValues1 = new List<Alarm>
  11683. {
  11684. #region 第一组报警(电机)
  11685. new Alarm { 报警类型 = "电机故障", 报警详情 = "料盘搬运_Y轴电机故障", 关联的PLC地址 = 5100 },
  11686. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_X轴电机故障", 关联的PLC地址 = 5101 },
  11687. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_Z轴电机故障", 关联的PLC地址 = 5102 },
  11688. new Alarm { 报警类型 = "电机故障", 报警详情 = "载具搬运_X轴电机故障", 关联的PLC地址 = 5103 },
  11689. new Alarm { 报警类型 = "电机故障", 报警详情 = "镭射_X轴电机故障", 关联的PLC地址 = 5104 },
  11690. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_X轴电机故障", 关联的PLC地址 = 5105 },
  11691. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_Z轴电机故障", 关联的PLC地址 = 5106 },
  11692. new Alarm { 报警类型 = "电机故障", 报警详情 = "下相机_X轴电机故障", 关联的PLC地址 = 5107 },
  11693. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_Y轴电机故障", 关联的PLC地址 = 5108 },
  11694. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_X轴电机故障", 关联的PLC地址 = 5109 },
  11695. #endregion 第一组报警(电机)
  11696. #region 第二组报警(气缸)
  11697. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料进退气缸故障", 关联的PLC地址 = 5200 },
  11698. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料升降气缸故障", 关联的PLC地址 = 5201 },
  11699. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓顶升气缸故障", 关联的PLC地址 = 5202 },
  11700. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体取料夹爪气缸故障", 关联的PLC地址 = 5203 },
  11701. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料仓顶升气缸故障", 关联的PLC地址 = 5204 },
  11702. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料平移气缸故障", 关联的PLC地址 = 5205 },
  11703. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料升降气缸故障", 关联的PLC地址 = 5206 },
  11704. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料夹爪气缸故障", 关联的PLC地址 = 5207 },
  11705. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料旋转气缸故障", 关联的PLC地址 = 5208 },
  11706. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装平移气缸故障", 关联的PLC地址 = 5209 },
  11707. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装升降气缸故障", 关联的PLC地址 = 5210 },
  11708. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装夹爪气缸故障", 关联的PLC地址 = 5211 },
  11709. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装撑开气缸故障", 关联的PLC地址 = 5212 },
  11710. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸1故障", 关联的PLC地址 = 5213 },
  11711. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸2故障", 关联的PLC地址 = 5214 },
  11712. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具下料移载气缸故障", 关联的PLC地址 = 5215 },
  11713. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具侧推气缸故障", 关联的PLC地址 = 5216 },
  11714. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具回流气缸故障", 关联的PLC地址 = 5217 },
  11715. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2压料气缸故障", 关联的PLC地址 = 5218 },
  11716. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2电测气缸故障", 关联的PLC地址 = 5219 },
  11717. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2气密气缸故障", 关联的PLC地址 = 5220 },
  11718. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3下压气缸故障", 关联的PLC地址 = 5221 },
  11719. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3上顶气缸故障", 关联的PLC地址 = 5222 },
  11720. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位5相机升降气缸故障", 关联的PLC地址 = 5223 },
  11721. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组升降气缸故障", 关联的PLC地址 = 5224 },
  11722. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸1故障", 关联的PLC地址 = 5225 },
  11723. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸2故障", 关联的PLC地址 = 5226 },
  11724. new Alarm { 报警类型 = "气缸故障", 报警详情 = "机械手夹爪气缸故障", 关联的PLC地址 = 5227 },
  11725. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位4:镭射压料气缸故障", 关联的PLC地址 = 5228 },
  11726. #endregion 第二组报警(气缸)
  11727. #region 第三组报警(其他故障)
  11728. new Alarm { 报警类型 = "其他故障", 报警详情 = "上料处缺料报警", 关联的PLC地址 = 5300 },
  11729. new Alarm { 报警类型 = "其他故障", 报警详情 = "震盘缺料报警", 关联的PLC地址 = 5301 },
  11730. new Alarm { 报警类型 = "其他故障", 报警详情 = "成品仓料满报警", 关联的PLC地址 = 5302 },
  11731. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照超时报警", 关联的PLC地址 = 5303 },
  11732. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照NG报警", 关联的PLC地址 = 5304 },
  11733. new Alarm { 报警类型 = "其他故障", 报警详情 = "玻璃门打开报警", 关联的PLC地址 = 5305 },
  11734. #endregion 第三组报警(其他故障)
  11735. };
  11736. DicAlarms_Cur.Add(GlobalContext.LineCode, keyValues1); // 这里使用线体代替工位
  11737. #endregion 第一个工站(这里使用线体代替工位)
  11738. # region 第二个工站-原来的写法(废弃)
  11739. //keyValues = new Dictionary<int, AlarmData[]>();
  11740. ////1
  11741. //dicAlarmName = new Dictionary<int, Alarm>();
  11742. //dicAlarmName.Add(0, new Alarm { Name = "M01衬套组模组X电机报警" });
  11743. //dicAlarmName.Add(1, new Alarm { Name = "M02衬套组模组Y电机报警" });
  11744. //dicAlarmName.Add(2, new Alarm { Name = "M03衬套组模组Z电机报警" });
  11745. //dicAlarmName.Add(3, new Alarm { Name = "M04衬套组模组U电机报警" });
  11746. //dicAlarmName.Add(4, new Alarm { Name = "M05外流线皮带电机报警" });
  11747. //alarmDatas = new AlarmData[dicAlarmName.Count];
  11748. //for (int i = 0; i < dicAlarmName.Count; i++)
  11749. //{
  11750. // alarmDatas[i] = new AlarmData();
  11751. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  11752. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  11753. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  11754. // alarmDatas[i].AlarmType = 1;
  11755. //}
  11756. //keyValues.Add(1, alarmDatas);
  11757. ////2
  11758. //dicAlarmName = new Dictionary<int, Alarm>();
  11759. //dicAlarmName.Add(0, new Alarm { Name = "C01定位气缸故障" });
  11760. //dicAlarmName.Add(1, new Alarm { Name = "C02左推料气缸故障" });
  11761. //dicAlarmName.Add(2, new Alarm { Name = "C03右推料气缸故障" });
  11762. //dicAlarmName.Add(3, new Alarm { Name = "C04左压料气缸故障" });
  11763. //dicAlarmName.Add(4, new Alarm { Name = "C05右压料气缸故障" });
  11764. //dicAlarmName.Add(5, new Alarm { Name = "C06切料气缸故障" });
  11765. //dicAlarmName.Add(6, new Alarm { Name = "C07左入料吹气气缸故障" });
  11766. //dicAlarmName.Add(7, new Alarm { Name = "C08右入料吹气气缸故障" });
  11767. //alarmDatas = new AlarmData[dicAlarmName.Count];
  11768. //for (int i = 0; i < dicAlarmName.Count; i++)
  11769. //{
  11770. // alarmDatas[i] = new AlarmData();
  11771. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  11772. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  11773. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  11774. // alarmDatas[i].AlarmType = 2;
  11775. //}
  11776. //keyValues.Add(2, alarmDatas);
  11777. ////3
  11778. //dicAlarmName = new Dictionary<int, Alarm>();
  11779. //dicAlarmName.Add(0, new Alarm { Name = "安全门报警" });
  11780. //dicAlarmName.Add(1, new Alarm { Name = "联机通信故障" });
  11781. //dicAlarmName.Add(2, new Alarm { Name = "连续NG报警" });
  11782. //dicAlarmName.Add(3, new Alarm { Name = "合格率低于设定值报警" });
  11783. //alarmDatas = new AlarmData[dicAlarmName.Count];
  11784. //for (int i = 0; i < dicAlarmName.Count; i++)
  11785. //{
  11786. // alarmDatas[i] = new AlarmData();
  11787. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-3";
  11788. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  11789. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  11790. // alarmDatas[i].AlarmType = 3;
  11791. //}
  11792. //keyValues.Add(3, alarmDatas);
  11793. //DicAlarms.Add(2, keyValues);
  11794. #endregion 第二个工站-原来的写法(废弃)
  11795. }
  11796. }
  11797. }