Form_Home.cs 699 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787
  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. /*
  48. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  49. */
  50. namespace MainForm
  51. {
  52. /// <summary>
  53. /// 记录日志的委托
  54. /// </summary>
  55. /// <param name="logType">日志类型</param>
  56. /// <param name="message">日志信息</param>
  57. public delegate void HomeMessageHandler(LogType logType, string message);
  58. /// <summary>
  59. /// 主页窗体
  60. /// </summary>
  61. public partial class Form_Home : Form
  62. {
  63. #region 常量
  64. //文本常量
  65. private const string Head = "开始采集";
  66. private const string Tail = "采集完成";
  67. private const string Body = "工位出站数据";
  68. private const string BodyCheck = "工位点检数据";
  69. private const string BodyRun = "整线运行数据";
  70. private const string BodyAlarm = "整线报警数据";
  71. #endregion 常量
  72. #region 变量
  73. /// <summary>
  74. /// 委托-记录日志的方法
  75. /// </summary>
  76. public event HomeMessageHandler MessageEvent;
  77. /// <summary>
  78. /// 日志接口
  79. /// </summary>
  80. ILogNet _PLCLogNet;
  81. /// <summary>
  82. /// 用于记录IOT MQTT日志
  83. /// </summary>
  84. ILogNet _IOTMqttLogNet;
  85. /// <summary>
  86. /// 用于记录AGV MQTT日志
  87. /// </summary>
  88. ILogNet _AGVMqttLogNet;
  89. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  90. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  91. // 间隔时间
  92. private int IntervalReadPLC = 300; //ms 读PLC
  93. private int IntervalMonitorMES = 1000; //ms MES心跳
  94. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  95. /// <summary>
  96. /// 设备报警数据
  97. /// </summary>
  98. uint[] _FaultDatas = { };
  99. uint[] _FaultDatas_Old = { };
  100. // 软件状态
  101. private bool IsRun = true;
  102. #region PLC 与 TCP对象
  103. // 定义一个字典,存plc对象(通讯)
  104. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  105. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  106. // 定义TCPClient对象列表
  107. Dictionary<int, HPSocket_TcpClientHelper>
  108. _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  109. // 定义MQTTHelper对象
  110. MQTTHelper _MQTTHelper = new MQTTHelper();
  111. #endregion PLC 与 TCP对象
  112. /// <summary>
  113. /// 上次的设备运行信息
  114. /// </summary>
  115. private string lineWorkingData1_OldStr = string.Empty;
  116. /// <summary>
  117. /// 设备报警字典-当前结果
  118. /// Dictionary<工位代码,List<报警信息>>
  119. /// </summary>
  120. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  121. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  122. /// <summary>
  123. /// 单机用-设备状态
  124. /// </summary>
  125. //XiaomiDeviceState xmDeviceState = XiaomiDeviceState.Uninitialized;
  126. XiaomiDeviceStateData xmDeviceStateData = new XiaomiDeviceStateData();
  127. #endregion 变量
  128. #region 窗体基础事件
  129. /// <summary>
  130. /// 初始化
  131. /// </summary>
  132. public Form_Home()
  133. {
  134. InitializeComponent();
  135. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  136. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  137. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  138. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  139. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  140. }
  141. /// <summary>
  142. /// 窗体加载事件
  143. /// </summary>
  144. private void Form_Home_Load(object sender, EventArgs e)
  145. {
  146. try
  147. {
  148. AddMessage(LogType.Info, "开始初始化程序");
  149. //组建plc对象字典
  150. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  151. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  152. if (GlobalContext.IsUsePLC1)
  153. {
  154. GlobalContext.IsUsePLCNow = 1;
  155. GlobalContext.IsUseStationName = "[OP10]壳体清洁上料";
  156. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  157. }
  158. if (GlobalContext.IsUsePLC2)
  159. {
  160. GlobalContext.IsUsePLCNow = 2;
  161. GlobalContext.IsUseStationName = "[OP20]上盖板上料装备";
  162. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  163. }
  164. if (GlobalContext.IsUsePLC3)
  165. {
  166. GlobalContext.IsUsePLCNow = 3;
  167. GlobalContext.IsUseStationName = "[OP30]点散热胶装备";
  168. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  169. }
  170. if (GlobalContext.IsUsePLC4)
  171. {
  172. GlobalContext.IsUsePLCNow = 4;
  173. GlobalContext.IsUseStationName = "[OP40]胶线检测";
  174. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  175. }
  176. if (GlobalContext.IsUsePLC5)
  177. {
  178. GlobalContext.IsUsePLCNow = 5;
  179. GlobalContext.IsUseStationName = "[OP50]ADD板上料组装装备";
  180. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  181. }
  182. if (GlobalContext.IsUsePLC6)
  183. {
  184. GlobalContext.IsUsePLCNow = 6;
  185. GlobalContext.IsUseStationName = "[OP60]组上盖板";
  186. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  187. }
  188. if (GlobalContext.IsUsePLC7)
  189. {
  190. GlobalContext.IsUsePLCNow = 7;
  191. GlobalContext.IsUseStationName = "[OP70]上盖板锁螺丝";
  192. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  193. }
  194. if (GlobalContext.IsUsePLC8)
  195. {
  196. GlobalContext.IsUsePLCNow = 8;
  197. GlobalContext.IsUseStationName = "[OP80]NG下料";
  198. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC8Address, GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  199. }
  200. if (GlobalContext.IsUsePLC9)
  201. {
  202. GlobalContext.IsUsePLCNow = 9;
  203. GlobalContext.IsUseStationName = "[OP90]半成品下料";
  204. FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  205. }
  206. (bool,string)DicResult=InitalDicAlarm(); // 实例化报警字典
  207. AddMessage(LogType.Info, DicResult.Item2);
  208. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  209. {
  210. if (plcEIP != null)
  211. {
  212. try
  213. {
  214. (int, string) result = plcEIP.Connect();
  215. }
  216. catch (Exception ex)
  217. {
  218. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  219. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
  220. MessageBoxOptions.ServiceNotification);
  221. }
  222. }
  223. }
  224. /*
  225. //plc1Alarm.Connect();
  226. foreach (ModbusClientHelper modbusClient in Funs.Values)
  227. {
  228. if (modbusClient != null)
  229. {
  230. try
  231. {
  232. modbusClient.Connect();
  233. }
  234. catch (Exception ex)
  235. {
  236. MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
  237. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  238. }
  239. }
  240. }
  241. */
  242. // 采集任务
  243. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  244. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  245. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  246. if (GlobalContext.IsUsePLC1)
  247. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  248. if (GlobalContext.IsUsePLC2)
  249. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  250. if (GlobalContext.IsUsePLC3)
  251. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  252. if (GlobalContext.IsUsePLC4)
  253. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  254. if (GlobalContext.IsUsePLC5)
  255. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  256. if (GlobalContext.IsUsePLC6)
  257. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  258. if (GlobalContext.IsUsePLC7)
  259. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  260. if (GlobalContext.IsUsePLC8)
  261. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  262. if (GlobalContext.IsUsePLC9)
  263. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  264. #region 初始化
  265. try
  266. {
  267. // 开启边线MES(绑定/查询数据)
  268. //int mesRoute = XiaomiMES_RouteCommunication.Init();
  269. //if (mesRoute == 0)
  270. //{
  271. // //picMESStatus.Image = imageListState.Images[1];
  272. // //GlobalContext.MESIsConnect = true;
  273. // AddMessage(LogType.Info, "小米MES边线初始连接成功!");
  274. //}
  275. //else
  276. //{
  277. // //picMESStatus.Image = imageListState.Images[0];
  278. // //GlobalContext.MESIsConnect = false;
  279. // AddMessage(LogType.Info, $"小米MES边线初始连接失败!");
  280. //}
  281. // 开启MES(Http)
  282. if (GlobalContext.IsUseMES)
  283. {
  284. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  285. if (mesret)
  286. {
  287. picMESStatus.Image = imageListState.Images[1];
  288. GlobalContext.MESIsConnect = true;
  289. AddMessage(LogType.Info, "小米MES初始连接成功!");
  290. }
  291. else
  292. {
  293. picMESStatus.Image = imageListState.Images[0];
  294. GlobalContext.MESIsConnect = false;
  295. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  296. }
  297. }
  298. // 开启IOT(MQTT)
  299. if (GlobalContext.IsUseIot)
  300. {
  301. string addr = GlobalContext.MQTTServerHost;
  302. int port = GlobalContext.MQTTServerPort;
  303. //生产环境需要修改
  304. (int, string) qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666, GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  305. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult.Item1;
  306. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  307. {
  308. picIot.Image = imageListState.Images[1];
  309. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  310. // 设置回调函数
  311. //XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  312. // 配置参数
  313. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  314. // fds
  315. param.parameter.fds.address = "http://file-cm.be.mi.com/file/x5/file/upload/mqtt";
  316. param.parameter.fds.appId = "Auto-Soft";
  317. param.parameter.fds.appKey = "d11ec2b9-0e7a-4086-a80c-a1ec716e0896";
  318. // mes
  319. param.parameter.mes.address = GlobalContext.ServerIp;
  320. param.parameter.mes.appId = GlobalContext.MESAppId;
  321. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  322. // mqtt
  323. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  324. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  325. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  326. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  327. // 设备配置
  328. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  329. if (GlobalContext.IsUsePLC1)
  330. {
  331. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  332. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  333. }
  334. if (GlobalContext.IsUsePLC2)
  335. {
  336. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  337. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  338. }
  339. if (GlobalContext.IsUsePLC3)
  340. {
  341. param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
  342. //param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
  343. }
  344. if (GlobalContext.IsUsePLC4)
  345. {
  346. param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
  347. param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
  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. }
  354. if (GlobalContext.IsUsePLC6)
  355. {
  356. param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
  357. param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
  358. }
  359. if (GlobalContext.IsUsePLC7)
  360. {
  361. param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  362. //param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  363. }
  364. if (GlobalContext.IsUsePLC8)
  365. {
  366. param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
  367. param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
  368. }
  369. if (GlobalContext.IsUsePLC9)
  370. {
  371. param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
  372. param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
  373. }
  374. param.parameter.equipment.project = GlobalContext.Project_Code;
  375. param.parameter.equipment.productMode = "debug";
  376. param.parameter.other.logLevel = 0;
  377. param.parameter.other.LogPath = GlobalContext.MqttLogDir;
  378. XiaomiMqttClient_Extend.ParameterConfig(param);
  379. }
  380. else
  381. {
  382. picIot.Image = imageListState.Images[0];
  383. AddMessage(LogType.Info,
  384. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  385. }
  386. }
  387. // 开启AGV(Http与MQTT)
  388. if (GlobalContext.IsUseAGV)
  389. {
  390. // AGV HTTP
  391. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  392. if (mesret1)
  393. {
  394. picAgvHttp.Image = imageListState.Images[1];
  395. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  396. }
  397. else
  398. {
  399. picAgvHttp.Image = imageListState.Images[0];
  400. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  401. }
  402. string agvMqttIp = GlobalContext.MQTTServerHost;
  403. int agvMqttPort = GlobalContext.MQTTServerPort;
  404. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  405. ResultData_MQTT result_MQTT = _MQTTHelper
  406. .CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  407. // AGV MQTT
  408. if (result_MQTT.ResultCode == 1)
  409. {
  410. picAgvMqtt.Image = imageListState.Images[1];
  411. GlobalContext.AGVMQTTIsConnect = true;
  412. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  413. ResultData_MQTT result =
  414. XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  415. AddMessage(LogType.Info,
  416. $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  417. }
  418. else
  419. {
  420. picAgvMqtt.Image = imageListState.Images[0];
  421. GlobalContext.AGVMQTTIsConnect = false;
  422. AddMessage(LogType.Info,
  423. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  424. }
  425. }
  426. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  427. Task.Run(MonitorMESConnect);
  428. // 查询PLC连接状态
  429. foreach (int plcNo in FunsEip.Keys)
  430. {
  431. bool connected = FunsEip[plcNo].IsConnected;
  432. if (connected)
  433. {
  434. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  435. AddMessage(LogType.Info, msg);
  436. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  437. }
  438. else
  439. {
  440. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  441. AddMessage(LogType.Info, msg);
  442. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  443. }
  444. }
  445. // PLC4时 初始化扫码器TCP
  446. //if (GlobalContext.IsUsePLC4)
  447. // HpTCPClientInit();
  448. // 开启PLC的业务处理线程-监听PLC点位+状态
  449. foreach (Task task in TaskReadProcess)
  450. {
  451. if (task != null)
  452. task.Start();
  453. }
  454. //// 开启iot的线程
  455. TaskReadAlarm.Start();
  456. ////下传MES信息给1工位(先判断下plc对象数量)
  457. //if (Funs.Count > 1)
  458. // DownLoadProductInfo(1);
  459. if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  460. {
  461. uiLabel1.Text = "设备状态(左):";
  462. uiLabel2.Text = "设备状态(右):";
  463. uiLabel3.Visible = true;
  464. uiLabel2.Visible = true;
  465. }
  466. AddMessage(LogType.Info, "程序初始化完成");
  467. }
  468. catch (Exception ex)
  469. {
  470. string str = ex.StackTrace;
  471. this.BeginInvoke(new Action(() =>
  472. {
  473. AddMessage(LogType.Error,
  474. "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  475. str.Length - str.LastIndexOf("\\") - 1));
  476. }));
  477. }
  478. #endregion
  479. }
  480. catch (Exception ex)
  481. {
  482. string str = ex.StackTrace;
  483. OnMessage(LogType.Info,
  484. "主窗体的首页初始化出错!异常位置:" +
  485. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" +
  486. ex.Message.ToString());
  487. if (ex.Message != null && ex.Message.Contains("timed out"))
  488. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  489. else
  490. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  491. }
  492. }
  493. /// <summary>
  494. /// 窗体关闭事件
  495. /// </summary>
  496. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  497. {
  498. Closed2();
  499. }
  500. public void Closed2()
  501. {
  502. try
  503. {
  504. IsRun = false;
  505. Thread.Sleep(IntervalReadPLC);
  506. // 断开TCP
  507. int count = _HPSocket_TcpClients.Count();
  508. for (int i = 0; i < count; i++)
  509. {
  510. try
  511. {
  512. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  513. {
  514. _HPSocket_TcpClients[i].Stop();
  515. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  516. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  517. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  518. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  519. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  520. }
  521. }
  522. catch
  523. {
  524. }
  525. }
  526. // 关闭Iot
  527. try
  528. {
  529. XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath,
  530. GlobalContext.MqttServerName);
  531. }
  532. catch
  533. {
  534. }
  535. // 关闭AGV Mqtt
  536. try
  537. {
  538. _MQTTHelper.DisconnectAsync_Client().Wait();
  539. }
  540. catch
  541. {
  542. }
  543. }
  544. catch
  545. {
  546. }
  547. }
  548. #endregion 窗体基础事件
  549. #region 监控MES状态
  550. /// <summary>
  551. /// 监控MES连接状态
  552. /// </summary>
  553. private void MonitorMESConnect()
  554. {
  555. while (IsRun) // 运行被控线程
  556. {
  557. try
  558. {
  559. // 开启MES(Http)
  560. if (GlobalContext.IsUseMES)
  561. {
  562. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  563. if (mesret)
  564. {
  565. picMESStatus.Image = imageListState.Images[1];
  566. GlobalContext.MESIsConnect = true;
  567. }
  568. else
  569. {
  570. picMESStatus.Image = imageListState.Images[0];
  571. GlobalContext.MESIsConnect = false;
  572. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  573. }
  574. }
  575. // 开启IOT(MQTT)
  576. if (GlobalContext.IsUseIot)
  577. {
  578. bool iIot = XiaomiMqttClient.IsOpen;
  579. if (iIot)
  580. picIot.Image = imageListState.Images[1];
  581. else
  582. {
  583. picIot.Image = imageListState.Images[0];
  584. OnMessage(LogType.Info,
  585. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  586. }
  587. }
  588. // 开启AGV(Http与MQTT)
  589. if (GlobalContext.IsUseAGV)
  590. {
  591. // AGV Http
  592. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  593. if (mesret1)
  594. picAgvHttp.Image = imageListState.Images[1];
  595. else
  596. {
  597. picAgvHttp.Image = imageListState.Images[0];
  598. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  599. }
  600. // AGV MQTT
  601. if (GlobalContext.AGVMQTTIsConnect)
  602. picAgvMqtt.Image = imageListState.Images[1];
  603. else
  604. {
  605. picAgvMqtt.Image = imageListState.Images[0];
  606. OnMessage(LogType.Info,
  607. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  608. }
  609. }
  610. }
  611. catch (Exception ex)
  612. {
  613. string str = ex.StackTrace;
  614. AddMessage(LogType.Error,
  615. "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  616. str.Length - str.LastIndexOf("\\") - 1));
  617. }
  618. Thread.Sleep(IntervalMonitorMES);
  619. }
  620. }
  621. #endregion 监控MES连接状态
  622. #region 采集设备状态、运行数据、报警数据
  623. /// <summary>
  624. /// 请求设备状态 5000
  625. /// </summary>
  626. /// <param name="no">1</param>
  627. /// <param name="stationNameStr"></param>
  628. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  629. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  630. {
  631. try
  632. {
  633. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  634. {
  635. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  636. return result;
  637. }
  638. else
  639. {
  640. return 0;
  641. }
  642. }
  643. catch (Exception ex)
  644. {
  645. string str = ex.StackTrace;
  646. AddMessage_Station(stationNameStr, LogType.Error,
  647. "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  648. str.Length - str.LastIndexOf("\\") - 1));
  649. return 0;
  650. }
  651. }
  652. /// <summary>
  653. /// 检查是否可采集点检数据 - 不取新值
  654. /// 5000不为1时可点检
  655. /// </summary>
  656. /// <returns></returns>
  657. public bool CheckCanSpotcheck1(int deviceState)
  658. {
  659. //return true;
  660. //D5000 = 1,代表设备控制状态处于运行状态
  661. //D5000 = 2, 代表设备控制状态处于故障状态
  662. //D5000 = 3,代表设备控制状态处于缺料状态
  663. //D5000 = 4, 代表设备控制状态处于待机状态
  664. //D5000 = 5,代表设备控制状态处于维修状态
  665. return deviceState != 1;
  666. }
  667. /// <summary>
  668. /// 检查是否可采集产品数据 - 不取新值
  669. /// </summary>
  670. /// <returns></returns>
  671. public bool CheckCanCollData(int deviceState)
  672. {
  673. return deviceState == 0; // 点检时该值不为0
  674. }
  675. /// <summary>
  676. /// 采集到的设备状态
  677. /// </summary>
  678. private string _DeviceStates = "未知状态";
  679. private string _DeviceStates_Old = "未知状态";
  680. private string _DeviceStates2 = "未知状态";
  681. private string _DeviceStates_Old2 = "未知状态";
  682. /// <summary>
  683. /// 获取设备报警数据与获取设备运行信息
  684. /// </summary>
  685. private async void ReadAlarmAllPLC()
  686. {
  687. /// 获取设备报警数据与状态信息
  688. string stationNameStr = "获取设备报警数据与状态信息";
  689. // 已连接到PLC
  690. while (IsRun)
  691. {
  692. try
  693. {
  694. #region 报警数据
  695. try
  696. {
  697. //_FaultDatas = new uint[] { 4, 0, 30, 10 };
  698. if (_FaultDatas.Length>0)
  699. {
  700. ReadPLCAlarmToIot(_FaultDatas, stationNameStr);
  701. }
  702. else
  703. {
  704. AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!" );
  705. }
  706. }
  707. catch (Exception ex)
  708. {
  709. string str = ex.StackTrace;
  710. AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  711. }
  712. #endregion 报警数据
  713. #region 设备状态
  714. //if (!GlobalContext._IsCon_plc1Alarm)
  715. //{
  716. // UpdatePLCMonitor(1, -2, 0);
  717. // continue;
  718. //}
  719. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  720. {
  721. if (plcEIP != null)
  722. {
  723. if (plcEIP.IsConnected)
  724. {
  725. #region 主页展示设备运行状态并上传到IOT中,有双工位left就是左工位,没有双工位left就是单工位
  726. switch (xmDeviceStateData.left)
  727. {
  728. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  729. _DeviceStates = "未初始化状态";
  730. lblDeviceStates.Text = _DeviceStates;
  731. break;
  732. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  733. _DeviceStates = "初始化状态";
  734. lblDeviceStates.Text = _DeviceStates;
  735. break;
  736. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  737. _DeviceStates = "初始化完成状态";
  738. lblDeviceStates.Text = _DeviceStates;
  739. break;
  740. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  741. _DeviceStates = "运行状态";
  742. lblDeviceStates.Text = _DeviceStates;
  743. break;
  744. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  745. _DeviceStates = "暂停状态";
  746. lblDeviceStates.Text = _DeviceStates;
  747. break;
  748. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  749. _DeviceStates = "故障状态";
  750. lblDeviceStates.Text = _DeviceStates;
  751. break;
  752. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  753. _DeviceStates = "警报状态";
  754. lblDeviceStates.Text = _DeviceStates;
  755. break;
  756. }
  757. if (!_DeviceStates.Equals(_DeviceStates_Old))
  758. {
  759. var iotResult =
  760. SaveDeviceStateData(stationNameStr, xmDeviceStateData.left, "left"); // 上传+保存
  761. if (iotResult.Item1 == 1)
  762. {
  763. _DeviceStates_Old = _DeviceStates;
  764. AddMessage_Station(stationNameStr, LogType.Info,
  765. "【设备状态】" + stationNameStr + $"_上传设备状态到Iot成功!");
  766. }
  767. else
  768. AddMessage_Station(stationNameStr, LogType.Info,
  769. "【设备状态】"+stationNameStr +
  770. $"_上传设备状态到Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  771. }
  772. #endregion 主页展示设备运行状态并上传到IOT中
  773. #region 右工位
  774. if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  775. {
  776. switch (xmDeviceStateData.right)
  777. {
  778. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  779. _DeviceStates2 = "未初始化状态";
  780. lblDeviceStates.Text = _DeviceStates2;
  781. break;
  782. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  783. _DeviceStates2 = "初始化状态";
  784. lblDeviceStates.Text = _DeviceStates2;
  785. break;
  786. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  787. _DeviceStates2 = "初始化完成状态";
  788. lblDeviceStates.Text = _DeviceStates2;
  789. break;
  790. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  791. _DeviceStates2 = "运行状态";
  792. lblDeviceStates.Text = _DeviceStates2;
  793. break;
  794. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  795. _DeviceStates2 = "暂停状态";
  796. lblDeviceStates.Text = _DeviceStates2;
  797. break;
  798. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  799. _DeviceStates2 = "故障状态";
  800. lblDeviceStates.Text = _DeviceStates2;
  801. break;
  802. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  803. _DeviceStates2 = "警报状态";
  804. lblDeviceStates.Text = _DeviceStates2;
  805. break;
  806. }
  807. if (!_DeviceStates2.Equals(_DeviceStates_Old2))
  808. {
  809. var iotResult = SaveDeviceStateData(stationNameStr, xmDeviceStateData.left,
  810. "right"); // 上传+保存
  811. if (iotResult.Item1 == 1)
  812. {
  813. _DeviceStates_Old2 = _DeviceStates2;
  814. AddMessage_Station(stationNameStr, LogType.Info,
  815. "【设备状态】" + stationNameStr + $"_上传Iot成功!");
  816. }
  817. else
  818. AddMessage_Station(stationNameStr, LogType.Info,
  819. "【设备状态】" + stationNameStr +
  820. $"_上传Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  821. }
  822. }
  823. #endregion 右工位
  824. }
  825. }
  826. }
  827. #endregion
  828. //if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  829. //{
  830. // DateTime dtNow = DateTime.Now;
  831. // //#region 获取设备运行信息
  832. // //try
  833. // //{
  834. // // LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  835. // // lineWorkingData1.GUID = Guid.NewGuid().ToString();
  836. // // lineWorkingData1.LineName = GlobalContext.LineCode;
  837. // // //
  838. // // lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  839. // // lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  840. // // lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  841. // // lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  842. // // lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  843. // // lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  844. // // lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  845. // // lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  846. // // lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  847. // // lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  848. // // lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  849. // // lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  850. // // lineWorkingData1.CreateTime = DateTime.Now;
  851. // // string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  852. // // // UI展示-展示到设备状态页
  853. // // if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  854. // // {
  855. // // // 查询数据库最新一条数据,确定是不是更新
  856. // // string qSql = @"SELECT top(1) [GUID]
  857. // // ,[LineName]
  858. // // ,[BootTimeLong]
  859. // // ,[NormalTimeLong]
  860. // // ,[StandbyTimeLong]
  861. // // ,[FaultTimeLong]
  862. // // ,[MaterialShortageTimeLong]
  863. // // ,[MaintenanceTimeLong]
  864. // // ,[FaultNumber]
  865. // // ,[OutputNumber]
  866. // // ,[QualifiedNumber]
  867. // // ,[QualifiedRate]
  868. // // ,[DesignRhythm]
  869. // // ,[RealityRhythm]
  870. // // ,[CreateTime]
  871. // // FROM [LineWorkingData]
  872. // // where [CreateTime] > '{0}'
  873. // // and [LineName]='{1}'
  874. // // order by [CreateTime] desc
  875. // // ";
  876. // // qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  877. // // var ds = SQLHelper_New.Query(qSql, null);
  878. // // if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  879. // // {
  880. // // var dataDBlast = new LineWorkingData_ThisTime();
  881. // // dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  882. // // dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  883. // // dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  884. // // dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  885. // // if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  886. // // {
  887. // // dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  888. // // dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  889. // // dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  890. // // dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  891. // // dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  892. // // dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  893. // // dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  894. // // dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  895. // // dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  896. // // dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  897. // // dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  898. // // dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  899. // // string usql = dataDBlast.ToStringUpdate();
  900. // // SQLHelper_New.ExecuteSQL(usql, null);
  901. // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  902. // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  903. // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  904. // // }
  905. // // }
  906. // // else
  907. // // {
  908. // // // 插入
  909. // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  910. // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  911. // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  912. // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  913. // // }
  914. // // }
  915. // // else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  916. // // {
  917. // // LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  918. // // //// 本次开机设备运行情况
  919. // // //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  920. // // //Task.Run(() =>
  921. // // //{
  922. // // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  923. // // // {
  924. // // // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  925. // // // }
  926. // // //});
  927. // // // 本日设备运行情况
  928. // // // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  929. // // if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  930. // // {
  931. // // // 更新
  932. // // lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  933. // // lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  934. // // lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  935. // // lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  936. // // lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  937. // // lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  938. // // lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  939. // // lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  940. // // lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  941. // // lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  942. // // lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  943. // // lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  944. // // SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  945. // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  946. // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  947. // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  948. // // }
  949. // // else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  950. // // {
  951. // // // 插入
  952. // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  953. // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  954. // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  955. // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  956. // // }
  957. // // await Task.Run(() =>
  958. // // {
  959. // // try
  960. // // {
  961. // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  962. // // {
  963. // // Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  964. // // }
  965. // // }
  966. // // catch { }
  967. // // });
  968. // // }
  969. // //}
  970. // //catch (Exception ex)
  971. // //{
  972. // // string str = ex.StackTrace;
  973. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  974. // //}
  975. // //#endregion 获取设备运行信息
  976. // #region 报警数据
  977. // try
  978. // {
  979. // List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  980. // bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  981. // // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  982. // var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  983. // for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  984. // {
  985. // short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  986. // dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  987. // if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  988. // {
  989. // isNeedUpdUI = true; // 需要更新历史报警UI信息
  990. // // 记录
  991. // dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  992. // switch (dicAlarms_Cur_PLC1[i].是否报警)
  993. // {
  994. // case true: // 报警
  995. // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  996. // {
  997. // GUID = Guid.NewGuid().ToString(),
  998. // LineName = GlobalContext.LineCode, // 线体
  999. // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  1000. // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  1001. // StartTime = dtNow // 开始时间
  1002. // };
  1003. // // 传输到页面
  1004. // deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  1005. // {
  1006. // 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  1007. // 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  1008. // 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  1009. // 开始时间 = dtNow
  1010. // });
  1011. // // 新增到数据库
  1012. // var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  1013. // SaveAlarmDataByDB(stationNameStr, data1, false);
  1014. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  1015. // break;
  1016. // case false: // 消除报警
  1017. // if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  1018. // {
  1019. // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  1020. // {
  1021. // GUID = Guid.NewGuid().ToString(),
  1022. // LineName = GlobalContext.LineCode, // 线体
  1023. // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  1024. // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  1025. // StartTime = dtNow, // 开始时间
  1026. // EndTime = dtNow, // 开始时间
  1027. // PersistTime = 1, // 耗时1s
  1028. // };
  1029. // // 新增
  1030. // var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  1031. // SaveAlarmDataByDB(stationNameStr, data2, false);
  1032. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  1033. // }
  1034. // else
  1035. // {
  1036. // dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  1037. // dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  1038. // - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  1039. // // 修改
  1040. // var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  1041. // SaveAlarmDataByDB(stationNameStr, data3, true);
  1042. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  1043. // }
  1044. // break;
  1045. // default:
  1046. // break;
  1047. // }
  1048. // }
  1049. // }
  1050. // DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  1051. // // 有新报警则更新
  1052. // if (isNeedUpdUI)
  1053. // {
  1054. // // UI展示 - 展示到设备状态页
  1055. // await Task.Run(() =>
  1056. // {
  1057. // try
  1058. // {
  1059. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  1060. // {
  1061. // Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  1062. // if (Form_Main.formDevAlarm.Visible)
  1063. // {
  1064. // Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  1065. // }
  1066. // }
  1067. // }
  1068. // catch { }
  1069. // });
  1070. // }
  1071. // }
  1072. // catch (Exception ex)
  1073. // {
  1074. // string str = ex.StackTrace;
  1075. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1076. // }
  1077. // #endregion 报警数据
  1078. // UpdatePLCMonitor(1, -2, 1);
  1079. //}
  1080. //else
  1081. //{
  1082. // UpdatePLCMonitor(1, -2, 0);
  1083. //}
  1084. }
  1085. catch (Exception ex)
  1086. {
  1087. //AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1088. AddMessage_Station(stationNameStr, LogType.Error,
  1089. $"PLC1_{stationNameStr}_采集运行数据与报警数据出错!错误信息:" + ex.Message.ToString());
  1090. }
  1091. Thread.Sleep(IntervalAlarm);
  1092. }
  1093. }
  1094. #endregion 轮询PLC
  1095. #region 下发订单信息
  1096. ///// <summary>
  1097. ///// 壳体上料(下发工单)的交互逻辑
  1098. ///// </summary>
  1099. ///// <param name="no"></param>
  1100. ///// <exception cref="NotImplementedException"></exception>
  1101. //private void ReadStation_DownOrderInfo(int plcNo)
  1102. //{
  1103. // // [S1] Tray盘上料装备(板测)
  1104. // // [S2] FCT(板测)
  1105. // // [S3] 值板机
  1106. // // [S4] 取放桁架
  1107. // // [S5] Tray盘下料装备
  1108. // /// 上位机心跳
  1109. // /// 获取设备报警数据与状态信息
  1110. // string stationNameStr = "[S0]壳体上料";
  1111. // while (IsRun)
  1112. // {
  1113. // try
  1114. // {
  1115. // if (!GlobalContext._IsCon_Funs1)
  1116. // {
  1117. // UpdatePLCMonitor(plcNo, 0);
  1118. // continue;
  1119. // }
  1120. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  1121. // {
  1122. // #region 壳体上料(下发工单)
  1123. // try
  1124. // {
  1125. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  1126. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  1127. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  1128. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  1129. // // 重置数据和信号
  1130. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  1131. // {
  1132. // // 清空写给PLC的数据
  1133. // int[] i497 = new int[1] { 0 };
  1134. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  1135. // // MES_Flag重置为0
  1136. // int[] i500 = new int[1] { 0 };
  1137. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  1138. // }
  1139. // }
  1140. // catch (Exception ex)
  1141. // {
  1142. // string str = ex.StackTrace;
  1143. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1144. // }
  1145. // #endregion 壳体上料(下发工单)
  1146. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1147. // }
  1148. // else
  1149. // {
  1150. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  1151. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1152. //
  1153. // Funs[plcNo].Connect();
  1154. // }
  1155. // }
  1156. // catch (Exception ex)
  1157. // {
  1158. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  1159. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1160. //
  1161. // Funs[plcNo].ReConnect();
  1162. // }
  1163. // Thread.Sleep(IntervalReadPLC);
  1164. // }
  1165. //}
  1166. ///// <summary>
  1167. ///// 下发订单信息到PLC
  1168. ///// </summary>
  1169. ///// <param name="no">PLC编号</param>
  1170. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  1171. //{
  1172. // try
  1173. // {
  1174. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  1175. // {
  1176. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  1177. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  1178. // }
  1179. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  1180. // }
  1181. // catch (Exception ex)
  1182. // {
  1183. // string str = ex.StackTrace;
  1184. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1185. // }
  1186. //}
  1187. /// <summary>
  1188. /// 下发清料信号
  1189. /// </summary>
  1190. /// <param name="no">PLC编号</param>
  1191. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  1192. {
  1193. try
  1194. {
  1195. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  1196. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  1197. return true;
  1198. }
  1199. catch (Exception ex)
  1200. {
  1201. string str = ex.StackTrace;
  1202. AddMessage_Station(stationNameStr, LogType.Error,
  1203. "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  1204. str.Length - str.LastIndexOf("\\") - 1));
  1205. return false;
  1206. }
  1207. }
  1208. #endregion 下发订单信息
  1209. #region Xiaomi 贲流
  1210. #region 公共方法
  1211. private static bool ProgressState = false;
  1212. private static readonly object lockObj = new object(); // 锁对象
  1213. private static bool isCollectingFlagLeft;
  1214. private static bool isCollectingFlagRight;
  1215. /// <summary>
  1216. /// float[]转为string
  1217. /// </summary>
  1218. public string FloatArrayToString(float[] nScrewResults)
  1219. {
  1220. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  1221. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  1222. }
  1223. /// <summary>
  1224. /// short[]转为string
  1225. /// </summary>
  1226. public string ShortArrayToString(short[] nScrewResults)
  1227. {
  1228. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  1229. return string.Join(",", nScrewResults);
  1230. }
  1231. /// <summary>
  1232. /// 写入PLC重复三次
  1233. /// </summary>
  1234. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount,
  1235. T inObj)
  1236. {
  1237. int i = 0;
  1238. int nRet = 0;
  1239. string strRet = "";
  1240. try
  1241. {
  1242. while (i < 3) // 最多上传三次
  1243. {
  1244. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  1245. if (nRet == 0) //成功
  1246. {
  1247. break;
  1248. }
  1249. else
  1250. {
  1251. AddMessage_Station(stationNameStr, LogType.Error,
  1252. $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1253. i++;
  1254. }
  1255. }
  1256. return (nRet, strRet);
  1257. }
  1258. catch (Exception ex)
  1259. {
  1260. return (1, ex.Message);
  1261. }
  1262. }
  1263. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes,
  1264. short[] nScrewOrders, short[] nScrewResults)
  1265. {
  1266. try
  1267. {
  1268. // 获取当前日期
  1269. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1270. // 构建保存路径
  1271. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  1272. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction, "螺丝Mes数据");
  1273. // 确保目录存在
  1274. Directory.CreateDirectory(savePath);
  1275. // 文件名
  1276. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  1277. string filePath = Path.Combine(savePath, fileName);
  1278. // 确保不会超出数组长度,只取前14个或数组的实际长度
  1279. int count = Math.Min(14, fScrewTimes.Length);
  1280. using (StreamWriter sw = new StreamWriter(filePath))
  1281. {
  1282. for (int i = 0; i < count; i++)
  1283. {
  1284. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  1285. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  1286. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  1287. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  1288. sw.WriteLine(); // 空行分隔不同螺丝的信息
  1289. }
  1290. }
  1291. return (0, "");
  1292. }
  1293. catch (Exception ex)
  1294. {
  1295. return (1, ex.Message);
  1296. }
  1297. }
  1298. public Dictionary<string, string> GetLastLineCompensation(string path, string direction, string sn)
  1299. {
  1300. // 创建字典存储补偿点及其对应的值
  1301. Dictionary<string, string> compensationDict = new Dictionary<string, string>();
  1302. try
  1303. {
  1304. //string path = GlobalContext.MESLaserRPath;
  1305. // 获取当前日期并格式化为 "yyyy-MM-dd" 格式
  1306. string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
  1307. string filename = $"Laser-{currentDate}-W0.txt";
  1308. // 拼接完整路径
  1309. string fullPath = Path.Combine(path, filename);
  1310. string lastNonEmptyLine = "";
  1311. // 判断文件是否存在
  1312. if (File.Exists(fullPath))
  1313. {
  1314. //读取文件内容
  1315. string[] lines = File.ReadAllLines(fullPath);
  1316. // 获取最后一行数据(忽略标题行)
  1317. if (lines.Length > 1)
  1318. {
  1319. string lastLine = "";
  1320. for (int i = lines.Length - 1; i > 0; i--)
  1321. {
  1322. if (!string.IsNullOrEmpty(lines[i]))
  1323. {
  1324. lastLine = lines[i];
  1325. break;
  1326. }
  1327. }
  1328. // 将最后一行按逗号分隔
  1329. string[] values = lastLine.Split(',');
  1330. values[1] = sn;
  1331. string key = "三点激光_" + direction; // 构造键名
  1332. string value = string.Join(",", values); // 获取值并去除多余空格
  1333. compensationDict[key] = value;
  1334. //// 提取“1点补偿”到“6点补偿”的值
  1335. //for (int i = 2; i <= 7 && i < values.Length; i++) // 从索引2开始,最多提取6个值
  1336. //{
  1337. // string key = $"{i - 1}点补偿"; // 构造键名
  1338. // string value = values[i].Trim(); // 获取值并去除多余空格
  1339. // compensationDict[key] = value;
  1340. //}
  1341. }
  1342. }
  1343. else
  1344. {
  1345. Console.WriteLine($"文件不存在: {fullPath}");
  1346. }
  1347. }
  1348. catch (Exception ex)
  1349. {
  1350. // 捕获异常并输出错误信息
  1351. Console.WriteLine($"发生错误: {ex.Message}");
  1352. }
  1353. return compensationDict;
  1354. }
  1355. /// <summary>
  1356. /// 调用进站接口并保存进站数据
  1357. /// </summary>
  1358. /// <param name="stationNameStr">工站信息</param>
  1359. /// <param name="workorder_code">工单号</param>
  1360. /// <param name="mtltmrk">型号(物料号)</param>
  1361. /// <param name="sn">产品SN</param>
  1362. /// <param name="items">进站数据</param>
  1363. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1364. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn,
  1365. List<TestItem> items, string MachineId, string StationId)
  1366. {
  1367. int result = 0;
  1368. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1369. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1370. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1371. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1372. inRequest_Body.clientTime =
  1373. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1374. inRequest_Body.unitSn = sn; // 产品SN
  1375. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1376. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1377. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1378. StationIn stationIn = new StationIn()
  1379. {
  1380. Workorder_code = workorder_code, // 车间订单号
  1381. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1382. Sn = sn, // SN
  1383. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1384. Parameter_values = items, // 进站数据
  1385. Write_user = inRequest_Body.userId, // 员工Id
  1386. Test_time = inRequest_Body.clientTime // 进站时间
  1387. };
  1388. // 本地数据
  1389. string sql = stationIn.ToStringInsert(0);
  1390. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1391. result = ret == "成功" ? 1 : 6;
  1392. //await Task.Delay(200);
  1393. // 上传MES
  1394. if (GlobalContext.IsSendStationIn)
  1395. {
  1396. try
  1397. {
  1398. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1399. string resultJson = "";
  1400. string mesRet = string.Empty;
  1401. int i = 0;
  1402. while (i < 2) // 1009会多次尝试上传
  1403. {
  1404. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1405. resultJson = JsonConvert.SerializeObject(response);
  1406. if (response != null && response.header.code == "200")
  1407. break;
  1408. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1409. i++;
  1410. i++;
  1411. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1412. // 记录失败原因
  1413. OnMessage(LogType.Error, $"上传出站数据到MES服务器---失败!正在重新上传!请求参数:{json_Body},接口报错信息:" + mesRet);
  1414. }
  1415. if (response?.header?.code == "200")
  1416. {
  1417. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1418. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1419. result = ret_Upd == "成功" ? 1 : 6;
  1420. AddMessage( LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功,请求参数:{json_Body},返回参数:{resultJson}");
  1421. }
  1422. else
  1423. {
  1424. result = 5;
  1425. AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!请求参数:{json_Body},接口报错信息:" + mesRet);
  1426. }
  1427. string sql_response =
  1428. stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1429. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1430. }
  1431. catch (Exception ex)
  1432. {
  1433. result = 6;
  1434. string str = ex.StackTrace;
  1435. AddMessage_Station(stationNameStr, LogType.Error,
  1436. $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1437. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1438. }
  1439. }
  1440. return result;
  1441. }
  1442. /// <summary>
  1443. /// 选择如何记录出站数据
  1444. /// </summary>
  1445. /// <param name="items">出站数据</param>
  1446. /// <param name="equipmentCode">设备编号</param>
  1447. /// <param name="processItem">测试项目</param>
  1448. /// <param name="workorder_code">车间订单号</param>
  1449. /// <param name="batch_num">批次号</param>
  1450. /// <param name="mtltmrk">型号</param>
  1451. /// <param name="proDate">日期</param>
  1452. /// <param name="supplierCode">供应商代码</param>
  1453. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1454. /// <returns>上传成功时返回1;失败返回0</returns>
  1455. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode,
  1456. string processItem,
  1457. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1458. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode,string jsonParm, string direction="")
  1459. {
  1460. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
  1461. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode, jsonParm, direction);
  1462. }
  1463. /// <summary>
  1464. /// 添加出站数据(提交到MES+本地保存到数据库)
  1465. /// </summary>
  1466. /// <param name="items">出站数据</param>
  1467. /// <param name="equipmentCode">设备编号</param>
  1468. /// <param name="processItem">测试项目</param>
  1469. /// <param name="workorder_code">车间订单号</param>
  1470. /// <param name="batch_num">批次号</param>
  1471. /// <param name="mtltmrk">型号</param>
  1472. /// <param name="proDate">日期</param>
  1473. /// <param name="supplierCode">供应商代码</param>
  1474. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1475. /// <returns>上传成功时返回1;失败返回0</returns>
  1476. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1477. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1478. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode,string jsonParm,string direction="")
  1479. {
  1480. int upload = 0;
  1481. int result = 0;
  1482. ProcessData processData = new ProcessData()
  1483. {
  1484. Equipment_code = equipmentCode,
  1485. Workorder_code = workorder_code,
  1486. Batch_number = batch_num,
  1487. Sn = sn, // SN
  1488. Testitem = processItem,
  1489. Parameter_values = items,
  1490. Write_user = GlobalContext.CurrentUser,
  1491. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1492. };
  1493. // 本地数据
  1494. string sql = processData.ToStringInsert(upload);
  1495. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1496. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1497. // 上传MES
  1498. if (GlobalContext.IsSendProcessData)
  1499. {
  1500. try
  1501. {
  1502. string id = processData.ID.Copy();
  1503. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1504. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1505. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1506. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1507. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1508. outRequest_Body.unitSn = sn; // 产品SN
  1509. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1510. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1511. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1512. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1513. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1514. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1515. if (!string.IsNullOrEmpty(partBarcode))
  1516. {
  1517. outRequest_Body.unitData.keyMaterial.Add(
  1518. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1519. {
  1520. bindSort = 1,
  1521. materialSn = partBarcode
  1522. }); // 设备数据 - 部件码
  1523. }
  1524. //OP30站读txt数据
  1525. if (stationNameStr.Contains("CPAPHD"))
  1526. {
  1527. string path = "";
  1528. if (direction == "Left")
  1529. path = GlobalContext.MESLaserLPath;
  1530. else
  1531. path = GlobalContext.MESLaserRPath;
  1532. //字典存储数据
  1533. Dictionary<string, string> compensationDict = GetLastLineCompensation(path, direction, sn);
  1534. foreach (var kvp in compensationDict)
  1535. {
  1536. outRequest_Body.unitData.processData.Add(
  1537. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1538. {
  1539. dataName = kvp.Key.ToString(),
  1540. dataValue = kvp.Value.ToString()
  1541. });
  1542. }
  1543. }
  1544. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1545. if (GlobalContext.IsSendProcessData)
  1546. {
  1547. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1548. string mesRet = string.Empty;
  1549. int i = 0;
  1550. while (i < 2) // 1009会多次尝试上传
  1551. {
  1552. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1553. if (response != null && response.header.code == "200")
  1554. {
  1555. OnMessage(LogType.Error,
  1556. "上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" +
  1557. JsonConvert.SerializeObject(response.body));
  1558. break;
  1559. }
  1560. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1561. i++;
  1562. i++;
  1563. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1564. // 记录失败原因
  1565. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1566. }
  1567. if (response?.header?.code == "200")
  1568. {
  1569. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1570. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1571. result = 1;
  1572. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1573. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1574. }
  1575. else
  1576. {
  1577. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1578. }
  1579. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(
  1580. JsonConvert.SerializeObject(outRequest_Body),
  1581. JsonConvert.SerializeObject(response), id);
  1582. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1583. }
  1584. }
  1585. catch (Exception ex)
  1586. {
  1587. string str = ex.StackTrace;
  1588. AddMessage_Station(stationNameStr, LogType.Error,
  1589. $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1590. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1591. }
  1592. }
  1593. return result;
  1594. }
  1595. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1596. //{
  1597. // Stopwatch stopwatch = new Stopwatch();
  1598. // stopwatch.Start();
  1599. // try
  1600. // {
  1601. // // 初始化 AtlasScrew 实例
  1602. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1603. // atlasScrew1.Initial();
  1604. // // 存储结果的列表
  1605. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1606. // // 存储角度和扭力的字符串列表
  1607. // List<string> angleStrs = new List<string>();
  1608. // List<string> torqueStrs = new List<string>();
  1609. // // 上一次获取的数据
  1610. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1611. // while (isExitAtlasLeft) // 检查是否收集数据
  1612. // {
  1613. // // 获取当前数据
  1614. // var currentResult = atlasScrew1.GetResults();
  1615. // // 判断是否为新数据
  1616. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1617. // {
  1618. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1619. // // 更新角度和扭力的字符串列表
  1620. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1621. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1622. // // 计算角度、扭力、起始扭力和最大扭力
  1623. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1624. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1625. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1626. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1627. // // 将新数据添加到结果列表
  1628. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1629. // // 更新上一次获取的数据
  1630. // lastResult = currentResult;
  1631. // }
  1632. // // 等待一段时间后再次检查
  1633. // Thread.Sleep(20); // 轮询间隔时间
  1634. // // 如果触发了出站,则退出循环
  1635. // if (!isExitAtlasLeft)
  1636. // {
  1637. // break;
  1638. // }
  1639. // }
  1640. // // 生成文件名
  1641. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1642. // // 写入数据到文件
  1643. // using (StreamWriter writer = new StreamWriter(fileName))
  1644. // {
  1645. // // 写入标题行
  1646. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1647. // // 写入每一行数据
  1648. // foreach (var result in results)
  1649. // {
  1650. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1651. // }
  1652. // }
  1653. // stopwatch.Stop();
  1654. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1655. // }
  1656. // catch (Exception ex)
  1657. // {
  1658. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1659. // }
  1660. // finally
  1661. // {
  1662. // // 重置标志变量
  1663. // isExitAtlasLeft = false;
  1664. // }
  1665. //}
  1666. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1667. //{
  1668. // Stopwatch stopwatch = new Stopwatch();
  1669. // stopwatch.Start();
  1670. // try
  1671. // {
  1672. // // 初始化 AtlasScrew 实例
  1673. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1674. // atlasScrew2.Initial();
  1675. // // 存储结果的列表
  1676. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1677. // // 上一次获取的数据
  1678. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1679. // while (isExitAtlasRight) // 检查是否收集数据
  1680. // {
  1681. // // 获取当前数据
  1682. // var currentResult = atlasScrew2.GetResults();
  1683. // // 判断是否为新数据
  1684. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1685. // {
  1686. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1687. // // 将新数据写入PLC
  1688. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1689. // // 将新数据添加到结果列表
  1690. // results.Add(currentResult);
  1691. // // 更新上一次获取的数据
  1692. // lastResult = currentResult;
  1693. // }
  1694. // // 等待一段时间后再次检查
  1695. // Thread.Sleep(20); // 轮询间隔时间
  1696. // // 如果触发了出站,则退出循环
  1697. // if (!isExitAtlasRight)
  1698. // {
  1699. // break;
  1700. // }
  1701. // }
  1702. // // 将所有数据写入文件
  1703. // //WriteDataToFile(sn, direction, results);
  1704. // stopwatch.Stop();
  1705. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1706. // }
  1707. // catch (Exception ex)
  1708. // {
  1709. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1710. // }
  1711. // finally
  1712. // {
  1713. // // 重置标志变量
  1714. // isExitAtlasRight = false;
  1715. // }
  1716. //}
  1717. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1718. {
  1719. Stopwatch stopwatch = new Stopwatch();
  1720. stopwatch.Start();
  1721. int nRet = 0;
  1722. string strRet = "";
  1723. try
  1724. {
  1725. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1726. while (isCollectingFlagLeft)
  1727. {
  1728. // 从缓存中获取所有未处理的数据
  1729. var cachedData = atlasScrew.GetCachedDataLeft();
  1730. foreach (var currentResult in cachedData)
  1731. {
  1732. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1733. {
  1734. continue; // 跳过无效数据
  1735. }
  1736. OnMessage(LogType.Info,
  1737. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1738. // 写入PLC
  1739. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1740. {
  1741. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1742. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1743. };
  1744. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1745. if (nRet != 0)
  1746. {
  1747. OnMessage(LogType.Info,
  1748. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1749. }
  1750. else
  1751. {
  1752. OnMessage(LogType.Info,
  1753. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1754. }
  1755. // 构建保存路径
  1756. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1757. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1758. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1759. Directory.CreateDirectory(savePath); // 确保目录存在
  1760. // 构建文件名(以 SN + 序号命名)
  1761. string fileName = $"{sn}_{fileCounter}.txt";
  1762. string filePath = Path.Combine(savePath, fileName);
  1763. // 写入文件
  1764. using (StreamWriter writer = new StreamWriter(filePath))
  1765. {
  1766. writer.WriteLine("精度, 扭力");
  1767. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1768. for (int i = 0;
  1769. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  1770. i++)
  1771. {
  1772. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1773. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1774. writer.WriteLine($"{precision}, {torque}");
  1775. }
  1776. }
  1777. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1778. // 增加文件计数器
  1779. fileCounter++;
  1780. }
  1781. // 如果没有更多数据,则短暂休眠以节省资源
  1782. if (!cachedData.Any())
  1783. {
  1784. Thread.Sleep(10); // 根据需要调整休眠时间
  1785. }
  1786. // 如果触发了出站,则退出循环
  1787. if (!isCollectingFlagLeft)
  1788. {
  1789. break;
  1790. }
  1791. }
  1792. stopwatch.Stop();
  1793. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1794. }
  1795. catch (Exception ex)
  1796. {
  1797. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1798. }
  1799. finally
  1800. {
  1801. isCollectingFlagLeft = false;
  1802. }
  1803. }
  1804. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1805. {
  1806. Stopwatch stopwatch = new Stopwatch();
  1807. stopwatch.Start();
  1808. int nRet = 0;
  1809. string strRet = "";
  1810. try
  1811. {
  1812. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1813. while (isCollectingFlagRight)
  1814. {
  1815. // 从缓存中获取所有未处理的数据
  1816. var cachedData = atlasScrew.GetCachedDataLeft();
  1817. foreach (var currentResult in cachedData)
  1818. {
  1819. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1820. {
  1821. continue; // 跳过无效数据
  1822. }
  1823. OnMessage(LogType.Info,
  1824. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1825. // 写入PLC
  1826. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1827. {
  1828. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1829. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1830. };
  1831. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1832. if (nRet != 0)
  1833. {
  1834. OnMessage(LogType.Info,
  1835. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1836. }
  1837. else
  1838. {
  1839. OnMessage(LogType.Info,
  1840. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1841. }
  1842. // 构建保存路径
  1843. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1844. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1845. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1846. Directory.CreateDirectory(savePath); // 确保目录存在
  1847. // 构建文件名(以 SN + 序号命名)
  1848. string fileName = $"{sn}_{fileCounter}.txt";
  1849. string filePath = Path.Combine(savePath, fileName);
  1850. // 写入文件
  1851. using (StreamWriter writer = new StreamWriter(filePath))
  1852. {
  1853. writer.WriteLine("精度, 扭力");
  1854. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1855. for (int i = 0;
  1856. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  1857. i++)
  1858. {
  1859. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1860. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1861. writer.WriteLine($"{precision}, {torque}");
  1862. }
  1863. }
  1864. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1865. // 增加文件计数器
  1866. fileCounter++;
  1867. }
  1868. // 如果没有更多数据,则短暂休眠以节省资源
  1869. if (!cachedData.Any())
  1870. {
  1871. Thread.Sleep(10); // 根据需要调整休眠时间
  1872. }
  1873. // 如果触发了出站,则退出循环
  1874. if (!isCollectingFlagRight)
  1875. {
  1876. break;
  1877. }
  1878. }
  1879. stopwatch.Stop();
  1880. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1881. }
  1882. catch (Exception ex)
  1883. {
  1884. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1885. }
  1886. finally
  1887. {
  1888. isCollectingFlagRight = false;
  1889. }
  1890. }
  1891. /// <summary>
  1892. /// 上传文件
  1893. /// </summary>
  1894. /// <param name="BarcodeSet_t">条码集合</param>
  1895. /// <param name="stationCode">工站编号</param>
  1896. /// <param name="stationName">工站名称</param>
  1897. /// <param name="path">文件路径</param>
  1898. public async Task<(int, string)> SaveDBbyFileInfo(BarcodeSet_t BarcodeSet, string stationCode, string stationName,string path)
  1899. {
  1900. string sql, filename = "";
  1901. Guid guid;
  1902. int result = 0;
  1903. var formData = new MultipartFormDataContent();
  1904. // 获取所有图片文件
  1905. List<string> imageFiles = GetAllImageFiles(path);
  1906. try
  1907. {
  1908. if (imageFiles.Count>0)
  1909. {
  1910. foreach (string imageFile in imageFiles)
  1911. {
  1912. guid = Guid.NewGuid();
  1913. filename = Path.GetFileName(imageFile);
  1914. sql = string.Format("INSERT INTO [dbo].[DataFiles](stationCode,stationName,CarrierBarcode,ProductBarcode,bucket,fileName,fileContext,uuid,fileUrl,status,submitTime,createTime) " +
  1915. "VALUES('{0}','{1}','{2}' ,'{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')"
  1916. , stationCode
  1917. , stationName
  1918. , BarcodeSet.strCarrierBarcode
  1919. , BarcodeSet.strProductBarcode
  1920. , "/mesCommToPC/pic/left"
  1921. , filename
  1922. , ""
  1923. , guid.ToString()
  1924. , ""
  1925. , 0
  1926. , ""
  1927. , DateTime.Now
  1928. );
  1929. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1930. FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
  1931. string bucket = string.Empty;
  1932. //bucket = "IMAGE/IMAGE/N3/debug/online/PASS/M0002PA-0001/P320N000006B/382f55e9-c2bb";
  1933. bucket = "/mesCommToPC/pic/left";
  1934. fileUpload_X5.bucket = bucket;
  1935. fileUpload_X5.name = imageFile;
  1936. fileUpload_X5.md5 = "";
  1937. fileUpload_X5.uploadCloud = true;
  1938. fileUpload_X5.informMqtt = true;
  1939. FileMqttPayload fileMqttPayload = new FileMqttPayload();
  1940. //fileMqttPayload.factory = "";
  1941. //fileMqttPayload.project_name = "";
  1942. //fileMqttPayload.product_mode = "";
  1943. //fileMqttPayload.line_no = "";
  1944. //fileMqttPayload.work_station_no = "";
  1945. //fileMqttPayload.equipment_no = "";
  1946. //fileMqttPayload.station_no = "";
  1947. //fileMqttPayload.file_id = "";
  1948. //fileMqttPayload.file_name = "";
  1949. //fileMqttPayload.sn = "";
  1950. //fileMqttPayload.opt_time = "";
  1951. //fileMqttPayload.file_type = "";
  1952. //fileMqttPayload.file_category = "";
  1953. //fileMqttPayload.tag = "";
  1954. //fileMqttPayload.pass_station_id = "";
  1955. //FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
  1956. //FileMqttPayload fileMqttPayload = new FileMqttPayload();
  1957. //fileUpload_X5.bucket = "IMAGE/IMAGE/N3/debug/online/PASS/M0002PA-0001/P320N000006B/382f55e9-c2bb";
  1958. //fileUpload_X5.name = "test";
  1959. //fileUpload_X5.md5 = "";
  1960. //fileUpload_X5.uploadCloud = true;
  1961. //fileUpload_X5.informMqtt = true;
  1962. var fileresult = XiaomiMESHttp_UpLoadFile.FileUoladToMes(imageFile, fileUpload_X5, fileMqttPayload);
  1963. if (fileresult.Result.Item1 == 0)
  1964. {
  1965. return (1, fileresult.Result.Item2);
  1966. }
  1967. sql = string.Format("UPDATE [dbo].[DataFiles] SET status='{0}' WHERE uuid='{1}'", 1, guid);
  1968. string retnew = SQLHelper_New.ExecuteNonQuery(sql, null);
  1969. return fileresult.Result;
  1970. }
  1971. return (1, "程序错误!");
  1972. }
  1973. else
  1974. {
  1975. return (1,"文件不存在!");
  1976. }
  1977. }
  1978. catch (Exception e)
  1979. {
  1980. return (1, filename + $"图片保存失败!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode},错误原因:" + e.Message);
  1981. //AddMessage_Station(stationName, LogType.Error, filename + $"图片保存失败!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode}");
  1982. }
  1983. }
  1984. /// <summary>
  1985. /// 获取路径下的所有图片
  1986. /// </summary>
  1987. /// <param name="directoryPath"></param>
  1988. /// <returns></returns>
  1989. public List<string> GetAllImageFiles(string directoryPath)
  1990. {
  1991. var imageExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { ".jpg", ".jpeg", ".png", ".bmp", ".gif", ".tiff" };
  1992. var imageFiles = new List<string>();
  1993. try
  1994. {
  1995. // 遍历目录及子目录中的所有文件
  1996. foreach (string file in Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories))
  1997. {
  1998. // 获取文件扩展名并检查是否为图片格式
  1999. string extension = Path.GetExtension(file);
  2000. if (imageExtensions.Contains(extension))
  2001. {
  2002. imageFiles.Add(file);
  2003. }
  2004. }
  2005. }
  2006. catch (Exception ex)
  2007. {
  2008. OnMessage(LogType.Error, $"图片查询发生错误: {ex.Message}");
  2009. }
  2010. return imageFiles;
  2011. }
  2012. /// <summary>
  2013. /// 实例化报警字典
  2014. /// </summary>
  2015. private (bool, string) InitalDicAlarm()
  2016. {
  2017. #region 加载报警表
  2018. string excelPath = "";
  2019. switch (GlobalContext.IsUsePLCNow)
  2020. {
  2021. case 1:
  2022. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_10_壳体清洁上料.xlsx";
  2023. break;
  2024. case 2:
  2025. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_20_上盖板上料装备.xlsx";
  2026. break;
  2027. case 3:
  2028. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_30_点散热胶装备.xlsx";
  2029. break;
  2030. case 4:
  2031. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_40_胶线检测.xlsx";
  2032. break;
  2033. case 5:
  2034. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_50_ADD板上料组装装备.xlsx";
  2035. break;
  2036. case 6:
  2037. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_60_组上盖板.xlsx";
  2038. break;
  2039. case 7:
  2040. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_70_上盖板锁螺丝.xlsx";
  2041. break;
  2042. case 8:
  2043. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_80_NG下料.xlsx";
  2044. break;
  2045. case 9:
  2046. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_90_半成品下料.xlsx";
  2047. break;
  2048. default:
  2049. return (false, $"不支持当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请在设置页切换到正确的plc后重启该软件!");
  2050. }
  2051. if (!File.Exists(excelPath))
  2052. return (false, $"未找到当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请检查文件路径:'{excelPath}'。");
  2053. DataTable DtModel = NPOIHelper.ReadExcel(excelPath);
  2054. if (DtModel == null || DtModel.Rows.Count < 1)
  2055. return (false, $"报警点位表未包含任何报警数据!请检查‘{excelPath}’文件!");
  2056. // 检查列名
  2057. List<string> isNeedParms = new List<string>() {"设备分类名称","设备分类编码","分类层级1","分类层级2","分类层级3" ,"分类层级4","事件名称"
  2058. ,"事件ID","描述","标签","PLC地址","工位"}; // 必须要有的列
  2059. // 指定列名 + 检查列是否完整
  2060. DataRow dtRowName = DtModel.Rows[0];
  2061. int count = DtModel.Columns.Count;
  2062. for (int i = 0; i < count; i++)
  2063. {
  2064. string columeName = dtRowName[i]?.ToString();
  2065. if (!string.IsNullOrEmpty(columeName))
  2066. DtModel.Columns[i].ColumnName = columeName;
  2067. if ((!string.IsNullOrEmpty(columeName)) && isNeedParms.Count > 0 && isNeedParms.Contains(columeName))
  2068. isNeedParms.Remove(columeName);
  2069. }
  2070. DtModel.Rows.RemoveAt(0);
  2071. if (isNeedParms.Count > 0)
  2072. {
  2073. string msg1 = string.Join(",", isNeedParms);
  2074. return (false, $"报警点位表未包含列:{msg1}!请检查‘{excelPath}’文件!");
  2075. }
  2076. #endregion 加载报警表
  2077. List<Alarm> keyValues1 = new List<Alarm>();
  2078. for (int i = 0; i < DtModel.Rows.Count; i++)
  2079. {
  2080. Alarm alarm = new Alarm();
  2081. alarm.plcName = DtModel.Rows[i]["设备分类名称"]?.ToString(); // 设备名;
  2082. string type1Str = DtModel.Rows[i]["分类层级1"]?.ToString(); // 分类层级1;
  2083. alarm.type1CH = type1Str; // 分类层级1 中文
  2084. alarm.type1 = type1Str; // 分类层级1
  2085. if (!string.IsNullOrEmpty(type1Str) && type1Str.Contains("\n"))
  2086. {
  2087. string[] type1Strs = type1Str.Split('\n');
  2088. if (type1Strs.Length >= 2)
  2089. {
  2090. alarm.type1CH = type1Strs[0].Trim(); // 分类层级1 中文
  2091. alarm.type1 = type1Strs[1].Trim(); // 分类层级1
  2092. if (string.IsNullOrEmpty(alarm.type1))
  2093. alarm.type1 = alarm.type1CH;
  2094. }
  2095. }
  2096. string type2Str = DtModel.Rows[i]["分类层级2"]?.ToString(); // 分类层级2;电气控制 electric_control
  2097. alarm.type2CH = type2Str; // 分类层级2 中文
  2098. alarm.type2 = type2Str; // 分类层级2
  2099. if (!string.IsNullOrEmpty(type2Str) && type2Str.Contains("\n"))
  2100. {
  2101. string[] type2Strs = type2Str.Split('\n');
  2102. if (type2Strs.Length >= 2)
  2103. {
  2104. alarm.type2CH = type2Strs[0].Trim(); // 分类层级2 中文
  2105. alarm.type2 = type2Strs[1].Trim(); // 分类层级2
  2106. if (string.IsNullOrEmpty(alarm.type2))
  2107. alarm.type2 = alarm.type2CH;
  2108. }
  2109. }
  2110. string type3Str = DtModel.Rows[i]["分类层级3"]?.ToString(); // 分类层级3;故障 Fault
  2111. alarm.type3CH = type3Str; // 分类层级3 中文
  2112. alarm.type3 = type3Str; // 分类层级3
  2113. if (!string.IsNullOrEmpty(type3Str) && type3Str.Contains("\n"))
  2114. {
  2115. string[] type3Strs = type3Str.Split('\n');
  2116. if (type3Strs.Length >= 2)
  2117. {
  2118. alarm.type3CH = type3Strs[0].Trim(); // 分类层级3 中文
  2119. alarm.type3 = type3Strs[1].Trim(); // 分类层级3
  2120. if (string.IsNullOrEmpty(alarm.type3))
  2121. alarm.type3 = alarm.type3CH;
  2122. }
  2123. }
  2124. string faultStr = DtModel.Rows[i]["分类层级4"]?.ToString(); // 故障部件;overall_module
  2125. alarm.type4 = faultStr; // 分类层级4 中文
  2126. alarm.type4CH = faultStr; // 分类层级4
  2127. if (!string.IsNullOrEmpty(faultStr) && faultStr.Contains("\n"))
  2128. {
  2129. string[] faultStrs = faultStr.Split('\n');
  2130. if (faultStrs.Length >= 2)
  2131. {
  2132. alarm.type4CH = faultStrs[0].Trim(); // 故障部件;overall_module
  2133. alarm.type4 = faultStrs[1].Trim(); // 故障部件
  2134. if (string.IsNullOrEmpty(alarm.type4))
  2135. alarm.type4 = alarm.type4CH;
  2136. }
  2137. }
  2138. alarm.fault_code = DtModel.Rows[i]["事件ID"]?.ToString(); // 故障编码;A40001
  2139. alarm.fault_name = DtModel.Rows[i]["事件名称"]?.ToString(); // 故障名称;AL[1000]_系统_HMI急停故障
  2140. alarm.fault_desc = alarm.fault_name; // 故障描述;AL[1000]_系统_HMI急停故障
  2141. string plcAdress = DtModel.Rows[i]["PLC地址"]?.ToString();
  2142. alarm.PLC地址 = plcAdress;
  2143. plcAdress = plcAdress.Replace("fault_codes[", "");
  2144. plcAdress = plcAdress.Replace("]", "");
  2145. alarm.group_index = Convert.ToInt32(plcAdress.Split(".")[0]);
  2146. keyValues1.Add(alarm);
  2147. }
  2148. DicAlarms_Cur.Add(GlobalContext.IsUseStationName, keyValues1); // 这里使用线体代替工位
  2149. return (true, "报警字典表初始化成功!");
  2150. }
  2151. private async void ReadPLCAlarmToIot(uint[] FaultData,string stationNameStr)
  2152. {
  2153. DateTime dtNow = DateTime.Now;
  2154. try
  2155. {
  2156. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  2157. List<(int, int)> AlarmIndexList = new List<(int, int)>();//收集所有报警信息的位置
  2158. AlarmData alarmData = new AlarmData();
  2159. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  2160. bool isNoAlarm = false;//是否有报警
  2161. string binaryString = "";
  2162. bool isNoNewAlarm = false;//是否有新的报警
  2163. if (FaultData.Length > 0)
  2164. {
  2165. }
  2166. foreach (var item in FaultData)
  2167. {
  2168. isNoAlarm = item > 0 ? true : false;
  2169. }
  2170. if (!FaultData.SequenceEqual(_FaultDatas_Old))
  2171. {
  2172. isNoNewAlarm = true;
  2173. isNeedUpdUI = true;
  2174. }
  2175. if (FaultData.Length > 0 && isNoAlarm && isNoNewAlarm)
  2176. {
  2177. //解析报警信息,分析当前报警在字典中的定位
  2178. for (int i = 0; i <= FaultData.Length - 1; i++)
  2179. {
  2180. var num = 0;
  2181. if (FaultData[i] > 0)
  2182. {
  2183. //转换二进制
  2184. binaryString = Convert.ToString(FaultData[i], 2);
  2185. for (int j = binaryString.Length - 1; j >= 0; j--)
  2186. {
  2187. num++;
  2188. char s = binaryString[j];
  2189. if (binaryString[j] == '1')
  2190. {
  2191. //记录1的位置
  2192. AlarmIndexList.Add((i, num - 1));
  2193. }
  2194. }
  2195. }
  2196. }
  2197. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  2198. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.IsUseStationName];
  2199. foreach ((int index, int row) in AlarmIndexList)
  2200. {
  2201. var tempDic = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList();
  2202. for (int i = 0; i < tempDic.Count - 1; i++) // 读取
  2203. {
  2204. //若报警字典第[group_index]个数据,第[i]行与AlarmIndexList中的定位匹配,则添加进对应行的报警数据
  2205. if (tempDic[i].group_index == index && i == row)
  2206. {
  2207. dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据 = new AlarmData()
  2208. {
  2209. GUID = Guid.NewGuid().ToString(),
  2210. LineName = GlobalContext.IsUseStationName, // 工站
  2211. PlcStation = tempDic[i].plcName, // 工站全称;[S1]
  2212. Type1 = tempDic[i].type1, // 故障层级1
  2213. Type2 = tempDic[i].type2, // 故障层级2
  2214. Type3 = tempDic[i].type3, // 故障层级3
  2215. Type4 = tempDic[i].type4, // 故障层级4
  2216. AlarmType = tempDic[i].fault_code, // 报警类型
  2217. AlarmDesc = tempDic[i].fault_name, // 报警内容
  2218. StartTime = dtNow // 开始时间
  2219. };
  2220. // 传输到页面
  2221. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  2222. {
  2223. 线体名称 = tempDic[i].plcName,
  2224. 报警类型 = tempDic[i].fault_code,
  2225. 报警内容 = tempDic[i].fault_name,
  2226. 开始时间 = dtNow
  2227. });
  2228. // 新增到数据库
  2229. //var data1 = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据;
  2230. //SaveAlarmDataByDB(stationNameStr, data1, false);
  2231. //OnMessage(LogType.Info, $"更新{BodyAlarm}完毕!");
  2232. }
  2233. }
  2234. }
  2235. //筛选含报警数据的字典
  2236. var dicAlarms_Cur = dicAlarms_Cur_PLC1.Where(x => x.报警数据 != null).ToList();
  2237. if (dicAlarms_Cur.Count > 0)
  2238. {
  2239. foreach (var item in dicAlarms_Cur)
  2240. {
  2241. //上传
  2242. SaveAlarmDataByDB(GlobalContext.IsUseStationName, item.报警数据, false);
  2243. }
  2244. }
  2245. // 有新报警则更新
  2246. if (isNeedUpdUI)
  2247. // UI展示 - 展示到设备状态页
  2248. await Task.Run(() =>
  2249. {
  2250. try
  2251. {
  2252. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  2253. {
  2254. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  2255. if (Form_Main.formDevAlarm.Visible)
  2256. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  2257. }
  2258. }
  2259. catch { }
  2260. });
  2261. _FaultDatas_Old = FaultData.ToArray();
  2262. }
  2263. //FaultLogRequest request = new FaultLogRequest();
  2264. //request.station = mesStation; // 工位
  2265. //request.fault_name = xmFaultName; // 故障名称(同数据字典中的事件名称)
  2266. //request.fault_code = xmFaultCode2; // 故障编码(A,B,C,D,E)
  2267. //request.fault_cmpnt = xmFaultCmpnt; // 故障部件
  2268. //request.fault_desc = xmFaultDesc; // 故障描述
  2269. //request.fault_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 故障发生时间 2022-06-01 14:27:57.283
  2270. // // 上传
  2271. //(int, string) iotResult = XiaomiMqttClient_Extend.Write_FaultLog(request, type1, type2, type3, request.fault_cmpnt, deciveCode);
  2272. }
  2273. catch (Exception ex)
  2274. {
  2275. string str = ex.StackTrace;
  2276. AddMessage_Station(stationNameStr, LogType.Error, $"{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2277. }
  2278. }
  2279. #endregion
  2280. #region S1
  2281. /// <summary>
  2282. /// [S1] 壳体清洁上料装备
  2283. /// </summary>
  2284. /// <param name="plcNo">PLC编号</param>
  2285. private void ReadStation_S1(int plcNo)
  2286. {
  2287. string stationCode = "[OP10]";
  2288. string stationName = "壳体清洁上料";
  2289. string stationNameStr = stationCode + stationName;
  2290. string tagBaseName = "g_OP10_MES"; //标签变量名称
  2291. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2292. string tagAgvCommName = "agvCommFrmPC";
  2293. string tagBarsetName = "BarcodeSet";
  2294. // 触发信号字典
  2295. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2296. s1PLCSignal_Old.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2297. // PLC数据字典 赋值
  2298. s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2299. s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  2300. s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  2301. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  2302. (int, string) result;
  2303. while (true)
  2304. {
  2305. try
  2306. {
  2307. if (!GlobalContext._IsCon_Funs1)
  2308. {
  2309. UpdatePLCMonitor(1, plcNo, 0);
  2310. continue;
  2311. }
  2312. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2313. {
  2314. Stopwatch stopwatch1 = new Stopwatch();
  2315. Stopwatch stopwatch2 = new Stopwatch();
  2316. stopwatch1.Start();
  2317. stopwatch2.Start();
  2318. #region 一次性读取所有数据
  2319. // 一次性读取所有数据
  2320. result = FunsEip[plcNo]
  2321. .Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2322. if (result.Item1 != 0)
  2323. {
  2324. //richTextBox1.AppendText("\n" + strRet);
  2325. }
  2326. else
  2327. {
  2328. //richTextBox1.AppendText("\n" + "读取成功");
  2329. //设备状态
  2330. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  2331. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  2332. ? XiaomiDeviceState.Unknown
  2333. : (XiaomiDeviceState)xmDeviceStateInt;
  2334. // 物料码(物料码还未绑定载具SN时必填)
  2335. s1PLCData["a1OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode;
  2336. // 载具SN
  2337. s1PLCData["a1OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode;
  2338. // 节拍
  2339. s1PLCData["a1OEEType"] = stPLC_MesData.iotData.BeatAction;
  2340. //报警信息
  2341. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  2342. }
  2343. #endregion 一次性读取所有数据
  2344. stopwatch2.Stop();
  2345. #region 进站
  2346. try
  2347. {
  2348. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2349. {
  2350. lock (lockObj)
  2351. {
  2352. if (!ProgressState)
  2353. {
  2354. ProgressState = true;
  2355. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData,
  2356. tagBaseName + "." + tagMesCommName, out ProgressState));
  2357. }
  2358. }
  2359. }
  2360. }
  2361. catch (Exception ex)
  2362. {
  2363. ProgressState = false;
  2364. string str = ex.StackTrace;
  2365. AddMessage_Station(stationNameStr, LogType.Error,
  2366. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2367. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2368. }
  2369. #endregion 进站
  2370. #region 出站
  2371. try
  2372. {
  2373. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2374. {
  2375. lock (lockObj)
  2376. {
  2377. if (!ProgressState)
  2378. {
  2379. ProgressState = true;
  2380. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData,
  2381. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  2382. out ProgressState));
  2383. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  2384. }
  2385. }
  2386. }
  2387. }
  2388. catch (Exception ex)
  2389. {
  2390. ProgressState = false;
  2391. string str = ex.StackTrace;
  2392. AddMessage_Station(stationNameStr, LogType.Error,
  2393. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2394. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2395. }
  2396. #endregion 出站
  2397. #region 节拍接口
  2398. try
  2399. {
  2400. int a10EEType = (int)s1PLCData["a10EEType"];
  2401. int a10EETypeGOld = (int)s1PLCSignal_Old["a10EEType"];
  2402. //若设备紧急复原后节拍重置
  2403. if (a10EEType == 1)
  2404. {
  2405. a10EETypeGOld = 0;
  2406. }
  2407. if (a10EEType != a10EETypeGOld)
  2408. {
  2409. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  2410. if ((a10EETypeGOld == 1 && a10EEType != 2) || (a10EETypeGOld == 3 && a10EEType != 4) ||
  2411. (a10EETypeGOld == 5 && a10EEType != 6))
  2412. {
  2413. //写入PLC
  2414. stPLC_MesData.iotData.beatReturn = 2; //NG
  2415. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  2416. AddMessage(LogType.Info,
  2417. stationNameStr +
  2418. $"_节拍接口-- 设备本次上传节拍[{a10EEType}],未上传节拍[{a10EETypeGOld}]的结束信号,请检查;总用时" +
  2419. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  2420. "ms");
  2421. return;
  2422. }
  2423. else
  2424. {
  2425. Task.Run(() =>
  2426. S1节拍接口(plcNo, stationNameStr, tagBaseName,
  2427. stPLC_MesData.iotData)); // MreTasks[4].Set();
  2428. }
  2429. s1PLCSignal_Old["a10EEType"] = s1PLCData["a10EEType"];
  2430. }
  2431. }
  2432. catch (Exception ex)
  2433. {
  2434. string str = ex.StackTrace;
  2435. AddMessage_Station(stationNameStr, LogType.Error,
  2436. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  2437. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2438. }
  2439. #endregion
  2440. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2441. stopwatch1.Stop();
  2442. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2443. }
  2444. else
  2445. {
  2446. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2447. AddMessage_Station(stationNameStr, LogType.Info,
  2448. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2449. FunsEip[plcNo].Connect(); // 重连
  2450. }
  2451. }
  2452. catch (Exception ex)
  2453. {
  2454. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2455. AddMessage_Station(stationNameStr, LogType.Error,
  2456. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2457. }
  2458. Thread.Sleep(IntervalReadPLC);
  2459. }
  2460. }
  2461. /// <summary>
  2462. /// [S1] 壳体清洁上料 - 进站
  2463. /// </summary>
  2464. /// <param name="plcNo">PLC编号</param>
  2465. /// <param name="stationNameStr">工站全称</param>
  2466. /// <param name="stPLC_MesData"></param>
  2467. /// <param name="tagMesCommName"></param>
  2468. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  2469. out bool ProgressState)
  2470. {
  2471. Stopwatch stopwatch1 = new Stopwatch();
  2472. Stopwatch stopwatch2 = new Stopwatch();
  2473. try
  2474. {
  2475. stopwatch1.Start();
  2476. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2477. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  2478. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2479. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  2480. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  2481. if (string.IsNullOrEmpty(sn))
  2482. {
  2483. ProgressState = false;
  2484. return;
  2485. }
  2486. //正式生产就用PLC中取的
  2487. //sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;
  2488. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  2489. sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2490. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2491. //绑定载具和产品
  2492. ResponseMessage message = new ResponseMessage();
  2493. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  2494. if (message.result == false)
  2495. {
  2496. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  2497. }
  2498. // 产品SN进站
  2499. List<TestItem> item = new List<TestItem>();
  2500. stopwatch2.Start();
  2501. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  2502. item, MachineId, StationId);
  2503. stopwatch2.Stop();
  2504. //指令执行结果 1:OK 110:失败
  2505. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2506. //进站结果写入PLC
  2507. CommandFromPLC resultToPlC = new CommandFromPLC();
  2508. resultToPlC.cmd = 0;
  2509. resultToPlC.cmdParam = 0;
  2510. resultToPlC.cmdResult = mesResultFrmWeb;
  2511. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2512. }
  2513. catch (Exception ex)
  2514. {
  2515. string str = ex.StackTrace;
  2516. AddMessage(LogType.Error,
  2517. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  2518. str.Length - str.LastIndexOf("\\") - 1));
  2519. CommandFromPLC resultToPlC = new CommandFromPLC();
  2520. resultToPlC.cmd = 0;
  2521. resultToPlC.cmdParam = 0; //指令参数
  2522. resultToPlC.cmdResult = 110;
  2523. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2524. }
  2525. stopwatch1.Stop();
  2526. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2527. AddMessage(LogType.Info,
  2528. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  2529. stopwatch2.ElapsedMilliseconds + "ms");
  2530. ProgressState = false;
  2531. }
  2532. /// <summary>
  2533. /// [S1] 壳体清洁上料 - 出站接口
  2534. /// </summary>
  2535. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  2536. string stationCode, string stationName, out bool ProgressState)
  2537. {
  2538. Stopwatch stopwatch1 = new Stopwatch();
  2539. Stopwatch stopwatch2 = new Stopwatch();
  2540. try
  2541. {
  2542. stopwatch1.Start();
  2543. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2544. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2545. string processItem = stationName; // 项目
  2546. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2547. string supplierCode = ""; // 供应商代码
  2548. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  2549. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  2550. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  2551. string sn = string.Empty;
  2552. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2553. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  2554. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  2555. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2556. //a1Result = 1;
  2557. bool pass = a1Result == 1;
  2558. //根据载具码获取产品码
  2559. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2560. if (string.IsNullOrEmpty(strProductBarcode))
  2561. {
  2562. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2563. }
  2564. sn = strProductBarcode;
  2565. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2566. List<TestItem> items = new List<TestItem>();
  2567. items.Add(new TestItem()
  2568. {
  2569. Parameter_name = "载具码",
  2570. Parameter_value = CarrierBarcode,
  2571. Parameter_unit = ""
  2572. });
  2573. items.Add(new TestItem()
  2574. {
  2575. Parameter_name = "产品码",
  2576. Parameter_value = sn,
  2577. Parameter_unit = ""
  2578. });
  2579. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  2580. //出站接口
  2581. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2582. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  2583. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2584. stopwatch2.Start();
  2585. //进站结果写入PLC
  2586. CommandFromPLC resultToPlC = new CommandFromPLC();
  2587. resultToPlC.cmd = 0;
  2588. resultToPlC.cmdParam = 0; //指令参数
  2589. resultToPlC.cmdResult = mesResultFrmWeb;
  2590. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2591. stopwatch2.Stop();
  2592. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2593. //保存PLC返回MES数据到本地
  2594. ResponseMessage message = new ResponseMessage();
  2595. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  2596. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress,
  2597. stPLC_MesData.mesData.fCleanSpeed,
  2598. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime,
  2599. stPLC_MesData.mesData.nCleanCount,
  2600. stPLC_MesData.mesData.nRemainCount);
  2601. if (message.result == false)
  2602. {
  2603. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2604. }
  2605. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  2606. }
  2607. catch (Exception ex)
  2608. {
  2609. stopwatch2.Start();
  2610. CommandFromPLC resultToPlC = new CommandFromPLC();
  2611. resultToPlC.cmd = 0;
  2612. resultToPlC.cmdParam = 0; //指令参数
  2613. resultToPlC.cmdResult = 110;
  2614. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2615. stopwatch2.Stop();
  2616. string str = ex.StackTrace;
  2617. AddMessage(LogType.Error,
  2618. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  2619. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2620. }
  2621. stopwatch1.Stop();
  2622. AddMessage(LogType.Info,
  2623. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  2624. stopwatch2.ElapsedMilliseconds + "ms");
  2625. ProgressState = false;
  2626. }
  2627. #endregion
  2628. #region S2
  2629. /// <summary>
  2630. /// [S2] 上盖板上料装备
  2631. /// </summary>
  2632. /// <param name="plcNo">PLC编号</param>
  2633. private void ReadStation_S2(int plcNo)
  2634. {
  2635. string stationCode = "[OP20]";
  2636. string stationName = "上盖板上料装备";
  2637. string stationNameStr = stationCode + stationName;
  2638. string tagBaseName = "g_OP20_MES"; //标签变量名称
  2639. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2640. string tagAgvCommName = "agvCommFrmPC";
  2641. string tagBarsetName = "BarcodeSet";
  2642. // 触发信号字典
  2643. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2644. s2PLCSignal_Old.Add("a2OEEType", 0); // 节拍类型(plc写入)
  2645. // PLC数据字典 赋值
  2646. s2PLCData.Add("a2OEEType", 0); // 节拍类型(plc写入)
  2647. s2PLCData.Add("a2OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  2648. s2PLCData.Add("a2OEEVehicleCode", ""); // 载具SN
  2649. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  2650. IoT_DataSet_t iot_data;
  2651. (int, string) result;
  2652. while (true)
  2653. {
  2654. try
  2655. {
  2656. if (!GlobalContext._IsCon_Funs2)
  2657. {
  2658. UpdatePLCMonitor(1, plcNo, 0);
  2659. continue;
  2660. }
  2661. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2662. {
  2663. Stopwatch stopwatch1 = new Stopwatch();
  2664. Stopwatch stopwatch2 = new Stopwatch();
  2665. stopwatch1.Start();
  2666. stopwatch2.Start();
  2667. #region 一次性读取所有数据
  2668. // 一次性读取所有数据
  2669. result = FunsEip[plcNo]
  2670. .Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2671. if (result.Item1 != 0)
  2672. {
  2673. //richTextBox1.AppendText("\n" + strRet);
  2674. }
  2675. else
  2676. {
  2677. //richTextBox1.AppendText("\n" + "读取成功");
  2678. //设备状态
  2679. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  2680. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  2681. ? XiaomiDeviceState.Unknown
  2682. : (XiaomiDeviceState)xmDeviceStateInt;
  2683. s2PLCData["a2OEEPartNo"] =
  2684. stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  2685. s2PLCData["a2OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  2686. s2PLCData["a2OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  2687. }
  2688. #endregion 一次性读取所有数据
  2689. stopwatch2.Stop();
  2690. #region 进站
  2691. try
  2692. {
  2693. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2694. {
  2695. lock (lockObj)
  2696. {
  2697. if (!ProgressState)
  2698. {
  2699. ProgressState = true;
  2700. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData,
  2701. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  2702. out ProgressState));
  2703. }
  2704. }
  2705. }
  2706. }
  2707. catch (Exception ex)
  2708. {
  2709. ProgressState = false;
  2710. string str = ex.StackTrace;
  2711. AddMessage_Station(stationNameStr, LogType.Error,
  2712. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2713. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2714. }
  2715. #endregion 进站
  2716. #region 出站
  2717. try
  2718. {
  2719. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2720. {
  2721. lock (lockObj)
  2722. {
  2723. if (!ProgressState)
  2724. {
  2725. ProgressState = true;
  2726. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData,
  2727. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  2728. out ProgressState));
  2729. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  2730. }
  2731. }
  2732. }
  2733. }
  2734. catch (Exception ex)
  2735. {
  2736. ProgressState = false;
  2737. string str = ex.StackTrace;
  2738. AddMessage_Station(stationNameStr, LogType.Error,
  2739. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2740. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2741. }
  2742. #endregion 出站
  2743. #region 节拍接口
  2744. try
  2745. {
  2746. int a20EEType = (int)s2PLCData["a20EEType"];
  2747. int a20EETypeGOld = (int)s2PLCSignal_Old["a20EEType"];
  2748. //若设备紧急复原后节拍重置
  2749. if (a20EEType == 1)
  2750. {
  2751. a20EETypeGOld = 0;
  2752. }
  2753. if (a20EEType != a20EETypeGOld)
  2754. {
  2755. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  2756. if ((a20EETypeGOld == 1 && a20EEType != 2) || (a20EETypeGOld == 3 && a20EEType != 4) ||
  2757. (a20EETypeGOld == 5 && a20EEType != 6))
  2758. {
  2759. //写入PLC
  2760. stPLC_MesData.iotData.beatReturn = 2; //NG
  2761. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  2762. AddMessage(LogType.Info,
  2763. stationNameStr +
  2764. $"_节拍接口-- 设备本次上传节拍[{a20EEType}],未上传节拍[{a20EETypeGOld}]的结束信号,请检查;总用时" +
  2765. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  2766. "ms");
  2767. return;
  2768. }
  2769. else
  2770. {
  2771. Task.Run(() =>
  2772. S2节拍接口(plcNo, stationNameStr, tagBaseName,
  2773. stPLC_MesData.iotData)); // MreTasks[4].Set();
  2774. }
  2775. s2PLCSignal_Old["a20EEType"] = s2PLCData["a20EEType"];
  2776. }
  2777. }
  2778. catch (Exception ex)
  2779. {
  2780. string str = ex.StackTrace;
  2781. AddMessage_Station(stationNameStr, LogType.Error,
  2782. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  2783. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2784. }
  2785. #endregion
  2786. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2787. stopwatch1.Stop();
  2788. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2789. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2790. }
  2791. else
  2792. {
  2793. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2794. AddMessage_Station(stationNameStr, LogType.Info,
  2795. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2796. FunsEip[plcNo].Connect();
  2797. }
  2798. }
  2799. catch (Exception ex)
  2800. {
  2801. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2802. AddMessage_Station(stationNameStr, LogType.Error,
  2803. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2804. //Funs[plcNo].ReConnect();
  2805. }
  2806. Thread.Sleep(IntervalReadPLC);
  2807. }
  2808. }
  2809. /// <summary>
  2810. /// [S2] 上盖板上料装备
  2811. /// </summary>
  2812. /// <param name="plcNo">PLC编号</param>
  2813. /// <param name="stationNameStr">工站全称</param>
  2814. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  2815. string tagBarsetName, out bool ProgressState)
  2816. {
  2817. Stopwatch stopwatch1 = new Stopwatch();
  2818. Stopwatch stopwatch2 = new Stopwatch();
  2819. try
  2820. {
  2821. stopwatch1.Start();
  2822. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2823. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  2824. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2825. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  2826. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  2827. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2828. //根据载具码获取产品码
  2829. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2830. if (string.IsNullOrEmpty(strProductBarcode))
  2831. {
  2832. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2833. }
  2834. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  2835. //if (sn != strProductBarcode)
  2836. //{
  2837. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  2838. //}
  2839. sn = strProductBarcode;
  2840. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2841. // 产品SN(物料码)校验
  2842. List<TestItem> item = new List<TestItem>();
  2843. stopwatch2.Start();
  2844. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  2845. item, MachineId, StationId);
  2846. stopwatch2.Stop();
  2847. //指令执行结果 1:OK 110:失败
  2848. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2849. //进站结果写入PLC
  2850. CommandFromPLC resultToPlC = new CommandFromPLC();
  2851. resultToPlC.cmd = 0;
  2852. resultToPlC.cmdParam = 0; //指令参数
  2853. resultToPlC.cmdResult = mesResultFrmWeb;
  2854. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2855. }
  2856. catch (Exception ex)
  2857. {
  2858. string str = ex.StackTrace;
  2859. AddMessage(LogType.Error,
  2860. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  2861. str.Length - str.LastIndexOf("\\") - 1));
  2862. CommandFromPLC resultToPlC = new CommandFromPLC();
  2863. resultToPlC.cmd = 0;
  2864. resultToPlC.cmdParam = 0; //指令参数
  2865. resultToPlC.cmdResult = 110;
  2866. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2867. }
  2868. stopwatch1.Stop();
  2869. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2870. AddMessage(LogType.Info,
  2871. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  2872. stopwatch2.ElapsedMilliseconds + "ms");
  2873. ProgressState = false;
  2874. }
  2875. /// <summary>
  2876. /// [S2] 上盖板上料装备 - 出站接口
  2877. /// </summary>
  2878. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  2879. string stationCode, string stationName, out bool ProgressState)
  2880. {
  2881. Stopwatch stopwatch1 = new Stopwatch();
  2882. Stopwatch stopwatch2 = new Stopwatch();
  2883. try
  2884. {
  2885. stopwatch1.Start();
  2886. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2887. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2888. string processItem = stationName; // 测试项目
  2889. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2890. string supplierCode = ""; // 供应商代码
  2891. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2892. string batch_num = GlobalContext.BatchNumber; // 批次号
  2893. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2894. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2895. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2896. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  2897. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  2898. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  2899. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2900. bool pass = a1Result == 1;
  2901. //根据载具码获取产品码
  2902. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2903. if (string.IsNullOrEmpty(strProductBarcode))
  2904. {
  2905. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2906. }
  2907. sn = strProductBarcode;
  2908. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2909. List<TestItem> items = new List<TestItem>();
  2910. items.Add(new TestItem()
  2911. {
  2912. Parameter_name = "载具码",
  2913. Parameter_value = CarrierBarcode,
  2914. Parameter_unit = ""
  2915. });
  2916. items.Add(new TestItem()
  2917. {
  2918. Parameter_name = "产品码",
  2919. Parameter_value = sn,
  2920. Parameter_unit = ""
  2921. });
  2922. items.Add(new TestItem()
  2923. {
  2924. Parameter_name = "部件码",
  2925. Parameter_value = PartBarcode,
  2926. Parameter_unit = ""
  2927. });
  2928. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  2929. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2930. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode, paramJson);
  2931. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2932. stopwatch2.Start();
  2933. //进站结果写入PLC
  2934. CommandFromPLC resultToPlC = new CommandFromPLC();
  2935. resultToPlC.cmd = 0;
  2936. resultToPlC.cmdParam = 0; //指令参数
  2937. resultToPlC.cmdResult = mesResultFrmWeb;
  2938. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2939. stopwatch2.Stop();
  2940. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2941. //保存PLC返回MES数据到本地
  2942. ResponseMessage message = new ResponseMessage();
  2943. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  2944. stPLC_MesData.mesData.nRemainCount);
  2945. if (message.result == false)
  2946. {
  2947. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2948. }
  2949. if (!string.IsNullOrEmpty(PartBarcode))
  2950. {
  2951. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  2952. if (message.result == false)
  2953. {
  2954. AddMessage(LogType.Error, message.text);
  2955. }
  2956. }
  2957. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2958. }
  2959. catch (Exception ex)
  2960. {
  2961. stopwatch2.Start();
  2962. CommandFromPLC resultToPlC = new CommandFromPLC();
  2963. resultToPlC.cmd = 0;
  2964. resultToPlC.cmdParam = 0; //指令参数
  2965. resultToPlC.cmdResult = 110;
  2966. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2967. stopwatch2.Stop();
  2968. string str = ex.StackTrace;
  2969. AddMessage(LogType.Error,
  2970. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  2971. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2972. }
  2973. stopwatch1.Stop();
  2974. AddMessage(LogType.Info,
  2975. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  2976. stopwatch2.ElapsedMilliseconds + "ms");
  2977. ProgressState = false;
  2978. }
  2979. #endregion
  2980. #region S3
  2981. /// <summary>
  2982. /// [S3] 点散热胶装备
  2983. /// </summary>
  2984. /// <param name="plcNo">PLC编号</param>
  2985. private void ReadStation_S3(int plcNo)
  2986. {
  2987. string stationCode = "[OP30]";
  2988. string stationName = "点散热胶装备";
  2989. string stationNameStr = stationCode + stationName;
  2990. string tagBaseName = "g_OP30_MES"; //标签变量名称
  2991. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2992. string tagAgvCommName = "agvCommFrmPC";
  2993. string tagBarsetName = "BarcodeSet";
  2994. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2995. s3PLCSignal_Old.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
  2996. s3PLCSignal_Old.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
  2997. // PLC数据字典 赋值
  2998. s3PLCData.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
  2999. s3PLCData.Add("a3OEEPartNo_left", ""); // 物料码(物料码还未绑定载具SN时必填)
  3000. s3PLCData.Add("a3OEEVehicleCode_left", ""); // 载具SN
  3001. s3PLCData.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
  3002. s3PLCData.Add("a3OEEPartNo_right", ""); // 物料码(物料码还未绑定载具SN时必填)
  3003. s3PLCData.Add("a3OEEVehicleCode_right", ""); // 载具SN
  3004. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  3005. (int, string) result;
  3006. while (true)
  3007. {
  3008. try
  3009. {
  3010. if (!GlobalContext._IsCon_Funs2)
  3011. {
  3012. UpdatePLCMonitor(1, plcNo, 0);
  3013. continue;
  3014. }
  3015. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3016. {
  3017. Stopwatch stopwatch1 = new Stopwatch();
  3018. Stopwatch stopwatch2 = new Stopwatch();
  3019. stopwatch1.Start();
  3020. stopwatch2.Start();
  3021. #region 一次性读取所有数据
  3022. // 一次性读取所有数据
  3023. result = FunsEip[plcNo]
  3024. .Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3025. if (result.Item1 != 0)
  3026. {
  3027. //richTextBox1.AppendText("\n" + strRet);
  3028. }
  3029. else
  3030. {
  3031. //richTextBox1.AppendText("\n" + "读取成功");
  3032. int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  3033. int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  3034. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  3035. ? XiaomiDeviceState.Unknown
  3036. : (XiaomiDeviceState)xmDeviceStateInt_L;
  3037. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  3038. ? XiaomiDeviceState.Unknown
  3039. : (XiaomiDeviceState)xmDeviceStateInt_R;
  3040. s1PLCData["a1OEEPartNo"] =stPLC_MesData.Left.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  3041. s1PLCData["a1OEEVehicleCode"] = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode; // 载具SN
  3042. s1PLCData["a1OEEType"] = stPLC_MesData.Left.iotData.BeatAction; // 节拍
  3043. s1PLCData["a1OEEVehicleCode_right"] = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode; // 载具SN
  3044. s1PLCData["a1OEEType_right"] = stPLC_MesData.Right.iotData.BeatAction; // 节拍
  3045. }
  3046. #endregion 一次性读取所有数据
  3047. stopwatch2.Stop();
  3048. #region 左边进站
  3049. try
  3050. {
  3051. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3052. {
  3053. lock (lockObj)
  3054. {
  3055. if (!ProgressState)
  3056. {
  3057. ProgressState = true;
  3058. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left,
  3059. tagBaseName + ".Left." + tagMesCommName,
  3060. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  3061. }
  3062. }
  3063. }
  3064. }
  3065. catch (Exception ex)
  3066. {
  3067. ProgressState = false;
  3068. string str = ex.StackTrace;
  3069. AddMessage_Station(stationNameStr, LogType.Error,
  3070. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3071. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3072. }
  3073. #endregion 左边进站
  3074. #region 左边出站
  3075. try
  3076. {
  3077. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3078. {
  3079. lock (lockObj)
  3080. {
  3081. if (!ProgressState)
  3082. {
  3083. ProgressState = true;
  3084. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left,
  3085. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  3086. out ProgressState));
  3087. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  3088. }
  3089. }
  3090. }
  3091. }
  3092. catch (Exception ex)
  3093. {
  3094. ProgressState = false;
  3095. string str = ex.StackTrace;
  3096. AddMessage_Station(stationNameStr, LogType.Error,
  3097. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3098. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3099. }
  3100. #endregion 左边出站
  3101. #region 右边进站
  3102. try
  3103. {
  3104. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3105. {
  3106. lock (lockObj)
  3107. {
  3108. if (!ProgressState)
  3109. {
  3110. ProgressState = true;
  3111. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right,
  3112. tagBaseName + ".Right." + tagMesCommName,
  3113. tagBaseName + ".Right." + tagBarsetName, "Right", out ProgressState));
  3114. }
  3115. }
  3116. }
  3117. }
  3118. catch (Exception ex)
  3119. {
  3120. ProgressState = false;
  3121. string str = ex.StackTrace;
  3122. AddMessage_Station(stationNameStr, LogType.Error,
  3123. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3124. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3125. }
  3126. #endregion 右边进站
  3127. #region 右边出站
  3128. try
  3129. {
  3130. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3131. {
  3132. lock (lockObj)
  3133. {
  3134. if (!ProgressState)
  3135. {
  3136. ProgressState = true;
  3137. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right,
  3138. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  3139. out ProgressState));
  3140. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  3141. }
  3142. }
  3143. }
  3144. }
  3145. catch (Exception ex)
  3146. {
  3147. string str = ex.StackTrace;
  3148. AddMessage_Station(stationNameStr, LogType.Error,
  3149. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3150. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3151. }
  3152. #endregion 右边出站
  3153. #region 节拍接口
  3154. try
  3155. {
  3156. #region 左工位 节拍
  3157. int a30EEType_left = (int)s3PLCData["a30EEType_left"];
  3158. int a30EETypeGOld_left = (int)s3PLCSignal_Old["a30EEType_left"];
  3159. //若设备紧急复原后节拍重置
  3160. if (a30EEType_left == 1)
  3161. {
  3162. a30EETypeGOld_left = 0;
  3163. }
  3164. if (a30EEType_left != a30EETypeGOld_left)
  3165. {
  3166. stationNameStr = stationNameStr + "_Left";
  3167. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  3168. if ((a30EETypeGOld_left == 1 && a30EEType_left != 2) || (a30EETypeGOld_left == 3 && a30EEType_left != 4) ||
  3169. (a30EETypeGOld_left == 5 && a30EEType_left != 6))
  3170. {
  3171. //写入PLC
  3172. stPLC_MesData.Left.iotData.beatReturn = 2; //NG
  3173. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName, 1, stPLC_MesData.Left.iotData);
  3174. AddMessage(LogType.Info,
  3175. stationNameStr +
  3176. $"_节拍接口-- 设备本次上传节拍[{a30EEType_left}],未上传节拍[{a30EETypeGOld_left}]的结束信号,请检查;总用时" +
  3177. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  3178. "ms");
  3179. return;
  3180. }
  3181. else
  3182. {
  3183. Task.Run(() =>
  3184. S3节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName,
  3185. stPLC_MesData.Left.iotData)); // MreTasks[4].Set();
  3186. }
  3187. s3PLCSignal_Old["a30EEType_left"] = s3PLCData["a30EEType_left"];
  3188. }
  3189. #endregion 左工位 节拍
  3190. #region 右工位 节拍
  3191. int a30EEType_right = (int)s3PLCData["a30EEType_right"];
  3192. int a30EETypeGOld_right = (int)s3PLCSignal_Old["a30EEType_right"];
  3193. //若设备紧急复原后节拍重置
  3194. if (a30EEType_right == 1)
  3195. {
  3196. a30EETypeGOld_right = 0;
  3197. }
  3198. if (a30EEType_right != a30EETypeGOld_right)
  3199. {
  3200. stationNameStr = stationNameStr + "_Right";
  3201. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  3202. if ((a30EETypeGOld_right == 1 && a30EEType_right != 2) || (a30EETypeGOld_right == 3 && a30EEType_right != 4) ||
  3203. (a30EETypeGOld_right == 5 && a30EEType_right != 6))
  3204. {
  3205. //写入PLC
  3206. stPLC_MesData.Right.iotData.beatReturn = 2; //NG
  3207. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName, 1, stPLC_MesData.Left.iotData);
  3208. AddMessage(LogType.Info,
  3209. stationNameStr +
  3210. $"_节拍接口-- 设备本次上传节拍[{a30EEType_right}],未上传节拍[{a30EETypeGOld_right}]的结束信号,请检查;总用时" +
  3211. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  3212. "ms");
  3213. return;
  3214. }
  3215. else
  3216. {
  3217. Task.Run(() =>
  3218. S3节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName,
  3219. stPLC_MesData.Left.iotData)); // MreTasks[4].Set();
  3220. }
  3221. s3PLCSignal_Old["a30EEType_right"] = s3PLCData["a30EEType_right"];
  3222. }
  3223. #endregion 右工位 节拍
  3224. }
  3225. catch (Exception ex)
  3226. {
  3227. string str = ex.StackTrace;
  3228. AddMessage_Station(stationNameStr, LogType.Error,
  3229. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3230. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3231. }
  3232. #endregion
  3233. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3234. stopwatch1.Stop();
  3235. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  3236. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3237. }
  3238. else
  3239. {
  3240. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3241. AddMessage_Station(stationNameStr, LogType.Info,
  3242. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3243. FunsEip[plcNo].Connect();
  3244. }
  3245. }
  3246. catch (Exception ex)
  3247. {
  3248. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3249. AddMessage_Station(stationNameStr, LogType.Error,
  3250. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3251. //Funs[plcNo].ReConnect();
  3252. }
  3253. Thread.Sleep(IntervalReadPLC);
  3254. }
  3255. }
  3256. /// <summary>
  3257. /// [S3] 点散热胶装备 - 进站
  3258. /// </summary>
  3259. /// <param name="plcNo">PLC编号</param>
  3260. /// <param name="stationNameStr">工站全称</param>
  3261. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  3262. string tagBarsetName, string direction, out bool ProgressState)
  3263. {
  3264. Stopwatch stopwatch1 = new Stopwatch();
  3265. Stopwatch stopwatch2 = new Stopwatch();
  3266. try
  3267. {
  3268. stopwatch1.Start();
  3269. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  3270. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3271. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  3272. string StationId = string.Empty;
  3273. if (direction == "Left")
  3274. {
  3275. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  3276. }
  3277. if (direction == "Right")
  3278. {
  3279. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  3280. }
  3281. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3282. //载具码验证产品码
  3283. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3284. if (string.IsNullOrEmpty(strProductBarcode))
  3285. {
  3286. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3287. }
  3288. sn = strProductBarcode;
  3289. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  3290. // 产品SN(物料码)校验
  3291. List<TestItem> item = new List<TestItem>();
  3292. stopwatch2.Start();
  3293. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3294. item, MachineId, StationId);
  3295. stopwatch2.Stop();
  3296. //指令执行结果 1:OK 110:失败
  3297. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3298. //进站结果写入PLC
  3299. CommandFromPLC resultToPlC = new CommandFromPLC();
  3300. resultToPlC.cmd = 0;
  3301. resultToPlC.cmdParam = 0; //指令参数
  3302. resultToPlC.cmdResult = mesResultFrmWeb;
  3303. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3304. }
  3305. catch (Exception ex)
  3306. {
  3307. string str = ex.StackTrace;
  3308. AddMessage(LogType.Error,
  3309. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3310. str.Length - str.LastIndexOf("\\") - 1));
  3311. CommandFromPLC resultToPlC = new CommandFromPLC();
  3312. resultToPlC.cmd = 0;
  3313. resultToPlC.cmdParam = 0; //指令参数
  3314. resultToPlC.cmdResult = 110;
  3315. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3316. }
  3317. stopwatch1.Stop();
  3318. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3319. AddMessage(LogType.Info,
  3320. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3321. stopwatch2.ElapsedMilliseconds + "ms");
  3322. ProgressState = false;
  3323. }
  3324. /// <summary>
  3325. /// [S3] 点散热胶装备 - 出站
  3326. /// </summary>
  3327. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  3328. string stationCode, string stationName, string direction, out bool ProgressState)
  3329. {
  3330. Stopwatch stopwatch1 = new Stopwatch();
  3331. Stopwatch stopwatch2 = new Stopwatch();
  3332. try
  3333. {
  3334. stopwatch1.Start();
  3335. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  3336. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3337. string processItem = stationName; // 测试项目
  3338. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3339. string supplierCode = ""; // 供应商代码
  3340. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3341. string batch_num = GlobalContext.BatchNumber; // 批次号
  3342. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3343. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3344. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3345. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  3346. string StationId = string.Empty;
  3347. if (direction == "Left")
  3348. {
  3349. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  3350. }
  3351. if (direction == "Right")
  3352. {
  3353. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  3354. }
  3355. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3356. bool pass = a1Result == 1;
  3357. //根据载具码获取产品码
  3358. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3359. if (string.IsNullOrEmpty(strProductBarcode))
  3360. {
  3361. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3362. }
  3363. sn = strProductBarcode;
  3364. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3365. List<TestItem> items = new List<TestItem>();
  3366. items.Add(new TestItem()
  3367. {
  3368. Parameter_name = "载具码",
  3369. Parameter_value = CarrierBarcode,
  3370. Parameter_unit = ""
  3371. });
  3372. items.Add(new TestItem()
  3373. {
  3374. Parameter_name = "产品码",
  3375. Parameter_value = sn,
  3376. Parameter_unit = ""
  3377. });
  3378. int result1 = 1;
  3379. //if (direction == "Right")
  3380. //{
  3381. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3382. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3383. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson, direction);
  3384. //}
  3385. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3386. stopwatch2.Start();
  3387. //进站结果写入PLC
  3388. CommandFromPLC resultToPlC = new CommandFromPLC();
  3389. resultToPlC.cmd = 0;
  3390. resultToPlC.cmdParam = 0; //指令参数
  3391. resultToPlC.cmdResult = mesResultFrmWeb;
  3392. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3393. stopwatch2.Stop();
  3394. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  3395. //保存PLC返回MES数据到本地
  3396. ResponseMessage message = new ResponseMessage();
  3397. if (direction == "Left")
  3398. {
  3399. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  3400. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  3401. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  3402. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  3403. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  3404. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  3405. if (message.result == false)
  3406. {
  3407. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3408. }
  3409. }
  3410. if (direction == "Right")
  3411. {
  3412. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  3413. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  3414. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  3415. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  3416. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  3417. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  3418. if (message.result == false)
  3419. {
  3420. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3421. }
  3422. }
  3423. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3424. }
  3425. catch (Exception ex)
  3426. {
  3427. stopwatch2.Start();
  3428. CommandFromPLC resultToPlC = new CommandFromPLC();
  3429. resultToPlC.cmd = 0;
  3430. resultToPlC.cmdParam = 0; //指令参数
  3431. resultToPlC.cmdResult = 110;
  3432. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3433. stopwatch2.Stop();
  3434. string str = ex.StackTrace;
  3435. AddMessage(LogType.Error,
  3436. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3437. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3438. }
  3439. stopwatch1.Stop();
  3440. AddMessage(LogType.Info,
  3441. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3442. stopwatch2.ElapsedMilliseconds + "ms");
  3443. ProgressState = false;
  3444. }
  3445. #endregion S3
  3446. #region S4
  3447. /// <summary>
  3448. /// [S4] 点胶检测设备
  3449. /// </summary>
  3450. /// <param name="plcNo">PLC编号</param>
  3451. private void ReadStation_S4(int plcNo)
  3452. {
  3453. string stationCode = "[OP40]";
  3454. string stationName = "胶线检测";
  3455. string stationNameStr = stationCode + stationName;
  3456. string tagBaseName = "g_OP40_MES"; //标签变量名称
  3457. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3458. string tagAgvCommName = "agvCommFrmPC";
  3459. string tagBarsetName = "BarcodeSet";
  3460. // 触发信号字典
  3461. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  3462. s4PLCSignal_Old.Add("a4OEEType", 0); // 节拍类型(plc写入)
  3463. // PLC数据字典 赋值
  3464. s4PLCData.Add("a4OEEType", 0); // 节拍类型(plc写入)
  3465. s4PLCData.Add("a4OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  3466. s4PLCData.Add("a4OEEVehicleCode", ""); // 载具SN
  3467. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  3468. (int, string) result;
  3469. while (true)
  3470. {
  3471. try
  3472. {
  3473. if (!GlobalContext._IsCon_Funs1)
  3474. {
  3475. UpdatePLCMonitor(1, plcNo, 0);
  3476. continue;
  3477. }
  3478. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3479. {
  3480. Stopwatch stopwatch1 = new Stopwatch();
  3481. Stopwatch stopwatch2 = new Stopwatch();
  3482. stopwatch1.Start();
  3483. stopwatch2.Start();
  3484. #region 一次性读取所有数据
  3485. // 一次性读取所有数据
  3486. result = FunsEip[plcNo]
  3487. .Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3488. if (result.Item1 != 0)
  3489. {
  3490. //richTextBox1.AppendText("\n" + strRet);
  3491. }
  3492. else
  3493. {
  3494. //richTextBox1.AppendText("\n" + "读取成功");
  3495. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  3496. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  3497. ? XiaomiDeviceState.Unknown
  3498. : (XiaomiDeviceState)xmDeviceStateInt;
  3499. s4PLCData["a4OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  3500. s4PLCData["a4OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  3501. s4PLCData["a4OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  3502. }
  3503. #endregion 一次性读取所有数据
  3504. stopwatch2.Stop();
  3505. #region 进站
  3506. try
  3507. {
  3508. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3509. {
  3510. lock (lockObj)
  3511. {
  3512. if (!ProgressState)
  3513. {
  3514. ProgressState = true;
  3515. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData,
  3516. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  3517. out ProgressState));
  3518. }
  3519. }
  3520. }
  3521. }
  3522. catch (Exception ex)
  3523. {
  3524. ProgressState = false;
  3525. string str = ex.StackTrace;
  3526. AddMessage_Station(stationNameStr, LogType.Error,
  3527. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3528. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3529. }
  3530. #endregion 进站
  3531. #region 出站
  3532. try
  3533. {
  3534. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3535. {
  3536. lock (lockObj)
  3537. {
  3538. if (!ProgressState)
  3539. {
  3540. ProgressState = true;
  3541. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData,
  3542. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  3543. out ProgressState));
  3544. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3545. }
  3546. }
  3547. }
  3548. }
  3549. catch (Exception ex)
  3550. {
  3551. string str = ex.StackTrace;
  3552. AddMessage_Station(stationNameStr, LogType.Error,
  3553. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3554. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3555. }
  3556. #endregion 出站
  3557. #region 节拍接口
  3558. try
  3559. {
  3560. int a40EEType = (int)s4PLCData["a40EEType"];
  3561. int a40EETypeGOld = (int)s4PLCSignal_Old["a40EEType"];
  3562. //若设备紧急复原后节拍重置
  3563. if (a40EEType == 1)
  3564. {
  3565. a40EETypeGOld = 0;
  3566. }
  3567. if (a40EEType != a40EETypeGOld)
  3568. {
  3569. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  3570. if ((a40EETypeGOld == 1 && a40EEType != 2) || (a40EETypeGOld == 3 && a40EEType != 4) ||
  3571. (a40EETypeGOld == 5 && a40EEType != 6))
  3572. {
  3573. //写入PLC
  3574. stPLC_MesData.iotData.beatReturn = 2; //NG
  3575. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  3576. AddMessage(LogType.Info,
  3577. stationNameStr +
  3578. $"_节拍接口-- 设备本次上传节拍[{a40EEType}],未上传节拍[{a40EETypeGOld}]的结束信号,请检查;总用时" +
  3579. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  3580. "ms");
  3581. return;
  3582. }
  3583. else
  3584. {
  3585. Task.Run(() =>
  3586. S4节拍接口(plcNo, stationNameStr, tagBaseName,
  3587. stPLC_MesData.iotData)); // MreTasks[4].Set();
  3588. }
  3589. s4PLCSignal_Old["a40EEType"] = s4PLCData["a40EEType"];
  3590. }
  3591. }
  3592. catch (Exception ex)
  3593. {
  3594. string str = ex.StackTrace;
  3595. AddMessage_Station(stationNameStr, LogType.Error,
  3596. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3597. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3598. }
  3599. #endregion
  3600. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3601. stopwatch1.Stop();
  3602. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3603. }
  3604. else
  3605. {
  3606. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3607. AddMessage_Station(stationNameStr, LogType.Info,
  3608. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3609. FunsEip[plcNo].Connect(); // 重连
  3610. }
  3611. }
  3612. catch (Exception ex)
  3613. {
  3614. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3615. AddMessage_Station(stationNameStr, LogType.Error,
  3616. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3617. }
  3618. Thread.Sleep(IntervalReadPLC);
  3619. }
  3620. }
  3621. /// <summary>
  3622. /// [S4] 点胶检测设备 - 进站
  3623. /// </summary>
  3624. /// <param name="plcNo">PLC编号</param>
  3625. /// <param name="stationNameStr">工站全称</param>
  3626. /// <param name="stPLC_MesData"></param>
  3627. /// <param name="tagMesCommName"></param>
  3628. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  3629. string tagBarsetName, out bool ProgressState)
  3630. {
  3631. Stopwatch stopwatch1 = new Stopwatch();
  3632. Stopwatch stopwatch2 = new Stopwatch();
  3633. try
  3634. {
  3635. stopwatch1.Start();
  3636. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3637. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3638. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  3639. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  3640. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3641. //载具码验证产品码
  3642. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3643. if (string.IsNullOrEmpty(strProductBarcode))
  3644. {
  3645. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3646. }
  3647. sn = strProductBarcode;
  3648. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3649. // 产品SN(物料码)校验
  3650. List<TestItem> item = new List<TestItem>();
  3651. stopwatch2.Start();
  3652. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3653. item, MachineId, StationId);
  3654. stopwatch2.Stop();
  3655. //指令执行结果 1:OK 110:失败
  3656. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3657. //进站结果写入PLC
  3658. CommandFromPLC resultToPlC = new CommandFromPLC();
  3659. resultToPlC.cmd = 0;
  3660. resultToPlC.cmdParam = 0; //指令参数
  3661. resultToPlC.cmdResult = mesResultFrmWeb;
  3662. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3663. }
  3664. catch (Exception ex)
  3665. {
  3666. string str = ex.StackTrace;
  3667. AddMessage(LogType.Error,
  3668. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3669. str.Length - str.LastIndexOf("\\") - 1));
  3670. CommandFromPLC resultToPlC = new CommandFromPLC();
  3671. resultToPlC.cmd = 0;
  3672. resultToPlC.cmdParam = 0; //指令参数
  3673. resultToPlC.cmdResult = 110;
  3674. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3675. }
  3676. stopwatch1.Stop();
  3677. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3678. AddMessage(LogType.Info,
  3679. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3680. stopwatch2.ElapsedMilliseconds + "ms");
  3681. ProgressState = false;
  3682. }
  3683. /// <summary>
  3684. /// [S4] 点胶检测设备 - 出站接口
  3685. /// </summary>
  3686. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  3687. string stationCode, string stationName, out bool ProgressState)
  3688. {
  3689. Stopwatch stopwatch1 = new Stopwatch();
  3690. Stopwatch stopwatch2 = new Stopwatch();
  3691. try
  3692. {
  3693. stopwatch1.Start();
  3694. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3695. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3696. string processItem = stationName; // 测试项目
  3697. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3698. string supplierCode = ""; // 供应商代码
  3699. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3700. string batch_num = GlobalContext.BatchNumber; // 批次号
  3701. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3702. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3703. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3704. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  3705. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  3706. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3707. bool pass = a1Result == 1;
  3708. //根据载具码获取产品码
  3709. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3710. if (string.IsNullOrEmpty(strProductBarcode))
  3711. {
  3712. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3713. }
  3714. sn = strProductBarcode;
  3715. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3716. List<TestItem> items = new List<TestItem>();
  3717. items.Add(new TestItem()
  3718. {
  3719. Parameter_name = "载具码",
  3720. Parameter_value = CarrierBarcode,
  3721. Parameter_unit = ""
  3722. });
  3723. items.Add(new TestItem()
  3724. {
  3725. Parameter_name = "产品码",
  3726. Parameter_value = sn,
  3727. Parameter_unit = ""
  3728. });
  3729. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3730. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3731. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  3732. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3733. stopwatch2.Start();
  3734. //进站结果写入PLC
  3735. CommandFromPLC resultToPlC = new CommandFromPLC();
  3736. resultToPlC.cmd = 0;
  3737. resultToPlC.cmdParam = 0; //指令参数
  3738. resultToPlC.cmdResult = mesResultFrmWeb;
  3739. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3740. stopwatch2.Stop();
  3741. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3742. //保存PLC返回MES数据到本地
  3743. ResponseMessage message = new ResponseMessage();
  3744. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  3745. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  3746. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  3747. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  3748. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  3749. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  3750. if (message.result == false)
  3751. {
  3752. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3753. }
  3754. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3755. }
  3756. catch (Exception ex)
  3757. {
  3758. stopwatch2.Start();
  3759. CommandFromPLC resultToPlC = new CommandFromPLC();
  3760. resultToPlC.cmd = 0;
  3761. resultToPlC.cmdParam = 0; //指令参数
  3762. resultToPlC.cmdResult = 110;
  3763. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3764. stopwatch2.Stop();
  3765. string str = ex.StackTrace;
  3766. AddMessage(LogType.Error,
  3767. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3768. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3769. }
  3770. stopwatch1.Stop();
  3771. AddMessage(LogType.Info,
  3772. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3773. stopwatch2.ElapsedMilliseconds + "ms");
  3774. ProgressState = false;
  3775. }
  3776. private void S4节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  3777. {
  3778. Stopwatch stopwatch1 = new Stopwatch();
  3779. Stopwatch stopwatch2 = new Stopwatch();
  3780. string resultStr = string.Empty;
  3781. try
  3782. {
  3783. stopwatch1.Start();
  3784. string oEEType = ((int)s1PLCData["a4OEEType"]).ToString(); // 节拍类型(plc写入)
  3785. string a40EEPartNo = (string)s1PLCData["a40EEPartNo"]; // 物料码
  3786. a40EEPartNo = a40EEPartNo.Replace("\0", "");
  3787. string a50EEVehicleCode = (string)s1PLCData["a50EEVehicleCode"]; // 载具SN
  3788. a50EEVehicleCode = a50EEVehicleCode.Replace("\0", "");
  3789. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  3790. if (!actionBool)
  3791. {
  3792. stopwatch2.Start();
  3793. //写入PLC
  3794. iot_data.beatReturn = 2; //NG
  3795. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3796. stopwatch2.Stop();
  3797. AddMessage(LogType.Info,
  3798. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  3799. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3800. return;
  3801. }
  3802. //作业开始后要有物料和载具信息
  3803. if (string.IsNullOrEmpty(a40EEPartNo) && string.IsNullOrEmpty(a50EEVehicleCode) &&
  3804. Convert.ToInt32(oEEType) > 2)
  3805. {
  3806. stopwatch2.Start();
  3807. //写入PLC
  3808. iot_data.beatReturn = 2; //NG
  3809. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3810. stopwatch2.Stop();
  3811. AddMessage_Station(stationNameStr, LogType.Info,
  3812. stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  3813. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3814. return;
  3815. }
  3816. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a40EEPartNo))
  3817. {
  3818. stopwatch2.Start();
  3819. //写入PLC
  3820. iot_data.beatReturn = 2; //NG
  3821. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3822. stopwatch2.Stop();
  3823. AddMessage_Station(stationNameStr, LogType.Info,
  3824. stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  3825. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3826. return;
  3827. }
  3828. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a50EEVehicleCode))
  3829. {
  3830. stopwatch2.Start();
  3831. //写入PLC
  3832. iot_data.beatReturn = 2; //NG
  3833. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3834. stopwatch2.Stop();
  3835. AddMessage_Station(stationNameStr, LogType.Info,
  3836. stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  3837. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3838. return;
  3839. }
  3840. short _result = 0;
  3841. // 上传OEE
  3842. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a40EEPartNo, a50EEVehicleCode);
  3843. _result = result.Item1;
  3844. resultStr = result.Item2;
  3845. if (_result == 1)
  3846. {
  3847. stopwatch2.Start();
  3848. //写入PLC
  3849. iot_data.beatReturn = 1; //OK
  3850. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3851. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  3852. stopwatch2.Stop();
  3853. }
  3854. else
  3855. {
  3856. stopwatch2.Start();
  3857. //写入PLC
  3858. iot_data.beatReturn = 2; //NG
  3859. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3860. stopwatch2.Stop();
  3861. AddMessage_Station(stationNameStr, LogType.Error,
  3862. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  3863. }
  3864. }
  3865. catch (Exception ex)
  3866. {
  3867. string str = ex.StackTrace;
  3868. AddMessage_Station(stationNameStr, LogType.Error,
  3869. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  3870. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3871. // MES_Flag
  3872. stopwatch2.Start();
  3873. //写入PLC
  3874. iot_data.beatReturn = 2; //NG
  3875. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  3876. stopwatch2.Stop();
  3877. }
  3878. stopwatch1.Stop();
  3879. AddMessage(LogType.Info,
  3880. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3881. stopwatch2.ElapsedMilliseconds + "ms");
  3882. }
  3883. #endregion
  3884. #region S5
  3885. /// <summary>
  3886. /// [S5] 点胶检测设备
  3887. /// </summary>
  3888. /// <param name="plcNo">PLC编号</param>
  3889. private void ReadStation_S5(int plcNo)
  3890. {
  3891. string stationCode = "[OP50]";
  3892. string stationName = "ADD板上料组装装备";
  3893. string stationNameStr = stationCode + stationName;
  3894. string tagBaseName = "g_OP50_MES"; //标签变量名称
  3895. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3896. string tagAgvCommName = "agvCommFrmPC";
  3897. string tagBarsetName = "BarcodeSet";
  3898. // 触发信号字典
  3899. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  3900. s5PLCSignal_Old.Add("a5OEEType", 0); // 节拍类型(plc写入)
  3901. // PLC数据字典 赋值
  3902. s5PLCData.Add("a5OEEType", 0); // 节拍类型(plc写入)
  3903. s5PLCData.Add("a5OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  3904. s5PLCData.Add("a5OEEVehicleCode", ""); // 载具SN
  3905. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  3906. (int, string) result;
  3907. while (true)
  3908. {
  3909. try
  3910. {
  3911. if (!GlobalContext._IsCon_Funs1)
  3912. {
  3913. UpdatePLCMonitor(1, plcNo, 0);
  3914. continue;
  3915. }
  3916. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3917. {
  3918. Stopwatch stopwatch1 = new Stopwatch();
  3919. Stopwatch stopwatch2 = new Stopwatch();
  3920. stopwatch1.Start();
  3921. stopwatch2.Start();
  3922. #region 一次性读取所有数据
  3923. // 一次性读取所有数据
  3924. result = FunsEip[plcNo]
  3925. .Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3926. if (result.Item1 != 0)
  3927. {
  3928. //richTextBox1.AppendText("\n" + strRet);
  3929. }
  3930. else
  3931. {
  3932. //richTextBox1.AppendText("\n" + "读取成功");
  3933. //richTextBox1.AppendText("\n" + "读取成功");
  3934. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  3935. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  3936. ? XiaomiDeviceState.Unknown
  3937. : (XiaomiDeviceState)xmDeviceStateInt;
  3938. s5PLCData["a5OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  3939. s5PLCData["a5OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  3940. s5PLCData["a5OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  3941. }
  3942. #endregion 一次性读取所有数据
  3943. stopwatch2.Stop();
  3944. #region 进站
  3945. try
  3946. {
  3947. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3948. {
  3949. lock (lockObj)
  3950. {
  3951. if (!ProgressState)
  3952. {
  3953. ProgressState = true;
  3954. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData,
  3955. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  3956. out ProgressState));
  3957. }
  3958. }
  3959. }
  3960. }
  3961. catch (Exception ex)
  3962. {
  3963. ProgressState = false;
  3964. string str = ex.StackTrace;
  3965. AddMessage_Station(stationNameStr, LogType.Error,
  3966. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3967. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3968. }
  3969. #endregion 进站
  3970. #region 出站
  3971. try
  3972. {
  3973. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3974. {
  3975. lock (lockObj)
  3976. {
  3977. if (!ProgressState)
  3978. {
  3979. ProgressState = true;
  3980. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData,
  3981. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  3982. out ProgressState));
  3983. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3984. }
  3985. }
  3986. }
  3987. }
  3988. catch (Exception ex)
  3989. {
  3990. ProgressState = false;
  3991. string str = ex.StackTrace;
  3992. AddMessage_Station(stationNameStr, LogType.Error,
  3993. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3994. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3995. }
  3996. #endregion 出站
  3997. #region 节拍接口
  3998. try
  3999. {
  4000. int a50EEType = (int)s5PLCData["a50EEType"];
  4001. int a50EETypeGOld = (int)s5PLCSignal_Old["a50EEType"];
  4002. //若设备紧急复原后节拍重置
  4003. if (a50EEType == 1)
  4004. {
  4005. a50EETypeGOld = 0;
  4006. }
  4007. if (a50EEType != a50EETypeGOld)
  4008. {
  4009. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  4010. if ((a50EETypeGOld == 1 && a50EEType != 2) || (a50EETypeGOld == 3 && a50EEType != 4) ||
  4011. (a50EETypeGOld == 5 && a50EEType != 6))
  4012. {
  4013. //写入PLC
  4014. stPLC_MesData.iotData.beatReturn = 2; //NG
  4015. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  4016. AddMessage(LogType.Info,
  4017. stationNameStr +
  4018. $"_节拍接口-- 设备本次上传节拍[{a50EEType}],未上传节拍[{a50EETypeGOld}]的结束信号,请检查;总用时" +
  4019. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  4020. "ms");
  4021. return;
  4022. }
  4023. else
  4024. {
  4025. Task.Run(() =>
  4026. S5节拍接口(plcNo, stationNameStr, tagBaseName,
  4027. stPLC_MesData.iotData)); // MreTasks[4].Set();
  4028. }
  4029. s5PLCSignal_Old["a50EEType"] = s5PLCData["a50EEType"];
  4030. }
  4031. }
  4032. catch (Exception ex)
  4033. {
  4034. string str = ex.StackTrace;
  4035. AddMessage_Station(stationNameStr, LogType.Error,
  4036. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4037. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4038. }
  4039. #endregion
  4040. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4041. stopwatch1.Stop();
  4042. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4043. }
  4044. else
  4045. {
  4046. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4047. AddMessage_Station(stationNameStr, LogType.Info,
  4048. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4049. FunsEip[plcNo].Connect(); // 重连
  4050. }
  4051. }
  4052. catch (Exception ex)
  4053. {
  4054. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4055. AddMessage_Station(stationNameStr, LogType.Error,
  4056. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4057. }
  4058. Thread.Sleep(IntervalReadPLC);
  4059. }
  4060. }
  4061. /// <summary>
  4062. /// [S5] 点胶检测设备 - 进站
  4063. /// </summary>
  4064. /// <param name="plcNo">PLC编号</param>
  4065. /// <param name="stationNameStr">工站全称</param>
  4066. /// <param name="stPLC_MesData"></param>
  4067. /// <param name="tagMesCommName"></param>
  4068. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  4069. string tagBarsetName, out bool ProgressState)
  4070. {
  4071. Stopwatch stopwatch1 = new Stopwatch();
  4072. Stopwatch stopwatch2 = new Stopwatch();
  4073. try
  4074. {
  4075. stopwatch1.Start();
  4076. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4077. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4078. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  4079. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  4080. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  4081. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4082. //载具码验证产品码 //载具码验证产品码
  4083. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4084. if (string.IsNullOrEmpty(strProductBarcode))
  4085. {
  4086. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4087. }
  4088. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  4089. //if (sn != strProductBarcode)
  4090. //{
  4091. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  4092. //}
  4093. sn = strProductBarcode;
  4094. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4095. // 产品SN(物料码)校验
  4096. List<TestItem> item = new List<TestItem>();
  4097. stopwatch2.Start();
  4098. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  4099. item, MachineId, StationId);
  4100. stopwatch2.Stop();
  4101. //指令执行结果 1:OK 110:失败
  4102. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4103. //进站结果写入PLC
  4104. CommandFromPLC resultToPlC = new CommandFromPLC();
  4105. resultToPlC.cmd = 0;
  4106. resultToPlC.cmdParam = 0; //指令参数
  4107. resultToPlC.cmdResult = mesResultFrmWeb;
  4108. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4109. }
  4110. catch (Exception ex)
  4111. {
  4112. string str = ex.StackTrace;
  4113. AddMessage(LogType.Error,
  4114. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4115. str.Length - str.LastIndexOf("\\") - 1));
  4116. CommandFromPLC resultToPlC = new CommandFromPLC();
  4117. resultToPlC.cmd = 0;
  4118. resultToPlC.cmdParam = 0; //指令参数
  4119. resultToPlC.cmdResult = 110;
  4120. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4121. }
  4122. stopwatch1.Stop();
  4123. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4124. AddMessage(LogType.Info,
  4125. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4126. stopwatch2.ElapsedMilliseconds + "ms");
  4127. ProgressState = false;
  4128. }
  4129. /// <summary>
  4130. /// [S5] 点胶检测设备 - 出站接口
  4131. /// </summary>
  4132. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  4133. string stationCode, string stationName, out bool ProgressState)
  4134. {
  4135. Stopwatch stopwatch1 = new Stopwatch();
  4136. Stopwatch stopwatch2 = new Stopwatch();
  4137. try
  4138. {
  4139. stopwatch1.Start();
  4140. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4141. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4142. string processItem = stationName; // 测试项目
  4143. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4144. string supplierCode = ""; // 供应商代码
  4145. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4146. string batch_num = GlobalContext.BatchNumber; // 批次号
  4147. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4148. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4149. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
  4150. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4151. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  4152. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  4153. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4154. bool pass = a1Result == 1;
  4155. //根据载具码获取产品码
  4156. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4157. if (string.IsNullOrEmpty(strProductBarcode))
  4158. {
  4159. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4160. }
  4161. sn = strProductBarcode;
  4162. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4163. List<TestItem> items = new List<TestItem>();
  4164. items.Add(new TestItem()
  4165. {
  4166. Parameter_name = "载具码",
  4167. Parameter_value = CarrierBarcode,
  4168. Parameter_unit = ""
  4169. });
  4170. items.Add(new TestItem()
  4171. {
  4172. Parameter_name = "产品码",
  4173. Parameter_value = sn,
  4174. Parameter_unit = ""
  4175. });
  4176. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4177. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4178. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode, paramJson);
  4179. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4180. stopwatch2.Start();
  4181. //进站结果写入PLC
  4182. CommandFromPLC resultToPlC = new CommandFromPLC();
  4183. resultToPlC.cmd = 0;
  4184. resultToPlC.cmdParam = 0; //指令参数
  4185. resultToPlC.cmdResult = mesResultFrmWeb;
  4186. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4187. stopwatch2.Stop();
  4188. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4189. //保存PLC返回MES数据到本地
  4190. ResponseMessage message = new ResponseMessage();
  4191. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  4192. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB,
  4193. stPLC_MesData.mesData.nRemainCount, "");
  4194. if (message.result == false)
  4195. {
  4196. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4197. }
  4198. //保存部件码信息
  4199. if (!string.IsNullOrEmpty(PartBarcode))
  4200. {
  4201. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  4202. if (message.result == false)
  4203. {
  4204. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  4205. }
  4206. }
  4207. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4208. }
  4209. catch (Exception ex)
  4210. {
  4211. stopwatch2.Start();
  4212. CommandFromPLC resultToPlC = new CommandFromPLC();
  4213. resultToPlC.cmd = 0;
  4214. resultToPlC.cmdParam = 0; //指令参数
  4215. resultToPlC.cmdResult = 110;
  4216. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4217. stopwatch2.Stop();
  4218. string str = ex.StackTrace;
  4219. AddMessage(LogType.Error,
  4220. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4221. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4222. }
  4223. stopwatch1.Stop();
  4224. AddMessage(LogType.Info,
  4225. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4226. stopwatch2.ElapsedMilliseconds + "ms");
  4227. ProgressState = false;
  4228. }
  4229. private void S5节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  4230. {
  4231. Stopwatch stopwatch1 = new Stopwatch();
  4232. Stopwatch stopwatch2 = new Stopwatch();
  4233. string resultStr = string.Empty;
  4234. try
  4235. {
  4236. stopwatch1.Start();
  4237. string oEEType = ((int)s1PLCData["a5OEEType"]).ToString(); // 节拍类型(plc写入)
  4238. string a50EEPartNo = (string)s1PLCData["a50EEPartNo"]; // 物料码
  4239. a50EEPartNo = a50EEPartNo.Replace("\0", "");
  4240. string a40EEVehicleCode = (string)s1PLCData["a40EEVehicleCode"]; // 载具SN
  4241. a40EEVehicleCode = a40EEVehicleCode.Replace("\0", "");
  4242. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4243. if (!actionBool)
  4244. {
  4245. stopwatch2.Start();
  4246. //写入PLC
  4247. iot_data.beatReturn = 2; //NG
  4248. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4249. stopwatch2.Stop();
  4250. AddMessage(LogType.Info,
  4251. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  4252. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4253. return;
  4254. }
  4255. //作业开始后要有物料和载具信息
  4256. if (string.IsNullOrEmpty(a50EEPartNo) && string.IsNullOrEmpty(a40EEVehicleCode) &&
  4257. Convert.ToInt32(oEEType) > 2)
  4258. {
  4259. stopwatch2.Start();
  4260. //写入PLC
  4261. iot_data.beatReturn = 2; //NG
  4262. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4263. stopwatch2.Stop();
  4264. AddMessage_Station(stationNameStr, LogType.Info,
  4265. stationNameStr + $"_[{a40EEVehicleCode}][{a50EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  4266. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4267. return;
  4268. }
  4269. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a50EEPartNo))
  4270. {
  4271. stopwatch2.Start();
  4272. //写入PLC
  4273. iot_data.beatReturn = 2; //NG
  4274. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4275. stopwatch2.Stop();
  4276. AddMessage_Station(stationNameStr, LogType.Info,
  4277. stationNameStr + $"_[{a40EEVehicleCode}][{a50EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  4278. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4279. return;
  4280. }
  4281. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a40EEVehicleCode))
  4282. {
  4283. stopwatch2.Start();
  4284. //写入PLC
  4285. iot_data.beatReturn = 2; //NG
  4286. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4287. stopwatch2.Stop();
  4288. AddMessage_Station(stationNameStr, LogType.Info,
  4289. stationNameStr + $"_[{a40EEVehicleCode}][{a50EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  4290. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4291. return;
  4292. }
  4293. short _result = 0;
  4294. // 上传OEE
  4295. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a50EEPartNo, a40EEVehicleCode);
  4296. _result = result.Item1;
  4297. resultStr = result.Item2;
  4298. if (_result == 1)
  4299. {
  4300. stopwatch2.Start();
  4301. //写入PLC
  4302. iot_data.beatReturn = 1; //OK
  4303. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4304. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  4305. stopwatch2.Stop();
  4306. }
  4307. else
  4308. {
  4309. stopwatch2.Start();
  4310. //写入PLC
  4311. iot_data.beatReturn = 2; //NG
  4312. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4313. stopwatch2.Stop();
  4314. AddMessage_Station(stationNameStr, LogType.Error,
  4315. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  4316. }
  4317. }
  4318. catch (Exception ex)
  4319. {
  4320. string str = ex.StackTrace;
  4321. AddMessage_Station(stationNameStr, LogType.Error,
  4322. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  4323. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4324. // MES_Flag
  4325. stopwatch2.Start();
  4326. //写入PLC
  4327. iot_data.beatReturn = 2; //NG
  4328. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4329. stopwatch2.Stop();
  4330. }
  4331. stopwatch1.Stop();
  4332. AddMessage(LogType.Info,
  4333. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4334. stopwatch2.ElapsedMilliseconds + "ms");
  4335. }
  4336. #endregion
  4337. #region S6
  4338. private Dictionary<string, object> s6PLCData = new Dictionary<string, object>();
  4339. private Dictionary<string, object> s6PLCSignal_Old = new Dictionary<string, object>();
  4340. /// <summary>
  4341. /// [S6] 顶盖装配设备
  4342. /// </summary>
  4343. /// <param name="plcNo">PLC编号</param>
  4344. private void ReadStation_S6(int plcNo)
  4345. {
  4346. string stationCode = "[OP60]";
  4347. string stationName = "组上盖板";
  4348. string stationNameStr = stationCode + stationName;
  4349. string tagBaseName = "g_OP60_MES"; //标签变量名称
  4350. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4351. string tagAgvCommName = "agvCommFrmPC";
  4352. string tagBarsetName = "BarcodeSet";
  4353. // 触发信号字典
  4354. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4355. s6PLCSignal_Old.Add("a6OEEType", 0); // 节拍类型(plc写入)
  4356. // PLC数据字典 赋值
  4357. s6PLCData.Add("a6OEEType", 0); // 节拍类型(plc写入)
  4358. s6PLCData.Add("a6OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4359. s6PLCData.Add("a6OEEVehicleCode", ""); // 载具SN
  4360. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  4361. (int, string) result;
  4362. while (true)
  4363. {
  4364. try
  4365. {
  4366. if (!GlobalContext._IsCon_Funs1)
  4367. {
  4368. UpdatePLCMonitor(1, plcNo, 0);
  4369. continue;
  4370. }
  4371. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4372. {
  4373. Stopwatch stopwatch1 = new Stopwatch();
  4374. Stopwatch stopwatch2 = new Stopwatch();
  4375. stopwatch1.Start();
  4376. stopwatch2.Start();
  4377. #region 一次性读取所有数据
  4378. // 一次性读取所有数据
  4379. result = FunsEip[plcNo]
  4380. .Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4381. if (result.Item1 != 0)
  4382. {
  4383. //richTextBox1.AppendText("\n" + strRet);
  4384. }
  4385. else
  4386. {
  4387. //richTextBox1.AppendText("\n" + "读取成功");
  4388. //richTextBox1.AppendText("\n" + "读取成功");
  4389. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  4390. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  4391. ? XiaomiDeviceState.Unknown
  4392. : (XiaomiDeviceState)xmDeviceStateInt;
  4393. s6PLCData["a6OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  4394. s6PLCData["a6OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  4395. s6PLCData["a6OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  4396. }
  4397. #endregion 一次性读取所有数据
  4398. stopwatch2.Stop();
  4399. #region 进站
  4400. try
  4401. {
  4402. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4403. {
  4404. lock (lockObj)
  4405. {
  4406. if (!ProgressState)
  4407. {
  4408. ProgressState = true;
  4409. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData,
  4410. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  4411. out ProgressState));
  4412. }
  4413. }
  4414. }
  4415. }
  4416. catch (Exception ex)
  4417. {
  4418. ProgressState = false;
  4419. string str = ex.StackTrace;
  4420. AddMessage_Station(stationNameStr, LogType.Error,
  4421. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4422. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4423. }
  4424. #endregion 进站
  4425. #region 出站
  4426. try
  4427. {
  4428. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4429. {
  4430. lock (lockObj)
  4431. {
  4432. if (!ProgressState)
  4433. {
  4434. ProgressState = true;
  4435. ;
  4436. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData,
  4437. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4438. out ProgressState));
  4439. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4440. }
  4441. }
  4442. }
  4443. }
  4444. catch (Exception ex)
  4445. {
  4446. ProgressState = false;
  4447. string str = ex.StackTrace;
  4448. AddMessage_Station(stationNameStr, LogType.Error,
  4449. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4450. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4451. }
  4452. #endregion 出站
  4453. #region 节拍接口
  4454. try
  4455. {
  4456. int a60EEType = (int)s6PLCData["a60EEType"];
  4457. int a60EETypeGOld = (int)s6PLCSignal_Old["a60EEType"];
  4458. //若设备紧急复原后节拍重置
  4459. if (a60EEType == 1)
  4460. {
  4461. a60EETypeGOld = 0;
  4462. }
  4463. if (a60EEType != a60EETypeGOld)
  4464. {
  4465. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  4466. if ((a60EETypeGOld == 1 && a60EEType != 2) || (a60EETypeGOld == 3 && a60EEType != 4) ||
  4467. (a60EETypeGOld == 5 && a60EEType != 6))
  4468. {
  4469. //写入PLC
  4470. stPLC_MesData.iotData.beatReturn = 2; //NG
  4471. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  4472. AddMessage(LogType.Info,
  4473. stationNameStr +
  4474. $"_节拍接口-- 设备本次上传节拍[{a60EEType}],未上传节拍[{a60EETypeGOld}]的结束信号,请检查;总用时" +
  4475. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  4476. "ms");
  4477. return;
  4478. }
  4479. else
  4480. {
  4481. Task.Run(() =>
  4482. S6节拍接口(plcNo, stationNameStr, tagBaseName,
  4483. stPLC_MesData.iotData)); // MreTasks[4].Set();
  4484. }
  4485. s6PLCSignal_Old["a60EEType"] = s6PLCData["a60EEType"];
  4486. }
  4487. }
  4488. catch (Exception ex)
  4489. {
  4490. string str = ex.StackTrace;
  4491. AddMessage_Station(stationNameStr, LogType.Error,
  4492. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4493. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4494. }
  4495. #endregion
  4496. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4497. stopwatch1.Stop();
  4498. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4499. }
  4500. else
  4501. {
  4502. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4503. AddMessage_Station(stationNameStr, LogType.Info,
  4504. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4505. FunsEip[plcNo].Connect(); // 重连
  4506. }
  4507. }
  4508. catch (Exception ex)
  4509. {
  4510. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4511. AddMessage_Station(stationNameStr, LogType.Error,
  4512. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4513. }
  4514. Thread.Sleep(IntervalReadPLC);
  4515. }
  4516. }
  4517. /// <summary>
  4518. /// [S6] 顶盖装配设备 - 进站
  4519. /// </summary>
  4520. /// <param name="plcNo">PLC编号</param>
  4521. /// <param name="stationNameStr">工站全称</param>
  4522. /// <param name="stPLC_MesData"></param>
  4523. /// <param name="tagMesCommName"></param>
  4524. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  4525. string tagBarsetName, out bool ProgressState)
  4526. {
  4527. Stopwatch stopwatch1 = new Stopwatch();
  4528. Stopwatch stopwatch2 = new Stopwatch();
  4529. try
  4530. {
  4531. stopwatch1.Start();
  4532. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4533. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4534. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  4535. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  4536. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4537. //载具码验证产品码
  4538. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4539. if (string.IsNullOrEmpty(strProductBarcode))
  4540. {
  4541. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4542. }
  4543. sn = strProductBarcode;
  4544. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4545. // 产品SN(物料码)校验
  4546. List<TestItem> item = new List<TestItem>();
  4547. stopwatch2.Start();
  4548. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  4549. item, MachineId, StationId);
  4550. stopwatch2.Stop();
  4551. //指令执行结果 1:OK 110:失败
  4552. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4553. //进站结果写入PLC
  4554. CommandFromPLC resultToPlC = new CommandFromPLC();
  4555. resultToPlC.cmd = 0;
  4556. resultToPlC.cmdParam = 0; //指令参数
  4557. resultToPlC.cmdResult = mesResultFrmWeb;
  4558. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4559. }
  4560. catch (Exception ex)
  4561. {
  4562. string str = ex.StackTrace;
  4563. AddMessage(LogType.Error,
  4564. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4565. str.Length - str.LastIndexOf("\\") - 1));
  4566. CommandFromPLC resultToPlC = new CommandFromPLC();
  4567. resultToPlC.cmd = 0;
  4568. resultToPlC.cmdParam = 0; //指令参数
  4569. resultToPlC.cmdResult = 110;
  4570. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4571. }
  4572. stopwatch1.Stop();
  4573. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4574. AddMessage(LogType.Info,
  4575. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4576. stopwatch2.ElapsedMilliseconds + "ms");
  4577. ProgressState = false;
  4578. }
  4579. /// <summary>
  4580. /// [S6] 顶盖装配设备 - 出站接口
  4581. /// </summary>
  4582. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  4583. string stationCode, string stationName, out bool ProgressState)
  4584. {
  4585. Stopwatch stopwatch1 = new Stopwatch();
  4586. Stopwatch stopwatch2 = new Stopwatch();
  4587. try
  4588. {
  4589. stopwatch1.Start();
  4590. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4591. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4592. string processItem = stationName; // 测试项目
  4593. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4594. string supplierCode = ""; // 供应商代码
  4595. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4596. string batch_num = GlobalContext.BatchNumber; // 批次号
  4597. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4598. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4599. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4600. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  4601. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  4602. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4603. bool pass = a1Result == 1;
  4604. //根据载具码获取产品码
  4605. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4606. if (string.IsNullOrEmpty(strProductBarcode))
  4607. {
  4608. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4609. }
  4610. sn = strProductBarcode;
  4611. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4612. List<TestItem> items = new List<TestItem>();
  4613. items.Add(new TestItem()
  4614. {
  4615. Parameter_name = "载具码",
  4616. Parameter_value = CarrierBarcode,
  4617. Parameter_unit = ""
  4618. });
  4619. items.Add(new TestItem()
  4620. {
  4621. Parameter_name = "产品码",
  4622. Parameter_value = sn,
  4623. Parameter_unit = ""
  4624. });
  4625. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4626. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4627. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  4628. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4629. stopwatch2.Start();
  4630. //进站结果写入PLC
  4631. CommandFromPLC resultToPlC = new CommandFromPLC();
  4632. resultToPlC.cmd = 0;
  4633. resultToPlC.cmdParam = 0; //指令参数
  4634. resultToPlC.cmdResult = mesResultFrmWeb;
  4635. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4636. stopwatch2.Stop();
  4637. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4638. //保存PLC返回MES数据到本地
  4639. ResponseMessage message = new ResponseMessage();
  4640. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  4641. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  4642. if (message.result == false)
  4643. {
  4644. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4645. }
  4646. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4647. }
  4648. catch (Exception ex)
  4649. {
  4650. stopwatch2.Start();
  4651. CommandFromPLC resultToPlC = new CommandFromPLC();
  4652. resultToPlC.cmd = 0;
  4653. resultToPlC.cmdParam = 0; //指令参数
  4654. resultToPlC.cmdResult = 110;
  4655. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4656. stopwatch2.Stop();
  4657. string str = ex.StackTrace;
  4658. AddMessage(LogType.Error,
  4659. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4660. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4661. }
  4662. stopwatch1.Stop();
  4663. AddMessage(LogType.Info,
  4664. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4665. stopwatch2.ElapsedMilliseconds + "ms");
  4666. ProgressState = false;
  4667. }
  4668. private void S6节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  4669. {
  4670. Stopwatch stopwatch1 = new Stopwatch();
  4671. Stopwatch stopwatch2 = new Stopwatch();
  4672. string resultStr = string.Empty;
  4673. try
  4674. {
  4675. stopwatch1.Start();
  4676. string oEEType = ((int)s1PLCData["a6OEEType"]).ToString(); // 节拍类型(plc写入)
  4677. string a60EEPartNo = (string)s1PLCData["a60EEPartNo"]; // 物料码
  4678. a60EEPartNo = a60EEPartNo.Replace("\0", "");
  4679. string a60EEVehicleCode = (string)s1PLCData["a60EEVehicleCode"]; // 载具SN
  4680. a60EEVehicleCode = a60EEVehicleCode.Replace("\0", "");
  4681. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4682. if (!actionBool)
  4683. {
  4684. stopwatch2.Start();
  4685. //写入PLC
  4686. iot_data.beatReturn = 2; //NG
  4687. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4688. stopwatch2.Stop();
  4689. AddMessage(LogType.Info,
  4690. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  4691. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4692. return;
  4693. }
  4694. //作业开始后要有物料和载具信息
  4695. if (string.IsNullOrEmpty(a60EEPartNo) && string.IsNullOrEmpty(a60EEVehicleCode) &&
  4696. Convert.ToInt32(oEEType) > 2)
  4697. {
  4698. stopwatch2.Start();
  4699. //写入PLC
  4700. iot_data.beatReturn = 2; //NG
  4701. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4702. stopwatch2.Stop();
  4703. AddMessage_Station(stationNameStr, LogType.Info,
  4704. stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  4705. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4706. return;
  4707. }
  4708. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a60EEPartNo))
  4709. {
  4710. stopwatch2.Start();
  4711. //写入PLC
  4712. iot_data.beatReturn = 2; //NG
  4713. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4714. stopwatch2.Stop();
  4715. AddMessage_Station(stationNameStr, LogType.Info,
  4716. stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  4717. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4718. return;
  4719. }
  4720. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a60EEVehicleCode))
  4721. {
  4722. stopwatch2.Start();
  4723. //写入PLC
  4724. iot_data.beatReturn = 2; //NG
  4725. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4726. stopwatch2.Stop();
  4727. AddMessage_Station(stationNameStr, LogType.Info,
  4728. stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  4729. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4730. return;
  4731. }
  4732. short _result = 0;
  4733. // 上传OEE
  4734. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a60EEPartNo, a60EEVehicleCode);
  4735. _result = result.Item1;
  4736. resultStr = result.Item2;
  4737. if (_result == 1)
  4738. {
  4739. stopwatch2.Start();
  4740. //写入PLC
  4741. iot_data.beatReturn = 1; //OK
  4742. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4743. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  4744. stopwatch2.Stop();
  4745. }
  4746. else
  4747. {
  4748. stopwatch2.Start();
  4749. //写入PLC
  4750. iot_data.beatReturn = 2; //NG
  4751. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4752. stopwatch2.Stop();
  4753. AddMessage_Station(stationNameStr, LogType.Error,
  4754. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  4755. }
  4756. }
  4757. catch (Exception ex)
  4758. {
  4759. string str = ex.StackTrace;
  4760. AddMessage_Station(stationNameStr, LogType.Error,
  4761. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  4762. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4763. // MES_Flag
  4764. stopwatch2.Start();
  4765. //写入PLC
  4766. iot_data.beatReturn = 2; //NG
  4767. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  4768. stopwatch2.Stop();
  4769. }
  4770. stopwatch1.Stop();
  4771. AddMessage(LogType.Info,
  4772. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4773. stopwatch2.ElapsedMilliseconds + "ms");
  4774. }
  4775. #endregion
  4776. #region S7
  4777. private Dictionary<string, object> s7PLCSignal_Old = new Dictionary<string, object>();
  4778. private Dictionary<string, object> s7PLCData = new Dictionary<string, object>();
  4779. /// <summary>
  4780. /// [S7] 锁螺丝设备
  4781. /// </summary>
  4782. /// <param name="plcNo">PLC编号</param>
  4783. private void ReadStation_S7(int plcNo)
  4784. {
  4785. string stationCode = "[OP70]";
  4786. string stationName = "上盖板锁螺丝";
  4787. string stationNameStr = stationCode + stationName;
  4788. string tagBaseName = "g_OP70_MES"; //标签变量名称
  4789. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4790. string tagAgvCommName = "agvCommFrmPC";
  4791. string tagBarsetName = "BarcodeSet";
  4792. string tagScrewDataset = "screwDataset";
  4793. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4794. s7PLCSignal_Old.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
  4795. s7PLCSignal_Old.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
  4796. // PLC数据字典 赋值
  4797. s7PLCData.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
  4798. s7PLCData.Add("a7OEEPartNo_left", ""); // 物料码(物料码还未绑定载具SN时必填)
  4799. s7PLCData.Add("a7OEEVehicleCode_left", ""); // 载具SN
  4800. s7PLCData.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
  4801. s7PLCData.Add("a7OEEPartNo_right", ""); // 物料码(物料码还未绑定载具SN时必填)
  4802. s7PLCData.Add("a7OEEVehicleCode_right", ""); // 载具SN
  4803. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  4804. (int, string) result;
  4805. AtlasScrew atlasScrewLeft = new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort,
  4806. 3000, 3000, "Left");
  4807. atlasScrewLeft.Initial();
  4808. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort,
  4809. 3000, 3000, "Right");
  4810. atlasScrewRight.Initial();
  4811. while (true)
  4812. {
  4813. try
  4814. {
  4815. if (!GlobalContext._IsCon_Funs1)
  4816. {
  4817. UpdatePLCMonitor(1, plcNo, 0);
  4818. continue;
  4819. }
  4820. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4821. {
  4822. Stopwatch stopwatch1 = new Stopwatch();
  4823. Stopwatch stopwatch2 = new Stopwatch();
  4824. stopwatch1.Start();
  4825. stopwatch2.Start();
  4826. #region 一次性读取所有数据
  4827. // 一次性读取所有数据
  4828. result = FunsEip[plcNo]
  4829. .Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4830. if (result.Item1 != 0)
  4831. {
  4832. //richTextBox1.AppendText("\n" + strRet);
  4833. }
  4834. else
  4835. {
  4836. //richTextBox1.AppendText("\n" + "读取成功");
  4837. int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  4838. int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  4839. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  4840. ? XiaomiDeviceState.Unknown
  4841. : (XiaomiDeviceState)xmDeviceStateInt_L;
  4842. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  4843. ? XiaomiDeviceState.Unknown
  4844. : (XiaomiDeviceState)xmDeviceStateInt_R;
  4845. s7PLCData["a7OEEPartNo"] =stPLC_MesData.Left.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  4846. s7PLCData["a7OEEVehicleCode"] = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode; // 载具SN
  4847. s7PLCData["a7OEEType"] = stPLC_MesData.Left.iotData.BeatAction; // 节拍
  4848. s7PLCData["a7OEEVehicleCode_right"] = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode; // 载具SN
  4849. s7PLCData["a7OEEType_right"] = stPLC_MesData.Right.iotData.BeatAction; // 节拍
  4850. }
  4851. #endregion 一次性读取所有数据
  4852. stopwatch2.Stop();
  4853. #region 左边进站
  4854. try
  4855. {
  4856. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4857. {
  4858. lock (lockObj)
  4859. {
  4860. if (!ProgressState)
  4861. {
  4862. ProgressState = true;
  4863. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left,
  4864. tagBaseName + ".Left." + tagMesCommName,
  4865. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState,
  4866. atlasScrewLeft));
  4867. }
  4868. }
  4869. }
  4870. }
  4871. catch (Exception ex)
  4872. {
  4873. ProgressState = false;
  4874. string str = ex.StackTrace;
  4875. AddMessage_Station(stationNameStr, LogType.Error,
  4876. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4877. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4878. }
  4879. #endregion 左边进站
  4880. #region 左边出站
  4881. try
  4882. {
  4883. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4884. {
  4885. lock (lockObj)
  4886. {
  4887. if (!ProgressState)
  4888. {
  4889. ProgressState = true;
  4890. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left,
  4891. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  4892. out ProgressState));
  4893. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  4894. }
  4895. }
  4896. }
  4897. }
  4898. catch (Exception ex)
  4899. {
  4900. ProgressState = false;
  4901. string str = ex.StackTrace;
  4902. AddMessage_Station(stationNameStr, LogType.Error,
  4903. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4904. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4905. }
  4906. #endregion 左边出站
  4907. #region 右边进站
  4908. try
  4909. {
  4910. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4911. {
  4912. lock (lockObj)
  4913. {
  4914. if (!ProgressState)
  4915. {
  4916. ProgressState = true;
  4917. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right,
  4918. tagBaseName + ".Right." + tagMesCommName,
  4919. tagBaseName + ".Right" + tagBarsetName, "Right", out ProgressState,
  4920. atlasScrewRight));
  4921. }
  4922. }
  4923. }
  4924. }
  4925. catch (Exception ex)
  4926. {
  4927. ProgressState = false;
  4928. string str = ex.StackTrace;
  4929. AddMessage_Station(stationNameStr, LogType.Error,
  4930. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4931. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4932. }
  4933. #endregion 右边进站
  4934. #region 右边出站
  4935. try
  4936. {
  4937. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4938. {
  4939. lock (lockObj)
  4940. {
  4941. if (!ProgressState)
  4942. {
  4943. ProgressState = true;
  4944. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right,
  4945. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  4946. out ProgressState));
  4947. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  4948. }
  4949. }
  4950. }
  4951. }
  4952. catch (Exception ex)
  4953. {
  4954. ProgressState = false;
  4955. string str = ex.StackTrace;
  4956. AddMessage_Station(stationNameStr, LogType.Error,
  4957. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4958. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4959. }
  4960. #endregion 右边出站
  4961. #region 节拍接口
  4962. try
  4963. {
  4964. #region 左工位 节拍
  4965. int a70EEType_left = (int)s7PLCData["a70EEType_left"];
  4966. int a70EETypeGOld_left = (int)s7PLCSignal_Old["a70EEType_left"];
  4967. //若设备紧急复原后节拍重置
  4968. if (a70EEType_left == 1)
  4969. {
  4970. a70EETypeGOld_left = 0;
  4971. }
  4972. if (a70EEType_left != a70EETypeGOld_left)
  4973. {
  4974. stationNameStr = stationNameStr + "_Left";
  4975. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  4976. if ((a70EETypeGOld_left == 1 && a70EEType_left != 2) || (a70EETypeGOld_left == 3 && a70EEType_left != 4) ||
  4977. (a70EETypeGOld_left == 5 && a70EEType_left != 6))
  4978. {
  4979. //写入PLC
  4980. stPLC_MesData.Left.iotData.beatReturn = 2; //NG
  4981. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName, 1, stPLC_MesData.Left.iotData);
  4982. AddMessage(LogType.Info,
  4983. stationNameStr +
  4984. $"_节拍接口-- 设备本次上传节拍[{a70EEType_left}],未上传节拍[{a70EETypeGOld_left}]的结束信号,请检查;总用时" +
  4985. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  4986. "ms");
  4987. return;
  4988. }
  4989. else
  4990. {
  4991. Task.Run(() =>
  4992. S3节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName,
  4993. stPLC_MesData.Left.iotData)); // MreTasks[4].Set();
  4994. }
  4995. s7PLCSignal_Old["a70EEType_left"] = s7PLCData["a70EEType_left"];
  4996. }
  4997. #endregion 左工位 节拍
  4998. #region 右工位 节拍
  4999. int a70EEType_right = (int)s7PLCData["a70EEType_right"];
  5000. int a70EETypeGOld_right = (int)s7PLCSignal_Old["a70EEType_right"];
  5001. //若设备紧急复原后节拍重置
  5002. if (a70EEType_right == 1)
  5003. {
  5004. a70EETypeGOld_right = 0;
  5005. }
  5006. if (a70EEType_right != a70EETypeGOld_right)
  5007. {
  5008. stationNameStr = stationNameStr + "_Right";
  5009. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  5010. if ((a70EETypeGOld_right == 1 && a70EEType_right != 2) || (a70EETypeGOld_right == 3 && a70EEType_right != 4) ||
  5011. (a70EETypeGOld_right == 5 && a70EEType_right != 6))
  5012. {
  5013. //写入PLC
  5014. stPLC_MesData.Right.iotData.beatReturn = 2; //NG
  5015. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName, 1, stPLC_MesData.Left.iotData);
  5016. AddMessage(LogType.Info,
  5017. stationNameStr +
  5018. $"_节拍接口-- 设备本次上传节拍[{a70EEType_right}],未上传节拍[{a70EETypeGOld_right}]的结束信号,请检查;总用时" +
  5019. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  5020. "ms");
  5021. return;
  5022. }
  5023. else
  5024. {
  5025. Task.Run(() =>
  5026. S3节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName,
  5027. stPLC_MesData.Left.iotData)); // MreTasks[4].Set();
  5028. }
  5029. s7PLCSignal_Old["a70EEType_right"] = s7PLCData["a70EEType_right"];
  5030. }
  5031. #endregion 右工位 节拍
  5032. }
  5033. catch (Exception ex)
  5034. {
  5035. string str = ex.StackTrace;
  5036. AddMessage_Station(stationNameStr, LogType.Error,
  5037. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  5038. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5039. }
  5040. #endregion
  5041. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5042. stopwatch1.Stop();
  5043. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5044. }
  5045. else
  5046. {
  5047. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5048. AddMessage_Station(stationNameStr, LogType.Info,
  5049. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5050. FunsEip[plcNo].Connect(); // 重连
  5051. }
  5052. }
  5053. catch (Exception ex)
  5054. {
  5055. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5056. AddMessage_Station(stationNameStr, LogType.Error,
  5057. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5058. }
  5059. Thread.Sleep(IntervalReadPLC);
  5060. }
  5061. }
  5062. /// <summary>
  5063. /// [S7] 锁螺丝设备 - 进站
  5064. /// </summary>
  5065. /// <param name="plcNo">PLC编号</param>
  5066. /// <param name="stationNameStr">工站全称</param>
  5067. /// <param name="stPLC_MesData"></param>
  5068. /// <param name="tagMesCommName"></param>
  5069. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  5070. string tagBarsetName, string direction, out bool ProgressState, AtlasScrew atlasScrew)
  5071. {
  5072. Stopwatch stopwatch1 = new Stopwatch();
  5073. Stopwatch stopwatch2 = new Stopwatch();
  5074. string atlasSn = string.Empty;
  5075. try
  5076. {
  5077. stopwatch1.Start();
  5078. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  5079. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5080. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  5081. string StationId = string.Empty; // 工位ID(可配置)
  5082. if (direction == "Left")
  5083. {
  5084. StationId = GlobalContext.S7_StationId_1;
  5085. }
  5086. if (direction == "Right")
  5087. {
  5088. StationId = GlobalContext.S7_StationId_2;
  5089. }
  5090. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  5091. //载具码验证产品码
  5092. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  5093. if (string.IsNullOrEmpty(strProductBarcode))
  5094. {
  5095. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  5096. }
  5097. sn = strProductBarcode;
  5098. atlasSn = strProductBarcode;
  5099. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5100. if (direction == "Left")
  5101. {
  5102. isCollectingFlagLeft = false; //采集螺丝数据结束
  5103. }
  5104. if (direction == "Right")
  5105. {
  5106. isCollectingFlagRight = false; //采集螺丝数据结束
  5107. }
  5108. // 产品SN(物料码)校验
  5109. List<TestItem> item = new List<TestItem>();
  5110. stopwatch2.Start();
  5111. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  5112. item, MachineId, StationId);
  5113. stopwatch2.Stop();
  5114. //指令执行结果 1:OK 110:失败
  5115. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5116. //进站结果写入PLC
  5117. CommandFromPLC resultToPlC = new CommandFromPLC();
  5118. resultToPlC.cmd = 0;
  5119. resultToPlC.cmdParam = 0; //指令参数
  5120. resultToPlC.cmdResult = mesResultFrmWeb;
  5121. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5122. }
  5123. catch (Exception ex)
  5124. {
  5125. string str = ex.StackTrace;
  5126. AddMessage(LogType.Error,
  5127. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  5128. str.Length - str.LastIndexOf("\\") - 1));
  5129. CommandFromPLC resultToPlC = new CommandFromPLC();
  5130. resultToPlC.cmd = 0;
  5131. resultToPlC.cmdParam = 0; //指令参数
  5132. resultToPlC.cmdResult = 110;
  5133. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5134. }
  5135. stopwatch1.Stop();
  5136. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  5137. AddMessage(LogType.Info,
  5138. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5139. stopwatch2.ElapsedMilliseconds + "ms");
  5140. ProgressState = false;
  5141. //开始采集螺丝数据
  5142. if (direction == "Left")
  5143. {
  5144. isCollectingFlagLeft = true;
  5145. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  5146. }
  5147. if (direction == "Right")
  5148. {
  5149. isCollectingFlagRight = true;
  5150. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  5151. }
  5152. }
  5153. /// <summary>
  5154. /// [S7] 锁螺丝设备 - 出站
  5155. /// </summary>
  5156. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  5157. string stationCode, string stationName, string direction, out bool ProgressState)
  5158. {
  5159. Stopwatch stopwatch1 = new Stopwatch();
  5160. Stopwatch stopwatch2 = new Stopwatch();
  5161. try
  5162. {
  5163. stopwatch1.Start();
  5164. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  5165. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5166. string processItem = stationName; // 测试项目
  5167. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5168. string supplierCode = ""; // 供应商代码
  5169. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5170. string batch_num = GlobalContext.BatchNumber; // 批次号
  5171. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5172. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5173. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5174. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  5175. string StationId = string.Empty; // 工位ID(可配置)
  5176. if (direction == "Left")
  5177. {
  5178. StationId = GlobalContext.S7_StationId_1;
  5179. }
  5180. if (direction == "Right")
  5181. {
  5182. StationId = GlobalContext.S7_StationId_2;
  5183. }
  5184. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5185. a1Result = 1;
  5186. bool pass = a1Result == 1;
  5187. //根据载具码获取产品码
  5188. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5189. if (string.IsNullOrEmpty(strProductBarcode))
  5190. {
  5191. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  5192. }
  5193. sn = strProductBarcode;
  5194. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  5195. List<TestItem> items = new List<TestItem>();
  5196. items.Add(new TestItem()
  5197. {
  5198. Parameter_name = "载具码",
  5199. Parameter_value = CarrierBarcode,
  5200. Parameter_unit = ""
  5201. });
  5202. items.Add(new TestItem()
  5203. {
  5204. Parameter_name = "产品码",
  5205. Parameter_value = sn,
  5206. Parameter_unit = ""
  5207. });
  5208. int result1 = 1;
  5209. //if (direction == "Right")
  5210. //{
  5211. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  5212. SwitctProcessData(stationNameStr, items, equipmentCode, processItem , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode
  5213. , sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  5214. //}
  5215. //if (direction == "Left")
  5216. //{
  5217. // isCollectingFlagLeft = false;//采集螺丝数据结束
  5218. //}
  5219. //if (direction == "Right")
  5220. //{
  5221. // isCollectingFlagRight = false;//采集螺丝数据结束
  5222. //}
  5223. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5224. stopwatch2.Start();
  5225. //进站结果写入PLC
  5226. CommandFromPLC resultToPlC = new CommandFromPLC();
  5227. resultToPlC.cmd = 0;
  5228. resultToPlC.cmdParam = 0; //指令参数
  5229. resultToPlC.cmdResult = mesResultFrmWeb;
  5230. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5231. stopwatch2.Stop();
  5232. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  5233. //保存PLC返回MES数据到本地
  5234. ResponseMessage message = new ResponseMessage();
  5235. if (direction == "Left")
  5236. {
  5237. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  5238. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  5239. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  5240. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  5241. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  5242. if (message.result == false)
  5243. {
  5244. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  5245. }
  5246. }
  5247. if (direction == "Right")
  5248. {
  5249. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  5250. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  5251. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  5252. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  5253. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  5254. if (message.result == false)
  5255. {
  5256. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  5257. }
  5258. }
  5259. //保存螺丝数据到txt
  5260. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes,
  5261. stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  5262. if (result.Item1 != 0)
  5263. {
  5264. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  5265. }
  5266. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_保存加工数据到本地成功");
  5267. }
  5268. catch (Exception ex)
  5269. {
  5270. stopwatch2.Start();
  5271. CommandFromPLC resultToPlC = new CommandFromPLC();
  5272. resultToPlC.cmd = 0;
  5273. resultToPlC.cmdParam = 0; //指令参数
  5274. resultToPlC.cmdResult = 110;
  5275. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5276. stopwatch2.Stop();
  5277. string str = ex.StackTrace;
  5278. AddMessage(LogType.Error,
  5279. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5280. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5281. }
  5282. stopwatch1.Stop();
  5283. AddMessage(LogType.Info,
  5284. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5285. stopwatch2.ElapsedMilliseconds + "ms");
  5286. ProgressState = false;
  5287. }
  5288. private void S7节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  5289. {
  5290. Stopwatch stopwatch1 = new Stopwatch();
  5291. Stopwatch stopwatch2 = new Stopwatch();
  5292. string resultStr = string.Empty;
  5293. try
  5294. {
  5295. stopwatch1.Start();
  5296. string oEEType = ((int)s1PLCData["a7OEEType"]).ToString(); // 节拍类型(plc写入)
  5297. string a7OEEPartNo = (string)s1PLCData["a7OEEPartNo"]; // 物料码
  5298. a7OEEPartNo = a7OEEPartNo.Replace("\0", "");
  5299. string a7OEEVehicleCode = (string)s1PLCData["a7OEEVehicleCode"]; // 载具SN
  5300. a7OEEVehicleCode = a7OEEVehicleCode.Replace("\0", "");
  5301. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5302. if (!actionBool)
  5303. {
  5304. stopwatch2.Start();
  5305. //写入PLC
  5306. iot_data.beatReturn = 2; //NG
  5307. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5308. stopwatch2.Stop();
  5309. AddMessage(LogType.Info,
  5310. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  5311. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5312. return;
  5313. }
  5314. //作业开始后要有物料和载具信息
  5315. if (string.IsNullOrEmpty(a7OEEPartNo) && string.IsNullOrEmpty(a7OEEVehicleCode) &&
  5316. Convert.ToInt32(oEEType) > 2)
  5317. {
  5318. stopwatch2.Start();
  5319. //写入PLC
  5320. iot_data.beatReturn = 2; //NG
  5321. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5322. stopwatch2.Stop();
  5323. AddMessage_Station(stationNameStr, LogType.Info,
  5324. stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  5325. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5326. return;
  5327. }
  5328. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a7OEEPartNo))
  5329. {
  5330. stopwatch2.Start();
  5331. //写入PLC
  5332. iot_data.beatReturn = 2; //NG
  5333. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5334. stopwatch2.Stop();
  5335. AddMessage_Station(stationNameStr, LogType.Info,
  5336. stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  5337. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5338. return;
  5339. }
  5340. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a7OEEVehicleCode))
  5341. {
  5342. stopwatch2.Start();
  5343. //写入PLC
  5344. iot_data.beatReturn = 2; //NG
  5345. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5346. stopwatch2.Stop();
  5347. AddMessage_Station(stationNameStr, LogType.Info,
  5348. stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  5349. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5350. return;
  5351. }
  5352. short _result = 0;
  5353. // 上传OEE
  5354. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a7OEEPartNo, a7OEEVehicleCode);
  5355. _result = result.Item1;
  5356. resultStr = result.Item2;
  5357. if (_result == 1)
  5358. {
  5359. stopwatch2.Start();
  5360. //写入PLC
  5361. iot_data.beatReturn = 1; //OK
  5362. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5363. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  5364. stopwatch2.Stop();
  5365. }
  5366. else
  5367. {
  5368. stopwatch2.Start();
  5369. //写入PLC
  5370. iot_data.beatReturn = 2; //NG
  5371. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5372. stopwatch2.Stop();
  5373. AddMessage_Station(stationNameStr, LogType.Error,
  5374. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  5375. }
  5376. }
  5377. catch (Exception ex)
  5378. {
  5379. string str = ex.StackTrace;
  5380. AddMessage_Station(stationNameStr, LogType.Error,
  5381. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  5382. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5383. // MES_Flag
  5384. stopwatch2.Start();
  5385. //写入PLC
  5386. iot_data.beatReturn = 2; //NG
  5387. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5388. stopwatch2.Stop();
  5389. }
  5390. stopwatch1.Stop();
  5391. AddMessage(LogType.Info,
  5392. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5393. stopwatch2.ElapsedMilliseconds + "ms");
  5394. }
  5395. #endregion
  5396. #region S8
  5397. private Dictionary<string, object> s8PLCData = new Dictionary<string, object>();
  5398. private Dictionary<string, object> s8PLCSignal_Old = new Dictionary<string, object>();
  5399. /// <summary>
  5400. /// [S8] 3D螺丝高度检测设备
  5401. /// </summary>
  5402. /// <param name="plcNo">PLC编号</param>
  5403. private void ReadStation_S8(int plcNo)
  5404. {
  5405. string stationCode = "[OP80]";
  5406. string stationName = "NG下料";
  5407. string stationNameStr = stationCode + stationName;
  5408. string tagBaseName = "g_OP80_MES"; //标签变量名称
  5409. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5410. string tagAgvCommName = "agvCommFrmPC";
  5411. string tagBarsetName = "BarcodeSet";
  5412. // 触发信号字典
  5413. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5414. s8PLCSignal_Old.Add("a8OEEType", 0); // 节拍类型(plc写入)
  5415. // PLC数据字典 赋值
  5416. s8PLCData.Add("a8OEEType", 0); // 节拍类型(plc写入)
  5417. s8PLCData.Add("a8OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  5418. s8PLCData.Add("a8OEEVehicleCode", ""); // 载具SN
  5419. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  5420. (int, string) result;
  5421. while (true)
  5422. {
  5423. try
  5424. {
  5425. if (!GlobalContext._IsCon_Funs1)
  5426. {
  5427. UpdatePLCMonitor(1, plcNo, 0);
  5428. continue;
  5429. }
  5430. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5431. {
  5432. Stopwatch stopwatch1 = new Stopwatch();
  5433. Stopwatch stopwatch2 = new Stopwatch();
  5434. stopwatch1.Start();
  5435. stopwatch2.Start();
  5436. #region 一次性读取所有数据
  5437. // 一次性读取所有数据
  5438. result = FunsEip[plcNo]
  5439. .Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  5440. if (result.Item1 != 0)
  5441. {
  5442. //richTextBox1.AppendText("\n" + strRet);
  5443. }
  5444. else
  5445. {
  5446. //richTextBox1.AppendText("\n" + "读取成功");
  5447. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  5448. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  5449. ? XiaomiDeviceState.Unknown
  5450. : (XiaomiDeviceState)xmDeviceStateInt;
  5451. s8PLCData["a8OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  5452. s8PLCData["a8OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  5453. s8PLCData["a8OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  5454. }
  5455. #endregion 一次性读取所有数据
  5456. stopwatch2.Stop();
  5457. #region 进站
  5458. try
  5459. {
  5460. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5461. {
  5462. lock (lockObj)
  5463. {
  5464. if (!ProgressState)
  5465. {
  5466. ProgressState = true;
  5467. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData,
  5468. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  5469. out ProgressState));
  5470. }
  5471. }
  5472. }
  5473. }
  5474. catch (Exception ex)
  5475. {
  5476. ProgressState = false;
  5477. string str = ex.StackTrace;
  5478. AddMessage_Station(stationNameStr, LogType.Error,
  5479. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5480. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5481. }
  5482. #endregion 进站
  5483. #region 出站
  5484. try
  5485. {
  5486. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5487. {
  5488. lock (lockObj)
  5489. {
  5490. if (!ProgressState)
  5491. {
  5492. ProgressState = true;
  5493. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData,
  5494. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  5495. out ProgressState));
  5496. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  5497. }
  5498. }
  5499. }
  5500. }
  5501. catch (Exception ex)
  5502. {
  5503. ProgressState = false;
  5504. string str = ex.StackTrace;
  5505. AddMessage_Station(stationNameStr, LogType.Error,
  5506. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5507. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5508. }
  5509. #endregion 出站
  5510. #region 节拍接口
  5511. try
  5512. {
  5513. int a80EEType = (int)s9PLCData["a80EEType"];
  5514. int a80EETypeGOld = (int)s9PLCSignal_Old["a80EEType"];
  5515. //若设备紧急复原后节拍重置
  5516. if (a80EEType == 1)
  5517. {
  5518. a80EETypeGOld = 0;
  5519. }
  5520. if (a80EEType != a80EETypeGOld)
  5521. {
  5522. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  5523. if ((a80EETypeGOld == 1 && a80EEType != 2) || (a80EETypeGOld == 3 && a80EEType != 4) ||
  5524. (a80EETypeGOld == 5 && a80EEType != 6))
  5525. {
  5526. //写入PLC
  5527. stPLC_MesData.iotData.beatReturn = 2; //NG
  5528. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  5529. AddMessage(LogType.Info,
  5530. stationNameStr +
  5531. $"_节拍接口-- 设备本次上传节拍[{a80EEType}],未上传节拍[{a80EETypeGOld}]的结束信号,请检查;总用时" +
  5532. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  5533. "ms");
  5534. return;
  5535. }
  5536. else
  5537. {
  5538. Task.Run(() =>
  5539. S8节拍接口(plcNo, stationNameStr, tagBaseName,
  5540. stPLC_MesData.iotData)); // MreTasks[4].Set();
  5541. }
  5542. s8PLCSignal_Old["a80EEType"] = s8PLCData["a80EEType"];
  5543. }
  5544. }
  5545. catch (Exception ex)
  5546. {
  5547. string str = ex.StackTrace;
  5548. AddMessage_Station(stationNameStr, LogType.Error,
  5549. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  5550. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5551. }
  5552. #endregion
  5553. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5554. stopwatch1.Stop();
  5555. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5556. }
  5557. else
  5558. {
  5559. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5560. AddMessage_Station(stationNameStr, LogType.Info,
  5561. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5562. FunsEip[plcNo].Connect(); // 重连
  5563. }
  5564. }
  5565. catch (Exception ex)
  5566. {
  5567. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5568. AddMessage_Station(stationNameStr, LogType.Error,
  5569. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5570. }
  5571. Thread.Sleep(IntervalReadPLC);
  5572. }
  5573. }
  5574. /// <summary>
  5575. /// [S8] 3D螺丝高度检测设备 - 进站
  5576. /// </summary>
  5577. /// <param name="plcNo">PLC编号</param>
  5578. /// <param name="stationNameStr">工站全称</param>
  5579. /// <param name="stPLC_MesData"></param>
  5580. /// <param name="tagMesCommName"></param>
  5581. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  5582. string tagBarsetName, out bool ProgressState)
  5583. {
  5584. Stopwatch stopwatch1 = new Stopwatch();
  5585. Stopwatch stopwatch2 = new Stopwatch();
  5586. try
  5587. {
  5588. stopwatch1.Start();
  5589. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  5590. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5591. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  5592. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  5593. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  5594. //载具码验证产品码
  5595. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  5596. if (string.IsNullOrEmpty(strProductBarcode))
  5597. {
  5598. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  5599. }
  5600. sn = strProductBarcode;
  5601. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5602. // 产品SN(物料码)校验
  5603. List<TestItem> item = new List<TestItem>();
  5604. stopwatch2.Start();
  5605. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  5606. item, MachineId, StationId);
  5607. stopwatch2.Stop();
  5608. //指令执行结果 1:OK 110:失败
  5609. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5610. //进站结果写入PLC
  5611. CommandFromPLC resultToPlC = new CommandFromPLC();
  5612. resultToPlC.cmd = 0;
  5613. resultToPlC.cmdParam = 0; //指令参数
  5614. resultToPlC.cmdResult = mesResultFrmWeb;
  5615. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5616. }
  5617. catch (Exception ex)
  5618. {
  5619. string str = ex.StackTrace;
  5620. AddMessage(LogType.Error,
  5621. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  5622. str.Length - str.LastIndexOf("\\") - 1));
  5623. CommandFromPLC resultToPlC = new CommandFromPLC();
  5624. resultToPlC.cmd = 0;
  5625. resultToPlC.cmdParam = 0; //指令参数
  5626. resultToPlC.cmdResult = 110;
  5627. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5628. }
  5629. stopwatch1.Stop();
  5630. AddMessage(LogType.Info,
  5631. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5632. stopwatch2.ElapsedMilliseconds + "ms");
  5633. ProgressState = false;
  5634. }
  5635. /// <summary>
  5636. /// [S8] 3D螺丝高度检测设备 - 出站接口
  5637. /// </summary>
  5638. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  5639. string stationCode, string stationName, out bool ProgressState)
  5640. {
  5641. Stopwatch stopwatch1 = new Stopwatch();
  5642. Stopwatch stopwatch2 = new Stopwatch();
  5643. try
  5644. {
  5645. stopwatch1.Start();
  5646. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  5647. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5648. string processItem = stationName; // 测试项目
  5649. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5650. string supplierCode = ""; // 供应商代码
  5651. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5652. string batch_num = GlobalContext.BatchNumber; // 批次号
  5653. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5654. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5655. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5656. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  5657. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  5658. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5659. bool pass = a1Result == 1;
  5660. //根据载具码获取产品码
  5661. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5662. if (string.IsNullOrEmpty(strProductBarcode))
  5663. {
  5664. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  5665. }
  5666. sn = strProductBarcode;
  5667. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  5668. List<TestItem> items = new List<TestItem>();
  5669. items.Add(new TestItem()
  5670. {
  5671. Parameter_name = "载具码",
  5672. Parameter_value = CarrierBarcode,
  5673. Parameter_unit = ""
  5674. });
  5675. items.Add(new TestItem()
  5676. {
  5677. Parameter_name = "产品码",
  5678. Parameter_value = sn,
  5679. Parameter_unit = ""
  5680. });
  5681. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  5682. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  5683. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  5684. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5685. stopwatch2.Start();
  5686. //进站结果写入PLC
  5687. CommandFromPLC resultToPlC = new CommandFromPLC();
  5688. resultToPlC.cmd = 0;
  5689. resultToPlC.cmdParam = 0; //指令参数
  5690. resultToPlC.cmdResult = mesResultFrmWeb;
  5691. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5692. stopwatch2.Stop();
  5693. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  5694. //保存PLC返回MES数据到本地
  5695. ResponseMessage message = new ResponseMessage();
  5696. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  5697. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  5698. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  5699. if (message.result == false)
  5700. {
  5701. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  5702. }
  5703. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  5704. }
  5705. catch (Exception ex)
  5706. {
  5707. stopwatch2.Start();
  5708. CommandFromPLC resultToPlC = new CommandFromPLC();
  5709. resultToPlC.cmd = 0;
  5710. resultToPlC.cmdParam = 0; //指令参数
  5711. resultToPlC.cmdResult = 110;
  5712. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5713. stopwatch2.Stop();
  5714. string str = ex.StackTrace;
  5715. AddMessage(LogType.Error,
  5716. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5717. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5718. }
  5719. stopwatch1.Stop();
  5720. AddMessage(LogType.Info,
  5721. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5722. stopwatch2.ElapsedMilliseconds + "ms");
  5723. ProgressState = false;
  5724. }
  5725. private void S8节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  5726. {
  5727. Stopwatch stopwatch1 = new Stopwatch();
  5728. Stopwatch stopwatch2 = new Stopwatch();
  5729. string resultStr = string.Empty;
  5730. try
  5731. {
  5732. stopwatch1.Start();
  5733. string oEEType = ((int)s1PLCData["a8OEEType"]).ToString(); // 节拍类型(plc写入)
  5734. string a80EEPartNo = (string)s1PLCData["a80EEPartNo"]; // 物料码
  5735. a80EEPartNo = a80EEPartNo.Replace("\0", "");
  5736. string a80EEVehicleCode = (string)s1PLCData["a80EEVehicleCode"]; // 载具SN
  5737. a80EEVehicleCode = a80EEVehicleCode.Replace("\0", "");
  5738. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5739. if (!actionBool)
  5740. {
  5741. stopwatch2.Start();
  5742. //写入PLC
  5743. iot_data.beatReturn = 2; //NG
  5744. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5745. stopwatch2.Stop();
  5746. AddMessage(LogType.Info,
  5747. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  5748. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5749. return;
  5750. }
  5751. //作业开始后要有物料和载具信息
  5752. if (string.IsNullOrEmpty(a80EEPartNo) && string.IsNullOrEmpty(a80EEVehicleCode) &&
  5753. Convert.ToInt32(oEEType) > 2)
  5754. {
  5755. stopwatch2.Start();
  5756. //写入PLC
  5757. iot_data.beatReturn = 2; //NG
  5758. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5759. stopwatch2.Stop();
  5760. AddMessage_Station(stationNameStr, LogType.Info,
  5761. stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  5762. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5763. return;
  5764. }
  5765. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a80EEPartNo))
  5766. {
  5767. stopwatch2.Start();
  5768. //写入PLC
  5769. iot_data.beatReturn = 2; //NG
  5770. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5771. stopwatch2.Stop();
  5772. AddMessage_Station(stationNameStr, LogType.Info,
  5773. stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  5774. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5775. return;
  5776. }
  5777. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a80EEVehicleCode))
  5778. {
  5779. stopwatch2.Start();
  5780. //写入PLC
  5781. iot_data.beatReturn = 2; //NG
  5782. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5783. stopwatch2.Stop();
  5784. AddMessage_Station(stationNameStr, LogType.Info,
  5785. stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  5786. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5787. return;
  5788. }
  5789. short _result = 0;
  5790. // 上传OEE
  5791. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a80EEPartNo, a80EEVehicleCode);
  5792. _result = result.Item1;
  5793. resultStr = result.Item2;
  5794. if (_result == 1)
  5795. {
  5796. stopwatch2.Start();
  5797. //写入PLC
  5798. iot_data.beatReturn = 1; //OK
  5799. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5800. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  5801. stopwatch2.Stop();
  5802. }
  5803. else
  5804. {
  5805. stopwatch2.Start();
  5806. //写入PLC
  5807. iot_data.beatReturn = 2; //NG
  5808. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5809. stopwatch2.Stop();
  5810. AddMessage_Station(stationNameStr, LogType.Error,
  5811. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  5812. }
  5813. }
  5814. catch (Exception ex)
  5815. {
  5816. string str = ex.StackTrace;
  5817. AddMessage_Station(stationNameStr, LogType.Error,
  5818. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  5819. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5820. // MES_Flag
  5821. stopwatch2.Start();
  5822. //写入PLC
  5823. iot_data.beatReturn = 2; //NG
  5824. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  5825. stopwatch2.Stop();
  5826. }
  5827. stopwatch1.Stop();
  5828. AddMessage(LogType.Info,
  5829. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5830. stopwatch2.ElapsedMilliseconds + "ms");
  5831. }
  5832. #endregion
  5833. #region S9
  5834. private Dictionary<string, object> s9PLCData = new Dictionary<string, object>();
  5835. private Dictionary<string, object> s9PLCSignal_Old = new Dictionary<string, object>();
  5836. /// <summary>
  5837. /// [S9] 下料设备
  5838. /// </summary>
  5839. /// <param name="plcNo">PLC编号</param>
  5840. private void ReadStation_S9(int plcNo)
  5841. {
  5842. string stationCode = "[OP90]";
  5843. string stationName = "半成品下料";
  5844. string stationNameStr = stationCode + stationName;
  5845. string tagBaseName = "g_OP90_MES"; //标签变量名称
  5846. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5847. string tagAgvCommName = "agvCommFrmPC";
  5848. string tagBarsetName = "BarcodeSet";
  5849. // 触发信号字典
  5850. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5851. s9PLCSignal_Old.Add("a9OEEType", 0); // 节拍类型(plc写入)
  5852. // PLC数据字典 赋值
  5853. s9PLCData.Add("a9OEEType", 0); // 节拍类型(plc写入)
  5854. s9PLCData.Add("a9OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  5855. s9PLCData.Add("a9OEEVehicleCode", ""); // 载具SN
  5856. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  5857. (int, string) result;
  5858. while (true)
  5859. {
  5860. try
  5861. {
  5862. if (!GlobalContext._IsCon_Funs1)
  5863. {
  5864. UpdatePLCMonitor(1, plcNo, 0);
  5865. continue;
  5866. }
  5867. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5868. {
  5869. Stopwatch stopwatch1 = new Stopwatch();
  5870. Stopwatch stopwatch2 = new Stopwatch();
  5871. stopwatch1.Start();
  5872. stopwatch2.Start();
  5873. #region 一次性读取所有数据
  5874. // 一次性读取所有数据
  5875. result = FunsEip[plcNo]
  5876. .Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  5877. if (result.Item1 != 0)
  5878. {
  5879. //richTextBox1.AppendText("\n" + strRet);
  5880. }
  5881. else
  5882. {
  5883. //richTextBox1.AppendText("\n" + "读取成功");
  5884. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  5885. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  5886. ? XiaomiDeviceState.Unknown
  5887. : (XiaomiDeviceState)xmDeviceStateInt;
  5888. s9PLCData["a9OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  5889. s9PLCData["a9OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  5890. s9PLCData["a9OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
  5891. }
  5892. #endregion 一次性读取所有数据
  5893. stopwatch2.Stop();
  5894. #region 进站
  5895. try
  5896. {
  5897. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5898. {
  5899. lock (lockObj)
  5900. {
  5901. if (!ProgressState)
  5902. {
  5903. ProgressState = true;
  5904. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData,
  5905. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  5906. out ProgressState));
  5907. }
  5908. }
  5909. }
  5910. }
  5911. catch (Exception ex)
  5912. {
  5913. ProgressState = false;
  5914. string str = ex.StackTrace;
  5915. AddMessage_Station(stationNameStr, LogType.Error,
  5916. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5917. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5918. }
  5919. #endregion 进站
  5920. #region 出站
  5921. try
  5922. {
  5923. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5924. {
  5925. lock (lockObj)
  5926. {
  5927. if (!ProgressState)
  5928. {
  5929. ProgressState = true;
  5930. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData,
  5931. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  5932. out ProgressState));
  5933. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  5934. }
  5935. }
  5936. }
  5937. }
  5938. catch (Exception ex)
  5939. {
  5940. ProgressState = false;
  5941. string str = ex.StackTrace;
  5942. AddMessage_Station(stationNameStr, LogType.Error,
  5943. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5944. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5945. }
  5946. #endregion 出站
  5947. #region 节拍接口
  5948. try
  5949. {
  5950. int a90EEType = (int)s9PLCData["a90EEType"];
  5951. int a90EETypeGOld = (int)s9PLCSignal_Old["a90EEType"];
  5952. //若设备紧急复原后节拍重置
  5953. if (a90EEType == 1)
  5954. {
  5955. a90EETypeGOld = 0;
  5956. }
  5957. if (a90EEType != a90EETypeGOld)
  5958. {
  5959. //节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
  5960. if ((a90EETypeGOld == 1 && a90EEType != 2) || (a90EETypeGOld == 3 && a90EEType != 4) ||
  5961. (a90EETypeGOld == 5 && a90EEType != 6))
  5962. {
  5963. //写入PLC
  5964. stPLC_MesData.iotData.beatReturn = 2; //NG
  5965. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
  5966. AddMessage(LogType.Info,
  5967. stationNameStr +
  5968. $"_节拍接口-- 设备本次上传节拍[{a90EEType}],未上传节拍[{a90EETypeGOld}]的结束信号,请检查;总用时" +
  5969. stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
  5970. "ms");
  5971. return;
  5972. }
  5973. else
  5974. {
  5975. Task.Run(() =>
  5976. S9节拍接口(plcNo, stationNameStr, tagBaseName,
  5977. stPLC_MesData.iotData)); // MreTasks[4].Set();
  5978. }
  5979. s9PLCSignal_Old["a90EEType"] = s9PLCData["a90EEType"];
  5980. }
  5981. }
  5982. catch (Exception ex)
  5983. {
  5984. string str = ex.StackTrace;
  5985. AddMessage_Station(stationNameStr, LogType.Error,
  5986. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  5987. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5988. }
  5989. #endregion
  5990. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5991. stopwatch1.Stop();
  5992. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5993. }
  5994. else
  5995. {
  5996. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5997. AddMessage_Station(stationNameStr, LogType.Info,
  5998. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5999. FunsEip[plcNo].Connect(); // 重连
  6000. }
  6001. }
  6002. catch (Exception ex)
  6003. {
  6004. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6005. AddMessage_Station(stationNameStr, LogType.Error,
  6006. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6007. }
  6008. Thread.Sleep(IntervalReadPLC);
  6009. }
  6010. }
  6011. /// <summary>
  6012. /// [S9] 下料设备 - 进站
  6013. /// </summary>
  6014. /// <param name="plcNo">PLC编号</param>
  6015. /// <param name="stationNameStr">工站全称</param>
  6016. /// <param name="stPLC_MesData"></param>
  6017. /// <param name="tagMesCommName"></param>
  6018. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  6019. string tagBarsetName, out bool ProgressState)
  6020. {
  6021. Stopwatch stopwatch1 = new Stopwatch();
  6022. Stopwatch stopwatch2 = new Stopwatch();
  6023. try
  6024. {
  6025. stopwatch1.Start();
  6026. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  6027. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  6028. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  6029. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  6030. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  6031. //载具码验证产品码
  6032. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  6033. if (string.IsNullOrEmpty(strProductBarcode))
  6034. {
  6035. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  6036. }
  6037. sn = strProductBarcode;
  6038. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  6039. // 产品SN(物料码)校验
  6040. List<TestItem> item = new List<TestItem>();
  6041. stopwatch2.Start();
  6042. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  6043. item, MachineId, StationId);
  6044. stopwatch2.Stop();
  6045. //指令执行结果 1:OK 110:失败
  6046. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  6047. //进站结果写入PLC
  6048. CommandFromPLC resultToPlC = new CommandFromPLC();
  6049. resultToPlC.cmd = 0;
  6050. resultToPlC.cmdParam = 0; //指令参数
  6051. resultToPlC.cmdResult = mesResultFrmWeb;
  6052. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6053. }
  6054. catch (Exception ex)
  6055. {
  6056. string str = ex.StackTrace;
  6057. AddMessage(LogType.Error,
  6058. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  6059. str.Length - str.LastIndexOf("\\") - 1));
  6060. CommandFromPLC resultToPlC = new CommandFromPLC();
  6061. resultToPlC.cmd = 0;
  6062. resultToPlC.cmdParam = 0; //指令参数
  6063. resultToPlC.cmdResult = 110;
  6064. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6065. }
  6066. stopwatch1.Stop();
  6067. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  6068. AddMessage(LogType.Info,
  6069. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  6070. stopwatch2.ElapsedMilliseconds + "ms");
  6071. ProgressState = false;
  6072. }
  6073. /// <summary>
  6074. /// [S9] 下料设备 - 出站接口
  6075. /// </summary>
  6076. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  6077. string stationCode, string stationName, out bool ProgressState)
  6078. {
  6079. Stopwatch stopwatch1 = new Stopwatch();
  6080. Stopwatch stopwatch2 = new Stopwatch();
  6081. try
  6082. {
  6083. stopwatch1.Start();
  6084. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  6085. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6086. string processItem = stationName; // 测试项目
  6087. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6088. string supplierCode = ""; // 供应商代码
  6089. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6090. string batch_num = GlobalContext.BatchNumber; // 批次号
  6091. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6092. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  6093. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  6094. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  6095. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  6096. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6097. bool pass = a1Result == 1;
  6098. //根据载具码获取产品码
  6099. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  6100. if (string.IsNullOrEmpty(strProductBarcode))
  6101. {
  6102. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  6103. }
  6104. sn = strProductBarcode;
  6105. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  6106. List<TestItem> items = new List<TestItem>();
  6107. items.Add(new TestItem()
  6108. {
  6109. Parameter_name = "载具码",
  6110. Parameter_value = CarrierBarcode,
  6111. Parameter_unit = ""
  6112. });
  6113. items.Add(new TestItem()
  6114. {
  6115. Parameter_name = "产品码",
  6116. Parameter_value = sn,
  6117. Parameter_unit = ""
  6118. });
  6119. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  6120. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6121. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  6122. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  6123. stopwatch2.Start();
  6124. //进站结果写入PLC
  6125. CommandFromPLC resultToPlC = new CommandFromPLC();
  6126. resultToPlC.cmd = 0;
  6127. resultToPlC.cmdParam = 0; //指令参数
  6128. resultToPlC.cmdResult = mesResultFrmWeb;
  6129. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6130. stopwatch2.Stop();
  6131. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  6132. //保存PLC返回MES数据到本地
  6133. ResponseMessage message = new ResponseMessage();
  6134. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  6135. stPLC_MesData.mesData.nRemainCount);
  6136. if (message.result == false)
  6137. {
  6138. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  6139. }
  6140. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  6141. if (result1 == 1)
  6142. {
  6143. //载具码解除绑定
  6144. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  6145. if (message.result == false)
  6146. {
  6147. AddMessage(LogType.Error, message.text);
  6148. }
  6149. }
  6150. }
  6151. catch (Exception ex)
  6152. {
  6153. stopwatch2.Start();
  6154. CommandFromPLC resultToPlC = new CommandFromPLC();
  6155. resultToPlC.cmd = 0;
  6156. resultToPlC.cmdParam = 0; //指令参数
  6157. resultToPlC.cmdResult = 110;
  6158. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6159. stopwatch2.Stop();
  6160. string str = ex.StackTrace;
  6161. AddMessage(LogType.Error,
  6162. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  6163. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6164. }
  6165. stopwatch1.Stop();
  6166. AddMessage(LogType.Info,
  6167. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6168. stopwatch2.ElapsedMilliseconds + "ms");
  6169. ProgressState = false;
  6170. }
  6171. private void S9节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  6172. {
  6173. Stopwatch stopwatch1 = new Stopwatch();
  6174. Stopwatch stopwatch2 = new Stopwatch();
  6175. string resultStr = string.Empty;
  6176. try
  6177. {
  6178. stopwatch1.Start();
  6179. string oEEType = ((int)s1PLCData["a9OEEType"]).ToString(); // 节拍类型(plc写入)
  6180. string a90EEPartNo = (string)s1PLCData["a90EEPartNo"]; // 物料码
  6181. a90EEPartNo = a90EEPartNo.Replace("\0", "");
  6182. string a90EEVehicleCode = (string)s1PLCData["a90EEVehicleCode"]; // 载具SN
  6183. a90EEVehicleCode = a90EEVehicleCode.Replace("\0", "");
  6184. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6185. if (!actionBool)
  6186. {
  6187. stopwatch2.Start();
  6188. //写入PLC
  6189. iot_data.beatReturn = 2; //NG
  6190. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6191. stopwatch2.Stop();
  6192. AddMessage(LogType.Info,
  6193. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  6194. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6195. return;
  6196. }
  6197. //作业开始后要有物料和载具信息
  6198. if (string.IsNullOrEmpty(a90EEPartNo) && string.IsNullOrEmpty(a90EEVehicleCode) &&
  6199. Convert.ToInt32(oEEType) > 2)
  6200. {
  6201. stopwatch2.Start();
  6202. //写入PLC
  6203. iot_data.beatReturn = 2; //NG
  6204. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6205. stopwatch2.Stop();
  6206. AddMessage_Station(stationNameStr, LogType.Info,
  6207. stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  6208. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6209. return;
  6210. }
  6211. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a90EEPartNo))
  6212. {
  6213. stopwatch2.Start();
  6214. //写入PLC
  6215. iot_data.beatReturn = 2; //NG
  6216. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6217. stopwatch2.Stop();
  6218. AddMessage_Station(stationNameStr, LogType.Info,
  6219. stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  6220. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6221. return;
  6222. }
  6223. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a90EEVehicleCode))
  6224. {
  6225. stopwatch2.Start();
  6226. //写入PLC
  6227. iot_data.beatReturn = 2; //NG
  6228. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6229. stopwatch2.Stop();
  6230. AddMessage_Station(stationNameStr, LogType.Info,
  6231. stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  6232. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6233. return;
  6234. }
  6235. short _result = 0;
  6236. // 上传OEE
  6237. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a90EEPartNo, a90EEVehicleCode);
  6238. _result = result.Item1;
  6239. resultStr = result.Item2;
  6240. if (_result == 1)
  6241. {
  6242. stopwatch2.Start();
  6243. //写入PLC
  6244. iot_data.beatReturn = 1; //OK
  6245. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6246. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  6247. stopwatch2.Stop();
  6248. }
  6249. else
  6250. {
  6251. stopwatch2.Start();
  6252. //写入PLC
  6253. iot_data.beatReturn = 2; //NG
  6254. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6255. stopwatch2.Stop();
  6256. AddMessage_Station(stationNameStr, LogType.Error,
  6257. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  6258. }
  6259. }
  6260. catch (Exception ex)
  6261. {
  6262. string str = ex.StackTrace;
  6263. AddMessage_Station(stationNameStr, LogType.Error,
  6264. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  6265. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6266. // MES_Flag
  6267. stopwatch2.Start();
  6268. //写入PLC
  6269. iot_data.beatReturn = 2; //NG
  6270. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  6271. stopwatch2.Stop();
  6272. }
  6273. stopwatch1.Stop();
  6274. AddMessage(LogType.Info,
  6275. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6276. stopwatch2.ElapsedMilliseconds + "ms");
  6277. }
  6278. #endregion
  6279. #endregion Xiaomi
  6280. #region PLC1 张超凡
  6281. #region [S1] Tray盘上料装备(板测)
  6282. /// <summary>
  6283. /// S1工位的数据- 触发信号上次的值
  6284. /// </summary>
  6285. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  6286. /// <summary>
  6287. /// S1工位的数据(含触发信号)
  6288. /// </summary>
  6289. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  6290. /// <summary>
  6291. /// S1工位的数据- 回写点位
  6292. /// </summary>
  6293. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6294. ///// <summary>
  6295. ///// 触发信号
  6296. ///// </summary>
  6297. //private ManualResetEvent[] MreTasks;
  6298. /// <summary>
  6299. /// [S1] Tray盘上料装备(板测)
  6300. /// </summary>
  6301. /// <param name="plcNo">PLC编号</param>
  6302. //private void ReadStation_S1(int plcNo)
  6303. //{
  6304. // // [S1] Tray盘上料装备
  6305. // // [S2] FCT
  6306. // // [S3] 值板机
  6307. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6308. // // [S5] Tray盘下料装备
  6309. // string stationCode = "[S1]";
  6310. // string stationName = "Tray盘上料装备";
  6311. // string stationNameStr = stationCode + stationName;
  6312. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6313. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6314. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  6315. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  6316. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6317. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  6318. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6319. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  6320. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  6321. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  6322. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  6323. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6324. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  6325. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  6326. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  6327. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  6328. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  6329. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  6330. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6331. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  6332. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  6333. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  6334. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  6335. // s1PLCData.Add("a1Result", 0); // 产品结果
  6336. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  6337. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  6338. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  6339. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  6340. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  6341. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6342. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  6343. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  6344. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  6345. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  6346. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  6347. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  6348. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  6349. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  6350. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  6351. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  6352. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  6353. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6354. // while (IsRun)
  6355. // {
  6356. // try
  6357. // {
  6358. // if (!GlobalContext._IsCon_Funs1)
  6359. // {
  6360. // UpdatePLCMonitor(1, plcNo, 0);
  6361. // continue;
  6362. // }
  6363. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6364. // {
  6365. // Stopwatch stopwatch1 = new Stopwatch();
  6366. // Stopwatch stopwatch2 = new Stopwatch();
  6367. // stopwatch1.Start();
  6368. // stopwatch2.Start();
  6369. // #region 一次性读取所有数据
  6370. // // 一次性读取所有数据
  6371. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6372. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6373. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6374. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  6375. // int[] datas = data1.Concat(data2).ToArray();
  6376. // datas = datas.Concat(data3).ToArray();
  6377. // datas = datas.Concat(data4).ToArray();
  6378. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  6379. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  6380. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  6381. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  6382. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  6383. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  6384. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  6385. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  6386. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  6387. // s1PLCData["a1MES_FLAG"] = datas[109];
  6388. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  6389. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  6390. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  6391. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  6392. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  6393. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  6394. // s1PLCData["a1Result"] = datas[170];
  6395. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  6396. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  6397. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  6398. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  6399. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  6400. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  6401. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  6402. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  6403. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  6404. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  6405. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  6406. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  6407. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  6408. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  6409. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  6410. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  6411. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  6412. // s1PLCData["a1AGVUpStart"] = datas[308];
  6413. // s1PLCData["a1AGVUpEnd"] = datas[309];
  6414. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  6415. // s1PLCData["a1AGVDownStart"] = datas[321];
  6416. // s1PLCData["a1AGVDownEnd"] = datas[322];
  6417. // #endregion 一次性读取所有数据
  6418. // stopwatch2.Stop();
  6419. // #region 回写操作,写后清空flag
  6420. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  6421. // #endregion 回写操作,写后清空flag
  6422. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  6423. // try
  6424. // {
  6425. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  6426. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  6427. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  6428. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  6429. // {
  6430. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  6431. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  6432. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  6433. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  6434. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  6435. // }
  6436. // }
  6437. // catch (Exception ex)
  6438. // {
  6439. // // 6代表上位机报警
  6440. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  6441. // string str = ex.StackTrace;
  6442. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6443. // }
  6444. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  6445. // #region 上料进站校验
  6446. // try
  6447. // {
  6448. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  6449. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  6450. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  6451. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  6452. // {
  6453. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  6454. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  6455. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  6456. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  6457. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  6458. // }
  6459. // }
  6460. // catch (Exception ex)
  6461. // {
  6462. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  6463. // string str = ex.StackTrace;
  6464. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6465. // }
  6466. // #endregion 上料进站校验
  6467. // #region Tray盘上料装备-出站接口
  6468. // try
  6469. // {
  6470. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  6471. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  6472. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  6473. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  6474. // {
  6475. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  6476. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6477. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  6478. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  6479. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  6480. // }
  6481. // }
  6482. // catch (Exception ex)
  6483. // {
  6484. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  6485. // string str = ex.StackTrace;
  6486. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6487. // }
  6488. // #endregion Tray盘上料装备-出站接口
  6489. // #region Tray盘上料装备-将SN发给ICT标机
  6490. // try
  6491. // {
  6492. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  6493. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  6494. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  6495. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  6496. // {
  6497. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  6498. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  6499. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  6500. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  6501. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  6502. // }
  6503. // }
  6504. // catch (Exception ex)
  6505. // {
  6506. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  6507. // string str = ex.StackTrace;
  6508. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6509. // }
  6510. // #endregion Tray盘上料装备-将SN发给ICT标机
  6511. // #region Tray盘上料装备-点检数据
  6512. // //try
  6513. // //{
  6514. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  6515. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  6516. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  6517. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  6518. // // if (pLC_Flag && !mES_Flag) // 1 0
  6519. // // {
  6520. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  6521. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  6522. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  6523. // // }
  6524. // // else if (!pLC_Flag && mES_Flag) // 0 1
  6525. // // {
  6526. // // // 清空写给PLC的数据
  6527. // // // MES_Flag重置为0
  6528. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  6529. // // }
  6530. // //}
  6531. // //catch (Exception ex)
  6532. // //{
  6533. // // // MES_Flag 为2上位机报错
  6534. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  6535. // // string str = ex.StackTrace;
  6536. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6537. // //}
  6538. // #endregion Tray盘上料装备-点检数据
  6539. // #region 节拍接口
  6540. // try
  6541. // {
  6542. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  6543. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  6544. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  6545. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  6546. // {
  6547. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  6548. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6549. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  6550. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  6551. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  6552. // }
  6553. // }
  6554. // catch (Exception ex)
  6555. // {
  6556. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  6557. // string str = ex.StackTrace;
  6558. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6559. // }
  6560. // #endregion 节拍接口
  6561. // #region AGV上料
  6562. // // AGV上料叫AGV信号
  6563. // try
  6564. // {
  6565. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  6566. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  6567. // if (a1AGVUpCall != a1AGVUpCallOld)
  6568. // {
  6569. // if (a1AGVUpCall == 1) // 0->1
  6570. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  6571. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  6572. // }
  6573. // }
  6574. // catch (Exception ex)
  6575. // {
  6576. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  6577. // string str = ex.StackTrace;
  6578. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6579. // }
  6580. // // AGV上料完成信号
  6581. // try
  6582. // {
  6583. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  6584. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  6585. // if (a1AGVUpEnd != a1AGVUpEndOld)
  6586. // {
  6587. // if (a1AGVUpEnd == 1) // 0->1
  6588. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  6589. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  6590. // }
  6591. // }
  6592. // catch (Exception ex)
  6593. // {
  6594. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  6595. // string str = ex.StackTrace;
  6596. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6597. // }
  6598. // #endregion AGV上料
  6599. // #region AGV下料
  6600. // // AGV下料叫agv信号
  6601. // try
  6602. // {
  6603. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  6604. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  6605. // if (a1AGVDownCall != a1AGVDownCallOld)
  6606. // {
  6607. // if (a1AGVDownCall == 1) // 0->1
  6608. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  6609. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  6610. // }
  6611. // }
  6612. // catch (Exception ex)
  6613. // {
  6614. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  6615. // string str = ex.StackTrace;
  6616. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6617. // }
  6618. // // AGV下料完成信号
  6619. // try
  6620. // {
  6621. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  6622. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  6623. // if (a1AGVDownEnd != a1AGVDownEndOld)
  6624. // {
  6625. // if (a1AGVDownEnd == 1) // 0->1
  6626. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  6627. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  6628. // }
  6629. // }
  6630. // catch (Exception ex)
  6631. // {
  6632. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  6633. // string str = ex.StackTrace;
  6634. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6635. // }
  6636. // #endregion AGV下料
  6637. // #region 心跳
  6638. // try
  6639. // {
  6640. // short states = 0;
  6641. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  6642. // }
  6643. // catch (Exception ex)
  6644. // {
  6645. // string str = ex.StackTrace;
  6646. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6647. // }
  6648. // #endregion 心跳
  6649. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6650. // stopwatch1.Stop();
  6651. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  6652. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6653. // }
  6654. // else
  6655. // {
  6656. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6657. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6658. // Funs[plcNo].Connect(); // 重连
  6659. // }
  6660. // }
  6661. // catch (Exception ex)
  6662. // {
  6663. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6664. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6665. // Funs[plcNo].ReConnect();
  6666. // }
  6667. // Thread.Sleep(IntervalReadPLC);
  6668. // }
  6669. //}
  6670. /// <summary>
  6671. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  6672. /// </summary>
  6673. /// <param name="plcNo">PLC编号</param>
  6674. /// <param name="stationNameStr">工站全称</param>
  6675. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  6676. {
  6677. Stopwatch stopwatch1 = new Stopwatch();
  6678. Stopwatch stopwatch2 = new Stopwatch();
  6679. try
  6680. {
  6681. stopwatch1.Start();
  6682. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  6683. sn = sn.Replace("\0", "");
  6684. #region 查询载具上的产品信息
  6685. string cavityData = string.Empty;
  6686. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6687. if (string.IsNullOrEmpty(cavityData))
  6688. cavityData = "";
  6689. if (snResult != 0)
  6690. {
  6691. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6692. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  6693. writeToPLC_Flag1.Adress = 2003;
  6694. writeToPLC_Flag1.Value = (short)6;
  6695. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  6696. stopwatch1.Stop();
  6697. AddMessage(LogType.Info,
  6698. stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  6699. "ms");
  6700. return;
  6701. }
  6702. #endregion 查询载具上的产品信息
  6703. string[] cavitySNs = cavityData.Split('.');
  6704. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  6705. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  6706. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  6707. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  6708. if (cavitySNs != null && cavitySNs.Length >= 2)
  6709. {
  6710. a1CavitySN1_VehicleStates = cavitySNs[0];
  6711. a1CavitySN2_VehicleStates = cavitySNs[1];
  6712. a1CavityResult1_VehicleStates = 2;
  6713. a1CavityResult2_VehicleStates = 2;
  6714. }
  6715. if (a1CavitySN1_VehicleStates == "假产品")
  6716. a1CavityResult1_VehicleStates = 3;
  6717. if (a1CavitySN2_VehicleStates == "假产品")
  6718. a1CavityResult2_VehicleStates = 3;
  6719. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6720. // 回写
  6721. stopwatch2.Start();
  6722. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  6723. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  6724. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  6725. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  6726. //// MES_Flag
  6727. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  6728. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6729. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  6730. writeToPLC_Flag.Adress = 2003;
  6731. writeToPLC_Flag.Value = mES_Flag;
  6732. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  6733. {
  6734. Name = "a1CavitySN1_VehicleStates",
  6735. Adress = 2024,
  6736. ValueType = PLCValueType.String,
  6737. ValueTypeStrLength = 20,
  6738. Value = a1CavitySN1_VehicleStates
  6739. });
  6740. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  6741. {
  6742. Name = "a1CavitySN2_VehicleStates",
  6743. Adress = 2044,
  6744. ValueType = PLCValueType.String,
  6745. ValueTypeStrLength = 20,
  6746. Value = a1CavitySN2_VehicleStates
  6747. });
  6748. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  6749. {
  6750. Name = "a1CavityResult1_VehicleStates",
  6751. Adress = 2064,
  6752. ValueType = PLCValueType.Short,
  6753. Value = a1CavityResult1_VehicleStates
  6754. });
  6755. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  6756. {
  6757. Name = "a1CavityResult2_VehicleStates",
  6758. Adress = 2065,
  6759. ValueType = PLCValueType.Short,
  6760. Value = a1CavityResult2_VehicleStates
  6761. });
  6762. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  6763. stopwatch2.Stop();
  6764. }
  6765. catch (Exception ex)
  6766. {
  6767. string str = ex.StackTrace;
  6768. AddMessage_Station(stationNameStr, LogType.Error,
  6769. $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" +
  6770. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6771. // MES_Flag
  6772. stopwatch2.Start();
  6773. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6774. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6775. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  6776. writeToPLC_Flag.Adress = 2003;
  6777. writeToPLC_Flag.Value = (short)6;
  6778. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  6779. stopwatch2.Stop();
  6780. }
  6781. stopwatch1.Stop();
  6782. AddMessage(LogType.Info,
  6783. stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6784. stopwatch2.ElapsedMilliseconds + "ms");
  6785. }
  6786. /// <summary>
  6787. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  6788. /// </summary>
  6789. /// <param name="plcNo">PLC编号</param>
  6790. /// <param name="stationNameStr">工站全称</param>
  6791. private void S1上料进站校验(int plcNo, string stationNameStr)
  6792. {
  6793. Stopwatch stopwatch1 = new Stopwatch();
  6794. Stopwatch stopwatch2 = new Stopwatch();
  6795. try
  6796. {
  6797. stopwatch1.Start();
  6798. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  6799. sn = sn.Replace("\0", "");
  6800. // 保存进站数据+调用进站MES接口
  6801. List<TestItem> item = new List<TestItem>();
  6802. stopwatch2.Start();
  6803. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  6804. item, out string errorMsg);
  6805. stopwatch2.Stop();
  6806. short a1MES_FLAG_Check = (short)result;
  6807. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6808. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6809. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  6810. writeToPLC_Flag.Adress = 2077;
  6811. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  6812. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  6813. }
  6814. catch (Exception ex)
  6815. {
  6816. string str = ex.StackTrace;
  6817. AddMessage_Station(stationNameStr, LogType.Error,
  6818. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  6819. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6820. // MES_Flag
  6821. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  6822. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6823. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  6824. writeToPLC_Flag.Adress = 2077;
  6825. writeToPLC_Flag.Value = (short)6;
  6826. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  6827. }
  6828. stopwatch1.Stop();
  6829. AddMessage(LogType.Info,
  6830. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  6831. stopwatch2.ElapsedMilliseconds + "ms");
  6832. }
  6833. /// <summary>
  6834. /// [S1] Tray盘上料装备(板测)- 出站接口
  6835. /// </summary>
  6836. /// <param name="plcNo"></param>
  6837. /// <param name="stationCode"></param>
  6838. /// <param name="stationName"></param>
  6839. private void S1出站接口(int plcNo, string stationCode, string stationName)
  6840. {
  6841. Stopwatch stopwatch1 = new Stopwatch();
  6842. Stopwatch stopwatch2 = new Stopwatch();
  6843. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6844. string stationNameStr = stationCode + stationName;
  6845. string processItem = stationName; // 测试项目
  6846. try
  6847. {
  6848. stopwatch1.Start();
  6849. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6850. //string batch_num = GlobalContext.BatchNumber; // 批次号
  6851. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6852. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6853. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  6854. sn = sn.Replace("\0", "");
  6855. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  6856. partNo1 = partNo1.Replace("\0", "");
  6857. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  6858. partNo2 = partNo2.Replace("\0", "");
  6859. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  6860. bool pass = a1Result == 1;
  6861. stopwatch2.Start();
  6862. // 产品1
  6863. List<TestItem> items = new List<TestItem>();
  6864. items.Add(new TestItem()
  6865. {
  6866. Parameter_name = "载具码",
  6867. Parameter_value = sn,
  6868. Parameter_unit = ""
  6869. });
  6870. items.Add(new TestItem()
  6871. {
  6872. Parameter_name = "载具穴号",
  6873. Parameter_value = "1",
  6874. Parameter_unit = ""
  6875. });
  6876. items.Add(new TestItem()
  6877. {
  6878. Parameter_name = "产品结果",
  6879. Parameter_value = a1Result == 1 ? "OK" : "NG",
  6880. Parameter_unit = ""
  6881. });
  6882. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  6883. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  6884. // 产品2
  6885. items = new List<TestItem>();
  6886. items.Add(new TestItem()
  6887. {
  6888. Parameter_name = "载具码",
  6889. Parameter_value = sn,
  6890. Parameter_unit = ""
  6891. });
  6892. items.Add(new TestItem()
  6893. {
  6894. Parameter_name = "载具穴号",
  6895. Parameter_value = "2",
  6896. Parameter_unit = ""
  6897. });
  6898. items.Add(new TestItem()
  6899. {
  6900. Parameter_name = "产品结果",
  6901. Parameter_value = a1Result == 1 ? "OK" : "NG",
  6902. Parameter_unit = ""
  6903. });
  6904. int result2 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  6905. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  6906. short result = 0;
  6907. List<int> results = new List<int>() { result1, result2 };
  6908. if (result1 == 1 && result2 == 1)
  6909. result = 1;
  6910. else if (results.Contains(3))
  6911. result = 3;
  6912. else if (results.Contains(2))
  6913. result = 2;
  6914. else if (results.Contains(4))
  6915. result = 4;
  6916. else
  6917. result = 4;
  6918. stopwatch2.Stop();
  6919. #region 存储绑定数据到 边线MES系统中
  6920. if (result == 1)
  6921. {
  6922. string data = string.Concat(partNo1, ".", partNo2);
  6923. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  6924. if (resultMesR != 0)
  6925. {
  6926. result = 4;
  6927. AddMessage_Station(stationNameStr, LogType.Error,
  6928. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  6929. }
  6930. }
  6931. #endregion 存储绑定数据到 边线MES系统中
  6932. // MES_Flag 为MES报错
  6933. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6934. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  6935. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6936. writeToPLC_Flag.Name = "a1MES_FLAG";
  6937. writeToPLC_Flag.Adress = 2109;
  6938. writeToPLC_Flag.Value = result;
  6939. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  6940. OnMessage(LogType.Debug,
  6941. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  6942. }
  6943. catch (Exception ex)
  6944. {
  6945. stopwatch2.Restart();
  6946. // MES_Flag 为4上位机报错
  6947. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  6948. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6949. writeToPLC_Flag.Name = "a1MES_FLAG";
  6950. writeToPLC_Flag.Adress = 2109;
  6951. writeToPLC_Flag.Value = (short)4;
  6952. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  6953. stopwatch2.Stop();
  6954. string str = ex.StackTrace;
  6955. AddMessage_Station(stationNameStr, LogType.Error,
  6956. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  6957. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6958. }
  6959. stopwatch1.Stop();
  6960. AddMessage(LogType.Info,
  6961. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  6962. stopwatch2.ElapsedMilliseconds + "ms");
  6963. }
  6964. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  6965. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  6966. //{
  6967. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6968. // string stationNameStr = stationCode + stationName;
  6969. // string processItem = stationName; // 测试项目
  6970. // try
  6971. // {
  6972. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6973. // string accno = "1"; // 工序编号
  6974. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  6975. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  6976. // List<OneCheckItem> items = new List<OneCheckItem>()
  6977. // {
  6978. // new OneCheckItem()
  6979. // {
  6980. // Onecheck_name="胶圈装配行程设定上限",
  6981. // Onecheck_content="上限值",
  6982. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  6983. // },
  6984. // };
  6985. // OneCheckData oneCheckData = new OneCheckData()
  6986. // {
  6987. // Line_code = GlobalContext.LineCode,
  6988. // Line_name = GlobalContext.LineName,
  6989. // Equipment_code = equipmentCode,
  6990. // Equipment_name = equipmentCode,
  6991. // Workorder_code = workorder_code,
  6992. // Procedure_code = accno,
  6993. // Procedure_name = processItem,
  6994. // Oneckeck_values = items,
  6995. // Onecheck_empcode = "",
  6996. // Onecheck_empname = "",
  6997. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  6998. // };
  6999. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  7000. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  7001. // short result = result1 == 1 ? (short)1 : (short)2;
  7002. // // MES_Flag 为4MES报错
  7003. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  7004. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7005. // }
  7006. // catch (Exception ex)
  7007. // {
  7008. // // MES_Flag 为2上位机报错
  7009. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  7010. // string str = ex.StackTrace;
  7011. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7012. // }
  7013. //}
  7014. // ReadStation_S1_2 节拍接口+AGV
  7015. /// <summary>
  7016. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  7017. /// </summary>
  7018. /// <param name="plcNo">PLC编号</param>
  7019. /// <param name="stationNameStr">工站全称</param>
  7020. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  7021. {
  7022. Stopwatch stopwatch1 = new Stopwatch();
  7023. Stopwatch stopwatch2 = new Stopwatch();
  7024. try
  7025. {
  7026. stopwatch1.Start();
  7027. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  7028. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  7029. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  7030. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  7031. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  7032. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  7033. // ZS 将SN发给ICT标机(串口)
  7034. short a1MES_FLAG_ICT = 1;
  7035. stopwatch2.Start();
  7036. // MES_Flag
  7037. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  7038. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7039. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  7040. writeToPLC_Flag.Adress = 2182;
  7041. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  7042. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  7043. stopwatch2.Stop();
  7044. }
  7045. catch (Exception ex)
  7046. {
  7047. string str = ex.StackTrace;
  7048. AddMessage_Station(stationNameStr, LogType.Error,
  7049. $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" +
  7050. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7051. stopwatch2.Start();
  7052. // MES_Flag
  7053. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  7054. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7055. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  7056. writeToPLC_Flag.Adress = 2182;
  7057. writeToPLC_Flag.Value = (short)4;
  7058. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  7059. stopwatch2.Stop();
  7060. }
  7061. stopwatch1.Stop();
  7062. AddMessage(LogType.Info,
  7063. stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7064. stopwatch2.ElapsedMilliseconds + "ms");
  7065. }
  7066. /// <summary>
  7067. /// [S1] Tray盘上料装备(板测)- 节拍接口
  7068. /// </summary>
  7069. /// <param name="plcNo">PLC编号</param>
  7070. /// <param name="stationNameStr">工站全称</param>
  7071. private void S1节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  7072. {
  7073. Stopwatch stopwatch1 = new Stopwatch();
  7074. Stopwatch stopwatch2 = new Stopwatch();
  7075. string resultStr = string.Empty;
  7076. try
  7077. {
  7078. stopwatch1.Start();
  7079. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  7080. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  7081. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  7082. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  7083. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  7084. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7085. if (!actionBool)
  7086. {
  7087. stopwatch2.Start();
  7088. //写入PLC
  7089. iot_data.beatReturn = 2; //NG
  7090. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7091. stopwatch2.Stop();
  7092. AddMessage(LogType.Info,
  7093. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  7094. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7095. return;
  7096. }
  7097. //作业开始后要有物料和载具信息
  7098. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode) &&
  7099. Convert.ToInt32(oEEType) > 2)
  7100. {
  7101. stopwatch2.Start();
  7102. //写入PLC
  7103. iot_data.beatReturn = 2; //NG
  7104. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7105. stopwatch2.Stop();
  7106. AddMessage_Station(stationNameStr, LogType.Info,
  7107. stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  7108. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7109. return;
  7110. }
  7111. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a1OEEPartNo))
  7112. {
  7113. stopwatch2.Start();
  7114. //写入PLC
  7115. iot_data.beatReturn = 2; //NG
  7116. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7117. stopwatch2.Stop();
  7118. AddMessage_Station(stationNameStr, LogType.Info,
  7119. stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  7120. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7121. return;
  7122. }
  7123. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a1OEEVehicleCode))
  7124. {
  7125. stopwatch2.Start();
  7126. //写入PLC
  7127. iot_data.beatReturn = 2; //NG
  7128. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7129. stopwatch2.Stop();
  7130. AddMessage_Station(stationNameStr, LogType.Info,
  7131. stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  7132. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7133. return;
  7134. }
  7135. short _result = 0;
  7136. // 上传OEE
  7137. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  7138. _result = result.Item1;
  7139. resultStr = result.Item2;
  7140. if (_result == 1)
  7141. {
  7142. stopwatch2.Start();
  7143. //写入PLC
  7144. iot_data.beatReturn = 1; //OK
  7145. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7146. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  7147. stopwatch2.Stop();
  7148. }
  7149. else {
  7150. stopwatch2.Start();
  7151. //写入PLC
  7152. iot_data.beatReturn = 2; //NG
  7153. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7154. stopwatch2.Stop();
  7155. AddMessage_Station(stationNameStr, LogType.Error,
  7156. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr );
  7157. }
  7158. }
  7159. catch (Exception ex)
  7160. {
  7161. string str = ex.StackTrace;
  7162. AddMessage_Station(stationNameStr, LogType.Error,
  7163. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  7164. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7165. // MES_Flag
  7166. stopwatch2.Start();
  7167. //写入PLC
  7168. iot_data.beatReturn = 2; //NG
  7169. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  7170. stopwatch2.Stop();
  7171. }
  7172. stopwatch1.Stop();
  7173. AddMessage(LogType.Info,
  7174. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7175. stopwatch2.ElapsedMilliseconds + "ms");
  7176. }
  7177. /// <summary>
  7178. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  7179. /// </summary>
  7180. /// <param name="plcNo">PLC编号</param>
  7181. /// <param name="stationNameStr">工站全称</param>
  7182. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  7183. {
  7184. Stopwatch stopwatch1 = new Stopwatch();
  7185. Stopwatch stopwatch2 = new Stopwatch();
  7186. try
  7187. {
  7188. stopwatch1.Start();
  7189. // ZS 呼叫AGV
  7190. short a1AGVUpCall = 2;
  7191. stopwatch2.Start();
  7192. // a1AGVUpCall
  7193. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7194. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7195. writeToPLC_Flag.Name = "a1AGVUpCall";
  7196. writeToPLC_Flag.Adress = 2307;
  7197. writeToPLC_Flag.Value = a1AGVUpCall;
  7198. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  7199. stopwatch2.Stop();
  7200. }
  7201. catch (Exception ex)
  7202. {
  7203. string str = ex.StackTrace;
  7204. AddMessage_Station(stationNameStr, LogType.Error,
  7205. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  7206. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7207. // a1AGVUpCall
  7208. stopwatch2.Start();
  7209. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  7210. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7211. writeToPLC_Flag.Name = "a1AGVUpCall";
  7212. writeToPLC_Flag.Adress = 2307;
  7213. writeToPLC_Flag.Value = (short)4;
  7214. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  7215. stopwatch2.Stop();
  7216. }
  7217. stopwatch1.Stop();
  7218. AddMessage(LogType.Info,
  7219. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7220. stopwatch2.ElapsedMilliseconds + "ms");
  7221. }
  7222. /// <summary>
  7223. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  7224. /// </summary>
  7225. /// <param name="plcNo">PLC编号</param>
  7226. /// <param name="stationNameStr">工站全称</param>
  7227. private void S1AGV上料完成(int plcNo, string stationNameStr)
  7228. {
  7229. Stopwatch stopwatch1 = new Stopwatch();
  7230. Stopwatch stopwatch2 = new Stopwatch();
  7231. try
  7232. {
  7233. stopwatch1.Start();
  7234. // ZS AGV上料完成,让小车离开
  7235. short a1AGVUpEnd = 2;
  7236. stopwatch2.Start();
  7237. // a1AGVUpEnd
  7238. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7239. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7240. writeToPLC_Flag.Name = "a1AGVUpEnd";
  7241. writeToPLC_Flag.Adress = 2309;
  7242. writeToPLC_Flag.Value = a1AGVUpEnd;
  7243. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  7244. stopwatch2.Stop();
  7245. }
  7246. catch (Exception ex)
  7247. {
  7248. string str = ex.StackTrace;
  7249. AddMessage_Station(stationNameStr, LogType.Error,
  7250. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  7251. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7252. // a1AGVUpEnd
  7253. stopwatch2.Start();
  7254. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  7255. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7256. writeToPLC_Flag.Name = "a1AGVUpEnd";
  7257. writeToPLC_Flag.Adress = 2309;
  7258. writeToPLC_Flag.Value = (short)4;
  7259. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  7260. stopwatch2.Stop();
  7261. }
  7262. stopwatch1.Stop();
  7263. AddMessage(LogType.Info,
  7264. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7265. stopwatch2.ElapsedMilliseconds + "ms");
  7266. }
  7267. /// <summary>
  7268. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  7269. /// </summary>
  7270. /// <param name="plcNo">PLC编号</param>
  7271. /// <param name="stationNameStr">工站全称</param>
  7272. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  7273. {
  7274. Stopwatch stopwatch1 = new Stopwatch();
  7275. Stopwatch stopwatch2 = new Stopwatch();
  7276. try
  7277. {
  7278. stopwatch1.Start();
  7279. // ZS 呼叫AGV
  7280. short a1AGVDownCall = 2;
  7281. stopwatch2.Start();
  7282. // a1AGVDownCall
  7283. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7284. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7285. writeToPLC_Flag.Name = "a1AGVDownCall";
  7286. writeToPLC_Flag.Adress = 2320;
  7287. writeToPLC_Flag.Value = a1AGVDownCall;
  7288. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  7289. stopwatch2.Stop();
  7290. }
  7291. catch (Exception ex)
  7292. {
  7293. string str = ex.StackTrace;
  7294. AddMessage_Station(stationNameStr, LogType.Error,
  7295. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  7296. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7297. // a1AGVDownCall
  7298. stopwatch2.Start();
  7299. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  7300. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7301. writeToPLC_Flag.Name = "a1AGVDownCall";
  7302. writeToPLC_Flag.Adress = 2320;
  7303. writeToPLC_Flag.Value = (short)4;
  7304. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  7305. stopwatch2.Stop();
  7306. }
  7307. stopwatch1.Stop();
  7308. AddMessage(LogType.Info,
  7309. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7310. stopwatch2.ElapsedMilliseconds + "ms");
  7311. }
  7312. /// <summary>
  7313. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  7314. /// </summary>
  7315. /// <param name="plcNo">PLC编号</param>
  7316. /// <param name="stationNameStr">工站全称</param>
  7317. private void S1AGV下料完成(int plcNo, string stationNameStr)
  7318. {
  7319. Stopwatch stopwatch1 = new Stopwatch();
  7320. Stopwatch stopwatch2 = new Stopwatch();
  7321. try
  7322. {
  7323. stopwatch1.Start();
  7324. // ZS AGV上料完成,让小车离开
  7325. short a1AGVDownEnd = 2;
  7326. stopwatch2.Start();
  7327. // a1AGVDownEnd
  7328. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7329. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7330. writeToPLC_Flag.Name = "a1AGVDownEnd";
  7331. writeToPLC_Flag.Adress = 2322;
  7332. writeToPLC_Flag.Value = a1AGVDownEnd;
  7333. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  7334. stopwatch2.Stop();
  7335. }
  7336. catch (Exception ex)
  7337. {
  7338. string str = ex.StackTrace;
  7339. AddMessage_Station(stationNameStr, LogType.Error,
  7340. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  7341. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7342. // a1AGVDownEnd
  7343. stopwatch2.Start();
  7344. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  7345. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7346. writeToPLC_Flag.Name = "a1AGVDownEnd";
  7347. writeToPLC_Flag.Adress = 2322;
  7348. writeToPLC_Flag.Value = (short)4;
  7349. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  7350. stopwatch2.Stop();
  7351. }
  7352. stopwatch1.Stop();
  7353. AddMessage(LogType.Info,
  7354. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7355. stopwatch2.ElapsedMilliseconds + "ms");
  7356. }
  7357. #endregion [S1] Tray盘上料装备(板测)
  7358. #endregion PLC1 张超凡
  7359. #region PLC2 李晓奇
  7360. #region [S2] FCT(板测)
  7361. /// <summary>
  7362. /// S2工位的数据- 触发信号上次的值
  7363. /// </summary>
  7364. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  7365. /// <summary>
  7366. /// S2工位的数据(含触发信号)
  7367. /// </summary>
  7368. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  7369. /// <summary>
  7370. /// S2工位的数据- 回写点位
  7371. /// </summary>
  7372. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  7373. /// <summary>
  7374. /// [S2] FCT(板测)
  7375. /// </summary>
  7376. /// <param name="plcNo">PLC编号</param>
  7377. //private void ReadStation_S2(int plcNo)
  7378. //{
  7379. // // [S1] Tray盘上料装备
  7380. // // [S2] FCT
  7381. // // [S3] 值板机
  7382. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  7383. // // [S5] Tray盘下料装备
  7384. // /// 上位机心跳
  7385. // /// 获取设备报警数据与状态信息
  7386. // string stationCode = "[S2]";
  7387. // string stationName = "FCT";
  7388. // string stationNameStr = stationCode + stationName;
  7389. // #region 创建字典
  7390. // // 触发信号字典 赋值
  7391. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  7392. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  7393. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  7394. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  7395. // // PLC数据字典 赋值
  7396. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  7397. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  7398. // s2PLCData.Add("b1ProductSN_Check", 0);
  7399. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  7400. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  7401. // s2PLCData.Add("b1ProductSN_Unbind", "");
  7402. // s2PLCData.Add("b1ProductSN_Bind", "");
  7403. // s2PLCData.Add("b1Part1SN_Bind", "");
  7404. // s2PLCData.Add("b1Part2SN_Bind", "");
  7405. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  7406. // s2PLCData.Add("b1MES_FLAG", 0);
  7407. // s2PLCData.Add("b1ProductSN", 0);
  7408. // s2PLCData.Add("b1Part1Result", 0);
  7409. // s2PLCData.Add("b1Part2Result", 0);
  7410. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  7411. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  7412. // s2PLCData.Add("b1OEEProductSN", "");
  7413. // s2PLCData.Add("b1OEEType", 0);
  7414. // #endregion 创建字典
  7415. // while (IsRun)
  7416. // {
  7417. // try
  7418. // {
  7419. // if (!GlobalContext._IsCon_Funs2)
  7420. // {
  7421. // UpdatePLCMonitor(1, plcNo, 0);
  7422. // continue;
  7423. // }
  7424. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  7425. // {
  7426. // Stopwatch stopwatch1 = new Stopwatch();
  7427. // Stopwatch stopwatch2 = new Stopwatch();
  7428. // stopwatch1.Start();
  7429. // stopwatch2.Start();
  7430. // #region 一次性读取所有数据
  7431. // // 一次性读取所有数据
  7432. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  7433. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  7434. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  7435. // int[] datas = data1.Concat(data2).ToArray();
  7436. // datas = datas.Concat(data3).ToArray();
  7437. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  7438. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  7439. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  7440. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  7441. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  7442. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  7443. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  7444. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  7445. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  7446. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  7447. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  7448. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  7449. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  7450. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  7451. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  7452. // s2PLCData["b1MES_FLAG"] = datas[169];
  7453. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  7454. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  7455. // s2PLCData["b1Part1Result"] = datas[190];
  7456. // s2PLCData["b1Part2Result"] = datas[191];
  7457. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  7458. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  7459. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  7460. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  7461. // s2PLCData["b1OEEType"] = datas[224];
  7462. // #endregion 一次性读取所有数据
  7463. // stopwatch2.Stop();
  7464. // #region 回写操作,写后清空flag
  7465. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  7466. // #endregion 回写操作,写后清空flag
  7467. // #region 进站校验
  7468. // try
  7469. // {
  7470. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  7471. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  7472. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  7473. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  7474. // {
  7475. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  7476. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  7477. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  7478. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  7479. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  7480. // }
  7481. // }
  7482. // catch (Exception ex)
  7483. // {
  7484. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7485. // string str = ex.StackTrace;
  7486. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7487. // }
  7488. // #endregion 进站校验
  7489. // #region 二穴载具解绑/绑定(产品换载具)
  7490. // try
  7491. // {
  7492. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  7493. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  7494. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  7495. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  7496. // {
  7497. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  7498. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  7499. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  7500. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  7501. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  7502. // }
  7503. // }
  7504. // catch (Exception ex)
  7505. // {
  7506. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7507. // string str = ex.StackTrace;
  7508. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7509. // }
  7510. // #endregion 二穴载具解绑/绑定(产品换载具)
  7511. // #region FCT-出站接口
  7512. // try
  7513. // {
  7514. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  7515. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  7516. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  7517. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  7518. // {
  7519. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  7520. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  7521. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  7522. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  7523. // }
  7524. // }
  7525. // catch (Exception ex)
  7526. // {
  7527. // // MES_Flag 为6上位机报错
  7528. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  7529. // string str = ex.StackTrace;
  7530. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7531. // }
  7532. // #endregion FCT-出站接口
  7533. // #region 节拍接口
  7534. // try
  7535. // {
  7536. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  7537. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  7538. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  7539. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  7540. // {
  7541. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  7542. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7543. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  7544. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  7545. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  7546. // }
  7547. // }
  7548. // catch (Exception ex)
  7549. // {
  7550. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  7551. // string str = ex.StackTrace;
  7552. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7553. // }
  7554. // #endregion 节拍接口
  7555. // #region 心跳
  7556. // try
  7557. // {
  7558. // short states = 0;
  7559. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7560. // }
  7561. // catch (Exception ex)
  7562. // {
  7563. // string str = ex.StackTrace;
  7564. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7565. // }
  7566. // #endregion 心跳
  7567. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7568. // stopwatch1.Stop();
  7569. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7570. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7571. // }
  7572. // else
  7573. // {
  7574. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7575. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  7576. // Funs[plcNo].Connect();
  7577. // }
  7578. // }
  7579. // catch (Exception ex)
  7580. // {
  7581. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7582. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  7583. // Funs[plcNo].ReConnect();
  7584. // }
  7585. // Thread.Sleep(IntervalReadPLC);
  7586. // }
  7587. //}
  7588. /// <summary>
  7589. /// [S2] FCT(板测)- 进站校验
  7590. /// </summary>
  7591. /// <param name="plcNo">PLC编号</param>
  7592. /// <param name="stationNameStr">工站全称</param>
  7593. private void S2进站校验(int plcNo, string stationNameStr)
  7594. {
  7595. Stopwatch stopwatch1 = new Stopwatch();
  7596. Stopwatch stopwatch2 = new Stopwatch();
  7597. try
  7598. {
  7599. stopwatch1.Start();
  7600. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  7601. sn = sn.Replace("\0", "");
  7602. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  7603. // 查询物料码By载具码 并判断是不是假产品
  7604. string cavityData = string.Empty;
  7605. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  7606. if (string.IsNullOrEmpty(cavityData))
  7607. cavityData = "";
  7608. if (snResult != 0)
  7609. {
  7610. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7611. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  7612. writeToPLC_Flag1.Adress = 2003;
  7613. writeToPLC_Flag1.Value = (short)6;
  7614. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  7615. stopwatch1.Stop();
  7616. AddMessage(LogType.Info,
  7617. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7618. return;
  7619. }
  7620. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  7621. string[] cavitySNs = cavityData.Split('.');
  7622. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  7623. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  7624. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  7625. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  7626. if (cavitySNs != null && cavitySNs.Length >= 2)
  7627. {
  7628. b1Part1SN_Check = cavitySNs[0];
  7629. b1Part2SN_Check = cavitySNs[1];
  7630. b1Part1Result_Check = 2;
  7631. b1Part2Result_Check = 2;
  7632. }
  7633. if (b1Part1SN_Check == "假产品")
  7634. b1Part1Result_Check = 3;
  7635. if (b1Part2SN_Check == "假产品")
  7636. b1Part2Result_Check = 3;
  7637. // 调用MES进站
  7638. stopwatch2.Start();
  7639. // 调用MES进站 - 产品1
  7640. List<TestItem> item;
  7641. int result1 = b1Part1Result_Check;
  7642. if (result1 != 3)
  7643. {
  7644. item = new List<TestItem>();
  7645. item.Add(new TestItem()
  7646. {
  7647. Parameter_name = "载具码",
  7648. Parameter_value = sn,
  7649. });
  7650. item.Add(new TestItem()
  7651. {
  7652. Parameter_name = "载具穴号",
  7653. Parameter_value = "1",
  7654. });
  7655. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  7656. b1Part1SN_Check, item, out string errorMsg);
  7657. }
  7658. // 调用MES进站 - 产品2
  7659. int result2 = b1Part2Result_Check;
  7660. if (result2 != 3)
  7661. {
  7662. item = new List<TestItem>();
  7663. item.Add(new TestItem()
  7664. {
  7665. Parameter_name = "载具码",
  7666. Parameter_value = sn,
  7667. });
  7668. item.Add(new TestItem()
  7669. {
  7670. Parameter_name = "载具穴号",
  7671. Parameter_value = "2",
  7672. });
  7673. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  7674. b1Part2SN_Check, item, out string errorMsg);
  7675. }
  7676. stopwatch2.Stop();
  7677. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  7678. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  7679. int result = result1;
  7680. if (result == 1)
  7681. result = result2;
  7682. short b1MES_FLAG_Check = (short)result;
  7683. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  7684. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  7685. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  7686. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  7687. //// MES_Flag
  7688. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7689. WriteToPLC_Flag
  7690. writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7691. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  7692. writeToPLC_Flag.Adress = 2003;
  7693. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  7694. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7695. {
  7696. Name = "b1Part1SN_Check",
  7697. Adress = 2024,
  7698. ValueType = PLCValueType.String,
  7699. ValueTypeStrLength = 20,
  7700. Value = b1Part1SN_Check
  7701. });
  7702. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7703. {
  7704. Name = "b1Part2SN_Check",
  7705. Adress = 2044,
  7706. ValueType = PLCValueType.String,
  7707. ValueTypeStrLength = 20,
  7708. Value = b1Part2SN_Check
  7709. });
  7710. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7711. {
  7712. Name = "b1Part1Result_Check",
  7713. Adress = 2064,
  7714. ValueType = PLCValueType.Short,
  7715. Value = b1Part1Result_Check
  7716. });
  7717. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7718. {
  7719. Name = "b1Part2Result_Check",
  7720. Adress = 2065,
  7721. ValueType = PLCValueType.Short,
  7722. Value = b1Part2Result_Check
  7723. });
  7724. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  7725. }
  7726. catch (Exception ex)
  7727. {
  7728. string str = ex.StackTrace;
  7729. AddMessage_Station(stationNameStr, LogType.Error,
  7730. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  7731. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7732. // MES_Flag
  7733. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7734. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7735. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  7736. writeToPLC_Flag.Adress = 2003;
  7737. writeToPLC_Flag.Value = (short)6;
  7738. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  7739. }
  7740. stopwatch1.Stop();
  7741. AddMessage(LogType.Info,
  7742. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  7743. stopwatch2.ElapsedMilliseconds + "ms");
  7744. }
  7745. /// <summary>
  7746. /// [S2] FCT(板测)- 二穴载具解绑绑定
  7747. /// </summary>
  7748. /// <param name="plcNo">PLC编号</param>
  7749. /// <param name="stationNameStr">工站全称</param>
  7750. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  7751. {
  7752. Stopwatch stopwatch1 = new Stopwatch();
  7753. Stopwatch stopwatch2 = new Stopwatch();
  7754. try
  7755. {
  7756. stopwatch1.Start();
  7757. // 产品换载具
  7758. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  7759. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  7760. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  7761. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  7762. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  7763. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  7764. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  7765. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  7766. stopwatch2.Start();
  7767. #region 查询载具上的产品信息
  7768. //string cavityData = string.Empty;
  7769. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  7770. //if (string.IsNullOrEmpty(cavityData))
  7771. // cavityData = "";
  7772. //if (snResult != 0)
  7773. //{
  7774. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7775. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  7776. // writeToPLC_Flag.Adress = 2077;
  7777. // writeToPLC_Flag.Value = (short)6;
  7778. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  7779. // stopwatch1.Stop();
  7780. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7781. // return;
  7782. //}
  7783. #endregion 查询载具上的产品信息
  7784. #region 解绑(边线MES系统)
  7785. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  7786. if (snResult != 0)
  7787. {
  7788. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7789. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  7790. writeToPLC_Flag1.Adress = 2077;
  7791. writeToPLC_Flag1.Value = (short)6;
  7792. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  7793. stopwatch1.Stop();
  7794. AddMessage(LogType.Info,
  7795. stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" +
  7796. stopwatch1.ElapsedMilliseconds + "ms");
  7797. return;
  7798. }
  7799. #endregion 解绑(边线MES系统)
  7800. #region 存储绑定数据到 边线MES系统中
  7801. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  7802. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  7803. if (snResult != 0)
  7804. {
  7805. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7806. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  7807. writeToPLC_Flag1.Adress = 2077;
  7808. writeToPLC_Flag1.Value = (short)6;
  7809. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  7810. stopwatch1.Stop();
  7811. AddMessage(LogType.Info,
  7812. stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" +
  7813. stopwatch1.ElapsedMilliseconds + "ms");
  7814. return;
  7815. }
  7816. #endregion 存储绑定数据到 边线MES系统中
  7817. stopwatch2.Stop();
  7818. short b1MES_FLAG_Unbind = 1;
  7819. // MES_Flag
  7820. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7821. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7822. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  7823. writeToPLC_Flag.Adress = 2077;
  7824. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  7825. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  7826. }
  7827. catch (Exception ex)
  7828. {
  7829. string str = ex.StackTrace;
  7830. AddMessage_Station(stationNameStr, LogType.Error,
  7831. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" +
  7832. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7833. // MES_Flag
  7834. stopwatch2.Start();
  7835. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7836. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7837. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  7838. writeToPLC_Flag.Adress = 2077;
  7839. writeToPLC_Flag.Value = (short)6;
  7840. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  7841. stopwatch2.Stop();
  7842. }
  7843. stopwatch1.Stop();
  7844. AddMessage(LogType.Info,
  7845. stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7846. stopwatch2.ElapsedMilliseconds + "ms");
  7847. }
  7848. //// 上次采集到的SN
  7849. //private string sn_FCT = string.Empty;
  7850. /// <summary>
  7851. /// [S2] FCT(板测)- 出站数据
  7852. /// </summary>
  7853. private void S2出站接口(int plcNo, string stationCode, string stationName)
  7854. {
  7855. Stopwatch stopwatch1 = new Stopwatch();
  7856. Stopwatch stopwatch2 = new Stopwatch();
  7857. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7858. string stationNameStr = stationCode + stationName;
  7859. string processItem = stationName; // 测试项目
  7860. try
  7861. {
  7862. stopwatch1.Start();
  7863. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7864. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7865. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7866. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7867. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  7868. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  7869. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  7870. bool pass1 = b1Part1Result == 1;
  7871. bool pass2 = b1Part2Result == 1;
  7872. #region 根据 载具SN 查 物料SN
  7873. string cavityData = string.Empty;
  7874. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  7875. if (string.IsNullOrEmpty(cavityData))
  7876. cavityData = "";
  7877. if (snResult != 0)
  7878. {
  7879. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7880. writeToPLC_Flag1.Name = "b1MES_FLAG";
  7881. writeToPLC_Flag1.Adress = 2169;
  7882. writeToPLC_Flag1.Value = (short)4;
  7883. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  7884. stopwatch1.Stop();
  7885. AddMessage(LogType.Info,
  7886. stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  7887. "ms");
  7888. return;
  7889. }
  7890. #endregion 根据 载具SN 查 物料SN
  7891. string[] cavitySNs = cavityData.Split('.');
  7892. string b1ProductSN1 = string.Empty;
  7893. string b1ProductSN2 = string.Empty;
  7894. if (cavitySNs != null && cavitySNs.Length >= 2)
  7895. {
  7896. b1ProductSN1 = cavitySNs[0];
  7897. b1ProductSN2 = cavitySNs[1];
  7898. }
  7899. stopwatch2.Start();
  7900. // 产品1
  7901. int result1 = 0;
  7902. if (b1ProductSN1 == "假产品")
  7903. result1 = 1;
  7904. else
  7905. {
  7906. List<TestItem> items1 = new List<TestItem>();
  7907. items1.Add(new TestItem()
  7908. {
  7909. Parameter_name = "载具码",
  7910. Parameter_value = b1ProductSN.ToString(),
  7911. Parameter_unit = ""
  7912. });
  7913. items1.Add(new TestItem()
  7914. {
  7915. Parameter_name = "载具穴号",
  7916. Parameter_value = "1",
  7917. Parameter_unit = ""
  7918. });
  7919. items1.Add(new TestItem()
  7920. {
  7921. Parameter_name = "产品结果",
  7922. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  7923. Parameter_unit = ""
  7924. });
  7925. result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  7926. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  7927. }
  7928. // 产品2
  7929. int result2 = 0;
  7930. if (b1ProductSN1 == "假产品")
  7931. result2 = 1;
  7932. else
  7933. {
  7934. List<TestItem> items2 = new List<TestItem>();
  7935. items2.Add(new TestItem()
  7936. {
  7937. Parameter_name = "载具码",
  7938. Parameter_value = b1ProductSN.ToString(),
  7939. Parameter_unit = ""
  7940. });
  7941. items2.Add(new TestItem()
  7942. {
  7943. Parameter_name = "载具穴号",
  7944. Parameter_value = "2",
  7945. Parameter_unit = ""
  7946. });
  7947. items2.Add(new TestItem()
  7948. {
  7949. Parameter_name = "产品结果",
  7950. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  7951. Parameter_unit = ""
  7952. });
  7953. result2 = SwitctProcessData_old(stationNameStr, items2, equipmentCode, processItem
  7954. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  7955. }
  7956. short result = 0;
  7957. List<int> results = new List<int>() { result1, result2 };
  7958. if (result1 == 1 && result2 == 1)
  7959. result = 1;
  7960. else if (results.Contains(3))
  7961. result = 3;
  7962. else if (results.Contains(2))
  7963. result = 2;
  7964. else if (results.Contains(4))
  7965. result = 4;
  7966. else
  7967. result = 4;
  7968. stopwatch2.Stop();
  7969. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7970. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7971. writeToPLC_Flag.Name = "b1MES_FLAG";
  7972. writeToPLC_Flag.Adress = 2169;
  7973. writeToPLC_Flag.Value = result;
  7974. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  7975. OnMessage(LogType.Debug,
  7976. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7977. }
  7978. catch (Exception ex)
  7979. {
  7980. stopwatch2.Restart();
  7981. // MES_Flag 为4上位机报错
  7982. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  7983. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7984. writeToPLC_Flag.Name = "b1MES_FLAG";
  7985. writeToPLC_Flag.Adress = 2169;
  7986. writeToPLC_Flag.Value = (short)4;
  7987. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  7988. stopwatch2.Stop();
  7989. string str = ex.StackTrace;
  7990. AddMessage_Station(stationNameStr, LogType.Error,
  7991. $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  7992. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7993. }
  7994. stopwatch1.Stop();
  7995. AddMessage(LogType.Info,
  7996. stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  7997. stopwatch2.ElapsedMilliseconds + "ms");
  7998. }
  7999. /// <summary>
  8000. /// [S2] FCT(板测)- 节拍接口
  8001. /// </summary>
  8002. /// <param name="plcNo">PLC编号</param>
  8003. /// <param name="stationNameStr">工站全称</param>
  8004. private void S2节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  8005. {
  8006. Stopwatch stopwatch1 = new Stopwatch();
  8007. Stopwatch stopwatch2 = new Stopwatch();
  8008. string resultStr = string.Empty;
  8009. try
  8010. {
  8011. stopwatch1.Start();
  8012. string oEEType = ((int)s1PLCData["a2OEEType"]).ToString(); // 节拍类型(plc写入)
  8013. string a2OEEPartNo = (string)s1PLCData["a2OEEPartNo"]; // 物料码
  8014. a2OEEPartNo = a2OEEPartNo.Replace("\0", "");
  8015. string a20EEVehicleCode = (string)s1PLCData["a20EEVehicleCode"]; // 载具SN
  8016. a20EEVehicleCode = a20EEVehicleCode.Replace("\0", "");
  8017. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8018. if (!actionBool)
  8019. {
  8020. stopwatch2.Start();
  8021. //写入PLC
  8022. iot_data.beatReturn = 2; //NG
  8023. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8024. stopwatch2.Stop();
  8025. AddMessage(LogType.Info,
  8026. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  8027. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8028. return;
  8029. }
  8030. //作业开始后要有物料和载具信息
  8031. if (string.IsNullOrEmpty(a2OEEPartNo) && string.IsNullOrEmpty(a20EEVehicleCode) &&
  8032. Convert.ToInt32(oEEType) > 2)
  8033. {
  8034. stopwatch2.Start();
  8035. //写入PLC
  8036. iot_data.beatReturn = 2; //NG
  8037. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8038. stopwatch2.Stop();
  8039. AddMessage_Station(stationNameStr, LogType.Info,
  8040. stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  8041. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8042. return;
  8043. }
  8044. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a2OEEPartNo))
  8045. {
  8046. stopwatch2.Start();
  8047. //写入PLC
  8048. iot_data.beatReturn = 2; //NG
  8049. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8050. stopwatch2.Stop();
  8051. AddMessage_Station(stationNameStr, LogType.Info,
  8052. stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  8053. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8054. return;
  8055. }
  8056. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a20EEVehicleCode))
  8057. {
  8058. stopwatch2.Start();
  8059. //写入PLC
  8060. iot_data.beatReturn = 2; //NG
  8061. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8062. stopwatch2.Stop();
  8063. AddMessage_Station(stationNameStr, LogType.Info,
  8064. stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  8065. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8066. return;
  8067. }
  8068. short _result = 0;
  8069. // 上传OEE
  8070. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a2OEEPartNo, a20EEVehicleCode);
  8071. _result = result.Item1;
  8072. resultStr = result.Item2;
  8073. if (_result == 1)
  8074. {
  8075. stopwatch2.Start();
  8076. //写入PLC
  8077. iot_data.beatReturn = 1; //OK
  8078. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8079. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  8080. stopwatch2.Stop();
  8081. }
  8082. else
  8083. {
  8084. stopwatch2.Start();
  8085. //写入PLC
  8086. iot_data.beatReturn = 2; //NG
  8087. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8088. stopwatch2.Stop();
  8089. AddMessage_Station(stationNameStr, LogType.Error,
  8090. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  8091. }
  8092. }
  8093. catch (Exception ex)
  8094. {
  8095. string str = ex.StackTrace;
  8096. AddMessage_Station(stationNameStr, LogType.Error,
  8097. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  8098. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8099. // MES_Flag
  8100. stopwatch2.Start();
  8101. //写入PLC
  8102. iot_data.beatReturn = 2; //NG
  8103. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8104. stopwatch2.Stop();
  8105. }
  8106. stopwatch1.Stop();
  8107. AddMessage(LogType.Info,
  8108. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8109. stopwatch2.ElapsedMilliseconds + "ms");
  8110. }
  8111. #endregion [S2] FCT(板测)
  8112. #endregion PLC2 李晓奇
  8113. #region PLC3 刘永村
  8114. #region [S3] 值板机
  8115. /// <summary>
  8116. /// S3工位的数据- 触发信号上次的值
  8117. /// </summary>
  8118. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  8119. /// <summary>
  8120. /// S3工位的数据(含触发信号)
  8121. /// </summary>
  8122. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  8123. /// <summary>
  8124. /// S3工位的数据- 回写点位
  8125. /// </summary>
  8126. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8127. /// <summary>
  8128. /// [S3] 值板机
  8129. /// </summary>
  8130. /// <param name="plcNo">PLC编号</param>
  8131. //private void ReadStation_S3(int plcNo)
  8132. //{
  8133. // // [S1] Tray盘上料装备
  8134. // // [S2] FCT
  8135. // // [S3] 值板机
  8136. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8137. // // [S5] Tray盘下料装备
  8138. // /// 上位机心跳
  8139. // /// 获取设备报警数据与状态信息
  8140. // string stationCode = "[S3]";
  8141. // string stationName = "值板机";
  8142. // string stationNameStr = stationCode + stationName;
  8143. // #region 创建字典
  8144. // // 触发信号字典 赋值
  8145. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8146. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  8147. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  8148. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8149. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8150. // // PLC数据字典 赋值
  8151. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8152. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  8153. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8154. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  8155. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  8156. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8157. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8158. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  8159. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  8160. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8161. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  8162. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  8163. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8164. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8165. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  8166. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  8167. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  8168. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8169. // s3PLCData.Add("c1Result", 0); // 产品结果
  8170. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8171. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  8172. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  8173. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  8174. // #endregion 创建字典
  8175. // while (IsRun)
  8176. // {
  8177. // try
  8178. // {
  8179. // if (!GlobalContext._IsCon_Funs3)
  8180. // {
  8181. // UpdatePLCMonitor(1, plcNo, 0);
  8182. // continue;
  8183. // }
  8184. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8185. // {
  8186. // Stopwatch stopwatch1 = new Stopwatch();
  8187. // Stopwatch stopwatch2 = new Stopwatch();
  8188. // stopwatch1.Start();
  8189. // stopwatch2.Start();
  8190. // #region 一次性读取所有数据
  8191. // // 一次性读取所有数据
  8192. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  8193. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8194. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  8195. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  8196. // int[] datas = data1.Concat(data2).ToArray();
  8197. // datas = datas.Concat(data3).ToArray();
  8198. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  8199. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  8200. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8201. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  8202. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  8203. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  8204. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8205. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  8206. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  8207. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  8208. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  8209. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8210. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  8211. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  8212. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  8213. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  8214. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8215. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  8216. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  8217. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  8218. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  8219. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  8220. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  8221. // #endregion 一次性读取所有数据
  8222. // stopwatch2.Stop();
  8223. // #region 回写操作,写后清空flag
  8224. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  8225. // #endregion 回写操作,写后清空flag
  8226. // #region S3进站校验
  8227. // try
  8228. // {
  8229. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  8230. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  8231. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  8232. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  8233. // {
  8234. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  8235. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8236. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  8237. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8238. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  8239. // }
  8240. // }
  8241. // catch (Exception ex)
  8242. // {
  8243. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8244. // string str = ex.StackTrace;
  8245. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8246. // }
  8247. // #endregion S3进站校验
  8248. // #region S3二穴载具解绑
  8249. // try
  8250. // {
  8251. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  8252. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  8253. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  8254. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  8255. // {
  8256. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  8257. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  8258. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  8259. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  8260. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  8261. // }
  8262. // }
  8263. // catch (Exception ex)
  8264. // {
  8265. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  8266. // string str = ex.StackTrace;
  8267. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8268. // }
  8269. // #endregion S3二穴载具解绑
  8270. // #region S3二穴载具绑定
  8271. // try
  8272. // {
  8273. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  8274. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  8275. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  8276. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  8277. // {
  8278. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  8279. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  8280. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  8281. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  8282. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  8283. // }
  8284. // }
  8285. // catch (Exception ex)
  8286. // {
  8287. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  8288. // string str = ex.StackTrace;
  8289. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8290. // }
  8291. // #endregion S3二穴载具绑定
  8292. // #region S3出站接口(+一穴载具绑定)
  8293. // try
  8294. // {
  8295. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  8296. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  8297. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  8298. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  8299. // {
  8300. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  8301. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8302. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  8303. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  8304. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  8305. // }
  8306. // }
  8307. // catch (Exception ex)
  8308. // {
  8309. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  8310. // string str = ex.StackTrace;
  8311. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8312. // }
  8313. // #endregion S3出站接口(+一穴载具绑定)
  8314. // #region S3节拍接口
  8315. // try
  8316. // {
  8317. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  8318. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  8319. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  8320. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  8321. // {
  8322. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  8323. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8324. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  8325. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  8326. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  8327. // }
  8328. // }
  8329. // catch (Exception ex)
  8330. // {
  8331. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  8332. // string str = ex.StackTrace;
  8333. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8334. // }
  8335. // #endregion S3节拍接口
  8336. // #region 心跳
  8337. // try
  8338. // {
  8339. // short states = 0;
  8340. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  8341. // }
  8342. // catch (Exception ex)
  8343. // {
  8344. // string str = ex.StackTrace;
  8345. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8346. // }
  8347. // #endregion 心跳
  8348. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  8349. // stopwatch1.Stop();
  8350. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  8351. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  8352. // }
  8353. // else
  8354. // {
  8355. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8356. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  8357. // Funs[plcNo].Connect();
  8358. // }
  8359. // }
  8360. // catch (Exception ex)
  8361. // {
  8362. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8363. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  8364. // Funs[plcNo].ReConnect();
  8365. // }
  8366. // Thread.Sleep(IntervalReadPLC);
  8367. // }
  8368. //}
  8369. /// <summary>
  8370. /// [S3] 值板机- 进站校验
  8371. /// </summary>
  8372. /// <param name="plcNo">PLC编号</param>
  8373. /// <param name="stationNameStr">工站全称</param>
  8374. private void S3进站校验(int plcNo, string stationNameStr)
  8375. {
  8376. Stopwatch stopwatch1 = new Stopwatch();
  8377. Stopwatch stopwatch2 = new Stopwatch();
  8378. try
  8379. {
  8380. stopwatch1.Start();
  8381. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  8382. sn = sn.Replace("\0", "");
  8383. #region 查询载具上的产品信息
  8384. string cavityData = string.Empty;
  8385. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  8386. if (string.IsNullOrEmpty(cavityData))
  8387. cavityData = "";
  8388. if (snResult != 0)
  8389. {
  8390. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8391. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  8392. writeToPLC_Flag1.Adress = 2003;
  8393. writeToPLC_Flag1.Value = (short)6;
  8394. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  8395. stopwatch1.Stop();
  8396. AddMessage(LogType.Info,
  8397. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8398. return;
  8399. }
  8400. #endregion 查询载具上的产品信息
  8401. string[] cavitySNs = cavityData.Split('.');
  8402. string part1Str = ""; // 产品1的SN码
  8403. string part2Str = ""; // 产品2的SN码
  8404. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  8405. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  8406. if (cavitySNs != null && cavitySNs.Length >= 2)
  8407. {
  8408. part1Str = cavitySNs[0];
  8409. part2Str = cavitySNs[1];
  8410. c1Part1Result_Check = 2;
  8411. c1Part2Result_Check = 2;
  8412. }
  8413. if (part1Str == "假产品")
  8414. c1Part1Result_Check = 3;
  8415. if (part2Str == "假产品")
  8416. c1Part2Result_Check = 3;
  8417. // 调用MES进站
  8418. stopwatch2.Start();
  8419. // 调用MES进站 - 产品1
  8420. List<TestItem> item;
  8421. int result1 = c1Part1Result_Check;
  8422. if (result1 != 3)
  8423. {
  8424. item = new List<TestItem>();
  8425. item.Add(new TestItem()
  8426. {
  8427. Parameter_name = "载具码",
  8428. Parameter_value = sn,
  8429. });
  8430. item.Add(new TestItem()
  8431. {
  8432. Parameter_name = "载具穴号",
  8433. Parameter_value = "1",
  8434. });
  8435. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8436. part1Str, item, out string errorMsg);
  8437. }
  8438. // 调用MES进站 - 产品2
  8439. int result2 = c1Part2Result_Check;
  8440. if (result2 != 3)
  8441. {
  8442. item = new List<TestItem>();
  8443. item.Add(new TestItem()
  8444. {
  8445. Parameter_name = "载具码",
  8446. Parameter_value = sn,
  8447. });
  8448. item.Add(new TestItem()
  8449. {
  8450. Parameter_name = "载具穴号",
  8451. Parameter_value = "2",
  8452. });
  8453. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8454. part2Str, item, out string errorMsg);
  8455. }
  8456. stopwatch2.Stop();
  8457. if (result1 == 2)
  8458. c1Part1Result_Check = 2;
  8459. if (result2 == 2)
  8460. c1Part2Result_Check = 2;
  8461. int result = result1;
  8462. if (result == 1)
  8463. result = result2;
  8464. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  8465. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  8466. short c1MES_FLAG_Check = (short)result;
  8467. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  8468. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  8469. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  8470. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  8471. //// MES_Flag
  8472. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8473. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8474. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  8475. writeToPLC_Flag.Adress = 2003;
  8476. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  8477. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8478. {
  8479. Name = "c1Part1Result_Check",
  8480. Adress = 2024,
  8481. ValueType = PLCValueType.Short,
  8482. Value = c1Part1Result_Check
  8483. });
  8484. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8485. {
  8486. Name = "c1Part2Result_Check",
  8487. Adress = 2025,
  8488. ValueType = PLCValueType.Short,
  8489. Value = c1Part2Result_Check
  8490. });
  8491. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8492. {
  8493. Name = "c1Part1Num_Check",
  8494. Adress = 2026,
  8495. ValueType = PLCValueType.Short,
  8496. Value = c1Part1Num_Check
  8497. });
  8498. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8499. {
  8500. Name = "c1Part2Num_Check",
  8501. Adress = 2027,
  8502. ValueType = PLCValueType.Short,
  8503. Value = c1Part2Num_Check
  8504. });
  8505. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  8506. }
  8507. catch (Exception ex)
  8508. {
  8509. string str = ex.StackTrace;
  8510. AddMessage_Station(stationNameStr, LogType.Error,
  8511. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  8512. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8513. // MES_Flag
  8514. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8515. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8516. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  8517. writeToPLC_Flag.Adress = 2003;
  8518. writeToPLC_Flag.Value = (short)6;
  8519. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  8520. }
  8521. stopwatch1.Stop();
  8522. AddMessage(LogType.Info,
  8523. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  8524. stopwatch2.ElapsedMilliseconds + "ms");
  8525. }
  8526. /// <summary>
  8527. /// [S3] 值板机 - 二穴载具解绑
  8528. /// </summary>
  8529. /// <param name="plcNo">PLC编号</param>
  8530. /// <param name="stationNameStr">工站全称</param>
  8531. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  8532. {
  8533. Stopwatch stopwatch1 = new Stopwatch();
  8534. Stopwatch stopwatch2 = new Stopwatch();
  8535. try
  8536. {
  8537. stopwatch1.Start();
  8538. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  8539. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8540. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8541. // 解绑
  8542. #region 查询载具上的产品信息
  8543. string cavityData = string.Empty;
  8544. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8545. if (string.IsNullOrEmpty(cavityData))
  8546. cavityData = "";
  8547. if (snResult != 0)
  8548. {
  8549. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8550. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  8551. writeToPLC_Flag1.Adress = 2082;
  8552. writeToPLC_Flag1.Value = (short)6;
  8553. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  8554. stopwatch1.Stop();
  8555. AddMessage(LogType.Info,
  8556. stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8557. "ms");
  8558. return;
  8559. }
  8560. #endregion 查询载具上的产品信息
  8561. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  8562. #region 解绑
  8563. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  8564. {
  8565. // 删除
  8566. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8567. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  8568. }
  8569. else
  8570. {
  8571. string data_new = string.Join(".", cavitySNs);
  8572. // 删除再插入
  8573. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8574. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  8575. OnMessage(LogType.Debug,
  8576. $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  8577. }
  8578. #endregion 解绑
  8579. short c1MES_FLAG_Unbind = 1;
  8580. stopwatch2.Start();
  8581. // MES_Flag
  8582. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8583. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8584. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  8585. writeToPLC_Flag.Adress = 2082;
  8586. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  8587. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  8588. stopwatch2.Stop();
  8589. }
  8590. catch (Exception ex)
  8591. {
  8592. string str = ex.StackTrace;
  8593. AddMessage_Station(stationNameStr, LogType.Error,
  8594. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" +
  8595. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8596. // MES_Flag
  8597. stopwatch2.Start();
  8598. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  8599. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8600. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  8601. writeToPLC_Flag.Adress = 2082;
  8602. writeToPLC_Flag.Value = (short)6;
  8603. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  8604. stopwatch2.Stop();
  8605. }
  8606. stopwatch1.Stop();
  8607. AddMessage(LogType.Info,
  8608. stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8609. stopwatch2.ElapsedMilliseconds + "ms");
  8610. }
  8611. /// <summary>
  8612. /// [S3] 值板机 - 二穴载具绑定
  8613. /// </summary>
  8614. /// <param name="plcNo">PLC编号</param>
  8615. /// <param name="stationNameStr">工站全称</param>
  8616. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  8617. {
  8618. Stopwatch stopwatch1 = new Stopwatch();
  8619. Stopwatch stopwatch2 = new Stopwatch();
  8620. try
  8621. {
  8622. stopwatch1.Start();
  8623. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  8624. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8625. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  8626. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  8627. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8628. stopwatch2.Start();
  8629. #region 查询载具上的产品信息
  8630. string cavityData = string.Empty;
  8631. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8632. if (string.IsNullOrEmpty(cavityData))
  8633. cavityData = "";
  8634. if (snResult != 0)
  8635. {
  8636. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8637. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  8638. writeToPLC_Flag1.Adress = 2115;
  8639. writeToPLC_Flag1.Value = (short)6;
  8640. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  8641. stopwatch1.Stop();
  8642. AddMessage(LogType.Info,
  8643. stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8644. "ms");
  8645. return;
  8646. }
  8647. #endregion 查询载具上的产品信息
  8648. // 产品换载具
  8649. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  8650. string partSn1 = "";
  8651. string partSn2 = "";
  8652. if (cavitySNs != null && cavitySNs.Length >= 2)
  8653. {
  8654. partSn1 = cavitySNs[0];
  8655. partSn2 = cavitySNs[1];
  8656. }
  8657. string data_new = string.Empty;
  8658. // 是否是两个穴位交换
  8659. if (c1CavityReverse_Bind == 1)
  8660. {
  8661. // 交换
  8662. data_new = string.Concat(partSn2, ".", partSn1);
  8663. }
  8664. else
  8665. {
  8666. // 不交换
  8667. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  8668. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  8669. cavitySNs[c1VehicleCavityFr_Bind] = "";
  8670. data_new = string.Join(".", cavitySNs);
  8671. }
  8672. // 删除再插入
  8673. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8674. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  8675. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  8676. stopwatch2.Stop();
  8677. short c1MES_FLAG_Bind = 1;
  8678. // MES_Flag
  8679. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8680. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8681. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  8682. writeToPLC_Flag.Adress = 2115;
  8683. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  8684. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  8685. }
  8686. catch (Exception ex)
  8687. {
  8688. string str = ex.StackTrace;
  8689. AddMessage_Station(stationNameStr, LogType.Error,
  8690. $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" +
  8691. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8692. // MES_Flag
  8693. stopwatch2.Start();
  8694. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  8695. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8696. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  8697. writeToPLC_Flag.Adress = 2115;
  8698. writeToPLC_Flag.Value = (short)6;
  8699. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  8700. stopwatch2.Stop();
  8701. }
  8702. stopwatch1.Stop();
  8703. AddMessage(LogType.Info,
  8704. stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8705. stopwatch2.ElapsedMilliseconds + "ms");
  8706. }
  8707. //// 上次采集到的SN
  8708. //private string sn_值板机 = string.Empty;
  8709. /// <summary>
  8710. /// [S3] 值板机 - 出站接口
  8711. /// </summary>
  8712. /// <param name="plcNo">PLC编号</param>
  8713. private void S3出站接口(int plcNo, string stationCode, string stationName)
  8714. {
  8715. Stopwatch stopwatch1 = new Stopwatch();
  8716. Stopwatch stopwatch2 = new Stopwatch();
  8717. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8718. string stationNameStr = stationCode + stationName;
  8719. string processItem = stationName; // 测试项目
  8720. try
  8721. {
  8722. stopwatch1.Start();
  8723. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8724. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8725. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8726. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8727. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  8728. sn = sn.Replace("\0", "");
  8729. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  8730. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8731. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8732. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  8733. bool pass = c1Result == 1;
  8734. // 查sn
  8735. #region 查询载具上的产品信息
  8736. string cavityData = string.Empty;
  8737. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8738. if (string.IsNullOrEmpty(cavityData))
  8739. cavityData = "";
  8740. if (snResult != 0)
  8741. {
  8742. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8743. writeToPLC_Flag1.Name = "c1MES_FLAG";
  8744. writeToPLC_Flag1.Adress = 2150;
  8745. writeToPLC_Flag1.Value = (short)4;
  8746. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  8747. stopwatch1.Stop();
  8748. AddMessage(LogType.Info,
  8749. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8750. return;
  8751. }
  8752. #endregion 查询载具上的产品信息
  8753. string[] cavitySNs = cavityData.Split('.');
  8754. string productSN = "";
  8755. if (cavitySNs != null && cavitySNs.Length >= 2)
  8756. {
  8757. productSN = cavitySNs[c1VehicleCavity];
  8758. cavitySNs[c1VehicleCavity] = "";
  8759. }
  8760. stopwatch2.Start();
  8761. List<TestItem> items = new List<TestItem>();
  8762. items.Add(new TestItem()
  8763. {
  8764. Parameter_name = "二穴载具码",
  8765. Parameter_value = c1ProductSN_Check,
  8766. Parameter_unit = ""
  8767. });
  8768. items.Add(new TestItem()
  8769. {
  8770. Parameter_name = "二穴载具穴号",
  8771. Parameter_value = c1VehicleCavity.ToString(),
  8772. Parameter_unit = ""
  8773. });
  8774. items.Add(new TestItem()
  8775. {
  8776. Parameter_name = "一穴载具码",
  8777. Parameter_value = sn,
  8778. Parameter_unit = ""
  8779. });
  8780. items.Add(new TestItem()
  8781. {
  8782. Parameter_name = "一穴载具穴号",
  8783. Parameter_value = "1",
  8784. Parameter_unit = ""
  8785. });
  8786. items.Add(new TestItem()
  8787. {
  8788. Parameter_name = "产品结果",
  8789. Parameter_value = c1Result == 1 ? "OK" : "NG",
  8790. Parameter_unit = ""
  8791. });
  8792. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  8793. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  8794. short result = (short)result1;
  8795. stopwatch2.Stop();
  8796. #region 存储绑定数据到 边线MES系统中
  8797. if (result == 1)
  8798. {
  8799. string data = string.Concat(productSN);
  8800. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  8801. if (resultMesR != 0)
  8802. {
  8803. result = 4;
  8804. AddMessage_Station(stationNameStr, LogType.Error,
  8805. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  8806. }
  8807. }
  8808. #endregion 存储绑定数据到 边线MES系统中
  8809. #region 产品从 来源载具(二穴载具)中删除
  8810. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  8811. {
  8812. // 删除
  8813. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8814. OnMessage(LogType.Debug,
  8815. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  8816. }
  8817. else
  8818. {
  8819. string data_new = string.Join(".", cavitySNs);
  8820. // 删除再插入
  8821. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8822. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  8823. OnMessage(LogType.Debug,
  8824. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  8825. }
  8826. #endregion 产品从 来源载具(二穴载具)中删除
  8827. // MES_Flag 为MES报错
  8828. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8829. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  8830. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8831. writeToPLC_Flag.Name = "c1MES_FLAG";
  8832. writeToPLC_Flag.Adress = 2150;
  8833. writeToPLC_Flag.Value = result;
  8834. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  8835. OnMessage(LogType.Debug,
  8836. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8837. }
  8838. catch (Exception ex)
  8839. {
  8840. stopwatch2.Restart();
  8841. // MES_Flag 为4上位机报错
  8842. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  8843. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8844. writeToPLC_Flag.Name = "c1MES_FLAG";
  8845. writeToPLC_Flag.Adress = 2150;
  8846. writeToPLC_Flag.Value = (short)4;
  8847. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  8848. stopwatch2.Stop();
  8849. string str = ex.StackTrace;
  8850. AddMessage_Station(stationNameStr, LogType.Error,
  8851. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  8852. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8853. }
  8854. stopwatch1.Stop();
  8855. AddMessage(LogType.Info,
  8856. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  8857. stopwatch2.ElapsedMilliseconds + "ms");
  8858. }
  8859. /// <summary>
  8860. /// [S3] 值板机- 节拍接口
  8861. /// </summary>
  8862. /// <param name="plcNo">PLC编号</param>
  8863. /// <param name="stationNameStr">工站全称</param>
  8864. private void S3节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
  8865. {
  8866. Stopwatch stopwatch1 = new Stopwatch();
  8867. Stopwatch stopwatch2 = new Stopwatch();
  8868. string resultStr = string.Empty;
  8869. try
  8870. {
  8871. stopwatch1.Start();
  8872. string oEEType = ((int)s1PLCData["a3OEEType"]).ToString(); // 节拍类型(plc写入)
  8873. string a3OEEPartNo = (string)s1PLCData["a3OEEPartNo"]; // 物料码
  8874. a3OEEPartNo = a3OEEPartNo.Replace("\0", "");
  8875. string a3OEEVehicleCode = (string)s1PLCData["a3OEEVehicleCode"]; // 载具SN
  8876. a3OEEVehicleCode = a3OEEVehicleCode.Replace("\0", "");
  8877. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8878. if (!actionBool)
  8879. {
  8880. stopwatch2.Start();
  8881. //写入PLC
  8882. iot_data.beatReturn = 2; //NG
  8883. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8884. stopwatch2.Stop();
  8885. AddMessage(LogType.Info,
  8886. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  8887. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8888. return;
  8889. }
  8890. //作业开始后要有物料和载具信息
  8891. if (string.IsNullOrEmpty(a3OEEPartNo) && string.IsNullOrEmpty(a3OEEVehicleCode) &&
  8892. Convert.ToInt32(oEEType) > 2)
  8893. {
  8894. stopwatch2.Start();
  8895. //写入PLC
  8896. iot_data.beatReturn = 2; //NG
  8897. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8898. stopwatch2.Stop();
  8899. AddMessage_Station(stationNameStr, LogType.Info,
  8900. stationNameStr + $"_[{a3OEEVehicleCode}][{a3OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
  8901. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8902. return;
  8903. }
  8904. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a3OEEPartNo))
  8905. {
  8906. stopwatch2.Start();
  8907. //写入PLC
  8908. iot_data.beatReturn = 2; //NG
  8909. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8910. stopwatch2.Stop();
  8911. AddMessage_Station(stationNameStr, LogType.Info,
  8912. stationNameStr + $"_[{a3OEEVehicleCode}][{a3OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
  8913. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8914. return;
  8915. }
  8916. else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a3OEEVehicleCode))
  8917. {
  8918. stopwatch2.Start();
  8919. //写入PLC
  8920. iot_data.beatReturn = 2; //NG
  8921. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8922. stopwatch2.Stop();
  8923. AddMessage_Station(stationNameStr, LogType.Info,
  8924. stationNameStr + $"_[{a3OEEVehicleCode}][{a3OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
  8925. stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8926. return;
  8927. }
  8928. short _result = 0;
  8929. // 上传OEE
  8930. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a3OEEPartNo, a3OEEVehicleCode);
  8931. _result = result.Item1;
  8932. resultStr = result.Item2;
  8933. if (_result == 1)
  8934. {
  8935. stopwatch2.Start();
  8936. //写入PLC
  8937. iot_data.beatReturn = 1; //OK
  8938. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8939. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
  8940. stopwatch2.Stop();
  8941. }
  8942. else
  8943. {
  8944. stopwatch2.Start();
  8945. //写入PLC
  8946. iot_data.beatReturn = 2; //NG
  8947. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8948. stopwatch2.Stop();
  8949. AddMessage_Station(stationNameStr, LogType.Error,
  8950. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
  8951. }
  8952. }
  8953. catch (Exception ex)
  8954. {
  8955. string str = ex.StackTrace;
  8956. AddMessage_Station(stationNameStr, LogType.Error,
  8957. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  8958. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8959. // MES_Flag
  8960. stopwatch2.Start();
  8961. //写入PLC
  8962. iot_data.beatReturn = 2; //NG
  8963. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
  8964. stopwatch2.Stop();
  8965. }
  8966. stopwatch1.Stop();
  8967. AddMessage(LogType.Info,
  8968. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8969. stopwatch2.ElapsedMilliseconds + "ms");
  8970. }
  8971. #endregion [S3] 值板机
  8972. #endregion PLC3 刘永村
  8973. #region PLC4 刘果段
  8974. #region [S4] 取放桁架
  8975. /// <summary>
  8976. /// S4工位的数据- 触发信号上次的值
  8977. /// </summary>
  8978. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  8979. /// <summary>
  8980. /// S4工位的数据(含触发信号)
  8981. /// </summary>
  8982. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  8983. /// <summary>
  8984. /// S4工位的数据- 回写点位
  8985. /// </summary>
  8986. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8987. /// <summary>
  8988. /// [S4] 取放桁架
  8989. /// </summary>
  8990. /// <param name="plcNo">PLC编号</param>
  8991. //private void ReadStation_S4(int plcNo)
  8992. //{
  8993. // // [S1] Tray盘上料装备
  8994. // // [S2] FCT
  8995. // // [S3] 值板机
  8996. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8997. // // [S5] Tray盘下料装备
  8998. // /// 上位机心跳
  8999. // /// 获取设备报警数据与状态信息
  9000. // string stationCode = "[S4_1]";
  9001. // string stationName = "载具下线装备";
  9002. // string stationNameStr = stationCode + stationName;
  9003. // string stationCode2 = "[S4_2]";
  9004. // string stationName2 = "桁架";
  9005. // string stationNameStr2 = stationCode2 + stationName2;
  9006. // string stationCode3 = "[S4_3]";
  9007. // string stationName3 = "提升机1";
  9008. // string stationNameStr3 = stationCode3 + stationName3;
  9009. // string stationCode4 = "[S4_4]";
  9010. // string stationName4 = "提升机2";
  9011. // string stationNameStr4 = stationCode4 + stationName4;
  9012. // string stationCode5 = "[S4_5]";
  9013. // string stationName5 = "载具上线装备";
  9014. // string stationNameStr5 = stationCode5 + stationName5;
  9015. // #region 创建字典
  9016. // // 触发信号字典 赋值
  9017. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9018. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  9019. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  9020. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9021. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  9022. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  9023. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  9024. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9025. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  9026. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  9027. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9028. // // PLC数据字典 赋值
  9029. // // 载具下线装备(弹夹上线)
  9030. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9031. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  9032. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  9033. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  9034. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  9035. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  9036. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  9037. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  9038. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  9039. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  9040. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  9041. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  9042. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  9043. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  9044. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  9045. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  9046. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  9047. // s4PLCData.Add("d1Result", 0); // 产品结果
  9048. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9049. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  9050. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  9051. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  9052. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  9053. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  9054. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  9055. // // 真空标机(提升机)
  9056. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  9057. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  9058. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  9059. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  9060. // s4PLCData.Add("d3Result", 0); // 产品结果
  9061. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  9062. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  9063. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  9064. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  9065. // s4PLCData.Add("d4Result", 0); // 产品结果
  9066. // // 载具上线装备(弹夹下线)
  9067. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9068. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  9069. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  9070. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  9071. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  9072. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  9073. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  9074. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  9075. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  9076. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  9077. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  9078. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  9079. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  9080. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  9081. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  9082. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  9083. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  9084. // s4PLCData.Add("d5Result", 0); // 产品结果
  9085. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9086. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  9087. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  9088. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  9089. // #endregion 创建字典
  9090. // while (IsRun)
  9091. // {
  9092. // try
  9093. // {
  9094. // if (!GlobalContext._IsCon_Funs4)
  9095. // {
  9096. // UpdatePLCMonitor(1, plcNo, 0);
  9097. // continue;
  9098. // }
  9099. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  9100. // {
  9101. // Stopwatch stopwatch1 = new Stopwatch();
  9102. // Stopwatch stopwatch2 = new Stopwatch();
  9103. // stopwatch1.Start();
  9104. // stopwatch2.Start();
  9105. // #region 一次性读取所有数据
  9106. // // 载具下线装备(弹夹上线)
  9107. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  9108. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  9109. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  9110. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  9111. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  9112. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  9113. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  9114. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  9115. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  9116. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  9117. // int[] datas = data1.Concat(data2).ToArray();
  9118. // datas = datas.Concat(data3).ToArray();
  9119. // datas = datas.Concat(data4).ToArray();
  9120. // datas = datas.Concat(data5).ToArray();
  9121. // datas = datas.Concat(data6).ToArray();
  9122. // datas = datas.Concat(data7).ToArray();
  9123. // datas = datas.Concat(data8).ToArray();
  9124. // datas = datas.Concat(data9).ToArray();
  9125. // datas = datas.Concat(data10).ToArray();
  9126. // // 载具下线装备(弹夹上线)
  9127. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  9128. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  9129. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  9130. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  9131. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  9132. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  9133. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  9134. // s4PLCData["d1MES_FLAG"] = datas[65];
  9135. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  9136. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  9137. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  9138. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  9139. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  9140. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  9141. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  9142. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  9143. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  9144. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  9145. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  9146. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  9147. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  9148. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  9149. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  9150. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  9151. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  9152. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  9153. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  9154. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  9155. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  9156. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  9157. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  9158. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  9159. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  9160. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  9161. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  9162. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  9163. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  9164. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  9165. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  9166. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  9167. // s4PLCData["d1Result"] = datas[386];
  9168. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  9169. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  9170. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  9171. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  9172. // s4PLCData["d1OEEType"] = datas[419];
  9173. // // 桁架(查询标机中弹夹的状态)
  9174. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  9175. // s4PLCData["d2BulletclipStates"] = datas[431];
  9176. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  9177. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  9178. // // 真空标机
  9179. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  9180. // s4PLCData["d3MES_FLAG"] = datas[463];
  9181. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  9182. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  9183. // s4PLCData["d3Result"] = datas[484];
  9184. // s4PLCData["d3Type"] = datas[485];
  9185. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  9186. // s4PLCData["d4MES_FLAG"] = datas[496];
  9187. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  9188. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  9189. // s4PLCData["d4Result"] = datas[517];
  9190. // s4PLCData["d4Type"] = datas[518];
  9191. // // 载具上线装备(弹夹下线)
  9192. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  9193. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  9194. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  9195. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  9196. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  9197. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  9198. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  9199. // s4PLCData["d5MES_FLAG"] = datas[591];
  9200. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  9201. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  9202. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  9203. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  9204. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  9205. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  9206. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  9207. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  9208. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  9209. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  9210. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  9211. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  9212. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  9213. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  9214. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  9215. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  9216. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  9217. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  9218. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  9219. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  9220. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  9221. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  9222. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  9223. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  9224. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  9225. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  9226. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  9227. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  9228. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  9229. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  9230. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  9231. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  9232. // s4PLCData["d5Result"] = datas[912];
  9233. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  9234. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  9235. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  9236. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  9237. // s4PLCData["d5OEEType"] = datas[945];
  9238. // #endregion 一次性读取所有数据
  9239. // stopwatch2.Stop();
  9240. // #region 回写操作,写后清空flag
  9241. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  9242. // #endregion 回写操作,写后清空flag
  9243. // // N801A-S4_1 弹夹扫码
  9244. // #region N801A-S4_1 弹夹扫码
  9245. // try
  9246. // {
  9247. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  9248. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  9249. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  9250. // {
  9251. // if (d1BulletclipScanCode == 1) // 0->1
  9252. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  9253. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  9254. // }
  9255. // }
  9256. // catch (Exception ex)
  9257. // {
  9258. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  9259. // string str = ex.StackTrace;
  9260. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9261. // }
  9262. // #endregion N801A-S4_1 弹夹扫码
  9263. // // N801A-S4_1 载具扫码
  9264. // #region N801A-S4_1 载具扫码
  9265. // try
  9266. // {
  9267. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  9268. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  9269. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  9270. // {
  9271. // if (d1VehicleScanCode == 1) // 0->1
  9272. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  9273. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  9274. // }
  9275. // }
  9276. // catch (Exception ex)
  9277. // {
  9278. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  9279. // string str = ex.StackTrace;
  9280. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9281. // }
  9282. // #endregion N801A-S4_1 载具扫码
  9283. // // N801A-S4_1 出站接口
  9284. // #region N801A-S4_1 出站接口
  9285. // try
  9286. // {
  9287. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  9288. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  9289. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  9290. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  9291. // {
  9292. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  9293. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  9294. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  9295. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  9296. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  9297. // }
  9298. // }
  9299. // catch (Exception ex)
  9300. // {
  9301. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  9302. // string str = ex.StackTrace;
  9303. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9304. // }
  9305. // #endregion N801A-S4_1 出站接口
  9306. // // N801A-S4_1 节拍接口
  9307. // #region N801A-S4_1 节拍接口
  9308. // try
  9309. // {
  9310. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  9311. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  9312. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  9313. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  9314. // {
  9315. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  9316. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  9317. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  9318. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  9319. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  9320. // }
  9321. // }
  9322. // catch (Exception ex)
  9323. // {
  9324. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  9325. // string str = ex.StackTrace;
  9326. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9327. // }
  9328. // #endregion N801A-S4_1 节拍接口
  9329. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  9330. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  9331. // try
  9332. // {
  9333. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  9334. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  9335. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  9336. // {
  9337. // if (d2BulletclipScanCode == 1) // 0->1
  9338. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  9339. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  9340. // }
  9341. // }
  9342. // catch (Exception ex)
  9343. // {
  9344. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  9345. // string str = ex.StackTrace;
  9346. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9347. // }
  9348. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  9349. // // N801A-S4_3 真空标机1 数据
  9350. // #region N801A-S4_3 真空标机1
  9351. // try
  9352. // {
  9353. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  9354. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  9355. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  9356. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  9357. // {
  9358. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  9359. // {
  9360. // int stationType = (int)s4PLCData["d3Type"];
  9361. // if (stationType == 1)
  9362. // {
  9363. // // S4_3进站接口
  9364. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  9365. // }
  9366. // else if (stationType == 2)
  9367. // {
  9368. // // S4_3出站接口
  9369. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  9370. // }
  9371. // }
  9372. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  9373. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  9374. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  9375. // }
  9376. // }
  9377. // catch (Exception ex)
  9378. // {
  9379. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  9380. // string str = ex.StackTrace;
  9381. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9382. // }
  9383. // #endregion N801A-S4_3 真空标机1
  9384. // // N801A-S4_4 真空标机2 数据
  9385. // #region N801A-S4_4 真空标机2
  9386. // try
  9387. // {
  9388. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  9389. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  9390. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  9391. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  9392. // {
  9393. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  9394. // {
  9395. // int stationType = (int)s4PLCData["d4Type"];
  9396. // if (stationType == 1)
  9397. // {
  9398. // // S4_4进站接口
  9399. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  9400. // }
  9401. // else if (stationType == 2)
  9402. // {
  9403. // // S4_4出站接口
  9404. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  9405. // }
  9406. // }
  9407. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  9408. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  9409. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  9410. // }
  9411. // }
  9412. // catch (Exception ex)
  9413. // {
  9414. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  9415. // string str = ex.StackTrace;
  9416. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9417. // }
  9418. // #endregion N801A-S4_4 真空标机2
  9419. // // N801A-S4_5 弹夹扫码 数据
  9420. // #region N801A-S4_5 弹夹扫码
  9421. // try
  9422. // {
  9423. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  9424. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  9425. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  9426. // {
  9427. // if (d5BulletclipScanCode == 1) // 0->1
  9428. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  9429. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  9430. // }
  9431. // }
  9432. // catch (Exception ex)
  9433. // {
  9434. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  9435. // string str = ex.StackTrace;
  9436. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9437. // }
  9438. // #endregion N801A-S4_5 弹夹扫码
  9439. // // N801A-S4_5 载具扫码 数据
  9440. // #region N801A-S4_5 载具扫码
  9441. // try
  9442. // {
  9443. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  9444. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  9445. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  9446. // {
  9447. // if (d5VehicleScanCode == 1) // 0->1
  9448. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  9449. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  9450. // }
  9451. // }
  9452. // catch (Exception ex)
  9453. // {
  9454. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  9455. // string str = ex.StackTrace;
  9456. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9457. // }
  9458. // #endregion N801A-S4_5 载具扫码
  9459. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  9460. // #region N801A-S4_5 出站接口
  9461. // try
  9462. // {
  9463. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  9464. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  9465. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  9466. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  9467. // {
  9468. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  9469. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  9470. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  9471. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  9472. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  9473. // }
  9474. // }
  9475. // catch (Exception ex)
  9476. // {
  9477. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  9478. // string str = ex.StackTrace;
  9479. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9480. // }
  9481. // #endregion N801A-S4_5 出站接口
  9482. // // N801A-S4_5 节拍接口 数据
  9483. // #region N801A-S4_5 节拍接口
  9484. // try
  9485. // {
  9486. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  9487. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  9488. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  9489. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  9490. // {
  9491. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  9492. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  9493. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  9494. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  9495. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  9496. // }
  9497. // }
  9498. // catch (Exception ex)
  9499. // {
  9500. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  9501. // string str = ex.StackTrace;
  9502. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9503. // }
  9504. // #endregion N801A-S4_5 节拍接口
  9505. // #region 心跳
  9506. // try
  9507. // {
  9508. // short states = 0;
  9509. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  9510. // }
  9511. // catch (Exception ex)
  9512. // {
  9513. // string str = ex.StackTrace;
  9514. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9515. // }
  9516. // #endregion 心跳
  9517. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  9518. // stopwatch1.Stop();
  9519. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  9520. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  9521. // }
  9522. // else
  9523. // {
  9524. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9525. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  9526. // Funs[plcNo].Connect();
  9527. // }
  9528. // }
  9529. // catch (Exception ex)
  9530. // {
  9531. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9532. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  9533. // Funs[plcNo].ReConnect();
  9534. // }
  9535. // Thread.Sleep(IntervalReadPLC);
  9536. // }
  9537. //}
  9538. /// <summary>
  9539. /// [S4] 取放桁架 - S4_1弹夹扫码
  9540. /// </summary>
  9541. /// <param name="plcNo">PLC编号</param>
  9542. /// <param name="stationNameStr">工站全称</param>
  9543. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  9544. {
  9545. Stopwatch stopwatch1 = new Stopwatch();
  9546. Stopwatch stopwatch2 = new Stopwatch();
  9547. try
  9548. {
  9549. stopwatch1.Start();
  9550. // ZS 弹夹扫码
  9551. string d1BulletclipCode = " "; // 扫到的码
  9552. short d1BulletclipScanCode = 2;
  9553. stopwatch2.Start();
  9554. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  9555. //// MES_Flag
  9556. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  9557. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9558. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  9559. writeToPLC_Flag.Adress = 2002;
  9560. writeToPLC_Flag.Value = d1BulletclipScanCode;
  9561. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  9562. {
  9563. Name = "d1BulletclipCode",
  9564. Adress = 2003,
  9565. ValueType = PLCValueType.String,
  9566. ValueTypeStrLength = 20,
  9567. Value = d1BulletclipCode
  9568. });
  9569. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  9570. stopwatch2.Stop();
  9571. }
  9572. catch (Exception ex)
  9573. {
  9574. string str = ex.StackTrace;
  9575. AddMessage_Station(stationNameStr, LogType.Error,
  9576. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  9577. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9578. stopwatch2.Start();
  9579. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  9580. //// MES_Flag
  9581. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  9582. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9583. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  9584. writeToPLC_Flag.Adress = 2002;
  9585. writeToPLC_Flag.Value = (short)6;
  9586. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  9587. {
  9588. Name = "d1BulletclipCode",
  9589. Adress = 2003,
  9590. ValueType = PLCValueType.String,
  9591. ValueTypeStrLength = 20,
  9592. Value = " "
  9593. });
  9594. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  9595. stopwatch2.Stop();
  9596. }
  9597. stopwatch1.Stop();
  9598. AddMessage(LogType.Info,
  9599. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9600. stopwatch2.ElapsedMilliseconds + "ms");
  9601. }
  9602. /// <summary>
  9603. /// [S4] 取放桁架 - S4_1载具扫码
  9604. /// </summary>
  9605. /// <param name="plcNo">PLC编号</param>
  9606. /// <param name="stationNameStr">工站全称</param>
  9607. private void S4_1载具扫码(int plcNo, string stationNameStr)
  9608. {
  9609. Stopwatch stopwatch1 = new Stopwatch();
  9610. Stopwatch stopwatch2 = new Stopwatch();
  9611. try
  9612. {
  9613. stopwatch1.Start();
  9614. // ZS 载具扫码
  9615. string d1VehicleCode = ""; // 扫到的码
  9616. short d1VehicleScanCode = 2;
  9617. #region 进站
  9618. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  9619. {
  9620. #region 查询载具上的产品信息
  9621. string cavityData = string.Empty;
  9622. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  9623. if (string.IsNullOrEmpty(cavityData))
  9624. cavityData = "";
  9625. if (snResult != 0)
  9626. {
  9627. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9628. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  9629. writeToPLC_Flag1.Adress = 2033;
  9630. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  9631. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9632. {
  9633. Name = "d1VehicleCode",
  9634. Adress = 2034,
  9635. ValueType = PLCValueType.String,
  9636. ValueTypeStrLength = 20,
  9637. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  9638. });
  9639. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  9640. stopwatch1.Stop();
  9641. AddMessage(LogType.Info,
  9642. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9643. "ms");
  9644. return;
  9645. }
  9646. string[] cavitySNs = cavityData.Split('.');
  9647. string partNo = "";
  9648. if (cavitySNs != null && cavitySNs.Length >= 1)
  9649. {
  9650. partNo = cavitySNs[0];
  9651. }
  9652. #endregion 查询载具上的产品信息
  9653. List<TestItem> item = new List<TestItem>();
  9654. item.Add(new TestItem()
  9655. {
  9656. Parameter_name = "载具码",
  9657. Parameter_value = d1VehicleCode,
  9658. });
  9659. item.Add(new TestItem()
  9660. {
  9661. Parameter_name = "载具穴号",
  9662. Parameter_value = "1",
  9663. });
  9664. stopwatch2.Start();
  9665. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  9666. partNo, item, out string errorMsg);
  9667. stopwatch2.Stop();
  9668. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  9669. }
  9670. #endregion 进站
  9671. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  9672. //// MES_Flag
  9673. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  9674. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9675. writeToPLC_Flag.Name = "d1VehicleScanCode";
  9676. writeToPLC_Flag.Adress = 2033;
  9677. writeToPLC_Flag.Value = d1VehicleScanCode;
  9678. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9679. {
  9680. Name = "d1VehicleCode",
  9681. Adress = 2034,
  9682. ValueType = PLCValueType.String,
  9683. ValueTypeStrLength = 20,
  9684. Value = d1VehicleCode
  9685. });
  9686. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  9687. }
  9688. catch (Exception ex)
  9689. {
  9690. string str = ex.StackTrace;
  9691. AddMessage_Station(stationNameStr, LogType.Error,
  9692. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  9693. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9694. stopwatch2.Start();
  9695. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  9696. //// MES_Flag
  9697. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  9698. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9699. writeToPLC_Flag.Name = "d1VehicleScanCode";
  9700. writeToPLC_Flag.Adress = 2033;
  9701. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  9702. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9703. {
  9704. Name = "d1VehicleCode",
  9705. Adress = 2034,
  9706. ValueType = PLCValueType.String,
  9707. ValueTypeStrLength = 20,
  9708. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  9709. });
  9710. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  9711. stopwatch2.Stop();
  9712. }
  9713. stopwatch1.Stop();
  9714. AddMessage(LogType.Info,
  9715. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9716. stopwatch2.ElapsedMilliseconds + "ms");
  9717. }
  9718. // 上次采集到的SN
  9719. //private string sn_S4_1出站接口 = string.Empty;
  9720. /// <summary>
  9721. /// [S4] 取放桁架 - S4_1出站接口
  9722. /// </summary>
  9723. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  9724. {
  9725. Stopwatch stopwatch1 = new Stopwatch();
  9726. Stopwatch stopwatch2 = new Stopwatch();
  9727. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9728. string stationNameStr = stationCode + stationName;
  9729. string processItem = stationName; // 测试项目
  9730. try
  9731. {
  9732. stopwatch1.Start();
  9733. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9734. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9735. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9736. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9737. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  9738. sn = sn.Replace("\0", "");
  9739. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  9740. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  9741. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  9742. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  9743. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  9744. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  9745. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  9746. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  9747. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  9748. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  9749. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  9750. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  9751. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  9752. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  9753. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  9754. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  9755. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  9756. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  9757. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  9758. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  9759. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  9760. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  9761. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  9762. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  9763. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  9764. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  9765. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  9766. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  9767. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  9768. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  9769. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  9770. bool pass = d1Result == 1;
  9771. // 存 载具SN列表
  9772. List<string> vehicleCodes = new List<string>()
  9773. {
  9774. d1VehicleCode1, d1VehicleCode2, d1VehicleCode3, d1VehicleCode4, d1VehicleCode5,
  9775. d1VehicleCode6, d1VehicleCode7, d1VehicleCode8, d1VehicleCode9, d1VehicleCode10,
  9776. d1VehicleCode11, d1VehicleCode12, d1VehicleCode13, d1VehicleCode14, d1VehicleCode15
  9777. };
  9778. // 统一查 产品SN列表
  9779. List<string> partNos = new List<string>();
  9780. foreach (string vehicleCode in vehicleCodes)
  9781. {
  9782. if (string.IsNullOrEmpty(vehicleCode))
  9783. partNos.Add("");
  9784. else
  9785. {
  9786. string partNo = "";
  9787. #region 查询载具上的产品信息
  9788. string cavityData = string.Empty;
  9789. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  9790. if (string.IsNullOrEmpty(cavityData))
  9791. cavityData = "";
  9792. if (snResult != 0)
  9793. {
  9794. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9795. writeToPLC_Flag1.Name = "d1MES_FLAG";
  9796. writeToPLC_Flag1.Adress = 2065;
  9797. writeToPLC_Flag1.Value = (short)4;
  9798. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  9799. stopwatch1.Stop();
  9800. AddMessage(LogType.Info,
  9801. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9802. "ms");
  9803. return;
  9804. }
  9805. string[] cavitySNs = cavityData.Split('.');
  9806. if (cavitySNs != null && cavitySNs.Length >= 1)
  9807. partNo = cavitySNs[0];
  9808. #endregion 查询载具上的产品信息
  9809. partNos.Add(partNo);
  9810. }
  9811. }
  9812. // 统一上传
  9813. stopwatch2.Start();
  9814. List<int> results = new List<int>();
  9815. for (int i = 0; i < partNos.Count; i++)
  9816. {
  9817. string index = (i + 1).ToString(); // 弹夹穴号
  9818. if (string.IsNullOrEmpty(partNos[i]))
  9819. results.Add(1);
  9820. else
  9821. {
  9822. List<TestItem> items1 = new List<TestItem>();
  9823. items1.Add(new TestItem()
  9824. {
  9825. Parameter_name = "弹夹码",
  9826. Parameter_value = sn,
  9827. Parameter_unit = ""
  9828. });
  9829. items1.Add(new TestItem()
  9830. {
  9831. Parameter_name = "弹夹穴号",
  9832. Parameter_value = index,
  9833. Parameter_unit = ""
  9834. });
  9835. items1.Add(new TestItem()
  9836. {
  9837. Parameter_name = "载具码",
  9838. Parameter_value = vehicleCodes[i],
  9839. Parameter_unit = ""
  9840. });
  9841. items1.Add(new TestItem()
  9842. {
  9843. Parameter_name = "载具穴号",
  9844. Parameter_value = "1",
  9845. Parameter_unit = ""
  9846. });
  9847. items1.Add(new TestItem()
  9848. {
  9849. Parameter_name = "产品结果",
  9850. Parameter_value = d1Result == 1 ? "OK" : "NG",
  9851. Parameter_unit = ""
  9852. });
  9853. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  9854. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  9855. results.Add(result1);
  9856. }
  9857. }
  9858. short result = 0;
  9859. if (results.All(a => a == 1))
  9860. result = 1;
  9861. else if (results.Contains(3))
  9862. result = 3;
  9863. else if (results.Contains(2))
  9864. result = 2;
  9865. else if (results.Contains(4))
  9866. result = 4;
  9867. else
  9868. result = 4;
  9869. stopwatch2.Stop();
  9870. #region 存储绑定数据到 边线MES系统中
  9871. if (result == 1)
  9872. {
  9873. string data = string.Join(".", vehicleCodes);
  9874. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  9875. if (resultMesR != 0)
  9876. {
  9877. result = 4;
  9878. AddMessage_Station(stationNameStr, LogType.Error,
  9879. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  9880. }
  9881. }
  9882. #endregion 存储绑定数据到 边线MES系统中
  9883. // MES_Flag 为4MES报错
  9884. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9885. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9886. writeToPLC_Flag.Name = "d1MES_FLAG";
  9887. writeToPLC_Flag.Adress = 2065;
  9888. writeToPLC_Flag.Value = result;
  9889. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  9890. OnMessage(LogType.Debug,
  9891. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9892. }
  9893. catch (Exception ex)
  9894. {
  9895. stopwatch2.Restart();
  9896. // MES_Flag 为4上位机报错
  9897. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  9898. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9899. writeToPLC_Flag.Name = "d1MES_FLAG";
  9900. writeToPLC_Flag.Adress = 2065;
  9901. writeToPLC_Flag.Value = (short)4;
  9902. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  9903. stopwatch2.Stop();
  9904. string str = ex.StackTrace;
  9905. AddMessage_Station(stationNameStr, LogType.Error,
  9906. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  9907. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9908. }
  9909. stopwatch1.Stop();
  9910. AddMessage(LogType.Info,
  9911. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  9912. stopwatch2.ElapsedMilliseconds + "ms");
  9913. }
  9914. /// <summary>
  9915. /// [S4] 取放桁架 - S4_1节拍接口
  9916. /// </summary>
  9917. /// <param name="plcNo">PLC编号</param>
  9918. /// <param name="stationNameStr">工站全称</param>
  9919. private void S4_1节拍接口(int plcNo, string stationNameStr)
  9920. {
  9921. Stopwatch stopwatch1 = new Stopwatch();
  9922. Stopwatch stopwatch2 = new Stopwatch();
  9923. string resultStr = string.Empty;
  9924. try
  9925. {
  9926. stopwatch1.Start();
  9927. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  9928. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  9929. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  9930. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9931. if (!actionBool)
  9932. {
  9933. stopwatch2.Start();
  9934. // MES_Flag
  9935. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9936. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9937. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  9938. writeToPLC_Flag1.Adress = 2398;
  9939. writeToPLC_Flag1.Value = (short)4;
  9940. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  9941. stopwatch2.Stop();
  9942. AddMessage(LogType.Info,
  9943. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  9944. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9945. return;
  9946. }
  9947. string d1OEEPartNo = string.Empty; // 物料码
  9948. if (string.IsNullOrEmpty(d1OEEProductSN))
  9949. {
  9950. stopwatch2.Start();
  9951. // MES_Flag
  9952. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9953. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9954. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  9955. writeToPLC_Flag1.Adress = 2398;
  9956. writeToPLC_Flag1.Value = (short)1;
  9957. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  9958. stopwatch2.Stop();
  9959. AddMessage(LogType.Info,
  9960. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9961. stopwatch2.ElapsedMilliseconds + "ms");
  9962. return;
  9963. }
  9964. else
  9965. {
  9966. // 查产品SN ZS
  9967. d1OEEPartNo = "Test";
  9968. }
  9969. short d1OEEMES_FLAG = 0;
  9970. // 上传OEE
  9971. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  9972. d1OEEMES_FLAG = result.Item1;
  9973. resultStr = result.Item2;
  9974. stopwatch2.Start();
  9975. // MES_Flag
  9976. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9977. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9978. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  9979. writeToPLC_Flag.Adress = 2398;
  9980. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  9981. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  9982. stopwatch2.Stop();
  9983. }
  9984. catch (Exception ex)
  9985. {
  9986. string str = ex.StackTrace;
  9987. AddMessage_Station(stationNameStr, LogType.Error,
  9988. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  9989. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9990. // MES_Flag
  9991. stopwatch2.Start();
  9992. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  9993. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9994. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  9995. writeToPLC_Flag.Adress = 2398;
  9996. writeToPLC_Flag.Value = (short)4;
  9997. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  9998. stopwatch2.Stop();
  9999. }
  10000. stopwatch1.Stop();
  10001. AddMessage(LogType.Info,
  10002. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10003. stopwatch2.ElapsedMilliseconds + "ms");
  10004. }
  10005. /// <summary>
  10006. /// [S4] 取放桁架 - S4_2桁架
  10007. /// </summary>
  10008. /// <param name="plcNo">PLC编号</param>
  10009. /// <param name="stationNameStr">工站全称</param>
  10010. private void S4_2桁架(int plcNo, string stationNameStr)
  10011. {
  10012. Stopwatch stopwatch1 = new Stopwatch();
  10013. Stopwatch stopwatch2 = new Stopwatch();
  10014. try
  10015. {
  10016. stopwatch1.Start();
  10017. // ZS 弹夹扫码
  10018. string d2BulletclipCode = " "; // 扫到的码
  10019. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  10020. short d2BulletclipScanCode = 2;
  10021. stopwatch2.Start();
  10022. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  10023. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  10024. //// MES_Flag
  10025. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10026. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10027. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  10028. writeToPLC_Flag.Adress = 2430;
  10029. writeToPLC_Flag.Value = d2BulletclipScanCode;
  10030. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10031. {
  10032. Name = "d2BulletclipCode",
  10033. Adress = 2432,
  10034. ValueType = PLCValueType.String,
  10035. ValueTypeStrLength = 20,
  10036. Value = d2BulletclipCode
  10037. });
  10038. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10039. {
  10040. Name = "d2BulletclipStates",
  10041. Adress = 2431,
  10042. ValueType = PLCValueType.Short,
  10043. Value = d2BulletclipStates
  10044. });
  10045. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  10046. stopwatch2.Stop();
  10047. }
  10048. catch (Exception ex)
  10049. {
  10050. string str = ex.StackTrace;
  10051. AddMessage_Station(stationNameStr, LogType.Error,
  10052. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10053. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10054. stopwatch2.Start();
  10055. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  10056. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  10057. // MES_Flag
  10058. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  10059. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10060. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  10061. writeToPLC_Flag.Adress = 2430;
  10062. writeToPLC_Flag.Value = (short)6;
  10063. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10064. {
  10065. Name = "d2BulletclipCode",
  10066. Adress = 2432,
  10067. ValueType = PLCValueType.String,
  10068. ValueTypeStrLength = 20,
  10069. Value = " "
  10070. });
  10071. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10072. {
  10073. Name = "d2BulletclipStates",
  10074. Adress = 2431,
  10075. ValueType = PLCValueType.Short,
  10076. Value = (short)0
  10077. });
  10078. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  10079. stopwatch2.Stop();
  10080. }
  10081. stopwatch1.Stop();
  10082. AddMessage(LogType.Info,
  10083. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10084. stopwatch2.ElapsedMilliseconds + "ms");
  10085. }
  10086. // 上次采集到的SN
  10087. //private string sn_S4_3进站接口 = string.Empty;
  10088. /// <summary>
  10089. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  10090. /// </summary>
  10091. private void S4_3进站接口(int plcNo, string stationNameStr)
  10092. {
  10093. Stopwatch stopwatch1 = new Stopwatch();
  10094. Stopwatch stopwatch2 = new Stopwatch();
  10095. try
  10096. {
  10097. stopwatch1.Start();
  10098. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  10099. sn = sn.Replace("\0", "");
  10100. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  10101. #region 查询15个载具码
  10102. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10103. string vehicleData = string.Empty;
  10104. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10105. if (string.IsNullOrEmpty(vehicleData))
  10106. vehicleData = "";
  10107. if (snResult != 0)
  10108. {
  10109. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10110. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10111. writeToPLC_Flag1.Adress = 2463;
  10112. writeToPLC_Flag1.Value = (short)4;
  10113. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10114. stopwatch1.Stop();
  10115. AddMessage(LogType.Info,
  10116. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10117. return;
  10118. }
  10119. string[] cavitySNs = vehicleData.Split('.');
  10120. if (cavitySNs != null && cavitySNs.Length > 0)
  10121. {
  10122. for (int i = 0; i < cavitySNs.Length; i++)
  10123. {
  10124. if (string.IsNullOrEmpty(cavitySNs[i]))
  10125. vehicleCodes.Add("");
  10126. else
  10127. vehicleCodes.Add(cavitySNs[i]);
  10128. }
  10129. }
  10130. #endregion 查询15个载具码
  10131. #region 查询15个产品SN
  10132. List<string> portNos = new List<string>(); // 15个产品SN
  10133. foreach (string vehicleCode in vehicleCodes)
  10134. {
  10135. if (string.IsNullOrEmpty(vehicleCode))
  10136. portNos.Add("");
  10137. else
  10138. {
  10139. // 查询
  10140. string cavityData = string.Empty;
  10141. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10142. if (string.IsNullOrEmpty(cavityData))
  10143. cavityData = "";
  10144. if (snResult1 != 0)
  10145. {
  10146. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10147. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10148. writeToPLC_Flag1.Adress = 2463;
  10149. writeToPLC_Flag1.Value = (short)4;
  10150. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10151. stopwatch1.Stop();
  10152. AddMessage(LogType.Info,
  10153. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  10154. stopwatch1.ElapsedMilliseconds + "ms");
  10155. return;
  10156. }
  10157. string[] partSNs = cavityData.Split('.');
  10158. if (partSNs != null && partSNs.Length >= 1)
  10159. portNos.Add(partSNs[0]);
  10160. else
  10161. portNos.Add("");
  10162. }
  10163. }
  10164. #endregion 查询15个产品SN
  10165. // 调用MES进站(最多15个)
  10166. stopwatch2.Start();
  10167. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  10168. for (int i = 0; i < vehicleCodes.Count; i++)
  10169. {
  10170. // 循环进站
  10171. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  10172. {
  10173. // 产品SN(物料码)校验
  10174. string portNo = portNos[i];
  10175. List<TestItem> item = new List<TestItem>();
  10176. item.Add(new TestItem()
  10177. {
  10178. Parameter_name = "弹夹码",
  10179. Parameter_value = sn,
  10180. });
  10181. item.Add(new TestItem()
  10182. {
  10183. Parameter_name = "弹夹穴位",
  10184. Parameter_value = (i + 1).ToString(),
  10185. });
  10186. item.Add(new TestItem()
  10187. {
  10188. Parameter_name = "载具码",
  10189. Parameter_value = vehicleCodes[i],
  10190. });
  10191. item.Add(new TestItem()
  10192. {
  10193. Parameter_name = "载具穴号",
  10194. Parameter_value = "1",
  10195. });
  10196. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  10197. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  10198. }
  10199. }
  10200. stopwatch2.Stop();
  10201. short result = 0;
  10202. bool haveMesWarn = results.Contains(5);
  10203. bool havePCWarn = results.Contains(6);
  10204. if (haveMesWarn)
  10205. result = 2; // 5->2
  10206. else if (havePCWarn)
  10207. result = 6; // 6->4
  10208. else
  10209. result = 1;
  10210. // MES_Flag 为4MES报错
  10211. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10212. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10213. writeToPLC_Flag.Name = "d3MES_FLAG";
  10214. writeToPLC_Flag.Adress = 2463;
  10215. writeToPLC_Flag.Value = result;
  10216. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10217. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10218. }
  10219. catch (Exception ex)
  10220. {
  10221. stopwatch2.Stop();
  10222. // MES_Flag 为4上位机报错
  10223. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  10224. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10225. writeToPLC_Flag.Name = "d3MES_FLAG";
  10226. writeToPLC_Flag.Adress = 2463;
  10227. writeToPLC_Flag.Value = (short)4;
  10228. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10229. string str = ex.StackTrace;
  10230. AddMessage_Station(stationNameStr, LogType.Error,
  10231. $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10232. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10233. }
  10234. stopwatch1.Stop();
  10235. AddMessage(LogType.Info,
  10236. stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  10237. stopwatch2.ElapsedMilliseconds + "ms");
  10238. }
  10239. // 上次采集到的SN
  10240. //private string sn_S4_3出站接口 = string.Empty;
  10241. /// <summary>
  10242. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  10243. /// </summary>
  10244. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  10245. {
  10246. Stopwatch stopwatch1 = new Stopwatch();
  10247. Stopwatch stopwatch2 = new Stopwatch();
  10248. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10249. string stationNameStr = stationCode + stationName;
  10250. string processItem = stationName; // 测试项目
  10251. try
  10252. {
  10253. stopwatch1.Start();
  10254. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10255. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10256. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10257. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10258. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  10259. sn = sn.Replace("\0", "");
  10260. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  10261. bool isPass = d3Result == 1; // 产品结果 bool
  10262. #region 查询15个载具码
  10263. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10264. string vehicleData = string.Empty;
  10265. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10266. if (string.IsNullOrEmpty(vehicleData))
  10267. vehicleData = "";
  10268. if (snResult1 != 0)
  10269. {
  10270. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10271. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10272. writeToPLC_Flag1.Adress = 2463;
  10273. writeToPLC_Flag1.Value = (short)4;
  10274. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10275. stopwatch1.Stop();
  10276. AddMessage(LogType.Info,
  10277. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10278. return;
  10279. }
  10280. string[] cavitySNs = vehicleData.Split('.');
  10281. if (cavitySNs != null && cavitySNs.Length > 0)
  10282. {
  10283. for (int i = 0; i < cavitySNs.Length; i++)
  10284. {
  10285. if (string.IsNullOrEmpty(cavitySNs[i]))
  10286. vehicleCodes.Add("");
  10287. else
  10288. vehicleCodes.Add(cavitySNs[i]);
  10289. }
  10290. }
  10291. #endregion 查询15个载具码
  10292. // 统一查 产品SN列表
  10293. List<string> partNos = new List<string>();
  10294. foreach (string vehicleCode in vehicleCodes)
  10295. {
  10296. if (string.IsNullOrEmpty(vehicleCode))
  10297. partNos.Add("");
  10298. else
  10299. {
  10300. string partNo = "";
  10301. #region 查询载具上的产品信息
  10302. string cavityData = string.Empty;
  10303. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10304. if (string.IsNullOrEmpty(cavityData))
  10305. cavityData = "";
  10306. if (snResult != 0)
  10307. {
  10308. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10309. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10310. writeToPLC_Flag1.Adress = 2463;
  10311. writeToPLC_Flag1.Value = (short)4;
  10312. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10313. stopwatch1.Stop();
  10314. AddMessage(LogType.Info,
  10315. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10316. "ms");
  10317. return;
  10318. }
  10319. string[] partSNs = cavityData.Split('.');
  10320. if (partSNs != null && partSNs.Length >= 1)
  10321. partNo = partSNs[0];
  10322. #endregion 查询载具上的产品信息
  10323. partNos.Add(partNo);
  10324. }
  10325. }
  10326. // 统一上传 - 调用MES出站
  10327. stopwatch2.Start();
  10328. List<int> results = new List<int>();
  10329. for (int i = 0; i < partNos.Count; i++)
  10330. {
  10331. string index = (i + 1).ToString(); // 弹夹穴号
  10332. if (string.IsNullOrEmpty(partNos[i]))
  10333. results.Add(1);
  10334. else
  10335. {
  10336. List<TestItem> items1 = new List<TestItem>();
  10337. items1.Add(new TestItem()
  10338. {
  10339. Parameter_name = "弹夹码",
  10340. Parameter_value = sn,
  10341. Parameter_unit = ""
  10342. });
  10343. items1.Add(new TestItem()
  10344. {
  10345. Parameter_name = "弹夹穴号",
  10346. Parameter_value = index,
  10347. Parameter_unit = ""
  10348. });
  10349. items1.Add(new TestItem()
  10350. {
  10351. Parameter_name = "载具码",
  10352. Parameter_value = vehicleCodes[i],
  10353. Parameter_unit = ""
  10354. });
  10355. items1.Add(new TestItem()
  10356. {
  10357. Parameter_name = "载具穴号",
  10358. Parameter_value = "1",
  10359. Parameter_unit = ""
  10360. });
  10361. items1.Add(new TestItem()
  10362. {
  10363. Parameter_name = "产品结果",
  10364. Parameter_value = d3Result == 1 ? "OK" : "NG",
  10365. Parameter_unit = ""
  10366. });
  10367. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  10368. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  10369. results.Add(result1);
  10370. }
  10371. }
  10372. short result = 0;
  10373. if (results.All(a => a == 1))
  10374. result = 1;
  10375. else if (results.Contains(3))
  10376. result = 3;
  10377. else if (results.Contains(2))
  10378. result = 2;
  10379. else if (results.Contains(4))
  10380. result = 4;
  10381. else
  10382. result = 4;
  10383. stopwatch2.Stop();
  10384. // MES_Flag 为4MES报错
  10385. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10386. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10387. writeToPLC_Flag.Name = "d3MES_FLAG";
  10388. writeToPLC_Flag.Adress = 2463;
  10389. writeToPLC_Flag.Value = result;
  10390. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10391. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10392. }
  10393. catch (Exception ex)
  10394. {
  10395. stopwatch2.Restart();
  10396. // MES_Flag 为4上位机报错
  10397. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  10398. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10399. writeToPLC_Flag.Name = "d3MES_FLAG";
  10400. writeToPLC_Flag.Adress = 2463;
  10401. writeToPLC_Flag.Value = (short)4;
  10402. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10403. string str = ex.StackTrace;
  10404. AddMessage_Station(stationNameStr, LogType.Error,
  10405. $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10406. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10407. stopwatch2.Stop();
  10408. }
  10409. stopwatch1.Stop();
  10410. AddMessage(LogType.Info,
  10411. stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10412. stopwatch2.ElapsedMilliseconds + "ms");
  10413. }
  10414. // 上次采集到的SN
  10415. //private string sn_S4_4进站接口 = string.Empty;
  10416. /// <summary>
  10417. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  10418. /// </summary>
  10419. private void S4_4进站接口(int plcNo, string stationNameStr)
  10420. {
  10421. Stopwatch stopwatch1 = new Stopwatch();
  10422. Stopwatch stopwatch2 = new Stopwatch();
  10423. try
  10424. {
  10425. stopwatch1.Start();
  10426. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  10427. sn = sn.Replace("\0", "");
  10428. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  10429. #region 查询15个载具码
  10430. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10431. string vehicleData = string.Empty;
  10432. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10433. if (string.IsNullOrEmpty(vehicleData))
  10434. vehicleData = "";
  10435. if (snResult != 0)
  10436. {
  10437. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10438. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10439. writeToPLC_Flag1.Adress = 2463;
  10440. writeToPLC_Flag1.Value = (short)4;
  10441. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10442. stopwatch1.Stop();
  10443. AddMessage(LogType.Info,
  10444. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10445. return;
  10446. }
  10447. string[] cavitySNs = vehicleData.Split('.');
  10448. if (cavitySNs != null && cavitySNs.Length > 0)
  10449. {
  10450. for (int i = 0; i < cavitySNs.Length; i++)
  10451. {
  10452. if (string.IsNullOrEmpty(cavitySNs[i]))
  10453. vehicleCodes.Add("");
  10454. else
  10455. vehicleCodes.Add(cavitySNs[i]);
  10456. }
  10457. }
  10458. #endregion 查询15个载具码
  10459. #region 查询15个产品SN
  10460. List<string> portNos = new List<string>(); // 15个产品SN
  10461. foreach (string vehicleCode in vehicleCodes)
  10462. {
  10463. if (string.IsNullOrEmpty(vehicleCode))
  10464. portNos.Add("");
  10465. else
  10466. {
  10467. // 查询
  10468. string cavityData = string.Empty;
  10469. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10470. if (string.IsNullOrEmpty(cavityData))
  10471. cavityData = "";
  10472. if (snResult1 != 0)
  10473. {
  10474. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10475. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10476. writeToPLC_Flag1.Adress = 2463;
  10477. writeToPLC_Flag1.Value = (short)4;
  10478. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10479. stopwatch1.Stop();
  10480. AddMessage(LogType.Info,
  10481. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  10482. stopwatch1.ElapsedMilliseconds + "ms");
  10483. return;
  10484. }
  10485. string[] partSNs = cavityData.Split('.');
  10486. if (partSNs != null && partSNs.Length >= 1)
  10487. portNos.Add(partSNs[0]);
  10488. else
  10489. portNos.Add("");
  10490. }
  10491. }
  10492. #endregion 查询15个产品SN
  10493. // 调用MES进站(最多15个)
  10494. stopwatch2.Start();
  10495. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  10496. for (int i = 0; i < vehicleCodes.Count; i++)
  10497. {
  10498. // 循环进站
  10499. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  10500. {
  10501. // 产品SN(物料码)校验
  10502. string portNo = portNos[i];
  10503. List<TestItem> item = new List<TestItem>();
  10504. item.Add(new TestItem()
  10505. {
  10506. Parameter_name = "弹夹码",
  10507. Parameter_value = sn,
  10508. });
  10509. item.Add(new TestItem()
  10510. {
  10511. Parameter_name = "弹夹穴位",
  10512. Parameter_value = (i + 1).ToString(),
  10513. });
  10514. item.Add(new TestItem()
  10515. {
  10516. Parameter_name = "载具码",
  10517. Parameter_value = vehicleCodes[i],
  10518. });
  10519. item.Add(new TestItem()
  10520. {
  10521. Parameter_name = "载具穴号",
  10522. Parameter_value = "1",
  10523. });
  10524. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  10525. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  10526. }
  10527. }
  10528. stopwatch2.Stop();
  10529. short result = 0;
  10530. bool haveMesWarn = results.Contains(5);
  10531. bool havePCWarn = results.Contains(6);
  10532. if (haveMesWarn)
  10533. result = 2; // 5->2
  10534. else if (havePCWarn)
  10535. result = 6; // 6->4
  10536. else
  10537. result = 1;
  10538. // MES_Flag 为4MES报错
  10539. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10540. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10541. writeToPLC_Flag.Name = "d4MES_FLAG";
  10542. writeToPLC_Flag.Adress = 2496;
  10543. writeToPLC_Flag.Value = result;
  10544. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10545. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10546. }
  10547. catch (Exception ex)
  10548. {
  10549. stopwatch2.Stop();
  10550. // MES_Flag 为4上位机报错
  10551. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  10552. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10553. writeToPLC_Flag.Name = "d4MES_FLAG";
  10554. writeToPLC_Flag.Adress = 2496;
  10555. writeToPLC_Flag.Value = (short)4;
  10556. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10557. string str = ex.StackTrace;
  10558. AddMessage_Station(stationNameStr, LogType.Error,
  10559. $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10560. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10561. }
  10562. stopwatch1.Stop();
  10563. AddMessage(LogType.Info,
  10564. stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  10565. stopwatch2.ElapsedMilliseconds + "ms");
  10566. }
  10567. // 上次采集到的SN
  10568. //private string sn_S4_4出站接口 = string.Empty;
  10569. /// <summary>
  10570. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  10571. /// </summary>
  10572. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  10573. {
  10574. Stopwatch stopwatch1 = new Stopwatch();
  10575. Stopwatch stopwatch2 = new Stopwatch();
  10576. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10577. string stationNameStr = stationCode + stationName;
  10578. string processItem = stationName; // 测试项目
  10579. try
  10580. {
  10581. stopwatch1.Start();
  10582. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10583. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10584. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10585. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10586. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  10587. sn = sn.Replace("\0", "");
  10588. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  10589. bool isPass = d4Result == 1; // 产品结果 bool
  10590. #region 查询15个载具码
  10591. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10592. string vehicleData = string.Empty;
  10593. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10594. if (string.IsNullOrEmpty(vehicleData))
  10595. vehicleData = "";
  10596. if (snResult1 != 0)
  10597. {
  10598. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10599. writeToPLC_Flag1.Name = "d4MES_FLAG";
  10600. writeToPLC_Flag1.Adress = 2496;
  10601. writeToPLC_Flag1.Value = (short)4;
  10602. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  10603. stopwatch1.Stop();
  10604. AddMessage(LogType.Info,
  10605. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10606. return;
  10607. }
  10608. string[] cavitySNs = vehicleData.Split('.');
  10609. if (cavitySNs != null && cavitySNs.Length > 0)
  10610. {
  10611. for (int i = 0; i < cavitySNs.Length; i++)
  10612. {
  10613. if (string.IsNullOrEmpty(cavitySNs[i]))
  10614. vehicleCodes.Add("");
  10615. else
  10616. vehicleCodes.Add(cavitySNs[i]);
  10617. }
  10618. }
  10619. #endregion 查询15个载具码
  10620. // 统一查 产品SN列表
  10621. List<string> partNos = new List<string>();
  10622. foreach (string vehicleCode in vehicleCodes)
  10623. {
  10624. if (string.IsNullOrEmpty(vehicleCode))
  10625. partNos.Add("");
  10626. else
  10627. {
  10628. string partNo = "";
  10629. #region 查询载具上的产品信息
  10630. string cavityData = string.Empty;
  10631. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10632. if (string.IsNullOrEmpty(cavityData))
  10633. cavityData = "";
  10634. if (snResult != 0)
  10635. {
  10636. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10637. writeToPLC_Flag1.Name = "d4MES_FLAG";
  10638. writeToPLC_Flag1.Adress = 2496;
  10639. writeToPLC_Flag1.Value = (short)4;
  10640. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  10641. stopwatch1.Stop();
  10642. AddMessage(LogType.Info,
  10643. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10644. "ms");
  10645. return;
  10646. }
  10647. string[] partSNs = cavityData.Split('.');
  10648. if (partSNs != null && partSNs.Length >= 1)
  10649. partNo = partSNs[0];
  10650. #endregion 查询载具上的产品信息
  10651. partNos.Add(partNo);
  10652. }
  10653. }
  10654. // 调用MES出站
  10655. stopwatch2.Start();
  10656. // 统一上传
  10657. List<int> results = new List<int>();
  10658. for (int i = 0; i < partNos.Count; i++)
  10659. {
  10660. string index = (i + 1).ToString(); // 弹夹穴号
  10661. if (string.IsNullOrEmpty(partNos[i]))
  10662. results.Add(1);
  10663. else
  10664. {
  10665. List<TestItem> items1 = new List<TestItem>();
  10666. items1.Add(new TestItem()
  10667. {
  10668. Parameter_name = "弹夹码",
  10669. Parameter_value = sn,
  10670. Parameter_unit = ""
  10671. });
  10672. items1.Add(new TestItem()
  10673. {
  10674. Parameter_name = "弹夹穴号",
  10675. Parameter_value = index,
  10676. Parameter_unit = ""
  10677. });
  10678. items1.Add(new TestItem()
  10679. {
  10680. Parameter_name = "载具码",
  10681. Parameter_value = vehicleCodes[i],
  10682. Parameter_unit = ""
  10683. });
  10684. items1.Add(new TestItem()
  10685. {
  10686. Parameter_name = "载具穴号",
  10687. Parameter_value = "1",
  10688. Parameter_unit = ""
  10689. });
  10690. items1.Add(new TestItem()
  10691. {
  10692. Parameter_name = "产品结果",
  10693. Parameter_value = d4Result == 1 ? "OK" : "NG",
  10694. Parameter_unit = ""
  10695. });
  10696. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  10697. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  10698. results.Add(result1);
  10699. }
  10700. }
  10701. short result = 0;
  10702. if (results.All(a => a == 1))
  10703. result = 1;
  10704. else if (results.Contains(3))
  10705. result = 3;
  10706. else if (results.Contains(2))
  10707. result = 2;
  10708. else if (results.Contains(4))
  10709. result = 4;
  10710. else
  10711. result = 4;
  10712. stopwatch2.Stop();
  10713. // MES_Flag 为4MES报错
  10714. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10715. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10716. writeToPLC_Flag.Name = "d4MES_FLAG";
  10717. writeToPLC_Flag.Adress = 2496;
  10718. writeToPLC_Flag.Value = result;
  10719. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10720. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10721. }
  10722. catch (Exception ex)
  10723. {
  10724. stopwatch2.Restart();
  10725. // MES_Flag 为4上位机报错
  10726. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  10727. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10728. writeToPLC_Flag.Name = "d4MES_FLAG";
  10729. writeToPLC_Flag.Adress = 2496;
  10730. writeToPLC_Flag.Value = (short)4;
  10731. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10732. string str = ex.StackTrace;
  10733. AddMessage_Station(stationNameStr, LogType.Error,
  10734. $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10735. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10736. stopwatch2.Stop();
  10737. }
  10738. stopwatch1.Stop();
  10739. AddMessage(LogType.Info,
  10740. stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10741. stopwatch2.ElapsedMilliseconds + "ms");
  10742. }
  10743. /// <summary>
  10744. /// [S4] 取放桁架 - S4_5弹夹扫码
  10745. /// </summary>
  10746. /// <param name="plcNo">PLC编号</param>
  10747. /// <param name="stationNameStr">工站全称</param>
  10748. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  10749. {
  10750. Stopwatch stopwatch1 = new Stopwatch();
  10751. Stopwatch stopwatch2 = new Stopwatch();
  10752. try
  10753. {
  10754. stopwatch1.Start();
  10755. // ZS 弹夹扫码
  10756. string d5BulletclipCode = " "; // 扫到的码
  10757. short d5BulletclipScanCode = 2;
  10758. stopwatch2.Start();
  10759. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  10760. //// MES_Flag
  10761. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10762. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10763. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  10764. writeToPLC_Flag.Adress = 2528;
  10765. writeToPLC_Flag.Value = d5BulletclipScanCode;
  10766. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10767. {
  10768. Name = "d5BulletclipCode",
  10769. Adress = 2529,
  10770. ValueType = PLCValueType.String,
  10771. ValueTypeStrLength = 20,
  10772. Value = d5BulletclipCode
  10773. });
  10774. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  10775. stopwatch2.Stop();
  10776. }
  10777. catch (Exception ex)
  10778. {
  10779. string str = ex.StackTrace;
  10780. AddMessage_Station(stationNameStr, LogType.Error,
  10781. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10782. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10783. stopwatch2.Start();
  10784. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  10785. //// MES_Flag
  10786. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  10787. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10788. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  10789. writeToPLC_Flag.Adress = 2528;
  10790. writeToPLC_Flag.Value = (short)6;
  10791. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10792. {
  10793. Name = "d5BulletclipCode",
  10794. Adress = 2529,
  10795. ValueType = PLCValueType.String,
  10796. ValueTypeStrLength = 20,
  10797. Value = " "
  10798. });
  10799. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  10800. stopwatch2.Stop();
  10801. }
  10802. stopwatch1.Stop();
  10803. AddMessage(LogType.Info,
  10804. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10805. stopwatch2.ElapsedMilliseconds + "ms");
  10806. }
  10807. /// <summary>
  10808. /// [S4] 取放桁架 - S4_5载具扫码
  10809. /// </summary>
  10810. /// <param name="plcNo">PLC编号</param>
  10811. /// <param name="stationNameStr">工站全称</param>
  10812. private void S4_5载具扫码(int plcNo, string stationNameStr)
  10813. {
  10814. Stopwatch stopwatch1 = new Stopwatch();
  10815. Stopwatch stopwatch2 = new Stopwatch();
  10816. try
  10817. {
  10818. stopwatch1.Start();
  10819. // ZS 载具扫码
  10820. string d5VehicleCode = " "; // 扫到的码
  10821. short d5VehicleScanCode = 2;
  10822. #region 进站
  10823. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  10824. {
  10825. // 查产品SN
  10826. #region 查询载具上的产品信息
  10827. string cavityData = string.Empty;
  10828. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  10829. if (string.IsNullOrEmpty(cavityData))
  10830. cavityData = "";
  10831. if (snResult != 0)
  10832. {
  10833. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10834. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  10835. writeToPLC_Flag1.Adress = 2559;
  10836. writeToPLC_Flag1.Value = (short)6;
  10837. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10838. {
  10839. Name = "d5VehicleCode",
  10840. Adress = 2560,
  10841. ValueType = PLCValueType.String,
  10842. ValueTypeStrLength = 20,
  10843. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  10844. });
  10845. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  10846. stopwatch1.Stop();
  10847. AddMessage(LogType.Info,
  10848. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10849. "ms");
  10850. return;
  10851. }
  10852. string[] cavitySNs = cavityData.Split('.');
  10853. string partNo = "";
  10854. if (cavitySNs != null && cavitySNs.Length >= 1)
  10855. {
  10856. partNo = cavitySNs[0];
  10857. }
  10858. #endregion 查询载具上的产品信息
  10859. List<TestItem> item = new List<TestItem>();
  10860. item.Add(new TestItem()
  10861. {
  10862. Parameter_name = "载具码",
  10863. Parameter_value = d5VehicleCode,
  10864. });
  10865. item.Add(new TestItem()
  10866. {
  10867. Parameter_name = "载具穴号",
  10868. Parameter_value = "1",
  10869. });
  10870. stopwatch2.Start();
  10871. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  10872. partNo, item, out string errorMsg);
  10873. stopwatch2.Stop();
  10874. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  10875. }
  10876. #endregion 进站
  10877. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  10878. //// MES_Flag
  10879. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10880. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10881. writeToPLC_Flag.Name = "d5VehicleScanCode";
  10882. writeToPLC_Flag.Adress = 2559;
  10883. writeToPLC_Flag.Value = d5VehicleScanCode;
  10884. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10885. {
  10886. Name = "d5VehicleCode",
  10887. Adress = 2560,
  10888. ValueType = PLCValueType.String,
  10889. ValueTypeStrLength = 20,
  10890. Value = d5VehicleCode
  10891. });
  10892. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  10893. }
  10894. catch (Exception ex)
  10895. {
  10896. string str = ex.StackTrace;
  10897. AddMessage_Station(stationNameStr, LogType.Error,
  10898. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10899. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10900. stopwatch2.Start();
  10901. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  10902. //// MES_Flag
  10903. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  10904. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10905. writeToPLC_Flag.Name = "d5VehicleScanCode";
  10906. writeToPLC_Flag.Adress = 2559;
  10907. writeToPLC_Flag.Value = (short)6;
  10908. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10909. {
  10910. Name = "d5VehicleCode",
  10911. Adress = 2560,
  10912. ValueType = PLCValueType.String,
  10913. ValueTypeStrLength = 20,
  10914. Value = " "
  10915. });
  10916. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  10917. stopwatch2.Stop();
  10918. }
  10919. stopwatch1.Stop();
  10920. AddMessage(LogType.Info,
  10921. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10922. stopwatch2.ElapsedMilliseconds + "ms");
  10923. }
  10924. // 上次采集到的SN
  10925. //private string sn_S4_5出站接口 = string.Empty;
  10926. /// <summary>
  10927. /// [S4] 取放桁架 - S4_5出站接口
  10928. /// </summary>
  10929. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  10930. {
  10931. Stopwatch stopwatch1 = new Stopwatch();
  10932. Stopwatch stopwatch2 = new Stopwatch();
  10933. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10934. string stationNameStr = stationCode + stationName;
  10935. string processItem = stationName; // 测试项目
  10936. try
  10937. {
  10938. stopwatch1.Start();
  10939. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10940. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10941. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10942. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10943. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  10944. sn = sn.Replace("\0", "");
  10945. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  10946. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  10947. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  10948. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  10949. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  10950. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  10951. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  10952. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  10953. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  10954. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  10955. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  10956. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  10957. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  10958. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  10959. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  10960. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  10961. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  10962. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  10963. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  10964. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  10965. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  10966. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  10967. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  10968. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  10969. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  10970. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  10971. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  10972. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  10973. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  10974. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  10975. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  10976. bool pass = d5Result == 1;
  10977. // 存 载具SN列表
  10978. List<string> vehicleCodes = new List<string>()
  10979. {
  10980. d5VehicleCode1, d5VehicleCode2, d5VehicleCode3, d5VehicleCode4, d5VehicleCode5,
  10981. d5VehicleCode6, d5VehicleCode7, d5VehicleCode8, d5VehicleCode9, d5VehicleCode10,
  10982. d5VehicleCode11, d5VehicleCode12, d5VehicleCode13, d5VehicleCode14, d5VehicleCode15
  10983. };
  10984. // 统一查 产品SN列表
  10985. List<string> partNos = new List<string>();
  10986. foreach (string vehicleCode in vehicleCodes)
  10987. {
  10988. if (string.IsNullOrEmpty(vehicleCode))
  10989. partNos.Add("");
  10990. else
  10991. {
  10992. string partNo = "";
  10993. #region 查询载具上的产品信息
  10994. string cavityData = string.Empty;
  10995. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10996. if (string.IsNullOrEmpty(cavityData))
  10997. cavityData = "";
  10998. if (snResult != 0)
  10999. {
  11000. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11001. writeToPLC_Flag1.Name = "d5MES_FLAG";
  11002. writeToPLC_Flag1.Adress = 2591;
  11003. writeToPLC_Flag1.Value = (short)4;
  11004. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  11005. stopwatch1.Stop();
  11006. AddMessage(LogType.Info,
  11007. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  11008. "ms");
  11009. return;
  11010. }
  11011. string[] cavitySNs = cavityData.Split('.');
  11012. if (cavitySNs != null && cavitySNs.Length >= 1)
  11013. partNo = cavitySNs[0];
  11014. #endregion 查询载具上的产品信息
  11015. partNos.Add(partNo);
  11016. }
  11017. }
  11018. // 统一上传
  11019. stopwatch2.Start();
  11020. List<int> results = new List<int>();
  11021. for (int i = 0; i < partNos.Count; i++)
  11022. {
  11023. string index = (i + 1).ToString(); // 弹夹穴号
  11024. if (string.IsNullOrEmpty(partNos[i]))
  11025. results.Add(1);
  11026. else
  11027. {
  11028. List<TestItem> items1 = new List<TestItem>();
  11029. items1.Add(new TestItem()
  11030. {
  11031. Parameter_name = "弹夹码",
  11032. Parameter_value = sn,
  11033. Parameter_unit = ""
  11034. });
  11035. items1.Add(new TestItem()
  11036. {
  11037. Parameter_name = "弹夹穴号",
  11038. Parameter_value = index,
  11039. Parameter_unit = ""
  11040. });
  11041. items1.Add(new TestItem()
  11042. {
  11043. Parameter_name = "载具码",
  11044. Parameter_value = vehicleCodes[i],
  11045. Parameter_unit = ""
  11046. });
  11047. items1.Add(new TestItem()
  11048. {
  11049. Parameter_name = "载具穴号",
  11050. Parameter_value = "1",
  11051. Parameter_unit = ""
  11052. });
  11053. items1.Add(new TestItem()
  11054. {
  11055. Parameter_name = "产品结果",
  11056. Parameter_value = d5Result == 1 ? "OK" : "NG",
  11057. Parameter_unit = ""
  11058. });
  11059. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  11060. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  11061. results.Add(result1);
  11062. }
  11063. }
  11064. short result = 0;
  11065. if (results.All(a => a == 1))
  11066. result = 1;
  11067. else if (results.Contains(3))
  11068. result = 3;
  11069. else if (results.Contains(2))
  11070. result = 2;
  11071. else if (results.Contains(4))
  11072. result = 4;
  11073. else
  11074. result = 4;
  11075. stopwatch2.Stop();
  11076. #region 存储绑定数据到 边线MES系统中
  11077. if (result == 1)
  11078. {
  11079. // 删除绑定信息
  11080. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  11081. if (resultMesR != 0)
  11082. {
  11083. result = 4;
  11084. AddMessage_Station(stationNameStr, LogType.Error,
  11085. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  11086. }
  11087. }
  11088. #endregion 存储绑定数据到 边线MES系统中
  11089. // MES_Flag 为4MES报错
  11090. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11091. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11092. writeToPLC_Flag.Name = "d5MES_FLAG";
  11093. writeToPLC_Flag.Adress = 2591;
  11094. writeToPLC_Flag.Value = result;
  11095. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  11096. OnMessage(LogType.Debug,
  11097. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  11098. }
  11099. catch (Exception ex)
  11100. {
  11101. stopwatch2.Restart();
  11102. // MES_Flag 为4上位机报错
  11103. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  11104. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11105. writeToPLC_Flag.Name = "d5MES_FLAG";
  11106. writeToPLC_Flag.Adress = 2591;
  11107. writeToPLC_Flag.Value = (short)4;
  11108. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  11109. stopwatch2.Stop();
  11110. string str = ex.StackTrace;
  11111. AddMessage_Station(stationNameStr, LogType.Error,
  11112. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11113. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11114. }
  11115. stopwatch1.Stop();
  11116. AddMessage(LogType.Info,
  11117. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11118. stopwatch2.ElapsedMilliseconds + "ms");
  11119. }
  11120. /// <summary>
  11121. /// [S4] 取放桁架 - S4_5节拍接口
  11122. /// </summary>
  11123. /// <param name="plcNo">PLC编号</param>
  11124. /// <param name="stationNameStr">工站全称</param>
  11125. private void S4_5节拍接口(int plcNo, string stationNameStr)
  11126. {
  11127. Stopwatch stopwatch1 = new Stopwatch();
  11128. Stopwatch stopwatch2 = new Stopwatch();
  11129. string resultStr = string.Empty;
  11130. try
  11131. {
  11132. stopwatch1.Start();
  11133. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  11134. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  11135. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  11136. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  11137. if (!actionBool)
  11138. {
  11139. stopwatch2.Start();
  11140. // MES_Flag
  11141. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  11142. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11143. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  11144. writeToPLC_Flag1.Adress = 2924;
  11145. writeToPLC_Flag1.Value = (short)4;
  11146. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  11147. stopwatch2.Stop();
  11148. AddMessage(LogType.Info,
  11149. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  11150. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  11151. return;
  11152. }
  11153. string d5OEEPartNo = string.Empty; // 物料码
  11154. if (string.IsNullOrEmpty(d5OEEProductSN))
  11155. {
  11156. stopwatch2.Start();
  11157. // MES_Flag
  11158. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11159. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11160. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  11161. writeToPLC_Flag1.Adress = 2924;
  11162. writeToPLC_Flag1.Value = (short)1;
  11163. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  11164. stopwatch2.Stop();
  11165. AddMessage(LogType.Info,
  11166. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11167. stopwatch2.ElapsedMilliseconds + "ms");
  11168. return;
  11169. }
  11170. else
  11171. {
  11172. // 查产品SN
  11173. d5OEEPartNo = "Test"; // ZS
  11174. }
  11175. short d5OEEMES_FLAG = 0;
  11176. // 上传OEE
  11177. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  11178. d5OEEMES_FLAG = result.Item1;
  11179. resultStr = result.Item2;
  11180. stopwatch2.Start();
  11181. // MES_Flag
  11182. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11183. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11184. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  11185. writeToPLC_Flag.Adress = 2924;
  11186. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  11187. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  11188. stopwatch2.Stop();
  11189. }
  11190. catch (Exception ex)
  11191. {
  11192. string str = ex.StackTrace;
  11193. AddMessage_Station(stationNameStr, LogType.Error,
  11194. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  11195. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11196. // MES_Flag
  11197. stopwatch2.Start();
  11198. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  11199. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11200. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  11201. writeToPLC_Flag.Adress = 2924;
  11202. writeToPLC_Flag.Value = (short)4;
  11203. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  11204. stopwatch2.Stop();
  11205. }
  11206. stopwatch1.Stop();
  11207. AddMessage(LogType.Info,
  11208. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11209. stopwatch2.ElapsedMilliseconds + "ms");
  11210. }
  11211. #endregion [S4] 取放桁架
  11212. #endregion PLC4 刘果段
  11213. #region PLC5 张超凡
  11214. #region [S5] Tray盘下料装备
  11215. /// <summary>
  11216. /// S5工位的数据- 触发信号上次的值
  11217. /// </summary>
  11218. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  11219. /// <summary>
  11220. /// S5工位的数据(含触发信号)
  11221. /// </summary>
  11222. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  11223. /// <summary>
  11224. /// S5工位的数据- 回写点位
  11225. /// </summary>
  11226. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  11227. /// <summary>
  11228. /// [S5] Tray盘下料装备
  11229. /// </summary>
  11230. /// <param name="plcNo">PLC编号</param>
  11231. //private void ReadStation_S5(int plcNo)
  11232. //{
  11233. // // [S1] Tray盘上料装备
  11234. // // [S2] FCT
  11235. // // [S3] 值板机
  11236. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  11237. // // [S5] Tray盘下料装备
  11238. // /// 上位机心跳
  11239. // /// 获取设备报警数据与状态信息
  11240. // string stationCode = "[S5]";
  11241. // string stationName = "Tray盘下料装备";
  11242. // string stationNameStr = stationCode + stationName;
  11243. // #region 创建字典
  11244. // // 触发信号字典 赋值
  11245. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  11246. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  11247. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  11248. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  11249. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  11250. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  11251. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  11252. // // PLC数据字典 赋值
  11253. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  11254. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  11255. // s5PLCData.Add("e1ProductSN_Check", ""); //
  11256. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  11257. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  11258. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  11259. // s5PLCData.Add("e1PartNo", ""); // 物料码
  11260. // s5PLCData.Add("e1Result", 0); // 产品结果
  11261. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  11262. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  11263. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  11264. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  11265. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  11266. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  11267. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  11268. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  11269. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  11270. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  11271. // #endregion 创建字典
  11272. // while (IsRun)
  11273. // {
  11274. // try
  11275. // {
  11276. // if (!GlobalContext._IsCon_Funs5)
  11277. // {
  11278. // UpdatePLCMonitor(1, plcNo, 0);
  11279. // continue;
  11280. // }
  11281. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  11282. // {
  11283. // Stopwatch stopwatch1 = new Stopwatch();
  11284. // Stopwatch stopwatch2 = new Stopwatch();
  11285. // stopwatch1.Start();
  11286. // stopwatch2.Start();
  11287. // #region 一次性读取所有数据
  11288. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  11289. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  11290. // int[] datas = data1.Concat(data2).ToArray();
  11291. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  11292. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  11293. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  11294. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  11295. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  11296. // s5PLCData["e1MES_FLAG"] = datas[35];
  11297. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  11298. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  11299. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  11300. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  11301. // s5PLCData["e1Result"] = datas[76];
  11302. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  11303. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  11304. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  11305. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  11306. // s5PLCData["e1OEEType"] = datas[109];
  11307. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  11308. // s5PLCData["e1AGVUpStart"] = datas[121];
  11309. // s5PLCData["e1AGVUpEnd"] = datas[122];
  11310. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  11311. // s5PLCData["e1AGVDownStart"] = datas[134];
  11312. // s5PLCData["e1AGVDownEnd"] = datas[135];
  11313. // #endregion 一次性读取所有数据
  11314. // stopwatch2.Stop();
  11315. // #region 回写操作,写后清空flag
  11316. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  11317. // #endregion 回写操作,写后清空flag
  11318. // #region 进站校验
  11319. // try
  11320. // {
  11321. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  11322. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  11323. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  11324. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  11325. // {
  11326. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  11327. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  11328. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  11329. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  11330. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  11331. // }
  11332. // }
  11333. // catch (Exception ex)
  11334. // {
  11335. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  11336. // string str = ex.StackTrace;
  11337. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11338. // }
  11339. // #endregion 进站校验
  11340. // #region 出站接口
  11341. // try
  11342. // {
  11343. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  11344. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  11345. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  11346. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  11347. // {
  11348. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  11349. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  11350. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  11351. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  11352. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  11353. // }
  11354. // }
  11355. // catch (Exception ex)
  11356. // {
  11357. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  11358. // string str = ex.StackTrace;
  11359. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11360. // }
  11361. // #endregion 出站接口
  11362. // #region 节拍接口
  11363. // try
  11364. // {
  11365. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  11366. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  11367. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  11368. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  11369. // {
  11370. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  11371. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  11372. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  11373. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  11374. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  11375. // }
  11376. // }
  11377. // catch (Exception ex)
  11378. // {
  11379. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  11380. // string str = ex.StackTrace;
  11381. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11382. // }
  11383. // #endregion 节拍接口
  11384. // #region AGV上料
  11385. // // AGV上料叫AGV信号
  11386. // try
  11387. // {
  11388. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  11389. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  11390. // if (e1AGVUpCall != e1AGVUpCallOld)
  11391. // {
  11392. // if (e1AGVUpCall == 1) // 0->1
  11393. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  11394. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  11395. // }
  11396. // }
  11397. // catch (Exception ex)
  11398. // {
  11399. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  11400. // string str = ex.StackTrace;
  11401. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11402. // }
  11403. // // AGV上料完成信号
  11404. // try
  11405. // {
  11406. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  11407. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  11408. // if (e1AGVUpEnd != e1AGVUpEndOld)
  11409. // {
  11410. // if (e1AGVUpEnd == 1) // 0->1
  11411. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  11412. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  11413. // }
  11414. // }
  11415. // catch (Exception ex)
  11416. // {
  11417. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  11418. // string str = ex.StackTrace;
  11419. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11420. // }
  11421. // #endregion AGV上料
  11422. // #region AGV下料
  11423. // // AGV下料叫agv信号
  11424. // try
  11425. // {
  11426. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  11427. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  11428. // if (e1AGVDownCall != e1AGVDownCallOld)
  11429. // {
  11430. // if (e1AGVDownCall == 1) // 0->1
  11431. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  11432. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  11433. // }
  11434. // }
  11435. // catch (Exception ex)
  11436. // {
  11437. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  11438. // string str = ex.StackTrace;
  11439. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11440. // }
  11441. // // AGV下料完成信号
  11442. // try
  11443. // {
  11444. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  11445. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  11446. // if (e1AGVDownEnd != e1AGVDownEndOld)
  11447. // {
  11448. // if (e1AGVDownEnd == 1) // 0->1
  11449. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  11450. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  11451. // }
  11452. // }
  11453. // catch (Exception ex)
  11454. // {
  11455. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  11456. // string str = ex.StackTrace;
  11457. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11458. // }
  11459. // #endregion AGV下料
  11460. // #region 心跳
  11461. // try
  11462. // {
  11463. // short states = 0;
  11464. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  11465. // }
  11466. // catch (Exception ex)
  11467. // {
  11468. // string str = ex.StackTrace;
  11469. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11470. // }
  11471. // #endregion 心跳
  11472. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  11473. // stopwatch1.Stop();
  11474. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  11475. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  11476. // }
  11477. // else
  11478. // {
  11479. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  11480. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  11481. // Funs[plcNo].Connect();
  11482. // }
  11483. // }
  11484. // catch (Exception ex)
  11485. // {
  11486. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  11487. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  11488. // Funs[plcNo].ReConnect();
  11489. // }
  11490. // Thread.Sleep(IntervalReadPLC);
  11491. // }
  11492. //}
  11493. /// <summary>
  11494. /// [S5] Tray盘下料装备 - 进站校验
  11495. /// </summary>
  11496. /// <param name="plcNo">PLC编号</param>
  11497. /// <param name="stationNameStr">工站全称</param>
  11498. private void S5进站校验(int plcNo, string stationNameStr)
  11499. {
  11500. Stopwatch stopwatch1 = new Stopwatch();
  11501. Stopwatch stopwatch2 = new Stopwatch();
  11502. try
  11503. {
  11504. stopwatch1.Start();
  11505. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  11506. sn = sn.Replace("\0", "");
  11507. // 获取产品SN By 载具码
  11508. #region 查询载具上的产品信息
  11509. string cavityData = string.Empty;
  11510. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  11511. if (string.IsNullOrEmpty(cavityData))
  11512. cavityData = "";
  11513. if (snResult != 0)
  11514. {
  11515. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11516. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  11517. writeToPLC_Flag1.Adress = 2003;
  11518. writeToPLC_Flag1.Value = (short)6;
  11519. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  11520. stopwatch1.Stop();
  11521. AddMessage(LogType.Info,
  11522. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11523. return;
  11524. }
  11525. string[] cavitySNs = cavityData.Split('.');
  11526. string partNo = string.Empty;
  11527. if (cavitySNs != null && cavitySNs.Length >= 1)
  11528. partNo = cavitySNs[0];
  11529. #endregion 查询载具上的产品信息
  11530. // 产品SN(物料码)校验
  11531. List<TestItem> item = new List<TestItem>();
  11532. item.Add(new TestItem()
  11533. {
  11534. Parameter_name = "载具码",
  11535. Parameter_value = sn,
  11536. });
  11537. item.Add(new TestItem()
  11538. {
  11539. Parameter_name = "载具穴号",
  11540. Parameter_value = "1",
  11541. });
  11542. stopwatch2.Start();
  11543. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  11544. partNo, item, out string errorMsg);
  11545. stopwatch2.Stop();
  11546. short e1MES_FLAG_Check = (short)result;
  11547. // MES_Flag
  11548. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  11549. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11550. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  11551. writeToPLC_Flag.Adress = 2003;
  11552. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  11553. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  11554. }
  11555. catch (Exception ex)
  11556. {
  11557. string str = ex.StackTrace;
  11558. AddMessage_Station(stationNameStr, LogType.Error,
  11559. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  11560. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11561. // MES_Flag
  11562. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  11563. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11564. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  11565. writeToPLC_Flag.Adress = 2003;
  11566. writeToPLC_Flag.Value = (short)6;
  11567. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  11568. }
  11569. stopwatch1.Stop();
  11570. AddMessage(LogType.Info,
  11571. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  11572. stopwatch2.ElapsedMilliseconds + "ms");
  11573. }
  11574. /// <summary>
  11575. /// [S5] Tray盘下料装备 - 出站接口
  11576. /// </summary>
  11577. /// <param name="plcNo"></param>
  11578. /// <param name="stationCode"></param>
  11579. /// <param name="stationName"></param>
  11580. private void S5出站接口(int plcNo, string stationCode, string stationName)
  11581. {
  11582. Stopwatch stopwatch1 = new Stopwatch();
  11583. Stopwatch stopwatch2 = new Stopwatch();
  11584. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  11585. string stationNameStr = stationCode + stationName;
  11586. string processItem = stationName; // 测试项目
  11587. try
  11588. {
  11589. stopwatch1.Start();
  11590. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  11591. //string batch_num = GlobalContext.BatchNumber; // 批次号
  11592. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  11593. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  11594. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  11595. sn = sn.Replace("\0", "");
  11596. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  11597. //partNo = partNo.Replace("\0", "");
  11598. #region 查询载具上的产品信息
  11599. string cavityData = string.Empty;
  11600. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  11601. if (string.IsNullOrEmpty(cavityData))
  11602. cavityData = "";
  11603. if (snResult != 0)
  11604. {
  11605. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11606. writeToPLC_Flag1.Name = "e1MES_FLAG";
  11607. writeToPLC_Flag1.Adress = 2035;
  11608. writeToPLC_Flag1.Value = (short)4;
  11609. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  11610. stopwatch1.Stop();
  11611. AddMessage(LogType.Info,
  11612. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11613. return;
  11614. }
  11615. string[] cavitySNs = cavityData.Split('.');
  11616. string partNo = string.Empty;
  11617. if (cavitySNs != null && cavitySNs.Length >= 1)
  11618. partNo = cavitySNs[0];
  11619. #endregion 查询载具上的产品信息
  11620. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  11621. bool pass = e1Result == 1;
  11622. stopwatch2.Start();
  11623. // 上传MES
  11624. List<TestItem> items = new List<TestItem>();
  11625. items.Add(new TestItem()
  11626. {
  11627. Parameter_name = "载具码",
  11628. Parameter_value = sn,
  11629. Parameter_unit = ""
  11630. });
  11631. items.Add(new TestItem()
  11632. {
  11633. Parameter_name = "载具穴号",
  11634. Parameter_value = "1",
  11635. Parameter_unit = ""
  11636. });
  11637. items.Add(new TestItem()
  11638. {
  11639. Parameter_name = "产品结果",
  11640. Parameter_value = e1Result == 1 ? "OK" : "NG",
  11641. Parameter_unit = ""
  11642. });
  11643. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  11644. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  11645. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  11646. short result = result1 == 1 ? (short)1 : (short)3;
  11647. stopwatch2.Stop();
  11648. #region 存储绑定数据到 边线MES系统中
  11649. if (result == 1)
  11650. {
  11651. // 删除绑定信息
  11652. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  11653. if (resultMesR != 0)
  11654. {
  11655. result = 4;
  11656. AddMessage_Station(stationNameStr, LogType.Error,
  11657. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  11658. }
  11659. }
  11660. #endregion 存储绑定数据到 边线MES系统中
  11661. // MES_Flag 为MES报错
  11662. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11663. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  11664. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11665. writeToPLC_Flag.Name = "e1MES_FLAG";
  11666. writeToPLC_Flag.Adress = 2035;
  11667. writeToPLC_Flag.Value = result;
  11668. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  11669. OnMessage(LogType.Debug,
  11670. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  11671. }
  11672. catch (Exception ex)
  11673. {
  11674. stopwatch2.Restart();
  11675. // MES_Flag 为4上位机报错
  11676. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  11677. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11678. writeToPLC_Flag.Name = "e1MES_FLAG";
  11679. writeToPLC_Flag.Adress = 2035;
  11680. writeToPLC_Flag.Value = (short)4;
  11681. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  11682. stopwatch2.Stop();
  11683. string str = ex.StackTrace;
  11684. AddMessage_Station(stationNameStr, LogType.Error,
  11685. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11686. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11687. }
  11688. stopwatch1.Stop();
  11689. AddMessage(LogType.Info,
  11690. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11691. stopwatch2.ElapsedMilliseconds + "ms");
  11692. }
  11693. /// <summary>
  11694. /// [S5] Tray盘下料装备 - 节拍接口
  11695. /// </summary>
  11696. /// <param name="plcNo">PLC编号</param>
  11697. /// <param name="stationNameStr">工站全称</param>
  11698. //private void S5节拍接口(int plcNo, string stationNameStr)
  11699. //{
  11700. // Stopwatch stopwatch1 = new Stopwatch();
  11701. // Stopwatch stopwatch2 = new Stopwatch();
  11702. // string resultStr = string.Empty;
  11703. // try
  11704. // {
  11705. // stopwatch1.Start();
  11706. // string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  11707. // string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  11708. // e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  11709. // bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  11710. // if (!actionBool)
  11711. // {
  11712. // stopwatch2.Start();
  11713. // // MES_Flag
  11714. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11715. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11716. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  11717. // writeToPLC_Flag1.Adress = 2088;
  11718. // writeToPLC_Flag1.Value = (short)4;
  11719. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  11720. // stopwatch2.Stop();
  11721. // AddMessage(LogType.Info,
  11722. // stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  11723. // "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  11724. // return;
  11725. // }
  11726. // string e1OEEPartNo = string.Empty; // 物料码
  11727. // if (string.IsNullOrEmpty(e1OEEProductSN))
  11728. // {
  11729. // stopwatch2.Start();
  11730. // // MES_Flag
  11731. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11732. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11733. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  11734. // writeToPLC_Flag1.Adress = 2088;
  11735. // writeToPLC_Flag1.Value = (short)1;
  11736. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  11737. // stopwatch2.Stop();
  11738. // AddMessage(LogType.Info,
  11739. // stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11740. // stopwatch2.ElapsedMilliseconds + "ms");
  11741. // return;
  11742. // }
  11743. // else
  11744. // {
  11745. // // 查产品SN
  11746. // e1OEEPartNo = "Test"; // ZS
  11747. // }
  11748. // short e1OEEMES_FLAG = 0;
  11749. // // 上传OEE
  11750. // (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  11751. // e1OEEMES_FLAG = result.Item1;
  11752. // resultStr = result.Item2;
  11753. // stopwatch2.Start();
  11754. // // MES_Flag
  11755. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11756. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11757. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  11758. // writeToPLC_Flag.Adress = 2088;
  11759. // writeToPLC_Flag.Value = e1OEEMES_FLAG;
  11760. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  11761. // stopwatch2.Stop();
  11762. // }
  11763. // catch (Exception ex)
  11764. // {
  11765. // string str = ex.StackTrace;
  11766. // AddMessage_Station(stationNameStr, LogType.Error,
  11767. // $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  11768. // str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11769. // // MES_Flag
  11770. // stopwatch2.Start();
  11771. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  11772. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11773. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  11774. // writeToPLC_Flag.Adress = 2088;
  11775. // writeToPLC_Flag.Value = (short)4;
  11776. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  11777. // stopwatch2.Stop();
  11778. // }
  11779. // stopwatch1.Stop();
  11780. // AddMessage(LogType.Info,
  11781. // stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11782. // stopwatch2.ElapsedMilliseconds + "ms");
  11783. //}
  11784. /// <summary>
  11785. /// [S5] Tray盘下料装备 - AGV上料叫agv
  11786. /// </summary>
  11787. /// <param name="plcNo">PLC编号</param>
  11788. /// <param name="stationNameStr">工站全称</param>
  11789. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  11790. {
  11791. Stopwatch stopwatch1 = new Stopwatch();
  11792. Stopwatch stopwatch2 = new Stopwatch();
  11793. try
  11794. {
  11795. stopwatch1.Start();
  11796. // ZS 呼叫AGV
  11797. short e1AGVUpCall = 2;
  11798. stopwatch2.Start();
  11799. // e1AGVUpCall
  11800. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11801. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11802. writeToPLC_Flag.Name = "e1AGVUpCall";
  11803. writeToPLC_Flag.Adress = 2120;
  11804. writeToPLC_Flag.Value = e1AGVUpCall;
  11805. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  11806. stopwatch2.Stop();
  11807. }
  11808. catch (Exception ex)
  11809. {
  11810. string str = ex.StackTrace;
  11811. AddMessage_Station(stationNameStr, LogType.Error,
  11812. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  11813. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11814. // e1AGVUpCall
  11815. stopwatch2.Start();
  11816. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  11817. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11818. writeToPLC_Flag.Name = "e1AGVUpCall";
  11819. writeToPLC_Flag.Adress = 2120;
  11820. writeToPLC_Flag.Value = (short)4;
  11821. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  11822. stopwatch2.Stop();
  11823. }
  11824. stopwatch1.Stop();
  11825. AddMessage(LogType.Info,
  11826. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11827. stopwatch2.ElapsedMilliseconds + "ms");
  11828. }
  11829. /// <summary>
  11830. /// [S5] Tray盘下料装备 - AGV上料完成
  11831. /// </summary>
  11832. /// <param name="plcNo">PLC编号</param>
  11833. /// <param name="stationNameStr">工站全称</param>
  11834. private void S5AGV上料完成(int plcNo, string stationNameStr)
  11835. {
  11836. Stopwatch stopwatch1 = new Stopwatch();
  11837. Stopwatch stopwatch2 = new Stopwatch();
  11838. try
  11839. {
  11840. stopwatch1.Start();
  11841. // ZS AGV上料完成,让小车离开
  11842. short e1AGVUpEnd = 2;
  11843. stopwatch2.Start();
  11844. // e1AGVUpEnd
  11845. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11846. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11847. writeToPLC_Flag.Name = "e1AGVUpEnd";
  11848. writeToPLC_Flag.Adress = 2122;
  11849. writeToPLC_Flag.Value = e1AGVUpEnd;
  11850. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  11851. stopwatch2.Stop();
  11852. }
  11853. catch (Exception ex)
  11854. {
  11855. string str = ex.StackTrace;
  11856. AddMessage_Station(stationNameStr, LogType.Error,
  11857. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  11858. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11859. // e1AGVUpEnd
  11860. stopwatch2.Start();
  11861. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  11862. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11863. writeToPLC_Flag.Name = "e1AGVUpEnd";
  11864. writeToPLC_Flag.Adress = 2122;
  11865. writeToPLC_Flag.Value = (short)4;
  11866. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  11867. stopwatch2.Stop();
  11868. }
  11869. stopwatch1.Stop();
  11870. AddMessage(LogType.Info,
  11871. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11872. stopwatch2.ElapsedMilliseconds + "ms");
  11873. }
  11874. /// <summary>
  11875. /// [S5] Tray盘下料装备 - AGV下料叫agv
  11876. /// </summary>
  11877. /// <param name="plcNo">PLC编号</param>
  11878. /// <param name="stationNameStr">工站全称</param>
  11879. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  11880. {
  11881. Stopwatch stopwatch1 = new Stopwatch();
  11882. Stopwatch stopwatch2 = new Stopwatch();
  11883. try
  11884. {
  11885. stopwatch1.Start();
  11886. // ZS 呼叫AGV
  11887. short e1AGVDownCall = 2;
  11888. stopwatch2.Start();
  11889. // e1AGVDownCall
  11890. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11891. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11892. writeToPLC_Flag.Name = "e1AGVDownCall";
  11893. writeToPLC_Flag.Adress = 2133;
  11894. writeToPLC_Flag.Value = e1AGVDownCall;
  11895. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  11896. stopwatch2.Stop();
  11897. }
  11898. catch (Exception ex)
  11899. {
  11900. string str = ex.StackTrace;
  11901. AddMessage_Station(stationNameStr, LogType.Error,
  11902. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  11903. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11904. // e1AGVDownCall
  11905. stopwatch2.Start();
  11906. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  11907. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11908. writeToPLC_Flag.Name = "e1AGVDownCall";
  11909. writeToPLC_Flag.Adress = 2133;
  11910. writeToPLC_Flag.Value = (short)4;
  11911. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  11912. stopwatch2.Stop();
  11913. }
  11914. stopwatch1.Stop();
  11915. AddMessage(LogType.Info,
  11916. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11917. stopwatch2.ElapsedMilliseconds + "ms");
  11918. }
  11919. /// <summary>
  11920. /// [S5] Tray盘下料装备 - AGV下料完成
  11921. /// </summary>
  11922. /// <param name="plcNo">PLC编号</param>
  11923. /// <param name="stationNameStr">工站全称</param>
  11924. private void S5AGV下料完成(int plcNo, string stationNameStr)
  11925. {
  11926. Stopwatch stopwatch1 = new Stopwatch();
  11927. Stopwatch stopwatch2 = new Stopwatch();
  11928. try
  11929. {
  11930. stopwatch1.Start();
  11931. // ZS AGV上料完成,让小车离开
  11932. short e1AGVDownEnd = 2;
  11933. stopwatch2.Start();
  11934. // e1AGVDownEnd
  11935. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11936. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11937. writeToPLC_Flag.Name = "e1AGVDownEnd";
  11938. writeToPLC_Flag.Adress = 2135;
  11939. writeToPLC_Flag.Value = e1AGVDownEnd;
  11940. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  11941. stopwatch2.Stop();
  11942. }
  11943. catch (Exception ex)
  11944. {
  11945. string str = ex.StackTrace;
  11946. AddMessage_Station(stationNameStr, LogType.Error,
  11947. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  11948. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11949. // e1AGVDownEnd
  11950. stopwatch2.Start();
  11951. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  11952. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11953. writeToPLC_Flag.Name = "e1AGVDownEnd";
  11954. writeToPLC_Flag.Adress = 2135;
  11955. writeToPLC_Flag.Value = (short)4;
  11956. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  11957. stopwatch2.Stop();
  11958. }
  11959. stopwatch1.Stop();
  11960. AddMessage(LogType.Info,
  11961. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11962. stopwatch2.ElapsedMilliseconds + "ms");
  11963. }
  11964. #endregion [S5] Tray盘下料装备
  11965. #endregion PLC5 张超凡
  11966. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  11967. /// <summary>
  11968. /// PLC读取到的数据 -添加数据
  11969. /// </summary>
  11970. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  11971. {
  11972. if (sxPlcData.ContainsKey(newKey))
  11973. sxPlcData[newKey] = newValue;
  11974. else
  11975. sxPlcData.Add(newKey, newValue);
  11976. }
  11977. /// <summary>
  11978. /// PLC需要写入的数据 -添加数据
  11979. /// </summary>
  11980. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey,
  11981. WriteToPLC_Flag newValue)
  11982. {
  11983. if (sxPLCWriteData.ContainsKey(newKey))
  11984. sxPLCWriteData[newKey] = newValue;
  11985. else
  11986. sxPLCWriteData.Add(newKey, newValue);
  11987. }
  11988. /// <summary>
  11989. /// PLC回写操作,写后清空flag
  11990. /// </summary>
  11991. /// <param name="modbusClient">modbus对象</param>
  11992. /// <param name="pLCReadDatas">读取到的数据字典</param>
  11993. /// <param name="pLCWriteDatas">需要写入的数据</param>
  11994. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas,
  11995. ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  11996. {
  11997. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  11998. {
  11999. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  12000. for (int i = 0; i < pLCWriteDatas.Count; i++)
  12001. {
  12002. string mesFlagName = pLCWriteDatas[i].Name;
  12003. int mesFlagAdress = pLCWriteDatas[i].Adress;
  12004. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  12005. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  12006. {
  12007. // 先回写数据
  12008. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  12009. for (int j = 0; j < writeToPLCDatas.Count; j++)
  12010. {
  12011. int mesDataAdress = writeToPLCDatas[j].Adress;
  12012. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  12013. switch (mesDataType)
  12014. {
  12015. case PLCValueType.Short:
  12016. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  12017. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  12018. break;
  12019. case PLCValueType.String:
  12020. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  12021. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  12022. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr,
  12023. mesDataValueStrLength);
  12024. break;
  12025. }
  12026. }
  12027. // 再回写信号
  12028. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  12029. // 存储读取数据的字典
  12030. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  12031. // 存储写入数据的字典 - 清空写入值
  12032. pLCWriteDatas[i].Value = (short)0;
  12033. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  12034. }
  12035. }
  12036. }
  12037. }
  12038. /// <summary>
  12039. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  12040. /// </summary>
  12041. /// <param name="no">3</param>
  12042. /// <param name="stationCode">设备编号</param>
  12043. /// <param name="stationNameStr">设备名称</param>
  12044. /// <param name="plcOrder">车间订单号</param>
  12045. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  12046. {
  12047. try
  12048. {
  12049. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  12050. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  12051. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  12052. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  12053. int result1 = 0;
  12054. switch (stationCode)
  12055. {
  12056. case 2:
  12057. case 3:
  12058. case 4:
  12059. case 6:
  12060. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  12061. break;
  12062. case 102:
  12063. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  12064. break;
  12065. case 103:
  12066. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  12067. break;
  12068. case 104:
  12069. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  12070. break;
  12071. case 106:
  12072. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  12073. break;
  12074. default:
  12075. // MES_Flag 为“6未找到正确设备编号”
  12076. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  12077. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  12078. return;
  12079. }
  12080. short result = result1 == 1 ? (short)1 : (short)2;
  12081. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  12082. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  12083. }
  12084. catch (Exception ex)
  12085. {
  12086. // MES_Flag 为2上位机报错
  12087. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  12088. string str = ex.StackTrace;
  12089. AddMessage_Station(stationNameStr, LogType.Error,
  12090. $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  12091. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12092. }
  12093. }
  12094. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  12095. #region UI刷新
  12096. /// <summary>
  12097. /// 更新商品信息的UI + 下发产品信息(SN)
  12098. /// </summary>
  12099. private void UpdateProductInfo()
  12100. {
  12101. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  12102. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  12103. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  12104. //txt_CurSupplierCode.Text = ""; // 供应商代号
  12105. }
  12106. /// <summary>
  12107. /// 更新PLC连接状态的UI
  12108. /// </summary>
  12109. /// <param name="no">PLC编号</param>
  12110. /// <param name="status">状态</param>
  12111. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  12112. {
  12113. if (this != null && !this.IsDisposed)
  12114. {
  12115. switch (imgNo)
  12116. {
  12117. case 1:
  12118. this.BeginInvoke(new Action(() => { picPLC.Image = imageListState.Images[status]; }));
  12119. break;
  12120. case 2:
  12121. this.BeginInvoke(new Action(() => { pictureBox2.Image = imageListState.Images[status]; }));
  12122. break;
  12123. case 3:
  12124. this.BeginInvoke(new Action(() => { pictureBox3.Image = imageListState.Images[status]; }));
  12125. break;
  12126. case 4:
  12127. this.BeginInvoke(new Action(() => { pictureBox4.Image = imageListState.Images[status]; }));
  12128. break;
  12129. case 5:
  12130. this.BeginInvoke(new Action(() => { pictureBox5.Image = imageListState.Images[status]; }));
  12131. break;
  12132. case 6:
  12133. this.BeginInvoke(new Action(() => { pictureBox6.Image = imageListState.Images[status]; }));
  12134. break;
  12135. case 7:
  12136. this.BeginInvoke(new Action(() => { pictureBox7.Image = imageListState.Images[status]; }));
  12137. break;
  12138. case 8:
  12139. this.BeginInvoke(new Action(() => { pictureBox8.Image = imageListState.Images[status]; }));
  12140. break;
  12141. default:
  12142. break;
  12143. }
  12144. }
  12145. Task.Run(() => // 更新PLC交互页的指示灯
  12146. {
  12147. try
  12148. {
  12149. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  12150. {
  12151. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  12152. }
  12153. }
  12154. catch
  12155. {
  12156. }
  12157. });
  12158. }
  12159. #endregion UI刷新
  12160. #region 日志
  12161. /// <summary>
  12162. /// 添加各工位运行日志(同步至PLC交互页面)
  12163. /// </summary>
  12164. /// <param name="stationNameStr">工站名称</param>
  12165. /// <param name="logType">日志类型</param>
  12166. /// <param name="message">日志内容</param>
  12167. /// <param name="snNumber">产品数字SN</param>
  12168. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  12169. {
  12170. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")))
  12171. {
  12172. AddMessage(logType, message); // 首页展示+日志记录
  12173. }
  12174. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  12175. {
  12176. StationName = stationNameStr,
  12177. SnNumber = snNumber,
  12178. Message = message,
  12179. CreateTime = DateTime.Now
  12180. };
  12181. // PLC交互页展示
  12182. Task.Run(() =>
  12183. {
  12184. try
  12185. {
  12186. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  12187. {
  12188. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  12189. }
  12190. }
  12191. catch
  12192. {
  12193. }
  12194. });
  12195. }
  12196. /// <summary>
  12197. /// 添加运行日志
  12198. /// </summary>
  12199. /// <param name="logType">日志类型</param>
  12200. /// <param name="message">日志内容</param>
  12201. public void AddMessage(LogType logType, string message)
  12202. {
  12203. OnMessage(logType, message);
  12204. string date = DateTime.Now.ToString("yyyy/MM/dd");
  12205. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  12206. string msgShow = time + "--> " + message + "\r\n";
  12207. this.BeginInvoke(new Action(() =>
  12208. {
  12209. systemLog.Rows.Insert(0, date, time, message);
  12210. if (systemLog.Rows.Count >= 100)
  12211. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  12212. }));
  12213. }
  12214. /// <summary>
  12215. /// 添加运行日志-保存
  12216. /// </summary>
  12217. /// <param name="logType">日志类型</param>
  12218. /// <param name="message">日志内容</param>
  12219. private void OnMessage(LogType logType, string msg)
  12220. {
  12221. MessageEvent?.Invoke(logType, msg);
  12222. }
  12223. /// <summary>
  12224. /// 保存PLC写入日志
  12225. /// </summary>
  12226. /// <param name="logType"></param>
  12227. /// <param name="logValue"></param>
  12228. private void WritePLCLog(LogType logType, string logValue)
  12229. {
  12230. switch ((int)logType)
  12231. {
  12232. case 0:
  12233. _PLCLogNet.WriteDebug(logValue);
  12234. break;
  12235. case 1:
  12236. _PLCLogNet.WriteInfo(logValue);
  12237. break;
  12238. case 2:
  12239. _PLCLogNet.WriteWarn(logValue);
  12240. break;
  12241. case 3:
  12242. _PLCLogNet.WriteError(logValue);
  12243. break;
  12244. default:
  12245. _PLCLogNet.WriteFatal(logValue);
  12246. break;
  12247. }
  12248. }
  12249. /// <summary>
  12250. /// IOT Mqtt回调方法- With DataId
  12251. /// </summary>
  12252. /// <param name="id"></param>
  12253. /// <param name="v"></param>
  12254. /// <param name="dataId"></param>
  12255. public void CallbackWithDataId(string id, string msg, string dataId)
  12256. {
  12257. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  12258. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  12259. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  12260. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  12261. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  12262. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  12263. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  12264. }
  12265. /// <summary>
  12266. /// AGV Mqtt回调方法- 记录Log并处理数据
  12267. /// </summary>
  12268. /// <param name="obj"></param>
  12269. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  12270. {
  12271. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  12272. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  12273. // 接收到的信息
  12274. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  12275. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  12276. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  12277. {
  12278. }
  12279. }
  12280. #endregion 日志
  12281. }
  12282. }