Form_Home.cs 781 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. //using System.Text;
  8. using Microsoft.Win32;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using HslCommunication.LogNet;
  13. using MainForm.FaForm;
  14. using Sunny.UI;
  15. using MainForm.ClassFile.XiaomiAPI;
  16. using System.Diagnostics;
  17. using MainForm.Models;
  18. using SqlSugar;
  19. using EasyModbus;
  20. using ModBusClientSimple.Util;
  21. using csharp_networkprotocol_hpsocket;
  22. using MqttnetServerWin;
  23. using Sunny.UI.Win32;
  24. using MainForm.ClassFile.XiaomiAPI_AGV;
  25. using MainForm.ClassFile.XiaomiAPI_RouteCom;
  26. using HslCommunication.Controls;
  27. using EIP_Protocol;
  28. using MainForm.ClassFile.XiaomiAPI_MES;
  29. using NPOI.Util;
  30. using static MainForm.SQLHelper;
  31. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
  32. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
  33. using MainForm.ClassFile.ProjectClass;
  34. using CommonLib;
  35. using Org.BouncyCastle.Asn1.IsisMtt;
  36. using System.Web.Services.Description;
  37. using System.Numerics;
  38. using MathNet.Numerics.RootFinding;
  39. using HslCommunication.Enthernet;
  40. using BZFAStandardLib;
  41. using MainForm.ClassFile;
  42. using NPOI.SS.Formula.Functions;
  43. using static MainForm.ClassFile.XiaomiAPI.XiaomiMqttClient_Extend;
  44. using System.Net.Http;
  45. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_UpLoadFile;
  46. using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
  47. using System.Reflection;
  48. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
  49. using FaFrameUI;
  50. using System.Security.Policy;
  51. using static MainForm.ClassFile.XiaomiClass.MesHelper;
  52. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
  53. using System.Drawing.Imaging;
  54. using System.Drawing;
  55. using ICSharpCode.SharpZipLib.Zip;
  56. using System.Text.RegularExpressions;
  57. /*
  58. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  59. */
  60. namespace MainForm
  61. {
  62. /// <summary>
  63. /// 记录日志的委托
  64. /// </summary>
  65. /// <param name="logType">日志类型</param>
  66. /// <param name="message">日志信息</param>
  67. public delegate void HomeMessageHandler(LogType logType, string message);
  68. /// <summary>
  69. /// 主页窗体
  70. /// </summary>
  71. public partial class Form_Home : Form
  72. {
  73. #region 常量
  74. //文本常量
  75. private const string Head = "开始采集";
  76. private const string Tail = "采集完成";
  77. private const string Body = "工位出站数据";
  78. private const string BodyCheck = "工位点检数据";
  79. private const string BodyRun = "整线运行数据";
  80. private const string BodyAlarm = "整线报警数据";
  81. #endregion 常量
  82. #region 变量
  83. /// <summary>
  84. /// 委托-记录日志的方法
  85. /// </summary>
  86. public event HomeMessageHandler MessageEvent;
  87. /// <summary>
  88. /// 日志接口
  89. /// </summary>
  90. ILogNet _PLCLogNet;
  91. /// <summary>
  92. /// 用于记录IOT MQTT日志
  93. /// </summary>
  94. ILogNet _IOTMqttLogNet;
  95. /// <summary>
  96. /// 用于记录AGV MQTT日志
  97. /// </summary>
  98. ILogNet _AGVMqttLogNet;
  99. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  100. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  101. // 间隔时间
  102. private int IntervalReadPLC = 300; //ms 读PLC
  103. private int IntervalMonitorMES = 1000; //ms MES心跳
  104. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  105. /// <summary>
  106. /// 设备报警数据
  107. /// </summary>
  108. uint[] _FaultDatas = { };
  109. uint[] _FaultDatas_Old = { };
  110. uint[] _FaultDatas2 = { };
  111. uint[] _FaultDatas_Old2 = { };
  112. // 软件状态
  113. private bool IsRun = true;
  114. #region PLC 与 TCP对象
  115. // 定义一个字典,存plc对象(通讯)
  116. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  117. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  118. // 定义TCPClient对象列表
  119. Dictionary<int, HPSocket_TcpClientHelper>
  120. _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  121. // 定义MQTTHelper对象
  122. MQTTHelper _MQTTHelper = new MQTTHelper();
  123. #endregion PLC 与 TCP对象
  124. /// <summary>
  125. /// 上次的设备运行信息
  126. /// </summary>
  127. private string lineWorkingData1_OldStr = string.Empty;
  128. /// <summary>
  129. /// 设备报警字典-当前结果
  130. /// Dictionary<工位代码,List<报警信息>>
  131. /// </summary>
  132. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  133. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  134. /// <summary>
  135. /// 单机用-设备状态
  136. /// </summary>
  137. //XiaomiDeviceState xmDeviceState = XiaomiDeviceState.Uninitialized;
  138. XiaomiDeviceStateData xmDeviceStateData = new XiaomiDeviceStateData();
  139. private int test_item_num = 0; //iot 过站数据序号
  140. public static string uuid = "";
  141. private bool inpass = false; //保存进站测试状态
  142. public static XiaoMiParm xiaomiParm = new XiaoMiParm();
  143. //记录上传附件的信息
  144. public static FileUpload_FileData fileUploadData = new FileUpload_FileData();
  145. #endregion 变量
  146. #region 窗体基础事件
  147. /// <summary>
  148. /// 初始化
  149. /// </summary>
  150. public Form_Home()
  151. {
  152. InitializeComponent();
  153. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  154. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  155. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  156. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  157. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  158. }
  159. /// <summary>
  160. /// 窗体加载事件
  161. /// </summary>
  162. public void Form_Home_Load(object sender, EventArgs e)
  163. {
  164. try
  165. {
  166. AddMessage(LogType.Info, "开始初始化程序");
  167. //组建plc对象字典
  168. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  169. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  170. if (GlobalContext.IsUsePLC1)
  171. {
  172. GlobalContext.IsUsePLCNow = 1;
  173. GlobalContext.IsUseStationName = "[OP10]壳体清洁上料";
  174. FunsEip.Add(GlobalContext.IsUsePLCNow,
  175. new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  176. }
  177. if (GlobalContext.IsUsePLC2)
  178. {
  179. GlobalContext.IsUsePLCNow = 2;
  180. GlobalContext.IsUseStationName = "[OP20]上盖板上料装备";
  181. FunsEip.Add(GlobalContext.IsUsePLCNow,
  182. new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  183. }
  184. if (GlobalContext.IsUsePLC3)
  185. {
  186. GlobalContext.IsUsePLCNow = 3;
  187. GlobalContext.IsUseStationName = "[OP30]点散热胶装备";
  188. FunsEip.Add(GlobalContext.IsUsePLCNow,
  189. new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  190. }
  191. if (GlobalContext.IsUsePLC4)
  192. {
  193. GlobalContext.IsUsePLCNow = 4;
  194. GlobalContext.IsUseStationName = "[OP40]胶线检测";
  195. FunsEip.Add(GlobalContext.IsUsePLCNow,
  196. new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  197. }
  198. if (GlobalContext.IsUsePLC5)
  199. {
  200. GlobalContext.IsUsePLCNow = 5;
  201. GlobalContext.IsUseStationName = "[OP50]ADD板上料组装装备";
  202. FunsEip.Add(GlobalContext.IsUsePLCNow,
  203. new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  204. }
  205. if (GlobalContext.IsUsePLC6)
  206. {
  207. GlobalContext.IsUsePLCNow = 6;
  208. GlobalContext.IsUseStationName = "[OP70]组上盖板";
  209. FunsEip.Add(GlobalContext.IsUsePLCNow,
  210. new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  211. }
  212. if (GlobalContext.IsUsePLC7)
  213. {
  214. GlobalContext.IsUsePLCNow = 7;
  215. GlobalContext.IsUseStationName = "[OP80]上盖板锁螺丝";
  216. FunsEip.Add(GlobalContext.IsUsePLCNow,
  217. new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  218. }
  219. if (GlobalContext.IsUsePLC8)
  220. {
  221. GlobalContext.IsUsePLCNow = 8;
  222. GlobalContext.IsUseStationName = "[OP90]NG下料";
  223. FunsEip.Add(GlobalContext.IsUsePLCNow,
  224. new Inovance_EIP(GlobalContext.PC8Address,
  225. GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  226. }
  227. if (GlobalContext.IsUsePLC9)
  228. {
  229. GlobalContext.IsUsePLCNow = 9;
  230. GlobalContext.IsUseStationName = "[OP100]半成品下料";
  231. FunsEip.Add(GlobalContext.IsUsePLCNow,
  232. new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  233. }
  234. (bool, string) DicResult = InitalDicAlarm(); // 实例化报警字典
  235. AddMessage(LogType.Info, DicResult.Item2);
  236. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  237. {
  238. if (plcEIP != null)
  239. {
  240. try
  241. {
  242. (int, string) result = plcEIP.Connect();
  243. }
  244. catch (Exception ex)
  245. {
  246. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  247. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
  248. MessageBoxOptions.ServiceNotification);
  249. }
  250. }
  251. }
  252. // 采集任务
  253. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  254. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  255. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  256. if (GlobalContext.IsUsePLC1)
  257. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  258. if (GlobalContext.IsUsePLC2)
  259. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  260. if (GlobalContext.IsUsePLC3)
  261. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  262. if (GlobalContext.IsUsePLC4)
  263. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  264. if (GlobalContext.IsUsePLC5)
  265. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  266. if (GlobalContext.IsUsePLC6)
  267. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  268. if (GlobalContext.IsUsePLC7)
  269. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  270. if (GlobalContext.IsUsePLC8)
  271. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  272. if (GlobalContext.IsUsePLC9)
  273. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  274. #region 初始化
  275. try
  276. {
  277. // 开启MES(Http)
  278. if (GlobalContext.IsUseMES)
  279. {
  280. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  281. if (mesret)
  282. {
  283. picMESStatus.Image = imageListState.Images[1];
  284. GlobalContext.MESIsConnect = true;
  285. AddMessage(LogType.Info, "小米MES初始连接成功!");
  286. }
  287. else
  288. {
  289. picMESStatus.Image = imageListState.Images[0];
  290. GlobalContext.MESIsConnect = false;
  291. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  292. }
  293. }
  294. // 开启IOT(MQTT)
  295. if (GlobalContext.IsUseIot)
  296. {
  297. string addr = GlobalContext.MQTTServerHost;
  298. int port = GlobalContext.MQTTServerPort;
  299. //生产环境需要修改
  300. (int, string) qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666,
  301. GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  302. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult.Item1;
  303. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  304. {
  305. picIot.Image = imageListState.Images[1];
  306. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  307. // 设置回调函数
  308. //XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  309. // 配置参数
  310. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  311. // fds
  312. param.parameter.fds.address = GlobalContext.address;
  313. param.parameter.fds.appId = GlobalContext.appId;
  314. param.parameter.fds.appKey = GlobalContext.appKey;
  315. // mes
  316. param.parameter.mes.address = GlobalContext.ServerIp;
  317. param.parameter.mes.appId = GlobalContext.MESAppId;
  318. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  319. // mqtt
  320. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  321. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  322. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  323. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  324. // 设备配置
  325. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  326. if (GlobalContext.IsUsePLC1)
  327. {
  328. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  329. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  330. xiaomiParm.workstation = GlobalContext.S1_work_station; //工站
  331. }
  332. if (GlobalContext.IsUsePLC2)
  333. {
  334. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  335. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  336. xiaomiParm.workstation = GlobalContext.S2_work_station; //工站
  337. }
  338. if (GlobalContext.IsUsePLC3)
  339. {
  340. param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
  341. //param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
  342. }
  343. if (GlobalContext.IsUsePLC4)
  344. {
  345. param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
  346. param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
  347. xiaomiParm.workstation = GlobalContext.s4_work_station; //工站
  348. }
  349. if (GlobalContext.IsUsePLC5)
  350. {
  351. param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
  352. param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
  353. xiaomiParm.workstation = GlobalContext.s5_work_station; //工站
  354. }
  355. if (GlobalContext.IsUsePLC6)
  356. {
  357. param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
  358. param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
  359. xiaomiParm.workstation = GlobalContext.s6_work_station; //工站
  360. }
  361. if (GlobalContext.IsUsePLC7)
  362. {
  363. param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  364. //param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  365. xiaomiParm.stationCode = GlobalContext.s7_1_station;
  366. }
  367. if (GlobalContext.IsUsePLC8)
  368. {
  369. param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
  370. param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
  371. xiaomiParm.workstation = GlobalContext.s8_work_station; //工站
  372. }
  373. if (GlobalContext.IsUsePLC9)
  374. {
  375. param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
  376. param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
  377. xiaomiParm.workstation = GlobalContext.s9_work_station; //工站
  378. }
  379. param.parameter.equipment.project = GlobalContext.Project_Code;
  380. param.parameter.equipment.productMode = "debug";
  381. param.parameter.other.logLevel = 0;
  382. param.parameter.other.LogPath = GlobalContext.MqttLogDir;
  383. XiaomiMqttClient_Extend.ParameterConfig(param);
  384. //保存全局变量
  385. xiaomiParm.stationCode = param.parameter.equipment.stationCode;
  386. xiaomiParm.deviceCode = param.parameter.equipment.deviceCode;
  387. }
  388. else
  389. {
  390. picIot.Image = imageListState.Images[0];
  391. AddMessage(LogType.Info,
  392. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  393. }
  394. }
  395. // 开启AGV(Http与MQTT)
  396. if (GlobalContext.IsUseAGV)
  397. {
  398. // AGV HTTP
  399. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  400. if (mesret1)
  401. {
  402. picAgvHttp.Image = imageListState.Images[1];
  403. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  404. }
  405. else
  406. {
  407. picAgvHttp.Image = imageListState.Images[0];
  408. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  409. }
  410. string agvMqttIp = GlobalContext.MQTTServerHost;
  411. int agvMqttPort = GlobalContext.MQTTServerPort;
  412. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  413. ResultData_MQTT result_MQTT = _MQTTHelper
  414. .CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  415. // AGV MQTT
  416. if (result_MQTT.ResultCode == 1)
  417. {
  418. picAgvMqtt.Image = imageListState.Images[1];
  419. GlobalContext.AGVMQTTIsConnect = true;
  420. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  421. ResultData_MQTT result =
  422. XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  423. AddMessage(LogType.Info,
  424. $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  425. }
  426. else
  427. {
  428. picAgvMqtt.Image = imageListState.Images[0];
  429. GlobalContext.AGVMQTTIsConnect = false;
  430. AddMessage(LogType.Info,
  431. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  432. }
  433. }
  434. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  435. Task.Run(MonitorMESConnect);
  436. // 查询PLC连接状态
  437. foreach (int plcNo in FunsEip.Keys)
  438. {
  439. bool connected = FunsEip[plcNo].IsConnected;
  440. if (connected)
  441. {
  442. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  443. AddMessage(LogType.Info, msg);
  444. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  445. }
  446. else
  447. {
  448. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  449. AddMessage(LogType.Info, msg);
  450. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  451. }
  452. }
  453. // PLC4时 初始化扫码器TCP
  454. //if (GlobalContext.IsUsePLC4)
  455. // HpTCPClientInit();
  456. // 开启PLC的业务处理线程-监听PLC点位+状态
  457. foreach (Task task in TaskReadProcess)
  458. {
  459. if (task != null)
  460. task.Start();
  461. }
  462. //// 开启iot的线程
  463. TaskReadAlarm.Start();
  464. ////下传MES信息给1工位(先判断下plc对象数量)
  465. //if (Funs.Count > 1)
  466. // DownLoadProductInfo(1);
  467. if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  468. {
  469. state_l.Text = "设备状态(左):";
  470. state_r.Text = "设备状态(右):";
  471. state_r.Visible = true;
  472. lblDeviceStates2.Visible = true;
  473. }
  474. //上传操作记录
  475. operateToIot("startup", "开启");
  476. AddMessage(LogType.Info, "程序初始化完成");
  477. }
  478. catch (Exception ex)
  479. {
  480. string str = ex.StackTrace;
  481. this.BeginInvoke(new Action(() =>
  482. {
  483. AddMessage(LogType.Error,
  484. "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  485. str.Length - str.LastIndexOf("\\") - 1));
  486. }));
  487. }
  488. #endregion
  489. }
  490. catch (Exception ex)
  491. {
  492. string str = ex.StackTrace;
  493. OnMessage(LogType.Info,
  494. "主窗体的首页初始化出错!异常位置:" +
  495. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" +
  496. ex.Message.ToString());
  497. if (ex.Message != null && ex.Message.Contains("timed out"))
  498. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  499. else
  500. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  501. }
  502. }
  503. /// <summary>
  504. /// 窗体关闭事件
  505. /// </summary>
  506. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  507. {
  508. Closed2();
  509. }
  510. public void Closed2()
  511. {
  512. try
  513. {
  514. IsRun = false;
  515. Thread.Sleep(IntervalReadPLC);
  516. // 断开TCP
  517. int count = _HPSocket_TcpClients.Count();
  518. for (int i = 0; i < count; i++)
  519. {
  520. try
  521. {
  522. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  523. {
  524. _HPSocket_TcpClients[i].Stop();
  525. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  526. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  527. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  528. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  529. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  530. }
  531. }
  532. catch
  533. {
  534. }
  535. }
  536. // 关闭Iot
  537. try
  538. {
  539. XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath,
  540. GlobalContext.MqttServerName);
  541. }
  542. catch
  543. {
  544. }
  545. // 关闭AGV Mqtt
  546. try
  547. {
  548. _MQTTHelper.DisconnectAsync_Client().Wait();
  549. }
  550. catch
  551. {
  552. }
  553. }
  554. catch
  555. {
  556. }
  557. }
  558. #endregion 窗体基础事件
  559. #region 监控MES状态
  560. /// <summary>
  561. /// 监控MES连接状态
  562. /// </summary>
  563. private void MonitorMESConnect()
  564. {
  565. while (IsRun) // 运行被控线程
  566. {
  567. try
  568. {
  569. // 开启MES(Http)
  570. if (GlobalContext.IsUseMES)
  571. {
  572. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  573. if (mesret)
  574. {
  575. picMESStatus.Image = imageListState.Images[1];
  576. GlobalContext.MESIsConnect = true;
  577. }
  578. else
  579. {
  580. picMESStatus.Image = imageListState.Images[0];
  581. GlobalContext.MESIsConnect = false;
  582. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  583. }
  584. }
  585. // 开启IOT(MQTT)
  586. if (GlobalContext.IsUseIot)
  587. {
  588. bool iIot = XiaomiMqttClient.IsOpen;
  589. if (iIot)
  590. picIot.Image = imageListState.Images[1];
  591. else
  592. {
  593. picIot.Image = imageListState.Images[0];
  594. OnMessage(LogType.Info,
  595. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  596. }
  597. }
  598. // 开启AGV(Http与MQTT)
  599. if (GlobalContext.IsUseAGV)
  600. {
  601. // AGV Http
  602. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  603. if (mesret1)
  604. picAgvHttp.Image = imageListState.Images[1];
  605. else
  606. {
  607. picAgvHttp.Image = imageListState.Images[0];
  608. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  609. }
  610. // AGV MQTT
  611. if (GlobalContext.AGVMQTTIsConnect)
  612. picAgvMqtt.Image = imageListState.Images[1];
  613. else
  614. {
  615. picAgvMqtt.Image = imageListState.Images[0];
  616. OnMessage(LogType.Info,
  617. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  618. }
  619. }
  620. }
  621. catch (Exception ex)
  622. {
  623. string str = ex.StackTrace;
  624. AddMessage(LogType.Error,
  625. "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  626. str.Length - str.LastIndexOf("\\") - 1));
  627. }
  628. Thread.Sleep(IntervalMonitorMES);
  629. }
  630. }
  631. #endregion 监控MES连接状态
  632. #region 采集设备状态、运行数据、报警数据
  633. /// <summary>
  634. /// 请求设备状态 5000
  635. /// </summary>
  636. /// <param name="no">1</param>
  637. /// <param name="stationNameStr"></param>
  638. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  639. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  640. {
  641. try
  642. {
  643. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  644. {
  645. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  646. return result;
  647. }
  648. else
  649. {
  650. return 0;
  651. }
  652. }
  653. catch (Exception ex)
  654. {
  655. string str = ex.StackTrace;
  656. AddMessage_Station(stationNameStr, LogType.Error,
  657. "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  658. str.Length - str.LastIndexOf("\\") - 1));
  659. return 0;
  660. }
  661. }
  662. /// <summary>
  663. /// 检查是否可采集点检数据 - 不取新值
  664. /// 5000不为1时可点检
  665. /// </summary>
  666. /// <returns></returns>
  667. public bool CheckCanSpotcheck1(int deviceState)
  668. {
  669. //return true;
  670. //D5000 = 1,代表设备控制状态处于运行状态
  671. //D5000 = 2, 代表设备控制状态处于故障状态
  672. //D5000 = 3,代表设备控制状态处于缺料状态
  673. //D5000 = 4, 代表设备控制状态处于待机状态
  674. //D5000 = 5,代表设备控制状态处于维修状态
  675. return deviceState != 1;
  676. }
  677. /// <summary>
  678. /// 检查是否可采集产品数据 - 不取新值
  679. /// </summary>
  680. /// <returns></returns>
  681. public bool CheckCanCollData(int deviceState)
  682. {
  683. return deviceState == 0; // 点检时该值不为0
  684. }
  685. /// <summary>
  686. /// 采集到的设备状态
  687. /// </summary>
  688. private string _DeviceStates = "未知状态";
  689. private string _DeviceStates_Old = "未知状态";
  690. private string _DeviceStates2 = "未知状态";
  691. private string _DeviceStates_Old2 = "未知状态";
  692. /// <summary>
  693. /// 获取设备报警数据与获取设备运行信息
  694. /// </summary>
  695. private async void ReadAlarmAllPLC()
  696. {
  697. /// 获取设备报警数据与状态信息
  698. string stationNameStr = "获取设备报警数据与状态信息";
  699. // 已连接到PLC
  700. while (IsRun)
  701. {
  702. try
  703. {
  704. #region 报警数据
  705. try
  706. {
  707. //_FaultDatas = new uint[] { 4, 0, 30, 10 };
  708. if (_FaultDatas.Length > 0)
  709. {
  710. ReadPLCAlarmToIot(_FaultDatas, _FaultDatas_Old, stationNameStr);
  711. }
  712. else
  713. {
  714. AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!");
  715. }
  716. if (_FaultDatas2.Length > 0)
  717. {
  718. ReadPLCAlarmToIot(_FaultDatas2, _FaultDatas_Old2, stationNameStr);
  719. }
  720. else
  721. {
  722. AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!");
  723. }
  724. }
  725. catch (Exception ex)
  726. {
  727. string str = ex.StackTrace;
  728. AddMessage_Station(stationNameStr, LogType.Error,
  729. $"【报警日志】{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" +
  730. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  731. }
  732. #endregion 报警数据
  733. #region 设备状态
  734. //if (!GlobalContext._IsCon_plc1Alarm)
  735. //{
  736. // UpdatePLCMonitor(1, -2, 0);
  737. // continue;
  738. //}
  739. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  740. {
  741. if (plcEIP != null)
  742. {
  743. if (plcEIP.IsConnected)
  744. {
  745. #region 主页展示设备运行状态并上传到IOT中,有双工位left就是左工位,没有双工位left就是单工位
  746. switch (xmDeviceStateData.left)
  747. {
  748. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  749. _DeviceStates = "未初始化状态";
  750. lblDeviceStates.Text = _DeviceStates;
  751. break;
  752. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  753. _DeviceStates = "初始化状态";
  754. lblDeviceStates.Text = _DeviceStates;
  755. break;
  756. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  757. _DeviceStates = "初始化完成状态";
  758. lblDeviceStates.Text = _DeviceStates;
  759. break;
  760. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  761. _DeviceStates = "运行状态";
  762. lblDeviceStates.Text = _DeviceStates;
  763. break;
  764. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  765. _DeviceStates = "暂停状态";
  766. lblDeviceStates.Text = _DeviceStates;
  767. break;
  768. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  769. _DeviceStates = "故障状态";
  770. lblDeviceStates.Text = _DeviceStates;
  771. break;
  772. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  773. _DeviceStates = "警报状态";
  774. lblDeviceStates.Text = _DeviceStates;
  775. break;
  776. }
  777. if (!_DeviceStates.Equals(_DeviceStates_Old))
  778. {
  779. var iotResult =
  780. SaveDeviceStateData(stationNameStr, xmDeviceStateData.left, "left"); // 上传+保存
  781. if (iotResult.Item1 == 1)
  782. {
  783. _DeviceStates_Old = _DeviceStates;
  784. AddMessage_Station(stationNameStr, LogType.Info,
  785. "【设备状态】" + stationNameStr + $"_上传设备状态到Iot成功!");
  786. }
  787. else
  788. AddMessage_Station(stationNameStr, LogType.Info,
  789. "【设备状态】" + stationNameStr +
  790. $"_上传设备状态到Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  791. }
  792. #endregion 主页展示设备运行状态并上传到IOT中
  793. #region 右工位
  794. if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  795. {
  796. switch (xmDeviceStateData.right)
  797. {
  798. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  799. _DeviceStates2 = "未初始化状态";
  800. lblDeviceStates.Text = _DeviceStates2;
  801. break;
  802. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  803. _DeviceStates2 = "初始化状态";
  804. lblDeviceStates.Text = _DeviceStates2;
  805. break;
  806. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  807. _DeviceStates2 = "初始化完成状态";
  808. lblDeviceStates.Text = _DeviceStates2;
  809. break;
  810. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  811. _DeviceStates2 = "运行状态";
  812. lblDeviceStates.Text = _DeviceStates2;
  813. break;
  814. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  815. _DeviceStates2 = "暂停状态";
  816. lblDeviceStates.Text = _DeviceStates2;
  817. break;
  818. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  819. _DeviceStates2 = "故障状态";
  820. lblDeviceStates.Text = _DeviceStates2;
  821. break;
  822. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  823. _DeviceStates2 = "警报状态";
  824. lblDeviceStates.Text = _DeviceStates2;
  825. break;
  826. }
  827. if (!_DeviceStates2.Equals(_DeviceStates_Old2))
  828. {
  829. var iotResult = SaveDeviceStateData(stationNameStr, xmDeviceStateData.left,
  830. "right"); // 上传+保存
  831. if (iotResult.Item1 == 1)
  832. {
  833. _DeviceStates_Old2 = _DeviceStates2;
  834. AddMessage_Station(stationNameStr, LogType.Info,
  835. "【设备状态】" + stationNameStr + $"_上传Iot成功!");
  836. }
  837. else
  838. AddMessage_Station(stationNameStr, LogType.Info,
  839. "【设备状态】" + stationNameStr +
  840. $"_上传Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  841. }
  842. }
  843. #endregion 右工位
  844. }
  845. }
  846. }
  847. #endregion
  848. //if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  849. //{
  850. // DateTime dtNow = DateTime.Now;
  851. // //#region 获取设备运行信息
  852. // //try
  853. // //{
  854. // // LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  855. // // lineWorkingData1.GUID = Guid.NewGuid().ToString();
  856. // // lineWorkingData1.LineName = GlobalContext.LineCode;
  857. // // //
  858. // // lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  859. // // lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  860. // // lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  861. // // lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  862. // // lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  863. // // lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  864. // // lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  865. // // lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  866. // // lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  867. // // lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  868. // // lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  869. // // lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  870. // // lineWorkingData1.CreateTime = DateTime.Now;
  871. // // string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  872. // // // UI展示-展示到设备状态页
  873. // // if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  874. // // {
  875. // // // 查询数据库最新一条数据,确定是不是更新
  876. // // string qSql = @"SELECT top(1) [GUID]
  877. // // ,[LineName]
  878. // // ,[BootTimeLong]
  879. // // ,[NormalTimeLong]
  880. // // ,[StandbyTimeLong]
  881. // // ,[FaultTimeLong]
  882. // // ,[MaterialShortageTimeLong]
  883. // // ,[MaintenanceTimeLong]
  884. // // ,[FaultNumber]
  885. // // ,[OutputNumber]
  886. // // ,[QualifiedNumber]
  887. // // ,[QualifiedRate]
  888. // // ,[DesignRhythm]
  889. // // ,[RealityRhythm]
  890. // // ,[CreateTime]
  891. // // FROM [LineWorkingData]
  892. // // where [CreateTime] > '{0}'
  893. // // and [LineName]='{1}'
  894. // // order by [CreateTime] desc
  895. // // ";
  896. // // qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  897. // // var ds = SQLHelper_New.Query(qSql, null);
  898. // // if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  899. // // {
  900. // // var dataDBlast = new LineWorkingData_ThisTime();
  901. // // dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  902. // // dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  903. // // dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  904. // // dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  905. // // if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  906. // // {
  907. // // dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  908. // // dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  909. // // dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  910. // // dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  911. // // dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  912. // // dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  913. // // dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  914. // // dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  915. // // dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  916. // // dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  917. // // dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  918. // // dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  919. // // string usql = dataDBlast.ToStringUpdate();
  920. // // SQLHelper_New.ExecuteSQL(usql, null);
  921. // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  922. // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  923. // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  924. // // }
  925. // // }
  926. // // else
  927. // // {
  928. // // // 插入
  929. // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  930. // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  931. // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  932. // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  933. // // }
  934. // // }
  935. // // else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  936. // // {
  937. // // LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  938. // // //// 本次开机设备运行情况
  939. // // //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  940. // // //Task.Run(() =>
  941. // // //{
  942. // // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  943. // // // {
  944. // // // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  945. // // // }
  946. // // //});
  947. // // // 本日设备运行情况
  948. // // // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  949. // // if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  950. // // {
  951. // // // 更新
  952. // // lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  953. // // lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  954. // // lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  955. // // lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  956. // // lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  957. // // lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  958. // // lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  959. // // lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  960. // // lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  961. // // lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  962. // // lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  963. // // lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  964. // // SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  965. // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  966. // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  967. // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  968. // // }
  969. // // else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  970. // // {
  971. // // // 插入
  972. // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  973. // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  974. // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  975. // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  976. // // }
  977. // // await Task.Run(() =>
  978. // // {
  979. // // try
  980. // // {
  981. // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  982. // // {
  983. // // Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  984. // // }
  985. // // }
  986. // // catch { }
  987. // // });
  988. // // }
  989. // //}
  990. // //catch (Exception ex)
  991. // //{
  992. // // string str = ex.StackTrace;
  993. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  994. // //}
  995. // //#endregion 获取设备运行信息
  996. // #region 报警数据
  997. // try
  998. // {
  999. // List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  1000. // bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  1001. // // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  1002. // var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  1003. // for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  1004. // {
  1005. // short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  1006. // dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  1007. // if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  1008. // {
  1009. // isNeedUpdUI = true; // 需要更新历史报警UI信息
  1010. // // 记录
  1011. // dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  1012. // switch (dicAlarms_Cur_PLC1[i].是否报警)
  1013. // {
  1014. // case true: // 报警
  1015. // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  1016. // {
  1017. // GUID = Guid.NewGuid().ToString(),
  1018. // LineName = GlobalContext.LineCode, // 线体
  1019. // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  1020. // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  1021. // StartTime = dtNow // 开始时间
  1022. // };
  1023. // // 传输到页面
  1024. // deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  1025. // {
  1026. // 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  1027. // 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  1028. // 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  1029. // 开始时间 = dtNow
  1030. // });
  1031. // // 新增到数据库
  1032. // var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  1033. // SaveAlarmDataByDB(stationNameStr, data1, false);
  1034. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  1035. // break;
  1036. // case false: // 消除报警
  1037. // if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  1038. // {
  1039. // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  1040. // {
  1041. // GUID = Guid.NewGuid().ToString(),
  1042. // LineName = GlobalContext.LineCode, // 线体
  1043. // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  1044. // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  1045. // StartTime = dtNow, // 开始时间
  1046. // EndTime = dtNow, // 开始时间
  1047. // PersistTime = 1, // 耗时1s
  1048. // };
  1049. // // 新增
  1050. // var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  1051. // SaveAlarmDataByDB(stationNameStr, data2, false);
  1052. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  1053. // }
  1054. // else
  1055. // {
  1056. // dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  1057. // dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  1058. // - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  1059. // // 修改
  1060. // var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  1061. // SaveAlarmDataByDB(stationNameStr, data3, true);
  1062. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  1063. // }
  1064. // break;
  1065. // default:
  1066. // break;
  1067. // }
  1068. // }
  1069. // }
  1070. // DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  1071. // // 有新报警则更新
  1072. // if (isNeedUpdUI)
  1073. // {
  1074. // // UI展示 - 展示到设备状态页
  1075. // await Task.Run(() =>
  1076. // {
  1077. // try
  1078. // {
  1079. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  1080. // {
  1081. // Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  1082. // if (Form_Main.formDevAlarm.Visible)
  1083. // {
  1084. // Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  1085. // }
  1086. // }
  1087. // }
  1088. // catch { }
  1089. // });
  1090. // }
  1091. // }
  1092. // catch (Exception ex)
  1093. // {
  1094. // string str = ex.StackTrace;
  1095. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1096. // }
  1097. // #endregion 报警数据
  1098. // UpdatePLCMonitor(1, -2, 1);
  1099. //}
  1100. //else
  1101. //{
  1102. // UpdatePLCMonitor(1, -2, 0);
  1103. //}
  1104. }
  1105. catch (Exception ex)
  1106. {
  1107. //AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1108. AddMessage_Station(stationNameStr, LogType.Error,
  1109. $"PLC1_{stationNameStr}_采集运行数据与报警数据出错!错误信息:" + ex.Message.ToString());
  1110. }
  1111. Thread.Sleep(IntervalAlarm);
  1112. }
  1113. }
  1114. #endregion 轮询PLC
  1115. #region 下发订单信息
  1116. ///// <summary>
  1117. ///// 壳体上料(下发工单)的交互逻辑
  1118. ///// </summary>
  1119. ///// <param name="no"></param>
  1120. ///// <exception cref="NotImplementedException"></exception>
  1121. //private void ReadStation_DownOrderInfo(int plcNo)
  1122. //{
  1123. // // [S1] Tray盘上料装备(板测)
  1124. // // [S2] FCT(板测)
  1125. // // [S3] 值板机
  1126. // // [S4] 取放桁架
  1127. // // [S5] Tray盘下料装备
  1128. // /// 上位机心跳
  1129. // /// 获取设备报警数据与状态信息
  1130. // string stationNameStr = "[S0]壳体上料";
  1131. // while (IsRun)
  1132. // {
  1133. // try
  1134. // {
  1135. // if (!GlobalContext._IsCon_Funs1)
  1136. // {
  1137. // UpdatePLCMonitor(plcNo, 0);
  1138. // continue;
  1139. // }
  1140. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  1141. // {
  1142. // #region 壳体上料(下发工单)
  1143. // try
  1144. // {
  1145. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  1146. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  1147. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  1148. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  1149. // // 重置数据和信号
  1150. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  1151. // {
  1152. // // 清空写给PLC的数据
  1153. // int[] i497 = new int[1] { 0 };
  1154. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  1155. // // MES_Flag重置为0
  1156. // int[] i500 = new int[1] { 0 };
  1157. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  1158. // }
  1159. // }
  1160. // catch (Exception ex)
  1161. // {
  1162. // string str = ex.StackTrace;
  1163. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1164. // }
  1165. // #endregion 壳体上料(下发工单)
  1166. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1167. // }
  1168. // else
  1169. // {
  1170. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  1171. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1172. //
  1173. // Funs[plcNo].Connect();
  1174. // }
  1175. // }
  1176. // catch (Exception ex)
  1177. // {
  1178. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  1179. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1180. //
  1181. // Funs[plcNo].ReConnect();
  1182. // }
  1183. // Thread.Sleep(IntervalReadPLC);
  1184. // }
  1185. //}
  1186. ///// <summary>
  1187. ///// 下发订单信息到PLC
  1188. ///// </summary>
  1189. ///// <param name="no">PLC编号</param>
  1190. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  1191. //{
  1192. // try
  1193. // {
  1194. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  1195. // {
  1196. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  1197. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  1198. // }
  1199. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  1200. // }
  1201. // catch (Exception ex)
  1202. // {
  1203. // string str = ex.StackTrace;
  1204. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1205. // }
  1206. //}
  1207. /// <summary>
  1208. /// 下发清料信号
  1209. /// </summary>
  1210. /// <param name="no">PLC编号</param>
  1211. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  1212. {
  1213. try
  1214. {
  1215. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  1216. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  1217. return true;
  1218. }
  1219. catch (Exception ex)
  1220. {
  1221. string str = ex.StackTrace;
  1222. AddMessage_Station(stationNameStr, LogType.Error,
  1223. "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  1224. str.Length - str.LastIndexOf("\\") - 1));
  1225. return false;
  1226. }
  1227. }
  1228. #endregion 下发订单信息
  1229. #region Xiaomi 贲流
  1230. #region 公共方法
  1231. private static bool ProgressState = false;
  1232. private static readonly object lockObj = new object(); // 锁对象
  1233. private static bool isCollectingFlagLeft;
  1234. private static bool isCollectingFlagRight;
  1235. private bool OpenDailogFalg = true; //是否开启扫码弹窗标识
  1236. public static bool isNoStop = false; //是否停止循环
  1237. public void ConnectToIOT()
  1238. {
  1239. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  1240. // fds
  1241. param.parameter.fds.address = GlobalContext.address;
  1242. param.parameter.fds.appId = GlobalContext.appId;
  1243. param.parameter.fds.appKey = GlobalContext.appKey;
  1244. // mes
  1245. param.parameter.mes.address = GlobalContext.ServerIp;
  1246. param.parameter.mes.appId = GlobalContext.MESAppId;
  1247. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  1248. // mqtt
  1249. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  1250. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  1251. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  1252. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  1253. // 设备配置
  1254. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  1255. if (GlobalContext.IsUsePLC1)
  1256. {
  1257. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  1258. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  1259. xiaomiParm.workstation = GlobalContext.S1_work_station; //工站
  1260. }
  1261. if (GlobalContext.IsUsePLC2)
  1262. {
  1263. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  1264. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  1265. xiaomiParm.workstation = GlobalContext.S2_work_station; //工站
  1266. }
  1267. if (GlobalContext.IsUsePLC3)
  1268. {
  1269. param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
  1270. //param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
  1271. }
  1272. if (GlobalContext.IsUsePLC4)
  1273. {
  1274. param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
  1275. param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
  1276. xiaomiParm.workstation = GlobalContext.s4_work_station; //工站
  1277. }
  1278. if (GlobalContext.IsUsePLC5)
  1279. {
  1280. param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
  1281. param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
  1282. xiaomiParm.workstation = GlobalContext.s5_work_station; //工站
  1283. }
  1284. if (GlobalContext.IsUsePLC6)
  1285. {
  1286. param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
  1287. param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
  1288. xiaomiParm.workstation = GlobalContext.s6_work_station; //工站
  1289. }
  1290. if (GlobalContext.IsUsePLC7)
  1291. {
  1292. param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  1293. //param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  1294. xiaomiParm.stationCode = GlobalContext.s7_1_station;
  1295. }
  1296. if (GlobalContext.IsUsePLC8)
  1297. {
  1298. param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
  1299. param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
  1300. xiaomiParm.workstation = GlobalContext.s8_work_station; //工站
  1301. }
  1302. if (GlobalContext.IsUsePLC9)
  1303. {
  1304. param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
  1305. param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
  1306. xiaomiParm.workstation = GlobalContext.s9_work_station; //工站
  1307. }
  1308. param.parameter.equipment.project = GlobalContext.Project_Code;
  1309. param.parameter.equipment.productMode = "debug";
  1310. param.parameter.other.logLevel = 0;
  1311. param.parameter.other.LogPath = GlobalContext.MqttLogDir;
  1312. XiaomiMqttClient_Extend.ParameterConfig(param);
  1313. }
  1314. /// <summary>
  1315. /// float[]转为string
  1316. /// </summary>
  1317. public string FloatArrayToString(float[] nScrewResults)
  1318. {
  1319. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  1320. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  1321. }
  1322. /// <summary>
  1323. /// short[]转为string
  1324. /// </summary>
  1325. public string ShortArrayToString(short[] nScrewResults)
  1326. {
  1327. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  1328. return string.Join(",", nScrewResults);
  1329. }
  1330. /// <summary>
  1331. /// 写入PLC重复三次
  1332. /// </summary>
  1333. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount,
  1334. T inObj)
  1335. {
  1336. int i = 0;
  1337. int nRet = 0;
  1338. string strRet = "";
  1339. try
  1340. {
  1341. while (i < 3) // 最多上传三次
  1342. {
  1343. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  1344. if (nRet == 0) //成功
  1345. {
  1346. break;
  1347. }
  1348. else
  1349. {
  1350. AddMessage_Station(stationNameStr, LogType.Error,
  1351. $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1352. i++;
  1353. }
  1354. }
  1355. return (nRet, strRet);
  1356. }
  1357. catch (Exception ex)
  1358. {
  1359. return (1, ex.Message);
  1360. }
  1361. }
  1362. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes,
  1363. short[] nScrewOrders, short[] nScrewResults)
  1364. {
  1365. try
  1366. {
  1367. // 获取当前日期
  1368. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1369. // 构建保存路径
  1370. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  1371. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction, "螺丝Mes数据");
  1372. // 确保目录存在
  1373. Directory.CreateDirectory(savePath);
  1374. // 文件名
  1375. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  1376. string filePath = Path.Combine(savePath, fileName);
  1377. // 确保不会超出数组长度,只取前14个或数组的实际长度
  1378. int count = Math.Min(14, fScrewTimes.Length);
  1379. using (StreamWriter sw = new StreamWriter(filePath))
  1380. {
  1381. for (int i = 0; i < count; i++)
  1382. {
  1383. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  1384. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  1385. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  1386. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  1387. sw.WriteLine(); // 空行分隔不同螺丝的信息
  1388. }
  1389. }
  1390. return (0, "");
  1391. }
  1392. catch (Exception ex)
  1393. {
  1394. return (1, ex.Message);
  1395. }
  1396. }
  1397. public Dictionary<string, string> GetLastLineCompensation(string path, string direction, string sn)
  1398. {
  1399. // 创建字典存储补偿点及其对应的值
  1400. Dictionary<string, string> compensationDict = new Dictionary<string, string>();
  1401. try
  1402. {
  1403. //string path = GlobalContext.MESLaserRPath;
  1404. // 获取当前日期并格式化为 "yyyy-MM-dd" 格式
  1405. string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
  1406. string filename = $"Laser-{currentDate}-W0.txt";
  1407. // 拼接完整路径
  1408. string fullPath = Path.Combine(path, filename);
  1409. string lastNonEmptyLine = "";
  1410. // 判断文件是否存在
  1411. if (File.Exists(fullPath))
  1412. {
  1413. //读取文件内容
  1414. string[] lines = File.ReadAllLines(fullPath);
  1415. // 获取最后一行数据(忽略标题行)
  1416. if (lines.Length > 1)
  1417. {
  1418. string lastLine = "";
  1419. for (int i = lines.Length - 1; i > 0; i--)
  1420. {
  1421. if (!string.IsNullOrEmpty(lines[i]))
  1422. {
  1423. lastLine = lines[i];
  1424. break;
  1425. }
  1426. }
  1427. // 将最后一行按逗号分隔
  1428. string[] values = lastLine.Split(',');
  1429. values[1] = sn;
  1430. string key = "三点激光_" + direction; // 构造键名
  1431. string value = string.Join(",", values); // 获取值并去除多余空格
  1432. compensationDict[key] = value;
  1433. //// 提取“1点补偿”到“6点补偿”的值
  1434. //for (int i = 2; i <= 7 && i < values.Length; i++) // 从索引2开始,最多提取6个值
  1435. //{
  1436. // string key = $"{i - 1}点补偿"; // 构造键名
  1437. // string value = values[i].Trim(); // 获取值并去除多余空格
  1438. // compensationDict[key] = value;
  1439. //}
  1440. }
  1441. }
  1442. else
  1443. {
  1444. Console.WriteLine($"文件不存在: {fullPath}");
  1445. }
  1446. }
  1447. catch (Exception ex)
  1448. {
  1449. // 捕获异常并输出错误信息
  1450. Console.WriteLine($"发生错误: {ex.Message}");
  1451. }
  1452. return compensationDict;
  1453. }
  1454. public int PCBStationOutData(BarcodeSet_t Barcode,IoT_DataSet_t iotData)
  1455. {
  1456. int res = 0;
  1457. string jsonstr1 = "";
  1458. try
  1459. {
  1460. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1461. outRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备id(可配置)
  1462. outRequest_Body.stationId = GlobalContext.s5_station; // ⼯位ID(可配置)
  1463. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1464. outRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1465. outRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
  1466. int a1Result = (int)iotData.testStatus;
  1467. //bool pass = a1Result == 1;
  1468. //outRequest_Body.state = pass ? "PASS" : "FAIL"; ; // 出站条件 PASS或FAIL
  1469. outRequest_Body.state = "PASS";
  1470. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1471. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1472. XmStationOut_KeyMaterial keyMaterial = new XmStationOut_KeyMaterial();
  1473. keyMaterial.bindSort = 1;
  1474. keyMaterial.materialSn = Barcode.strProductBarcode;
  1475. outRequest_Body.unitData.keyMaterial.Add(keyMaterial); // 产品码
  1476. jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1477. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1478. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1479. if (response != null && response.header.code == "200")
  1480. {
  1481. res = 1;
  1482. AddMessage(LogType.Info, "上传PCB出站数据到MES服务器---成功!请求信息:" + jsonstr1 + ",返回信息:" + JsonConvert.SerializeObject(response.body));
  1483. }
  1484. else
  1485. {
  1486. res = 0;
  1487. AddMessage(LogType.Error, "上传PCB出站数据到MES服务器---失败!错误信息:"+ response.header.desc + ",请求信息:" + jsonstr1 + ",返回信息:" + JsonConvert.SerializeObject(response.body));
  1488. }
  1489. }
  1490. catch (Exception e)
  1491. {
  1492. res = 0;
  1493. AddMessage(LogType.Info, "上传PCB出站数据到MES服务器---失败!请求信息:" + jsonstr1 + ",返回信息:" + e.Message);
  1494. }
  1495. return res;
  1496. }
  1497. public int PCBStationInData(BarcodeSet_t Barcode, IoT_DataSet_t iotData)
  1498. {
  1499. int res = 0;
  1500. string json_Body = "";
  1501. try
  1502. {
  1503. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1504. inRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  1505. inRequest_Body.stationId = GlobalContext.s5_station; // ⼯位ID(可配置)
  1506. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1507. inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1508. inRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
  1509. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1510. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1511. json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1512. var response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1513. string resultJson = JsonConvert.SerializeObject(response);
  1514. if (response != null && response.header.code == "200")
  1515. {
  1516. res = 1;
  1517. AddMessage(LogType.Info, "上传PCB进站数据到MES服务器---成功!请求信息:" + json_Body + ",返回信息:" + JsonConvert.SerializeObject(response.body));
  1518. }
  1519. else
  1520. {
  1521. res = 0;
  1522. AddMessage(LogType.Error, "上传PCB进站数据到MES服务器---失败!错误信息:" + response.header.desc + ",请求信息:" + json_Body + ",返回信息:" + JsonConvert.SerializeObject(response.body));
  1523. }
  1524. }
  1525. catch (Exception e)
  1526. {
  1527. res = 0;
  1528. AddMessage(LogType.Info, "上传PCB进站数据到MES服务器---失败!请求信息:" + json_Body + ",返回信息:" + e.Message);
  1529. }
  1530. return res;
  1531. }
  1532. /// <summary>
  1533. /// 调用进站接口并保存进站数据
  1534. /// </summary>
  1535. /// <param name="stationNameStr">工站信息</param>
  1536. /// <param name="workorder_code">工单号</param>
  1537. /// <param name="mtltmrk">型号(物料号)</param>
  1538. /// <param name="sn">产品SN</param>
  1539. /// <param name="items">进站数据</param>
  1540. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1541. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn,
  1542. List<TestItem> items, string MachineId, string StationId, bool pass, string slot)
  1543. {
  1544. int result = 0;
  1545. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1546. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1547. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1548. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1549. inRequest_Body.clientTime =
  1550. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1551. inRequest_Body.unitSn = sn; // 产品SN
  1552. inRequest_Body.uuidInspection = uuid;
  1553. inRequest_Body.state = pass ? "PASS" : "FAIL";
  1554. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1555. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1556. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1557. StationIn stationIn = new StationIn()
  1558. {
  1559. Workorder_code = workorder_code, // 车间订单号
  1560. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1561. Sn = sn, // SN
  1562. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1563. Parameter_values = items, // 进站数据
  1564. Write_user = inRequest_Body.userId, // 员工Id
  1565. Test_time = inRequest_Body.clientTime // 进站时间
  1566. };
  1567. // 本地数据
  1568. string sql = stationIn.ToStringInsert(0);
  1569. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1570. result = ret == "成功" ? 1 : 6;
  1571. #region MES
  1572. if (GlobalContext.IsSendStationIn)
  1573. {
  1574. try
  1575. {
  1576. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1577. string resultJson = "";
  1578. string mesRet = string.Empty;
  1579. int i = 0;
  1580. while (i < 2) // 1009会多次尝试上传
  1581. {
  1582. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1583. resultJson = JsonConvert.SerializeObject(response);
  1584. if (response != null && response.header.code == "200")
  1585. break;
  1586. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1587. i++;
  1588. i++;
  1589. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1590. // 记录失败原因
  1591. OnMessage(LogType.Error, $"上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:{mesRet},请求参数:{json_Body}");
  1592. }
  1593. if (response?.header?.code == "200")
  1594. {
  1595. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1596. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1597. result = ret_Upd == "成功" ? 1 : 6;
  1598. AddMessage(LogType.Info,
  1599. $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功,返回参数:{resultJson},请求参数:{json_Body}");
  1600. }
  1601. else
  1602. {
  1603. result = 5;
  1604. AddMessage(LogType.Info,
  1605. $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息: {mesRet},请求参数:{json_Body}");
  1606. }
  1607. string sql_response =
  1608. stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1609. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1610. }
  1611. catch (Exception ex)
  1612. {
  1613. result = 6;
  1614. string str = ex.StackTrace;
  1615. AddMessage_Station(stationNameStr, LogType.Error,
  1616. $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1617. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1618. }
  1619. }
  1620. #endregion
  1621. #region IOT
  1622. //过站结果
  1623. if (GlobalContext.IsMqttSendProcessData)
  1624. {
  1625. PassStationResultRequest request = new PassStationResultRequest();
  1626. request.project_code = GlobalContext.Project_Code; // 项⽬编码
  1627. request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
  1628. request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
  1629. request.line_code = GlobalContext.LineCode; // 线体编码
  1630. request.work_station = xiaomiParm.workstation; // ⼯站ID
  1631. request.device_code = xiaomiParm.deviceCode; // 装备编码
  1632. request.station = xiaomiParm.stationCode;
  1633. request.process_time =
  1634. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
  1635. request.slot = slot; // 槽位编码
  1636. request.sn = sn; // 产品SN
  1637. // request.enter_status = inpass ? "PASS" : "FAIL"; // 进站状态
  1638. request.enter_status = pass ? "PASS" : "FAIL"; // 进站状态
  1639. request.result = ""; // 出站条件 PASS或FAIL; // 过站结果
  1640. request.work_type = "OUT_STATION"; // 作业类型
  1641. // 上传过站结果
  1642. (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
  1643. if (iotResult.Item1 != 0)
  1644. {
  1645. OnMessage(LogType.Info,
  1646. $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}] 进站结果[{request.enter_status}] 出站结果[{request.result}]");
  1647. }
  1648. }
  1649. #endregion
  1650. return result;
  1651. }
  1652. /// <summary>
  1653. /// 选择如何记录出站数据
  1654. /// </summary>
  1655. /// <param name="items">出站数据</param>
  1656. /// <param name="equipmentCode">设备编号</param>
  1657. /// <param name="processItem">测试项目</param>
  1658. /// <param name="workorder_code">车间订单号</param>
  1659. /// <param name="batch_num">批次号</param>
  1660. /// <param name="mtltmrk">型号</param>
  1661. /// <param name="proDate">日期</param>
  1662. /// <param name="supplierCode">供应商代码</param>
  1663. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1664. /// <returns>上传成功时返回1;失败返回0</returns>
  1665. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode,
  1666. string processItem,
  1667. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1668. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId,
  1669. string StationId, string PartBarcode, string jsonParm, string direction = "")
  1670. {
  1671. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num,
  1672. mtltmrk,
  1673. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode, jsonParm,
  1674. direction);
  1675. }
  1676. /// <summary>
  1677. /// 添加出站数据(提交到MES+本地保存到数据库)
  1678. /// </summary>
  1679. /// <param name="items">出站数据</param>
  1680. /// <param name="equipmentCode">设备编号</param>
  1681. /// <param name="processItem">测试项目</param>
  1682. /// <param name="workorder_code">车间订单号</param>
  1683. /// <param name="batch_num">批次号</param>
  1684. /// <param name="mtltmrk">型号</param>
  1685. /// <param name="proDate">日期</param>
  1686. /// <param name="supplierCode">供应商代码</param>
  1687. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1688. /// <returns>上传成功时返回1;失败返回0</returns>
  1689. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1690. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1691. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot,
  1692. string machineId, string stationId, string partBarcode, string jsonParm, string direction = "")
  1693. {
  1694. int upload = 0;
  1695. int result = 0;
  1696. ProcessData processData = new ProcessData()
  1697. {
  1698. Equipment_code = equipmentCode,
  1699. Workorder_code = workorder_code,
  1700. Batch_number = batch_num,
  1701. Sn = sn, // SN
  1702. Testitem = processItem,
  1703. Parameter_values = items,
  1704. Write_user = GlobalContext.CurrentUser,
  1705. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1706. };
  1707. // 本地数据
  1708. string sql = processData.ToStringInsert(upload);
  1709. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1710. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1711. #region MES
  1712. if (GlobalContext.IsSendProcessData)
  1713. {
  1714. try
  1715. {
  1716. string id = processData.ID.Copy();
  1717. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1718. outRequest_Body.uuidInspection = uuid;
  1719. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1720. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1721. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1722. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1723. outRequest_Body.unitSn = sn; // 产品SN
  1724. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1725. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1726. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1727. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1728. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1729. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1730. if (!string.IsNullOrEmpty(partBarcode))
  1731. {
  1732. outRequest_Body.unitData.keyMaterial.Add(
  1733. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1734. {
  1735. bindSort = 1,
  1736. materialSn = partBarcode
  1737. }); // 设备数据 - 部件码
  1738. }
  1739. //OP30站读txt数据
  1740. if (stationNameStr.Contains("CPAPHD"))
  1741. {
  1742. string path = "";
  1743. if (direction == "Left")
  1744. path = GlobalContext.MESLaserLPath;
  1745. else
  1746. path = GlobalContext.MESLaserRPath;
  1747. //字典存储数据
  1748. Dictionary<string, string> compensationDict = GetLastLineCompensation(path, direction, sn);
  1749. foreach (var kvp in compensationDict)
  1750. {
  1751. outRequest_Body.unitData.processData.Add(
  1752. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1753. {
  1754. dataName = kvp.Key.ToString(),
  1755. dataValue = kvp.Value.ToString()
  1756. });
  1757. }
  1758. }
  1759. //过站明细
  1760. if (GlobalContext.IsSendProcessDetail)
  1761. {
  1762. if (jsonParm.Length > 0)
  1763. {
  1764. // 解析JSON字符串为字典
  1765. var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonParm);
  1766. foreach (var kvp in dictionary)
  1767. {
  1768. outRequest_Body.unitData.processData.Add(
  1769. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1770. {
  1771. dataName = kvp.Key.ToString(),
  1772. dataValue = string.IsNullOrEmpty(kvp.Value) ? "" : kvp.Value.ToString()
  1773. });
  1774. }
  1775. }
  1776. }
  1777. if (GlobalContext.MESIsSendUpFile)
  1778. {
  1779. foreach (var item in fileUploadData.fileData)
  1780. {
  1781. if (!string.IsNullOrEmpty(item.FileName))
  1782. {
  1783. outRequest_Body.unitData.fileData.Add(
  1784. new XmStationOut_FileData()
  1785. {
  1786. fileName = item.FileName,
  1787. fileId = item.FileId,
  1788. bucket = item.Bucket
  1789. });
  1790. }
  1791. }
  1792. }
  1793. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1794. if (GlobalContext.IsSendProcessData)
  1795. {
  1796. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1797. string mesRet = string.Empty;
  1798. int i = 0;
  1799. while (i < 2) // 1009会多次尝试上传
  1800. {
  1801. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1802. if (response != null && response.header.code == "200")
  1803. {
  1804. OnMessage(LogType.Info,
  1805. $"【出站数据 SN {sn}】上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" +
  1806. JsonConvert.SerializeObject(response.body));
  1807. break;
  1808. }
  1809. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1810. i++;
  1811. i++;
  1812. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1813. // 记录失败原因
  1814. OnMessage(LogType.Error,
  1815. $"【出站数据 SN {sn}】上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1816. }
  1817. if (response?.header?.code == "200")
  1818. {
  1819. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1820. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1821. result = 1;
  1822. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1823. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1824. }
  1825. else
  1826. {
  1827. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1828. }
  1829. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(
  1830. JsonConvert.SerializeObject(outRequest_Body),
  1831. JsonConvert.SerializeObject(response), id);
  1832. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1833. }
  1834. }
  1835. catch (Exception ex)
  1836. {
  1837. string str = ex.StackTrace;
  1838. AddMessage_Station(stationNameStr, LogType.Error,
  1839. $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1840. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1841. }
  1842. }
  1843. #endregion
  1844. #region IOT
  1845. //过站明细
  1846. if (GlobalContext.IsMqttSendProcessData)
  1847. {
  1848. test_item_num += 1;
  1849. PassStationDetailRequest request = new PassStationDetailRequest();
  1850. request.pass_station_id = uuid;
  1851. request.sn = sn; // 产品SN
  1852. request.slot = vehicleSlot; // 槽位编码
  1853. request.test_item_num = test_item_num.ToString();
  1854. request.function_name = "Machine_加⼯模块";
  1855. request.status = "PASS";
  1856. (int, string) iotResult = (0, "");
  1857. if (jsonParm.Length > 0)
  1858. {
  1859. // 解析JSON字符串为字典
  1860. var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonParm);
  1861. foreach (var kvp in dictionary)
  1862. {
  1863. request.test_item = kvp.Key.ToString();
  1864. request.result_val = string.IsNullOrEmpty(kvp.Value) ? "" : kvp.Value.ToString();
  1865. request.description = request.test_item;
  1866. // 上传过站明细
  1867. iotResult = XiaomiMqttClient_Extend.Write_PassStationDetail(request);
  1868. if (iotResult.Item1 != 0)
  1869. {
  1870. OnMessage(LogType.Info,
  1871. $"【IOT过站明细】上传失败!错误原因:{iotResult.Item2},过站明细;产品码[{sn}] 测试项目[{request.test_item}] 测试值[{request.result_val}]");
  1872. }
  1873. }
  1874. }
  1875. }
  1876. //过站结果
  1877. if (GlobalContext.IsMqttSendProcessData)
  1878. {
  1879. PassStationResultRequest request = new PassStationResultRequest();
  1880. request.project_code = GlobalContext.Project_Code; // 项⽬编码
  1881. request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
  1882. request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
  1883. request.line_code = GlobalContext.LineCode; // 线体编码
  1884. request.work_station = xiaomiParm.workstation; // ⼯站ID
  1885. request.device_code = xiaomiParm.deviceCode; // 装备编码
  1886. request.station = xiaomiParm.stationCode;
  1887. request.process_time =
  1888. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
  1889. request.slot = vehicleSlot; // 槽位编码
  1890. request.sn = sn; // 产品SN
  1891. // request.enter_status = inpass ? "PASS" : "FAIL"; // 进站状态
  1892. request.enter_status = ""; // 进站状态
  1893. request.result = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL; // 过站结果
  1894. request.work_type = "OUT_STATION"; // 作业类型
  1895. // 上传过站结果
  1896. (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
  1897. if (iotResult.Item1 != 0)
  1898. {
  1899. OnMessage(LogType.Info,
  1900. $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}] 进站结果[{request.enter_status}] 出站结果[{request.result}]");
  1901. }
  1902. }
  1903. #endregion
  1904. return result;
  1905. }
  1906. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1907. //{
  1908. // Stopwatch stopwatch = new Stopwatch();
  1909. // stopwatch.Start();
  1910. // try
  1911. // {
  1912. // // 初始化 AtlasScrew 实例
  1913. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1914. // atlasScrew1.Initial();
  1915. // // 存储结果的列表
  1916. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1917. // // 存储角度和扭力的字符串列表
  1918. // List<string> angleStrs = new List<string>();
  1919. // List<string> torqueStrs = new List<string>();
  1920. // // 上一次获取的数据
  1921. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1922. // while (isExitAtlasLeft) // 检查是否收集数据
  1923. // {
  1924. // // 获取当前数据
  1925. // var currentResult = atlasScrew1.GetResults();
  1926. // // 判断是否为新数据
  1927. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1928. // {
  1929. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1930. // // 更新角度和扭力的字符串列表
  1931. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1932. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1933. // // 计算角度、扭力、起始扭力和最大扭力
  1934. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1935. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1936. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1937. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1938. // // 将新数据添加到结果列表
  1939. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1940. // // 更新上一次获取的数据
  1941. // lastResult = currentResult;
  1942. // }
  1943. // // 等待一段时间后再次检查
  1944. // Thread.Sleep(20); // 轮询间隔时间
  1945. // // 如果触发了出站,则退出循环
  1946. // if (!isExitAtlasLeft)
  1947. // {
  1948. // break;
  1949. // }
  1950. // }
  1951. // // 生成文件名
  1952. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1953. // // 写入数据到文件
  1954. // using (StreamWriter writer = new StreamWriter(fileName))
  1955. // {
  1956. // // 写入标题行
  1957. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1958. // // 写入每一行数据
  1959. // foreach (var result in results)
  1960. // {
  1961. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1962. // }
  1963. // }
  1964. // stopwatch.Stop();
  1965. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1966. // }
  1967. // catch (Exception ex)
  1968. // {
  1969. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1970. // }
  1971. // finally
  1972. // {
  1973. // // 重置标志变量
  1974. // isExitAtlasLeft = false;
  1975. // }
  1976. //}
  1977. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1978. //{
  1979. // Stopwatch stopwatch = new Stopwatch();
  1980. // stopwatch.Start();
  1981. // try
  1982. // {
  1983. // // 初始化 AtlasScrew 实例
  1984. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1985. // atlasScrew2.Initial();
  1986. // // 存储结果的列表
  1987. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1988. // // 上一次获取的数据
  1989. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1990. // while (isExitAtlasRight) // 检查是否收集数据
  1991. // {
  1992. // // 获取当前数据
  1993. // var currentResult = atlasScrew2.GetResults();
  1994. // // 判断是否为新数据
  1995. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1996. // {
  1997. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1998. // // 将新数据写入PLC
  1999. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  2000. // // 将新数据添加到结果列表
  2001. // results.Add(currentResult);
  2002. // // 更新上一次获取的数据
  2003. // lastResult = currentResult;
  2004. // }
  2005. // // 等待一段时间后再次检查
  2006. // Thread.Sleep(20); // 轮询间隔时间
  2007. // // 如果触发了出站,则退出循环
  2008. // if (!isExitAtlasRight)
  2009. // {
  2010. // break;
  2011. // }
  2012. // }
  2013. // // 将所有数据写入文件
  2014. // //WriteDataToFile(sn, direction, results);
  2015. // stopwatch.Stop();
  2016. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  2017. // }
  2018. // catch (Exception ex)
  2019. // {
  2020. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  2021. // }
  2022. // finally
  2023. // {
  2024. // // 重置标志变量
  2025. // isExitAtlasRight = false;
  2026. // }
  2027. //}
  2028. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  2029. {
  2030. Stopwatch stopwatch = new Stopwatch();
  2031. stopwatch.Start();
  2032. int nRet = 0;
  2033. string strRet = "";
  2034. try
  2035. {
  2036. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  2037. while (isCollectingFlagLeft)
  2038. {
  2039. // 从缓存中获取所有未处理的数据
  2040. var cachedData = atlasScrew.GetCachedDataLeft();
  2041. foreach (var currentResult in cachedData)
  2042. {
  2043. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  2044. {
  2045. continue; // 跳过无效数据
  2046. }
  2047. OnMessage(LogType.Info,
  2048. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  2049. // 写入PLC
  2050. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  2051. {
  2052. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  2053. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  2054. };
  2055. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  2056. if (nRet != 0)
  2057. {
  2058. OnMessage(LogType.Info,
  2059. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  2060. }
  2061. else
  2062. {
  2063. OnMessage(LogType.Info,
  2064. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  2065. }
  2066. // 构建保存路径
  2067. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  2068. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  2069. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  2070. Directory.CreateDirectory(savePath); // 确保目录存在
  2071. // 构建文件名(以 SN + 序号命名)
  2072. string fileName = $"{sn}_{fileCounter}.txt";
  2073. string filePath = Path.Combine(savePath, fileName);
  2074. // 写入文件
  2075. using (StreamWriter writer = new StreamWriter(filePath))
  2076. {
  2077. writer.WriteLine("精度, 扭力");
  2078. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  2079. for (int i = 0;
  2080. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  2081. i++)
  2082. {
  2083. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  2084. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  2085. writer.WriteLine($"{precision}, {torque}");
  2086. }
  2087. }
  2088. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  2089. // 增加文件计数器
  2090. fileCounter++;
  2091. }
  2092. // 如果没有更多数据,则短暂休眠以节省资源
  2093. if (!cachedData.Any())
  2094. {
  2095. Thread.Sleep(10); // 根据需要调整休眠时间
  2096. }
  2097. // 如果触发了出站,则退出循环
  2098. if (!isCollectingFlagLeft)
  2099. {
  2100. break;
  2101. }
  2102. }
  2103. stopwatch.Stop();
  2104. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  2105. }
  2106. catch (Exception ex)
  2107. {
  2108. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  2109. }
  2110. finally
  2111. {
  2112. isCollectingFlagLeft = false;
  2113. }
  2114. }
  2115. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  2116. {
  2117. Stopwatch stopwatch = new Stopwatch();
  2118. stopwatch.Start();
  2119. int nRet = 0;
  2120. string strRet = "";
  2121. try
  2122. {
  2123. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  2124. while (isCollectingFlagRight)
  2125. {
  2126. // 从缓存中获取所有未处理的数据
  2127. var cachedData = atlasScrew.GetCachedDataLeft();
  2128. foreach (var currentResult in cachedData)
  2129. {
  2130. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  2131. {
  2132. continue; // 跳过无效数据
  2133. }
  2134. OnMessage(LogType.Info,
  2135. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  2136. // 写入PLC
  2137. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  2138. {
  2139. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  2140. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  2141. };
  2142. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  2143. if (nRet != 0)
  2144. {
  2145. OnMessage(LogType.Info,
  2146. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  2147. }
  2148. else
  2149. {
  2150. OnMessage(LogType.Info,
  2151. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  2152. }
  2153. // 构建保存路径
  2154. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  2155. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  2156. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  2157. Directory.CreateDirectory(savePath); // 确保目录存在
  2158. // 构建文件名(以 SN + 序号命名)
  2159. string fileName = $"{sn}_{fileCounter}.txt";
  2160. string filePath = Path.Combine(savePath, fileName);
  2161. // 写入文件
  2162. using (StreamWriter writer = new StreamWriter(filePath))
  2163. {
  2164. writer.WriteLine("精度, 扭力");
  2165. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  2166. for (int i = 0;
  2167. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  2168. i++)
  2169. {
  2170. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  2171. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  2172. writer.WriteLine($"{precision}, {torque}");
  2173. }
  2174. }
  2175. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  2176. // 增加文件计数器
  2177. fileCounter++;
  2178. }
  2179. // 如果没有更多数据,则短暂休眠以节省资源
  2180. if (!cachedData.Any())
  2181. {
  2182. Thread.Sleep(10); // 根据需要调整休眠时间
  2183. }
  2184. // 如果触发了出站,则退出循环
  2185. if (!isCollectingFlagRight)
  2186. {
  2187. break;
  2188. }
  2189. }
  2190. stopwatch.Stop();
  2191. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  2192. }
  2193. catch (Exception ex)
  2194. {
  2195. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  2196. }
  2197. finally
  2198. {
  2199. isCollectingFlagRight = false;
  2200. }
  2201. }
  2202. public static (int,string) CompressFolder(string folderPath, string zipFilePath)
  2203. {
  2204. try
  2205. {
  2206. // 创建zip文件,将指定文件夹内的所有内容压缩到这个zip文件中
  2207. System.IO.Compression.ZipFile.CreateFromDirectory(folderPath, zipFilePath);
  2208. return (1, "文件夹已成功压缩!");
  2209. }
  2210. catch (Exception ex)
  2211. {
  2212. return (0, "文件压缩出错!"+ ex.Message);
  2213. }
  2214. }
  2215. /// <summary>
  2216. /// 上传文件
  2217. /// </summary>
  2218. /// <param name="BarcodeSet_t">条码集合</param>
  2219. /// <param name="stationCode">工站编号</param>
  2220. /// <param name="stationName">工站名称</param>
  2221. /// <param name="path">文件路径</param>
  2222. public async Task<(int, string)> SaveDBbyFileInfo(BarcodeSet_t BarcodeSet, string stationCode,
  2223. string stationName, int pass, string path, string guid = "")
  2224. {
  2225. string sql, filename = "";
  2226. int result = 0;
  2227. var formData = new MultipartFormDataContent();
  2228. string msg = "";
  2229. string file_category = "IMAGE"; //IMAGE 、TEXT 、UNKNOWN
  2230. string file_type = "IMAGE";
  2231. string project = GlobalContext.ProgramName;
  2232. string run_mode = GlobalContext.run_mode;
  2233. string product_mode = GlobalContext.product_mode;
  2234. string pass_result = (pass == 1 ? "PASS" : "Fail");
  2235. string device_code = xiaomiParm.deviceCode;
  2236. string sn = BarcodeSet.strProductBarcode;
  2237. string staion_id = xiaomiParm.stationCode;
  2238. string bucket =
  2239. $"{file_category}/{file_type}/{project}/{product_mode}/{run_mode}/{pass_result}/{device_code}/{sn}/{staion_id}";
  2240. // 获取所有图片文件
  2241. if (guid == "")
  2242. {
  2243. guid = Guid.NewGuid().ToString();
  2244. }
  2245. try
  2246. {
  2247. if (GlobalContext.MESIsSendUpFile)
  2248. {
  2249. List<string> imageFiles = GetAllImageFiles(path);
  2250. string toPath = GlobalContext.MqttFileBackupLogDir;
  2251. filename = $"{xiaomiParm.workstation}_{file_type}_{sn}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";
  2252. //string directoryPath = Path.GetDirectoryName(path);
  2253. string strFilePath = toPath+ "\\"+ filename;
  2254. if (imageFiles.Count > 0)
  2255. {
  2256. var r = CompressFolder(path, strFilePath);
  2257. if (r.Item1 == 0)
  2258. {
  2259. return (0, r.Item2);
  2260. }
  2261. else
  2262. {
  2263. msg = r.Item2 + "\r\n";
  2264. }
  2265. }
  2266. else {
  2267. return (0, "文件不存在!");
  2268. }
  2269. FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
  2270. fileUpload_X5.bucket = bucket;
  2271. fileUpload_X5.name = filename;
  2272. fileUpload_X5.uuid = guid.ToString();
  2273. ///需要上传文件
  2274. FileInfo file = new FileInfo(strFilePath);
  2275. string fileMd5Hex = GetMD5Hex(file);
  2276. fileUpload_X5.md5 = fileMd5Hex;
  2277. fileUpload_X5.uploadCloud = true;
  2278. fileUpload_X5.informMqtt = true;
  2279. FileMqttPayload fileMqttPayload = new FileMqttPayload();
  2280. fileMqttPayload.factory = GlobalContext.Factory_Code;
  2281. fileMqttPayload.project_name = GlobalContext.Project_Code;
  2282. fileMqttPayload.product_mode = GlobalContext.product_mode;
  2283. fileMqttPayload.line_no = GlobalContext.LineCode;
  2284. fileMqttPayload.work_station_no = xiaomiParm.workstation;
  2285. fileMqttPayload.equipment_no = xiaomiParm.deviceCode;
  2286. fileMqttPayload.station_no = xiaomiParm.stationCode;
  2287. fileMqttPayload.file_id = guid;
  2288. fileMqttPayload.file_name = filename;
  2289. fileMqttPayload.sn = BarcodeSet.strProductBarcode;
  2290. //fileMqttPayload.opt_time = "";
  2291. //fileMqttPayload.file_type = "";
  2292. //fileMqttPayload.file_category = "";
  2293. //fileMqttPayload.tag = "";
  2294. fileMqttPayload.reference_info.pass_station_id = uuid;
  2295. var fileresult =await
  2296. XiaomiMESHttp_UpLoadFile.FileUoladToMes(strFilePath, fileUpload_X5, fileMqttPayload);
  2297. if (fileresult.Item1 != 1)
  2298. {
  2299. return (0, msg + fileresult.Item2 + "\r\n");
  2300. }
  2301. else
  2302. {
  2303. msg = msg + fileresult.Item2 + "\r\n";
  2304. }
  2305. foreach (var imageFile in imageFiles) {
  2306. if (File.Exists(imageFile))
  2307. {
  2308. //删除文件
  2309. (bool, string) newResult = DeleteFile(imageFile);
  2310. if (!newResult.Item1)
  2311. {
  2312. return (0, Path.GetFileName(imageFile) + newResult.Item2);
  2313. }
  2314. }
  2315. }
  2316. }
  2317. return (1, msg);
  2318. }
  2319. catch (Exception e)
  2320. {
  2321. return (0,
  2322. filename + $"文件上传错误!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode},错误原因:" +
  2323. e.Message);
  2324. }
  2325. }
  2326. /// <summary>
  2327. /// 获取路径下的所有图片
  2328. /// </summary>
  2329. /// <param name="directoryPath"></param>
  2330. /// <returns></returns>
  2331. public List<string> GetAllImageFiles(string directoryPath)
  2332. {
  2333. var imageExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
  2334. { ".jpg", ".jpeg", ".png", ".bmp", ".gif", ".tiff" };
  2335. var imageFiles = new List<string>();
  2336. try
  2337. {
  2338. // 遍历目录及子目录中的所有文件
  2339. foreach (string file in Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories))
  2340. {
  2341. // 获取文件扩展名并检查是否为图片格式
  2342. string extension = Path.GetExtension(file);
  2343. if (imageExtensions.Contains(extension))
  2344. {
  2345. imageFiles.Add(file);
  2346. }
  2347. }
  2348. }
  2349. catch (Exception ex)
  2350. {
  2351. OnMessage(LogType.Error, $"图片查询发生错误: {ex.Message}");
  2352. }
  2353. return imageFiles;
  2354. }
  2355. /// <summary>
  2356. /// 实例化报警字典
  2357. /// </summary>
  2358. private (bool, string) InitalDicAlarm()
  2359. {
  2360. #region 加载报警表
  2361. string excelPath = "";
  2362. switch (GlobalContext.IsUsePLCNow)
  2363. {
  2364. case 1:
  2365. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_10_壳体清洁上料.xlsx";
  2366. break;
  2367. case 2:
  2368. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_20_上盖板上料装备.xlsx";
  2369. break;
  2370. case 3:
  2371. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_30_点散热胶装备.xlsx";
  2372. break;
  2373. case 4:
  2374. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_40_胶线检测.xlsx";
  2375. break;
  2376. case 5:
  2377. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_50_ADD板上料组装装备.xlsx";
  2378. break;
  2379. case 6:
  2380. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_60_组上盖板.xlsx";
  2381. break;
  2382. case 7:
  2383. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_70_上盖板锁螺丝.xlsx";
  2384. break;
  2385. case 8:
  2386. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_80_NG下料.xlsx";
  2387. break;
  2388. case 9:
  2389. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_90_半成品下料.xlsx";
  2390. break;
  2391. default:
  2392. return (false, $"不支持当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请在设置页切换到正确的plc后重启该软件!");
  2393. }
  2394. if (!File.Exists(excelPath))
  2395. return (false, $"未找到当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请检查文件路径:'{excelPath}'。");
  2396. DataTable DtModel = NPOIHelper.ReadExcel(excelPath);
  2397. if (DtModel == null || DtModel.Rows.Count < 1)
  2398. return (false, $"报警点位表未包含任何报警数据!请检查‘{excelPath}’文件!");
  2399. // 检查列名
  2400. List<string> isNeedParms = new List<string>()
  2401. {
  2402. "设备分类名称", "设备分类编码", "分类层级1", "分类层级2", "分类层级3", "分类层级4", "事件名称", "事件ID", "描述", "标签", "PLC地址", "工位"
  2403. }; // 必须要有的列
  2404. // 指定列名 + 检查列是否完整
  2405. DataRow dtRowName = DtModel.Rows[0];
  2406. int count = DtModel.Columns.Count;
  2407. for (int i = 0; i < count; i++)
  2408. {
  2409. string columeName = dtRowName[i]?.ToString();
  2410. if (!string.IsNullOrEmpty(columeName))
  2411. DtModel.Columns[i].ColumnName = columeName;
  2412. if ((!string.IsNullOrEmpty(columeName)) && isNeedParms.Count > 0 && isNeedParms.Contains(columeName))
  2413. isNeedParms.Remove(columeName);
  2414. }
  2415. DtModel.Rows.RemoveAt(0);
  2416. if (isNeedParms.Count > 0)
  2417. {
  2418. string msg1 = string.Join(",", isNeedParms);
  2419. return (false, $"报警点位表未包含列:{msg1}!请检查‘{excelPath}’文件!");
  2420. }
  2421. #endregion 加载报警表
  2422. List<Alarm> keyValues1 = new List<Alarm>();
  2423. for (int i = 0; i < DtModel.Rows.Count; i++)
  2424. {
  2425. Alarm alarm = new Alarm();
  2426. alarm.plcName = DtModel.Rows[i]["设备分类名称"]?.ToString(); // 设备名;
  2427. string type1Str = DtModel.Rows[i]["分类层级1"]?.ToString(); // 分类层级1;
  2428. alarm.type1CH = type1Str; // 分类层级1 中文
  2429. alarm.type1 = type1Str; // 分类层级1
  2430. if (!string.IsNullOrEmpty(type1Str) && type1Str.Contains("\n"))
  2431. {
  2432. string[] type1Strs = type1Str.Split('\n');
  2433. if (type1Strs.Length >= 2)
  2434. {
  2435. alarm.type1CH = type1Strs[0].Trim(); // 分类层级1 中文
  2436. alarm.type1 = type1Strs[1].Trim(); // 分类层级1
  2437. if (string.IsNullOrEmpty(alarm.type1))
  2438. alarm.type1 = alarm.type1CH;
  2439. }
  2440. }
  2441. string type2Str = DtModel.Rows[i]["分类层级2"]?.ToString(); // 分类层级2;电气控制 electric_control
  2442. alarm.type2CH = type2Str; // 分类层级2 中文
  2443. alarm.type2 = type2Str; // 分类层级2
  2444. if (!string.IsNullOrEmpty(type2Str) && type2Str.Contains("\n"))
  2445. {
  2446. string[] type2Strs = type2Str.Split('\n');
  2447. if (type2Strs.Length >= 2)
  2448. {
  2449. alarm.type2CH = type2Strs[0].Trim(); // 分类层级2 中文
  2450. alarm.type2 = type2Strs[1].Trim(); // 分类层级2
  2451. if (string.IsNullOrEmpty(alarm.type2))
  2452. alarm.type2 = alarm.type2CH;
  2453. }
  2454. }
  2455. string type3Str = DtModel.Rows[i]["分类层级3"]?.ToString(); // 分类层级3;故障 Fault
  2456. alarm.type3CH = type3Str; // 分类层级3 中文
  2457. alarm.type3 = type3Str; // 分类层级3
  2458. if (!string.IsNullOrEmpty(type3Str) && type3Str.Contains("\n"))
  2459. {
  2460. string[] type3Strs = type3Str.Split('\n');
  2461. if (type3Strs.Length >= 2)
  2462. {
  2463. alarm.type3CH = type3Strs[0].Trim(); // 分类层级3 中文
  2464. alarm.type3 = type3Strs[1].Trim(); // 分类层级3
  2465. if (string.IsNullOrEmpty(alarm.type3))
  2466. alarm.type3 = alarm.type3CH;
  2467. }
  2468. }
  2469. string faultStr = DtModel.Rows[i]["分类层级4"]?.ToString(); // 故障部件;overall_module
  2470. alarm.type4 = faultStr; // 分类层级4 中文
  2471. alarm.type4CH = faultStr; // 分类层级4
  2472. if (!string.IsNullOrEmpty(faultStr) && faultStr.Contains("\n"))
  2473. {
  2474. string[] faultStrs = faultStr.Split('\n');
  2475. if (faultStrs.Length >= 2)
  2476. {
  2477. alarm.type4CH = faultStrs[0].Trim(); // 故障部件;overall_module
  2478. alarm.type4 = faultStrs[1].Trim(); // 故障部件
  2479. if (string.IsNullOrEmpty(alarm.type4))
  2480. alarm.type4 = alarm.type4CH;
  2481. }
  2482. }
  2483. alarm.fault_code = DtModel.Rows[i]["事件ID"]?.ToString(); // 故障编码;A40001
  2484. alarm.fault_name = DtModel.Rows[i]["事件名称"]?.ToString(); // 故障名称;AL[1000]_系统_HMI急停故障
  2485. alarm.fault_desc = alarm.fault_name; // 故障描述;AL[1000]_系统_HMI急停故障
  2486. string plcAdress = DtModel.Rows[i]["PLC地址"]?.ToString();
  2487. alarm.PLC地址 = plcAdress;
  2488. plcAdress = plcAdress.Replace("fault_codes[", "");
  2489. plcAdress = plcAdress.Replace("]", "");
  2490. alarm.group_index = Convert.ToInt32(plcAdress.Split(".")[0]);
  2491. keyValues1.Add(alarm);
  2492. }
  2493. DicAlarms_Cur.Add(GlobalContext.IsUseStationName, keyValues1); // 这里使用线体代替工位
  2494. return (true, "报警字典表初始化成功!");
  2495. }
  2496. private async void ReadPLCAlarmToIot(uint[] FaultData, uint[] FaultDataOld, string stationNameStr)
  2497. {
  2498. DateTime dtNow = DateTime.Now;
  2499. try
  2500. {
  2501. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  2502. List<(int, int)> AlarmIndexList = new List<(int, int)>(); //收集所有报警信息的位置
  2503. AlarmData alarmData = new AlarmData();
  2504. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  2505. bool isNoAlarm = false; //是否有报警
  2506. string binaryString = "";
  2507. bool isNoNewAlarm = false; //是否有新的报警
  2508. if (FaultData.Length > 0)
  2509. {
  2510. foreach (var item in FaultData)
  2511. {
  2512. isNoAlarm = item > 0 ? true : false;
  2513. }
  2514. if (!FaultData.SequenceEqual(FaultDataOld))
  2515. {
  2516. isNoNewAlarm = true;
  2517. isNeedUpdUI = true;
  2518. }
  2519. if (FaultData.Length > 0 && isNoAlarm && isNoNewAlarm)
  2520. {
  2521. //解析报警信息,分析当前报警在字典中的定位
  2522. for (int i = 0; i <= FaultData.Length - 1; i++)
  2523. {
  2524. var num = 0;
  2525. if (FaultData[i] > 0)
  2526. {
  2527. //转换二进制
  2528. binaryString = Convert.ToString(FaultData[i], 2);
  2529. for (int j = binaryString.Length - 1; j >= 0; j--)
  2530. {
  2531. num++;
  2532. char s = binaryString[j];
  2533. if (binaryString[j] == '1')
  2534. {
  2535. //记录1的位置
  2536. AlarmIndexList.Add((i, num - 1));
  2537. }
  2538. }
  2539. }
  2540. }
  2541. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  2542. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.IsUseStationName];
  2543. foreach ((int index, int row) in AlarmIndexList)
  2544. {
  2545. var tempDic = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList();
  2546. for (int i = 0; i < tempDic.Count - 1; i++) // 读取
  2547. {
  2548. //若报警字典第[group_index]个数据,第[i]行与AlarmIndexList中的定位匹配,则添加进对应行的报警数据
  2549. if (tempDic[i].group_index == index && i == row)
  2550. {
  2551. dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据 =
  2552. new AlarmData()
  2553. {
  2554. GUID = Guid.NewGuid().ToString(),
  2555. LineName = GlobalContext.IsUseStationName, // 工站
  2556. PlcStation = tempDic[i].plcName, // 工站全称;[S1]
  2557. Type1 = tempDic[i].type1, // 故障层级1
  2558. Type2 = tempDic[i].type2, // 故障层级2
  2559. Type3 = tempDic[i].type3, // 故障层级3
  2560. Type4 = tempDic[i].type4, // 故障层级4
  2561. AlarmType = tempDic[i].fault_code, // 报警类型
  2562. AlarmDesc = tempDic[i].fault_name, // 报警内容
  2563. StartTime = dtNow // 开始时间
  2564. };
  2565. // 传输到页面
  2566. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  2567. {
  2568. 线体名称 = tempDic[i].plcName,
  2569. 报警类型 = tempDic[i].fault_code,
  2570. 报警内容 = tempDic[i].fault_name,
  2571. 开始时间 = dtNow
  2572. });
  2573. // 新增到数据库
  2574. //var data1 = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据;
  2575. //SaveAlarmDataByDB(stationNameStr, data1, false);
  2576. //OnMessage(LogType.Info, $"更新{BodyAlarm}完毕!");
  2577. }
  2578. }
  2579. }
  2580. //筛选含报警数据的字典
  2581. var dicAlarms_Cur = dicAlarms_Cur_PLC1.Where(x => x.报警数据 != null).ToList();
  2582. if (dicAlarms_Cur.Count > 0)
  2583. {
  2584. foreach (var item in dicAlarms_Cur)
  2585. {
  2586. //上传
  2587. SaveAlarmDataByDB(GlobalContext.IsUseStationName, item.报警数据, false);
  2588. }
  2589. }
  2590. // 有新报警则更新
  2591. if (isNeedUpdUI)
  2592. // UI展示 - 展示到设备状态页
  2593. await Task.Run(() =>
  2594. {
  2595. try
  2596. {
  2597. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  2598. {
  2599. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  2600. if (Form_Main.formDevAlarm.Visible)
  2601. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  2602. }
  2603. }
  2604. catch
  2605. {
  2606. }
  2607. });
  2608. FaultDataOld = FaultData.ToArray();
  2609. }
  2610. }
  2611. //FaultLogRequest request = new FaultLogRequest();
  2612. //request.station = mesStation; // 工位
  2613. //request.fault_name = xmFaultName; // 故障名称(同数据字典中的事件名称)
  2614. //request.fault_code = xmFaultCode2; // 故障编码(A,B,C,D,E)
  2615. //request.fault_cmpnt = xmFaultCmpnt; // 故障部件
  2616. //request.fault_desc = xmFaultDesc; // 故障描述
  2617. //request.fault_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 故障发生时间 2022-06-01 14:27:57.283
  2618. // // 上传
  2619. //(int, string) iotResult = XiaomiMqttClient_Extend.Write_FaultLog(request, type1, type2, type3, request.fault_cmpnt, deciveCode);
  2620. }
  2621. catch (Exception ex)
  2622. {
  2623. string str = ex.StackTrace;
  2624. AddMessage_Station(stationNameStr, LogType.Error,
  2625. $"{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" +
  2626. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2627. }
  2628. }
  2629. public void operateToIot(string action, string stationNameStr)
  2630. {
  2631. OperateLogRequest request = new OperateLogRequest();
  2632. request.software_version = "V" + Application.ProductVersion; // 软件版本号;如:V1.2.4
  2633. request.operate_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 操作时间(2022-06-01 14:27:57.283)
  2634. request.operate_action = action; // 操作动作(对应软件开启/关闭/重新加载项⽬;startup、shutdown、reload)
  2635. //request.current_process = Process.GetCurrentProcess()?.Id.ToString(); // 当前进程;进程ID
  2636. request.current_process = Application.ProductName;
  2637. request.operate_desc = stationNameStr; // 操作描述;如:供应商软件开启/关闭/重新加载项⽬
  2638. request.operate_result = "success"; // 操作结果
  2639. request.operator_name = "default"; // 操作账号名;填当前操作⽤⼾,如⽆则填default
  2640. // 上传
  2641. (int, string) iotResult = XiaomiMqttClient_Extend.Write_OperateLog(request);
  2642. if (iotResult.Item1 != 0)
  2643. {
  2644. AddMessage(LogType.Info, "【操作记录】上传失败!错误原因:" + iotResult.Item2 + "操作状态:" + stationNameStr);
  2645. }
  2646. }
  2647. private void 通用节拍接口(int plcNo, string stationNameStr, string tagMesCommName, string CarrierBarcode,
  2648. IoT_DataSet_t iot_data)
  2649. {
  2650. Stopwatch stopwatch1 = new Stopwatch();
  2651. Stopwatch stopwatch2 = new Stopwatch();
  2652. string resultStr = string.Empty;
  2653. try
  2654. {
  2655. stopwatch1.Start();
  2656. string oEEType = iot_data.BeatAction.ToString(); // 节拍类型(plc写入)
  2657. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode); //产品SN
  2658. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  2659. if (!actionBool)
  2660. {
  2661. stopwatch2.Start();
  2662. //写入PLC
  2663. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2664. iotData.machineState = iot_data.machineState;
  2665. iotData.work_type = iot_data.work_type;
  2666. iotData.testStatus = iot_data.testStatus;
  2667. iotData.BeatAction = iot_data.BeatAction;
  2668. iotData.beatReturn = 2; //NG
  2669. iotData.fault_codes = iot_data.fault_codes;
  2670. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2671. if (PLCresult.Item1 != 0)
  2672. {
  2673. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iotData.BeatAction}写入成功!");
  2674. }
  2675. stopwatch2.Stop();
  2676. AddMessage(LogType.Info,
  2677. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  2678. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2679. return;
  2680. }
  2681. //作业开始后要有物料和载具信息
  2682. //if (string.IsNullOrEmpty(strProductBarcode) && string.IsNullOrEmpty(CarrierBarcode) &&
  2683. // Convert.ToInt32(oEEType) > 2)
  2684. //{
  2685. // stopwatch2.Start();
  2686. // //写入PLC
  2687. // IoT_DataSet_t iotData = new IoT_DataSet_t();
  2688. // iotData.machineState = iot_data.machineState;
  2689. // iotData.work_type = iot_data.work_type;
  2690. // iotData.testStatus = iot_data.testStatus;
  2691. // iotData.BeatAction = iot_data.BeatAction;
  2692. // iotData.beatReturn = 2; //NG
  2693. // iotData.fault_codes = iot_data.fault_codes;
  2694. // WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2695. // stopwatch2.Stop();
  2696. // AddMessage_Station(stationNameStr, LogType.Info,
  2697. // stationNameStr + $"_[{CarrierBarcode}][{strProductBarcode}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  2698. // stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2699. // return;
  2700. //}
  2701. //else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(strProductBarcode))
  2702. //{
  2703. // stopwatch2.Start();
  2704. // //写入PLC
  2705. // IoT_DataSet_t iotData = new IoT_DataSet_t();
  2706. // iotData.machineState = iot_data.machineState;
  2707. // iotData.work_type = iot_data.work_type;
  2708. // iotData.testStatus = iot_data.testStatus;
  2709. // iotData.BeatAction = iot_data.BeatAction;
  2710. // iotData.beatReturn = 2; //NG
  2711. // iotData.fault_codes = iot_data.fault_codes;
  2712. // WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2713. // stopwatch2.Stop();
  2714. // AddMessage_Station(stationNameStr, LogType.Info,
  2715. // stationNameStr + $"_[{CarrierBarcode}]上传节拍失败!物料码不可为空;总用时" +
  2716. // stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2717. // return;
  2718. //}
  2719. //else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(CarrierBarcode))
  2720. //{
  2721. // stopwatch2.Start();
  2722. // //写入PLC
  2723. // IoT_DataSet_t iotData = new IoT_DataSet_t();
  2724. // iotData.machineState = iot_data.machineState;
  2725. // iotData.work_type = iot_data.work_type;
  2726. // iotData.testStatus = iot_data.testStatus;
  2727. // iotData.BeatAction = iot_data.BeatAction;
  2728. // iotData.beatReturn = 2; //NG
  2729. // iotData.fault_codes = iot_data.fault_codes;
  2730. // WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2731. // stopwatch2.Stop();
  2732. // AddMessage_Station(stationNameStr, LogType.Info,
  2733. // stationNameStr + $"_上传节拍失败!载具码不可为空;总用时" +
  2734. // stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2735. // return;
  2736. //}
  2737. short _result = 0;
  2738. // 上传OEE
  2739. (short, string) result =
  2740. SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2741. _result = result.Item1;
  2742. resultStr = result.Item2;
  2743. if (_result == 1)
  2744. {
  2745. stopwatch2.Start();
  2746. //写入PLC
  2747. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2748. iotData.machineState = iot_data.machineState;
  2749. iotData.work_type = iot_data.work_type;
  2750. iotData.testStatus = iot_data.testStatus;
  2751. iotData.BeatAction = iot_data.BeatAction;
  2752. iotData.beatReturn = 1; //OK
  2753. iotData.fault_codes = iot_data.fault_codes;
  2754. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2755. if (PLCresult.Item1 != 0)
  2756. {
  2757. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iotData.BeatAction}写入成功!");
  2758. }
  2759. stopwatch2.Stop();
  2760. }
  2761. else
  2762. {
  2763. stopwatch2.Start();
  2764. //写入PLC
  2765. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2766. iotData.machineState = iot_data.machineState;
  2767. iotData.work_type = iot_data.work_type;
  2768. iotData.testStatus = iot_data.testStatus;
  2769. iotData.BeatAction = iot_data.BeatAction;
  2770. iotData.beatReturn = 2; //NG
  2771. iotData.fault_codes = iot_data.fault_codes;
  2772. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2773. if (PLCresult.Item1 != 0)
  2774. {
  2775. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iotData.BeatAction}写入成功!");
  2776. }
  2777. stopwatch2.Stop();
  2778. AddMessage_Station(stationNameStr, LogType.Error,
  2779. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  2780. }
  2781. }
  2782. catch (Exception ex)
  2783. {
  2784. string str = ex.StackTrace;
  2785. AddMessage_Station(stationNameStr, LogType.Error,
  2786. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  2787. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2788. // MES_Flag
  2789. stopwatch2.Start();
  2790. //写入PLC
  2791. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2792. iotData.machineState = iot_data.machineState;
  2793. iotData.work_type = iot_data.work_type;
  2794. iotData.testStatus = iot_data.testStatus;
  2795. iotData.BeatAction = iot_data.BeatAction;
  2796. iotData.beatReturn = 2; //NG
  2797. iotData.fault_codes = iot_data.fault_codes;
  2798. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  2799. if (PLCresult.Item1 != 0)
  2800. {
  2801. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iotData.BeatAction}写入成功!");
  2802. }
  2803. stopwatch2.Stop();
  2804. }
  2805. stopwatch1.Stop();
  2806. AddMessage(LogType.Info,
  2807. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  2808. stopwatch2.ElapsedMilliseconds + "ms");
  2809. }
  2810. /// <summary>
  2811. /// 去除常见特殊字符,如 \r, \n, \t 等
  2812. /// </summary>
  2813. /// <param name="format"></param>
  2814. /// <returns></returns>
  2815. private static string FormatStrbyPLC(string format) {
  2816. string cleanedString = Regex.Replace(format, @"[\r\n\t]", "");
  2817. return cleanedString;
  2818. }
  2819. #endregion
  2820. #region S1
  2821. /// <summary>
  2822. /// [S1] 壳体清洁上料装备
  2823. /// </summary>
  2824. /// <param name="plcNo">PLC编号</param>
  2825. private void ReadStation_S1(int plcNo)
  2826. {
  2827. string stationCode = "[OP10]";
  2828. string stationName = "壳体清洁上料";
  2829. string stationNameStr = stationCode + stationName;
  2830. string tagBaseName = "g_OP10_MES"; //标签变量名称
  2831. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2832. string tagAgvCommName = "agvCommFrmPC";
  2833. string tagiotComnName = "iotData";
  2834. string tagBarsetName = "BarcodeSet";
  2835. string CarrierBarcode = "";
  2836. string ProductBarcode = "";
  2837. // 触发信号字典
  2838. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2839. s1PLCSignal_Old.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2840. // PLC数据字典 赋值
  2841. s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2842. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  2843. (int, string) result;
  2844. while (true)
  2845. {
  2846. try
  2847. {
  2848. if (!GlobalContext._IsCon_Funs1)
  2849. {
  2850. UpdatePLCMonitor(1, plcNo, 0);
  2851. continue;
  2852. }
  2853. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2854. {
  2855. Stopwatch stopwatch1 = new Stopwatch();
  2856. Stopwatch stopwatch2 = new Stopwatch();
  2857. stopwatch1.Start();
  2858. stopwatch2.Start();
  2859. #region 一次性读取所有数据
  2860. // 一次性读取所有数据
  2861. result = FunsEip[plcNo]
  2862. .Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2863. if (result.Item1 != 0)
  2864. {
  2865. //richTextBox1.AppendText("\n" + strRet);
  2866. }
  2867. else
  2868. {
  2869. //richTextBox1.AppendText("\n" + "读取成功");
  2870. stPLC_MesData.BarcodeSet.strProductBarcode=FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  2871. stPLC_MesData.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  2872. stPLC_MesData.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  2873. stPLC_MesData.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  2874. //设备状态
  2875. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  2876. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  2877. ? XiaomiDeviceState.Unknown
  2878. : (XiaomiDeviceState)xmDeviceStateInt;
  2879. // 载具SN
  2880. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode.ToString();
  2881. // 物料码(物料码还未绑定载具SN时必填)
  2882. ProductBarcode = stPLC_MesData.BarcodeSet.strProductBarcode;
  2883. // 节拍
  2884. s1PLCData["a1OEEType"] = stPLC_MesData.iotData.BeatAction;
  2885. //报警信息
  2886. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  2887. }
  2888. #endregion 一次性读取所有数据
  2889. stopwatch2.Stop();
  2890. #region 进站
  2891. try
  2892. {
  2893. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2894. {
  2895. lock (lockObj)
  2896. {
  2897. if (!ProgressState)
  2898. {
  2899. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  2900. ProgressState = true;
  2901. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData,
  2902. tagBaseName + "." + tagMesCommName, out ProgressState));
  2903. }
  2904. }
  2905. }
  2906. }
  2907. catch (Exception ex)
  2908. {
  2909. ProgressState = false;
  2910. string str = ex.StackTrace;
  2911. AddMessage_Station(stationNameStr, LogType.Error,
  2912. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2913. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2914. }
  2915. #endregion 进站
  2916. #region 出站
  2917. try
  2918. {
  2919. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2920. {
  2921. lock (lockObj)
  2922. {
  2923. if (!ProgressState)
  2924. {
  2925. ProgressState = true;
  2926. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData,
  2927. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  2928. out ProgressState));
  2929. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  2930. uuid = "";
  2931. }
  2932. }
  2933. }
  2934. }
  2935. catch (Exception ex)
  2936. {
  2937. ProgressState = false;
  2938. string str = ex.StackTrace;
  2939. AddMessage_Station(stationNameStr, LogType.Error,
  2940. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2941. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2942. }
  2943. #endregion 出站
  2944. #region 节拍接口
  2945. try
  2946. {
  2947. if (stPLC_MesData.iotData.BeatAction > 0)
  2948. {
  2949. int a1OEEType = Convert.ToInt32(s1PLCData["a1OEEType"]);
  2950. int a1OEETypeGOld = Convert.ToInt32(s1PLCSignal_Old["a1OEEType"]);
  2951. //若设备紧急复原后节拍重置
  2952. if (a1OEEType == 1)
  2953. {
  2954. a1OEETypeGOld = 0;
  2955. }
  2956. if (a1OEEType != a1OEETypeGOld)
  2957. {
  2958. //如果上位机告诉PLC NG,PLC节拍会直接从1跳到4
  2959. if (a1OEETypeGOld <= 2 && a1OEEType == 4)
  2960. {
  2961. Task.Run(() =>
  2962. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  2963. CarrierBarcode,
  2964. stPLC_MesData.iotData));
  2965. }
  2966. else
  2967. {
  2968. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  2969. if ((a1OEETypeGOld == 1 && a1OEEType != 2) ||
  2970. (a1OEETypeGOld == 3 && a1OEEType != 4) ||
  2971. (a1OEETypeGOld == 5 && a1OEEType != 6))
  2972. {
  2973. //写入PLC
  2974. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2975. iotData.machineState = stPLC_MesData.iotData.machineState;
  2976. iotData.work_type = stPLC_MesData.iotData.work_type;
  2977. iotData.testStatus = stPLC_MesData.iotData.testStatus;
  2978. iotData.BeatAction = stPLC_MesData.iotData.BeatAction;
  2979. iotData.beatReturn = 2; //NG
  2980. iotData.fault_codes = stPLC_MesData.iotData.fault_codes;
  2981. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, 1,
  2982. iotData);
  2983. AddMessage(LogType.Info,
  2984. stationNameStr +
  2985. $"_节拍接口-- 设备本次上传节拍[{a1OEEType}],未上传节拍[{a1OEETypeGOld}]的结束信号,请检查;总用时" +
  2986. stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  2987. stopwatch2.ElapsedMilliseconds +
  2988. "ms");
  2989. return;
  2990. }
  2991. else
  2992. {
  2993. Task.Run(() => 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  2994. CarrierBarcode, stPLC_MesData.iotData));
  2995. }
  2996. }
  2997. }
  2998. }
  2999. s1PLCSignal_Old["a1OEEType"] = s1PLCData["a1OEEType"];
  3000. }
  3001. catch (Exception ex)
  3002. {
  3003. string str = ex.StackTrace;
  3004. AddMessage_Station(stationNameStr, LogType.Error,
  3005. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3006. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3007. }
  3008. #endregion
  3009. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3010. stopwatch1.Stop();
  3011. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3012. }
  3013. else
  3014. {
  3015. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3016. AddMessage_Station(stationNameStr, LogType.Info,
  3017. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3018. FunsEip[plcNo].Connect(); // 重连
  3019. }
  3020. }
  3021. catch (Exception ex)
  3022. {
  3023. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3024. AddMessage_Station(stationNameStr, LogType.Error,
  3025. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3026. }
  3027. Thread.Sleep(IntervalReadPLC);
  3028. }
  3029. }
  3030. /// <summary>
  3031. /// [S1] 壳体清洁上料 - 进站
  3032. /// </summary>
  3033. /// <param name="plcNo">PLC编号</param>
  3034. /// <param name="stationNameStr">工站全称</param>
  3035. /// <param name="stPLC_MesData"></param>
  3036. /// <param name="tagMesCommName"></param>
  3037. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  3038. out bool ProgressState)
  3039. {
  3040. Stopwatch stopwatch1 = new Stopwatch();
  3041. Stopwatch stopwatch2 = new Stopwatch();
  3042. try
  3043. {
  3044. stopwatch1.Start();
  3045. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3046. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  3047. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3048. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  3049. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  3050. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3051. bool pass = a1Result == 1;
  3052. if (string.IsNullOrEmpty(sn))
  3053. {
  3054. ProgressState = false;
  3055. AddMessage(LogType.Error, $"{stationNameStr}_未能查到产品码");
  3056. Thread.Sleep(10000);
  3057. return;
  3058. }
  3059. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  3060. // sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  3061. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3062. //绑定载具和产品
  3063. ResponseMessage message = new ResponseMessage();
  3064. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  3065. if (message.result == false)
  3066. {
  3067. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  3068. }
  3069. // 产品SN进站
  3070. List<TestItem> item = new List<TestItem>();
  3071. stopwatch2.Start();
  3072. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3073. item, MachineId, StationId, pass, "01-SLOT-01");
  3074. stopwatch2.Stop();
  3075. //指令执行结果 1:OK 110:失败
  3076. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3077. if (mesResultFrmWeb == 1)
  3078. {
  3079. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3080. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3081. }
  3082. //进站结果写入PLC
  3083. CommandFromPLC resultToPlC = new CommandFromPLC();
  3084. resultToPlC.cmd = 0;
  3085. resultToPlC.cmdParam = 0;
  3086. resultToPlC.cmdResult = mesResultFrmWeb;
  3087. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3088. }
  3089. catch (Exception ex)
  3090. {
  3091. string str = ex.StackTrace;
  3092. AddMessage(LogType.Error,
  3093. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3094. str.Length - str.LastIndexOf("\\") - 1));
  3095. CommandFromPLC resultToPlC = new CommandFromPLC();
  3096. resultToPlC.cmd = 0;
  3097. resultToPlC.cmdParam = 0; //指令参数
  3098. resultToPlC.cmdResult = 110;
  3099. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3100. }
  3101. stopwatch1.Stop();
  3102. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3103. AddMessage(LogType.Info,
  3104. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3105. stopwatch2.ElapsedMilliseconds + "ms");
  3106. ProgressState = false;
  3107. }
  3108. /// <summary>
  3109. /// [S1] 壳体清洁上料 - 出站接口
  3110. /// </summary>
  3111. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  3112. string stationCode, string stationName, out bool ProgressState)
  3113. {
  3114. Stopwatch stopwatch1 = new Stopwatch();
  3115. Stopwatch stopwatch2 = new Stopwatch();
  3116. test_item_num = 0; //iot 过站明细序号
  3117. try
  3118. {
  3119. stopwatch1.Start();
  3120. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3121. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3122. string processItem = stationName; // 项目
  3123. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3124. string supplierCode = ""; // 供应商代码
  3125. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  3126. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  3127. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  3128. string sn = string.Empty;
  3129. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3130. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  3131. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  3132. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3133. //a1Result = 1;
  3134. bool pass = a1Result == 1;
  3135. //根据载具码获取产品码
  3136. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3137. if (string.IsNullOrEmpty(strProductBarcode))
  3138. {
  3139. ProgressState = false;
  3140. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3141. Thread.Sleep(10000);
  3142. return;
  3143. }
  3144. sn = strProductBarcode;
  3145. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3146. List<TestItem> items = new List<TestItem>();
  3147. items.Add(new TestItem()
  3148. {
  3149. Parameter_name = "载具码",
  3150. Parameter_value = CarrierBarcode,
  3151. Parameter_unit = ""
  3152. });
  3153. items.Add(new TestItem()
  3154. {
  3155. Parameter_name = "产品码",
  3156. Parameter_value = sn,
  3157. Parameter_unit = ""
  3158. });
  3159. #region 转换过站明细字符串
  3160. //创建字典
  3161. var dic = new Dictionary<string, string>();
  3162. // 获取结构体类型
  3163. FieldInfo[] fields = typeof(OP10_DataSet_t).GetFields();
  3164. // 遍历变量名转换成字典描述
  3165. foreach (FieldInfo field in fields)
  3166. {
  3167. //获取枚举描述
  3168. string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
  3169. typeof(XiaomiMESEnum_ProcessData.Enum_10_ProcessData));
  3170. //获取过站明细的值
  3171. object valueObj = field.GetValue(stPLC_MesData.mesData);
  3172. dic.Add(name, valueObj.ToString());
  3173. }
  3174. string paramJson = JsonConvert.SerializeObject(dic);
  3175. #endregion
  3176. //出站接口
  3177. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3178. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  3179. MachineId, StationId, "", paramJson);
  3180. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3181. if (mesResultFrmWeb == 1)
  3182. {
  3183. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3184. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  3185. }
  3186. stopwatch2.Start();
  3187. //进站结果写入PLC
  3188. CommandFromPLC resultToPlC = new CommandFromPLC();
  3189. resultToPlC.cmd = 0;
  3190. resultToPlC.cmdParam = 0; //指令参数
  3191. resultToPlC.cmdResult = mesResultFrmWeb;
  3192. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3193. stopwatch2.Stop();
  3194. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3195. //保存PLC返回MES数据到本地
  3196. ResponseMessage message = new ResponseMessage();
  3197. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  3198. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress,
  3199. stPLC_MesData.mesData.fCleanSpeed,
  3200. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime,
  3201. stPLC_MesData.mesData.nCleanCount,
  3202. stPLC_MesData.mesData.nRemainCount);
  3203. if (message.result == false)
  3204. {
  3205. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3206. }
  3207. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  3208. }
  3209. catch (Exception ex)
  3210. {
  3211. stopwatch2.Start();
  3212. CommandFromPLC resultToPlC = new CommandFromPLC();
  3213. resultToPlC.cmd = 0;
  3214. resultToPlC.cmdParam = 0; //指令参数
  3215. resultToPlC.cmdResult = 110;
  3216. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3217. stopwatch2.Stop();
  3218. string str = ex.StackTrace;
  3219. AddMessage(LogType.Error,
  3220. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3221. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3222. }
  3223. stopwatch1.Stop();
  3224. AddMessage(LogType.Info,
  3225. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3226. stopwatch2.ElapsedMilliseconds + "ms");
  3227. ProgressState = false;
  3228. }
  3229. #endregion
  3230. #region S2
  3231. /// <summary>
  3232. /// [S2] 上盖板上料装备
  3233. /// </summary>
  3234. /// <param name="plcNo">PLC编号</param>
  3235. private void ReadStation_S2(int plcNo)
  3236. {
  3237. string stationCode = "[OP20]";
  3238. string stationName = "上盖板上料装备";
  3239. string stationNameStr = stationCode + stationName;
  3240. string tagBaseName = "g_OP20_MES"; //标签变量名称
  3241. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3242. string tagAgvCommName = "agvCommFrmPC";
  3243. string tagiotComnName = "iotData";
  3244. string tagBarsetName = "BarcodeSet";
  3245. string CarrierBarcode = "";
  3246. // 触发信号字典
  3247. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  3248. s2PLCSignal_Old.Add("a2OEEType", 0); // 节拍类型(plc写入)
  3249. // PLC数据字典 赋值
  3250. s2PLCData.Add("a2OEEType", 0); // 节拍类型(plc写入)
  3251. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  3252. (int, string) result;
  3253. while (true)
  3254. {
  3255. try
  3256. {
  3257. if (!GlobalContext._IsCon_Funs2)
  3258. {
  3259. UpdatePLCMonitor(1, plcNo, 0);
  3260. continue;
  3261. }
  3262. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3263. {
  3264. Stopwatch stopwatch1 = new Stopwatch();
  3265. Stopwatch stopwatch2 = new Stopwatch();
  3266. stopwatch1.Start();
  3267. stopwatch2.Start();
  3268. #region 一次性读取所有数据
  3269. // 一次性读取所有数据
  3270. result = FunsEip[plcNo]
  3271. .Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3272. if (result.Item1 != 0)
  3273. {
  3274. //richTextBox1.AppendText("\n" + strRet);
  3275. }
  3276. else
  3277. {
  3278. //richTextBox1.AppendText("\n" + "读取成功");
  3279. stPLC_MesData.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  3280. stPLC_MesData.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  3281. stPLC_MesData.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  3282. stPLC_MesData.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  3283. //设备状态
  3284. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  3285. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  3286. ? XiaomiDeviceState.Unknown
  3287. : (XiaomiDeviceState)xmDeviceStateInt;
  3288. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  3289. s2PLCData["a2OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  3290. //报警信息
  3291. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  3292. }
  3293. #endregion 一次性读取所有数据
  3294. stopwatch2.Stop();
  3295. #region 进站
  3296. try
  3297. {
  3298. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3299. {
  3300. lock (lockObj)
  3301. {
  3302. if (!ProgressState)
  3303. {
  3304. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3305. ProgressState = true;
  3306. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData,
  3307. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  3308. out ProgressState));
  3309. }
  3310. }
  3311. }
  3312. }
  3313. catch (Exception ex)
  3314. {
  3315. ProgressState = false;
  3316. string str = ex.StackTrace;
  3317. AddMessage_Station(stationNameStr, LogType.Error,
  3318. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3319. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3320. }
  3321. #endregion 进站
  3322. #region 出站
  3323. try
  3324. {
  3325. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3326. {
  3327. lock (lockObj)
  3328. {
  3329. if (!ProgressState)
  3330. {
  3331. ProgressState = true;
  3332. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData,
  3333. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  3334. out ProgressState));
  3335. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  3336. uuid = "";
  3337. }
  3338. }
  3339. }
  3340. }
  3341. catch (Exception ex)
  3342. {
  3343. ProgressState = false;
  3344. string str = ex.StackTrace;
  3345. AddMessage_Station(stationNameStr, LogType.Error,
  3346. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3347. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3348. }
  3349. #endregion 出站
  3350. #region 节拍接口
  3351. try
  3352. {
  3353. if (stPLC_MesData.iotData.BeatAction > 0)
  3354. {
  3355. int a2OEEType = Convert.ToInt32(s2PLCData["a2OEEType"]);
  3356. int a2OEETypeGOld = Convert.ToInt32(s2PLCSignal_Old["a2OEEType"]);
  3357. //若设备紧急复原后节拍重置
  3358. if (a2OEEType == 1)
  3359. {
  3360. a2OEETypeGOld = 0;
  3361. }
  3362. if (a2OEEType != a2OEETypeGOld)
  3363. {
  3364. //如果上位机告诉PLC NG,PLC节拍会直接从1跳到4
  3365. if (a2OEETypeGOld <= 2 && a2OEEType == 4)
  3366. {
  3367. Task.Run(() =>
  3368. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  3369. CarrierBarcode,
  3370. stPLC_MesData.iotData));
  3371. }
  3372. else
  3373. {
  3374. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  3375. if ((a2OEETypeGOld == 1 && a2OEEType != 2) ||
  3376. (a2OEETypeGOld == 3 && a2OEEType != 4) ||
  3377. (a2OEETypeGOld == 5 && a2OEEType != 6))
  3378. {
  3379. //写入PLC
  3380. IoT_DataSet_t iotData = new IoT_DataSet_t();
  3381. iotData.machineState = stPLC_MesData.iotData.machineState;
  3382. iotData.work_type = stPLC_MesData.iotData.work_type;
  3383. iotData.testStatus = stPLC_MesData.iotData.testStatus;
  3384. iotData.BeatAction = stPLC_MesData.iotData.BeatAction;
  3385. iotData.beatReturn = 2; //NG
  3386. iotData.fault_codes = stPLC_MesData.iotData.fault_codes;
  3387. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  3388. AddMessage(LogType.Info,
  3389. stationNameStr +
  3390. $"_节拍接口-- 设备本次上传节拍[{a2OEEType}],未上传节拍[{a2OEETypeGOld}]的结束信号,请检查;总用时" +
  3391. stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3392. stopwatch2.ElapsedMilliseconds +
  3393. "ms");
  3394. return;
  3395. }
  3396. else
  3397. {
  3398. Task.Run(() => 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  3399. CarrierBarcode, stPLC_MesData.iotData));
  3400. //Task.Run(() =>
  3401. // S2节拍接口(plcNo, stationNameStr, tagBaseName,
  3402. // stPLC_MesData.iotData));
  3403. }
  3404. }
  3405. }
  3406. }
  3407. s2PLCSignal_Old["a2OEEType"] = s2PLCData["a2OEEType"];
  3408. }
  3409. catch (Exception ex)
  3410. {
  3411. string str = ex.StackTrace;
  3412. AddMessage_Station(stationNameStr, LogType.Error,
  3413. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3414. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3415. }
  3416. #endregion
  3417. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3418. stopwatch1.Stop();
  3419. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  3420. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3421. }
  3422. else
  3423. {
  3424. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3425. AddMessage_Station(stationNameStr, LogType.Info,
  3426. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3427. FunsEip[plcNo].Connect();
  3428. }
  3429. }
  3430. catch (Exception ex)
  3431. {
  3432. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3433. AddMessage_Station(stationNameStr, LogType.Error,
  3434. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3435. //Funs[plcNo].ReConnect();
  3436. }
  3437. Thread.Sleep(IntervalReadPLC);
  3438. }
  3439. }
  3440. /// <summary>
  3441. /// [S2] 上盖板上料装备
  3442. /// </summary>
  3443. /// <param name="plcNo">PLC编号</param>
  3444. /// <param name="stationNameStr">工站全称</param>
  3445. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  3446. string tagBarsetName, out bool ProgressState)
  3447. {
  3448. Stopwatch stopwatch1 = new Stopwatch();
  3449. Stopwatch stopwatch2 = new Stopwatch();
  3450. try
  3451. {
  3452. stopwatch1.Start();
  3453. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3454. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  3455. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  3456. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3457. bool pass = a1Result == 1;
  3458. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  3459. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  3460. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3461. //根据载具码获取产品码
  3462. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3463. if (string.IsNullOrEmpty(strProductBarcode))
  3464. {
  3465. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3466. }
  3467. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  3468. //if (sn != strProductBarcode)
  3469. //{
  3470. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  3471. //}
  3472. sn = strProductBarcode;
  3473. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3474. // 产品SN(物料码)校验
  3475. List<TestItem> item = new List<TestItem>();
  3476. stopwatch2.Start();
  3477. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3478. item, MachineId, StationId, pass, "01-SLOT-01");
  3479. stopwatch2.Stop();
  3480. //指令执行结果 1:OK 110:失败
  3481. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3482. if (mesResultFrmWeb == 1)
  3483. {
  3484. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3485. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3486. }
  3487. //进站结果写入PLC
  3488. CommandFromPLC resultToPlC = new CommandFromPLC();
  3489. resultToPlC.cmd = 0;
  3490. resultToPlC.cmdParam = 0; //指令参数
  3491. resultToPlC.cmdResult = mesResultFrmWeb;
  3492. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3493. }
  3494. catch (Exception ex)
  3495. {
  3496. string str = ex.StackTrace;
  3497. AddMessage(LogType.Error,
  3498. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3499. str.Length - str.LastIndexOf("\\") - 1));
  3500. CommandFromPLC resultToPlC = new CommandFromPLC();
  3501. resultToPlC.cmd = 0;
  3502. resultToPlC.cmdParam = 0; //指令参数
  3503. resultToPlC.cmdResult = 110;
  3504. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3505. }
  3506. stopwatch1.Stop();
  3507. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3508. AddMessage(LogType.Info,
  3509. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3510. stopwatch2.ElapsedMilliseconds + "ms");
  3511. ProgressState = false;
  3512. }
  3513. /// <summary>
  3514. /// [S2] 上盖板上料装备 - 出站接口
  3515. /// </summary>
  3516. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  3517. string stationCode, string stationName, out bool ProgressState)
  3518. {
  3519. Stopwatch stopwatch1 = new Stopwatch();
  3520. Stopwatch stopwatch2 = new Stopwatch();
  3521. test_item_num = 0; //iot 过站明细序号
  3522. try
  3523. {
  3524. stopwatch1.Start();
  3525. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3526. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3527. string processItem = stationName; // 测试项目
  3528. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3529. string supplierCode = ""; // 供应商代码
  3530. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3531. string batch_num = GlobalContext.BatchNumber; // 批次号
  3532. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3533. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3534. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3535. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  3536. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  3537. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  3538. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3539. bool pass = a1Result == 1;
  3540. //根据载具码获取产品码
  3541. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3542. if (string.IsNullOrEmpty(strProductBarcode))
  3543. {
  3544. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3545. ProgressState = false;
  3546. Thread.Sleep(10000);
  3547. return;
  3548. }
  3549. sn = strProductBarcode;
  3550. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3551. List<TestItem> items = new List<TestItem>();
  3552. items.Add(new TestItem()
  3553. {
  3554. Parameter_name = "载具码",
  3555. Parameter_value = CarrierBarcode,
  3556. Parameter_unit = ""
  3557. });
  3558. items.Add(new TestItem()
  3559. {
  3560. Parameter_name = "产品码",
  3561. Parameter_value = sn,
  3562. Parameter_unit = ""
  3563. });
  3564. items.Add(new TestItem()
  3565. {
  3566. Parameter_name = "部件码",
  3567. Parameter_value = PartBarcode,
  3568. Parameter_unit = ""
  3569. });
  3570. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3571. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3572. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  3573. MachineId, StationId, PartBarcode, paramJson);
  3574. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3575. if (mesResultFrmWeb == 1)
  3576. {
  3577. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3578. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  3579. }
  3580. stopwatch2.Start();
  3581. //进站结果写入PLC
  3582. CommandFromPLC resultToPlC = new CommandFromPLC();
  3583. resultToPlC.cmd = 0;
  3584. resultToPlC.cmdParam = 0; //指令参数
  3585. resultToPlC.cmdResult = mesResultFrmWeb;
  3586. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3587. stopwatch2.Stop();
  3588. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3589. //保存PLC返回MES数据到本地
  3590. ResponseMessage message = new ResponseMessage();
  3591. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  3592. stPLC_MesData.mesData.nRemainCount);
  3593. if (message.result == false)
  3594. {
  3595. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3596. }
  3597. if (!string.IsNullOrEmpty(PartBarcode))
  3598. {
  3599. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  3600. if (message.result == false)
  3601. {
  3602. AddMessage(LogType.Error, message.text);
  3603. }
  3604. }
  3605. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3606. }
  3607. catch (Exception ex)
  3608. {
  3609. stopwatch2.Start();
  3610. CommandFromPLC resultToPlC = new CommandFromPLC();
  3611. resultToPlC.cmd = 0;
  3612. resultToPlC.cmdParam = 0; //指令参数
  3613. resultToPlC.cmdResult = 110;
  3614. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3615. stopwatch2.Stop();
  3616. string str = ex.StackTrace;
  3617. AddMessage(LogType.Error,
  3618. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3619. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3620. }
  3621. stopwatch1.Stop();
  3622. AddMessage(LogType.Info,
  3623. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3624. stopwatch2.ElapsedMilliseconds + "ms");
  3625. ProgressState = false;
  3626. }
  3627. #endregion
  3628. #region S3
  3629. /// <summary>
  3630. /// [S3] 点散热胶装备
  3631. /// </summary>
  3632. /// <param name="plcNo">PLC编号</param>
  3633. private void ReadStation_S3(int plcNo)
  3634. {
  3635. string stationCode = "[OP30]";
  3636. string stationName = "点散热胶装备";
  3637. string stationNameStr = stationCode + stationName;
  3638. string tagBaseName = "g_OP30_MES"; //标签变量名称
  3639. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3640. string tagAgvCommName = "agvCommFrmPC";
  3641. string tagiotComnName = "iotData";
  3642. string tagBarsetName = "BarcodeSet";
  3643. string CarrierBarcode_Left = "";
  3644. string CarrierBarcode_Right = "";
  3645. s3PLCSignal_Old.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
  3646. s3PLCSignal_Old.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
  3647. // PLC数据字典 赋值
  3648. s3PLCData.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
  3649. s3PLCData.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
  3650. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  3651. (int, string) result;
  3652. while (true)
  3653. {
  3654. try
  3655. {
  3656. if (!GlobalContext._IsCon_Funs2)
  3657. {
  3658. UpdatePLCMonitor(1, plcNo, 0);
  3659. continue;
  3660. }
  3661. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3662. {
  3663. Stopwatch stopwatch1 = new Stopwatch();
  3664. Stopwatch stopwatch2 = new Stopwatch();
  3665. stopwatch1.Start();
  3666. stopwatch2.Start();
  3667. #region 一次性读取所有数据
  3668. // 一次性读取所有数据
  3669. result = FunsEip[plcNo]
  3670. .Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3671. if (result.Item1 != 0)
  3672. {
  3673. //richTextBox1.AppendText("\n" + strRet);
  3674. }
  3675. else
  3676. {
  3677. #region 去除扫码产生的特殊字符
  3678. stPLC_MesData.Left.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strProductBarcode);
  3679. stPLC_MesData.Left.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPartBarcode);
  3680. stPLC_MesData.Left.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strCarrierBarcode);
  3681. stPLC_MesData.Left.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPCBBarcode);
  3682. stPLC_MesData.Right.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strProductBarcode);
  3683. stPLC_MesData.Right.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPartBarcode);
  3684. stPLC_MesData.Right.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strCarrierBarcode);
  3685. stPLC_MesData.Right.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPCBBarcode);
  3686. #endregion
  3687. //richTextBox1.AppendText("\n" + "读取成功");
  3688. //设备状态
  3689. int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  3690. int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  3691. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  3692. ? XiaomiDeviceState.Unknown
  3693. : (XiaomiDeviceState)xmDeviceStateInt_L;
  3694. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  3695. ? XiaomiDeviceState.Unknown
  3696. : (XiaomiDeviceState)xmDeviceStateInt_R;
  3697. //载具SN
  3698. CarrierBarcode_Left = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode;
  3699. CarrierBarcode_Right = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode;
  3700. // 节拍
  3701. s3PLCData["a3OEEType_left"] = stPLC_MesData.Left.iotData.BeatAction;
  3702. s3PLCData["a3OEEType_right"] = stPLC_MesData.Right.iotData.BeatAction;
  3703. //报警信息
  3704. _FaultDatas = stPLC_MesData.Left.iotData.fault_codes;
  3705. _FaultDatas2 = stPLC_MesData.Right.iotData.fault_codes;
  3706. }
  3707. #endregion 一次性读取所有数据
  3708. stopwatch2.Stop();
  3709. #region 左边进站
  3710. try
  3711. {
  3712. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3713. {
  3714. lock (lockObj)
  3715. {
  3716. if (!ProgressState)
  3717. {
  3718. stationCode = "[OP31]";
  3719. stationName = "点散热胶装备1";
  3720. stationNameStr = stationCode + stationName;
  3721. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3722. ProgressState = true;
  3723. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left,
  3724. tagBaseName + ".Left." + tagMesCommName,
  3725. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  3726. }
  3727. }
  3728. }
  3729. }
  3730. catch (Exception ex)
  3731. {
  3732. ProgressState = false;
  3733. string str = ex.StackTrace;
  3734. AddMessage_Station(stationNameStr, LogType.Error,
  3735. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3736. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3737. }
  3738. #endregion 左边进站
  3739. #region 左边出站
  3740. try
  3741. {
  3742. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3743. {
  3744. lock (lockObj)
  3745. {
  3746. if (!ProgressState)
  3747. {
  3748. stationCode = "[OP31]";
  3749. stationName = "点散热胶装备1";
  3750. stationNameStr = stationCode + stationName;
  3751. ProgressState = true;
  3752. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left,
  3753. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  3754. out ProgressState));
  3755. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  3756. uuid = "";
  3757. }
  3758. }
  3759. }
  3760. }
  3761. catch (Exception ex)
  3762. {
  3763. ProgressState = false;
  3764. string str = ex.StackTrace;
  3765. AddMessage_Station(stationNameStr, LogType.Error,
  3766. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3767. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3768. }
  3769. #endregion 左边出站
  3770. #region 右边进站
  3771. try
  3772. {
  3773. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3774. {
  3775. lock (lockObj)
  3776. {
  3777. if (!ProgressState)
  3778. {
  3779. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3780. stationCode = "[OP32]";
  3781. stationName = "点散热胶装备2";
  3782. stationNameStr = stationCode + stationName;
  3783. ProgressState = true;
  3784. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right,
  3785. tagBaseName + ".Right." + tagMesCommName,
  3786. tagBaseName + ".Right." + tagBarsetName, "Right", out ProgressState));
  3787. }
  3788. }
  3789. }
  3790. }
  3791. catch (Exception ex)
  3792. {
  3793. ProgressState = false;
  3794. string str = ex.StackTrace;
  3795. AddMessage_Station(stationNameStr, LogType.Error,
  3796. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3797. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3798. }
  3799. #endregion 右边进站
  3800. #region 右边出站
  3801. try
  3802. {
  3803. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3804. {
  3805. lock (lockObj)
  3806. {
  3807. if (!ProgressState)
  3808. {
  3809. stationCode = "[OP32]";
  3810. stationName = "点散热胶装备2";
  3811. stationNameStr = stationCode + stationName;
  3812. ProgressState = true;
  3813. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right,
  3814. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  3815. out ProgressState));
  3816. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  3817. uuid = "";
  3818. }
  3819. }
  3820. }
  3821. }
  3822. catch (Exception ex)
  3823. {
  3824. string str = ex.StackTrace;
  3825. AddMessage_Station(stationNameStr, LogType.Error,
  3826. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3827. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3828. }
  3829. #endregion 右边出站
  3830. #region 节拍接口
  3831. try
  3832. {
  3833. #region 左工位 节拍
  3834. if (stPLC_MesData.Left.iotData.BeatAction > 0)
  3835. {
  3836. stationCode = "[OP31]";
  3837. stationName = "点散热胶装备1";
  3838. stationNameStr = stationCode + stationName;
  3839. int a3OEEType_left = Convert.ToInt32(s3PLCData["a3OEEType_left"]);
  3840. int a3OEETypeGOld_left = Convert.ToInt32(s3PLCSignal_Old["a3OEEType_left"]);
  3841. //若设备紧急复原后节拍重置
  3842. if (a3OEEType_left == 1)
  3843. {
  3844. a3OEETypeGOld_left = 0;
  3845. }
  3846. if (a3OEEType_left != a3OEETypeGOld_left)
  3847. {
  3848. //如果上位机告诉PLC NG,PLC节拍会直接从1跳到4
  3849. if (a3OEETypeGOld_left <= 2 && a3OEEType_left == 4)
  3850. {
  3851. Task.Run(() =>
  3852. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagiotComnName,
  3853. CarrierBarcode_Left,
  3854. stPLC_MesData.Left.iotData));
  3855. }
  3856. else
  3857. {
  3858. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  3859. if ((a3OEETypeGOld_left == 1 && a3OEEType_left != 2) ||
  3860. (a3OEETypeGOld_left == 3 && a3OEEType_left != 4)
  3861. || (a3OEETypeGOld_left == 5 && a3OEEType_left != 6))
  3862. {
  3863. //写入PLC
  3864. IoT_DataSet_t iotData = new IoT_DataSet_t();
  3865. iotData.machineState = stPLC_MesData.Left.iotData.machineState;
  3866. iotData.work_type = stPLC_MesData.Left.iotData.work_type;
  3867. iotData.testStatus = stPLC_MesData.Left.iotData.testStatus;
  3868. iotData.BeatAction = stPLC_MesData.Left.iotData.BeatAction;
  3869. iotData.beatReturn = 2; //NG
  3870. iotData.fault_codes = stPLC_MesData.Left.iotData.fault_codes;
  3871. WriteResultToPlc(plcNo, stationNameStr,
  3872. tagBaseName + ".Left." + tagiotComnName, 1, iotData);
  3873. AddMessage(LogType.Info,
  3874. stationNameStr +
  3875. $"_节拍接口-- 设备本次上传节拍[{a3OEEType_left}],未上传节拍[{a3OEETypeGOld_left}]的结束信号,请检查;总用时" +
  3876. stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3877. stopwatch2.ElapsedMilliseconds +
  3878. "ms");
  3879. return;
  3880. }
  3881. else
  3882. {
  3883. Task.Run(() => 通用节拍接口(plcNo, stationNameStr,
  3884. tagBaseName + ".Left." + tagiotComnName, CarrierBarcode_Left,
  3885. stPLC_MesData.Left.iotData));
  3886. //Task.Run(() =>
  3887. // S3节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagiotComnName, stPLC_MesData.Left.BarcodeSet.strCarrierBarcode.ToString(),
  3888. // stPLC_MesData.Left.iotData));
  3889. }
  3890. }
  3891. }
  3892. }
  3893. s3PLCSignal_Old["a3OEEType_left"] = s3PLCData["a3OEEType_left"];
  3894. #endregion 左工位 节拍
  3895. #region 右工位 节拍
  3896. if (stPLC_MesData.Right.iotData.BeatAction > 0)
  3897. {
  3898. stationCode = "[OP32]";
  3899. stationName = "点散热胶装备2";
  3900. stationNameStr = stationCode + stationName;
  3901. int a3OEEType_right = Convert.ToInt32(s3PLCData["a3OEEType_right"]);
  3902. int a3OEETypeGOld_right = Convert.ToInt32(s3PLCSignal_Old["a3OEEType_right"]);
  3903. //若设备紧急复原后节拍重置
  3904. if (a3OEEType_right == 1)
  3905. {
  3906. a3OEETypeGOld_right = 0;
  3907. }
  3908. if (a3OEEType_right != a3OEETypeGOld_right)
  3909. {
  3910. if (a3OEETypeGOld_right <= 2 && a3OEEType_right == 4)
  3911. {
  3912. Task.Run(() =>
  3913. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagiotComnName,
  3914. CarrierBarcode_Right,
  3915. stPLC_MesData.Right.iotData));
  3916. }
  3917. else
  3918. {
  3919. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  3920. if ((a3OEETypeGOld_right == 1 && a3OEEType_right != 2) ||
  3921. (a3OEETypeGOld_right == 3 && a3OEEType_right != 4) ||
  3922. (a3OEETypeGOld_right == 5 && a3OEEType_right != 6))
  3923. {
  3924. //写入PLC
  3925. IoT_DataSet_t iotData = new IoT_DataSet_t();
  3926. iotData.machineState = stPLC_MesData.Left.iotData.machineState;
  3927. iotData.work_type = stPLC_MesData.Left.iotData.work_type;
  3928. iotData.testStatus = stPLC_MesData.Left.iotData.testStatus;
  3929. iotData.BeatAction = stPLC_MesData.Left.iotData.BeatAction;
  3930. iotData.beatReturn = 2; //NG
  3931. iotData.fault_codes = stPLC_MesData.Left.iotData.fault_codes;
  3932. WriteResultToPlc(plcNo, stationNameStr,
  3933. tagBaseName + ".Right." + tagiotComnName, 1, iotData);
  3934. AddMessage(LogType.Info,
  3935. stationNameStr +
  3936. $"_节拍接口-- 设备本次上传节拍[{a3OEEType_right}],未上传节拍[{a3OEETypeGOld_right}]的结束信号,请检查;总用时" +
  3937. stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3938. stopwatch2.ElapsedMilliseconds +
  3939. "ms");
  3940. return;
  3941. }
  3942. else
  3943. {
  3944. Task.Run(() =>
  3945. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagiotComnName,
  3946. CarrierBarcode_Right,
  3947. stPLC_MesData.Right.iotData));
  3948. //Task.Run(() =>
  3949. // S3节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagiotComnName,
  3950. // stPLC_MesData.Right.BarcodeSet.strCarrierBarcode,
  3951. // stPLC_MesData.Left.iotData));
  3952. }
  3953. }
  3954. }
  3955. }
  3956. s3PLCSignal_Old["a3OEEType_right"] = s3PLCData["a3OEEType_right"];
  3957. #endregion 右工位 节拍
  3958. }
  3959. catch (Exception ex)
  3960. {
  3961. string str = ex.StackTrace;
  3962. AddMessage_Station(stationNameStr, LogType.Error,
  3963. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3964. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3965. }
  3966. #endregion
  3967. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3968. stopwatch1.Stop();
  3969. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  3970. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3971. }
  3972. else
  3973. {
  3974. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3975. AddMessage_Station(stationNameStr, LogType.Info,
  3976. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3977. FunsEip[plcNo].Connect();
  3978. }
  3979. }
  3980. catch (Exception ex)
  3981. {
  3982. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3983. AddMessage_Station(stationNameStr, LogType.Error,
  3984. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3985. //Funs[plcNo].ReConnect();
  3986. }
  3987. Thread.Sleep(IntervalReadPLC);
  3988. }
  3989. }
  3990. /// <summary>
  3991. /// [S3] 点散热胶装备 - 进站
  3992. /// </summary>
  3993. /// <param name="plcNo">PLC编号</param>
  3994. /// <param name="stationNameStr">工站全称</param>
  3995. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  3996. string tagBarsetName, string direction, out bool ProgressState)
  3997. {
  3998. Stopwatch stopwatch1 = new Stopwatch();
  3999. Stopwatch stopwatch2 = new Stopwatch();
  4000. try
  4001. {
  4002. stopwatch1.Start();
  4003. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  4004. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4005. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  4006. string StationId = string.Empty;
  4007. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4008. bool pass = a1Result == 1;
  4009. string slot = "";
  4010. if (direction == "Left")
  4011. {
  4012. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  4013. slot = "01-SLOT-01";
  4014. }
  4015. if (direction == "Right")
  4016. {
  4017. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  4018. slot = "01-SLOT-02";
  4019. }
  4020. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4021. //载具码验证产品码
  4022. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4023. if (string.IsNullOrEmpty(strProductBarcode))
  4024. {
  4025. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4026. }
  4027. sn = strProductBarcode;
  4028. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  4029. // 产品SN(物料码)校验
  4030. List<TestItem> item = new List<TestItem>();
  4031. stopwatch2.Start();
  4032. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  4033. item, MachineId, StationId, pass, slot);
  4034. stopwatch2.Stop();
  4035. //指令执行结果 1:OK 110:失败
  4036. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4037. if (mesResultFrmWeb == 1)
  4038. {
  4039. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  4040. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  4041. }
  4042. //进站结果写入PLC
  4043. CommandFromPLC resultToPlC = new CommandFromPLC();
  4044. resultToPlC.cmd = 0;
  4045. resultToPlC.cmdParam = 0; //指令参数
  4046. resultToPlC.cmdResult = mesResultFrmWeb;
  4047. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4048. }
  4049. catch (Exception ex)
  4050. {
  4051. string str = ex.StackTrace;
  4052. AddMessage(LogType.Error,
  4053. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4054. str.Length - str.LastIndexOf("\\") - 1));
  4055. CommandFromPLC resultToPlC = new CommandFromPLC();
  4056. resultToPlC.cmd = 0;
  4057. resultToPlC.cmdParam = 0; //指令参数
  4058. resultToPlC.cmdResult = 110;
  4059. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4060. }
  4061. stopwatch1.Stop();
  4062. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  4063. AddMessage(LogType.Info,
  4064. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4065. stopwatch2.ElapsedMilliseconds + "ms");
  4066. ProgressState = false;
  4067. }
  4068. /// <summary>
  4069. /// [S3] 点散热胶装备 - 出站
  4070. /// </summary>
  4071. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  4072. string stationCode, string stationName, string direction, out bool ProgressState)
  4073. {
  4074. Stopwatch stopwatch1 = new Stopwatch();
  4075. Stopwatch stopwatch2 = new Stopwatch();
  4076. test_item_num = 0; //iot 过站明细序号
  4077. try
  4078. {
  4079. stopwatch1.Start();
  4080. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  4081. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4082. string processItem = stationName; // 测试项目
  4083. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4084. string supplierCode = ""; // 供应商代码
  4085. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4086. string batch_num = GlobalContext.BatchNumber; // 批次号
  4087. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4088. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4089. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4090. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  4091. string StationId = string.Empty;
  4092. if (direction == "Left")
  4093. {
  4094. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  4095. }
  4096. if (direction == "Right")
  4097. {
  4098. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  4099. }
  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. ProgressState = false;
  4108. Thread.Sleep(10000);
  4109. return;
  4110. }
  4111. sn = strProductBarcode;
  4112. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4113. List<TestItem> items = new List<TestItem>();
  4114. items.Add(new TestItem()
  4115. {
  4116. Parameter_name = "载具码",
  4117. Parameter_value = CarrierBarcode,
  4118. Parameter_unit = ""
  4119. });
  4120. items.Add(new TestItem()
  4121. {
  4122. Parameter_name = "产品码",
  4123. Parameter_value = sn,
  4124. Parameter_unit = ""
  4125. });
  4126. //if (direction == "Right")
  4127. //{
  4128. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4129. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4130. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  4131. MachineId, StationId, "", paramJson, direction);
  4132. //}
  4133. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4134. if (mesResultFrmWeb == 1)
  4135. {
  4136. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  4137. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  4138. }
  4139. stopwatch2.Start();
  4140. //进站结果写入PLC
  4141. CommandFromPLC resultToPlC = new CommandFromPLC();
  4142. resultToPlC.cmd = 0;
  4143. resultToPlC.cmdParam = 0; //指令参数
  4144. resultToPlC.cmdResult = mesResultFrmWeb;
  4145. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4146. stopwatch2.Stop();
  4147. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  4148. //保存PLC返回MES数据到本地
  4149. ResponseMessage message = new ResponseMessage();
  4150. if (direction == "Left")
  4151. {
  4152. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  4153. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  4154. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  4155. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  4156. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  4157. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  4158. if (message.result == false)
  4159. {
  4160. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4161. }
  4162. }
  4163. if (direction == "Right")
  4164. {
  4165. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  4166. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  4167. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  4168. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  4169. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  4170. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  4171. if (message.result == false)
  4172. {
  4173. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4174. }
  4175. }
  4176. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4177. }
  4178. catch (Exception ex)
  4179. {
  4180. stopwatch2.Start();
  4181. CommandFromPLC resultToPlC = new CommandFromPLC();
  4182. resultToPlC.cmd = 0;
  4183. resultToPlC.cmdParam = 0; //指令参数
  4184. resultToPlC.cmdResult = 110;
  4185. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4186. stopwatch2.Stop();
  4187. string str = ex.StackTrace;
  4188. AddMessage(LogType.Error,
  4189. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4190. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4191. }
  4192. stopwatch1.Stop();
  4193. AddMessage(LogType.Info,
  4194. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4195. stopwatch2.ElapsedMilliseconds + "ms");
  4196. ProgressState = false;
  4197. }
  4198. #endregion S3
  4199. #region S4
  4200. /// <summary>
  4201. /// [S4] 点胶检测设备
  4202. /// </summary>
  4203. /// <param name="plcNo">PLC编号</param>
  4204. private void ReadStation_S4(int plcNo)
  4205. {
  4206. string stationCode = "[OP40]";
  4207. string stationName = "胶线检测";
  4208. string stationNameStr = stationCode + stationName;
  4209. string tagBaseName = "g_OP40_MES"; //标签变量名称
  4210. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4211. string tagAgvCommName = "agvCommFrmPC";
  4212. string tagiotComnName = "iotData";
  4213. string tagBarsetName = "BarcodeSet";
  4214. string CarrierBarcode = "";
  4215. // 触发信号字典
  4216. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4217. s4PLCSignal_Old.Add("a4OEEType", 0); // 节拍类型(plc写入)
  4218. // PLC数据字典 赋值
  4219. s4PLCData.Add("a4OEEType", 0); // 节拍类型(plc写入)
  4220. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  4221. (int, string) result;
  4222. while (true)
  4223. {
  4224. try
  4225. {
  4226. if (!GlobalContext._IsCon_Funs1)
  4227. {
  4228. UpdatePLCMonitor(1, plcNo, 0);
  4229. continue;
  4230. }
  4231. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4232. {
  4233. Stopwatch stopwatch1 = new Stopwatch();
  4234. Stopwatch stopwatch2 = new Stopwatch();
  4235. stopwatch1.Start();
  4236. stopwatch2.Start();
  4237. #region 一次性读取所有数据
  4238. // 一次性读取所有数据
  4239. result = FunsEip[plcNo]
  4240. .Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4241. if (result.Item1 != 0)
  4242. {
  4243. //richTextBox1.AppendText("\n" + strRet);
  4244. }
  4245. else
  4246. {
  4247. //去除扫码产生的特殊字符
  4248. stPLC_MesData.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  4249. stPLC_MesData.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  4250. stPLC_MesData.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  4251. stPLC_MesData.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  4252. //richTextBox1.AppendText("\n" + "读取成功");
  4253. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  4254. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  4255. ? XiaomiDeviceState.Unknown
  4256. : (XiaomiDeviceState)xmDeviceStateInt;
  4257. // 载具SN
  4258. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode;
  4259. // 节拍
  4260. s4PLCData["a4OEEType"] = stPLC_MesData.iotData.BeatAction;
  4261. //报警信息
  4262. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  4263. }
  4264. #endregion 一次性读取所有数据
  4265. stopwatch2.Stop();
  4266. #region 进站
  4267. try
  4268. {
  4269. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4270. {
  4271. lock (lockObj)
  4272. {
  4273. if (!ProgressState)
  4274. {
  4275. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  4276. ProgressState = true;
  4277. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData,
  4278. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  4279. out ProgressState));
  4280. }
  4281. }
  4282. }
  4283. }
  4284. catch (Exception ex)
  4285. {
  4286. ProgressState = false;
  4287. string str = ex.StackTrace;
  4288. AddMessage_Station(stationNameStr, LogType.Error,
  4289. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4290. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4291. }
  4292. #endregion 进站
  4293. #region 出站
  4294. try
  4295. {
  4296. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4297. {
  4298. lock (lockObj)
  4299. {
  4300. if (!ProgressState)
  4301. {
  4302. ProgressState = true;
  4303. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData,
  4304. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4305. out ProgressState));
  4306. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4307. uuid = "";
  4308. }
  4309. }
  4310. }
  4311. }
  4312. catch (Exception ex)
  4313. {
  4314. string str = ex.StackTrace;
  4315. AddMessage_Station(stationNameStr, LogType.Error,
  4316. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4317. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4318. }
  4319. #endregion 出站
  4320. #region 节拍接口
  4321. try
  4322. {
  4323. if (stPLC_MesData.iotData.BeatAction > 0)
  4324. {
  4325. int a4OEEType = Convert.ToInt32(s4PLCData["a4OEEType"]);
  4326. int a4OEETypeGOld = Convert.ToInt32(s4PLCSignal_Old["a4OEEType"]);
  4327. //若设备紧急复原后节拍重置
  4328. if (a4OEEType == 1)
  4329. {
  4330. a4OEETypeGOld = 0;
  4331. }
  4332. if (a4OEEType != a4OEETypeGOld)
  4333. {
  4334. if (a4OEETypeGOld <= 2 && a4OEEType == 4)
  4335. {
  4336. Task.Run(() =>
  4337. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  4338. CarrierBarcode,
  4339. stPLC_MesData.iotData));
  4340. }
  4341. else
  4342. {
  4343. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  4344. if ((a4OEETypeGOld == 1 && a4OEEType != 2) ||
  4345. (a4OEETypeGOld == 3 && a4OEEType != 4) ||
  4346. (a4OEETypeGOld == 5 && a4OEEType != 6))
  4347. {
  4348. //写入PLC
  4349. stPLC_MesData.iotData.beatReturn = 2; //NG
  4350. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1,
  4351. stPLC_MesData.iotData);
  4352. AddMessage(LogType.Info,
  4353. stationNameStr +
  4354. $"_节拍接口-- 设备本次上传节拍[{a4OEEType}],未上传节拍[{a4OEETypeGOld}]的结束信号,请检查;总用时" +
  4355. stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4356. stopwatch2.ElapsedMilliseconds +
  4357. "ms");
  4358. return;
  4359. }
  4360. else
  4361. {
  4362. Task.Run(() => 通用节拍接口(plcNo, stationNameStr,
  4363. tagBaseName + "." + tagiotComnName, CarrierBarcode,
  4364. stPLC_MesData.iotData));
  4365. //Task.Run(() =>
  4366. // S4节拍接口(plcNo, stationNameStr, tagBaseName,
  4367. // stPLC_MesData.iotData));
  4368. }
  4369. }
  4370. }
  4371. }
  4372. s4PLCSignal_Old["a4OEEType"] = s4PLCData["a4OEEType"];
  4373. }
  4374. catch (Exception ex)
  4375. {
  4376. string str = ex.StackTrace;
  4377. AddMessage_Station(stationNameStr, LogType.Error,
  4378. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4379. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4380. }
  4381. #endregion
  4382. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4383. stopwatch1.Stop();
  4384. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4385. }
  4386. else
  4387. {
  4388. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4389. AddMessage_Station(stationNameStr, LogType.Info,
  4390. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4391. FunsEip[plcNo].Connect(); // 重连
  4392. }
  4393. }
  4394. catch (Exception ex)
  4395. {
  4396. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4397. AddMessage_Station(stationNameStr, LogType.Error,
  4398. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4399. }
  4400. Thread.Sleep(IntervalReadPLC);
  4401. }
  4402. }
  4403. /// <summary>
  4404. /// [S4] 点胶检测设备 - 进站
  4405. /// </summary>
  4406. /// <param name="plcNo">PLC编号</param>
  4407. /// <param name="stationNameStr">工站全称</param>
  4408. /// <param name="stPLC_MesData"></param>
  4409. /// <param name="tagMesCommName"></param>
  4410. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  4411. string tagBarsetName, out bool ProgressState)
  4412. {
  4413. Stopwatch stopwatch1 = new Stopwatch();
  4414. Stopwatch stopwatch2 = new Stopwatch();
  4415. test_item_num = 0; //iot 过站明细序号
  4416. try
  4417. {
  4418. stopwatch1.Start();
  4419. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4420. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4421. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  4422. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  4423. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4424. bool pass = a1Result == 1;
  4425. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4426. //载具码验证产品码
  4427. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4428. if (string.IsNullOrEmpty(strProductBarcode))
  4429. {
  4430. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4431. ProgressState = false;
  4432. Thread.Sleep(10000);
  4433. return;
  4434. }
  4435. sn = strProductBarcode;
  4436. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4437. // 产品SN(物料码)校验
  4438. List<TestItem> item = new List<TestItem>();
  4439. stopwatch2.Start();
  4440. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  4441. item, MachineId, StationId, pass, "01-SLOT-01");
  4442. stopwatch2.Stop();
  4443. //指令执行结果 1:OK 110:失败
  4444. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4445. if (mesResultFrmWeb == 1)
  4446. {
  4447. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  4448. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  4449. }
  4450. //进站结果写入PLC
  4451. CommandFromPLC resultToPlC = new CommandFromPLC();
  4452. resultToPlC.cmd = 0;
  4453. resultToPlC.cmdParam = 0; //指令参数
  4454. resultToPlC.cmdResult = mesResultFrmWeb;
  4455. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4456. }
  4457. catch (Exception ex)
  4458. {
  4459. string str = ex.StackTrace;
  4460. AddMessage(LogType.Error,
  4461. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4462. str.Length - str.LastIndexOf("\\") - 1));
  4463. CommandFromPLC resultToPlC = new CommandFromPLC();
  4464. resultToPlC.cmd = 0;
  4465. resultToPlC.cmdParam = 0; //指令参数
  4466. resultToPlC.cmdResult = 110;
  4467. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4468. }
  4469. stopwatch1.Stop();
  4470. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4471. AddMessage(LogType.Info,
  4472. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4473. stopwatch2.ElapsedMilliseconds + "ms");
  4474. ProgressState = false;
  4475. }
  4476. /// <summary>
  4477. /// [S4] 点胶检测设备 - 出站接口
  4478. /// </summary>
  4479. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  4480. string stationCode, string stationName, out bool ProgressState)
  4481. {
  4482. Stopwatch stopwatch1 = new Stopwatch();
  4483. Stopwatch stopwatch2 = new Stopwatch();
  4484. test_item_num = 0; //iot 过站明细序号
  4485. try
  4486. {
  4487. stopwatch1.Start();
  4488. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4489. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4490. string processItem = stationName; // 测试项目
  4491. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4492. string supplierCode = ""; // 供应商代码
  4493. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4494. string batch_num = GlobalContext.BatchNumber; // 批次号
  4495. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4496. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4497. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4498. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  4499. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  4500. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4501. bool pass = a1Result == 1;
  4502. //根据载具码获取产品码
  4503. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4504. if (string.IsNullOrEmpty(strProductBarcode))
  4505. {
  4506. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4507. ProgressState = false;
  4508. Thread.Sleep(10000);
  4509. return;
  4510. }
  4511. sn = strProductBarcode;
  4512. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4513. List<TestItem> items = new List<TestItem>();
  4514. items.Add(new TestItem()
  4515. {
  4516. Parameter_name = "载具码",
  4517. Parameter_value = CarrierBarcode,
  4518. Parameter_unit = ""
  4519. });
  4520. items.Add(new TestItem()
  4521. {
  4522. Parameter_name = "产品码",
  4523. Parameter_value = sn,
  4524. Parameter_unit = ""
  4525. });
  4526. #region 上传图片
  4527. if (GlobalContext.MQTTIsSendUpFile)
  4528. {
  4529. string[] urlarry = GlobalContext.UpFilePath.Split(",");
  4530. fileUploadData.fileData.Clear();
  4531. foreach (var item in urlarry)
  4532. {
  4533. if (!string.IsNullOrEmpty(item))
  4534. {
  4535. //上传图片
  4536. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName, a1Result,
  4537. item, uuid).Result;
  4538. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  4539. }
  4540. }
  4541. }
  4542. #endregion
  4543. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4544. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4545. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode,
  4546. "01-SLOT-01", MachineId, StationId, "", paramJson);
  4547. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4548. if (mesResultFrmWeb == 1)
  4549. {
  4550. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  4551. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  4552. }
  4553. stopwatch2.Start();
  4554. //进站结果写入PLC
  4555. CommandFromPLC resultToPlC = new CommandFromPLC();
  4556. resultToPlC.cmd = 0;
  4557. resultToPlC.cmdParam = 0; //指令参数
  4558. resultToPlC.cmdResult = mesResultFrmWeb;
  4559. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4560. stopwatch2.Stop();
  4561. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4562. //保存PLC返回MES数据到本地
  4563. ResponseMessage message = new ResponseMessage();
  4564. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  4565. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  4566. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  4567. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  4568. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  4569. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  4570. if (message.result == false)
  4571. {
  4572. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4573. }
  4574. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4575. }
  4576. catch (Exception ex)
  4577. {
  4578. stopwatch2.Start();
  4579. CommandFromPLC resultToPlC = new CommandFromPLC();
  4580. resultToPlC.cmd = 0;
  4581. resultToPlC.cmdParam = 0; //指令参数
  4582. resultToPlC.cmdResult = 110;
  4583. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4584. stopwatch2.Stop();
  4585. string str = ex.StackTrace;
  4586. AddMessage(LogType.Error,
  4587. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4588. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4589. }
  4590. stopwatch1.Stop();
  4591. AddMessage(LogType.Info,
  4592. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4593. stopwatch2.ElapsedMilliseconds + "ms");
  4594. ProgressState = false;
  4595. }
  4596. private void S4节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  4597. {
  4598. Stopwatch stopwatch1 = new Stopwatch();
  4599. Stopwatch stopwatch2 = new Stopwatch();
  4600. string resultStr = string.Empty;
  4601. try
  4602. {
  4603. stopwatch1.Start();
  4604. string oEEType = ((int)s1PLCData["a4OEEType"]).ToString(); // 节拍类型(plc写入)
  4605. string a40EEPartNo = (string)s1PLCData["a40EEPartNo"]; // 物料码
  4606. a40EEPartNo = a40EEPartNo.Replace("\0", "");
  4607. string a50EEVehicleCode = (string)s1PLCData["a50EEVehicleCode"]; // 载具SN
  4608. a50EEVehicleCode = a50EEVehicleCode.Replace("\0", "");
  4609. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4610. if (!actionBool)
  4611. {
  4612. stopwatch2.Start();
  4613. //写入PLC
  4614. iot_data.beatReturn = 2; //NG
  4615. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4616. stopwatch2.Stop();
  4617. AddMessage(LogType.Info,
  4618. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  4619. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4620. return;
  4621. }
  4622. //作业开始后要有物料和载具信息
  4623. if (string.IsNullOrEmpty(a40EEPartNo) && string.IsNullOrEmpty(a50EEVehicleCode) &&
  4624. Convert.ToInt32(oEEType) > 2)
  4625. {
  4626. stopwatch2.Start();
  4627. //写入PLC
  4628. iot_data.beatReturn = 2; //NG
  4629. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4630. stopwatch2.Stop();
  4631. AddMessage_Station(stationNameStr, LogType.Info,
  4632. stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  4633. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4634. return;
  4635. }
  4636. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a40EEPartNo))
  4637. {
  4638. stopwatch2.Start();
  4639. //写入PLC
  4640. iot_data.beatReturn = 2; //NG
  4641. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4642. stopwatch2.Stop();
  4643. AddMessage_Station(stationNameStr, LogType.Info,
  4644. stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  4645. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4646. return;
  4647. }
  4648. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a50EEVehicleCode))
  4649. {
  4650. stopwatch2.Start();
  4651. //写入PLC
  4652. iot_data.beatReturn = 2; //NG
  4653. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4654. stopwatch2.Stop();
  4655. AddMessage_Station(stationNameStr, LogType.Info,
  4656. stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  4657. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4658. return;
  4659. }
  4660. short _result = 0;
  4661. // 上传OEE
  4662. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a40EEPartNo, a50EEVehicleCode);
  4663. _result = result.Item1;
  4664. resultStr = result.Item2;
  4665. if (_result == 1)
  4666. {
  4667. stopwatch2.Start();
  4668. //写入PLC
  4669. iot_data.beatReturn = 1; //OK
  4670. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4671. OnMessage(LogType.Info,
  4672. $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  4673. stopwatch2.Stop();
  4674. }
  4675. else
  4676. {
  4677. stopwatch2.Start();
  4678. //写入PLC
  4679. iot_data.beatReturn = 2; //NG
  4680. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4681. stopwatch2.Stop();
  4682. AddMessage_Station(stationNameStr, LogType.Error,
  4683. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  4684. }
  4685. }
  4686. catch (Exception ex)
  4687. {
  4688. string str = ex.StackTrace;
  4689. AddMessage_Station(stationNameStr, LogType.Error,
  4690. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  4691. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4692. // MES_Flag
  4693. stopwatch2.Start();
  4694. //写入PLC
  4695. iot_data.beatReturn = 2; //NG
  4696. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4697. stopwatch2.Stop();
  4698. }
  4699. stopwatch1.Stop();
  4700. AddMessage(LogType.Info,
  4701. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4702. stopwatch2.ElapsedMilliseconds + "ms");
  4703. }
  4704. #endregion
  4705. #region S5
  4706. private static bool isPCBStation = false;//控制PCB是否进出站的标识
  4707. /// <summary>
  4708. /// [S5] 点胶检测设备
  4709. /// </summary>
  4710. /// <param name="plcNo">PLC编号</param>
  4711. private void ReadStation_S5(int plcNo)
  4712. {
  4713. string stationCode = "[OP50]";
  4714. string stationName = "ADD板上料组装装备";
  4715. string stationNameStr = stationCode + stationName;
  4716. string tagBaseName = "g_OP50_MES"; //标签变量名称
  4717. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4718. string tagAgvCommName = "agvCommFrmPC";
  4719. string tagiotComnName = "iotData";
  4720. string tagBarsetName = "BarcodeSet";
  4721. string pcbBarcode = "";
  4722. string pcbBarcodeOld = "";
  4723. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  4724. string CarrierBarcode = "";
  4725. // 触发信号字典
  4726. s5PLCSignal_Old.Add("a5OEEType", 0); // 节拍类型(plc写入)
  4727. // PLC数据字典 赋值
  4728. s5PLCData.Add("a5OEEType", 0); // 节拍类型(plc写入)
  4729. (int, string) result;
  4730. while (true)
  4731. {
  4732. try
  4733. {
  4734. if (!GlobalContext._IsCon_Funs1)
  4735. {
  4736. UpdatePLCMonitor(1, plcNo, 0);
  4737. continue;
  4738. }
  4739. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4740. {
  4741. Stopwatch stopwatch1 = new Stopwatch();
  4742. Stopwatch stopwatch2 = new Stopwatch();
  4743. stopwatch1.Start();
  4744. stopwatch2.Start();
  4745. //测试数据
  4746. //stPLC_MesData.mesCommFrmPLC.cmd = 2;
  4747. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
  4748. //stPLC_MesData.BarcodeSet.strPCBBarcode = "A1507V000239";
  4749. //stPLC_MesData.iotData.BeatAction = 1;
  4750. #region 一次性读取所有数据
  4751. // 一次性读取所有数据
  4752. result = FunsEip[plcNo]
  4753. .Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4754. if (result.Item1 != 0)
  4755. {
  4756. }
  4757. else
  4758. {
  4759. stPLC_MesData.BarcodeSet.strPCBBarcode = "A1507V000239\r";
  4760. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
  4761. #region 去除扫码产生的特殊字符
  4762. stPLC_MesData.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  4763. stPLC_MesData.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  4764. stPLC_MesData.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  4765. stPLC_MesData.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  4766. #endregion
  4767. //richTextBox1.AppendText("\n" + "读取成功");
  4768. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  4769. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  4770. ? XiaomiDeviceState.Unknown
  4771. : (XiaomiDeviceState)xmDeviceStateInt;
  4772. // 节拍
  4773. s5PLCData["a5OEEType"] = stPLC_MesData.iotData.BeatAction;
  4774. //载具码
  4775. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode.ToString();
  4776. //报警信息
  4777. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  4778. }
  4779. #endregion 一次性读取所有数据
  4780. stopwatch2.Stop();
  4781. #region 进站
  4782. try
  4783. {
  4784. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4785. {
  4786. lock (lockObj)
  4787. {
  4788. if (!ProgressState)
  4789. {
  4790. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  4791. ProgressState = true;
  4792. string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
  4793. if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
  4794. {
  4795. ProgressState = true;
  4796. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  4797. }
  4798. }
  4799. }
  4800. }
  4801. }
  4802. catch (Exception ex)
  4803. {
  4804. ProgressState = false;
  4805. string str = ex.StackTrace;
  4806. AddMessage_Station(stationNameStr, LogType.Error,
  4807. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4808. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4809. }
  4810. #endregion 进站
  4811. #region 出站
  4812. try
  4813. {
  4814. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4815. {
  4816. lock (lockObj)
  4817. {
  4818. if (!ProgressState)
  4819. {
  4820. ProgressState = true;
  4821. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData,
  4822. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4823. out ProgressState));
  4824. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4825. uuid = "";
  4826. }
  4827. }
  4828. }
  4829. }
  4830. catch (Exception ex)
  4831. {
  4832. ProgressState = false;
  4833. string str = ex.StackTrace;
  4834. AddMessage_Station(stationNameStr, LogType.Error,
  4835. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4836. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4837. }
  4838. #endregion 出站
  4839. #region 节拍接口
  4840. try
  4841. {
  4842. if (stPLC_MesData.iotData.BeatAction > 0)
  4843. {
  4844. int a5OEEType = Convert.ToInt32(s5PLCData["a5OEEType"]);
  4845. int a5OEETypeGOld = Convert.ToInt32(s5PLCSignal_Old["a5OEEType"]);
  4846. //若设备紧急复原后节拍重置
  4847. if (a5OEEType == 1)
  4848. {
  4849. a5OEETypeGOld = 0;
  4850. }
  4851. if (a5OEEType != a5OEETypeGOld)
  4852. {
  4853. //如果上位机告诉PLC NG,PLC节拍会直接从1跳到4
  4854. if (a5OEETypeGOld <= 2 && a5OEEType == 4)
  4855. {
  4856. Task.Run(() =>
  4857. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  4858. CarrierBarcode,
  4859. stPLC_MesData.iotData));
  4860. }
  4861. else
  4862. {
  4863. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  4864. if ((a5OEETypeGOld == 1 && a5OEEType != 2) ||
  4865. (a5OEETypeGOld == 3 && a5OEEType != 4) ||
  4866. (a5OEETypeGOld == 5 && a5OEEType != 6))
  4867. {
  4868. //写入PLC
  4869. IoT_DataSet_t iotData = new IoT_DataSet_t();
  4870. iotData.machineState = stPLC_MesData.iotData.machineState;
  4871. iotData.work_type = stPLC_MesData.iotData.work_type;
  4872. iotData.testStatus = stPLC_MesData.iotData.testStatus;
  4873. iotData.BeatAction = stPLC_MesData.iotData.BeatAction;
  4874. iotData.beatReturn = 2; //NG
  4875. iotData.fault_codes = stPLC_MesData.iotData.fault_codes;
  4876. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  4877. 1, iotData);
  4878. AddMessage(LogType.Info,
  4879. stationNameStr +
  4880. $"_节拍接口-- 设备本次上传节拍[{a5OEEType}],未上传节拍[{a5OEETypeGOld}]的结束信号,请检查;总用时" +
  4881. stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4882. stopwatch2.ElapsedMilliseconds +
  4883. "ms");
  4884. return;
  4885. }
  4886. else
  4887. {
  4888. Task.Run(() => 通用节拍接口(plcNo, stationNameStr,
  4889. tagBaseName + "." + tagiotComnName, CarrierBarcode,
  4890. stPLC_MesData.iotData));
  4891. }
  4892. }
  4893. }
  4894. }
  4895. s5PLCSignal_Old["a5OEEType"] = s5PLCData["a5OEEType"];
  4896. }
  4897. catch (Exception ex)
  4898. {
  4899. string str = ex.StackTrace;
  4900. AddMessage_Station(stationNameStr, LogType.Error,
  4901. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4902. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4903. }
  4904. #endregion
  4905. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4906. stopwatch1.Stop();
  4907. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4908. }
  4909. else
  4910. {
  4911. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4912. AddMessage_Station(stationNameStr, LogType.Info,
  4913. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4914. FunsEip[plcNo].Connect(); // 重连
  4915. }
  4916. }
  4917. catch (Exception ex)
  4918. {
  4919. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4920. AddMessage_Station(stationNameStr, LogType.Error,
  4921. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4922. }
  4923. Thread.Sleep(IntervalReadPLC);
  4924. }
  4925. }
  4926. /// <summary>
  4927. /// [S5] 点胶检测设备 - 进站
  4928. /// </summary>
  4929. /// <param name="plcNo">PLC编号</param>
  4930. /// <param name="stationNameStr">工站全称</param>
  4931. /// <param name="stPLC_MesData"></param>
  4932. /// <param name="tagMesCommName"></param>
  4933. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  4934. string tagBarsetName, out bool ProgressState)
  4935. {
  4936. Stopwatch stopwatch1 = new Stopwatch();
  4937. Stopwatch stopwatch2 = new Stopwatch();
  4938. try
  4939. {
  4940. stopwatch1.Start();
  4941. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4942. //string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4943. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  4944. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  4945. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  4946. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码
  4947. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  4948. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4949. bool pass = a1Result == 1;
  4950. AddMessage(LogType.Info, $"ADD板编码(PCB码):{pcbBarcode}");
  4951. //绑定载具和产品
  4952. ResponseMessage message = new ResponseMessage();
  4953. message = SQLHelper.PCBCarrierBind(strCarrierBarcode, pcbBarcode);
  4954. if (message.result == false)
  4955. {
  4956. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  4957. }
  4958. //载具码验证产品码 //载具码验证产品码
  4959. //string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4960. //if (string.IsNullOrEmpty(strProductBarcode))
  4961. //{
  4962. // AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4963. //}
  4964. //sn = strProductBarcode;
  4965. //AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4966. // 产品SN(物料码)校验
  4967. List<TestItem> item = new List<TestItem>();
  4968. stopwatch2.Start();
  4969. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  4970. item, MachineId, StationId, pass, "01-SLOT-01");
  4971. stopwatch2.Stop();
  4972. //指令执行结果 1:OK 110:失败
  4973. byte mesResultFrmWeb = (byte)(result == 1 ? 2 : 120);
  4974. if (mesResultFrmWeb == 1)
  4975. {
  4976. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  4977. }
  4978. //进站结果写入PLC
  4979. CommandFromPLC resultToPlC = new CommandFromPLC();
  4980. resultToPlC.cmd = 0;
  4981. resultToPlC.cmdParam = 0; //指令参数
  4982. resultToPlC.cmdResult = mesResultFrmWeb;
  4983. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4984. }
  4985. catch (Exception ex)
  4986. {
  4987. string str = ex.StackTrace;
  4988. AddMessage(LogType.Error,
  4989. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4990. str.Length - str.LastIndexOf("\\") - 1));
  4991. CommandFromPLC resultToPlC = new CommandFromPLC();
  4992. resultToPlC.cmd = 0;
  4993. resultToPlC.cmdParam = 0; //指令参数
  4994. resultToPlC.cmdResult = 110;
  4995. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4996. }
  4997. stopwatch1.Stop();
  4998. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4999. AddMessage(LogType.Info,
  5000. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5001. stopwatch2.ElapsedMilliseconds + "ms");
  5002. ProgressState = false;
  5003. }
  5004. /// <summary>
  5005. /// [S5] 点胶检测设备 - 出站接口
  5006. /// </summary>
  5007. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  5008. string stationCode, string stationName, out bool ProgressState)
  5009. {
  5010. Stopwatch stopwatch1 = new Stopwatch();
  5011. Stopwatch stopwatch2 = new Stopwatch();
  5012. test_item_num = 0; //iot 过站明细序号
  5013. try
  5014. {
  5015. stopwatch1.Start();
  5016. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  5017. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5018. string processItem = stationName; // 测试项目
  5019. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5020. string supplierCode = ""; // 供应商代码
  5021. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5022. string batch_num = GlobalContext.BatchNumber; // 批次号
  5023. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5024. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5025. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 部件条码;
  5026. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5027. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  5028. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  5029. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  5030. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5031. bool pass = a1Result == 1;
  5032. CommandFromPLC resultToPlC = new CommandFromPLC();
  5033. //根据载具码获取产品码
  5034. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5035. if (string.IsNullOrEmpty(strProductBarcode))
  5036. {
  5037. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5038. ProgressState=false;
  5039. //写入PLC
  5040. resultToPlC.cmd = 0;
  5041. resultToPlC.cmdParam = 0; //指令参数
  5042. resultToPlC.cmdResult = 110;
  5043. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5044. return;
  5045. }
  5046. stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
  5047. sn = strProductBarcode;
  5048. //数据库绑定载具和PCB
  5049. ResponseMessage message = new ResponseMessage();
  5050. message = SQLHelper.PCBCarrierBind(CarrierBarcode, pcbBarcode);
  5051. if (message.result == false)
  5052. {
  5053. AddMessage(LogType.Error, stationNameStr + "_PCB码数据库绑定失败,错误:" + message.text);
  5054. ProgressState = true;//防止循环报错
  5055. return;
  5056. }
  5057. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn};PCB码:{pcbBarcode}");
  5058. List<TestItem> items = new List<TestItem>();
  5059. items.Add(new TestItem()
  5060. {
  5061. Parameter_name = "载具码",
  5062. Parameter_value = CarrierBarcode,
  5063. Parameter_unit = ""
  5064. });
  5065. items.Add(new TestItem()
  5066. {
  5067. Parameter_name = "产品码",
  5068. Parameter_value = sn,
  5069. Parameter_unit = ""
  5070. });
  5071. items.Add(new TestItem()
  5072. {
  5073. Parameter_name = "PCB码",
  5074. Parameter_value = pcbBarcode,
  5075. Parameter_unit = ""
  5076. });
  5077. #region 上传图片
  5078. if (GlobalContext.MQTTIsSendUpFile)
  5079. {
  5080. string[] urlarry = GlobalContext.UpFilePath.Split(",");
  5081. fileUploadData.fileData.Clear();
  5082. foreach (var item in urlarry)
  5083. {
  5084. if (!string.IsNullOrEmpty(item))
  5085. {
  5086. //上传图片
  5087. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName, a1Result,
  5088. item, uuid).Result;
  5089. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  5090. }
  5091. }
  5092. }
  5093. #endregion
  5094. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  5095. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  5096. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  5097. MachineId, StationId, PartBarcode, paramJson);
  5098. int result1 = 0;
  5099. byte mesResultFrmWeb = 0;
  5100. if (stPLC_MesData.mesCommFrmPLC.cmdParam == 2) {
  5101. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num
  5102. , mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode, paramJson);
  5103. }
  5104. else if (stPLC_MesData.mesCommFrmPLC.cmdParam == 1) {
  5105. result1=PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  5106. }
  5107. mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5108. //进站结果写入PLC
  5109. resultToPlC.cmd = 0;
  5110. resultToPlC.cmdParam = 0; //指令参数
  5111. resultToPlC.cmdResult = mesResultFrmWeb;
  5112. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5113. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  5114. //保存PLC返回MES数据到本地
  5115. //ResponseMessage message = new ResponseMessage();
  5116. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  5117. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB, stPLC_MesData.mesData.nRemainCount, "");
  5118. if (message.result == false)
  5119. {
  5120. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  5121. }
  5122. //保存部件码信息
  5123. if (!string.IsNullOrEmpty(PartBarcode))
  5124. {
  5125. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  5126. if (message.result == false)
  5127. {
  5128. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  5129. }
  5130. }
  5131. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  5132. }
  5133. catch (Exception ex)
  5134. {
  5135. stopwatch2.Start();
  5136. CommandFromPLC resultToPlC = new CommandFromPLC();
  5137. resultToPlC.cmd = 0;
  5138. resultToPlC.cmdParam = 0; //指令参数
  5139. resultToPlC.cmdResult = 110;
  5140. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5141. stopwatch2.Stop();
  5142. string str = ex.StackTrace;
  5143. AddMessage(LogType.Error,
  5144. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5145. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5146. }
  5147. stopwatch1.Stop();
  5148. AddMessage(LogType.Info,
  5149. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5150. stopwatch2.ElapsedMilliseconds + "ms");
  5151. ProgressState = false;
  5152. }
  5153. private int S5_PCB进出站(OP50_MesData_t stPLC_MesData,int plcNo,string stationNameStr,string tagBaseName,string tagMesCommName) {
  5154. string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
  5155. if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
  5156. {
  5157. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  5158. stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
  5159. CommandFromPLC resultToPlC = new CommandFromPLC();
  5160. resultToPlC.cmd = 0;
  5161. resultToPlC.cmdParam = 0; //指令参数
  5162. if (GlobalContext.IsSendStationIn)
  5163. {
  5164. #region 进站
  5165. //int res1 = PCBStationInData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  5166. //if (res1 == 1)
  5167. //{
  5168. // resultToPlC.cmdResult = 2;//OK
  5169. // WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  5170. //}
  5171. //else
  5172. //{
  5173. // resultToPlC.cmdResult = 120;
  5174. // WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  5175. // return 2;
  5176. //}
  5177. #endregion
  5178. #region 出站
  5179. int res2 = PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  5180. if (res2 == 1)
  5181. {
  5182. resultToPlC.cmdResult = 2;//OK
  5183. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  5184. return 1;
  5185. }
  5186. else
  5187. {
  5188. resultToPlC.cmdResult = 120;
  5189. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  5190. return 2;
  5191. }
  5192. #endregion
  5193. }
  5194. else {
  5195. return 2;
  5196. }
  5197. }
  5198. else
  5199. {
  5200. return 2;
  5201. }
  5202. }
  5203. private void S5节拍接口(int plcNo, string stationNameStr, string tagMesCommName, string CarrierBarcode,
  5204. IoT_DataSet_t iot_data)
  5205. {
  5206. Stopwatch stopwatch1 = new Stopwatch();
  5207. Stopwatch stopwatch2 = new Stopwatch();
  5208. string resultStr = string.Empty;
  5209. try
  5210. {
  5211. stopwatch1.Start();
  5212. string oEEType = iot_data.BeatAction.ToString(); // 节拍类型(plc写入)
  5213. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode); //产品SN
  5214. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5215. if (!actionBool)
  5216. {
  5217. stopwatch2.Start();
  5218. //写入PLC
  5219. IoT_DataSet_t iotData = new IoT_DataSet_t();
  5220. iotData.machineState = iot_data.machineState;
  5221. iotData.work_type = iot_data.work_type;
  5222. iotData.testStatus = iot_data.testStatus;
  5223. iotData.BeatAction = iot_data.BeatAction;
  5224. iotData.beatReturn = 2; //NG
  5225. iotData.fault_codes = iot_data.fault_codes;
  5226. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  5227. stopwatch2.Stop();
  5228. AddMessage(LogType.Info,
  5229. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  5230. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5231. return;
  5232. }
  5233. //作业开始后要有物料和载具信息
  5234. if (string.IsNullOrEmpty(strProductBarcode) && string.IsNullOrEmpty(CarrierBarcode) &&
  5235. Convert.ToInt32(oEEType) > 2)
  5236. {
  5237. stopwatch2.Start();
  5238. //写入PLC
  5239. IoT_DataSet_t iotData = new IoT_DataSet_t();
  5240. iotData.machineState = iot_data.machineState;
  5241. iotData.work_type = iot_data.work_type;
  5242. iotData.testStatus = iot_data.testStatus;
  5243. iotData.BeatAction = iot_data.BeatAction;
  5244. iotData.beatReturn = 2; //NG
  5245. iotData.fault_codes = iot_data.fault_codes;
  5246. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  5247. stopwatch2.Stop();
  5248. AddMessage_Station(stationNameStr, LogType.Info,
  5249. stationNameStr + $"_[{CarrierBarcode}][{strProductBarcode}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  5250. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5251. return;
  5252. }
  5253. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(strProductBarcode))
  5254. {
  5255. stopwatch2.Start();
  5256. //写入PLC
  5257. IoT_DataSet_t iotData = new IoT_DataSet_t();
  5258. iotData.machineState = iot_data.machineState;
  5259. iotData.work_type = iot_data.work_type;
  5260. iotData.testStatus = iot_data.testStatus;
  5261. iotData.BeatAction = iot_data.BeatAction;
  5262. iotData.beatReturn = 2; //NG
  5263. iotData.fault_codes = iot_data.fault_codes;
  5264. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  5265. stopwatch2.Stop();
  5266. AddMessage_Station(stationNameStr, LogType.Info,
  5267. stationNameStr + $"_[{CarrierBarcode}]上传节拍失败!物料码不可为空;总用时" +
  5268. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5269. return;
  5270. }
  5271. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(CarrierBarcode))
  5272. {
  5273. stopwatch2.Start();
  5274. //写入PLC
  5275. IoT_DataSet_t iotData = new IoT_DataSet_t();
  5276. iotData.machineState = iot_data.machineState;
  5277. iotData.work_type = iot_data.work_type;
  5278. iotData.testStatus = iot_data.testStatus;
  5279. iotData.BeatAction = iot_data.BeatAction;
  5280. iotData.beatReturn = 2; //NG
  5281. iotData.fault_codes = iot_data.fault_codes;
  5282. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  5283. stopwatch2.Stop();
  5284. AddMessage_Station(stationNameStr, LogType.Info,
  5285. stationNameStr + $"_上传节拍失败!载具码不可为空;总用时" +
  5286. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5287. return;
  5288. }
  5289. short _result = 0;
  5290. // 上传OEE
  5291. (short, string) result =
  5292. SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  5293. _result = result.Item1;
  5294. resultStr = result.Item2;
  5295. if (_result == 1)
  5296. {
  5297. stopwatch2.Start();
  5298. //写入PLC
  5299. IoT_DataSet_t iotData = new IoT_DataSet_t();
  5300. iotData.machineState = iot_data.machineState;
  5301. iotData.work_type = iot_data.work_type;
  5302. iotData.testStatus = iot_data.testStatus;
  5303. iotData.BeatAction = iot_data.BeatAction;
  5304. iotData.beatReturn = 1; //OK
  5305. iotData.fault_codes = iot_data.fault_codes;
  5306. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  5307. OnMessage(LogType.Info,
  5308. $"PLC{plcNo}_{stationNameStr} 节拍{iotData.BeatAction}上传IOT成功!上传结果:" + resultStr);
  5309. stopwatch2.Stop();
  5310. }
  5311. else
  5312. {
  5313. stopwatch2.Start();
  5314. //写入PLC
  5315. IoT_DataSet_t iotData = new IoT_DataSet_t();
  5316. iotData.machineState = iot_data.machineState;
  5317. iotData.work_type = iot_data.work_type;
  5318. iotData.testStatus = iot_data.testStatus;
  5319. iotData.BeatAction = iot_data.BeatAction;
  5320. iotData.beatReturn = 2; //NG
  5321. iotData.fault_codes = iot_data.fault_codes;
  5322. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  5323. stopwatch2.Stop();
  5324. AddMessage_Station(stationNameStr, LogType.Error,
  5325. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  5326. }
  5327. }
  5328. catch (Exception ex)
  5329. {
  5330. string str = ex.StackTrace;
  5331. AddMessage_Station(stationNameStr, LogType.Error,
  5332. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  5333. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5334. // MES_Flag
  5335. stopwatch2.Start();
  5336. //写入PLC
  5337. IoT_DataSet_t iotData = new IoT_DataSet_t();
  5338. iotData.machineState = iot_data.machineState;
  5339. iotData.work_type = iot_data.work_type;
  5340. iotData.testStatus = iot_data.testStatus;
  5341. iotData.BeatAction = iot_data.BeatAction;
  5342. iotData.beatReturn = 2; //NG
  5343. iotData.fault_codes = iot_data.fault_codes;
  5344. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5345. stopwatch2.Stop();
  5346. }
  5347. stopwatch1.Stop();
  5348. AddMessage(LogType.Info,
  5349. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5350. stopwatch2.ElapsedMilliseconds + "ms");
  5351. }
  5352. #endregion
  5353. #region S6
  5354. private Dictionary<string, object> s6PLCData = new Dictionary<string, object>();
  5355. private Dictionary<string, object> s6PLCSignal_Old = new Dictionary<string, object>();
  5356. /// <summary>
  5357. /// [S6] 顶盖装配设备
  5358. /// </summary>
  5359. /// <param name="plcNo">PLC编号</param>
  5360. private void ReadStation_S6(int plcNo)
  5361. {
  5362. string stationCode = "[OP70]";
  5363. string stationName = "组上盖板";
  5364. string stationNameStr = stationCode + stationName;
  5365. string tagBaseName = "g_OP60_MES"; //标签变量名称
  5366. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5367. string tagAgvCommName = "agvCommFrmPC";
  5368. string tagiotComnName = "iotData";
  5369. string tagBarsetName = "BarcodeSet";
  5370. string CarrierBarcode = "";
  5371. // 触发信号字典
  5372. s6PLCSignal_Old.Add("a6OEEType", 0); // 节拍类型(plc写入)
  5373. // PLC数据字典 赋值
  5374. s6PLCData.Add("a6OEEType", 0); // 节拍类型(plc写入)
  5375. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  5376. (int, string) result;
  5377. while (true)
  5378. {
  5379. try
  5380. {
  5381. if (!GlobalContext._IsCon_Funs1)
  5382. {
  5383. UpdatePLCMonitor(1, plcNo, 0);
  5384. continue;
  5385. }
  5386. //弹出扫码框则停止循环
  5387. if (isNoStop)
  5388. {
  5389. Task.Delay(1000);
  5390. continue;
  5391. }
  5392. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5393. {
  5394. Stopwatch stopwatch1 = new Stopwatch();
  5395. Stopwatch stopwatch2 = new Stopwatch();
  5396. stopwatch1.Start();
  5397. stopwatch2.Start();
  5398. #region 一次性读取所有数据
  5399. // 一次性读取所有数据
  5400. result = FunsEip[plcNo]
  5401. .Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  5402. //测试
  5403. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
  5404. //stPLC_MesData.mesCommFrmPLC.cmd = 1;
  5405. if (result.Item1 != 0)
  5406. {
  5407. //richTextBox1.AppendText("\n" + strRet);
  5408. }
  5409. else
  5410. {
  5411. //去除扫码产生的特殊字符
  5412. stPLC_MesData.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  5413. stPLC_MesData.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  5414. stPLC_MesData.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  5415. stPLC_MesData.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  5416. //richTextBox1.AppendText("\n" + "读取成功");
  5417. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  5418. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  5419. ? XiaomiDeviceState.Unknown
  5420. : (XiaomiDeviceState)xmDeviceStateInt;
  5421. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  5422. s6PLCData["a6OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  5423. //报警信息
  5424. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  5425. }
  5426. #endregion 一次性读取所有数据
  5427. stopwatch2.Stop();
  5428. #region 进站
  5429. try
  5430. {
  5431. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5432. {
  5433. lock (lockObj)
  5434. {
  5435. if (!ProgressState)
  5436. {
  5437. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  5438. ProgressState = true;
  5439. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData,
  5440. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  5441. out ProgressState));
  5442. }
  5443. }
  5444. }
  5445. }
  5446. catch (Exception ex)
  5447. {
  5448. ProgressState = false;
  5449. string str = ex.StackTrace;
  5450. AddMessage_Station(stationNameStr, LogType.Error,
  5451. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5452. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5453. }
  5454. #endregion 进站
  5455. #region 出站
  5456. try
  5457. {
  5458. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5459. {
  5460. lock (lockObj)
  5461. {
  5462. if (!ProgressState)
  5463. {
  5464. ProgressState = true;
  5465. ;
  5466. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData,
  5467. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  5468. out ProgressState));
  5469. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  5470. uuid = "";
  5471. }
  5472. }
  5473. }
  5474. }
  5475. catch (Exception ex)
  5476. {
  5477. ProgressState = false;
  5478. string str = ex.StackTrace;
  5479. AddMessage_Station(stationNameStr, LogType.Error,
  5480. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5481. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5482. }
  5483. #endregion 出站
  5484. #region 节拍接口
  5485. try
  5486. {
  5487. if (stPLC_MesData.iotData.BeatAction > 0)
  5488. {
  5489. int a6OEEType = Convert.ToInt32(s6PLCData["a6OEEType"]);
  5490. int a6OEETypeGOld = Convert.ToInt32(s6PLCSignal_Old["a6OEEType"]);
  5491. //若设备紧急复原后节拍重置
  5492. if (a6OEEType == 1)
  5493. {
  5494. a6OEETypeGOld = 0;
  5495. }
  5496. if (a6OEEType != a6OEETypeGOld)
  5497. {
  5498. if (a6OEETypeGOld <= 2 && a6OEEType == 4)
  5499. {
  5500. Task.Run(() =>
  5501. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  5502. CarrierBarcode,
  5503. stPLC_MesData.iotData));
  5504. }
  5505. else
  5506. {
  5507. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  5508. if ((a6OEETypeGOld == 1 && a6OEEType != 2) ||
  5509. (a6OEETypeGOld == 3 && a6OEEType != 4) ||
  5510. (a6OEETypeGOld == 5 && a6OEEType != 6))
  5511. {
  5512. //写入PLC
  5513. stPLC_MesData.iotData.beatReturn = 2; //NG
  5514. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1,
  5515. stPLC_MesData.iotData);
  5516. AddMessage(LogType.Info,
  5517. stationNameStr +
  5518. $"_节拍接口-- 设备本次上传节拍[{a6OEEType}],未上传节拍[{a6OEETypeGOld}]的结束信号,请检查;总用时" +
  5519. stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5520. stopwatch2.ElapsedMilliseconds +
  5521. "ms");
  5522. return;
  5523. }
  5524. else
  5525. {
  5526. Task.Run(() =>
  5527. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  5528. CarrierBarcode,
  5529. stPLC_MesData.iotData));
  5530. //Task.Run(() =>
  5531. // S6节拍接口(plcNo, stationNameStr, tagBaseName,
  5532. // stPLC_MesData.iotData));
  5533. }
  5534. }
  5535. }
  5536. }
  5537. s6PLCSignal_Old["a6OEEType"] = s6PLCData["a6OEEType"];
  5538. }
  5539. catch (Exception ex)
  5540. {
  5541. string str = ex.StackTrace;
  5542. AddMessage_Station(stationNameStr, LogType.Error,
  5543. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  5544. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5545. }
  5546. #endregion
  5547. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5548. stopwatch1.Stop();
  5549. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5550. }
  5551. else
  5552. {
  5553. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5554. AddMessage_Station(stationNameStr, LogType.Info,
  5555. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5556. FunsEip[plcNo].Connect(); // 重连
  5557. }
  5558. }
  5559. catch (Exception ex)
  5560. {
  5561. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5562. AddMessage_Station(stationNameStr, LogType.Error,
  5563. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5564. }
  5565. Thread.Sleep(IntervalReadPLC);
  5566. }
  5567. }
  5568. /// <summary>
  5569. /// [S6] 顶盖装配设备 - 进站
  5570. /// </summary>
  5571. /// <param name="plcNo">PLC编号</param>
  5572. /// <param name="stationNameStr">工站全称</param>
  5573. /// <param name="stPLC_MesData"></param>
  5574. /// <param name="tagMesCommName"></param>
  5575. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  5576. string tagBarsetName, out bool ProgressState)
  5577. {
  5578. Stopwatch stopwatch1 = new Stopwatch();
  5579. Stopwatch stopwatch2 = new Stopwatch();
  5580. try
  5581. {
  5582. stopwatch1.Start();
  5583. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  5584. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5585. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  5586. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  5587. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5588. bool pass = a1Result == 1;
  5589. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  5590. //strCarrierBarcode = "N801A-003";
  5591. //载具码验证产品码
  5592. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  5593. string strPCBBarcode = SQLHelper.GetPCBBarcodeByCarrierCode(strCarrierBarcode);
  5594. if (string.IsNullOrEmpty(strProductBarcode))
  5595. {
  5596. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5597. }
  5598. sn = strProductBarcode;
  5599. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5600. if (OpenDailogFalg)
  5601. {
  5602. using (var dialog = new BandBarodeDialog())
  5603. {
  5604. dialog._CarrierBarcode = strCarrierBarcode;
  5605. dialog._ProductBarcode = sn;
  5606. dialog._PCBBarcode = strPCBBarcode;
  5607. var rs = dialog.ShowDialog();
  5608. if (rs == DialogResult.OK)
  5609. {
  5610. AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  5611. OpenDailogFalg = false; //关闭扫码
  5612. isNoStop = false;
  5613. }
  5614. else
  5615. {
  5616. ProgressState = false;
  5617. return;
  5618. }
  5619. }
  5620. }
  5621. // 产品SN(物料码)校验
  5622. List<TestItem> item = new List<TestItem>();
  5623. stopwatch2.Start();
  5624. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  5625. item, MachineId, StationId, pass, "01-SLOT-01");
  5626. stopwatch2.Stop();
  5627. //指令执行结果 1:OK 110:失败
  5628. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5629. if (mesResultFrmWeb == 1)
  5630. {
  5631. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  5632. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  5633. }
  5634. //进站结果写入PLC
  5635. CommandFromPLC resultToPlC = new CommandFromPLC();
  5636. resultToPlC.cmd = 0;
  5637. resultToPlC.cmdParam = 0; //指令参数
  5638. resultToPlC.cmdResult = mesResultFrmWeb;
  5639. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5640. }
  5641. catch (Exception ex)
  5642. {
  5643. string str = ex.StackTrace;
  5644. AddMessage(LogType.Error,
  5645. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  5646. str.Length - str.LastIndexOf("\\") - 1));
  5647. CommandFromPLC resultToPlC = new CommandFromPLC();
  5648. resultToPlC.cmd = 0;
  5649. resultToPlC.cmdParam = 0; //指令参数
  5650. resultToPlC.cmdResult = 110;
  5651. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5652. }
  5653. stopwatch1.Stop();
  5654. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  5655. AddMessage(LogType.Info,
  5656. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5657. stopwatch2.ElapsedMilliseconds + "ms");
  5658. ProgressState = false;
  5659. OpenDailogFalg = true; //开启下一个物料的扫码
  5660. }
  5661. /// <summary>
  5662. /// [S6] 顶盖装配设备 - 出站接口
  5663. /// </summary>
  5664. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  5665. string stationCode, string stationName, out bool ProgressState)
  5666. {
  5667. Stopwatch stopwatch1 = new Stopwatch();
  5668. Stopwatch stopwatch2 = new Stopwatch();
  5669. test_item_num = 0; //iot 过站明细序号
  5670. try
  5671. {
  5672. stopwatch1.Start();
  5673. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  5674. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5675. string processItem = stationName; // 测试项目
  5676. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5677. string supplierCode = ""; // 供应商代码
  5678. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5679. string batch_num = GlobalContext.BatchNumber; // 批次号
  5680. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5681. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5682. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5683. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  5684. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  5685. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5686. bool pass = a1Result == 1;
  5687. //根据载具码获取产品码
  5688. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5689. if (string.IsNullOrEmpty(strProductBarcode))
  5690. {
  5691. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5692. }
  5693. sn = strProductBarcode;
  5694. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  5695. List<TestItem> items = new List<TestItem>();
  5696. items.Add(new TestItem()
  5697. {
  5698. Parameter_name = "载具码",
  5699. Parameter_value = CarrierBarcode,
  5700. Parameter_unit = ""
  5701. });
  5702. items.Add(new TestItem()
  5703. {
  5704. Parameter_name = "产品码",
  5705. Parameter_value = sn,
  5706. Parameter_unit = ""
  5707. });
  5708. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  5709. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  5710. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  5711. MachineId, StationId, "", paramJson);
  5712. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5713. if (mesResultFrmWeb == 1)
  5714. {
  5715. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  5716. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  5717. }
  5718. stopwatch2.Start();
  5719. //进站结果写入PLC
  5720. CommandFromPLC resultToPlC = new CommandFromPLC();
  5721. resultToPlC.cmd = 0;
  5722. resultToPlC.cmdParam = 0; //指令参数
  5723. resultToPlC.cmdResult = mesResultFrmWeb;
  5724. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5725. stopwatch2.Stop();
  5726. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  5727. //保存PLC返回MES数据到本地
  5728. ResponseMessage message = new ResponseMessage();
  5729. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  5730. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  5731. if (message.result == false)
  5732. {
  5733. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  5734. }
  5735. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  5736. }
  5737. catch (Exception ex)
  5738. {
  5739. stopwatch2.Start();
  5740. CommandFromPLC resultToPlC = new CommandFromPLC();
  5741. resultToPlC.cmd = 0;
  5742. resultToPlC.cmdParam = 0; //指令参数
  5743. resultToPlC.cmdResult = 110;
  5744. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5745. stopwatch2.Stop();
  5746. string str = ex.StackTrace;
  5747. AddMessage(LogType.Error,
  5748. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5749. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5750. }
  5751. stopwatch1.Stop();
  5752. AddMessage(LogType.Info,
  5753. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5754. stopwatch2.ElapsedMilliseconds + "ms");
  5755. ProgressState = false;
  5756. }
  5757. private void S6节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  5758. {
  5759. Stopwatch stopwatch1 = new Stopwatch();
  5760. Stopwatch stopwatch2 = new Stopwatch();
  5761. string resultStr = string.Empty;
  5762. try
  5763. {
  5764. stopwatch1.Start();
  5765. string oEEType = ((int)s1PLCData["a6OEEType"]).ToString(); // 节拍类型(plc写入)
  5766. string a60EEPartNo = (string)s1PLCData["a60EEPartNo"]; // 物料码
  5767. a60EEPartNo = a60EEPartNo.Replace("\0", "");
  5768. string a60EEVehicleCode = (string)s1PLCData["a60EEVehicleCode"]; // 载具SN
  5769. a60EEVehicleCode = a60EEVehicleCode.Replace("\0", "");
  5770. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5771. if (!actionBool)
  5772. {
  5773. stopwatch2.Start();
  5774. //写入PLC
  5775. iot_data.beatReturn = 2; //NG
  5776. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5777. stopwatch2.Stop();
  5778. AddMessage(LogType.Info,
  5779. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  5780. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5781. return;
  5782. }
  5783. //作业开始后要有物料和载具信息
  5784. if (string.IsNullOrEmpty(a60EEPartNo) && string.IsNullOrEmpty(a60EEVehicleCode) &&
  5785. Convert.ToInt32(oEEType) > 2)
  5786. {
  5787. stopwatch2.Start();
  5788. //写入PLC
  5789. iot_data.beatReturn = 2; //NG
  5790. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5791. stopwatch2.Stop();
  5792. AddMessage_Station(stationNameStr, LogType.Info,
  5793. stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  5794. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5795. return;
  5796. }
  5797. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a60EEPartNo))
  5798. {
  5799. stopwatch2.Start();
  5800. //写入PLC
  5801. iot_data.beatReturn = 2; //NG
  5802. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5803. stopwatch2.Stop();
  5804. AddMessage_Station(stationNameStr, LogType.Info,
  5805. stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  5806. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5807. return;
  5808. }
  5809. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a60EEVehicleCode))
  5810. {
  5811. stopwatch2.Start();
  5812. //写入PLC
  5813. iot_data.beatReturn = 2; //NG
  5814. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5815. stopwatch2.Stop();
  5816. AddMessage_Station(stationNameStr, LogType.Info,
  5817. stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  5818. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5819. return;
  5820. }
  5821. short _result = 0;
  5822. // 上传OEE
  5823. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a60EEPartNo, a60EEVehicleCode);
  5824. _result = result.Item1;
  5825. resultStr = result.Item2;
  5826. if (_result == 1)
  5827. {
  5828. stopwatch2.Start();
  5829. //写入PLC
  5830. iot_data.beatReturn = 1; //OK
  5831. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5832. OnMessage(LogType.Info,
  5833. $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  5834. stopwatch2.Stop();
  5835. }
  5836. else
  5837. {
  5838. stopwatch2.Start();
  5839. //写入PLC
  5840. iot_data.beatReturn = 2; //NG
  5841. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5842. stopwatch2.Stop();
  5843. AddMessage_Station(stationNameStr, LogType.Error,
  5844. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  5845. }
  5846. }
  5847. catch (Exception ex)
  5848. {
  5849. string str = ex.StackTrace;
  5850. AddMessage_Station(stationNameStr, LogType.Error,
  5851. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  5852. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5853. // MES_Flag
  5854. stopwatch2.Start();
  5855. //写入PLC
  5856. iot_data.beatReturn = 2; //NG
  5857. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5858. stopwatch2.Stop();
  5859. }
  5860. stopwatch1.Stop();
  5861. AddMessage(LogType.Info,
  5862. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5863. stopwatch2.ElapsedMilliseconds + "ms");
  5864. }
  5865. #endregion
  5866. #region S7
  5867. private Dictionary<string, object> s7PLCSignal_Old = new Dictionary<string, object>();
  5868. private Dictionary<string, object> s7PLCData = new Dictionary<string, object>();
  5869. /// <summary>
  5870. /// [S7] 锁螺丝设备
  5871. /// </summary>
  5872. /// <param name="plcNo">PLC编号</param>
  5873. private void ReadStation_S7(int plcNo)
  5874. {
  5875. string stationCode = "[OP80]";
  5876. string stationName = "上盖板锁螺丝";
  5877. string stationNameStr = stationCode + stationName;
  5878. string tagBaseName = "g_OP70_MES"; //标签变量名称
  5879. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5880. string tagAgvCommName = "agvCommFrmPC";
  5881. string tagBarsetName = "BarcodeSet";
  5882. string tagiotComnName = "iotData";
  5883. string tagScrewDataset = "screwDataset";
  5884. string CarrierBarcode_Left = "";
  5885. string CarrierBarcode_Right = "";
  5886. s7PLCSignal_Old.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
  5887. s7PLCSignal_Old.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
  5888. // PLC数据字典 赋值
  5889. s7PLCData.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
  5890. s7PLCData.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
  5891. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  5892. (int, string) result;
  5893. AtlasScrew atlasScrewLeft = new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort,
  5894. 3000, 3000, "Left");
  5895. atlasScrewLeft.Initial();
  5896. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort,
  5897. 3000, 3000, "Right");
  5898. atlasScrewRight.Initial();
  5899. while (true)
  5900. {
  5901. try
  5902. {
  5903. if (!GlobalContext._IsCon_Funs1)
  5904. {
  5905. UpdatePLCMonitor(1, plcNo, 0);
  5906. continue;
  5907. }
  5908. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5909. {
  5910. Stopwatch stopwatch1 = new Stopwatch();
  5911. Stopwatch stopwatch2 = new Stopwatch();
  5912. stopwatch1.Start();
  5913. stopwatch2.Start();
  5914. #region 一次性读取所有数据
  5915. // 一次性读取所有数据
  5916. result = FunsEip[plcNo]
  5917. .Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  5918. if (result.Item1 != 0)
  5919. {
  5920. //richTextBox1.AppendText("\n" + strRet);
  5921. }
  5922. else
  5923. {
  5924. #region 去除扫码产生的特殊字符
  5925. stPLC_MesData.Left.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strProductBarcode);
  5926. stPLC_MesData.Left.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPartBarcode);
  5927. stPLC_MesData.Left.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strCarrierBarcode);
  5928. stPLC_MesData.Left.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPCBBarcode);
  5929. stPLC_MesData.Right.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strProductBarcode);
  5930. stPLC_MesData.Right.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPartBarcode);
  5931. stPLC_MesData.Right.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strCarrierBarcode);
  5932. stPLC_MesData.Right.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPCBBarcode);
  5933. #endregion
  5934. int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  5935. int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  5936. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  5937. ? XiaomiDeviceState.Unknown
  5938. : (XiaomiDeviceState)xmDeviceStateInt_L;
  5939. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  5940. ? XiaomiDeviceState.Unknown
  5941. : (XiaomiDeviceState)xmDeviceStateInt_R;
  5942. s7PLCData["a7OEEPartNo"] =
  5943. stPLC_MesData.Left.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  5944. // 载具SN
  5945. CarrierBarcode_Left = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode;
  5946. CarrierBarcode_Right = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode;
  5947. // 节拍
  5948. s7PLCData["a7OEEType"] = stPLC_MesData.Left.iotData.BeatAction;
  5949. s7PLCData["a7OEEType_right"] = stPLC_MesData.Right.iotData.BeatAction;
  5950. //报警信息
  5951. _FaultDatas = stPLC_MesData.Left.iotData.fault_codes;
  5952. _FaultDatas2 = stPLC_MesData.Right.iotData.fault_codes;
  5953. }
  5954. #endregion 一次性读取所有数据
  5955. stopwatch2.Stop();
  5956. #region 左边进站
  5957. try
  5958. {
  5959. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5960. {
  5961. lock (lockObj)
  5962. {
  5963. if (!ProgressState)
  5964. {
  5965. stationCode = "[OP81]";
  5966. stationName = "上盖板锁螺丝1";
  5967. stationNameStr = stationCode + stationName;
  5968. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  5969. ProgressState = true;
  5970. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left,
  5971. tagBaseName + ".Left." + tagMesCommName,
  5972. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState,
  5973. atlasScrewLeft));
  5974. }
  5975. }
  5976. }
  5977. }
  5978. catch (Exception ex)
  5979. {
  5980. ProgressState = false;
  5981. string str = ex.StackTrace;
  5982. AddMessage_Station(stationNameStr, LogType.Error,
  5983. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5984. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5985. }
  5986. #endregion 左边进站
  5987. #region 左边出站
  5988. try
  5989. {
  5990. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5991. {
  5992. lock (lockObj)
  5993. {
  5994. if (!ProgressState)
  5995. {
  5996. stationCode = "[OP81]";
  5997. stationName = "上盖板锁螺丝1";
  5998. stationNameStr = stationCode + stationName;
  5999. ProgressState = true;
  6000. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left,
  6001. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  6002. out ProgressState));
  6003. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  6004. uuid = "";
  6005. }
  6006. }
  6007. }
  6008. }
  6009. catch (Exception ex)
  6010. {
  6011. ProgressState = false;
  6012. string str = ex.StackTrace;
  6013. AddMessage_Station(stationNameStr, LogType.Error,
  6014. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6015. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6016. }
  6017. #endregion 左边出站
  6018. #region 右边进站
  6019. try
  6020. {
  6021. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  6022. {
  6023. lock (lockObj)
  6024. {
  6025. if (!ProgressState)
  6026. {
  6027. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  6028. stationCode = "[OP82]";
  6029. stationName = "上盖板锁螺丝2";
  6030. stationNameStr = stationCode + stationName;
  6031. ProgressState = true;
  6032. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right,
  6033. tagBaseName + ".Right." + tagMesCommName,
  6034. tagBaseName + ".Right" + tagBarsetName, "Right", out ProgressState,
  6035. atlasScrewRight));
  6036. }
  6037. }
  6038. }
  6039. }
  6040. catch (Exception ex)
  6041. {
  6042. ProgressState = false;
  6043. string str = ex.StackTrace;
  6044. AddMessage_Station(stationNameStr, LogType.Error,
  6045. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6046. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6047. }
  6048. #endregion 右边进站
  6049. #region 右边出站
  6050. try
  6051. {
  6052. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  6053. {
  6054. lock (lockObj)
  6055. {
  6056. if (!ProgressState)
  6057. {
  6058. stationCode = "[OP82]";
  6059. stationName = "上盖板锁螺丝2";
  6060. stationNameStr = stationCode + stationName;
  6061. ProgressState = true;
  6062. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right,
  6063. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  6064. out ProgressState));
  6065. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  6066. uuid = "";
  6067. }
  6068. }
  6069. }
  6070. }
  6071. catch (Exception ex)
  6072. {
  6073. ProgressState = false;
  6074. string str = ex.StackTrace;
  6075. AddMessage_Station(stationNameStr, LogType.Error,
  6076. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6077. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6078. }
  6079. #endregion 右边出站
  6080. #region 节拍接口
  6081. try
  6082. {
  6083. #region 左工位 节拍
  6084. if (stPLC_MesData.Left.iotData.BeatAction > 0)
  6085. {
  6086. stationCode = "[OP81]";
  6087. stationName = "上盖板锁螺丝1";
  6088. stationNameStr = stationCode + stationName;
  6089. int a7OEEType_left = Convert.ToInt32(s7PLCData["a7OEEType_left"]);
  6090. int a7OEETypeGOld_left = Convert.ToInt32(s7PLCSignal_Old["a7OEEType_left"]);
  6091. //若设备紧急复原后节拍重置
  6092. if (a7OEEType_left == 1)
  6093. {
  6094. a7OEETypeGOld_left = 0;
  6095. }
  6096. if (a7OEEType_left != a7OEETypeGOld_left)
  6097. {
  6098. //如果上位机告诉PLC NG,PLC节拍会直接从1跳到4
  6099. if (a7OEETypeGOld_left <= 2 && a7OEEType_left == 4)
  6100. {
  6101. Task.Run(() =>
  6102. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName,
  6103. CarrierBarcode_Left,
  6104. stPLC_MesData.Left.iotData));
  6105. }
  6106. else
  6107. {
  6108. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  6109. if ((a7OEETypeGOld_left == 1 && a7OEEType_left != 2) ||
  6110. (a7OEETypeGOld_left == 3 && a7OEEType_left != 4) ||
  6111. (a7OEETypeGOld_left == 5 && a7OEEType_left != 6))
  6112. {
  6113. //写入PLC
  6114. IoT_DataSet_t iotData = new IoT_DataSet_t();
  6115. iotData.machineState = stPLC_MesData.Left.iotData.machineState;
  6116. iotData.work_type = stPLC_MesData.Left.iotData.work_type;
  6117. iotData.testStatus = stPLC_MesData.Left.iotData.testStatus;
  6118. iotData.BeatAction = stPLC_MesData.Left.iotData.BeatAction;
  6119. iotData.beatReturn = 2; //NG
  6120. iotData.fault_codes = stPLC_MesData.Left.iotData.fault_codes;
  6121. WriteResultToPlc(plcNo, stationNameStr,
  6122. tagBaseName + ".Left." + tagiotComnName, 1, iotData);
  6123. AddMessage(LogType.Info,
  6124. stationNameStr +
  6125. $"_节拍接口-- 设备本次上传节拍[{a7OEEType_left}],未上传节拍[{a7OEETypeGOld_left}]的结束信号,请检查;总用时" +
  6126. stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6127. stopwatch2.ElapsedMilliseconds +
  6128. "ms");
  6129. return;
  6130. }
  6131. else
  6132. {
  6133. Task.Run(() =>
  6134. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName,
  6135. CarrierBarcode_Left,
  6136. stPLC_MesData.Left.iotData));
  6137. //Task.Run(() =>
  6138. // S7节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName,
  6139. // stPLC_MesData.Left.iotData));
  6140. }
  6141. }
  6142. }
  6143. }
  6144. s7PLCSignal_Old["a7OEEType_left"] = s7PLCData["a7OEEType_left"];
  6145. #endregion 左工位 节拍
  6146. #region 右工位 节拍
  6147. if (stPLC_MesData.Right.iotData.BeatAction > 0)
  6148. {
  6149. stationCode = "[OP82]";
  6150. stationName = "上盖板锁螺丝2";
  6151. stationNameStr = stationCode + stationName;
  6152. int a7OEEType_right = Convert.ToInt32(s7PLCData["a7OEEType_right"]);
  6153. int a7OEETypeGOld_right = Convert.ToInt32(s7PLCSignal_Old["a7OEEType_right"]);
  6154. //若设备紧急复原后节拍重置
  6155. if (a7OEEType_right == 1)
  6156. {
  6157. a7OEETypeGOld_right = 0;
  6158. }
  6159. if (a7OEEType_right != a7OEETypeGOld_right)
  6160. {
  6161. if (a7OEETypeGOld_right <= 2 && a7OEEType_right == 4)
  6162. {
  6163. Task.Run(() =>
  6164. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName,
  6165. CarrierBarcode_Right,
  6166. stPLC_MesData.Right.iotData));
  6167. }
  6168. else
  6169. {
  6170. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  6171. if ((a7OEETypeGOld_right == 1 && a7OEEType_right != 2) ||
  6172. (a7OEETypeGOld_right == 3 && a7OEEType_right != 4) ||
  6173. (a7OEETypeGOld_right == 5 && a7OEEType_right != 6))
  6174. {
  6175. //写入PLC
  6176. IoT_DataSet_t iotData = new IoT_DataSet_t();
  6177. iotData.machineState = stPLC_MesData.Left.iotData.machineState;
  6178. iotData.work_type = stPLC_MesData.Left.iotData.work_type;
  6179. iotData.testStatus = stPLC_MesData.Left.iotData.testStatus;
  6180. iotData.BeatAction = stPLC_MesData.Left.iotData.BeatAction;
  6181. iotData.beatReturn = 2; //NG
  6182. iotData.fault_codes = stPLC_MesData.Left.iotData.fault_codes;
  6183. WriteResultToPlc(plcNo, stationNameStr,
  6184. tagBaseName + ".Right." + tagiotComnName, 1, iotData);
  6185. AddMessage(LogType.Info,
  6186. stationNameStr +
  6187. $"_节拍接口-- 设备本次上传节拍[{a7OEEType_right}],未上传节拍[{a7OEETypeGOld_right}]的结束信号,请检查;总用时" +
  6188. stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6189. stopwatch2.ElapsedMilliseconds +
  6190. "ms");
  6191. return;
  6192. }
  6193. else
  6194. {
  6195. Task.Run(() =>
  6196. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName,
  6197. CarrierBarcode_Right,
  6198. stPLC_MesData.Right.iotData));
  6199. //Task.Run(() =>
  6200. // S7节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName,
  6201. // stPLC_MesData.Left.iotData));
  6202. }
  6203. }
  6204. }
  6205. }
  6206. s7PLCSignal_Old["a7OEEType_right"] = s7PLCData["a7OEEType_right"];
  6207. #endregion 右工位 节拍
  6208. }
  6209. catch (Exception ex)
  6210. {
  6211. string str = ex.StackTrace;
  6212. AddMessage_Station(stationNameStr, LogType.Error,
  6213. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  6214. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6215. }
  6216. #endregion
  6217. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6218. stopwatch1.Stop();
  6219. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6220. }
  6221. else
  6222. {
  6223. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6224. AddMessage_Station(stationNameStr, LogType.Info,
  6225. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6226. FunsEip[plcNo].Connect(); // 重连
  6227. }
  6228. }
  6229. catch (Exception ex)
  6230. {
  6231. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6232. AddMessage_Station(stationNameStr, LogType.Error,
  6233. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6234. }
  6235. Thread.Sleep(IntervalReadPLC);
  6236. }
  6237. }
  6238. /// <summary>
  6239. /// [S7] 锁螺丝设备 - 进站
  6240. /// </summary>
  6241. /// <param name="plcNo">PLC编号</param>
  6242. /// <param name="stationNameStr">工站全称</param>
  6243. /// <param name="stPLC_MesData"></param>
  6244. /// <param name="tagMesCommName"></param>
  6245. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  6246. string tagBarsetName, string direction, out bool ProgressState, AtlasScrew atlasScrew)
  6247. {
  6248. Stopwatch stopwatch1 = new Stopwatch();
  6249. Stopwatch stopwatch2 = new Stopwatch();
  6250. string atlasSn = string.Empty;
  6251. try
  6252. {
  6253. stopwatch1.Start();
  6254. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  6255. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  6256. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  6257. string StationId = string.Empty; // 工位ID(可配置)
  6258. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6259. bool pass = a1Result == 1;
  6260. if (direction == "Left")
  6261. {
  6262. StationId = GlobalContext.S7_StationId_1;
  6263. }
  6264. if (direction == "Right")
  6265. {
  6266. StationId = GlobalContext.S7_StationId_2;
  6267. }
  6268. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  6269. //载具码验证产品码
  6270. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  6271. if (string.IsNullOrEmpty(strProductBarcode))
  6272. {
  6273. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6274. }
  6275. sn = strProductBarcode;
  6276. atlasSn = strProductBarcode;
  6277. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  6278. string slot = "";
  6279. if (direction == "Left")
  6280. {
  6281. isCollectingFlagLeft = false; //采集螺丝数据结束
  6282. slot = "01-SLOT-01";
  6283. }
  6284. if (direction == "Right")
  6285. {
  6286. isCollectingFlagRight = false; //采集螺丝数据结束
  6287. slot = "01-SLOT-02";
  6288. }
  6289. // 产品SN(物料码)校验
  6290. List<TestItem> item = new List<TestItem>();
  6291. stopwatch2.Start();
  6292. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  6293. item, MachineId, StationId, pass, slot);
  6294. stopwatch2.Stop();
  6295. //指令执行结果 1:OK 110:失败
  6296. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  6297. if (mesResultFrmWeb == 1)
  6298. {
  6299. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  6300. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  6301. }
  6302. //进站结果写入PLC
  6303. CommandFromPLC resultToPlC = new CommandFromPLC();
  6304. resultToPlC.cmd = 0;
  6305. resultToPlC.cmdParam = 0; //指令参数
  6306. resultToPlC.cmdResult = mesResultFrmWeb;
  6307. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6308. }
  6309. catch (Exception ex)
  6310. {
  6311. string str = ex.StackTrace;
  6312. AddMessage(LogType.Error,
  6313. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  6314. str.Length - str.LastIndexOf("\\") - 1));
  6315. CommandFromPLC resultToPlC = new CommandFromPLC();
  6316. resultToPlC.cmd = 0;
  6317. resultToPlC.cmdParam = 0; //指令参数
  6318. resultToPlC.cmdResult = 110;
  6319. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6320. }
  6321. stopwatch1.Stop();
  6322. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  6323. AddMessage(LogType.Info,
  6324. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  6325. stopwatch2.ElapsedMilliseconds + "ms");
  6326. ProgressState = false;
  6327. //开始采集螺丝数据
  6328. if (direction == "Left")
  6329. {
  6330. isCollectingFlagLeft = true;
  6331. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  6332. }
  6333. if (direction == "Right")
  6334. {
  6335. isCollectingFlagRight = true;
  6336. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  6337. }
  6338. }
  6339. /// <summary>
  6340. /// [S7] 锁螺丝设备 - 出站
  6341. /// </summary>
  6342. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  6343. string stationCode, string stationName, string direction, out bool ProgressState)
  6344. {
  6345. Stopwatch stopwatch1 = new Stopwatch();
  6346. Stopwatch stopwatch2 = new Stopwatch();
  6347. test_item_num = 0; //iot 过站明细序号
  6348. try
  6349. {
  6350. stopwatch1.Start();
  6351. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  6352. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6353. string processItem = stationName; // 测试项目
  6354. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6355. string supplierCode = ""; // 供应商代码
  6356. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6357. string batch_num = GlobalContext.BatchNumber; // 批次号
  6358. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6359. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  6360. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  6361. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  6362. string StationId = string.Empty; // 工位ID(可配置)
  6363. if (direction == "Left")
  6364. {
  6365. StationId = GlobalContext.S7_StationId_1;
  6366. }
  6367. if (direction == "Right")
  6368. {
  6369. StationId = GlobalContext.S7_StationId_2;
  6370. }
  6371. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6372. //a1Result = 1;
  6373. bool pass = a1Result == 1;
  6374. //根据载具码获取产品码
  6375. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  6376. if (string.IsNullOrEmpty(strProductBarcode))
  6377. {
  6378. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6379. }
  6380. sn = strProductBarcode;
  6381. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  6382. List<TestItem> items = new List<TestItem>();
  6383. items.Add(new TestItem()
  6384. {
  6385. Parameter_name = "载具码",
  6386. Parameter_value = CarrierBarcode,
  6387. Parameter_unit = ""
  6388. });
  6389. items.Add(new TestItem()
  6390. {
  6391. Parameter_name = "产品码",
  6392. Parameter_value = sn,
  6393. Parameter_unit = ""
  6394. });
  6395. //if (direction == "Right")
  6396. //{
  6397. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  6398. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem, workorder_code,
  6399. batch_num, mtltmrk, plcDate_YMD, supplierCode
  6400. , sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  6401. //}
  6402. //if (direction == "Left")
  6403. //{
  6404. // isCollectingFlagLeft = false;//采集螺丝数据结束
  6405. //}
  6406. //if (direction == "Right")
  6407. //{
  6408. // isCollectingFlagRight = false;//采集螺丝数据结束
  6409. //}
  6410. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  6411. if (mesResultFrmWeb == 1)
  6412. {
  6413. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  6414. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  6415. }
  6416. stopwatch2.Start();
  6417. //进站结果写入PLC
  6418. CommandFromPLC resultToPlC = new CommandFromPLC();
  6419. resultToPlC.cmd = 0;
  6420. resultToPlC.cmdParam = 0; //指令参数
  6421. resultToPlC.cmdResult = mesResultFrmWeb;
  6422. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6423. stopwatch2.Stop();
  6424. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  6425. //保存PLC返回MES数据到本地
  6426. ResponseMessage message = new ResponseMessage();
  6427. if (direction == "Left")
  6428. {
  6429. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  6430. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  6431. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  6432. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  6433. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  6434. if (message.result == false)
  6435. {
  6436. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  6437. }
  6438. }
  6439. if (direction == "Right")
  6440. {
  6441. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  6442. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  6443. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  6444. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  6445. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  6446. if (message.result == false)
  6447. {
  6448. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  6449. }
  6450. }
  6451. //保存螺丝数据到txt
  6452. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes,
  6453. stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  6454. if (result.Item1 != 0)
  6455. {
  6456. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  6457. }
  6458. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_保存加工数据到本地成功");
  6459. }
  6460. catch (Exception ex)
  6461. {
  6462. stopwatch2.Start();
  6463. CommandFromPLC resultToPlC = new CommandFromPLC();
  6464. resultToPlC.cmd = 0;
  6465. resultToPlC.cmdParam = 0; //指令参数
  6466. resultToPlC.cmdResult = 110;
  6467. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6468. stopwatch2.Stop();
  6469. string str = ex.StackTrace;
  6470. AddMessage(LogType.Error,
  6471. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  6472. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6473. }
  6474. stopwatch1.Stop();
  6475. AddMessage(LogType.Info,
  6476. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6477. stopwatch2.ElapsedMilliseconds + "ms");
  6478. ProgressState = false;
  6479. }
  6480. private void S7节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  6481. {
  6482. Stopwatch stopwatch1 = new Stopwatch();
  6483. Stopwatch stopwatch2 = new Stopwatch();
  6484. string resultStr = string.Empty;
  6485. try
  6486. {
  6487. stopwatch1.Start();
  6488. string oEEType = ((int)s1PLCData["a7OEEType"]).ToString(); // 节拍类型(plc写入)
  6489. string a7OEEPartNo = (string)s1PLCData["a7OEEPartNo"]; // 物料码
  6490. a7OEEPartNo = a7OEEPartNo.Replace("\0", "");
  6491. string a7OEEVehicleCode = (string)s1PLCData["a7OEEVehicleCode"]; // 载具SN
  6492. a7OEEVehicleCode = a7OEEVehicleCode.Replace("\0", "");
  6493. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6494. if (!actionBool)
  6495. {
  6496. stopwatch2.Start();
  6497. //写入PLC
  6498. iot_data.beatReturn = 2; //NG
  6499. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6500. stopwatch2.Stop();
  6501. AddMessage(LogType.Info,
  6502. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  6503. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6504. return;
  6505. }
  6506. //作业开始后要有物料和载具信息
  6507. if (string.IsNullOrEmpty(a7OEEPartNo) && string.IsNullOrEmpty(a7OEEVehicleCode) &&
  6508. Convert.ToInt32(oEEType) > 2)
  6509. {
  6510. stopwatch2.Start();
  6511. //写入PLC
  6512. iot_data.beatReturn = 2; //NG
  6513. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6514. stopwatch2.Stop();
  6515. AddMessage_Station(stationNameStr, LogType.Info,
  6516. stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  6517. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6518. return;
  6519. }
  6520. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a7OEEPartNo))
  6521. {
  6522. stopwatch2.Start();
  6523. //写入PLC
  6524. iot_data.beatReturn = 2; //NG
  6525. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6526. stopwatch2.Stop();
  6527. AddMessage_Station(stationNameStr, LogType.Info,
  6528. stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  6529. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6530. return;
  6531. }
  6532. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a7OEEVehicleCode))
  6533. {
  6534. stopwatch2.Start();
  6535. //写入PLC
  6536. iot_data.beatReturn = 2; //NG
  6537. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6538. stopwatch2.Stop();
  6539. AddMessage_Station(stationNameStr, LogType.Info,
  6540. stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  6541. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6542. return;
  6543. }
  6544. short _result = 0;
  6545. // 上传OEE
  6546. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a7OEEPartNo, a7OEEVehicleCode);
  6547. _result = result.Item1;
  6548. resultStr = result.Item2;
  6549. if (_result == 1)
  6550. {
  6551. stopwatch2.Start();
  6552. //写入PLC
  6553. iot_data.beatReturn = 1; //OK
  6554. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6555. OnMessage(LogType.Info,
  6556. $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  6557. stopwatch2.Stop();
  6558. }
  6559. else
  6560. {
  6561. stopwatch2.Start();
  6562. //写入PLC
  6563. iot_data.beatReturn = 2; //NG
  6564. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6565. stopwatch2.Stop();
  6566. AddMessage_Station(stationNameStr, LogType.Error,
  6567. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  6568. }
  6569. }
  6570. catch (Exception ex)
  6571. {
  6572. string str = ex.StackTrace;
  6573. AddMessage_Station(stationNameStr, LogType.Error,
  6574. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  6575. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6576. // MES_Flag
  6577. stopwatch2.Start();
  6578. //写入PLC
  6579. iot_data.beatReturn = 2; //NG
  6580. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6581. stopwatch2.Stop();
  6582. }
  6583. stopwatch1.Stop();
  6584. AddMessage(LogType.Info,
  6585. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6586. stopwatch2.ElapsedMilliseconds + "ms");
  6587. }
  6588. #endregion
  6589. #region S8
  6590. private Dictionary<string, object> s8PLCData = new Dictionary<string, object>();
  6591. private Dictionary<string, object> s8PLCSignal_Old = new Dictionary<string, object>();
  6592. /// <summary>
  6593. /// [S8] 3D螺丝高度检测设备
  6594. /// </summary>
  6595. /// <param name="plcNo">PLC编号</param>
  6596. private void ReadStation_S8(int plcNo)
  6597. {
  6598. string stationCode = "[OP90]";
  6599. string stationName = "NG下料";
  6600. string stationNameStr = stationCode + stationName;
  6601. string tagBaseName = "g_OP80_MES"; //标签变量名称
  6602. string tagMesCommName = "mesCommToPC"; //标签变量名称
  6603. string tagAgvCommName = "agvCommFrmPC";
  6604. string tagiotComnName = "iotData";
  6605. string tagBarsetName = "BarcodeSet";
  6606. string CarrierBarcode = "";
  6607. // 触发信号字典
  6608. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6609. s8PLCSignal_Old.Add("a8OEEType", 0); // 节拍类型(plc写入)
  6610. // PLC数据字典 赋值
  6611. s8PLCData.Add("a8OEEType", 0); // 节拍类型(plc写入)
  6612. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  6613. (int, string) result;
  6614. while (true)
  6615. {
  6616. try
  6617. {
  6618. if (!GlobalContext._IsCon_Funs1)
  6619. {
  6620. UpdatePLCMonitor(1, plcNo, 0);
  6621. continue;
  6622. }
  6623. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  6624. {
  6625. Stopwatch stopwatch1 = new Stopwatch();
  6626. Stopwatch stopwatch2 = new Stopwatch();
  6627. stopwatch1.Start();
  6628. stopwatch2.Start();
  6629. #region 一次性读取所有数据
  6630. // 一次性读取所有数据
  6631. result = FunsEip[plcNo]
  6632. .Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  6633. if (result.Item1 != 0)
  6634. {
  6635. //richTextBox1.AppendText("\n" + strRet);
  6636. }
  6637. else
  6638. {
  6639. //去除扫码产生的特殊字符
  6640. stPLC_MesData.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  6641. stPLC_MesData.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  6642. stPLC_MesData.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  6643. stPLC_MesData.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  6644. }
  6645. #endregion 一次性读取所有数据
  6646. stopwatch2.Stop();
  6647. //richTextBox1.AppendText("\n" + "读取成功");
  6648. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  6649. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  6650. ? XiaomiDeviceState.Unknown
  6651. : (XiaomiDeviceState)xmDeviceStateInt;
  6652. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  6653. s8PLCData["a8OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  6654. //报警信息
  6655. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  6656. #endregion 一次性读取所有数据
  6657. stopwatch2.Stop();
  6658. #region 进站
  6659. try
  6660. {
  6661. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  6662. {
  6663. lock (lockObj)
  6664. {
  6665. if (!ProgressState)
  6666. {
  6667. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  6668. ProgressState = true;
  6669. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData,
  6670. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  6671. out ProgressState));
  6672. }
  6673. }
  6674. }
  6675. }
  6676. catch (Exception ex)
  6677. {
  6678. ProgressState = false;
  6679. string str = ex.StackTrace;
  6680. AddMessage_Station(stationNameStr, LogType.Error,
  6681. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6682. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6683. }
  6684. #endregion 进站
  6685. #region 出站
  6686. try
  6687. {
  6688. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  6689. {
  6690. lock (lockObj)
  6691. {
  6692. if (!ProgressState)
  6693. {
  6694. ProgressState = true;
  6695. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData,
  6696. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  6697. out ProgressState));
  6698. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  6699. uuid = "";
  6700. }
  6701. }
  6702. }
  6703. }
  6704. catch (Exception ex)
  6705. {
  6706. ProgressState = false;
  6707. string str = ex.StackTrace;
  6708. AddMessage_Station(stationNameStr, LogType.Error,
  6709. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6710. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6711. }
  6712. #endregion 出站
  6713. #region 节拍接口
  6714. try
  6715. {
  6716. int a8OEEType = Convert.ToInt32(s9PLCData["a8OEEType"]);
  6717. int a8OEETypeGOld = Convert.ToInt32(s9PLCSignal_Old["a8OEEType"]);
  6718. //若设备紧急复原后节拍重置
  6719. if (a8OEEType == 1)
  6720. {
  6721. a8OEETypeGOld = 0;
  6722. }
  6723. if (stPLC_MesData.iotData.BeatAction > 0)
  6724. {
  6725. if (a8OEEType != a8OEETypeGOld)
  6726. {
  6727. //如果上位机告诉PLC NG,PLC节拍会直接从1跳到4
  6728. if (a8OEETypeGOld <= 2 && a8OEEType == 4)
  6729. {
  6730. Task.Run(() =>
  6731. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  6732. CarrierBarcode,
  6733. stPLC_MesData.iotData));
  6734. }
  6735. else
  6736. {
  6737. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  6738. if ((a8OEETypeGOld == 1 && a8OEEType != 2) ||
  6739. (a8OEETypeGOld == 3 && a8OEEType != 4) ||
  6740. (a8OEETypeGOld == 5 && a8OEEType != 6))
  6741. {
  6742. //写入PLC
  6743. IoT_DataSet_t iotData = new IoT_DataSet_t();
  6744. iotData.machineState = stPLC_MesData.iotData.machineState;
  6745. iotData.work_type = stPLC_MesData.iotData.work_type;
  6746. iotData.testStatus = stPLC_MesData.iotData.testStatus;
  6747. iotData.BeatAction = stPLC_MesData.iotData.BeatAction;
  6748. iotData.beatReturn = 2; //NG
  6749. iotData.fault_codes = stPLC_MesData.iotData.fault_codes;
  6750. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  6751. 1, iotData);
  6752. AddMessage(LogType.Info,
  6753. stationNameStr +
  6754. $"_节拍接口-- 设备本次上传节拍[{a8OEEType}],未上传节拍[{a8OEETypeGOld}]的结束信号,请检查;总用时" +
  6755. stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6756. stopwatch2.ElapsedMilliseconds +
  6757. "ms");
  6758. return;
  6759. }
  6760. else
  6761. {
  6762. Task.Run(() =>
  6763. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  6764. CarrierBarcode,
  6765. stPLC_MesData.iotData));
  6766. //Task.Run(() =>
  6767. // S8节拍接口(plcNo, stationNameStr, tagBaseName,
  6768. // stPLC_MesData.iotData));
  6769. }
  6770. }
  6771. }
  6772. }
  6773. s8PLCSignal_Old["a8OEEType"] = s8PLCData["a8OEEType"];
  6774. }
  6775. catch (Exception ex)
  6776. {
  6777. string str = ex.StackTrace;
  6778. AddMessage_Station(stationNameStr, LogType.Error,
  6779. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  6780. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6781. }
  6782. #endregion
  6783. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6784. stopwatch1.Stop();
  6785. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6786. }
  6787. }
  6788. else
  6789. {
  6790. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6791. AddMessage_Station(stationNameStr, LogType.Info,
  6792. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6793. FunsEip[plcNo].Connect(); // 重连
  6794. }
  6795. }
  6796. catch (Exception ex)
  6797. {
  6798. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6799. AddMessage_Station(stationNameStr, LogType.Error,
  6800. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6801. }
  6802. Thread.Sleep(IntervalReadPLC);
  6803. }
  6804. }
  6805. /// <summary>
  6806. /// [S8] 3D螺丝高度检测设备 - 进站
  6807. /// </summary>
  6808. /// <param name="plcNo">PLC编号</param>
  6809. /// <param name="stationNameStr">工站全称</param>
  6810. /// <param name="stPLC_MesData"></param>
  6811. /// <param name="tagMesCommName"></param>
  6812. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  6813. string tagBarsetName, out bool ProgressState)
  6814. {
  6815. Stopwatch stopwatch1 = new Stopwatch();
  6816. Stopwatch stopwatch2 = new Stopwatch();
  6817. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6818. bool pass = a1Result == 1;
  6819. try
  6820. {
  6821. stopwatch1.Start();
  6822. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  6823. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  6824. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  6825. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  6826. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  6827. //载具码验证产品码
  6828. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  6829. if (string.IsNullOrEmpty(strProductBarcode))
  6830. {
  6831. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  6832. }
  6833. sn = strProductBarcode;
  6834. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  6835. // 产品SN(物料码)校验
  6836. List<TestItem> item = new List<TestItem>();
  6837. stopwatch2.Start();
  6838. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  6839. sn,
  6840. item, MachineId, StationId, pass, "01-SLOT-01");
  6841. stopwatch2.Stop();
  6842. //指令执行结果 1:OK 110:失败
  6843. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  6844. if (mesResultFrmWeb == 1)
  6845. {
  6846. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  6847. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  6848. }
  6849. //进站结果写入PLC
  6850. CommandFromPLC resultToPlC = new CommandFromPLC();
  6851. resultToPlC.cmd = 0;
  6852. resultToPlC.cmdParam = 0; //指令参数
  6853. resultToPlC.cmdResult = mesResultFrmWeb;
  6854. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6855. }
  6856. catch (Exception ex)
  6857. {
  6858. string str = ex.StackTrace;
  6859. AddMessage(LogType.Error,
  6860. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(
  6861. str.LastIndexOf("\\") + 1,
  6862. str.Length - str.LastIndexOf("\\") - 1));
  6863. CommandFromPLC resultToPlC = new CommandFromPLC();
  6864. resultToPlC.cmd = 0;
  6865. resultToPlC.cmdParam = 0; //指令参数
  6866. resultToPlC.cmdResult = 110;
  6867. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6868. }
  6869. stopwatch1.Stop();
  6870. AddMessage(LogType.Info,
  6871. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  6872. stopwatch2.ElapsedMilliseconds + "ms");
  6873. ProgressState = false;
  6874. }
  6875. /// <summary>
  6876. /// [S8] 3D螺丝高度检测设备 - 出站接口
  6877. /// </summary>
  6878. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  6879. string stationCode, string stationName, out bool ProgressState)
  6880. {
  6881. Stopwatch stopwatch1 = new Stopwatch();
  6882. Stopwatch stopwatch2 = new Stopwatch();
  6883. test_item_num = 0; //iot 过站明细序号
  6884. try
  6885. {
  6886. stopwatch1.Start();
  6887. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  6888. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6889. string processItem = stationName; // 测试项目
  6890. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6891. string supplierCode = ""; // 供应商代码
  6892. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6893. string batch_num = GlobalContext.BatchNumber; // 批次号
  6894. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6895. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  6896. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  6897. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  6898. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  6899. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6900. bool pass = a1Result == 1;
  6901. //根据载具码获取产品码
  6902. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  6903. if (string.IsNullOrEmpty(strProductBarcode))
  6904. {
  6905. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6906. }
  6907. sn = strProductBarcode;
  6908. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  6909. List<TestItem> items = new List<TestItem>();
  6910. items.Add(new TestItem()
  6911. {
  6912. Parameter_name = "载具码",
  6913. Parameter_value = CarrierBarcode,
  6914. Parameter_unit = ""
  6915. });
  6916. items.Add(new TestItem()
  6917. {
  6918. Parameter_name = "产品码",
  6919. Parameter_value = sn,
  6920. Parameter_unit = ""
  6921. });
  6922. #region 上传图片
  6923. if (GlobalContext.MQTTIsSendUpFile)
  6924. {
  6925. string[] urlarry = GlobalContext.UpFilePath.Split(",");
  6926. fileUploadData.fileData.Clear();
  6927. foreach (var item in urlarry)
  6928. {
  6929. if (!string.IsNullOrEmpty(item))
  6930. {
  6931. //上传图片
  6932. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName,
  6933. a1Result, item, uuid).Result;
  6934. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  6935. }
  6936. }
  6937. }
  6938. #endregion
  6939. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  6940. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6941. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  6942. MachineId, StationId, "", paramJson);
  6943. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  6944. if (mesResultFrmWeb == 1)
  6945. {
  6946. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  6947. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  6948. }
  6949. stopwatch2.Start();
  6950. //进站结果写入PLC
  6951. CommandFromPLC resultToPlC = new CommandFromPLC();
  6952. resultToPlC.cmd = 0;
  6953. resultToPlC.cmdParam = 0; //指令参数
  6954. resultToPlC.cmdResult = mesResultFrmWeb;
  6955. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6956. stopwatch2.Stop();
  6957. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  6958. //保存PLC返回MES数据到本地
  6959. ResponseMessage message = new ResponseMessage();
  6960. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  6961. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  6962. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  6963. if (message.result == false)
  6964. {
  6965. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  6966. }
  6967. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  6968. }
  6969. catch (Exception ex)
  6970. {
  6971. stopwatch2.Start();
  6972. CommandFromPLC resultToPlC = new CommandFromPLC();
  6973. resultToPlC.cmd = 0;
  6974. resultToPlC.cmdParam = 0; //指令参数
  6975. resultToPlC.cmdResult = 110;
  6976. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6977. stopwatch2.Stop();
  6978. string str = ex.StackTrace;
  6979. AddMessage(LogType.Error,
  6980. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  6981. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6982. }
  6983. stopwatch1.Stop();
  6984. AddMessage(LogType.Info,
  6985. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6986. stopwatch2.ElapsedMilliseconds + "ms");
  6987. ProgressState = false;
  6988. }
  6989. private void S8节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  6990. {
  6991. Stopwatch stopwatch1 = new Stopwatch();
  6992. Stopwatch stopwatch2 = new Stopwatch();
  6993. string resultStr = string.Empty;
  6994. try
  6995. {
  6996. stopwatch1.Start();
  6997. string oEEType = ((int)s1PLCData["a8OEEType"]).ToString(); // 节拍类型(plc写入)
  6998. string a80EEPartNo = (string)s1PLCData["a80EEPartNo"]; // 物料码
  6999. a80EEPartNo = a80EEPartNo.Replace("\0", "");
  7000. string a80EEVehicleCode = (string)s1PLCData["a80EEVehicleCode"]; // 载具SN
  7001. a80EEVehicleCode = a80EEVehicleCode.Replace("\0", "");
  7002. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7003. if (!actionBool)
  7004. {
  7005. stopwatch2.Start();
  7006. //写入PLC
  7007. iot_data.beatReturn = 2; //NG
  7008. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7009. stopwatch2.Stop();
  7010. AddMessage(LogType.Info,
  7011. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" +
  7012. stopwatch1.ElapsedMilliseconds +
  7013. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7014. return;
  7015. }
  7016. //作业开始后要有物料和载具信息
  7017. if (string.IsNullOrEmpty(a80EEPartNo) && string.IsNullOrEmpty(a80EEVehicleCode) &&
  7018. Convert.ToInt32(oEEType) > 2)
  7019. {
  7020. stopwatch2.Start();
  7021. //写入PLC
  7022. iot_data.beatReturn = 2; //NG
  7023. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7024. stopwatch2.Stop();
  7025. AddMessage_Station(stationNameStr, LogType.Info,
  7026. stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  7027. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7028. return;
  7029. }
  7030. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a80EEPartNo))
  7031. {
  7032. stopwatch2.Start();
  7033. //写入PLC
  7034. iot_data.beatReturn = 2; //NG
  7035. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7036. stopwatch2.Stop();
  7037. AddMessage_Station(stationNameStr, LogType.Info,
  7038. stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  7039. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7040. return;
  7041. }
  7042. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a80EEVehicleCode))
  7043. {
  7044. stopwatch2.Start();
  7045. //写入PLC
  7046. iot_data.beatReturn = 2; //NG
  7047. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7048. stopwatch2.Stop();
  7049. AddMessage_Station(stationNameStr, LogType.Info,
  7050. stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  7051. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7052. return;
  7053. }
  7054. short _result = 0;
  7055. // 上传OEE
  7056. (short, string) result =
  7057. SaveOEEData(plcNo, stationNameStr, deviceOEE, a80EEPartNo, a80EEVehicleCode);
  7058. _result = result.Item1;
  7059. resultStr = result.Item2;
  7060. if (_result == 1)
  7061. {
  7062. stopwatch2.Start();
  7063. //写入PLC
  7064. iot_data.beatReturn = 1; //OK
  7065. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7066. OnMessage(LogType.Info,
  7067. $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  7068. stopwatch2.Stop();
  7069. }
  7070. else
  7071. {
  7072. stopwatch2.Start();
  7073. //写入PLC
  7074. iot_data.beatReturn = 2; //NG
  7075. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7076. stopwatch2.Stop();
  7077. AddMessage_Station(stationNameStr, LogType.Error,
  7078. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  7079. }
  7080. }
  7081. catch (Exception ex)
  7082. {
  7083. string str = ex.StackTrace;
  7084. AddMessage_Station(stationNameStr, LogType.Error,
  7085. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  7086. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7087. // MES_Flag
  7088. stopwatch2.Start();
  7089. //写入PLC
  7090. iot_data.beatReturn = 2; //NG
  7091. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7092. stopwatch2.Stop();
  7093. }
  7094. stopwatch1.Stop();
  7095. AddMessage(LogType.Info,
  7096. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7097. stopwatch2.ElapsedMilliseconds + "ms");
  7098. }
  7099. #endregion
  7100. #region S9
  7101. private Dictionary<string, object> s9PLCData = new Dictionary<string, object>();
  7102. private Dictionary<string, object> s9PLCSignal_Old = new Dictionary<string, object>();
  7103. /// <summary>
  7104. /// [S9] 下料设备
  7105. /// </summary>
  7106. /// <param name="plcNo">PLC编号</param>
  7107. private void ReadStation_S9(int plcNo)
  7108. {
  7109. string stationCode = "[OP100]";
  7110. string stationName = "半成品下料";
  7111. string stationNameStr = stationCode + stationName;
  7112. string tagBaseName = "g_OP90_MES"; //标签变量名称
  7113. string tagMesCommName = "mesCommToPC"; //标签变量名称
  7114. string tagAgvCommName = "agvCommFrmPC";
  7115. string tagiotComnName = "iotData";
  7116. string tagBarsetName = "BarcodeSet";
  7117. string CarrierBarcode = "";
  7118. // 触发信号字典
  7119. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  7120. s9PLCSignal_Old.Add("a9OEEType", 0); // 节拍类型(plc写入)
  7121. // PLC数据字典 赋值
  7122. s9PLCData.Add("a9OEEType", 0); // 节拍类型(plc写入)
  7123. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  7124. (int, string) result;
  7125. while (true)
  7126. {
  7127. try
  7128. {
  7129. if (!GlobalContext._IsCon_Funs1)
  7130. {
  7131. UpdatePLCMonitor(1, plcNo, 0);
  7132. continue;
  7133. }
  7134. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  7135. {
  7136. Stopwatch stopwatch1 = new Stopwatch();
  7137. Stopwatch stopwatch2 = new Stopwatch();
  7138. stopwatch1.Start();
  7139. stopwatch2.Start();
  7140. #region 一次性读取所有数据
  7141. // 一次性读取所有数据
  7142. result = FunsEip[plcNo]
  7143. .Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  7144. if (result.Item1 != 0)
  7145. {
  7146. //richTextBox1.AppendText("\n" + strRet);
  7147. }
  7148. else
  7149. {
  7150. //去除扫码产生的特殊字符
  7151. stPLC_MesData.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  7152. stPLC_MesData.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  7153. stPLC_MesData.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  7154. stPLC_MesData.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  7155. //richTextBox1.AppendText("\n" + "读取成功");
  7156. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  7157. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  7158. ? XiaomiDeviceState.Unknown
  7159. : (XiaomiDeviceState)xmDeviceStateInt;
  7160. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  7161. s9PLCData["a9OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  7162. //报警信息
  7163. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  7164. }
  7165. #endregion 一次性读取所有数据
  7166. stopwatch2.Stop();
  7167. #region 进站
  7168. try
  7169. {
  7170. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  7171. {
  7172. lock (lockObj)
  7173. {
  7174. if (!ProgressState)
  7175. {
  7176. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  7177. ProgressState = true;
  7178. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData,
  7179. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  7180. out ProgressState));
  7181. }
  7182. }
  7183. }
  7184. }
  7185. catch (Exception ex)
  7186. {
  7187. ProgressState = false;
  7188. string str = ex.StackTrace;
  7189. AddMessage_Station(stationNameStr, LogType.Error,
  7190. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  7191. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7192. }
  7193. #endregion 进站
  7194. #region 出站
  7195. try
  7196. {
  7197. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  7198. {
  7199. lock (lockObj)
  7200. {
  7201. if (!ProgressState)
  7202. {
  7203. ProgressState = true;
  7204. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData,
  7205. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  7206. out ProgressState));
  7207. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  7208. uuid = "";
  7209. }
  7210. }
  7211. }
  7212. }
  7213. catch (Exception ex)
  7214. {
  7215. ProgressState = false;
  7216. string str = ex.StackTrace;
  7217. AddMessage_Station(stationNameStr, LogType.Error,
  7218. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  7219. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7220. }
  7221. #endregion 出站
  7222. #region 节拍接口
  7223. try
  7224. {
  7225. if (stPLC_MesData.iotData.BeatAction > 0)
  7226. {
  7227. int a9OEEType = Convert.ToInt32(s9PLCData["a9OEEType"]);
  7228. int a9OEETypeGOld = Convert.ToInt32(s9PLCSignal_Old["a9OEEType"]);
  7229. //若设备紧急复原后节拍重置
  7230. if (a9OEEType == 1)
  7231. {
  7232. a9OEETypeGOld = 0;
  7233. }
  7234. if (a9OEEType != a9OEETypeGOld)
  7235. {
  7236. //如果上位机告诉PLC NG,PLC节拍会直接从1跳到4
  7237. if (a9OEETypeGOld <= 2 && a9OEEType == 4)
  7238. {
  7239. Task.Run(() =>
  7240. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  7241. CarrierBarcode,
  7242. stPLC_MesData.iotData));
  7243. }
  7244. else
  7245. {
  7246. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  7247. if ((a9OEETypeGOld == 1 && a9OEEType != 2) || (a9OEETypeGOld == 3 && a9OEEType != 4) ||
  7248. (a9OEETypeGOld == 5 && a9OEEType != 6))
  7249. {
  7250. //写入PLC
  7251. IoT_DataSet_t iotData = new IoT_DataSet_t();
  7252. iotData.machineState = stPLC_MesData.iotData.machineState;
  7253. iotData.work_type = stPLC_MesData.iotData.work_type;
  7254. iotData.testStatus = stPLC_MesData.iotData.testStatus;
  7255. iotData.BeatAction = stPLC_MesData.iotData.BeatAction;
  7256. iotData.beatReturn = 2; //NG
  7257. iotData.fault_codes = stPLC_MesData.iotData.fault_codes;
  7258. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  7259. 1, iotData);
  7260. AddMessage(LogType.Info,
  7261. stationNameStr +
  7262. $"_节拍接口-- 设备本次上传节拍[{a9OEEType}],未上传节拍[{a9OEETypeGOld}]的结束信号,请检查;总用时" +
  7263. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  7264. "ms");
  7265. return;
  7266. }
  7267. else
  7268. {
  7269. Task.Run(() =>
  7270. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  7271. CarrierBarcode,
  7272. stPLC_MesData.iotData));
  7273. //Task.Run(() =>
  7274. // S9节拍接口(plcNo, stationNameStr, tagBaseName,
  7275. // stPLC_MesData.iotData));
  7276. }
  7277. }
  7278. }
  7279. }
  7280. s9PLCSignal_Old["a9OEEType"] = s9PLCData["a9OEEType"];
  7281. }
  7282. catch (Exception ex)
  7283. {
  7284. string str = ex.StackTrace;
  7285. AddMessage_Station(stationNameStr, LogType.Error,
  7286. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  7287. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7288. }
  7289. #endregion
  7290. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7291. stopwatch1.Stop();
  7292. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7293. }
  7294. else
  7295. {
  7296. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7297. AddMessage_Station(stationNameStr, LogType.Info,
  7298. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  7299. FunsEip[plcNo].Connect(); // 重连
  7300. }
  7301. }
  7302. catch (Exception ex)
  7303. {
  7304. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7305. AddMessage_Station(stationNameStr, LogType.Error,
  7306. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  7307. }
  7308. Thread.Sleep(IntervalReadPLC);
  7309. }
  7310. }
  7311. /// <summary>
  7312. /// [S9] 下料设备 - 进站
  7313. /// </summary>
  7314. /// <param name="plcNo">PLC编号</param>
  7315. /// <param name="stationNameStr">工站全称</param>
  7316. /// <param name="stPLC_MesData"></param>
  7317. /// <param name="tagMesCommName"></param>
  7318. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  7319. string tagBarsetName, out bool ProgressState)
  7320. {
  7321. Stopwatch stopwatch1 = new Stopwatch();
  7322. Stopwatch stopwatch2 = new Stopwatch();
  7323. try
  7324. {
  7325. stopwatch1.Start();
  7326. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  7327. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  7328. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  7329. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  7330. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  7331. bool pass = a1Result == 1;
  7332. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  7333. //载具码验证产品码
  7334. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  7335. if (string.IsNullOrEmpty(strProductBarcode))
  7336. {
  7337. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  7338. }
  7339. sn = strProductBarcode;
  7340. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  7341. // 产品SN(物料码)校验
  7342. List<TestItem> item = new List<TestItem>();
  7343. stopwatch2.Start();
  7344. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  7345. item, MachineId, StationId, pass, "01-SLOT-01");
  7346. stopwatch2.Stop();
  7347. //指令执行结果 1:OK 110:失败
  7348. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  7349. if (mesResultFrmWeb == 1)
  7350. {
  7351. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  7352. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  7353. }
  7354. //进站结果写入PLC
  7355. CommandFromPLC resultToPlC = new CommandFromPLC();
  7356. resultToPlC.cmd = 0;
  7357. resultToPlC.cmdParam = 0; //指令参数
  7358. resultToPlC.cmdResult = mesResultFrmWeb;
  7359. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  7360. }
  7361. catch (Exception ex)
  7362. {
  7363. string str = ex.StackTrace;
  7364. AddMessage(LogType.Error,
  7365. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  7366. str.Length - str.LastIndexOf("\\") - 1));
  7367. CommandFromPLC resultToPlC = new CommandFromPLC();
  7368. resultToPlC.cmd = 0;
  7369. resultToPlC.cmdParam = 0; //指令参数
  7370. resultToPlC.cmdResult = 110;
  7371. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  7372. }
  7373. stopwatch1.Stop();
  7374. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  7375. AddMessage(LogType.Info,
  7376. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  7377. stopwatch2.ElapsedMilliseconds + "ms");
  7378. ProgressState = false;
  7379. }
  7380. /// <summary>
  7381. /// [S9] 下料设备 - 出站接口
  7382. /// </summary>
  7383. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  7384. string stationCode, string stationName, out bool ProgressState)
  7385. {
  7386. Stopwatch stopwatch1 = new Stopwatch();
  7387. Stopwatch stopwatch2 = new Stopwatch();
  7388. test_item_num = 0; //iot 过站明细序号
  7389. try
  7390. {
  7391. stopwatch1.Start();
  7392. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  7393. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7394. string processItem = stationName; // 测试项目
  7395. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7396. string supplierCode = ""; // 供应商代码
  7397. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7398. string batch_num = GlobalContext.BatchNumber; // 批次号
  7399. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7400. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  7401. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  7402. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  7403. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  7404. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  7405. bool pass = a1Result == 1;
  7406. //根据载具码获取产品码
  7407. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  7408. if (string.IsNullOrEmpty(strProductBarcode))
  7409. {
  7410. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  7411. }
  7412. sn = strProductBarcode;
  7413. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  7414. List<TestItem> items = new List<TestItem>();
  7415. items.Add(new TestItem()
  7416. {
  7417. Parameter_name = "载具码",
  7418. Parameter_value = CarrierBarcode,
  7419. Parameter_unit = ""
  7420. });
  7421. items.Add(new TestItem()
  7422. {
  7423. Parameter_name = "产品码",
  7424. Parameter_value = sn,
  7425. Parameter_unit = ""
  7426. });
  7427. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  7428. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  7429. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  7430. MachineId, StationId, "", paramJson);
  7431. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  7432. if (mesResultFrmWeb == 1)
  7433. {
  7434. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  7435. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  7436. }
  7437. stopwatch2.Start();
  7438. //进站结果写入PLC
  7439. CommandFromPLC resultToPlC = new CommandFromPLC();
  7440. resultToPlC.cmd = 0;
  7441. resultToPlC.cmdParam = 0; //指令参数
  7442. resultToPlC.cmdResult = mesResultFrmWeb;
  7443. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  7444. stopwatch2.Stop();
  7445. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  7446. //保存PLC返回MES数据到本地
  7447. ResponseMessage message = new ResponseMessage();
  7448. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  7449. stPLC_MesData.mesData.nRemainCount);
  7450. if (message.result == false)
  7451. {
  7452. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  7453. }
  7454. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  7455. if (result1 == 1)
  7456. {
  7457. //载具码解除绑定
  7458. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  7459. if (message.result == false)
  7460. {
  7461. AddMessage(LogType.Error, message.text);
  7462. }
  7463. }
  7464. }
  7465. catch (Exception ex)
  7466. {
  7467. stopwatch2.Start();
  7468. CommandFromPLC resultToPlC = new CommandFromPLC();
  7469. resultToPlC.cmd = 0;
  7470. resultToPlC.cmdParam = 0; //指令参数
  7471. resultToPlC.cmdResult = 110;
  7472. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  7473. stopwatch2.Stop();
  7474. string str = ex.StackTrace;
  7475. AddMessage(LogType.Error,
  7476. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  7477. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7478. }
  7479. stopwatch1.Stop();
  7480. AddMessage(LogType.Info,
  7481. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7482. stopwatch2.ElapsedMilliseconds + "ms");
  7483. ProgressState = false;
  7484. }
  7485. private void S9节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  7486. {
  7487. Stopwatch stopwatch1 = new Stopwatch();
  7488. Stopwatch stopwatch2 = new Stopwatch();
  7489. string resultStr = string.Empty;
  7490. try
  7491. {
  7492. stopwatch1.Start();
  7493. string oEEType = ((int)s1PLCData["a9OEEType"]).ToString(); // 节拍类型(plc写入)
  7494. string a90EEPartNo = (string)s1PLCData["a90EEPartNo"]; // 物料码
  7495. a90EEPartNo = a90EEPartNo.Replace("\0", "");
  7496. string a90EEVehicleCode = (string)s1PLCData["a90EEVehicleCode"]; // 载具SN
  7497. a90EEVehicleCode = a90EEVehicleCode.Replace("\0", "");
  7498. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7499. if (!actionBool)
  7500. {
  7501. stopwatch2.Start();
  7502. //写入PLC
  7503. iot_data.beatReturn = 2; //NG
  7504. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7505. stopwatch2.Stop();
  7506. AddMessage(LogType.Info,
  7507. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  7508. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7509. return;
  7510. }
  7511. //作业开始后要有物料和载具信息
  7512. if (string.IsNullOrEmpty(a90EEPartNo) && string.IsNullOrEmpty(a90EEVehicleCode) &&
  7513. Convert.ToInt32(oEEType) > 2)
  7514. {
  7515. stopwatch2.Start();
  7516. //写入PLC
  7517. iot_data.beatReturn = 2; //NG
  7518. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7519. stopwatch2.Stop();
  7520. AddMessage_Station(stationNameStr, LogType.Info,
  7521. stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  7522. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7523. return;
  7524. }
  7525. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a90EEPartNo))
  7526. {
  7527. stopwatch2.Start();
  7528. //写入PLC
  7529. iot_data.beatReturn = 2; //NG
  7530. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7531. stopwatch2.Stop();
  7532. AddMessage_Station(stationNameStr, LogType.Info,
  7533. stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  7534. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7535. return;
  7536. }
  7537. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a90EEVehicleCode))
  7538. {
  7539. stopwatch2.Start();
  7540. //写入PLC
  7541. iot_data.beatReturn = 2; //NG
  7542. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7543. stopwatch2.Stop();
  7544. AddMessage_Station(stationNameStr, LogType.Info,
  7545. stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  7546. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7547. return;
  7548. }
  7549. short _result = 0;
  7550. // 上传OEE
  7551. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a90EEPartNo, a90EEVehicleCode);
  7552. _result = result.Item1;
  7553. resultStr = result.Item2;
  7554. if (_result == 1)
  7555. {
  7556. stopwatch2.Start();
  7557. //写入PLC
  7558. iot_data.beatReturn = 1; //OK
  7559. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7560. OnMessage(LogType.Info,
  7561. $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  7562. stopwatch2.Stop();
  7563. }
  7564. else
  7565. {
  7566. stopwatch2.Start();
  7567. //写入PLC
  7568. iot_data.beatReturn = 2; //NG
  7569. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7570. stopwatch2.Stop();
  7571. AddMessage_Station(stationNameStr, LogType.Error,
  7572. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  7573. }
  7574. }
  7575. catch (Exception ex)
  7576. {
  7577. string str = ex.StackTrace;
  7578. AddMessage_Station(stationNameStr, LogType.Error,
  7579. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  7580. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7581. // MES_Flag
  7582. stopwatch2.Start();
  7583. //写入PLC
  7584. iot_data.beatReturn = 2; //NG
  7585. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7586. stopwatch2.Stop();
  7587. }
  7588. stopwatch1.Stop();
  7589. AddMessage(LogType.Info,
  7590. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7591. stopwatch2.ElapsedMilliseconds + "ms");
  7592. }
  7593. #endregion
  7594. #endregion Xiaomi
  7595. #region PLC1 张超凡
  7596. #region [S1] Tray盘上料装备(板测)
  7597. /// <summary>
  7598. /// S1工位的数据- 触发信号上次的值
  7599. /// </summary>
  7600. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  7601. /// <summary>
  7602. /// S1工位的数据(含触发信号)
  7603. /// </summary>
  7604. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  7605. /// <summary>
  7606. /// S1工位的数据- 回写点位
  7607. /// </summary>
  7608. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  7609. ///// <summary>
  7610. ///// 触发信号
  7611. ///// </summary>
  7612. //private ManualResetEvent[] MreTasks;
  7613. /// <summary>
  7614. /// [S1] Tray盘上料装备(板测)
  7615. /// </summary>
  7616. /// <param name="plcNo">PLC编号</param>
  7617. //private void ReadStation_S1(int plcNo)
  7618. //{
  7619. // // [S1] Tray盘上料装备
  7620. // // [S2] FCT
  7621. // // [S3] 值板机
  7622. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  7623. // // [S5] Tray盘下料装备
  7624. // string stationCode = "[S1]";
  7625. // string stationName = "Tray盘上料装备";
  7626. // string stationNameStr = stationCode + stationName;
  7627. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  7628. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  7629. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  7630. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  7631. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  7632. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  7633. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  7634. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  7635. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  7636. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  7637. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  7638. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  7639. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  7640. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  7641. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  7642. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  7643. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  7644. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  7645. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  7646. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  7647. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  7648. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  7649. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  7650. // s1PLCData.Add("a1Result", 0); // 产品结果
  7651. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  7652. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  7653. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  7654. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  7655. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  7656. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  7657. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  7658. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  7659. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  7660. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  7661. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  7662. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  7663. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  7664. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  7665. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  7666. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  7667. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  7668. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  7669. // while (IsRun)
  7670. // {
  7671. // try
  7672. // {
  7673. // if (!GlobalContext._IsCon_Funs1)
  7674. // {
  7675. // UpdatePLCMonitor(1, plcNo, 0);
  7676. // continue;
  7677. // }
  7678. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  7679. // {
  7680. // Stopwatch stopwatch1 = new Stopwatch();
  7681. // Stopwatch stopwatch2 = new Stopwatch();
  7682. // stopwatch1.Start();
  7683. // stopwatch2.Start();
  7684. // #region 一次性读取所有数据
  7685. // // 一次性读取所有数据
  7686. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  7687. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  7688. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  7689. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  7690. // int[] datas = data1.Concat(data2).ToArray();
  7691. // datas = datas.Concat(data3).ToArray();
  7692. // datas = datas.Concat(data4).ToArray();
  7693. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  7694. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  7695. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  7696. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  7697. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  7698. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  7699. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  7700. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  7701. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  7702. // s1PLCData["a1MES_FLAG"] = datas[109];
  7703. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  7704. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  7705. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  7706. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  7707. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  7708. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  7709. // s1PLCData["a1Result"] = datas[170];
  7710. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  7711. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  7712. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  7713. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  7714. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  7715. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  7716. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  7717. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  7718. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  7719. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  7720. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  7721. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  7722. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  7723. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  7724. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  7725. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  7726. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  7727. // s1PLCData["a1AGVUpStart"] = datas[308];
  7728. // s1PLCData["a1AGVUpEnd"] = datas[309];
  7729. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  7730. // s1PLCData["a1AGVDownStart"] = datas[321];
  7731. // s1PLCData["a1AGVDownEnd"] = datas[322];
  7732. // #endregion 一次性读取所有数据
  7733. // stopwatch2.Stop();
  7734. // #region 回写操作,写后清空flag
  7735. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  7736. // #endregion 回写操作,写后清空flag
  7737. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  7738. // try
  7739. // {
  7740. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  7741. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  7742. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  7743. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  7744. // {
  7745. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  7746. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  7747. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  7748. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  7749. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  7750. // }
  7751. // }
  7752. // catch (Exception ex)
  7753. // {
  7754. // // 6代表上位机报警
  7755. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  7756. // string str = ex.StackTrace;
  7757. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7758. // }
  7759. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  7760. // #region 上料进站校验
  7761. // try
  7762. // {
  7763. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  7764. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  7765. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  7766. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  7767. // {
  7768. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  7769. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  7770. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  7771. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  7772. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  7773. // }
  7774. // }
  7775. // catch (Exception ex)
  7776. // {
  7777. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7778. // string str = ex.StackTrace;
  7779. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7780. // }
  7781. // #endregion 上料进站校验
  7782. // #region Tray盘上料装备-出站接口
  7783. // try
  7784. // {
  7785. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  7786. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  7787. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  7788. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  7789. // {
  7790. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  7791. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  7792. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  7793. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  7794. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  7795. // }
  7796. // }
  7797. // catch (Exception ex)
  7798. // {
  7799. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  7800. // string str = ex.StackTrace;
  7801. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7802. // }
  7803. // #endregion Tray盘上料装备-出站接口
  7804. // #region Tray盘上料装备-将SN发给ICT标机
  7805. // try
  7806. // {
  7807. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  7808. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  7809. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  7810. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  7811. // {
  7812. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  7813. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  7814. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  7815. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  7816. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  7817. // }
  7818. // }
  7819. // catch (Exception ex)
  7820. // {
  7821. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  7822. // string str = ex.StackTrace;
  7823. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7824. // }
  7825. // #endregion Tray盘上料装备-将SN发给ICT标机
  7826. // #region Tray盘上料装备-点检数据
  7827. // //try
  7828. // //{
  7829. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  7830. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  7831. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  7832. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  7833. // // if (pLC_Flag && !mES_Flag) // 1 0
  7834. // // {
  7835. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  7836. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  7837. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  7838. // // }
  7839. // // else if (!pLC_Flag && mES_Flag) // 0 1
  7840. // // {
  7841. // // // 清空写给PLC的数据
  7842. // // // MES_Flag重置为0
  7843. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  7844. // // }
  7845. // //}
  7846. // //catch (Exception ex)
  7847. // //{
  7848. // // // MES_Flag 为2上位机报错
  7849. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  7850. // // string str = ex.StackTrace;
  7851. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7852. // //}
  7853. // #endregion Tray盘上料装备-点检数据
  7854. // #region 节拍接口
  7855. // try
  7856. // {
  7857. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  7858. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  7859. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  7860. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  7861. // {
  7862. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  7863. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7864. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  7865. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  7866. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  7867. // }
  7868. // }
  7869. // catch (Exception ex)
  7870. // {
  7871. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  7872. // string str = ex.StackTrace;
  7873. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7874. // }
  7875. // #endregion 节拍接口
  7876. // #region AGV上料
  7877. // // AGV上料叫AGV信号
  7878. // try
  7879. // {
  7880. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  7881. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  7882. // if (a1AGVUpCall != a1AGVUpCallOld)
  7883. // {
  7884. // if (a1AGVUpCall == 1) // 0->1
  7885. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  7886. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  7887. // }
  7888. // }
  7889. // catch (Exception ex)
  7890. // {
  7891. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  7892. // string str = ex.StackTrace;
  7893. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7894. // }
  7895. // // AGV上料完成信号
  7896. // try
  7897. // {
  7898. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  7899. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  7900. // if (a1AGVUpEnd != a1AGVUpEndOld)
  7901. // {
  7902. // if (a1AGVUpEnd == 1) // 0->1
  7903. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  7904. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  7905. // }
  7906. // }
  7907. // catch (Exception ex)
  7908. // {
  7909. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  7910. // string str = ex.StackTrace;
  7911. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7912. // }
  7913. // #endregion AGV上料
  7914. // #region AGV下料
  7915. // // AGV下料叫agv信号
  7916. // try
  7917. // {
  7918. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  7919. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  7920. // if (a1AGVDownCall != a1AGVDownCallOld)
  7921. // {
  7922. // if (a1AGVDownCall == 1) // 0->1
  7923. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  7924. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  7925. // }
  7926. // }
  7927. // catch (Exception ex)
  7928. // {
  7929. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  7930. // string str = ex.StackTrace;
  7931. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7932. // }
  7933. // // AGV下料完成信号
  7934. // try
  7935. // {
  7936. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  7937. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  7938. // if (a1AGVDownEnd != a1AGVDownEndOld)
  7939. // {
  7940. // if (a1AGVDownEnd == 1) // 0->1
  7941. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  7942. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  7943. // }
  7944. // }
  7945. // catch (Exception ex)
  7946. // {
  7947. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  7948. // string str = ex.StackTrace;
  7949. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7950. // }
  7951. // #endregion AGV下料
  7952. // #region 心跳
  7953. // try
  7954. // {
  7955. // short states = 0;
  7956. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7957. // }
  7958. // catch (Exception ex)
  7959. // {
  7960. // string str = ex.StackTrace;
  7961. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7962. // }
  7963. // #endregion 心跳
  7964. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7965. // stopwatch1.Stop();
  7966. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7967. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7968. // }
  7969. // else
  7970. // {
  7971. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7972. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  7973. // Funs[plcNo].Connect(); // 重连
  7974. // }
  7975. // }
  7976. // catch (Exception ex)
  7977. // {
  7978. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7979. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  7980. // Funs[plcNo].ReConnect();
  7981. // }
  7982. // Thread.Sleep(IntervalReadPLC);
  7983. // }
  7984. //}
  7985. /// <summary>
  7986. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  7987. /// </summary>
  7988. /// <param name="plcNo">PLC编号</param>
  7989. /// <param name="stationNameStr">工站全称</param>
  7990. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  7991. {
  7992. Stopwatch stopwatch1 = new Stopwatch();
  7993. Stopwatch stopwatch2 = new Stopwatch();
  7994. try
  7995. {
  7996. stopwatch1.Start();
  7997. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  7998. sn = sn.Replace("\0", "");
  7999. #region 查询载具上的产品信息
  8000. string cavityData = string.Empty;
  8001. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  8002. if (string.IsNullOrEmpty(cavityData))
  8003. cavityData = "";
  8004. if (snResult != 0)
  8005. {
  8006. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8007. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  8008. writeToPLC_Flag1.Adress = 2003;
  8009. writeToPLC_Flag1.Value = (short)6;
  8010. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  8011. stopwatch1.Stop();
  8012. AddMessage(LogType.Info,
  8013. stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8014. "ms");
  8015. return;
  8016. }
  8017. #endregion 查询载具上的产品信息
  8018. string[] cavitySNs = cavityData.Split('.');
  8019. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  8020. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  8021. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  8022. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  8023. if (cavitySNs != null && cavitySNs.Length >= 2)
  8024. {
  8025. a1CavitySN1_VehicleStates = cavitySNs[0];
  8026. a1CavitySN2_VehicleStates = cavitySNs[1];
  8027. a1CavityResult1_VehicleStates = 2;
  8028. a1CavityResult2_VehicleStates = 2;
  8029. }
  8030. if (a1CavitySN1_VehicleStates == "假产品")
  8031. a1CavityResult1_VehicleStates = 3;
  8032. if (a1CavitySN2_VehicleStates == "假产品")
  8033. a1CavityResult2_VehicleStates = 3;
  8034. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8035. // 回写
  8036. stopwatch2.Start();
  8037. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  8038. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  8039. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  8040. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  8041. //// MES_Flag
  8042. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  8043. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8044. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  8045. writeToPLC_Flag.Adress = 2003;
  8046. writeToPLC_Flag.Value = mES_Flag;
  8047. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  8048. {
  8049. Name = "a1CavitySN1_VehicleStates",
  8050. Adress = 2024,
  8051. ValueType = PLCValueType.String,
  8052. ValueTypeStrLength = 20,
  8053. Value = a1CavitySN1_VehicleStates
  8054. });
  8055. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  8056. {
  8057. Name = "a1CavitySN2_VehicleStates",
  8058. Adress = 2044,
  8059. ValueType = PLCValueType.String,
  8060. ValueTypeStrLength = 20,
  8061. Value = a1CavitySN2_VehicleStates
  8062. });
  8063. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8064. {
  8065. Name = "a1CavityResult1_VehicleStates",
  8066. Adress = 2064,
  8067. ValueType = PLCValueType.Short,
  8068. Value = a1CavityResult1_VehicleStates
  8069. });
  8070. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8071. {
  8072. Name = "a1CavityResult2_VehicleStates",
  8073. Adress = 2065,
  8074. ValueType = PLCValueType.Short,
  8075. Value = a1CavityResult2_VehicleStates
  8076. });
  8077. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  8078. stopwatch2.Stop();
  8079. }
  8080. catch (Exception ex)
  8081. {
  8082. string str = ex.StackTrace;
  8083. AddMessage_Station(stationNameStr, LogType.Error,
  8084. $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" +
  8085. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8086. // MES_Flag
  8087. stopwatch2.Start();
  8088. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8089. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8090. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  8091. writeToPLC_Flag.Adress = 2003;
  8092. writeToPLC_Flag.Value = (short)6;
  8093. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  8094. stopwatch2.Stop();
  8095. }
  8096. stopwatch1.Stop();
  8097. AddMessage(LogType.Info,
  8098. stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8099. stopwatch2.ElapsedMilliseconds + "ms");
  8100. }
  8101. /// <summary>
  8102. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  8103. /// </summary>
  8104. /// <param name="plcNo">PLC编号</param>
  8105. /// <param name="stationNameStr">工站全称</param>
  8106. private void S1上料进站校验(int plcNo, string stationNameStr)
  8107. {
  8108. Stopwatch stopwatch1 = new Stopwatch();
  8109. Stopwatch stopwatch2 = new Stopwatch();
  8110. try
  8111. {
  8112. stopwatch1.Start();
  8113. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  8114. sn = sn.Replace("\0", "");
  8115. // 保存进站数据+调用进站MES接口
  8116. List<TestItem> item = new List<TestItem>();
  8117. stopwatch2.Start();
  8118. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  8119. item, out string errorMsg);
  8120. stopwatch2.Stop();
  8121. short a1MES_FLAG_Check = (short)result;
  8122. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8123. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8124. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  8125. writeToPLC_Flag.Adress = 2077;
  8126. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  8127. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  8128. }
  8129. catch (Exception ex)
  8130. {
  8131. string str = ex.StackTrace;
  8132. AddMessage_Station(stationNameStr, LogType.Error,
  8133. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  8134. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8135. // MES_Flag
  8136. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  8137. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8138. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  8139. writeToPLC_Flag.Adress = 2077;
  8140. writeToPLC_Flag.Value = (short)6;
  8141. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  8142. }
  8143. stopwatch1.Stop();
  8144. AddMessage(LogType.Info,
  8145. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  8146. stopwatch2.ElapsedMilliseconds + "ms");
  8147. }
  8148. /// <summary>
  8149. /// [S1] Tray盘上料装备(板测)- 出站接口
  8150. /// </summary>
  8151. /// <param name="plcNo"></param>
  8152. /// <param name="stationCode"></param>
  8153. /// <param name="stationName"></param>
  8154. private void S1出站接口(int plcNo, string stationCode, string stationName)
  8155. {
  8156. Stopwatch stopwatch1 = new Stopwatch();
  8157. Stopwatch stopwatch2 = new Stopwatch();
  8158. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8159. string stationNameStr = stationCode + stationName;
  8160. string processItem = stationName; // 测试项目
  8161. try
  8162. {
  8163. stopwatch1.Start();
  8164. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8165. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8166. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8167. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8168. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  8169. sn = sn.Replace("\0", "");
  8170. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  8171. partNo1 = partNo1.Replace("\0", "");
  8172. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  8173. partNo2 = partNo2.Replace("\0", "");
  8174. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  8175. bool pass = a1Result == 1;
  8176. stopwatch2.Start();
  8177. // 产品1
  8178. List<TestItem> items = new List<TestItem>();
  8179. items.Add(new TestItem()
  8180. {
  8181. Parameter_name = "载具码",
  8182. Parameter_value = sn,
  8183. Parameter_unit = ""
  8184. });
  8185. items.Add(new TestItem()
  8186. {
  8187. Parameter_name = "载具穴号",
  8188. Parameter_value = "1",
  8189. Parameter_unit = ""
  8190. });
  8191. items.Add(new TestItem()
  8192. {
  8193. Parameter_name = "产品结果",
  8194. Parameter_value = a1Result == 1 ? "OK" : "NG",
  8195. Parameter_unit = ""
  8196. });
  8197. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  8198. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  8199. // 产品2
  8200. items = new List<TestItem>();
  8201. items.Add(new TestItem()
  8202. {
  8203. Parameter_name = "载具码",
  8204. Parameter_value = sn,
  8205. Parameter_unit = ""
  8206. });
  8207. items.Add(new TestItem()
  8208. {
  8209. Parameter_name = "载具穴号",
  8210. Parameter_value = "2",
  8211. Parameter_unit = ""
  8212. });
  8213. items.Add(new TestItem()
  8214. {
  8215. Parameter_name = "产品结果",
  8216. Parameter_value = a1Result == 1 ? "OK" : "NG",
  8217. Parameter_unit = ""
  8218. });
  8219. int result2 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  8220. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  8221. short result = 0;
  8222. List<int> results = new List<int>() { result1, result2 };
  8223. if (result1 == 1 && result2 == 1)
  8224. result = 1;
  8225. else if (results.Contains(3))
  8226. result = 3;
  8227. else if (results.Contains(2))
  8228. result = 2;
  8229. else if (results.Contains(4))
  8230. result = 4;
  8231. else
  8232. result = 4;
  8233. stopwatch2.Stop();
  8234. #region 存储绑定数据到 边线MES系统中
  8235. if (result == 1)
  8236. {
  8237. string data = string.Concat(partNo1, ".", partNo2);
  8238. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  8239. if (resultMesR != 0)
  8240. {
  8241. result = 4;
  8242. AddMessage_Station(stationNameStr, LogType.Error,
  8243. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  8244. }
  8245. }
  8246. #endregion 存储绑定数据到 边线MES系统中
  8247. // MES_Flag 为MES报错
  8248. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8249. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  8250. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8251. writeToPLC_Flag.Name = "a1MES_FLAG";
  8252. writeToPLC_Flag.Adress = 2109;
  8253. writeToPLC_Flag.Value = result;
  8254. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  8255. OnMessage(LogType.Debug,
  8256. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8257. }
  8258. catch (Exception ex)
  8259. {
  8260. stopwatch2.Restart();
  8261. // MES_Flag 为4上位机报错
  8262. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  8263. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8264. writeToPLC_Flag.Name = "a1MES_FLAG";
  8265. writeToPLC_Flag.Adress = 2109;
  8266. writeToPLC_Flag.Value = (short)4;
  8267. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  8268. stopwatch2.Stop();
  8269. string str = ex.StackTrace;
  8270. AddMessage_Station(stationNameStr, LogType.Error,
  8271. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  8272. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8273. }
  8274. stopwatch1.Stop();
  8275. AddMessage(LogType.Info,
  8276. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  8277. stopwatch2.ElapsedMilliseconds + "ms");
  8278. }
  8279. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  8280. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  8281. //{
  8282. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8283. // string stationNameStr = stationCode + stationName;
  8284. // string processItem = stationName; // 测试项目
  8285. // try
  8286. // {
  8287. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8288. // string accno = "1"; // 工序编号
  8289. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  8290. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  8291. // List<OneCheckItem> items = new List<OneCheckItem>()
  8292. // {
  8293. // new OneCheckItem()
  8294. // {
  8295. // Onecheck_name="胶圈装配行程设定上限",
  8296. // Onecheck_content="上限值",
  8297. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  8298. // },
  8299. // };
  8300. // OneCheckData oneCheckData = new OneCheckData()
  8301. // {
  8302. // Line_code = GlobalContext.LineCode,
  8303. // Line_name = GlobalContext.LineName,
  8304. // Equipment_code = equipmentCode,
  8305. // Equipment_name = equipmentCode,
  8306. // Workorder_code = workorder_code,
  8307. // Procedure_code = accno,
  8308. // Procedure_name = processItem,
  8309. // Oneckeck_values = items,
  8310. // Onecheck_empcode = "",
  8311. // Onecheck_empname = "",
  8312. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  8313. // };
  8314. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  8315. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  8316. // short result = result1 == 1 ? (short)1 : (short)2;
  8317. // // MES_Flag 为4MES报错
  8318. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  8319. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8320. // }
  8321. // catch (Exception ex)
  8322. // {
  8323. // // MES_Flag 为2上位机报错
  8324. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  8325. // string str = ex.StackTrace;
  8326. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8327. // }
  8328. //}
  8329. // ReadStation_S1_2 节拍接口+AGV
  8330. /// <summary>
  8331. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  8332. /// </summary>
  8333. /// <param name="plcNo">PLC编号</param>
  8334. /// <param name="stationNameStr">工站全称</param>
  8335. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  8336. {
  8337. Stopwatch stopwatch1 = new Stopwatch();
  8338. Stopwatch stopwatch2 = new Stopwatch();
  8339. try
  8340. {
  8341. stopwatch1.Start();
  8342. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  8343. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  8344. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  8345. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  8346. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  8347. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  8348. // ZS 将SN发给ICT标机(串口)
  8349. short a1MES_FLAG_ICT = 1;
  8350. stopwatch2.Start();
  8351. // MES_Flag
  8352. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  8353. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8354. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  8355. writeToPLC_Flag.Adress = 2182;
  8356. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  8357. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  8358. stopwatch2.Stop();
  8359. }
  8360. catch (Exception ex)
  8361. {
  8362. string str = ex.StackTrace;
  8363. AddMessage_Station(stationNameStr, LogType.Error,
  8364. $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" +
  8365. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8366. stopwatch2.Start();
  8367. // MES_Flag
  8368. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  8369. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8370. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  8371. writeToPLC_Flag.Adress = 2182;
  8372. writeToPLC_Flag.Value = (short)4;
  8373. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  8374. stopwatch2.Stop();
  8375. }
  8376. stopwatch1.Stop();
  8377. AddMessage(LogType.Info,
  8378. stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8379. stopwatch2.ElapsedMilliseconds + "ms");
  8380. }
  8381. /// <summary>
  8382. /// [S1] Tray盘上料装备(板测)- 节拍接口
  8383. /// </summary>
  8384. /// <param name="plcNo">PLC编号</param>
  8385. /// <param name="stationNameStr">工站全称</param>
  8386. private void S1节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  8387. {
  8388. Stopwatch stopwatch1 = new Stopwatch();
  8389. Stopwatch stopwatch2 = new Stopwatch();
  8390. string resultStr = string.Empty;
  8391. try
  8392. {
  8393. stopwatch1.Start();
  8394. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  8395. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  8396. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  8397. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  8398. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  8399. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8400. if (!actionBool)
  8401. {
  8402. stopwatch2.Start();
  8403. //写入PLC
  8404. iot_data.beatReturn = 2; //NG
  8405. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8406. stopwatch2.Stop();
  8407. AddMessage(LogType.Info,
  8408. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  8409. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8410. return;
  8411. }
  8412. //作业开始后要有物料和载具信息
  8413. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode) &&
  8414. Convert.ToInt32(oEEType) > 2)
  8415. {
  8416. stopwatch2.Start();
  8417. //写入PLC
  8418. iot_data.beatReturn = 2; //NG
  8419. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8420. stopwatch2.Stop();
  8421. AddMessage_Station(stationNameStr, LogType.Info,
  8422. stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  8423. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8424. return;
  8425. }
  8426. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a1OEEPartNo))
  8427. {
  8428. stopwatch2.Start();
  8429. //写入PLC
  8430. iot_data.beatReturn = 2; //NG
  8431. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8432. stopwatch2.Stop();
  8433. AddMessage_Station(stationNameStr, LogType.Info,
  8434. stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  8435. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8436. return;
  8437. }
  8438. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a1OEEVehicleCode))
  8439. {
  8440. stopwatch2.Start();
  8441. //写入PLC
  8442. iot_data.beatReturn = 2; //NG
  8443. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8444. stopwatch2.Stop();
  8445. AddMessage_Station(stationNameStr, LogType.Info,
  8446. stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  8447. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8448. return;
  8449. }
  8450. short _result = 0;
  8451. // 上传OEE
  8452. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  8453. _result = result.Item1;
  8454. resultStr = result.Item2;
  8455. if (_result == 1)
  8456. {
  8457. stopwatch2.Start();
  8458. //写入PLC
  8459. iot_data.beatReturn = 1; //OK
  8460. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8461. OnMessage(LogType.Info,
  8462. $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  8463. stopwatch2.Stop();
  8464. }
  8465. else
  8466. {
  8467. stopwatch2.Start();
  8468. //写入PLC
  8469. iot_data.beatReturn = 2; //NG
  8470. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8471. stopwatch2.Stop();
  8472. AddMessage_Station(stationNameStr, LogType.Error,
  8473. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  8474. }
  8475. }
  8476. catch (Exception ex)
  8477. {
  8478. string str = ex.StackTrace;
  8479. AddMessage_Station(stationNameStr, LogType.Error,
  8480. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  8481. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8482. // MES_Flag
  8483. stopwatch2.Start();
  8484. //写入PLC
  8485. iot_data.beatReturn = 2; //NG
  8486. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8487. stopwatch2.Stop();
  8488. }
  8489. stopwatch1.Stop();
  8490. AddMessage(LogType.Info,
  8491. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8492. stopwatch2.ElapsedMilliseconds + "ms");
  8493. }
  8494. /// <summary>
  8495. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  8496. /// </summary>
  8497. /// <param name="plcNo">PLC编号</param>
  8498. /// <param name="stationNameStr">工站全称</param>
  8499. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  8500. {
  8501. Stopwatch stopwatch1 = new Stopwatch();
  8502. Stopwatch stopwatch2 = new Stopwatch();
  8503. try
  8504. {
  8505. stopwatch1.Start();
  8506. // ZS 呼叫AGV
  8507. short a1AGVUpCall = 2;
  8508. stopwatch2.Start();
  8509. // a1AGVUpCall
  8510. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  8511. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8512. writeToPLC_Flag.Name = "a1AGVUpCall";
  8513. writeToPLC_Flag.Adress = 2307;
  8514. writeToPLC_Flag.Value = a1AGVUpCall;
  8515. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  8516. stopwatch2.Stop();
  8517. }
  8518. catch (Exception ex)
  8519. {
  8520. string str = ex.StackTrace;
  8521. AddMessage_Station(stationNameStr, LogType.Error,
  8522. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  8523. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8524. // a1AGVUpCall
  8525. stopwatch2.Start();
  8526. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  8527. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8528. writeToPLC_Flag.Name = "a1AGVUpCall";
  8529. writeToPLC_Flag.Adress = 2307;
  8530. writeToPLC_Flag.Value = (short)4;
  8531. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  8532. stopwatch2.Stop();
  8533. }
  8534. stopwatch1.Stop();
  8535. AddMessage(LogType.Info,
  8536. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8537. stopwatch2.ElapsedMilliseconds + "ms");
  8538. }
  8539. /// <summary>
  8540. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  8541. /// </summary>
  8542. /// <param name="plcNo">PLC编号</param>
  8543. /// <param name="stationNameStr">工站全称</param>
  8544. private void S1AGV上料完成(int plcNo, string stationNameStr)
  8545. {
  8546. Stopwatch stopwatch1 = new Stopwatch();
  8547. Stopwatch stopwatch2 = new Stopwatch();
  8548. try
  8549. {
  8550. stopwatch1.Start();
  8551. // ZS AGV上料完成,让小车离开
  8552. short a1AGVUpEnd = 2;
  8553. stopwatch2.Start();
  8554. // a1AGVUpEnd
  8555. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  8556. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8557. writeToPLC_Flag.Name = "a1AGVUpEnd";
  8558. writeToPLC_Flag.Adress = 2309;
  8559. writeToPLC_Flag.Value = a1AGVUpEnd;
  8560. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  8561. stopwatch2.Stop();
  8562. }
  8563. catch (Exception ex)
  8564. {
  8565. string str = ex.StackTrace;
  8566. AddMessage_Station(stationNameStr, LogType.Error,
  8567. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  8568. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8569. // a1AGVUpEnd
  8570. stopwatch2.Start();
  8571. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  8572. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8573. writeToPLC_Flag.Name = "a1AGVUpEnd";
  8574. writeToPLC_Flag.Adress = 2309;
  8575. writeToPLC_Flag.Value = (short)4;
  8576. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  8577. stopwatch2.Stop();
  8578. }
  8579. stopwatch1.Stop();
  8580. AddMessage(LogType.Info,
  8581. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8582. stopwatch2.ElapsedMilliseconds + "ms");
  8583. }
  8584. /// <summary>
  8585. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  8586. /// </summary>
  8587. /// <param name="plcNo">PLC编号</param>
  8588. /// <param name="stationNameStr">工站全称</param>
  8589. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  8590. {
  8591. Stopwatch stopwatch1 = new Stopwatch();
  8592. Stopwatch stopwatch2 = new Stopwatch();
  8593. try
  8594. {
  8595. stopwatch1.Start();
  8596. // ZS 呼叫AGV
  8597. short a1AGVDownCall = 2;
  8598. stopwatch2.Start();
  8599. // a1AGVDownCall
  8600. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  8601. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8602. writeToPLC_Flag.Name = "a1AGVDownCall";
  8603. writeToPLC_Flag.Adress = 2320;
  8604. writeToPLC_Flag.Value = a1AGVDownCall;
  8605. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  8606. stopwatch2.Stop();
  8607. }
  8608. catch (Exception ex)
  8609. {
  8610. string str = ex.StackTrace;
  8611. AddMessage_Station(stationNameStr, LogType.Error,
  8612. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  8613. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8614. // a1AGVDownCall
  8615. stopwatch2.Start();
  8616. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  8617. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8618. writeToPLC_Flag.Name = "a1AGVDownCall";
  8619. writeToPLC_Flag.Adress = 2320;
  8620. writeToPLC_Flag.Value = (short)4;
  8621. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  8622. stopwatch2.Stop();
  8623. }
  8624. stopwatch1.Stop();
  8625. AddMessage(LogType.Info,
  8626. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8627. stopwatch2.ElapsedMilliseconds + "ms");
  8628. }
  8629. /// <summary>
  8630. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  8631. /// </summary>
  8632. /// <param name="plcNo">PLC编号</param>
  8633. /// <param name="stationNameStr">工站全称</param>
  8634. private void S1AGV下料完成(int plcNo, string stationNameStr)
  8635. {
  8636. Stopwatch stopwatch1 = new Stopwatch();
  8637. Stopwatch stopwatch2 = new Stopwatch();
  8638. try
  8639. {
  8640. stopwatch1.Start();
  8641. // ZS AGV上料完成,让小车离开
  8642. short a1AGVDownEnd = 2;
  8643. stopwatch2.Start();
  8644. // a1AGVDownEnd
  8645. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  8646. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8647. writeToPLC_Flag.Name = "a1AGVDownEnd";
  8648. writeToPLC_Flag.Adress = 2322;
  8649. writeToPLC_Flag.Value = a1AGVDownEnd;
  8650. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  8651. stopwatch2.Stop();
  8652. }
  8653. catch (Exception ex)
  8654. {
  8655. string str = ex.StackTrace;
  8656. AddMessage_Station(stationNameStr, LogType.Error,
  8657. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  8658. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8659. // a1AGVDownEnd
  8660. stopwatch2.Start();
  8661. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  8662. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8663. writeToPLC_Flag.Name = "a1AGVDownEnd";
  8664. writeToPLC_Flag.Adress = 2322;
  8665. writeToPLC_Flag.Value = (short)4;
  8666. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  8667. stopwatch2.Stop();
  8668. }
  8669. stopwatch1.Stop();
  8670. AddMessage(LogType.Info,
  8671. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8672. stopwatch2.ElapsedMilliseconds + "ms");
  8673. }
  8674. #endregion [S1] Tray盘上料装备(板测)
  8675. #endregion PLC1 张超凡
  8676. #region PLC2 李晓奇
  8677. #region [S2] FCT(板测)
  8678. /// <summary>
  8679. /// S2工位的数据- 触发信号上次的值
  8680. /// </summary>
  8681. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  8682. /// <summary>
  8683. /// S2工位的数据(含触发信号)
  8684. /// </summary>
  8685. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  8686. /// <summary>
  8687. /// S2工位的数据- 回写点位
  8688. /// </summary>
  8689. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8690. /// <summary>
  8691. /// [S2] FCT(板测)
  8692. /// </summary>
  8693. /// <param name="plcNo">PLC编号</param>
  8694. //private void ReadStation_S2(int plcNo)
  8695. //{
  8696. // // [S1] Tray盘上料装备
  8697. // // [S2] FCT
  8698. // // [S3] 值板机
  8699. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8700. // // [S5] Tray盘下料装备
  8701. // /// 上位机心跳
  8702. // /// 获取设备报警数据与状态信息
  8703. // string stationCode = "[S2]";
  8704. // string stationName = "FCT";
  8705. // string stationNameStr = stationCode + stationName;
  8706. // #region 创建字典
  8707. // // 触发信号字典 赋值
  8708. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8709. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  8710. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8711. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8712. // // PLC数据字典 赋值
  8713. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  8714. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  8715. // s2PLCData.Add("b1ProductSN_Check", 0);
  8716. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  8717. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  8718. // s2PLCData.Add("b1ProductSN_Unbind", "");
  8719. // s2PLCData.Add("b1ProductSN_Bind", "");
  8720. // s2PLCData.Add("b1Part1SN_Bind", "");
  8721. // s2PLCData.Add("b1Part2SN_Bind", "");
  8722. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  8723. // s2PLCData.Add("b1MES_FLAG", 0);
  8724. // s2PLCData.Add("b1ProductSN", 0);
  8725. // s2PLCData.Add("b1Part1Result", 0);
  8726. // s2PLCData.Add("b1Part2Result", 0);
  8727. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  8728. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  8729. // s2PLCData.Add("b1OEEProductSN", "");
  8730. // s2PLCData.Add("b1OEEType", 0);
  8731. // #endregion 创建字典
  8732. // while (IsRun)
  8733. // {
  8734. // try
  8735. // {
  8736. // if (!GlobalContext._IsCon_Funs2)
  8737. // {
  8738. // UpdatePLCMonitor(1, plcNo, 0);
  8739. // continue;
  8740. // }
  8741. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8742. // {
  8743. // Stopwatch stopwatch1 = new Stopwatch();
  8744. // Stopwatch stopwatch2 = new Stopwatch();
  8745. // stopwatch1.Start();
  8746. // stopwatch2.Start();
  8747. // #region 一次性读取所有数据
  8748. // // 一次性读取所有数据
  8749. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  8750. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  8751. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  8752. // int[] datas = data1.Concat(data2).ToArray();
  8753. // datas = datas.Concat(data3).ToArray();
  8754. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  8755. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  8756. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8757. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  8758. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  8759. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  8760. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  8761. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  8762. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  8763. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  8764. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  8765. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  8766. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  8767. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  8768. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  8769. // s2PLCData["b1MES_FLAG"] = datas[169];
  8770. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  8771. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  8772. // s2PLCData["b1Part1Result"] = datas[190];
  8773. // s2PLCData["b1Part2Result"] = datas[191];
  8774. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  8775. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  8776. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  8777. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  8778. // s2PLCData["b1OEEType"] = datas[224];
  8779. // #endregion 一次性读取所有数据
  8780. // stopwatch2.Stop();
  8781. // #region 回写操作,写后清空flag
  8782. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  8783. // #endregion 回写操作,写后清空flag
  8784. // #region 进站校验
  8785. // try
  8786. // {
  8787. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  8788. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  8789. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  8790. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  8791. // {
  8792. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  8793. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8794. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  8795. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8796. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  8797. // }
  8798. // }
  8799. // catch (Exception ex)
  8800. // {
  8801. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8802. // string str = ex.StackTrace;
  8803. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8804. // }
  8805. // #endregion 进站校验
  8806. // #region 二穴载具解绑/绑定(产品换载具)
  8807. // try
  8808. // {
  8809. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  8810. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  8811. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  8812. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  8813. // {
  8814. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  8815. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  8816. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  8817. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  8818. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  8819. // }
  8820. // }
  8821. // catch (Exception ex)
  8822. // {
  8823. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  8824. // string str = ex.StackTrace;
  8825. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8826. // }
  8827. // #endregion 二穴载具解绑/绑定(产品换载具)
  8828. // #region FCT-出站接口
  8829. // try
  8830. // {
  8831. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  8832. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  8833. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  8834. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  8835. // {
  8836. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  8837. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8838. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  8839. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  8840. // }
  8841. // }
  8842. // catch (Exception ex)
  8843. // {
  8844. // // MES_Flag 为6上位机报错
  8845. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  8846. // string str = ex.StackTrace;
  8847. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8848. // }
  8849. // #endregion FCT-出站接口
  8850. // #region 节拍接口
  8851. // try
  8852. // {
  8853. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  8854. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  8855. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  8856. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  8857. // {
  8858. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  8859. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8860. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  8861. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  8862. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  8863. // }
  8864. // }
  8865. // catch (Exception ex)
  8866. // {
  8867. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  8868. // string str = ex.StackTrace;
  8869. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8870. // }
  8871. // #endregion 节拍接口
  8872. // #region 心跳
  8873. // try
  8874. // {
  8875. // short states = 0;
  8876. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  8877. // }
  8878. // catch (Exception ex)
  8879. // {
  8880. // string str = ex.StackTrace;
  8881. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8882. // }
  8883. // #endregion 心跳
  8884. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  8885. // stopwatch1.Stop();
  8886. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  8887. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  8888. // }
  8889. // else
  8890. // {
  8891. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8892. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  8893. // Funs[plcNo].Connect();
  8894. // }
  8895. // }
  8896. // catch (Exception ex)
  8897. // {
  8898. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8899. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  8900. // Funs[plcNo].ReConnect();
  8901. // }
  8902. // Thread.Sleep(IntervalReadPLC);
  8903. // }
  8904. //}
  8905. /// <summary>
  8906. /// [S2] FCT(板测)- 进站校验
  8907. /// </summary>
  8908. /// <param name="plcNo">PLC编号</param>
  8909. /// <param name="stationNameStr">工站全称</param>
  8910. private void S2进站校验(int plcNo, string stationNameStr)
  8911. {
  8912. Stopwatch stopwatch1 = new Stopwatch();
  8913. Stopwatch stopwatch2 = new Stopwatch();
  8914. try
  8915. {
  8916. stopwatch1.Start();
  8917. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  8918. sn = sn.Replace("\0", "");
  8919. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  8920. // 查询物料码By载具码 并判断是不是假产品
  8921. string cavityData = string.Empty;
  8922. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  8923. if (string.IsNullOrEmpty(cavityData))
  8924. cavityData = "";
  8925. if (snResult != 0)
  8926. {
  8927. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8928. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  8929. writeToPLC_Flag1.Adress = 2003;
  8930. writeToPLC_Flag1.Value = (short)6;
  8931. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  8932. stopwatch1.Stop();
  8933. AddMessage(LogType.Info,
  8934. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8935. return;
  8936. }
  8937. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  8938. string[] cavitySNs = cavityData.Split('.');
  8939. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  8940. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  8941. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  8942. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  8943. if (cavitySNs != null && cavitySNs.Length >= 2)
  8944. {
  8945. b1Part1SN_Check = cavitySNs[0];
  8946. b1Part2SN_Check = cavitySNs[1];
  8947. b1Part1Result_Check = 2;
  8948. b1Part2Result_Check = 2;
  8949. }
  8950. if (b1Part1SN_Check == "假产品")
  8951. b1Part1Result_Check = 3;
  8952. if (b1Part2SN_Check == "假产品")
  8953. b1Part2Result_Check = 3;
  8954. // 调用MES进站
  8955. stopwatch2.Start();
  8956. // 调用MES进站 - 产品1
  8957. List<TestItem> item;
  8958. int result1 = b1Part1Result_Check;
  8959. if (result1 != 3)
  8960. {
  8961. item = new List<TestItem>();
  8962. item.Add(new TestItem()
  8963. {
  8964. Parameter_name = "载具码",
  8965. Parameter_value = sn,
  8966. });
  8967. item.Add(new TestItem()
  8968. {
  8969. Parameter_name = "载具穴号",
  8970. Parameter_value = "1",
  8971. });
  8972. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8973. b1Part1SN_Check, item, out string errorMsg);
  8974. }
  8975. // 调用MES进站 - 产品2
  8976. int result2 = b1Part2Result_Check;
  8977. if (result2 != 3)
  8978. {
  8979. item = new List<TestItem>();
  8980. item.Add(new TestItem()
  8981. {
  8982. Parameter_name = "载具码",
  8983. Parameter_value = sn,
  8984. });
  8985. item.Add(new TestItem()
  8986. {
  8987. Parameter_name = "载具穴号",
  8988. Parameter_value = "2",
  8989. });
  8990. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8991. b1Part2SN_Check, item, out string errorMsg);
  8992. }
  8993. stopwatch2.Stop();
  8994. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  8995. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  8996. int result = result1;
  8997. if (result == 1)
  8998. result = result2;
  8999. short b1MES_FLAG_Check = (short)result;
  9000. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  9001. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  9002. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  9003. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  9004. //// MES_Flag
  9005. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9006. WriteToPLC_Flag
  9007. writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9008. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  9009. writeToPLC_Flag.Adress = 2003;
  9010. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  9011. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9012. {
  9013. Name = "b1Part1SN_Check",
  9014. Adress = 2024,
  9015. ValueType = PLCValueType.String,
  9016. ValueTypeStrLength = 20,
  9017. Value = b1Part1SN_Check
  9018. });
  9019. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9020. {
  9021. Name = "b1Part2SN_Check",
  9022. Adress = 2044,
  9023. ValueType = PLCValueType.String,
  9024. ValueTypeStrLength = 20,
  9025. Value = b1Part2SN_Check
  9026. });
  9027. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9028. {
  9029. Name = "b1Part1Result_Check",
  9030. Adress = 2064,
  9031. ValueType = PLCValueType.Short,
  9032. Value = b1Part1Result_Check
  9033. });
  9034. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9035. {
  9036. Name = "b1Part2Result_Check",
  9037. Adress = 2065,
  9038. ValueType = PLCValueType.Short,
  9039. Value = b1Part2Result_Check
  9040. });
  9041. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  9042. }
  9043. catch (Exception ex)
  9044. {
  9045. string str = ex.StackTrace;
  9046. AddMessage_Station(stationNameStr, LogType.Error,
  9047. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  9048. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9049. // MES_Flag
  9050. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9051. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9052. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  9053. writeToPLC_Flag.Adress = 2003;
  9054. writeToPLC_Flag.Value = (short)6;
  9055. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  9056. }
  9057. stopwatch1.Stop();
  9058. AddMessage(LogType.Info,
  9059. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  9060. stopwatch2.ElapsedMilliseconds + "ms");
  9061. }
  9062. /// <summary>
  9063. /// [S2] FCT(板测)- 二穴载具解绑绑定
  9064. /// </summary>
  9065. /// <param name="plcNo">PLC编号</param>
  9066. /// <param name="stationNameStr">工站全称</param>
  9067. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  9068. {
  9069. Stopwatch stopwatch1 = new Stopwatch();
  9070. Stopwatch stopwatch2 = new Stopwatch();
  9071. try
  9072. {
  9073. stopwatch1.Start();
  9074. // 产品换载具
  9075. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  9076. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  9077. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  9078. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  9079. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  9080. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  9081. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  9082. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  9083. stopwatch2.Start();
  9084. #region 查询载具上的产品信息
  9085. //string cavityData = string.Empty;
  9086. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  9087. //if (string.IsNullOrEmpty(cavityData))
  9088. // cavityData = "";
  9089. //if (snResult != 0)
  9090. //{
  9091. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9092. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  9093. // writeToPLC_Flag.Adress = 2077;
  9094. // writeToPLC_Flag.Value = (short)6;
  9095. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  9096. // stopwatch1.Stop();
  9097. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9098. // return;
  9099. //}
  9100. #endregion 查询载具上的产品信息
  9101. #region 解绑(边线MES系统)
  9102. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  9103. if (snResult != 0)
  9104. {
  9105. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9106. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  9107. writeToPLC_Flag1.Adress = 2077;
  9108. writeToPLC_Flag1.Value = (short)6;
  9109. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  9110. stopwatch1.Stop();
  9111. AddMessage(LogType.Info,
  9112. stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" +
  9113. stopwatch1.ElapsedMilliseconds + "ms");
  9114. return;
  9115. }
  9116. #endregion 解绑(边线MES系统)
  9117. #region 存储绑定数据到 边线MES系统中
  9118. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  9119. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  9120. if (snResult != 0)
  9121. {
  9122. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9123. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  9124. writeToPLC_Flag1.Adress = 2077;
  9125. writeToPLC_Flag1.Value = (short)6;
  9126. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  9127. stopwatch1.Stop();
  9128. AddMessage(LogType.Info,
  9129. stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" +
  9130. stopwatch1.ElapsedMilliseconds + "ms");
  9131. return;
  9132. }
  9133. #endregion 存储绑定数据到 边线MES系统中
  9134. stopwatch2.Stop();
  9135. short b1MES_FLAG_Unbind = 1;
  9136. // MES_Flag
  9137. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9138. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9139. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  9140. writeToPLC_Flag.Adress = 2077;
  9141. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  9142. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  9143. }
  9144. catch (Exception ex)
  9145. {
  9146. string str = ex.StackTrace;
  9147. AddMessage_Station(stationNameStr, LogType.Error,
  9148. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" +
  9149. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9150. // MES_Flag
  9151. stopwatch2.Start();
  9152. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  9153. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9154. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  9155. writeToPLC_Flag.Adress = 2077;
  9156. writeToPLC_Flag.Value = (short)6;
  9157. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  9158. stopwatch2.Stop();
  9159. }
  9160. stopwatch1.Stop();
  9161. AddMessage(LogType.Info,
  9162. stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9163. stopwatch2.ElapsedMilliseconds + "ms");
  9164. }
  9165. //// 上次采集到的SN
  9166. //private string sn_FCT = string.Empty;
  9167. /// <summary>
  9168. /// [S2] FCT(板测)- 出站数据
  9169. /// </summary>
  9170. private void S2出站接口(int plcNo, string stationCode, string stationName)
  9171. {
  9172. Stopwatch stopwatch1 = new Stopwatch();
  9173. Stopwatch stopwatch2 = new Stopwatch();
  9174. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9175. string stationNameStr = stationCode + stationName;
  9176. string processItem = stationName; // 测试项目
  9177. try
  9178. {
  9179. stopwatch1.Start();
  9180. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9181. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9182. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9183. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9184. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  9185. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  9186. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  9187. bool pass1 = b1Part1Result == 1;
  9188. bool pass2 = b1Part2Result == 1;
  9189. #region 根据 载具SN 查 物料SN
  9190. string cavityData = string.Empty;
  9191. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  9192. if (string.IsNullOrEmpty(cavityData))
  9193. cavityData = "";
  9194. if (snResult != 0)
  9195. {
  9196. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9197. writeToPLC_Flag1.Name = "b1MES_FLAG";
  9198. writeToPLC_Flag1.Adress = 2169;
  9199. writeToPLC_Flag1.Value = (short)4;
  9200. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  9201. stopwatch1.Stop();
  9202. AddMessage(LogType.Info,
  9203. stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9204. "ms");
  9205. return;
  9206. }
  9207. #endregion 根据 载具SN 查 物料SN
  9208. string[] cavitySNs = cavityData.Split('.');
  9209. string b1ProductSN1 = string.Empty;
  9210. string b1ProductSN2 = string.Empty;
  9211. if (cavitySNs != null && cavitySNs.Length >= 2)
  9212. {
  9213. b1ProductSN1 = cavitySNs[0];
  9214. b1ProductSN2 = cavitySNs[1];
  9215. }
  9216. stopwatch2.Start();
  9217. // 产品1
  9218. int result1 = 0;
  9219. if (b1ProductSN1 == "假产品")
  9220. result1 = 1;
  9221. else
  9222. {
  9223. List<TestItem> items1 = new List<TestItem>();
  9224. items1.Add(new TestItem()
  9225. {
  9226. Parameter_name = "载具码",
  9227. Parameter_value = b1ProductSN.ToString(),
  9228. Parameter_unit = ""
  9229. });
  9230. items1.Add(new TestItem()
  9231. {
  9232. Parameter_name = "载具穴号",
  9233. Parameter_value = "1",
  9234. Parameter_unit = ""
  9235. });
  9236. items1.Add(new TestItem()
  9237. {
  9238. Parameter_name = "产品结果",
  9239. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  9240. Parameter_unit = ""
  9241. });
  9242. result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  9243. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  9244. }
  9245. // 产品2
  9246. int result2 = 0;
  9247. if (b1ProductSN1 == "假产品")
  9248. result2 = 1;
  9249. else
  9250. {
  9251. List<TestItem> items2 = new List<TestItem>();
  9252. items2.Add(new TestItem()
  9253. {
  9254. Parameter_name = "载具码",
  9255. Parameter_value = b1ProductSN.ToString(),
  9256. Parameter_unit = ""
  9257. });
  9258. items2.Add(new TestItem()
  9259. {
  9260. Parameter_name = "载具穴号",
  9261. Parameter_value = "2",
  9262. Parameter_unit = ""
  9263. });
  9264. items2.Add(new TestItem()
  9265. {
  9266. Parameter_name = "产品结果",
  9267. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  9268. Parameter_unit = ""
  9269. });
  9270. result2 = SwitctProcessData_old(stationNameStr, items2, equipmentCode, processItem
  9271. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  9272. }
  9273. short result = 0;
  9274. List<int> results = new List<int>() { result1, result2 };
  9275. if (result1 == 1 && result2 == 1)
  9276. result = 1;
  9277. else if (results.Contains(3))
  9278. result = 3;
  9279. else if (results.Contains(2))
  9280. result = 2;
  9281. else if (results.Contains(4))
  9282. result = 4;
  9283. else
  9284. result = 4;
  9285. stopwatch2.Stop();
  9286. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9287. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9288. writeToPLC_Flag.Name = "b1MES_FLAG";
  9289. writeToPLC_Flag.Adress = 2169;
  9290. writeToPLC_Flag.Value = result;
  9291. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  9292. OnMessage(LogType.Debug,
  9293. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9294. }
  9295. catch (Exception ex)
  9296. {
  9297. stopwatch2.Restart();
  9298. // MES_Flag 为4上位机报错
  9299. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  9300. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9301. writeToPLC_Flag.Name = "b1MES_FLAG";
  9302. writeToPLC_Flag.Adress = 2169;
  9303. writeToPLC_Flag.Value = (short)4;
  9304. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  9305. stopwatch2.Stop();
  9306. string str = ex.StackTrace;
  9307. AddMessage_Station(stationNameStr, LogType.Error,
  9308. $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  9309. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9310. }
  9311. stopwatch1.Stop();
  9312. AddMessage(LogType.Info,
  9313. stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  9314. stopwatch2.ElapsedMilliseconds + "ms");
  9315. }
  9316. /// <summary>
  9317. /// [S2] FCT(板测)- 节拍接口
  9318. /// </summary>
  9319. /// <param name="plcNo">PLC编号</param>
  9320. /// <param name="stationNameStr">工站全称</param>
  9321. private void S2节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  9322. {
  9323. Stopwatch stopwatch1 = new Stopwatch();
  9324. Stopwatch stopwatch2 = new Stopwatch();
  9325. string resultStr = string.Empty;
  9326. try
  9327. {
  9328. stopwatch1.Start();
  9329. string oEEType = ((int)s1PLCData["a2OEEType"]).ToString(); // 节拍类型(plc写入)
  9330. string a2OEEPartNo = (string)s1PLCData["a2OEEPartNo"]; // 物料码
  9331. a2OEEPartNo = a2OEEPartNo.Replace("\0", "");
  9332. string a20EEVehicleCode = (string)s1PLCData["a20EEVehicleCode"]; // 载具SN
  9333. a20EEVehicleCode = a20EEVehicleCode.Replace("\0", "");
  9334. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9335. if (!actionBool)
  9336. {
  9337. stopwatch2.Start();
  9338. //写入PLC
  9339. iot_data.beatReturn = 2; //NG
  9340. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9341. stopwatch2.Stop();
  9342. AddMessage(LogType.Info,
  9343. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  9344. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9345. return;
  9346. }
  9347. //作业开始后要有物料和载具信息
  9348. if (string.IsNullOrEmpty(a2OEEPartNo) && string.IsNullOrEmpty(a20EEVehicleCode) &&
  9349. Convert.ToInt32(oEEType) > 2)
  9350. {
  9351. stopwatch2.Start();
  9352. //写入PLC
  9353. iot_data.beatReturn = 2; //NG
  9354. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9355. stopwatch2.Stop();
  9356. AddMessage_Station(stationNameStr, LogType.Info,
  9357. stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  9358. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9359. return;
  9360. }
  9361. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a2OEEPartNo))
  9362. {
  9363. stopwatch2.Start();
  9364. //写入PLC
  9365. iot_data.beatReturn = 2; //NG
  9366. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9367. stopwatch2.Stop();
  9368. AddMessage_Station(stationNameStr, LogType.Info,
  9369. stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  9370. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9371. return;
  9372. }
  9373. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a20EEVehicleCode))
  9374. {
  9375. stopwatch2.Start();
  9376. //写入PLC
  9377. iot_data.beatReturn = 2; //NG
  9378. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9379. stopwatch2.Stop();
  9380. AddMessage_Station(stationNameStr, LogType.Info,
  9381. stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  9382. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9383. return;
  9384. }
  9385. short _result = 0;
  9386. // 上传OEE
  9387. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a2OEEPartNo, a20EEVehicleCode);
  9388. _result = result.Item1;
  9389. resultStr = result.Item2;
  9390. if (_result == 1)
  9391. {
  9392. stopwatch2.Start();
  9393. //写入PLC
  9394. iot_data.beatReturn = 1; //OK
  9395. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9396. OnMessage(LogType.Info,
  9397. $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  9398. stopwatch2.Stop();
  9399. }
  9400. else
  9401. {
  9402. stopwatch2.Start();
  9403. //写入PLC
  9404. iot_data.beatReturn = 2; //NG
  9405. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9406. stopwatch2.Stop();
  9407. AddMessage_Station(stationNameStr, LogType.Error,
  9408. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  9409. }
  9410. }
  9411. catch (Exception ex)
  9412. {
  9413. string str = ex.StackTrace;
  9414. AddMessage_Station(stationNameStr, LogType.Error,
  9415. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  9416. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9417. // MES_Flag
  9418. stopwatch2.Start();
  9419. //写入PLC
  9420. iot_data.beatReturn = 2; //NG
  9421. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  9422. stopwatch2.Stop();
  9423. }
  9424. stopwatch1.Stop();
  9425. AddMessage(LogType.Info,
  9426. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9427. stopwatch2.ElapsedMilliseconds + "ms");
  9428. }
  9429. #endregion [S2] FCT(板测)
  9430. #endregion PLC2 李晓奇
  9431. #region PLC3 刘永村
  9432. #region [S3] 值板机
  9433. /// <summary>
  9434. /// S3工位的数据- 触发信号上次的值
  9435. /// </summary>
  9436. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  9437. /// <summary>
  9438. /// S3工位的数据(含触发信号)
  9439. /// </summary>
  9440. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  9441. /// <summary>
  9442. /// S3工位的数据- 回写点位
  9443. /// </summary>
  9444. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  9445. /// <summary>
  9446. /// [S3] 值板机
  9447. /// </summary>
  9448. /// <param name="plcNo">PLC编号</param>
  9449. //private void ReadStation_S3(int plcNo)
  9450. //{
  9451. // // [S1] Tray盘上料装备
  9452. // // [S2] FCT
  9453. // // [S3] 值板机
  9454. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  9455. // // [S5] Tray盘下料装备
  9456. // /// 上位机心跳
  9457. // /// 获取设备报警数据与状态信息
  9458. // string stationCode = "[S3]";
  9459. // string stationName = "值板机";
  9460. // string stationNameStr = stationCode + stationName;
  9461. // #region 创建字典
  9462. // // 触发信号字典 赋值
  9463. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  9464. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  9465. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  9466. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  9467. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9468. // // PLC数据字典 赋值
  9469. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  9470. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  9471. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  9472. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  9473. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  9474. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  9475. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  9476. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  9477. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  9478. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  9479. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  9480. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  9481. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  9482. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  9483. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  9484. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  9485. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  9486. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  9487. // s3PLCData.Add("c1Result", 0); // 产品结果
  9488. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9489. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  9490. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  9491. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  9492. // #endregion 创建字典
  9493. // while (IsRun)
  9494. // {
  9495. // try
  9496. // {
  9497. // if (!GlobalContext._IsCon_Funs3)
  9498. // {
  9499. // UpdatePLCMonitor(1, plcNo, 0);
  9500. // continue;
  9501. // }
  9502. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  9503. // {
  9504. // Stopwatch stopwatch1 = new Stopwatch();
  9505. // Stopwatch stopwatch2 = new Stopwatch();
  9506. // stopwatch1.Start();
  9507. // stopwatch2.Start();
  9508. // #region 一次性读取所有数据
  9509. // // 一次性读取所有数据
  9510. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  9511. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  9512. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  9513. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  9514. // int[] datas = data1.Concat(data2).ToArray();
  9515. // datas = datas.Concat(data3).ToArray();
  9516. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  9517. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  9518. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  9519. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  9520. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  9521. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  9522. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  9523. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  9524. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  9525. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  9526. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  9527. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  9528. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  9529. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  9530. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  9531. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  9532. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  9533. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  9534. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  9535. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  9536. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  9537. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  9538. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  9539. // #endregion 一次性读取所有数据
  9540. // stopwatch2.Stop();
  9541. // #region 回写操作,写后清空flag
  9542. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  9543. // #endregion 回写操作,写后清空flag
  9544. // #region S3进站校验
  9545. // try
  9546. // {
  9547. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  9548. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  9549. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  9550. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  9551. // {
  9552. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  9553. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  9554. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  9555. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  9556. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  9557. // }
  9558. // }
  9559. // catch (Exception ex)
  9560. // {
  9561. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9562. // string str = ex.StackTrace;
  9563. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9564. // }
  9565. // #endregion S3进站校验
  9566. // #region S3二穴载具解绑
  9567. // try
  9568. // {
  9569. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  9570. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  9571. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  9572. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  9573. // {
  9574. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  9575. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  9576. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  9577. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  9578. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  9579. // }
  9580. // }
  9581. // catch (Exception ex)
  9582. // {
  9583. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  9584. // string str = ex.StackTrace;
  9585. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9586. // }
  9587. // #endregion S3二穴载具解绑
  9588. // #region S3二穴载具绑定
  9589. // try
  9590. // {
  9591. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  9592. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  9593. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  9594. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  9595. // {
  9596. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  9597. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  9598. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  9599. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  9600. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  9601. // }
  9602. // }
  9603. // catch (Exception ex)
  9604. // {
  9605. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  9606. // string str = ex.StackTrace;
  9607. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9608. // }
  9609. // #endregion S3二穴载具绑定
  9610. // #region S3出站接口(+一穴载具绑定)
  9611. // try
  9612. // {
  9613. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  9614. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  9615. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  9616. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  9617. // {
  9618. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  9619. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  9620. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  9621. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  9622. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  9623. // }
  9624. // }
  9625. // catch (Exception ex)
  9626. // {
  9627. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  9628. // string str = ex.StackTrace;
  9629. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9630. // }
  9631. // #endregion S3出站接口(+一穴载具绑定)
  9632. // #region S3节拍接口
  9633. // try
  9634. // {
  9635. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  9636. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  9637. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  9638. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  9639. // {
  9640. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  9641. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  9642. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  9643. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  9644. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  9645. // }
  9646. // }
  9647. // catch (Exception ex)
  9648. // {
  9649. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  9650. // string str = ex.StackTrace;
  9651. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9652. // }
  9653. // #endregion S3节拍接口
  9654. // #region 心跳
  9655. // try
  9656. // {
  9657. // short states = 0;
  9658. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  9659. // }
  9660. // catch (Exception ex)
  9661. // {
  9662. // string str = ex.StackTrace;
  9663. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9664. // }
  9665. // #endregion 心跳
  9666. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  9667. // stopwatch1.Stop();
  9668. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  9669. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  9670. // }
  9671. // else
  9672. // {
  9673. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9674. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  9675. // Funs[plcNo].Connect();
  9676. // }
  9677. // }
  9678. // catch (Exception ex)
  9679. // {
  9680. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9681. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  9682. // Funs[plcNo].ReConnect();
  9683. // }
  9684. // Thread.Sleep(IntervalReadPLC);
  9685. // }
  9686. //}
  9687. /// <summary>
  9688. /// [S3] 值板机- 进站校验
  9689. /// </summary>
  9690. /// <param name="plcNo">PLC编号</param>
  9691. /// <param name="stationNameStr">工站全称</param>
  9692. private void S3进站校验(int plcNo, string stationNameStr)
  9693. {
  9694. Stopwatch stopwatch1 = new Stopwatch();
  9695. Stopwatch stopwatch2 = new Stopwatch();
  9696. try
  9697. {
  9698. stopwatch1.Start();
  9699. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  9700. sn = sn.Replace("\0", "");
  9701. #region 查询载具上的产品信息
  9702. string cavityData = string.Empty;
  9703. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9704. if (string.IsNullOrEmpty(cavityData))
  9705. cavityData = "";
  9706. if (snResult != 0)
  9707. {
  9708. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9709. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  9710. writeToPLC_Flag1.Adress = 2003;
  9711. writeToPLC_Flag1.Value = (short)6;
  9712. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  9713. stopwatch1.Stop();
  9714. AddMessage(LogType.Info,
  9715. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9716. return;
  9717. }
  9718. #endregion 查询载具上的产品信息
  9719. string[] cavitySNs = cavityData.Split('.');
  9720. string part1Str = ""; // 产品1的SN码
  9721. string part2Str = ""; // 产品2的SN码
  9722. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  9723. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  9724. if (cavitySNs != null && cavitySNs.Length >= 2)
  9725. {
  9726. part1Str = cavitySNs[0];
  9727. part2Str = cavitySNs[1];
  9728. c1Part1Result_Check = 2;
  9729. c1Part2Result_Check = 2;
  9730. }
  9731. if (part1Str == "假产品")
  9732. c1Part1Result_Check = 3;
  9733. if (part2Str == "假产品")
  9734. c1Part2Result_Check = 3;
  9735. // 调用MES进站
  9736. stopwatch2.Start();
  9737. // 调用MES进站 - 产品1
  9738. List<TestItem> item;
  9739. int result1 = c1Part1Result_Check;
  9740. if (result1 != 3)
  9741. {
  9742. item = new List<TestItem>();
  9743. item.Add(new TestItem()
  9744. {
  9745. Parameter_name = "载具码",
  9746. Parameter_value = sn,
  9747. });
  9748. item.Add(new TestItem()
  9749. {
  9750. Parameter_name = "载具穴号",
  9751. Parameter_value = "1",
  9752. });
  9753. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  9754. part1Str, item, out string errorMsg);
  9755. }
  9756. // 调用MES进站 - 产品2
  9757. int result2 = c1Part2Result_Check;
  9758. if (result2 != 3)
  9759. {
  9760. item = new List<TestItem>();
  9761. item.Add(new TestItem()
  9762. {
  9763. Parameter_name = "载具码",
  9764. Parameter_value = sn,
  9765. });
  9766. item.Add(new TestItem()
  9767. {
  9768. Parameter_name = "载具穴号",
  9769. Parameter_value = "2",
  9770. });
  9771. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  9772. part2Str, item, out string errorMsg);
  9773. }
  9774. stopwatch2.Stop();
  9775. if (result1 == 2)
  9776. c1Part1Result_Check = 2;
  9777. if (result2 == 2)
  9778. c1Part2Result_Check = 2;
  9779. int result = result1;
  9780. if (result == 1)
  9781. result = result2;
  9782. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  9783. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  9784. short c1MES_FLAG_Check = (short)result;
  9785. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  9786. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  9787. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  9788. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  9789. //// MES_Flag
  9790. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9791. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9792. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  9793. writeToPLC_Flag.Adress = 2003;
  9794. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  9795. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9796. {
  9797. Name = "c1Part1Result_Check",
  9798. Adress = 2024,
  9799. ValueType = PLCValueType.Short,
  9800. Value = c1Part1Result_Check
  9801. });
  9802. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9803. {
  9804. Name = "c1Part2Result_Check",
  9805. Adress = 2025,
  9806. ValueType = PLCValueType.Short,
  9807. Value = c1Part2Result_Check
  9808. });
  9809. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9810. {
  9811. Name = "c1Part1Num_Check",
  9812. Adress = 2026,
  9813. ValueType = PLCValueType.Short,
  9814. Value = c1Part1Num_Check
  9815. });
  9816. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9817. {
  9818. Name = "c1Part2Num_Check",
  9819. Adress = 2027,
  9820. ValueType = PLCValueType.Short,
  9821. Value = c1Part2Num_Check
  9822. });
  9823. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  9824. }
  9825. catch (Exception ex)
  9826. {
  9827. string str = ex.StackTrace;
  9828. AddMessage_Station(stationNameStr, LogType.Error,
  9829. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  9830. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9831. // MES_Flag
  9832. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9833. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9834. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  9835. writeToPLC_Flag.Adress = 2003;
  9836. writeToPLC_Flag.Value = (short)6;
  9837. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  9838. }
  9839. stopwatch1.Stop();
  9840. AddMessage(LogType.Info,
  9841. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  9842. stopwatch2.ElapsedMilliseconds + "ms");
  9843. }
  9844. /// <summary>
  9845. /// [S3] 值板机 - 二穴载具解绑
  9846. /// </summary>
  9847. /// <param name="plcNo">PLC编号</param>
  9848. /// <param name="stationNameStr">工站全称</param>
  9849. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  9850. {
  9851. Stopwatch stopwatch1 = new Stopwatch();
  9852. Stopwatch stopwatch2 = new Stopwatch();
  9853. try
  9854. {
  9855. stopwatch1.Start();
  9856. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  9857. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  9858. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  9859. // 解绑
  9860. #region 查询载具上的产品信息
  9861. string cavityData = string.Empty;
  9862. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  9863. if (string.IsNullOrEmpty(cavityData))
  9864. cavityData = "";
  9865. if (snResult != 0)
  9866. {
  9867. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9868. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  9869. writeToPLC_Flag1.Adress = 2082;
  9870. writeToPLC_Flag1.Value = (short)6;
  9871. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  9872. stopwatch1.Stop();
  9873. AddMessage(LogType.Info,
  9874. stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9875. "ms");
  9876. return;
  9877. }
  9878. #endregion 查询载具上的产品信息
  9879. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  9880. #region 解绑
  9881. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  9882. {
  9883. // 删除
  9884. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  9885. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  9886. }
  9887. else
  9888. {
  9889. string data_new = string.Join(".", cavitySNs);
  9890. // 删除再插入
  9891. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  9892. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  9893. OnMessage(LogType.Debug,
  9894. $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  9895. }
  9896. #endregion 解绑
  9897. short c1MES_FLAG_Unbind = 1;
  9898. stopwatch2.Start();
  9899. // MES_Flag
  9900. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9901. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9902. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  9903. writeToPLC_Flag.Adress = 2082;
  9904. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  9905. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  9906. stopwatch2.Stop();
  9907. }
  9908. catch (Exception ex)
  9909. {
  9910. string str = ex.StackTrace;
  9911. AddMessage_Station(stationNameStr, LogType.Error,
  9912. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" +
  9913. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9914. // MES_Flag
  9915. stopwatch2.Start();
  9916. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  9917. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9918. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  9919. writeToPLC_Flag.Adress = 2082;
  9920. writeToPLC_Flag.Value = (short)6;
  9921. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  9922. stopwatch2.Stop();
  9923. }
  9924. stopwatch1.Stop();
  9925. AddMessage(LogType.Info,
  9926. stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9927. stopwatch2.ElapsedMilliseconds + "ms");
  9928. }
  9929. /// <summary>
  9930. /// [S3] 值板机 - 二穴载具绑定
  9931. /// </summary>
  9932. /// <param name="plcNo">PLC编号</param>
  9933. /// <param name="stationNameStr">工站全称</param>
  9934. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  9935. {
  9936. Stopwatch stopwatch1 = new Stopwatch();
  9937. Stopwatch stopwatch2 = new Stopwatch();
  9938. try
  9939. {
  9940. stopwatch1.Start();
  9941. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  9942. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  9943. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  9944. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  9945. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  9946. stopwatch2.Start();
  9947. #region 查询载具上的产品信息
  9948. string cavityData = string.Empty;
  9949. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  9950. if (string.IsNullOrEmpty(cavityData))
  9951. cavityData = "";
  9952. if (snResult != 0)
  9953. {
  9954. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9955. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  9956. writeToPLC_Flag1.Adress = 2115;
  9957. writeToPLC_Flag1.Value = (short)6;
  9958. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  9959. stopwatch1.Stop();
  9960. AddMessage(LogType.Info,
  9961. stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9962. "ms");
  9963. return;
  9964. }
  9965. #endregion 查询载具上的产品信息
  9966. // 产品换载具
  9967. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  9968. string partSn1 = "";
  9969. string partSn2 = "";
  9970. if (cavitySNs != null && cavitySNs.Length >= 2)
  9971. {
  9972. partSn1 = cavitySNs[0];
  9973. partSn2 = cavitySNs[1];
  9974. }
  9975. string data_new = string.Empty;
  9976. // 是否是两个穴位交换
  9977. if (c1CavityReverse_Bind == 1)
  9978. {
  9979. // 交换
  9980. data_new = string.Concat(partSn2, ".", partSn1);
  9981. }
  9982. else
  9983. {
  9984. // 不交换
  9985. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  9986. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  9987. cavitySNs[c1VehicleCavityFr_Bind] = "";
  9988. data_new = string.Join(".", cavitySNs);
  9989. }
  9990. // 删除再插入
  9991. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  9992. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  9993. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  9994. stopwatch2.Stop();
  9995. short c1MES_FLAG_Bind = 1;
  9996. // MES_Flag
  9997. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9998. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9999. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  10000. writeToPLC_Flag.Adress = 2115;
  10001. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  10002. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  10003. }
  10004. catch (Exception ex)
  10005. {
  10006. string str = ex.StackTrace;
  10007. AddMessage_Station(stationNameStr, LogType.Error,
  10008. $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" +
  10009. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10010. // MES_Flag
  10011. stopwatch2.Start();
  10012. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  10013. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10014. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  10015. writeToPLC_Flag.Adress = 2115;
  10016. writeToPLC_Flag.Value = (short)6;
  10017. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  10018. stopwatch2.Stop();
  10019. }
  10020. stopwatch1.Stop();
  10021. AddMessage(LogType.Info,
  10022. stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10023. stopwatch2.ElapsedMilliseconds + "ms");
  10024. }
  10025. //// 上次采集到的SN
  10026. //private string sn_值板机 = string.Empty;
  10027. /// <summary>
  10028. /// [S3] 值板机 - 出站接口
  10029. /// </summary>
  10030. /// <param name="plcNo">PLC编号</param>
  10031. private void S3出站接口(int plcNo, string stationCode, string stationName)
  10032. {
  10033. Stopwatch stopwatch1 = new Stopwatch();
  10034. Stopwatch stopwatch2 = new Stopwatch();
  10035. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10036. string stationNameStr = stationCode + stationName;
  10037. string processItem = stationName; // 测试项目
  10038. try
  10039. {
  10040. stopwatch1.Start();
  10041. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10042. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10043. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10044. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10045. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  10046. sn = sn.Replace("\0", "");
  10047. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  10048. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  10049. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  10050. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  10051. bool pass = c1Result == 1;
  10052. // 查sn
  10053. #region 查询载具上的产品信息
  10054. string cavityData = string.Empty;
  10055. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  10056. if (string.IsNullOrEmpty(cavityData))
  10057. cavityData = "";
  10058. if (snResult != 0)
  10059. {
  10060. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10061. writeToPLC_Flag1.Name = "c1MES_FLAG";
  10062. writeToPLC_Flag1.Adress = 2150;
  10063. writeToPLC_Flag1.Value = (short)4;
  10064. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  10065. stopwatch1.Stop();
  10066. AddMessage(LogType.Info,
  10067. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10068. return;
  10069. }
  10070. #endregion 查询载具上的产品信息
  10071. string[] cavitySNs = cavityData.Split('.');
  10072. string productSN = "";
  10073. if (cavitySNs != null && cavitySNs.Length >= 2)
  10074. {
  10075. productSN = cavitySNs[c1VehicleCavity];
  10076. cavitySNs[c1VehicleCavity] = "";
  10077. }
  10078. stopwatch2.Start();
  10079. List<TestItem> items = new List<TestItem>();
  10080. items.Add(new TestItem()
  10081. {
  10082. Parameter_name = "二穴载具码",
  10083. Parameter_value = c1ProductSN_Check,
  10084. Parameter_unit = ""
  10085. });
  10086. items.Add(new TestItem()
  10087. {
  10088. Parameter_name = "二穴载具穴号",
  10089. Parameter_value = c1VehicleCavity.ToString(),
  10090. Parameter_unit = ""
  10091. });
  10092. items.Add(new TestItem()
  10093. {
  10094. Parameter_name = "一穴载具码",
  10095. Parameter_value = sn,
  10096. Parameter_unit = ""
  10097. });
  10098. items.Add(new TestItem()
  10099. {
  10100. Parameter_name = "一穴载具穴号",
  10101. Parameter_value = "1",
  10102. Parameter_unit = ""
  10103. });
  10104. items.Add(new TestItem()
  10105. {
  10106. Parameter_name = "产品结果",
  10107. Parameter_value = c1Result == 1 ? "OK" : "NG",
  10108. Parameter_unit = ""
  10109. });
  10110. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  10111. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  10112. short result = (short)result1;
  10113. stopwatch2.Stop();
  10114. #region 存储绑定数据到 边线MES系统中
  10115. if (result == 1)
  10116. {
  10117. string data = string.Concat(productSN);
  10118. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  10119. if (resultMesR != 0)
  10120. {
  10121. result = 4;
  10122. AddMessage_Station(stationNameStr, LogType.Error,
  10123. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  10124. }
  10125. }
  10126. #endregion 存储绑定数据到 边线MES系统中
  10127. #region 产品从 来源载具(二穴载具)中删除
  10128. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  10129. {
  10130. // 删除
  10131. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  10132. OnMessage(LogType.Debug,
  10133. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  10134. }
  10135. else
  10136. {
  10137. string data_new = string.Join(".", cavitySNs);
  10138. // 删除再插入
  10139. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  10140. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  10141. OnMessage(LogType.Debug,
  10142. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  10143. }
  10144. #endregion 产品从 来源载具(二穴载具)中删除
  10145. // MES_Flag 为MES报错
  10146. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10147. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  10148. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10149. writeToPLC_Flag.Name = "c1MES_FLAG";
  10150. writeToPLC_Flag.Adress = 2150;
  10151. writeToPLC_Flag.Value = result;
  10152. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  10153. OnMessage(LogType.Debug,
  10154. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  10155. }
  10156. catch (Exception ex)
  10157. {
  10158. stopwatch2.Restart();
  10159. // MES_Flag 为4上位机报错
  10160. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  10161. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10162. writeToPLC_Flag.Name = "c1MES_FLAG";
  10163. writeToPLC_Flag.Adress = 2150;
  10164. writeToPLC_Flag.Value = (short)4;
  10165. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  10166. stopwatch2.Stop();
  10167. string str = ex.StackTrace;
  10168. AddMessage_Station(stationNameStr, LogType.Error,
  10169. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10170. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10171. }
  10172. stopwatch1.Stop();
  10173. AddMessage(LogType.Info,
  10174. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10175. stopwatch2.ElapsedMilliseconds + "ms");
  10176. }
  10177. /// <summary>
  10178. /// [S3] 值板机- 节拍接口
  10179. /// </summary>
  10180. /// <param name="plcNo">PLC编号</param>
  10181. /// <param name="stationNameStr">工站全称</param>
  10182. private void S3节拍接口(int plcNo, string stationNameStr, string tagMesCommName, string CarrierBarcode,
  10183. IoT_DataSet_t iot_data)
  10184. {
  10185. Stopwatch stopwatch1 = new Stopwatch();
  10186. Stopwatch stopwatch2 = new Stopwatch();
  10187. string resultStr = string.Empty;
  10188. try
  10189. {
  10190. stopwatch1.Start();
  10191. string oEEType = iot_data.BeatAction.ToString(); // 节拍类型(plc写入)
  10192. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode); //产品SN
  10193. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  10194. if (!actionBool)
  10195. {
  10196. stopwatch2.Start();
  10197. //写入PLC
  10198. IoT_DataSet_t iotData = new IoT_DataSet_t();
  10199. iotData.machineState = iot_data.machineState;
  10200. iotData.work_type = iot_data.work_type;
  10201. iotData.testStatus = iot_data.testStatus;
  10202. iotData.BeatAction = iot_data.BeatAction;
  10203. iotData.beatReturn = 2; //NG
  10204. iotData.fault_codes = iot_data.fault_codes;
  10205. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  10206. stopwatch2.Stop();
  10207. AddMessage(LogType.Info,
  10208. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  10209. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  10210. return;
  10211. }
  10212. //作业开始后要有物料和载具信息
  10213. if (string.IsNullOrEmpty(strProductBarcode) && string.IsNullOrEmpty(CarrierBarcode) &&
  10214. Convert.ToInt32(oEEType) > 2)
  10215. {
  10216. stopwatch2.Start();
  10217. //写入PLC
  10218. IoT_DataSet_t iotData = new IoT_DataSet_t();
  10219. iotData.machineState = iot_data.machineState;
  10220. iotData.work_type = iot_data.work_type;
  10221. iotData.testStatus = iot_data.testStatus;
  10222. iotData.BeatAction = iot_data.BeatAction;
  10223. iotData.beatReturn = 2; //NG
  10224. iotData.fault_codes = iot_data.fault_codes;
  10225. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  10226. stopwatch2.Stop();
  10227. AddMessage_Station(stationNameStr, LogType.Info,
  10228. stationNameStr + $"_[{CarrierBarcode}][{strProductBarcode}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  10229. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  10230. return;
  10231. }
  10232. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(strProductBarcode))
  10233. {
  10234. stopwatch2.Start();
  10235. //写入PLC
  10236. IoT_DataSet_t iotData = new IoT_DataSet_t();
  10237. iotData.machineState = iot_data.machineState;
  10238. iotData.work_type = iot_data.work_type;
  10239. iotData.testStatus = iot_data.testStatus;
  10240. iotData.BeatAction = iot_data.BeatAction;
  10241. iotData.beatReturn = 2; //NG
  10242. iotData.fault_codes = iot_data.fault_codes;
  10243. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  10244. stopwatch2.Stop();
  10245. AddMessage_Station(stationNameStr, LogType.Info,
  10246. stationNameStr + $"_[{CarrierBarcode}]上传节拍失败!物料码不可为空;总用时" +
  10247. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  10248. return;
  10249. }
  10250. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(CarrierBarcode))
  10251. {
  10252. stopwatch2.Start();
  10253. //写入PLC
  10254. IoT_DataSet_t iotData = new IoT_DataSet_t();
  10255. iotData.machineState = iot_data.machineState;
  10256. iotData.work_type = iot_data.work_type;
  10257. iotData.testStatus = iot_data.testStatus;
  10258. iotData.BeatAction = iot_data.BeatAction;
  10259. iotData.beatReturn = 2; //NG
  10260. iotData.fault_codes = iot_data.fault_codes;
  10261. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  10262. stopwatch2.Stop();
  10263. AddMessage_Station(stationNameStr, LogType.Info,
  10264. stationNameStr + $"_上传节拍失败!载具码不可为空;总用时" +
  10265. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  10266. return;
  10267. }
  10268. short _result = 0;
  10269. // 上传OEE
  10270. (short, string) result =
  10271. SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  10272. _result = result.Item1;
  10273. resultStr = result.Item2;
  10274. if (_result == 1)
  10275. {
  10276. stopwatch2.Start();
  10277. //写入PLC
  10278. IoT_DataSet_t iotData = new IoT_DataSet_t();
  10279. iotData.machineState = iot_data.machineState;
  10280. iotData.work_type = iot_data.work_type;
  10281. iotData.testStatus = iot_data.testStatus;
  10282. iotData.BeatAction = iot_data.BeatAction;
  10283. iotData.beatReturn = 1; //OK
  10284. iotData.fault_codes = iot_data.fault_codes;
  10285. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  10286. OnMessage(LogType.Info,
  10287. $"PLC{plcNo}_{stationNameStr} 节拍{iotData.BeatAction}上传IOT成功!上传结果:" + resultStr);
  10288. stopwatch2.Stop();
  10289. }
  10290. else
  10291. {
  10292. stopwatch2.Start();
  10293. //写入PLC
  10294. IoT_DataSet_t iotData = new IoT_DataSet_t();
  10295. iotData.machineState = iot_data.machineState;
  10296. iotData.work_type = iot_data.work_type;
  10297. iotData.testStatus = iot_data.testStatus;
  10298. iotData.BeatAction = iot_data.BeatAction;
  10299. iotData.beatReturn = 2; //NG
  10300. iotData.fault_codes = iot_data.fault_codes;
  10301. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  10302. stopwatch2.Stop();
  10303. AddMessage_Station(stationNameStr, LogType.Error,
  10304. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  10305. }
  10306. }
  10307. catch (Exception ex)
  10308. {
  10309. string str = ex.StackTrace;
  10310. AddMessage_Station(stationNameStr, LogType.Error,
  10311. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  10312. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10313. // MES_Flag
  10314. stopwatch2.Start();
  10315. //写入PLC
  10316. IoT_DataSet_t iotData = new IoT_DataSet_t();
  10317. iotData.machineState = iot_data.machineState;
  10318. iotData.work_type = iot_data.work_type;
  10319. iotData.testStatus = iot_data.testStatus;
  10320. iotData.BeatAction = iot_data.BeatAction;
  10321. iotData.beatReturn = 2; //NG
  10322. iotData.fault_codes = iot_data.fault_codes;
  10323. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  10324. stopwatch2.Stop();
  10325. }
  10326. stopwatch1.Stop();
  10327. AddMessage(LogType.Info,
  10328. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10329. stopwatch2.ElapsedMilliseconds + "ms");
  10330. }
  10331. #endregion [S3] 值板机
  10332. #endregion PLC3 刘永村
  10333. #region PLC4 刘果段
  10334. #region [S4] 取放桁架
  10335. /// <summary>
  10336. /// S4工位的数据- 触发信号上次的值
  10337. /// </summary>
  10338. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  10339. /// <summary>
  10340. /// S4工位的数据(含触发信号)
  10341. /// </summary>
  10342. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  10343. /// <summary>
  10344. /// S4工位的数据- 回写点位
  10345. /// </summary>
  10346. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  10347. /// <summary>
  10348. /// [S4] 取放桁架
  10349. /// </summary>
  10350. /// <param name="plcNo">PLC编号</param>
  10351. //private void ReadStation_S4(int plcNo)
  10352. //{
  10353. // // [S1] Tray盘上料装备
  10354. // // [S2] FCT
  10355. // // [S3] 值板机
  10356. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  10357. // // [S5] Tray盘下料装备
  10358. // /// 上位机心跳
  10359. // /// 获取设备报警数据与状态信息
  10360. // string stationCode = "[S4_1]";
  10361. // string stationName = "载具下线装备";
  10362. // string stationNameStr = stationCode + stationName;
  10363. // string stationCode2 = "[S4_2]";
  10364. // string stationName2 = "桁架";
  10365. // string stationNameStr2 = stationCode2 + stationName2;
  10366. // string stationCode3 = "[S4_3]";
  10367. // string stationName3 = "提升机1";
  10368. // string stationNameStr3 = stationCode3 + stationName3;
  10369. // string stationCode4 = "[S4_4]";
  10370. // string stationName4 = "提升机2";
  10371. // string stationNameStr4 = stationCode4 + stationName4;
  10372. // string stationCode5 = "[S4_5]";
  10373. // string stationName5 = "载具上线装备";
  10374. // string stationNameStr5 = stationCode5 + stationName5;
  10375. // #region 创建字典
  10376. // // 触发信号字典 赋值
  10377. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  10378. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  10379. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  10380. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  10381. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  10382. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  10383. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  10384. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  10385. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  10386. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  10387. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  10388. // // PLC数据字典 赋值
  10389. // // 载具下线装备(弹夹上线)
  10390. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  10391. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  10392. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  10393. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  10394. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  10395. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  10396. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  10397. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  10398. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  10399. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  10400. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  10401. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  10402. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  10403. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  10404. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  10405. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  10406. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  10407. // s4PLCData.Add("d1Result", 0); // 产品结果
  10408. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  10409. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  10410. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  10411. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  10412. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  10413. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  10414. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  10415. // // 真空标机(提升机)
  10416. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  10417. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  10418. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  10419. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  10420. // s4PLCData.Add("d3Result", 0); // 产品结果
  10421. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  10422. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  10423. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  10424. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  10425. // s4PLCData.Add("d4Result", 0); // 产品结果
  10426. // // 载具上线装备(弹夹下线)
  10427. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  10428. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  10429. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  10430. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  10431. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  10432. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  10433. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  10434. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  10435. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  10436. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  10437. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  10438. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  10439. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  10440. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  10441. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  10442. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  10443. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  10444. // s4PLCData.Add("d5Result", 0); // 产品结果
  10445. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  10446. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  10447. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  10448. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  10449. // #endregion 创建字典
  10450. // while (IsRun)
  10451. // {
  10452. // try
  10453. // {
  10454. // if (!GlobalContext._IsCon_Funs4)
  10455. // {
  10456. // UpdatePLCMonitor(1, plcNo, 0);
  10457. // continue;
  10458. // }
  10459. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  10460. // {
  10461. // Stopwatch stopwatch1 = new Stopwatch();
  10462. // Stopwatch stopwatch2 = new Stopwatch();
  10463. // stopwatch1.Start();
  10464. // stopwatch2.Start();
  10465. // #region 一次性读取所有数据
  10466. // // 载具下线装备(弹夹上线)
  10467. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  10468. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  10469. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  10470. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  10471. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  10472. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  10473. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  10474. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  10475. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  10476. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  10477. // int[] datas = data1.Concat(data2).ToArray();
  10478. // datas = datas.Concat(data3).ToArray();
  10479. // datas = datas.Concat(data4).ToArray();
  10480. // datas = datas.Concat(data5).ToArray();
  10481. // datas = datas.Concat(data6).ToArray();
  10482. // datas = datas.Concat(data7).ToArray();
  10483. // datas = datas.Concat(data8).ToArray();
  10484. // datas = datas.Concat(data9).ToArray();
  10485. // datas = datas.Concat(data10).ToArray();
  10486. // // 载具下线装备(弹夹上线)
  10487. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  10488. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  10489. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  10490. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  10491. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  10492. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  10493. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  10494. // s4PLCData["d1MES_FLAG"] = datas[65];
  10495. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  10496. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  10497. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  10498. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  10499. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  10500. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  10501. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  10502. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  10503. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  10504. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  10505. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  10506. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  10507. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  10508. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  10509. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  10510. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  10511. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  10512. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  10513. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  10514. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  10515. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  10516. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  10517. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  10518. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  10519. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  10520. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  10521. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  10522. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  10523. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  10524. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  10525. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  10526. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  10527. // s4PLCData["d1Result"] = datas[386];
  10528. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  10529. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  10530. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  10531. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  10532. // s4PLCData["d1OEEType"] = datas[419];
  10533. // // 桁架(查询标机中弹夹的状态)
  10534. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  10535. // s4PLCData["d2BulletclipStates"] = datas[431];
  10536. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  10537. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  10538. // // 真空标机
  10539. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  10540. // s4PLCData["d3MES_FLAG"] = datas[463];
  10541. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  10542. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  10543. // s4PLCData["d3Result"] = datas[484];
  10544. // s4PLCData["d3Type"] = datas[485];
  10545. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  10546. // s4PLCData["d4MES_FLAG"] = datas[496];
  10547. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  10548. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  10549. // s4PLCData["d4Result"] = datas[517];
  10550. // s4PLCData["d4Type"] = datas[518];
  10551. // // 载具上线装备(弹夹下线)
  10552. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  10553. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  10554. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  10555. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  10556. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  10557. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  10558. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  10559. // s4PLCData["d5MES_FLAG"] = datas[591];
  10560. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  10561. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  10562. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  10563. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  10564. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  10565. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  10566. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  10567. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  10568. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  10569. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  10570. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  10571. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  10572. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  10573. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  10574. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  10575. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  10576. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  10577. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  10578. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  10579. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  10580. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  10581. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  10582. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  10583. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  10584. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  10585. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  10586. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  10587. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  10588. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  10589. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  10590. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  10591. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  10592. // s4PLCData["d5Result"] = datas[912];
  10593. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  10594. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  10595. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  10596. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  10597. // s4PLCData["d5OEEType"] = datas[945];
  10598. // #endregion 一次性读取所有数据
  10599. // stopwatch2.Stop();
  10600. // #region 回写操作,写后清空flag
  10601. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  10602. // #endregion 回写操作,写后清空flag
  10603. // // N801A-S4_1 弹夹扫码
  10604. // #region N801A-S4_1 弹夹扫码
  10605. // try
  10606. // {
  10607. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  10608. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  10609. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  10610. // {
  10611. // if (d1BulletclipScanCode == 1) // 0->1
  10612. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  10613. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  10614. // }
  10615. // }
  10616. // catch (Exception ex)
  10617. // {
  10618. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  10619. // string str = ex.StackTrace;
  10620. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10621. // }
  10622. // #endregion N801A-S4_1 弹夹扫码
  10623. // // N801A-S4_1 载具扫码
  10624. // #region N801A-S4_1 载具扫码
  10625. // try
  10626. // {
  10627. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  10628. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  10629. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  10630. // {
  10631. // if (d1VehicleScanCode == 1) // 0->1
  10632. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  10633. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  10634. // }
  10635. // }
  10636. // catch (Exception ex)
  10637. // {
  10638. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  10639. // string str = ex.StackTrace;
  10640. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10641. // }
  10642. // #endregion N801A-S4_1 载具扫码
  10643. // // N801A-S4_1 出站接口
  10644. // #region N801A-S4_1 出站接口
  10645. // try
  10646. // {
  10647. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  10648. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  10649. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  10650. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  10651. // {
  10652. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  10653. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  10654. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  10655. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  10656. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  10657. // }
  10658. // }
  10659. // catch (Exception ex)
  10660. // {
  10661. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  10662. // string str = ex.StackTrace;
  10663. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10664. // }
  10665. // #endregion N801A-S4_1 出站接口
  10666. // // N801A-S4_1 节拍接口
  10667. // #region N801A-S4_1 节拍接口
  10668. // try
  10669. // {
  10670. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  10671. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  10672. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  10673. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  10674. // {
  10675. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  10676. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  10677. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  10678. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  10679. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  10680. // }
  10681. // }
  10682. // catch (Exception ex)
  10683. // {
  10684. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  10685. // string str = ex.StackTrace;
  10686. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10687. // }
  10688. // #endregion N801A-S4_1 节拍接口
  10689. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  10690. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  10691. // try
  10692. // {
  10693. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  10694. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  10695. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  10696. // {
  10697. // if (d2BulletclipScanCode == 1) // 0->1
  10698. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  10699. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  10700. // }
  10701. // }
  10702. // catch (Exception ex)
  10703. // {
  10704. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  10705. // string str = ex.StackTrace;
  10706. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10707. // }
  10708. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  10709. // // N801A-S4_3 真空标机1 数据
  10710. // #region N801A-S4_3 真空标机1
  10711. // try
  10712. // {
  10713. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  10714. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  10715. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  10716. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  10717. // {
  10718. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  10719. // {
  10720. // int stationType = (int)s4PLCData["d3Type"];
  10721. // if (stationType == 1)
  10722. // {
  10723. // // S4_3进站接口
  10724. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  10725. // }
  10726. // else if (stationType == 2)
  10727. // {
  10728. // // S4_3出站接口
  10729. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  10730. // }
  10731. // }
  10732. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  10733. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  10734. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  10735. // }
  10736. // }
  10737. // catch (Exception ex)
  10738. // {
  10739. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  10740. // string str = ex.StackTrace;
  10741. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10742. // }
  10743. // #endregion N801A-S4_3 真空标机1
  10744. // // N801A-S4_4 真空标机2 数据
  10745. // #region N801A-S4_4 真空标机2
  10746. // try
  10747. // {
  10748. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  10749. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  10750. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  10751. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  10752. // {
  10753. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  10754. // {
  10755. // int stationType = (int)s4PLCData["d4Type"];
  10756. // if (stationType == 1)
  10757. // {
  10758. // // S4_4进站接口
  10759. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  10760. // }
  10761. // else if (stationType == 2)
  10762. // {
  10763. // // S4_4出站接口
  10764. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  10765. // }
  10766. // }
  10767. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  10768. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  10769. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  10770. // }
  10771. // }
  10772. // catch (Exception ex)
  10773. // {
  10774. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  10775. // string str = ex.StackTrace;
  10776. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10777. // }
  10778. // #endregion N801A-S4_4 真空标机2
  10779. // // N801A-S4_5 弹夹扫码 数据
  10780. // #region N801A-S4_5 弹夹扫码
  10781. // try
  10782. // {
  10783. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  10784. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  10785. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  10786. // {
  10787. // if (d5BulletclipScanCode == 1) // 0->1
  10788. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  10789. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  10790. // }
  10791. // }
  10792. // catch (Exception ex)
  10793. // {
  10794. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  10795. // string str = ex.StackTrace;
  10796. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10797. // }
  10798. // #endregion N801A-S4_5 弹夹扫码
  10799. // // N801A-S4_5 载具扫码 数据
  10800. // #region N801A-S4_5 载具扫码
  10801. // try
  10802. // {
  10803. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  10804. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  10805. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  10806. // {
  10807. // if (d5VehicleScanCode == 1) // 0->1
  10808. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  10809. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  10810. // }
  10811. // }
  10812. // catch (Exception ex)
  10813. // {
  10814. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  10815. // string str = ex.StackTrace;
  10816. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10817. // }
  10818. // #endregion N801A-S4_5 载具扫码
  10819. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  10820. // #region N801A-S4_5 出站接口
  10821. // try
  10822. // {
  10823. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  10824. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  10825. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  10826. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  10827. // {
  10828. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  10829. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  10830. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  10831. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  10832. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  10833. // }
  10834. // }
  10835. // catch (Exception ex)
  10836. // {
  10837. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  10838. // string str = ex.StackTrace;
  10839. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10840. // }
  10841. // #endregion N801A-S4_5 出站接口
  10842. // // N801A-S4_5 节拍接口 数据
  10843. // #region N801A-S4_5 节拍接口
  10844. // try
  10845. // {
  10846. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  10847. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  10848. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  10849. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  10850. // {
  10851. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  10852. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  10853. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  10854. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  10855. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  10856. // }
  10857. // }
  10858. // catch (Exception ex)
  10859. // {
  10860. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  10861. // string str = ex.StackTrace;
  10862. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10863. // }
  10864. // #endregion N801A-S4_5 节拍接口
  10865. // #region 心跳
  10866. // try
  10867. // {
  10868. // short states = 0;
  10869. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  10870. // }
  10871. // catch (Exception ex)
  10872. // {
  10873. // string str = ex.StackTrace;
  10874. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10875. // }
  10876. // #endregion 心跳
  10877. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  10878. // stopwatch1.Stop();
  10879. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  10880. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  10881. // }
  10882. // else
  10883. // {
  10884. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  10885. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  10886. // Funs[plcNo].Connect();
  10887. // }
  10888. // }
  10889. // catch (Exception ex)
  10890. // {
  10891. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  10892. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  10893. // Funs[plcNo].ReConnect();
  10894. // }
  10895. // Thread.Sleep(IntervalReadPLC);
  10896. // }
  10897. //}
  10898. /// <summary>
  10899. /// [S4] 取放桁架 - S4_1弹夹扫码
  10900. /// </summary>
  10901. /// <param name="plcNo">PLC编号</param>
  10902. /// <param name="stationNameStr">工站全称</param>
  10903. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  10904. {
  10905. Stopwatch stopwatch1 = new Stopwatch();
  10906. Stopwatch stopwatch2 = new Stopwatch();
  10907. try
  10908. {
  10909. stopwatch1.Start();
  10910. // ZS 弹夹扫码
  10911. string d1BulletclipCode = " "; // 扫到的码
  10912. short d1BulletclipScanCode = 2;
  10913. stopwatch2.Start();
  10914. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  10915. //// MES_Flag
  10916. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10917. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10918. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  10919. writeToPLC_Flag.Adress = 2002;
  10920. writeToPLC_Flag.Value = d1BulletclipScanCode;
  10921. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  10922. {
  10923. Name = "d1BulletclipCode",
  10924. Adress = 2003,
  10925. ValueType = PLCValueType.String,
  10926. ValueTypeStrLength = 20,
  10927. Value = d1BulletclipCode
  10928. });
  10929. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  10930. stopwatch2.Stop();
  10931. }
  10932. catch (Exception ex)
  10933. {
  10934. string str = ex.StackTrace;
  10935. AddMessage_Station(stationNameStr, LogType.Error,
  10936. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10937. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10938. stopwatch2.Start();
  10939. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  10940. //// MES_Flag
  10941. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  10942. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10943. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  10944. writeToPLC_Flag.Adress = 2002;
  10945. writeToPLC_Flag.Value = (short)6;
  10946. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  10947. {
  10948. Name = "d1BulletclipCode",
  10949. Adress = 2003,
  10950. ValueType = PLCValueType.String,
  10951. ValueTypeStrLength = 20,
  10952. Value = " "
  10953. });
  10954. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  10955. stopwatch2.Stop();
  10956. }
  10957. stopwatch1.Stop();
  10958. AddMessage(LogType.Info,
  10959. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10960. stopwatch2.ElapsedMilliseconds + "ms");
  10961. }
  10962. /// <summary>
  10963. /// [S4] 取放桁架 - S4_1载具扫码
  10964. /// </summary>
  10965. /// <param name="plcNo">PLC编号</param>
  10966. /// <param name="stationNameStr">工站全称</param>
  10967. private void S4_1载具扫码(int plcNo, string stationNameStr)
  10968. {
  10969. Stopwatch stopwatch1 = new Stopwatch();
  10970. Stopwatch stopwatch2 = new Stopwatch();
  10971. try
  10972. {
  10973. stopwatch1.Start();
  10974. // ZS 载具扫码
  10975. string d1VehicleCode = ""; // 扫到的码
  10976. short d1VehicleScanCode = 2;
  10977. #region 进站
  10978. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  10979. {
  10980. #region 查询载具上的产品信息
  10981. string cavityData = string.Empty;
  10982. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  10983. if (string.IsNullOrEmpty(cavityData))
  10984. cavityData = "";
  10985. if (snResult != 0)
  10986. {
  10987. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10988. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  10989. writeToPLC_Flag1.Adress = 2033;
  10990. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  10991. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10992. {
  10993. Name = "d1VehicleCode",
  10994. Adress = 2034,
  10995. ValueType = PLCValueType.String,
  10996. ValueTypeStrLength = 20,
  10997. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  10998. });
  10999. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  11000. stopwatch1.Stop();
  11001. AddMessage(LogType.Info,
  11002. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  11003. "ms");
  11004. return;
  11005. }
  11006. string[] cavitySNs = cavityData.Split('.');
  11007. string partNo = "";
  11008. if (cavitySNs != null && cavitySNs.Length >= 1)
  11009. {
  11010. partNo = cavitySNs[0];
  11011. }
  11012. #endregion 查询载具上的产品信息
  11013. List<TestItem> item = new List<TestItem>();
  11014. item.Add(new TestItem()
  11015. {
  11016. Parameter_name = "载具码",
  11017. Parameter_value = d1VehicleCode,
  11018. });
  11019. item.Add(new TestItem()
  11020. {
  11021. Parameter_name = "载具穴号",
  11022. Parameter_value = "1",
  11023. });
  11024. stopwatch2.Start();
  11025. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  11026. partNo, item, out string errorMsg);
  11027. stopwatch2.Stop();
  11028. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  11029. }
  11030. #endregion 进站
  11031. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  11032. //// MES_Flag
  11033. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  11034. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11035. writeToPLC_Flag.Name = "d1VehicleScanCode";
  11036. writeToPLC_Flag.Adress = 2033;
  11037. writeToPLC_Flag.Value = d1VehicleScanCode;
  11038. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  11039. {
  11040. Name = "d1VehicleCode",
  11041. Adress = 2034,
  11042. ValueType = PLCValueType.String,
  11043. ValueTypeStrLength = 20,
  11044. Value = d1VehicleCode
  11045. });
  11046. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  11047. }
  11048. catch (Exception ex)
  11049. {
  11050. string str = ex.StackTrace;
  11051. AddMessage_Station(stationNameStr, LogType.Error,
  11052. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  11053. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11054. stopwatch2.Start();
  11055. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  11056. //// MES_Flag
  11057. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  11058. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11059. writeToPLC_Flag.Name = "d1VehicleScanCode";
  11060. writeToPLC_Flag.Adress = 2033;
  11061. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  11062. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  11063. {
  11064. Name = "d1VehicleCode",
  11065. Adress = 2034,
  11066. ValueType = PLCValueType.String,
  11067. ValueTypeStrLength = 20,
  11068. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  11069. });
  11070. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  11071. stopwatch2.Stop();
  11072. }
  11073. stopwatch1.Stop();
  11074. AddMessage(LogType.Info,
  11075. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11076. stopwatch2.ElapsedMilliseconds + "ms");
  11077. }
  11078. // 上次采集到的SN
  11079. //private string sn_S4_1出站接口 = string.Empty;
  11080. /// <summary>
  11081. /// [S4] 取放桁架 - S4_1出站接口
  11082. /// </summary>
  11083. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  11084. {
  11085. Stopwatch stopwatch1 = new Stopwatch();
  11086. Stopwatch stopwatch2 = new Stopwatch();
  11087. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  11088. string stationNameStr = stationCode + stationName;
  11089. string processItem = stationName; // 测试项目
  11090. try
  11091. {
  11092. stopwatch1.Start();
  11093. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  11094. //string batch_num = GlobalContext.BatchNumber; // 批次号
  11095. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  11096. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  11097. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  11098. sn = sn.Replace("\0", "");
  11099. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  11100. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  11101. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  11102. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  11103. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  11104. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  11105. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  11106. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  11107. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  11108. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  11109. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  11110. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  11111. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  11112. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  11113. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  11114. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  11115. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  11116. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  11117. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  11118. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  11119. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  11120. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  11121. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  11122. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  11123. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  11124. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  11125. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  11126. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  11127. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  11128. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  11129. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  11130. bool pass = d1Result == 1;
  11131. // 存 载具SN列表
  11132. List<string> vehicleCodes = new List<string>()
  11133. {
  11134. d1VehicleCode1, d1VehicleCode2, d1VehicleCode3, d1VehicleCode4, d1VehicleCode5,
  11135. d1VehicleCode6, d1VehicleCode7, d1VehicleCode8, d1VehicleCode9, d1VehicleCode10,
  11136. d1VehicleCode11, d1VehicleCode12, d1VehicleCode13, d1VehicleCode14, d1VehicleCode15
  11137. };
  11138. // 统一查 产品SN列表
  11139. List<string> partNos = new List<string>();
  11140. foreach (string vehicleCode in vehicleCodes)
  11141. {
  11142. if (string.IsNullOrEmpty(vehicleCode))
  11143. partNos.Add("");
  11144. else
  11145. {
  11146. string partNo = "";
  11147. #region 查询载具上的产品信息
  11148. string cavityData = string.Empty;
  11149. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  11150. if (string.IsNullOrEmpty(cavityData))
  11151. cavityData = "";
  11152. if (snResult != 0)
  11153. {
  11154. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11155. writeToPLC_Flag1.Name = "d1MES_FLAG";
  11156. writeToPLC_Flag1.Adress = 2065;
  11157. writeToPLC_Flag1.Value = (short)4;
  11158. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  11159. stopwatch1.Stop();
  11160. AddMessage(LogType.Info,
  11161. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  11162. "ms");
  11163. return;
  11164. }
  11165. string[] cavitySNs = cavityData.Split('.');
  11166. if (cavitySNs != null && cavitySNs.Length >= 1)
  11167. partNo = cavitySNs[0];
  11168. #endregion 查询载具上的产品信息
  11169. partNos.Add(partNo);
  11170. }
  11171. }
  11172. // 统一上传
  11173. stopwatch2.Start();
  11174. List<int> results = new List<int>();
  11175. for (int i = 0; i < partNos.Count; i++)
  11176. {
  11177. string index = (i + 1).ToString(); // 弹夹穴号
  11178. if (string.IsNullOrEmpty(partNos[i]))
  11179. results.Add(1);
  11180. else
  11181. {
  11182. List<TestItem> items1 = new List<TestItem>();
  11183. items1.Add(new TestItem()
  11184. {
  11185. Parameter_name = "弹夹码",
  11186. Parameter_value = sn,
  11187. Parameter_unit = ""
  11188. });
  11189. items1.Add(new TestItem()
  11190. {
  11191. Parameter_name = "弹夹穴号",
  11192. Parameter_value = index,
  11193. Parameter_unit = ""
  11194. });
  11195. items1.Add(new TestItem()
  11196. {
  11197. Parameter_name = "载具码",
  11198. Parameter_value = vehicleCodes[i],
  11199. Parameter_unit = ""
  11200. });
  11201. items1.Add(new TestItem()
  11202. {
  11203. Parameter_name = "载具穴号",
  11204. Parameter_value = "1",
  11205. Parameter_unit = ""
  11206. });
  11207. items1.Add(new TestItem()
  11208. {
  11209. Parameter_name = "产品结果",
  11210. Parameter_value = d1Result == 1 ? "OK" : "NG",
  11211. Parameter_unit = ""
  11212. });
  11213. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  11214. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  11215. results.Add(result1);
  11216. }
  11217. }
  11218. short result = 0;
  11219. if (results.All(a => a == 1))
  11220. result = 1;
  11221. else if (results.Contains(3))
  11222. result = 3;
  11223. else if (results.Contains(2))
  11224. result = 2;
  11225. else if (results.Contains(4))
  11226. result = 4;
  11227. else
  11228. result = 4;
  11229. stopwatch2.Stop();
  11230. #region 存储绑定数据到 边线MES系统中
  11231. if (result == 1)
  11232. {
  11233. string data = string.Join(".", vehicleCodes);
  11234. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  11235. if (resultMesR != 0)
  11236. {
  11237. result = 4;
  11238. AddMessage_Station(stationNameStr, LogType.Error,
  11239. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  11240. }
  11241. }
  11242. #endregion 存储绑定数据到 边线MES系统中
  11243. // MES_Flag 为4MES报错
  11244. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11245. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11246. writeToPLC_Flag.Name = "d1MES_FLAG";
  11247. writeToPLC_Flag.Adress = 2065;
  11248. writeToPLC_Flag.Value = result;
  11249. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  11250. OnMessage(LogType.Debug,
  11251. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  11252. }
  11253. catch (Exception ex)
  11254. {
  11255. stopwatch2.Restart();
  11256. // MES_Flag 为4上位机报错
  11257. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  11258. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11259. writeToPLC_Flag.Name = "d1MES_FLAG";
  11260. writeToPLC_Flag.Adress = 2065;
  11261. writeToPLC_Flag.Value = (short)4;
  11262. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  11263. stopwatch2.Stop();
  11264. string str = ex.StackTrace;
  11265. AddMessage_Station(stationNameStr, LogType.Error,
  11266. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11267. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11268. }
  11269. stopwatch1.Stop();
  11270. AddMessage(LogType.Info,
  11271. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11272. stopwatch2.ElapsedMilliseconds + "ms");
  11273. }
  11274. /// <summary>
  11275. /// [S4] 取放桁架 - S4_1节拍接口
  11276. /// </summary>
  11277. /// <param name="plcNo">PLC编号</param>
  11278. /// <param name="stationNameStr">工站全称</param>
  11279. private void S4_1节拍接口(int plcNo, string stationNameStr)
  11280. {
  11281. Stopwatch stopwatch1 = new Stopwatch();
  11282. Stopwatch stopwatch2 = new Stopwatch();
  11283. string resultStr = string.Empty;
  11284. try
  11285. {
  11286. stopwatch1.Start();
  11287. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  11288. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  11289. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  11290. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  11291. if (!actionBool)
  11292. {
  11293. stopwatch2.Start();
  11294. // MES_Flag
  11295. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11296. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11297. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  11298. writeToPLC_Flag1.Adress = 2398;
  11299. writeToPLC_Flag1.Value = (short)4;
  11300. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  11301. stopwatch2.Stop();
  11302. AddMessage(LogType.Info,
  11303. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  11304. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  11305. return;
  11306. }
  11307. string d1OEEPartNo = string.Empty; // 物料码
  11308. if (string.IsNullOrEmpty(d1OEEProductSN))
  11309. {
  11310. stopwatch2.Start();
  11311. // MES_Flag
  11312. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11313. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11314. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  11315. writeToPLC_Flag1.Adress = 2398;
  11316. writeToPLC_Flag1.Value = (short)1;
  11317. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  11318. stopwatch2.Stop();
  11319. AddMessage(LogType.Info,
  11320. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11321. stopwatch2.ElapsedMilliseconds + "ms");
  11322. return;
  11323. }
  11324. else
  11325. {
  11326. // 查产品SN ZS
  11327. d1OEEPartNo = "Test";
  11328. }
  11329. short d1OEEMES_FLAG = 0;
  11330. // 上传OEE
  11331. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  11332. d1OEEMES_FLAG = result.Item1;
  11333. resultStr = result.Item2;
  11334. stopwatch2.Start();
  11335. // MES_Flag
  11336. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11337. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11338. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  11339. writeToPLC_Flag.Adress = 2398;
  11340. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  11341. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  11342. stopwatch2.Stop();
  11343. }
  11344. catch (Exception ex)
  11345. {
  11346. string str = ex.StackTrace;
  11347. AddMessage_Station(stationNameStr, LogType.Error,
  11348. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  11349. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11350. // MES_Flag
  11351. stopwatch2.Start();
  11352. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  11353. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11354. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  11355. writeToPLC_Flag.Adress = 2398;
  11356. writeToPLC_Flag.Value = (short)4;
  11357. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  11358. stopwatch2.Stop();
  11359. }
  11360. stopwatch1.Stop();
  11361. AddMessage(LogType.Info,
  11362. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11363. stopwatch2.ElapsedMilliseconds + "ms");
  11364. }
  11365. /// <summary>
  11366. /// [S4] 取放桁架 - S4_2桁架
  11367. /// </summary>
  11368. /// <param name="plcNo">PLC编号</param>
  11369. /// <param name="stationNameStr">工站全称</param>
  11370. private void S4_2桁架(int plcNo, string stationNameStr)
  11371. {
  11372. Stopwatch stopwatch1 = new Stopwatch();
  11373. Stopwatch stopwatch2 = new Stopwatch();
  11374. try
  11375. {
  11376. stopwatch1.Start();
  11377. // ZS 弹夹扫码
  11378. string d2BulletclipCode = " "; // 扫到的码
  11379. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  11380. short d2BulletclipScanCode = 2;
  11381. stopwatch2.Start();
  11382. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  11383. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  11384. //// MES_Flag
  11385. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  11386. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11387. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  11388. writeToPLC_Flag.Adress = 2430;
  11389. writeToPLC_Flag.Value = d2BulletclipScanCode;
  11390. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  11391. {
  11392. Name = "d2BulletclipCode",
  11393. Adress = 2432,
  11394. ValueType = PLCValueType.String,
  11395. ValueTypeStrLength = 20,
  11396. Value = d2BulletclipCode
  11397. });
  11398. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  11399. {
  11400. Name = "d2BulletclipStates",
  11401. Adress = 2431,
  11402. ValueType = PLCValueType.Short,
  11403. Value = d2BulletclipStates
  11404. });
  11405. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  11406. stopwatch2.Stop();
  11407. }
  11408. catch (Exception ex)
  11409. {
  11410. string str = ex.StackTrace;
  11411. AddMessage_Station(stationNameStr, LogType.Error,
  11412. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  11413. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11414. stopwatch2.Start();
  11415. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  11416. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  11417. // MES_Flag
  11418. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  11419. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11420. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  11421. writeToPLC_Flag.Adress = 2430;
  11422. writeToPLC_Flag.Value = (short)6;
  11423. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  11424. {
  11425. Name = "d2BulletclipCode",
  11426. Adress = 2432,
  11427. ValueType = PLCValueType.String,
  11428. ValueTypeStrLength = 20,
  11429. Value = " "
  11430. });
  11431. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  11432. {
  11433. Name = "d2BulletclipStates",
  11434. Adress = 2431,
  11435. ValueType = PLCValueType.Short,
  11436. Value = (short)0
  11437. });
  11438. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  11439. stopwatch2.Stop();
  11440. }
  11441. stopwatch1.Stop();
  11442. AddMessage(LogType.Info,
  11443. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11444. stopwatch2.ElapsedMilliseconds + "ms");
  11445. }
  11446. // 上次采集到的SN
  11447. //private string sn_S4_3进站接口 = string.Empty;
  11448. /// <summary>
  11449. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  11450. /// </summary>
  11451. private void S4_3进站接口(int plcNo, string stationNameStr)
  11452. {
  11453. Stopwatch stopwatch1 = new Stopwatch();
  11454. Stopwatch stopwatch2 = new Stopwatch();
  11455. try
  11456. {
  11457. stopwatch1.Start();
  11458. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  11459. sn = sn.Replace("\0", "");
  11460. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  11461. #region 查询15个载具码
  11462. List<string> vehicleCodes = new List<string>(); // 15个载具码
  11463. string vehicleData = string.Empty;
  11464. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  11465. if (string.IsNullOrEmpty(vehicleData))
  11466. vehicleData = "";
  11467. if (snResult != 0)
  11468. {
  11469. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11470. writeToPLC_Flag1.Name = "d3MES_FLAG";
  11471. writeToPLC_Flag1.Adress = 2463;
  11472. writeToPLC_Flag1.Value = (short)4;
  11473. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  11474. stopwatch1.Stop();
  11475. AddMessage(LogType.Info,
  11476. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11477. return;
  11478. }
  11479. string[] cavitySNs = vehicleData.Split('.');
  11480. if (cavitySNs != null && cavitySNs.Length > 0)
  11481. {
  11482. for (int i = 0; i < cavitySNs.Length; i++)
  11483. {
  11484. if (string.IsNullOrEmpty(cavitySNs[i]))
  11485. vehicleCodes.Add("");
  11486. else
  11487. vehicleCodes.Add(cavitySNs[i]);
  11488. }
  11489. }
  11490. #endregion 查询15个载具码
  11491. #region 查询15个产品SN
  11492. List<string> portNos = new List<string>(); // 15个产品SN
  11493. foreach (string vehicleCode in vehicleCodes)
  11494. {
  11495. if (string.IsNullOrEmpty(vehicleCode))
  11496. portNos.Add("");
  11497. else
  11498. {
  11499. // 查询
  11500. string cavityData = string.Empty;
  11501. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  11502. if (string.IsNullOrEmpty(cavityData))
  11503. cavityData = "";
  11504. if (snResult1 != 0)
  11505. {
  11506. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11507. writeToPLC_Flag1.Name = "d3MES_FLAG";
  11508. writeToPLC_Flag1.Adress = 2463;
  11509. writeToPLC_Flag1.Value = (short)4;
  11510. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  11511. stopwatch1.Stop();
  11512. AddMessage(LogType.Info,
  11513. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  11514. stopwatch1.ElapsedMilliseconds + "ms");
  11515. return;
  11516. }
  11517. string[] partSNs = cavityData.Split('.');
  11518. if (partSNs != null && partSNs.Length >= 1)
  11519. portNos.Add(partSNs[0]);
  11520. else
  11521. portNos.Add("");
  11522. }
  11523. }
  11524. #endregion 查询15个产品SN
  11525. // 调用MES进站(最多15个)
  11526. stopwatch2.Start();
  11527. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  11528. for (int i = 0; i < vehicleCodes.Count; i++)
  11529. {
  11530. // 循环进站
  11531. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  11532. {
  11533. // 产品SN(物料码)校验
  11534. string portNo = portNos[i];
  11535. List<TestItem> item = new List<TestItem>();
  11536. item.Add(new TestItem()
  11537. {
  11538. Parameter_name = "弹夹码",
  11539. Parameter_value = sn,
  11540. });
  11541. item.Add(new TestItem()
  11542. {
  11543. Parameter_name = "弹夹穴位",
  11544. Parameter_value = (i + 1).ToString(),
  11545. });
  11546. item.Add(new TestItem()
  11547. {
  11548. Parameter_name = "载具码",
  11549. Parameter_value = vehicleCodes[i],
  11550. });
  11551. item.Add(new TestItem()
  11552. {
  11553. Parameter_name = "载具穴号",
  11554. Parameter_value = "1",
  11555. });
  11556. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  11557. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  11558. }
  11559. }
  11560. stopwatch2.Stop();
  11561. short result = 0;
  11562. bool haveMesWarn = results.Contains(5);
  11563. bool havePCWarn = results.Contains(6);
  11564. if (haveMesWarn)
  11565. result = 2; // 5->2
  11566. else if (havePCWarn)
  11567. result = 6; // 6->4
  11568. else
  11569. result = 1;
  11570. // MES_Flag 为4MES报错
  11571. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11572. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11573. writeToPLC_Flag.Name = "d3MES_FLAG";
  11574. writeToPLC_Flag.Adress = 2463;
  11575. writeToPLC_Flag.Value = result;
  11576. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  11577. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  11578. }
  11579. catch (Exception ex)
  11580. {
  11581. stopwatch2.Stop();
  11582. // MES_Flag 为4上位机报错
  11583. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  11584. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11585. writeToPLC_Flag.Name = "d3MES_FLAG";
  11586. writeToPLC_Flag.Adress = 2463;
  11587. writeToPLC_Flag.Value = (short)4;
  11588. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  11589. string str = ex.StackTrace;
  11590. AddMessage_Station(stationNameStr, LogType.Error,
  11591. $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11592. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11593. }
  11594. stopwatch1.Stop();
  11595. AddMessage(LogType.Info,
  11596. stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  11597. stopwatch2.ElapsedMilliseconds + "ms");
  11598. }
  11599. // 上次采集到的SN
  11600. //private string sn_S4_3出站接口 = string.Empty;
  11601. /// <summary>
  11602. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  11603. /// </summary>
  11604. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  11605. {
  11606. Stopwatch stopwatch1 = new Stopwatch();
  11607. Stopwatch stopwatch2 = new Stopwatch();
  11608. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  11609. string stationNameStr = stationCode + stationName;
  11610. string processItem = stationName; // 测试项目
  11611. try
  11612. {
  11613. stopwatch1.Start();
  11614. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  11615. //string batch_num = GlobalContext.BatchNumber; // 批次号
  11616. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  11617. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  11618. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  11619. sn = sn.Replace("\0", "");
  11620. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  11621. bool isPass = d3Result == 1; // 产品结果 bool
  11622. #region 查询15个载具码
  11623. List<string> vehicleCodes = new List<string>(); // 15个载具码
  11624. string vehicleData = string.Empty;
  11625. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  11626. if (string.IsNullOrEmpty(vehicleData))
  11627. vehicleData = "";
  11628. if (snResult1 != 0)
  11629. {
  11630. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11631. writeToPLC_Flag1.Name = "d3MES_FLAG";
  11632. writeToPLC_Flag1.Adress = 2463;
  11633. writeToPLC_Flag1.Value = (short)4;
  11634. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  11635. stopwatch1.Stop();
  11636. AddMessage(LogType.Info,
  11637. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11638. return;
  11639. }
  11640. string[] cavitySNs = vehicleData.Split('.');
  11641. if (cavitySNs != null && cavitySNs.Length > 0)
  11642. {
  11643. for (int i = 0; i < cavitySNs.Length; i++)
  11644. {
  11645. if (string.IsNullOrEmpty(cavitySNs[i]))
  11646. vehicleCodes.Add("");
  11647. else
  11648. vehicleCodes.Add(cavitySNs[i]);
  11649. }
  11650. }
  11651. #endregion 查询15个载具码
  11652. // 统一查 产品SN列表
  11653. List<string> partNos = new List<string>();
  11654. foreach (string vehicleCode in vehicleCodes)
  11655. {
  11656. if (string.IsNullOrEmpty(vehicleCode))
  11657. partNos.Add("");
  11658. else
  11659. {
  11660. string partNo = "";
  11661. #region 查询载具上的产品信息
  11662. string cavityData = string.Empty;
  11663. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  11664. if (string.IsNullOrEmpty(cavityData))
  11665. cavityData = "";
  11666. if (snResult != 0)
  11667. {
  11668. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11669. writeToPLC_Flag1.Name = "d3MES_FLAG";
  11670. writeToPLC_Flag1.Adress = 2463;
  11671. writeToPLC_Flag1.Value = (short)4;
  11672. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  11673. stopwatch1.Stop();
  11674. AddMessage(LogType.Info,
  11675. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  11676. "ms");
  11677. return;
  11678. }
  11679. string[] partSNs = cavityData.Split('.');
  11680. if (partSNs != null && partSNs.Length >= 1)
  11681. partNo = partSNs[0];
  11682. #endregion 查询载具上的产品信息
  11683. partNos.Add(partNo);
  11684. }
  11685. }
  11686. // 统一上传 - 调用MES出站
  11687. stopwatch2.Start();
  11688. List<int> results = new List<int>();
  11689. for (int i = 0; i < partNos.Count; i++)
  11690. {
  11691. string index = (i + 1).ToString(); // 弹夹穴号
  11692. if (string.IsNullOrEmpty(partNos[i]))
  11693. results.Add(1);
  11694. else
  11695. {
  11696. List<TestItem> items1 = new List<TestItem>();
  11697. items1.Add(new TestItem()
  11698. {
  11699. Parameter_name = "弹夹码",
  11700. Parameter_value = sn,
  11701. Parameter_unit = ""
  11702. });
  11703. items1.Add(new TestItem()
  11704. {
  11705. Parameter_name = "弹夹穴号",
  11706. Parameter_value = index,
  11707. Parameter_unit = ""
  11708. });
  11709. items1.Add(new TestItem()
  11710. {
  11711. Parameter_name = "载具码",
  11712. Parameter_value = vehicleCodes[i],
  11713. Parameter_unit = ""
  11714. });
  11715. items1.Add(new TestItem()
  11716. {
  11717. Parameter_name = "载具穴号",
  11718. Parameter_value = "1",
  11719. Parameter_unit = ""
  11720. });
  11721. items1.Add(new TestItem()
  11722. {
  11723. Parameter_name = "产品结果",
  11724. Parameter_value = d3Result == 1 ? "OK" : "NG",
  11725. Parameter_unit = ""
  11726. });
  11727. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  11728. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  11729. results.Add(result1);
  11730. }
  11731. }
  11732. short result = 0;
  11733. if (results.All(a => a == 1))
  11734. result = 1;
  11735. else if (results.Contains(3))
  11736. result = 3;
  11737. else if (results.Contains(2))
  11738. result = 2;
  11739. else if (results.Contains(4))
  11740. result = 4;
  11741. else
  11742. result = 4;
  11743. stopwatch2.Stop();
  11744. // MES_Flag 为4MES报错
  11745. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11746. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11747. writeToPLC_Flag.Name = "d3MES_FLAG";
  11748. writeToPLC_Flag.Adress = 2463;
  11749. writeToPLC_Flag.Value = result;
  11750. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  11751. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  11752. }
  11753. catch (Exception ex)
  11754. {
  11755. stopwatch2.Restart();
  11756. // MES_Flag 为4上位机报错
  11757. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  11758. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11759. writeToPLC_Flag.Name = "d3MES_FLAG";
  11760. writeToPLC_Flag.Adress = 2463;
  11761. writeToPLC_Flag.Value = (short)4;
  11762. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  11763. string str = ex.StackTrace;
  11764. AddMessage_Station(stationNameStr, LogType.Error,
  11765. $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11766. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11767. stopwatch2.Stop();
  11768. }
  11769. stopwatch1.Stop();
  11770. AddMessage(LogType.Info,
  11771. stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11772. stopwatch2.ElapsedMilliseconds + "ms");
  11773. }
  11774. // 上次采集到的SN
  11775. //private string sn_S4_4进站接口 = string.Empty;
  11776. /// <summary>
  11777. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  11778. /// </summary>
  11779. private void S4_4进站接口(int plcNo, string stationNameStr)
  11780. {
  11781. Stopwatch stopwatch1 = new Stopwatch();
  11782. Stopwatch stopwatch2 = new Stopwatch();
  11783. try
  11784. {
  11785. stopwatch1.Start();
  11786. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  11787. sn = sn.Replace("\0", "");
  11788. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  11789. #region 查询15个载具码
  11790. List<string> vehicleCodes = new List<string>(); // 15个载具码
  11791. string vehicleData = string.Empty;
  11792. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  11793. if (string.IsNullOrEmpty(vehicleData))
  11794. vehicleData = "";
  11795. if (snResult != 0)
  11796. {
  11797. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11798. writeToPLC_Flag1.Name = "d3MES_FLAG";
  11799. writeToPLC_Flag1.Adress = 2463;
  11800. writeToPLC_Flag1.Value = (short)4;
  11801. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  11802. stopwatch1.Stop();
  11803. AddMessage(LogType.Info,
  11804. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11805. return;
  11806. }
  11807. string[] cavitySNs = vehicleData.Split('.');
  11808. if (cavitySNs != null && cavitySNs.Length > 0)
  11809. {
  11810. for (int i = 0; i < cavitySNs.Length; i++)
  11811. {
  11812. if (string.IsNullOrEmpty(cavitySNs[i]))
  11813. vehicleCodes.Add("");
  11814. else
  11815. vehicleCodes.Add(cavitySNs[i]);
  11816. }
  11817. }
  11818. #endregion 查询15个载具码
  11819. #region 查询15个产品SN
  11820. List<string> portNos = new List<string>(); // 15个产品SN
  11821. foreach (string vehicleCode in vehicleCodes)
  11822. {
  11823. if (string.IsNullOrEmpty(vehicleCode))
  11824. portNos.Add("");
  11825. else
  11826. {
  11827. // 查询
  11828. string cavityData = string.Empty;
  11829. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  11830. if (string.IsNullOrEmpty(cavityData))
  11831. cavityData = "";
  11832. if (snResult1 != 0)
  11833. {
  11834. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11835. writeToPLC_Flag1.Name = "d3MES_FLAG";
  11836. writeToPLC_Flag1.Adress = 2463;
  11837. writeToPLC_Flag1.Value = (short)4;
  11838. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  11839. stopwatch1.Stop();
  11840. AddMessage(LogType.Info,
  11841. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  11842. stopwatch1.ElapsedMilliseconds + "ms");
  11843. return;
  11844. }
  11845. string[] partSNs = cavityData.Split('.');
  11846. if (partSNs != null && partSNs.Length >= 1)
  11847. portNos.Add(partSNs[0]);
  11848. else
  11849. portNos.Add("");
  11850. }
  11851. }
  11852. #endregion 查询15个产品SN
  11853. // 调用MES进站(最多15个)
  11854. stopwatch2.Start();
  11855. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  11856. for (int i = 0; i < vehicleCodes.Count; i++)
  11857. {
  11858. // 循环进站
  11859. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  11860. {
  11861. // 产品SN(物料码)校验
  11862. string portNo = portNos[i];
  11863. List<TestItem> item = new List<TestItem>();
  11864. item.Add(new TestItem()
  11865. {
  11866. Parameter_name = "弹夹码",
  11867. Parameter_value = sn,
  11868. });
  11869. item.Add(new TestItem()
  11870. {
  11871. Parameter_name = "弹夹穴位",
  11872. Parameter_value = (i + 1).ToString(),
  11873. });
  11874. item.Add(new TestItem()
  11875. {
  11876. Parameter_name = "载具码",
  11877. Parameter_value = vehicleCodes[i],
  11878. });
  11879. item.Add(new TestItem()
  11880. {
  11881. Parameter_name = "载具穴号",
  11882. Parameter_value = "1",
  11883. });
  11884. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  11885. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  11886. }
  11887. }
  11888. stopwatch2.Stop();
  11889. short result = 0;
  11890. bool haveMesWarn = results.Contains(5);
  11891. bool havePCWarn = results.Contains(6);
  11892. if (haveMesWarn)
  11893. result = 2; // 5->2
  11894. else if (havePCWarn)
  11895. result = 6; // 6->4
  11896. else
  11897. result = 1;
  11898. // MES_Flag 为4MES报错
  11899. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11900. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11901. writeToPLC_Flag.Name = "d4MES_FLAG";
  11902. writeToPLC_Flag.Adress = 2496;
  11903. writeToPLC_Flag.Value = result;
  11904. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  11905. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  11906. }
  11907. catch (Exception ex)
  11908. {
  11909. stopwatch2.Stop();
  11910. // MES_Flag 为4上位机报错
  11911. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  11912. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11913. writeToPLC_Flag.Name = "d4MES_FLAG";
  11914. writeToPLC_Flag.Adress = 2496;
  11915. writeToPLC_Flag.Value = (short)4;
  11916. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  11917. string str = ex.StackTrace;
  11918. AddMessage_Station(stationNameStr, LogType.Error,
  11919. $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11920. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11921. }
  11922. stopwatch1.Stop();
  11923. AddMessage(LogType.Info,
  11924. stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  11925. stopwatch2.ElapsedMilliseconds + "ms");
  11926. }
  11927. // 上次采集到的SN
  11928. //private string sn_S4_4出站接口 = string.Empty;
  11929. /// <summary>
  11930. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  11931. /// </summary>
  11932. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  11933. {
  11934. Stopwatch stopwatch1 = new Stopwatch();
  11935. Stopwatch stopwatch2 = new Stopwatch();
  11936. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  11937. string stationNameStr = stationCode + stationName;
  11938. string processItem = stationName; // 测试项目
  11939. try
  11940. {
  11941. stopwatch1.Start();
  11942. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  11943. //string batch_num = GlobalContext.BatchNumber; // 批次号
  11944. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  11945. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  11946. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  11947. sn = sn.Replace("\0", "");
  11948. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  11949. bool isPass = d4Result == 1; // 产品结果 bool
  11950. #region 查询15个载具码
  11951. List<string> vehicleCodes = new List<string>(); // 15个载具码
  11952. string vehicleData = string.Empty;
  11953. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  11954. if (string.IsNullOrEmpty(vehicleData))
  11955. vehicleData = "";
  11956. if (snResult1 != 0)
  11957. {
  11958. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11959. writeToPLC_Flag1.Name = "d4MES_FLAG";
  11960. writeToPLC_Flag1.Adress = 2496;
  11961. writeToPLC_Flag1.Value = (short)4;
  11962. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  11963. stopwatch1.Stop();
  11964. AddMessage(LogType.Info,
  11965. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11966. return;
  11967. }
  11968. string[] cavitySNs = vehicleData.Split('.');
  11969. if (cavitySNs != null && cavitySNs.Length > 0)
  11970. {
  11971. for (int i = 0; i < cavitySNs.Length; i++)
  11972. {
  11973. if (string.IsNullOrEmpty(cavitySNs[i]))
  11974. vehicleCodes.Add("");
  11975. else
  11976. vehicleCodes.Add(cavitySNs[i]);
  11977. }
  11978. }
  11979. #endregion 查询15个载具码
  11980. // 统一查 产品SN列表
  11981. List<string> partNos = new List<string>();
  11982. foreach (string vehicleCode in vehicleCodes)
  11983. {
  11984. if (string.IsNullOrEmpty(vehicleCode))
  11985. partNos.Add("");
  11986. else
  11987. {
  11988. string partNo = "";
  11989. #region 查询载具上的产品信息
  11990. string cavityData = string.Empty;
  11991. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  11992. if (string.IsNullOrEmpty(cavityData))
  11993. cavityData = "";
  11994. if (snResult != 0)
  11995. {
  11996. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11997. writeToPLC_Flag1.Name = "d4MES_FLAG";
  11998. writeToPLC_Flag1.Adress = 2496;
  11999. writeToPLC_Flag1.Value = (short)4;
  12000. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  12001. stopwatch1.Stop();
  12002. AddMessage(LogType.Info,
  12003. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  12004. "ms");
  12005. return;
  12006. }
  12007. string[] partSNs = cavityData.Split('.');
  12008. if (partSNs != null && partSNs.Length >= 1)
  12009. partNo = partSNs[0];
  12010. #endregion 查询载具上的产品信息
  12011. partNos.Add(partNo);
  12012. }
  12013. }
  12014. // 调用MES出站
  12015. stopwatch2.Start();
  12016. // 统一上传
  12017. List<int> results = new List<int>();
  12018. for (int i = 0; i < partNos.Count; i++)
  12019. {
  12020. string index = (i + 1).ToString(); // 弹夹穴号
  12021. if (string.IsNullOrEmpty(partNos[i]))
  12022. results.Add(1);
  12023. else
  12024. {
  12025. List<TestItem> items1 = new List<TestItem>();
  12026. items1.Add(new TestItem()
  12027. {
  12028. Parameter_name = "弹夹码",
  12029. Parameter_value = sn,
  12030. Parameter_unit = ""
  12031. });
  12032. items1.Add(new TestItem()
  12033. {
  12034. Parameter_name = "弹夹穴号",
  12035. Parameter_value = index,
  12036. Parameter_unit = ""
  12037. });
  12038. items1.Add(new TestItem()
  12039. {
  12040. Parameter_name = "载具码",
  12041. Parameter_value = vehicleCodes[i],
  12042. Parameter_unit = ""
  12043. });
  12044. items1.Add(new TestItem()
  12045. {
  12046. Parameter_name = "载具穴号",
  12047. Parameter_value = "1",
  12048. Parameter_unit = ""
  12049. });
  12050. items1.Add(new TestItem()
  12051. {
  12052. Parameter_name = "产品结果",
  12053. Parameter_value = d4Result == 1 ? "OK" : "NG",
  12054. Parameter_unit = ""
  12055. });
  12056. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  12057. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  12058. results.Add(result1);
  12059. }
  12060. }
  12061. short result = 0;
  12062. if (results.All(a => a == 1))
  12063. result = 1;
  12064. else if (results.Contains(3))
  12065. result = 3;
  12066. else if (results.Contains(2))
  12067. result = 2;
  12068. else if (results.Contains(4))
  12069. result = 4;
  12070. else
  12071. result = 4;
  12072. stopwatch2.Stop();
  12073. // MES_Flag 为4MES报错
  12074. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  12075. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12076. writeToPLC_Flag.Name = "d4MES_FLAG";
  12077. writeToPLC_Flag.Adress = 2496;
  12078. writeToPLC_Flag.Value = result;
  12079. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  12080. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  12081. }
  12082. catch (Exception ex)
  12083. {
  12084. stopwatch2.Restart();
  12085. // MES_Flag 为4上位机报错
  12086. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  12087. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12088. writeToPLC_Flag.Name = "d4MES_FLAG";
  12089. writeToPLC_Flag.Adress = 2496;
  12090. writeToPLC_Flag.Value = (short)4;
  12091. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  12092. string str = ex.StackTrace;
  12093. AddMessage_Station(stationNameStr, LogType.Error,
  12094. $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  12095. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12096. stopwatch2.Stop();
  12097. }
  12098. stopwatch1.Stop();
  12099. AddMessage(LogType.Info,
  12100. stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  12101. stopwatch2.ElapsedMilliseconds + "ms");
  12102. }
  12103. /// <summary>
  12104. /// [S4] 取放桁架 - S4_5弹夹扫码
  12105. /// </summary>
  12106. /// <param name="plcNo">PLC编号</param>
  12107. /// <param name="stationNameStr">工站全称</param>
  12108. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  12109. {
  12110. Stopwatch stopwatch1 = new Stopwatch();
  12111. Stopwatch stopwatch2 = new Stopwatch();
  12112. try
  12113. {
  12114. stopwatch1.Start();
  12115. // ZS 弹夹扫码
  12116. string d5BulletclipCode = " "; // 扫到的码
  12117. short d5BulletclipScanCode = 2;
  12118. stopwatch2.Start();
  12119. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  12120. //// MES_Flag
  12121. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  12122. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12123. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  12124. writeToPLC_Flag.Adress = 2528;
  12125. writeToPLC_Flag.Value = d5BulletclipScanCode;
  12126. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  12127. {
  12128. Name = "d5BulletclipCode",
  12129. Adress = 2529,
  12130. ValueType = PLCValueType.String,
  12131. ValueTypeStrLength = 20,
  12132. Value = d5BulletclipCode
  12133. });
  12134. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  12135. stopwatch2.Stop();
  12136. }
  12137. catch (Exception ex)
  12138. {
  12139. string str = ex.StackTrace;
  12140. AddMessage_Station(stationNameStr, LogType.Error,
  12141. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  12142. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12143. stopwatch2.Start();
  12144. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  12145. //// MES_Flag
  12146. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  12147. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12148. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  12149. writeToPLC_Flag.Adress = 2528;
  12150. writeToPLC_Flag.Value = (short)6;
  12151. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  12152. {
  12153. Name = "d5BulletclipCode",
  12154. Adress = 2529,
  12155. ValueType = PLCValueType.String,
  12156. ValueTypeStrLength = 20,
  12157. Value = " "
  12158. });
  12159. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  12160. stopwatch2.Stop();
  12161. }
  12162. stopwatch1.Stop();
  12163. AddMessage(LogType.Info,
  12164. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12165. stopwatch2.ElapsedMilliseconds + "ms");
  12166. }
  12167. /// <summary>
  12168. /// [S4] 取放桁架 - S4_5载具扫码
  12169. /// </summary>
  12170. /// <param name="plcNo">PLC编号</param>
  12171. /// <param name="stationNameStr">工站全称</param>
  12172. private void S4_5载具扫码(int plcNo, string stationNameStr)
  12173. {
  12174. Stopwatch stopwatch1 = new Stopwatch();
  12175. Stopwatch stopwatch2 = new Stopwatch();
  12176. try
  12177. {
  12178. stopwatch1.Start();
  12179. // ZS 载具扫码
  12180. string d5VehicleCode = " "; // 扫到的码
  12181. short d5VehicleScanCode = 2;
  12182. #region 进站
  12183. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  12184. {
  12185. // 查产品SN
  12186. #region 查询载具上的产品信息
  12187. string cavityData = string.Empty;
  12188. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  12189. if (string.IsNullOrEmpty(cavityData))
  12190. cavityData = "";
  12191. if (snResult != 0)
  12192. {
  12193. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  12194. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  12195. writeToPLC_Flag1.Adress = 2559;
  12196. writeToPLC_Flag1.Value = (short)6;
  12197. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  12198. {
  12199. Name = "d5VehicleCode",
  12200. Adress = 2560,
  12201. ValueType = PLCValueType.String,
  12202. ValueTypeStrLength = 20,
  12203. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  12204. });
  12205. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  12206. stopwatch1.Stop();
  12207. AddMessage(LogType.Info,
  12208. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  12209. "ms");
  12210. return;
  12211. }
  12212. string[] cavitySNs = cavityData.Split('.');
  12213. string partNo = "";
  12214. if (cavitySNs != null && cavitySNs.Length >= 1)
  12215. {
  12216. partNo = cavitySNs[0];
  12217. }
  12218. #endregion 查询载具上的产品信息
  12219. List<TestItem> item = new List<TestItem>();
  12220. item.Add(new TestItem()
  12221. {
  12222. Parameter_name = "载具码",
  12223. Parameter_value = d5VehicleCode,
  12224. });
  12225. item.Add(new TestItem()
  12226. {
  12227. Parameter_name = "载具穴号",
  12228. Parameter_value = "1",
  12229. });
  12230. stopwatch2.Start();
  12231. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  12232. partNo, item, out string errorMsg);
  12233. stopwatch2.Stop();
  12234. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  12235. }
  12236. #endregion 进站
  12237. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  12238. //// MES_Flag
  12239. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  12240. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12241. writeToPLC_Flag.Name = "d5VehicleScanCode";
  12242. writeToPLC_Flag.Adress = 2559;
  12243. writeToPLC_Flag.Value = d5VehicleScanCode;
  12244. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  12245. {
  12246. Name = "d5VehicleCode",
  12247. Adress = 2560,
  12248. ValueType = PLCValueType.String,
  12249. ValueTypeStrLength = 20,
  12250. Value = d5VehicleCode
  12251. });
  12252. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  12253. }
  12254. catch (Exception ex)
  12255. {
  12256. string str = ex.StackTrace;
  12257. AddMessage_Station(stationNameStr, LogType.Error,
  12258. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  12259. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12260. stopwatch2.Start();
  12261. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  12262. //// MES_Flag
  12263. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  12264. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12265. writeToPLC_Flag.Name = "d5VehicleScanCode";
  12266. writeToPLC_Flag.Adress = 2559;
  12267. writeToPLC_Flag.Value = (short)6;
  12268. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  12269. {
  12270. Name = "d5VehicleCode",
  12271. Adress = 2560,
  12272. ValueType = PLCValueType.String,
  12273. ValueTypeStrLength = 20,
  12274. Value = " "
  12275. });
  12276. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  12277. stopwatch2.Stop();
  12278. }
  12279. stopwatch1.Stop();
  12280. AddMessage(LogType.Info,
  12281. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12282. stopwatch2.ElapsedMilliseconds + "ms");
  12283. }
  12284. // 上次采集到的SN
  12285. //private string sn_S4_5出站接口 = string.Empty;
  12286. /// <summary>
  12287. /// [S4] 取放桁架 - S4_5出站接口
  12288. /// </summary>
  12289. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  12290. {
  12291. Stopwatch stopwatch1 = new Stopwatch();
  12292. Stopwatch stopwatch2 = new Stopwatch();
  12293. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  12294. string stationNameStr = stationCode + stationName;
  12295. string processItem = stationName; // 测试项目
  12296. try
  12297. {
  12298. stopwatch1.Start();
  12299. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  12300. //string batch_num = GlobalContext.BatchNumber; // 批次号
  12301. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  12302. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  12303. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  12304. sn = sn.Replace("\0", "");
  12305. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  12306. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  12307. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  12308. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  12309. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  12310. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  12311. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  12312. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  12313. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  12314. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  12315. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  12316. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  12317. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  12318. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  12319. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  12320. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  12321. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  12322. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  12323. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  12324. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  12325. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  12326. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  12327. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  12328. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  12329. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  12330. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  12331. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  12332. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  12333. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  12334. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  12335. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  12336. bool pass = d5Result == 1;
  12337. // 存 载具SN列表
  12338. List<string> vehicleCodes = new List<string>()
  12339. {
  12340. d5VehicleCode1, d5VehicleCode2, d5VehicleCode3, d5VehicleCode4, d5VehicleCode5,
  12341. d5VehicleCode6, d5VehicleCode7, d5VehicleCode8, d5VehicleCode9, d5VehicleCode10,
  12342. d5VehicleCode11, d5VehicleCode12, d5VehicleCode13, d5VehicleCode14, d5VehicleCode15
  12343. };
  12344. // 统一查 产品SN列表
  12345. List<string> partNos = new List<string>();
  12346. foreach (string vehicleCode in vehicleCodes)
  12347. {
  12348. if (string.IsNullOrEmpty(vehicleCode))
  12349. partNos.Add("");
  12350. else
  12351. {
  12352. string partNo = "";
  12353. #region 查询载具上的产品信息
  12354. string cavityData = string.Empty;
  12355. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  12356. if (string.IsNullOrEmpty(cavityData))
  12357. cavityData = "";
  12358. if (snResult != 0)
  12359. {
  12360. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  12361. writeToPLC_Flag1.Name = "d5MES_FLAG";
  12362. writeToPLC_Flag1.Adress = 2591;
  12363. writeToPLC_Flag1.Value = (short)4;
  12364. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  12365. stopwatch1.Stop();
  12366. AddMessage(LogType.Info,
  12367. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  12368. "ms");
  12369. return;
  12370. }
  12371. string[] cavitySNs = cavityData.Split('.');
  12372. if (cavitySNs != null && cavitySNs.Length >= 1)
  12373. partNo = cavitySNs[0];
  12374. #endregion 查询载具上的产品信息
  12375. partNos.Add(partNo);
  12376. }
  12377. }
  12378. // 统一上传
  12379. stopwatch2.Start();
  12380. List<int> results = new List<int>();
  12381. for (int i = 0; i < partNos.Count; i++)
  12382. {
  12383. string index = (i + 1).ToString(); // 弹夹穴号
  12384. if (string.IsNullOrEmpty(partNos[i]))
  12385. results.Add(1);
  12386. else
  12387. {
  12388. List<TestItem> items1 = new List<TestItem>();
  12389. items1.Add(new TestItem()
  12390. {
  12391. Parameter_name = "弹夹码",
  12392. Parameter_value = sn,
  12393. Parameter_unit = ""
  12394. });
  12395. items1.Add(new TestItem()
  12396. {
  12397. Parameter_name = "弹夹穴号",
  12398. Parameter_value = index,
  12399. Parameter_unit = ""
  12400. });
  12401. items1.Add(new TestItem()
  12402. {
  12403. Parameter_name = "载具码",
  12404. Parameter_value = vehicleCodes[i],
  12405. Parameter_unit = ""
  12406. });
  12407. items1.Add(new TestItem()
  12408. {
  12409. Parameter_name = "载具穴号",
  12410. Parameter_value = "1",
  12411. Parameter_unit = ""
  12412. });
  12413. items1.Add(new TestItem()
  12414. {
  12415. Parameter_name = "产品结果",
  12416. Parameter_value = d5Result == 1 ? "OK" : "NG",
  12417. Parameter_unit = ""
  12418. });
  12419. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  12420. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  12421. results.Add(result1);
  12422. }
  12423. }
  12424. short result = 0;
  12425. if (results.All(a => a == 1))
  12426. result = 1;
  12427. else if (results.Contains(3))
  12428. result = 3;
  12429. else if (results.Contains(2))
  12430. result = 2;
  12431. else if (results.Contains(4))
  12432. result = 4;
  12433. else
  12434. result = 4;
  12435. stopwatch2.Stop();
  12436. #region 存储绑定数据到 边线MES系统中
  12437. if (result == 1)
  12438. {
  12439. // 删除绑定信息
  12440. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  12441. if (resultMesR != 0)
  12442. {
  12443. result = 4;
  12444. AddMessage_Station(stationNameStr, LogType.Error,
  12445. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  12446. }
  12447. }
  12448. #endregion 存储绑定数据到 边线MES系统中
  12449. // MES_Flag 为4MES报错
  12450. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  12451. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12452. writeToPLC_Flag.Name = "d5MES_FLAG";
  12453. writeToPLC_Flag.Adress = 2591;
  12454. writeToPLC_Flag.Value = result;
  12455. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  12456. OnMessage(LogType.Debug,
  12457. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  12458. }
  12459. catch (Exception ex)
  12460. {
  12461. stopwatch2.Restart();
  12462. // MES_Flag 为4上位机报错
  12463. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  12464. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12465. writeToPLC_Flag.Name = "d5MES_FLAG";
  12466. writeToPLC_Flag.Adress = 2591;
  12467. writeToPLC_Flag.Value = (short)4;
  12468. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  12469. stopwatch2.Stop();
  12470. string str = ex.StackTrace;
  12471. AddMessage_Station(stationNameStr, LogType.Error,
  12472. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  12473. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12474. }
  12475. stopwatch1.Stop();
  12476. AddMessage(LogType.Info,
  12477. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  12478. stopwatch2.ElapsedMilliseconds + "ms");
  12479. }
  12480. /// <summary>
  12481. /// [S4] 取放桁架 - S4_5节拍接口
  12482. /// </summary>
  12483. /// <param name="plcNo">PLC编号</param>
  12484. /// <param name="stationNameStr">工站全称</param>
  12485. private void S4_5节拍接口(int plcNo, string stationNameStr)
  12486. {
  12487. Stopwatch stopwatch1 = new Stopwatch();
  12488. Stopwatch stopwatch2 = new Stopwatch();
  12489. string resultStr = string.Empty;
  12490. try
  12491. {
  12492. stopwatch1.Start();
  12493. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  12494. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  12495. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  12496. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  12497. if (!actionBool)
  12498. {
  12499. stopwatch2.Start();
  12500. // MES_Flag
  12501. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  12502. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  12503. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  12504. writeToPLC_Flag1.Adress = 2924;
  12505. writeToPLC_Flag1.Value = (short)4;
  12506. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  12507. stopwatch2.Stop();
  12508. AddMessage(LogType.Info,
  12509. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  12510. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  12511. return;
  12512. }
  12513. string d5OEEPartNo = string.Empty; // 物料码
  12514. if (string.IsNullOrEmpty(d5OEEProductSN))
  12515. {
  12516. stopwatch2.Start();
  12517. // MES_Flag
  12518. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  12519. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  12520. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  12521. writeToPLC_Flag1.Adress = 2924;
  12522. writeToPLC_Flag1.Value = (short)1;
  12523. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  12524. stopwatch2.Stop();
  12525. AddMessage(LogType.Info,
  12526. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12527. stopwatch2.ElapsedMilliseconds + "ms");
  12528. return;
  12529. }
  12530. else
  12531. {
  12532. // 查产品SN
  12533. d5OEEPartNo = "Test"; // ZS
  12534. }
  12535. short d5OEEMES_FLAG = 0;
  12536. // 上传OEE
  12537. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  12538. d5OEEMES_FLAG = result.Item1;
  12539. resultStr = result.Item2;
  12540. stopwatch2.Start();
  12541. // MES_Flag
  12542. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  12543. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12544. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  12545. writeToPLC_Flag.Adress = 2924;
  12546. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  12547. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  12548. stopwatch2.Stop();
  12549. }
  12550. catch (Exception ex)
  12551. {
  12552. string str = ex.StackTrace;
  12553. AddMessage_Station(stationNameStr, LogType.Error,
  12554. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  12555. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12556. // MES_Flag
  12557. stopwatch2.Start();
  12558. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  12559. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12560. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  12561. writeToPLC_Flag.Adress = 2924;
  12562. writeToPLC_Flag.Value = (short)4;
  12563. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  12564. stopwatch2.Stop();
  12565. }
  12566. stopwatch1.Stop();
  12567. AddMessage(LogType.Info,
  12568. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12569. stopwatch2.ElapsedMilliseconds + "ms");
  12570. }
  12571. #endregion [S4] 取放桁架
  12572. #endregion PLC4 刘果段
  12573. #region PLC5 张超凡
  12574. #region [S5] Tray盘下料装备
  12575. /// <summary>
  12576. /// S5工位的数据- 触发信号上次的值
  12577. /// </summary>
  12578. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  12579. /// <summary>
  12580. /// S5工位的数据(含触发信号)
  12581. /// </summary>
  12582. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  12583. /// <summary>
  12584. /// S5工位的数据- 回写点位
  12585. /// </summary>
  12586. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  12587. /// <summary>
  12588. /// [S5] Tray盘下料装备
  12589. /// </summary>
  12590. /// <param name="plcNo">PLC编号</param>
  12591. //private void ReadStation_S5(int plcNo)
  12592. //{
  12593. // // [S1] Tray盘上料装备
  12594. // // [S2] FCT
  12595. // // [S3] 值板机
  12596. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  12597. // // [S5] Tray盘下料装备
  12598. // /// 上位机心跳
  12599. // /// 获取设备报警数据与状态信息
  12600. // string stationCode = "[S5]";
  12601. // string stationName = "Tray盘下料装备";
  12602. // string stationNameStr = stationCode + stationName;
  12603. // #region 创建字典
  12604. // // 触发信号字典 赋值
  12605. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  12606. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  12607. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  12608. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  12609. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  12610. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  12611. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  12612. // // PLC数据字典 赋值
  12613. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  12614. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  12615. // s5PLCData.Add("e1ProductSN_Check", ""); //
  12616. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  12617. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  12618. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  12619. // s5PLCData.Add("e1PartNo", ""); // 物料码
  12620. // s5PLCData.Add("e1Result", 0); // 产品结果
  12621. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  12622. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  12623. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  12624. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  12625. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  12626. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  12627. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  12628. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  12629. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  12630. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  12631. // #endregion 创建字典
  12632. // while (IsRun)
  12633. // {
  12634. // try
  12635. // {
  12636. // if (!GlobalContext._IsCon_Funs5)
  12637. // {
  12638. // UpdatePLCMonitor(1, plcNo, 0);
  12639. // continue;
  12640. // }
  12641. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  12642. // {
  12643. // Stopwatch stopwatch1 = new Stopwatch();
  12644. // Stopwatch stopwatch2 = new Stopwatch();
  12645. // stopwatch1.Start();
  12646. // stopwatch2.Start();
  12647. // #region 一次性读取所有数据
  12648. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  12649. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  12650. // int[] datas = data1.Concat(data2).ToArray();
  12651. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  12652. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  12653. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  12654. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  12655. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  12656. // s5PLCData["e1MES_FLAG"] = datas[35];
  12657. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  12658. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  12659. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  12660. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  12661. // s5PLCData["e1Result"] = datas[76];
  12662. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  12663. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  12664. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  12665. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  12666. // s5PLCData["e1OEEType"] = datas[109];
  12667. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  12668. // s5PLCData["e1AGVUpStart"] = datas[121];
  12669. // s5PLCData["e1AGVUpEnd"] = datas[122];
  12670. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  12671. // s5PLCData["e1AGVDownStart"] = datas[134];
  12672. // s5PLCData["e1AGVDownEnd"] = datas[135];
  12673. // #endregion 一次性读取所有数据
  12674. // stopwatch2.Stop();
  12675. // #region 回写操作,写后清空flag
  12676. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  12677. // #endregion 回写操作,写后清空flag
  12678. // #region 进站校验
  12679. // try
  12680. // {
  12681. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  12682. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  12683. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  12684. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  12685. // {
  12686. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  12687. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  12688. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  12689. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  12690. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  12691. // }
  12692. // }
  12693. // catch (Exception ex)
  12694. // {
  12695. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  12696. // string str = ex.StackTrace;
  12697. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12698. // }
  12699. // #endregion 进站校验
  12700. // #region 出站接口
  12701. // try
  12702. // {
  12703. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  12704. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  12705. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  12706. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  12707. // {
  12708. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  12709. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  12710. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  12711. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  12712. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  12713. // }
  12714. // }
  12715. // catch (Exception ex)
  12716. // {
  12717. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  12718. // string str = ex.StackTrace;
  12719. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12720. // }
  12721. // #endregion 出站接口
  12722. // #region 节拍接口
  12723. // try
  12724. // {
  12725. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  12726. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  12727. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  12728. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  12729. // {
  12730. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  12731. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  12732. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  12733. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  12734. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  12735. // }
  12736. // }
  12737. // catch (Exception ex)
  12738. // {
  12739. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  12740. // string str = ex.StackTrace;
  12741. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12742. // }
  12743. // #endregion 节拍接口
  12744. // #region AGV上料
  12745. // // AGV上料叫AGV信号
  12746. // try
  12747. // {
  12748. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  12749. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  12750. // if (e1AGVUpCall != e1AGVUpCallOld)
  12751. // {
  12752. // if (e1AGVUpCall == 1) // 0->1
  12753. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  12754. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  12755. // }
  12756. // }
  12757. // catch (Exception ex)
  12758. // {
  12759. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  12760. // string str = ex.StackTrace;
  12761. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12762. // }
  12763. // // AGV上料完成信号
  12764. // try
  12765. // {
  12766. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  12767. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  12768. // if (e1AGVUpEnd != e1AGVUpEndOld)
  12769. // {
  12770. // if (e1AGVUpEnd == 1) // 0->1
  12771. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  12772. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  12773. // }
  12774. // }
  12775. // catch (Exception ex)
  12776. // {
  12777. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  12778. // string str = ex.StackTrace;
  12779. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12780. // }
  12781. // #endregion AGV上料
  12782. // #region AGV下料
  12783. // // AGV下料叫agv信号
  12784. // try
  12785. // {
  12786. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  12787. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  12788. // if (e1AGVDownCall != e1AGVDownCallOld)
  12789. // {
  12790. // if (e1AGVDownCall == 1) // 0->1
  12791. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  12792. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  12793. // }
  12794. // }
  12795. // catch (Exception ex)
  12796. // {
  12797. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  12798. // string str = ex.StackTrace;
  12799. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12800. // }
  12801. // // AGV下料完成信号
  12802. // try
  12803. // {
  12804. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  12805. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  12806. // if (e1AGVDownEnd != e1AGVDownEndOld)
  12807. // {
  12808. // if (e1AGVDownEnd == 1) // 0->1
  12809. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  12810. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  12811. // }
  12812. // }
  12813. // catch (Exception ex)
  12814. // {
  12815. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  12816. // string str = ex.StackTrace;
  12817. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12818. // }
  12819. // #endregion AGV下料
  12820. // #region 心跳
  12821. // try
  12822. // {
  12823. // short states = 0;
  12824. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  12825. // }
  12826. // catch (Exception ex)
  12827. // {
  12828. // string str = ex.StackTrace;
  12829. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12830. // }
  12831. // #endregion 心跳
  12832. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  12833. // stopwatch1.Stop();
  12834. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  12835. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  12836. // }
  12837. // else
  12838. // {
  12839. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  12840. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  12841. // Funs[plcNo].Connect();
  12842. // }
  12843. // }
  12844. // catch (Exception ex)
  12845. // {
  12846. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  12847. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  12848. // Funs[plcNo].ReConnect();
  12849. // }
  12850. // Thread.Sleep(IntervalReadPLC);
  12851. // }
  12852. //}
  12853. /// <summary>
  12854. /// [S5] Tray盘下料装备 - 进站校验
  12855. /// </summary>
  12856. /// <param name="plcNo">PLC编号</param>
  12857. /// <param name="stationNameStr">工站全称</param>
  12858. private void S5进站校验(int plcNo, string stationNameStr)
  12859. {
  12860. Stopwatch stopwatch1 = new Stopwatch();
  12861. Stopwatch stopwatch2 = new Stopwatch();
  12862. try
  12863. {
  12864. stopwatch1.Start();
  12865. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  12866. sn = sn.Replace("\0", "");
  12867. // 获取产品SN By 载具码
  12868. #region 查询载具上的产品信息
  12869. string cavityData = string.Empty;
  12870. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  12871. if (string.IsNullOrEmpty(cavityData))
  12872. cavityData = "";
  12873. if (snResult != 0)
  12874. {
  12875. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  12876. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  12877. writeToPLC_Flag1.Adress = 2003;
  12878. writeToPLC_Flag1.Value = (short)6;
  12879. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  12880. stopwatch1.Stop();
  12881. AddMessage(LogType.Info,
  12882. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  12883. return;
  12884. }
  12885. string[] cavitySNs = cavityData.Split('.');
  12886. string partNo = string.Empty;
  12887. if (cavitySNs != null && cavitySNs.Length >= 1)
  12888. partNo = cavitySNs[0];
  12889. #endregion 查询载具上的产品信息
  12890. // 产品SN(物料码)校验
  12891. List<TestItem> item = new List<TestItem>();
  12892. item.Add(new TestItem()
  12893. {
  12894. Parameter_name = "载具码",
  12895. Parameter_value = sn,
  12896. });
  12897. item.Add(new TestItem()
  12898. {
  12899. Parameter_name = "载具穴号",
  12900. Parameter_value = "1",
  12901. });
  12902. stopwatch2.Start();
  12903. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  12904. partNo, item, out string errorMsg);
  12905. stopwatch2.Stop();
  12906. short e1MES_FLAG_Check = (short)result;
  12907. // MES_Flag
  12908. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  12909. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12910. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  12911. writeToPLC_Flag.Adress = 2003;
  12912. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  12913. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  12914. }
  12915. catch (Exception ex)
  12916. {
  12917. string str = ex.StackTrace;
  12918. AddMessage_Station(stationNameStr, LogType.Error,
  12919. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  12920. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12921. // MES_Flag
  12922. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  12923. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12924. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  12925. writeToPLC_Flag.Adress = 2003;
  12926. writeToPLC_Flag.Value = (short)6;
  12927. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  12928. }
  12929. stopwatch1.Stop();
  12930. AddMessage(LogType.Info,
  12931. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  12932. stopwatch2.ElapsedMilliseconds + "ms");
  12933. }
  12934. /// <summary>
  12935. /// [S5] Tray盘下料装备 - 出站接口
  12936. /// </summary>
  12937. /// <param name="plcNo"></param>
  12938. /// <param name="stationCode"></param>
  12939. /// <param name="stationName"></param>
  12940. private void S5出站接口(int plcNo, string stationCode, string stationName)
  12941. {
  12942. Stopwatch stopwatch1 = new Stopwatch();
  12943. Stopwatch stopwatch2 = new Stopwatch();
  12944. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  12945. string stationNameStr = stationCode + stationName;
  12946. string processItem = stationName; // 测试项目
  12947. try
  12948. {
  12949. stopwatch1.Start();
  12950. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  12951. //string batch_num = GlobalContext.BatchNumber; // 批次号
  12952. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  12953. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  12954. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  12955. sn = sn.Replace("\0", "");
  12956. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  12957. //partNo = partNo.Replace("\0", "");
  12958. #region 查询载具上的产品信息
  12959. string cavityData = string.Empty;
  12960. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  12961. if (string.IsNullOrEmpty(cavityData))
  12962. cavityData = "";
  12963. if (snResult != 0)
  12964. {
  12965. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  12966. writeToPLC_Flag1.Name = "e1MES_FLAG";
  12967. writeToPLC_Flag1.Adress = 2035;
  12968. writeToPLC_Flag1.Value = (short)4;
  12969. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  12970. stopwatch1.Stop();
  12971. AddMessage(LogType.Info,
  12972. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  12973. return;
  12974. }
  12975. string[] cavitySNs = cavityData.Split('.');
  12976. string partNo = string.Empty;
  12977. if (cavitySNs != null && cavitySNs.Length >= 1)
  12978. partNo = cavitySNs[0];
  12979. #endregion 查询载具上的产品信息
  12980. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  12981. bool pass = e1Result == 1;
  12982. stopwatch2.Start();
  12983. // 上传MES
  12984. List<TestItem> items = new List<TestItem>();
  12985. items.Add(new TestItem()
  12986. {
  12987. Parameter_name = "载具码",
  12988. Parameter_value = sn,
  12989. Parameter_unit = ""
  12990. });
  12991. items.Add(new TestItem()
  12992. {
  12993. Parameter_name = "载具穴号",
  12994. Parameter_value = "1",
  12995. Parameter_unit = ""
  12996. });
  12997. items.Add(new TestItem()
  12998. {
  12999. Parameter_name = "产品结果",
  13000. Parameter_value = e1Result == 1 ? "OK" : "NG",
  13001. Parameter_unit = ""
  13002. });
  13003. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  13004. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  13005. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  13006. short result = result1 == 1 ? (short)1 : (short)3;
  13007. stopwatch2.Stop();
  13008. #region 存储绑定数据到 边线MES系统中
  13009. if (result == 1)
  13010. {
  13011. // 删除绑定信息
  13012. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  13013. if (resultMesR != 0)
  13014. {
  13015. result = 4;
  13016. AddMessage_Station(stationNameStr, LogType.Error,
  13017. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  13018. }
  13019. }
  13020. #endregion 存储绑定数据到 边线MES系统中
  13021. // MES_Flag 为MES报错
  13022. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  13023. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  13024. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  13025. writeToPLC_Flag.Name = "e1MES_FLAG";
  13026. writeToPLC_Flag.Adress = 2035;
  13027. writeToPLC_Flag.Value = result;
  13028. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  13029. OnMessage(LogType.Debug,
  13030. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  13031. }
  13032. catch (Exception ex)
  13033. {
  13034. stopwatch2.Restart();
  13035. // MES_Flag 为4上位机报错
  13036. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  13037. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  13038. writeToPLC_Flag.Name = "e1MES_FLAG";
  13039. writeToPLC_Flag.Adress = 2035;
  13040. writeToPLC_Flag.Value = (short)4;
  13041. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  13042. stopwatch2.Stop();
  13043. string str = ex.StackTrace;
  13044. AddMessage_Station(stationNameStr, LogType.Error,
  13045. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  13046. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  13047. }
  13048. stopwatch1.Stop();
  13049. AddMessage(LogType.Info,
  13050. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  13051. stopwatch2.ElapsedMilliseconds + "ms");
  13052. }
  13053. /// <summary>
  13054. /// [S5] Tray盘下料装备 - 节拍接口
  13055. /// </summary>
  13056. /// <param name="plcNo">PLC编号</param>
  13057. /// <param name="stationNameStr">工站全称</param>
  13058. //private void S5节拍接口(int plcNo, string stationNameStr)
  13059. //{
  13060. // Stopwatch stopwatch1 = new Stopwatch();
  13061. // Stopwatch stopwatch2 = new Stopwatch();
  13062. // string resultStr = string.Empty;
  13063. // try
  13064. // {
  13065. // stopwatch1.Start();
  13066. // string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  13067. // string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  13068. // e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  13069. // bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  13070. // if (!actionBool)
  13071. // {
  13072. // stopwatch2.Start();
  13073. // // MES_Flag
  13074. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  13075. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  13076. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  13077. // writeToPLC_Flag1.Adress = 2088;
  13078. // writeToPLC_Flag1.Value = (short)4;
  13079. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  13080. // stopwatch2.Stop();
  13081. // AddMessage(LogType.Info,
  13082. // stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  13083. // "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  13084. // return;
  13085. // }
  13086. // string e1OEEPartNo = string.Empty; // 物料码
  13087. // if (string.IsNullOrEmpty(e1OEEProductSN))
  13088. // {
  13089. // stopwatch2.Start();
  13090. // // MES_Flag
  13091. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  13092. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  13093. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  13094. // writeToPLC_Flag1.Adress = 2088;
  13095. // writeToPLC_Flag1.Value = (short)1;
  13096. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  13097. // stopwatch2.Stop();
  13098. // AddMessage(LogType.Info,
  13099. // stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  13100. // stopwatch2.ElapsedMilliseconds + "ms");
  13101. // return;
  13102. // }
  13103. // else
  13104. // {
  13105. // // 查产品SN
  13106. // e1OEEPartNo = "Test"; // ZS
  13107. // }
  13108. // short e1OEEMES_FLAG = 0;
  13109. // // 上传OEE
  13110. // (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  13111. // e1OEEMES_FLAG = result.Item1;
  13112. // resultStr = result.Item2;
  13113. // stopwatch2.Start();
  13114. // // MES_Flag
  13115. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  13116. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  13117. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  13118. // writeToPLC_Flag.Adress = 2088;
  13119. // writeToPLC_Flag.Value = e1OEEMES_FLAG;
  13120. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  13121. // stopwatch2.Stop();
  13122. // }
  13123. // catch (Exception ex)
  13124. // {
  13125. // string str = ex.StackTrace;
  13126. // AddMessage_Station(stationNameStr, LogType.Error,
  13127. // $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  13128. // str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  13129. // // MES_Flag
  13130. // stopwatch2.Start();
  13131. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  13132. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  13133. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  13134. // writeToPLC_Flag.Adress = 2088;
  13135. // writeToPLC_Flag.Value = (short)4;
  13136. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  13137. // stopwatch2.Stop();
  13138. // }
  13139. // stopwatch1.Stop();
  13140. // AddMessage(LogType.Info,
  13141. // stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  13142. // stopwatch2.ElapsedMilliseconds + "ms");
  13143. //}
  13144. /// <summary>
  13145. /// [S5] Tray盘下料装备 - AGV上料叫agv
  13146. /// </summary>
  13147. /// <param name="plcNo">PLC编号</param>
  13148. /// <param name="stationNameStr">工站全称</param>
  13149. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  13150. {
  13151. Stopwatch stopwatch1 = new Stopwatch();
  13152. Stopwatch stopwatch2 = new Stopwatch();
  13153. try
  13154. {
  13155. stopwatch1.Start();
  13156. // ZS 呼叫AGV
  13157. short e1AGVUpCall = 2;
  13158. stopwatch2.Start();
  13159. // e1AGVUpCall
  13160. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  13161. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  13162. writeToPLC_Flag.Name = "e1AGVUpCall";
  13163. writeToPLC_Flag.Adress = 2120;
  13164. writeToPLC_Flag.Value = e1AGVUpCall;
  13165. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  13166. stopwatch2.Stop();
  13167. }
  13168. catch (Exception ex)
  13169. {
  13170. string str = ex.StackTrace;
  13171. AddMessage_Station(stationNameStr, LogType.Error,
  13172. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  13173. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  13174. // e1AGVUpCall
  13175. stopwatch2.Start();
  13176. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  13177. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  13178. writeToPLC_Flag.Name = "e1AGVUpCall";
  13179. writeToPLC_Flag.Adress = 2120;
  13180. writeToPLC_Flag.Value = (short)4;
  13181. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  13182. stopwatch2.Stop();
  13183. }
  13184. stopwatch1.Stop();
  13185. AddMessage(LogType.Info,
  13186. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  13187. stopwatch2.ElapsedMilliseconds + "ms");
  13188. }
  13189. /// <summary>
  13190. /// [S5] Tray盘下料装备 - AGV上料完成
  13191. /// </summary>
  13192. /// <param name="plcNo">PLC编号</param>
  13193. /// <param name="stationNameStr">工站全称</param>
  13194. private void S5AGV上料完成(int plcNo, string stationNameStr)
  13195. {
  13196. Stopwatch stopwatch1 = new Stopwatch();
  13197. Stopwatch stopwatch2 = new Stopwatch();
  13198. try
  13199. {
  13200. stopwatch1.Start();
  13201. // ZS AGV上料完成,让小车离开
  13202. short e1AGVUpEnd = 2;
  13203. stopwatch2.Start();
  13204. // e1AGVUpEnd
  13205. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  13206. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  13207. writeToPLC_Flag.Name = "e1AGVUpEnd";
  13208. writeToPLC_Flag.Adress = 2122;
  13209. writeToPLC_Flag.Value = e1AGVUpEnd;
  13210. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  13211. stopwatch2.Stop();
  13212. }
  13213. catch (Exception ex)
  13214. {
  13215. string str = ex.StackTrace;
  13216. AddMessage_Station(stationNameStr, LogType.Error,
  13217. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  13218. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  13219. // e1AGVUpEnd
  13220. stopwatch2.Start();
  13221. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  13222. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  13223. writeToPLC_Flag.Name = "e1AGVUpEnd";
  13224. writeToPLC_Flag.Adress = 2122;
  13225. writeToPLC_Flag.Value = (short)4;
  13226. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  13227. stopwatch2.Stop();
  13228. }
  13229. stopwatch1.Stop();
  13230. AddMessage(LogType.Info,
  13231. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  13232. stopwatch2.ElapsedMilliseconds + "ms");
  13233. }
  13234. /// <summary>
  13235. /// [S5] Tray盘下料装备 - AGV下料叫agv
  13236. /// </summary>
  13237. /// <param name="plcNo">PLC编号</param>
  13238. /// <param name="stationNameStr">工站全称</param>
  13239. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  13240. {
  13241. Stopwatch stopwatch1 = new Stopwatch();
  13242. Stopwatch stopwatch2 = new Stopwatch();
  13243. try
  13244. {
  13245. stopwatch1.Start();
  13246. // ZS 呼叫AGV
  13247. short e1AGVDownCall = 2;
  13248. stopwatch2.Start();
  13249. // e1AGVDownCall
  13250. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  13251. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  13252. writeToPLC_Flag.Name = "e1AGVDownCall";
  13253. writeToPLC_Flag.Adress = 2133;
  13254. writeToPLC_Flag.Value = e1AGVDownCall;
  13255. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  13256. stopwatch2.Stop();
  13257. }
  13258. catch (Exception ex)
  13259. {
  13260. string str = ex.StackTrace;
  13261. AddMessage_Station(stationNameStr, LogType.Error,
  13262. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  13263. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  13264. // e1AGVDownCall
  13265. stopwatch2.Start();
  13266. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  13267. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  13268. writeToPLC_Flag.Name = "e1AGVDownCall";
  13269. writeToPLC_Flag.Adress = 2133;
  13270. writeToPLC_Flag.Value = (short)4;
  13271. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  13272. stopwatch2.Stop();
  13273. }
  13274. stopwatch1.Stop();
  13275. AddMessage(LogType.Info,
  13276. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  13277. stopwatch2.ElapsedMilliseconds + "ms");
  13278. }
  13279. /// <summary>
  13280. /// [S5] Tray盘下料装备 - AGV下料完成
  13281. /// </summary>
  13282. /// <param name="plcNo">PLC编号</param>
  13283. /// <param name="stationNameStr">工站全称</param>
  13284. private void S5AGV下料完成(int plcNo, string stationNameStr)
  13285. {
  13286. Stopwatch stopwatch1 = new Stopwatch();
  13287. Stopwatch stopwatch2 = new Stopwatch();
  13288. try
  13289. {
  13290. stopwatch1.Start();
  13291. // ZS AGV上料完成,让小车离开
  13292. short e1AGVDownEnd = 2;
  13293. stopwatch2.Start();
  13294. // e1AGVDownEnd
  13295. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  13296. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  13297. writeToPLC_Flag.Name = "e1AGVDownEnd";
  13298. writeToPLC_Flag.Adress = 2135;
  13299. writeToPLC_Flag.Value = e1AGVDownEnd;
  13300. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  13301. stopwatch2.Stop();
  13302. }
  13303. catch (Exception ex)
  13304. {
  13305. string str = ex.StackTrace;
  13306. AddMessage_Station(stationNameStr, LogType.Error,
  13307. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  13308. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  13309. // e1AGVDownEnd
  13310. stopwatch2.Start();
  13311. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  13312. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  13313. writeToPLC_Flag.Name = "e1AGVDownEnd";
  13314. writeToPLC_Flag.Adress = 2135;
  13315. writeToPLC_Flag.Value = (short)4;
  13316. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  13317. stopwatch2.Stop();
  13318. }
  13319. stopwatch1.Stop();
  13320. AddMessage(LogType.Info,
  13321. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  13322. stopwatch2.ElapsedMilliseconds + "ms");
  13323. }
  13324. #endregion [S5] Tray盘下料装备
  13325. #endregion PLC5 张超凡
  13326. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  13327. /// <summary>
  13328. /// PLC读取到的数据 -添加数据
  13329. /// </summary>
  13330. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  13331. {
  13332. if (sxPlcData.ContainsKey(newKey))
  13333. sxPlcData[newKey] = newValue;
  13334. else
  13335. sxPlcData.Add(newKey, newValue);
  13336. }
  13337. /// <summary>
  13338. /// PLC需要写入的数据 -添加数据
  13339. /// </summary>
  13340. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey,
  13341. WriteToPLC_Flag newValue)
  13342. {
  13343. if (sxPLCWriteData.ContainsKey(newKey))
  13344. sxPLCWriteData[newKey] = newValue;
  13345. else
  13346. sxPLCWriteData.Add(newKey, newValue);
  13347. }
  13348. /// <summary>
  13349. /// PLC回写操作,写后清空flag
  13350. /// </summary>
  13351. /// <param name="modbusClient">modbus对象</param>
  13352. /// <param name="pLCReadDatas">读取到的数据字典</param>
  13353. /// <param name="pLCWriteDatas">需要写入的数据</param>
  13354. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas,
  13355. ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  13356. {
  13357. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  13358. {
  13359. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  13360. for (int i = 0; i < pLCWriteDatas.Count; i++)
  13361. {
  13362. string mesFlagName = pLCWriteDatas[i].Name;
  13363. int mesFlagAdress = pLCWriteDatas[i].Adress;
  13364. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  13365. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  13366. {
  13367. // 先回写数据
  13368. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  13369. for (int j = 0; j < writeToPLCDatas.Count; j++)
  13370. {
  13371. int mesDataAdress = writeToPLCDatas[j].Adress;
  13372. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  13373. switch (mesDataType)
  13374. {
  13375. case PLCValueType.Short:
  13376. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  13377. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  13378. break;
  13379. case PLCValueType.String:
  13380. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  13381. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  13382. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr,
  13383. mesDataValueStrLength);
  13384. break;
  13385. }
  13386. }
  13387. // 再回写信号
  13388. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  13389. // 存储读取数据的字典
  13390. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  13391. // 存储写入数据的字典 - 清空写入值
  13392. pLCWriteDatas[i].Value = (short)0;
  13393. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  13394. }
  13395. }
  13396. }
  13397. }
  13398. /// <summary>
  13399. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  13400. /// </summary>
  13401. /// <param name="no">3</param>
  13402. /// <param name="stationCode">设备编号</param>
  13403. /// <param name="stationNameStr">设备名称</param>
  13404. /// <param name="plcOrder">车间订单号</param>
  13405. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  13406. {
  13407. try
  13408. {
  13409. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  13410. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  13411. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  13412. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  13413. int result1 = 0;
  13414. switch (stationCode)
  13415. {
  13416. case 2:
  13417. case 3:
  13418. case 4:
  13419. case 6:
  13420. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  13421. break;
  13422. case 102:
  13423. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  13424. break;
  13425. case 103:
  13426. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  13427. break;
  13428. case 104:
  13429. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  13430. break;
  13431. case 106:
  13432. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  13433. break;
  13434. default:
  13435. // MES_Flag 为“6未找到正确设备编号”
  13436. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  13437. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  13438. return;
  13439. }
  13440. short result = result1 == 1 ? (short)1 : (short)2;
  13441. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  13442. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  13443. }
  13444. catch (Exception ex)
  13445. {
  13446. // MES_Flag 为2上位机报错
  13447. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  13448. string str = ex.StackTrace;
  13449. AddMessage_Station(stationNameStr, LogType.Error,
  13450. $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  13451. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  13452. }
  13453. }
  13454. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  13455. #region UI刷新
  13456. /// <summary>
  13457. /// 更新商品信息的UI + 下发产品信息(SN)
  13458. /// </summary>
  13459. private void UpdateProductInfo()
  13460. {
  13461. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  13462. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  13463. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  13464. //txt_CurSupplierCode.Text = ""; // 供应商代号
  13465. }
  13466. /// <summary>
  13467. /// 更新PLC连接状态的UI
  13468. /// </summary>
  13469. /// <param name="no">PLC编号</param>
  13470. /// <param name="status">状态</param>
  13471. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  13472. {
  13473. if (this != null && !this.IsDisposed)
  13474. {
  13475. switch (imgNo)
  13476. {
  13477. case 1:
  13478. this.BeginInvoke(new Action(() => { picPLC.Image = imageListState.Images[status]; }));
  13479. break;
  13480. case 2:
  13481. this.BeginInvoke(new Action(() => { pictureBox2.Image = imageListState.Images[status]; }));
  13482. break;
  13483. case 3:
  13484. this.BeginInvoke(new Action(() => { pictureBox3.Image = imageListState.Images[status]; }));
  13485. break;
  13486. case 4:
  13487. this.BeginInvoke(new Action(() => { pictureBox4.Image = imageListState.Images[status]; }));
  13488. break;
  13489. case 5:
  13490. this.BeginInvoke(new Action(() => { pictureBox5.Image = imageListState.Images[status]; }));
  13491. break;
  13492. case 6:
  13493. this.BeginInvoke(new Action(() => { pictureBox6.Image = imageListState.Images[status]; }));
  13494. break;
  13495. case 7:
  13496. this.BeginInvoke(new Action(() => { pictureBox7.Image = imageListState.Images[status]; }));
  13497. break;
  13498. case 8:
  13499. this.BeginInvoke(new Action(() => { pictureBox8.Image = imageListState.Images[status]; }));
  13500. break;
  13501. default:
  13502. break;
  13503. }
  13504. }
  13505. Task.Run(() => // 更新PLC交互页的指示灯
  13506. {
  13507. try
  13508. {
  13509. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  13510. {
  13511. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  13512. }
  13513. }
  13514. catch
  13515. {
  13516. }
  13517. });
  13518. }
  13519. #endregion UI刷新
  13520. #region 日志
  13521. /// <summary>
  13522. /// 添加各工位运行日志(同步至PLC交互页面)
  13523. /// </summary>
  13524. /// <param name="stationNameStr">工站名称</param>
  13525. /// <param name="logType">日志类型</param>
  13526. /// <param name="message">日志内容</param>
  13527. /// <param name="snNumber">产品数字SN</param>
  13528. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  13529. {
  13530. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")))
  13531. {
  13532. AddMessage(logType, message); // 首页展示+日志记录
  13533. }
  13534. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  13535. {
  13536. StationName = stationNameStr,
  13537. SnNumber = snNumber,
  13538. Message = message,
  13539. CreateTime = DateTime.Now
  13540. };
  13541. // PLC交互页展示
  13542. Task.Run(() =>
  13543. {
  13544. try
  13545. {
  13546. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  13547. {
  13548. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  13549. }
  13550. }
  13551. catch
  13552. {
  13553. }
  13554. });
  13555. }
  13556. /// <summary>
  13557. /// 添加运行日志
  13558. /// </summary>
  13559. /// <param name="logType">日志类型</param>
  13560. /// <param name="message">日志内容</param>
  13561. public void AddMessage(LogType logType, string message)
  13562. {
  13563. OnMessage(logType, message);
  13564. string date = DateTime.Now.ToString("yyyy/MM/dd");
  13565. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  13566. string msgShow = time + "--> " + message + "\r\n";
  13567. this.BeginInvoke(new Action(() =>
  13568. {
  13569. systemLog.Rows.Insert(0, date, time, message);
  13570. if (systemLog.Rows.Count >= 100)
  13571. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  13572. }));
  13573. }
  13574. /// <summary>
  13575. /// 添加运行日志-保存
  13576. /// </summary>
  13577. /// <param name="logType">日志类型</param>
  13578. /// <param name="message">日志内容</param>
  13579. private void OnMessage(LogType logType, string msg)
  13580. {
  13581. MessageEvent?.Invoke(logType, msg);
  13582. }
  13583. /// <summary>
  13584. /// 保存PLC写入日志
  13585. /// </summary>
  13586. /// <param name="logType"></param>
  13587. /// <param name="logValue"></param>
  13588. private void WritePLCLog(LogType logType, string logValue)
  13589. {
  13590. switch ((int)logType)
  13591. {
  13592. case 0:
  13593. _PLCLogNet.WriteDebug(logValue);
  13594. break;
  13595. case 1:
  13596. _PLCLogNet.WriteInfo(logValue);
  13597. break;
  13598. case 2:
  13599. _PLCLogNet.WriteWarn(logValue);
  13600. break;
  13601. case 3:
  13602. _PLCLogNet.WriteError(logValue);
  13603. break;
  13604. default:
  13605. _PLCLogNet.WriteFatal(logValue);
  13606. break;
  13607. }
  13608. }
  13609. /// <summary>
  13610. /// IOT Mqtt回调方法- With DataId
  13611. /// </summary>
  13612. /// <param name="id"></param>
  13613. /// <param name="v"></param>
  13614. /// <param name="dataId"></param>
  13615. public void CallbackWithDataId(string id, string msg, string dataId)
  13616. {
  13617. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  13618. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  13619. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  13620. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  13621. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  13622. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  13623. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  13624. }
  13625. /// <summary>
  13626. /// AGV Mqtt回调方法- 记录Log并处理数据
  13627. /// </summary>
  13628. /// <param name="obj"></param>
  13629. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  13630. {
  13631. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  13632. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  13633. // 接收到的信息
  13634. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  13635. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  13636. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  13637. {
  13638. }
  13639. }
  13640. #endregion 日志
  13641. //private void button1_Click(object sender, EventArgs e)
  13642. //{
  13643. // OpenDailogFalg=true;
  13644. // if (OpenDailogFalg)
  13645. // {
  13646. // using (var dialog = new BandBarodeDialog())
  13647. // {
  13648. // string strCarrierBarcode = "N801A-003";
  13649. // dialog._CarrierBarcode = strCarrierBarcode;
  13650. // string sn = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  13651. // dialog._ProductBarcode = sn;
  13652. // var rs = dialog.ShowDialog();
  13653. // if (rs == DialogResult.OK)
  13654. // {
  13655. // AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  13656. // OpenDailogFalg = false;//关闭扫码
  13657. // }
  13658. // }
  13659. // }
  13660. //}
  13661. }
  13662. }