Form_Home.cs 680 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. //using System.Text;
  8. using Microsoft.Win32;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using HslCommunication.LogNet;
  13. using MainForm.FaForm;
  14. using Sunny.UI;
  15. using MainForm.ClassFile.XiaomiAPI;
  16. using System.Diagnostics;
  17. using MainForm.Models;
  18. using SqlSugar;
  19. using EasyModbus;
  20. using ModBusClientSimple.Util;
  21. using csharp_networkprotocol_hpsocket;
  22. using MqttnetServerWin;
  23. using Sunny.UI.Win32;
  24. using MainForm.ClassFile.XiaomiAPI_AGV;
  25. using MainForm.ClassFile.XiaomiAPI_RouteCom;
  26. using HslCommunication.Controls;
  27. using EIP_Protocol;
  28. using MainForm.ClassFile.XiaomiAPI_MES;
  29. using NPOI.Util;
  30. using static MainForm.SQLHelper;
  31. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
  32. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
  33. using MainForm.ClassFile.ProjectClass;
  34. using CommonLib;
  35. using Org.BouncyCastle.Asn1.IsisMtt;
  36. using System.Web.Services.Description;
  37. using System.Numerics;
  38. using MathNet.Numerics.RootFinding;
  39. using HslCommunication.Enthernet;
  40. using BZFAStandardLib;
  41. using MainForm.ClassFile;
  42. using NPOI.SS.Formula.Functions;
  43. using static MainForm.ClassFile.XiaomiAPI.XiaomiMqttClient_Extend;
  44. using System.Net.Http;
  45. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_UpLoadFile;
  46. using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
  47. using System.Reflection;
  48. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
  49. using FaFrameUI;
  50. using System.Security.Policy;
  51. using static MainForm.ClassFile.XiaomiClass.MesHelper;
  52. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
  53. using System.Drawing.Imaging;
  54. using System.Drawing;
  55. using ICSharpCode.SharpZipLib.Zip;
  56. using System.Text.RegularExpressions;
  57. using System.Text;
  58. /*
  59. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  60. */
  61. namespace MainForm
  62. {
  63. /// <summary>
  64. /// 记录日志的委托
  65. /// </summary>
  66. /// <param name="logType">日志类型</param>
  67. /// <param name="message">日志信息</param>
  68. public delegate void HomeMessageHandler(LogType logType, string message);
  69. /// <summary>
  70. /// 主页窗体
  71. /// </summary>
  72. public partial class Form_Home : Form
  73. {
  74. #region 常量
  75. //文本常量
  76. private const string Head = "开始采集";
  77. private const string Tail = "采集完成";
  78. private const string Body = "工位出站数据";
  79. private const string BodyCheck = "工位点检数据";
  80. private const string BodyRun = "整线运行数据";
  81. private const string BodyAlarm = "整线报警数据";
  82. #endregion 常量
  83. #region 变量
  84. /// <summary>
  85. /// 委托-记录日志的方法
  86. /// </summary>
  87. public event HomeMessageHandler MessageEvent;
  88. /// <summary>
  89. /// 日志接口
  90. /// </summary>
  91. ILogNet _PLCLogNet;
  92. /// <summary>
  93. /// 用于记录IOT MQTT日志
  94. /// </summary>
  95. ILogNet _IOTMqttLogNet;
  96. /// <summary>
  97. /// 用于记录AGV MQTT日志
  98. /// </summary>
  99. ILogNet _AGVMqttLogNet;
  100. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  101. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  102. // 间隔时间
  103. private int IntervalReadPLC = 300; //ms 读PLC
  104. private int IntervalMonitorMES = 1000; //ms MES心跳
  105. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  106. /// <summary>
  107. /// 设备报警数据
  108. /// </summary>
  109. uint[] _FaultDatas = { };
  110. uint[] _FaultDatas_Old = { };
  111. uint[] _FaultDatas2 = { };
  112. uint[] _FaultDatas_Old2 = { };
  113. // 软件状态
  114. private bool IsRun = true;
  115. #region PLC 与 TCP对象
  116. // 定义一个字典,存plc对象(通讯)
  117. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  118. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  119. // 定义TCPClient对象列表
  120. Dictionary<int, HPSocket_TcpClientHelper>
  121. _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  122. // 定义MQTTHelper对象
  123. MQTTHelper _MQTTHelper = new MQTTHelper();
  124. #endregion PLC 与 TCP对象
  125. /// <summary>
  126. /// 上次的设备运行信息
  127. /// </summary>
  128. private string lineWorkingData1_OldStr = string.Empty;
  129. /// <summary>
  130. /// 设备报警字典-当前结果
  131. /// Dictionary<工位代码,List<报警信息>>
  132. /// </summary>
  133. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  134. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  135. /// <summary>
  136. /// 单机用-设备状态
  137. /// </summary>
  138. //XiaomiDeviceState xmDeviceState = XiaomiDeviceState.Uninitialized;
  139. XiaomiDeviceStateData xmDeviceStateData = new XiaomiDeviceStateData();
  140. private int test_item_num = 0; //iot 过站数据序号
  141. public static string uuid = ""; //单工位或左工位
  142. public static string uuid2 = ""; //右工位
  143. private bool inpass = false; //保存进站测试状态
  144. public static XiaoMiParm xiaomiParm = new XiaoMiParm();
  145. //记录上传附件的信息
  146. public static FileUpload_FileData fileUploadData = new FileUpload_FileData();
  147. #endregion 变量
  148. #region 窗体基础事件
  149. /// <summary>
  150. /// 初始化
  151. /// </summary>
  152. public Form_Home()
  153. {
  154. InitializeComponent();
  155. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  156. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  157. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  158. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  159. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  160. }
  161. /// <summary>
  162. /// 窗体加载事件
  163. /// </summary>
  164. public void Form_Home_Load(object sender, EventArgs e)
  165. {
  166. try
  167. {
  168. AddMessage(LogType.Info, "开始初始化程序");
  169. //组建plc对象字典
  170. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  171. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  172. if (GlobalContext.IsUsePLC1)
  173. {
  174. GlobalContext.IsUsePLCNow = 1;
  175. GlobalContext.IsUseStationName = "[OP10]壳体清洁上料";
  176. FunsEip.Add(GlobalContext.IsUsePLCNow,
  177. new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  178. }
  179. if (GlobalContext.IsUsePLC2)
  180. {
  181. GlobalContext.IsUsePLCNow = 2;
  182. GlobalContext.IsUseStationName = "[OP20]上盖板上料装备";
  183. FunsEip.Add(GlobalContext.IsUsePLCNow,
  184. new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  185. }
  186. if (GlobalContext.IsUsePLC3)
  187. {
  188. GlobalContext.IsUsePLCNow = 3;
  189. GlobalContext.IsUseStationName = "[OP30]点散热胶装备";
  190. FunsEip.Add(GlobalContext.IsUsePLCNow,
  191. new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  192. }
  193. if (GlobalContext.IsUsePLC4)
  194. {
  195. GlobalContext.IsUsePLCNow = 4;
  196. GlobalContext.IsUseStationName = "[OP40]胶线检测";
  197. FunsEip.Add(GlobalContext.IsUsePLCNow,
  198. new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  199. }
  200. if (GlobalContext.IsUsePLC5)
  201. {
  202. GlobalContext.IsUsePLCNow = 5;
  203. GlobalContext.IsUseStationName = "[OP50]ADD板上料组装装备";
  204. FunsEip.Add(GlobalContext.IsUsePLCNow,
  205. new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  206. }
  207. if (GlobalContext.IsUsePLC6)
  208. {
  209. GlobalContext.IsUsePLCNow = 6;
  210. GlobalContext.IsUseStationName = "[OP70]组上盖板";
  211. FunsEip.Add(GlobalContext.IsUsePLCNow,
  212. new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  213. }
  214. if (GlobalContext.IsUsePLC7)
  215. {
  216. GlobalContext.IsUsePLCNow = 7;
  217. GlobalContext.IsUseStationName = "[OP80]上盖板锁螺丝";
  218. FunsEip.Add(GlobalContext.IsUsePLCNow,
  219. new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  220. }
  221. if (GlobalContext.IsUsePLC8)
  222. {
  223. GlobalContext.IsUsePLCNow = 8;
  224. GlobalContext.IsUseStationName = "[OP90]NG下料";
  225. FunsEip.Add(GlobalContext.IsUsePLCNow,
  226. new Inovance_EIP(GlobalContext.PC8Address,
  227. GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  228. }
  229. if (GlobalContext.IsUsePLC9)
  230. {
  231. GlobalContext.IsUsePLCNow = 9;
  232. GlobalContext.IsUseStationName = "[OP100]半成品下料";
  233. FunsEip.Add(GlobalContext.IsUsePLCNow,
  234. new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  235. }
  236. (bool, string) DicResult = InitalDicAlarm(); // 实例化报警字典
  237. AddMessage(LogType.Info, DicResult.Item2);
  238. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  239. {
  240. if (plcEIP != null)
  241. {
  242. try
  243. {
  244. (int, string) result = plcEIP.Connect();
  245. }
  246. catch (Exception ex)
  247. {
  248. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  249. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
  250. MessageBoxOptions.ServiceNotification);
  251. }
  252. }
  253. }
  254. // 采集任务
  255. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  256. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  257. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  258. if (GlobalContext.IsUsePLC1)
  259. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  260. if (GlobalContext.IsUsePLC2)
  261. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  262. if (GlobalContext.IsUsePLC3)
  263. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  264. if (GlobalContext.IsUsePLC4)
  265. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  266. if (GlobalContext.IsUsePLC5)
  267. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  268. if (GlobalContext.IsUsePLC6)
  269. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  270. if (GlobalContext.IsUsePLC7)
  271. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  272. if (GlobalContext.IsUsePLC8)
  273. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  274. if (GlobalContext.IsUsePLC9)
  275. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  276. #region 初始化
  277. try
  278. {
  279. // 开启MES(Http)
  280. if (GlobalContext.IsUseMES)
  281. {
  282. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  283. if (mesret)
  284. {
  285. picMESStatus.Image = imageListState.Images[1];
  286. GlobalContext.MESIsConnect = true;
  287. AddMessage(LogType.Info, "小米MES初始连接成功!");
  288. }
  289. else
  290. {
  291. picMESStatus.Image = imageListState.Images[0];
  292. GlobalContext.MESIsConnect = false;
  293. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  294. }
  295. }
  296. // 开启IOT(MQTT)
  297. if (GlobalContext.IsUseIot)
  298. {
  299. string addr = GlobalContext.MQTTServerHost;
  300. int port = GlobalContext.MQTTServerPort;
  301. //生产环境需要修改
  302. (int, string) qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666,
  303. GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  304. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult.Item1;
  305. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  306. {
  307. picIot.Image = imageListState.Images[1];
  308. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  309. // 设置回调函数
  310. //XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  311. // 配置参数
  312. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  313. // fds
  314. param.parameter.fds.address = GlobalContext.address;
  315. param.parameter.fds.appId = GlobalContext.appId;
  316. param.parameter.fds.appKey = GlobalContext.appKey;
  317. // mes
  318. param.parameter.mes.address = GlobalContext.ServerIp;
  319. param.parameter.mes.appId = GlobalContext.MESAppId;
  320. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  321. // mqtt
  322. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  323. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  324. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  325. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  326. // 设备配置
  327. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  328. if (GlobalContext.IsUsePLC1)
  329. {
  330. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  331. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  332. xiaomiParm.workstation = GlobalContext.S1_work_station; //工站
  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. xiaomiParm.workstation = GlobalContext.S2_work_station; //工站
  339. }
  340. if (GlobalContext.IsUsePLC3)
  341. {
  342. param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
  343. //param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
  344. }
  345. if (GlobalContext.IsUsePLC4)
  346. {
  347. param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
  348. param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
  349. xiaomiParm.workstation = GlobalContext.s4_work_station; //工站
  350. }
  351. if (GlobalContext.IsUsePLC5)
  352. {
  353. param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
  354. param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
  355. xiaomiParm.workstation = GlobalContext.s5_work_station; //工站
  356. }
  357. if (GlobalContext.IsUsePLC6)
  358. {
  359. param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
  360. param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
  361. xiaomiParm.workstation = GlobalContext.s6_work_station; //工站
  362. }
  363. if (GlobalContext.IsUsePLC7)
  364. {
  365. param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  366. //param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  367. xiaomiParm.stationCode = GlobalContext.s7_1_station;
  368. }
  369. if (GlobalContext.IsUsePLC8)
  370. {
  371. param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
  372. param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
  373. xiaomiParm.workstation = GlobalContext.s8_work_station; //工站
  374. }
  375. if (GlobalContext.IsUsePLC9)
  376. {
  377. param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
  378. param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
  379. xiaomiParm.workstation = GlobalContext.s9_work_station; //工站
  380. }
  381. param.parameter.equipment.project = GlobalContext.Project_Code;
  382. param.parameter.equipment.productMode = "debug";
  383. param.parameter.other.logLevel = 0;
  384. param.parameter.other.LogPath = GlobalContext.MqttLogDir;
  385. XiaomiMqttClient_Extend.ParameterConfig(param);
  386. //保存全局变量
  387. xiaomiParm.stationCode = param.parameter.equipment.stationCode;
  388. xiaomiParm.deviceCode = param.parameter.equipment.deviceCode;
  389. }
  390. else
  391. {
  392. picIot.Image = imageListState.Images[0];
  393. AddMessage(LogType.Info,
  394. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  395. }
  396. }
  397. // 开启AGV(Http与MQTT)
  398. if (GlobalContext.IsUseAGV)
  399. {
  400. // AGV HTTP
  401. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  402. if (mesret1)
  403. {
  404. picAgvHttp.Image = imageListState.Images[1];
  405. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  406. }
  407. else
  408. {
  409. picAgvHttp.Image = imageListState.Images[0];
  410. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  411. }
  412. string agvMqttIp = GlobalContext.MQTTServerHost;
  413. int agvMqttPort = GlobalContext.MQTTServerPort;
  414. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  415. ResultData_MQTT result_MQTT = _MQTTHelper
  416. .CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  417. // AGV MQTT
  418. if (result_MQTT.ResultCode == 1)
  419. {
  420. picAgvMqtt.Image = imageListState.Images[1];
  421. GlobalContext.AGVMQTTIsConnect = true;
  422. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  423. ResultData_MQTT result =
  424. XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  425. AddMessage(LogType.Info,
  426. $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  427. }
  428. else
  429. {
  430. picAgvMqtt.Image = imageListState.Images[0];
  431. GlobalContext.AGVMQTTIsConnect = false;
  432. AddMessage(LogType.Info,
  433. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  434. }
  435. }
  436. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  437. Task.Run(MonitorMESConnect);
  438. // 查询PLC连接状态
  439. foreach (int plcNo in FunsEip.Keys)
  440. {
  441. bool connected = FunsEip[plcNo].IsConnected;
  442. if (connected)
  443. {
  444. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  445. AddMessage(LogType.Info, msg);
  446. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  447. }
  448. else
  449. {
  450. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  451. AddMessage(LogType.Info, msg);
  452. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  453. }
  454. }
  455. // PLC4时 初始化扫码器TCP
  456. //if (GlobalContext.IsUsePLC4)
  457. // HpTCPClientInit();
  458. // 开启PLC的业务处理线程-监听PLC点位+状态
  459. foreach (Task task in TaskReadProcess)
  460. {
  461. if (task != null)
  462. task.Start();
  463. }
  464. //// 开启iot的线程
  465. TaskReadAlarm.Start();
  466. ////下传MES信息给1工位(先判断下plc对象数量)
  467. //if (Funs.Count > 1)
  468. // DownLoadProductInfo(1);
  469. if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  470. {
  471. //state_l.Text = "设备状态(左):";
  472. //state_r.Text = "设备状态(右):";
  473. //state_r.Visible = true;
  474. //lblDeviceStates2.Visible = true;
  475. }
  476. //上传操作记录
  477. operateToIot("startup", "开启");
  478. AddMessage(LogType.Info, "程序初始化完成");
  479. }
  480. catch (Exception ex)
  481. {
  482. string str = ex.StackTrace;
  483. this.BeginInvoke(new Action(() =>
  484. {
  485. AddMessage(LogType.Error,
  486. "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  487. str.Length - str.LastIndexOf("\\") - 1));
  488. }));
  489. }
  490. #endregion
  491. }
  492. catch (Exception ex)
  493. {
  494. string str = ex.StackTrace;
  495. OnMessage(LogType.Info,
  496. "主窗体的首页初始化出错!异常位置:" +
  497. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" +
  498. ex.Message.ToString());
  499. if (ex.Message != null && ex.Message.Contains("timed out"))
  500. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  501. else
  502. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  503. }
  504. }
  505. /// <summary>
  506. /// 窗体关闭事件
  507. /// </summary>
  508. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  509. {
  510. Closed2();
  511. }
  512. public void Closed2()
  513. {
  514. try
  515. {
  516. IsRun = false;
  517. Thread.Sleep(IntervalReadPLC);
  518. // 断开TCP
  519. int count = _HPSocket_TcpClients.Count();
  520. for (int i = 0; i < count; i++)
  521. {
  522. try
  523. {
  524. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  525. {
  526. _HPSocket_TcpClients[i].Stop();
  527. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  528. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  529. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  530. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  531. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  532. }
  533. }
  534. catch
  535. {
  536. }
  537. }
  538. // 关闭Iot
  539. try
  540. {
  541. XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath,
  542. GlobalContext.MqttServerName);
  543. }
  544. catch
  545. {
  546. }
  547. // 关闭AGV Mqtt
  548. try
  549. {
  550. _MQTTHelper.DisconnectAsync_Client().Wait();
  551. }
  552. catch
  553. {
  554. }
  555. }
  556. catch
  557. {
  558. }
  559. }
  560. #endregion 窗体基础事件
  561. #region 监控MES状态
  562. /// <summary>
  563. /// 监控MES连接状态
  564. /// </summary>
  565. private void MonitorMESConnect()
  566. {
  567. while (IsRun) // 运行被控线程
  568. {
  569. try
  570. {
  571. // 开启MES(Http)
  572. if (GlobalContext.IsUseMES)
  573. {
  574. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  575. if (mesret)
  576. {
  577. picMESStatus.Image = imageListState.Images[1];
  578. GlobalContext.MESIsConnect = true;
  579. }
  580. else
  581. {
  582. picMESStatus.Image = imageListState.Images[0];
  583. GlobalContext.MESIsConnect = false;
  584. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  585. }
  586. }
  587. // 开启IOT(MQTT)
  588. if (GlobalContext.IsUseIot)
  589. {
  590. bool iIot = XiaomiMqttClient.IsOpen;
  591. if (iIot)
  592. picIot.Image = imageListState.Images[1];
  593. else
  594. {
  595. picIot.Image = imageListState.Images[0];
  596. OnMessage(LogType.Info,
  597. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  598. }
  599. }
  600. // 开启AGV(Http与MQTT)
  601. if (GlobalContext.IsUseAGV)
  602. {
  603. // AGV Http
  604. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  605. if (mesret1)
  606. picAgvHttp.Image = imageListState.Images[1];
  607. else
  608. {
  609. picAgvHttp.Image = imageListState.Images[0];
  610. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  611. }
  612. // AGV MQTT
  613. if (GlobalContext.AGVMQTTIsConnect)
  614. picAgvMqtt.Image = imageListState.Images[1];
  615. else
  616. {
  617. picAgvMqtt.Image = imageListState.Images[0];
  618. OnMessage(LogType.Info,
  619. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  620. }
  621. }
  622. }
  623. catch (Exception ex)
  624. {
  625. string str = ex.StackTrace;
  626. AddMessage(LogType.Error,
  627. "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  628. str.Length - str.LastIndexOf("\\") - 1));
  629. }
  630. Thread.Sleep(IntervalMonitorMES);
  631. }
  632. }
  633. #endregion 监控MES连接状态
  634. #region 采集设备状态、运行数据、报警数据
  635. /// <summary>
  636. /// 请求设备状态 5000
  637. /// </summary>
  638. /// <param name="no">1</param>
  639. /// <param name="stationNameStr"></param>
  640. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  641. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  642. {
  643. try
  644. {
  645. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  646. {
  647. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  648. return result;
  649. }
  650. else
  651. {
  652. return 0;
  653. }
  654. }
  655. catch (Exception ex)
  656. {
  657. string str = ex.StackTrace;
  658. AddMessage_Station(stationNameStr, LogType.Error,
  659. "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  660. str.Length - str.LastIndexOf("\\") - 1));
  661. return 0;
  662. }
  663. }
  664. /// <summary>
  665. /// 检查是否可采集点检数据 - 不取新值
  666. /// 5000不为1时可点检
  667. /// </summary>
  668. /// <returns></returns>
  669. public bool CheckCanSpotcheck1(int deviceState)
  670. {
  671. //return true;
  672. //D5000 = 1,代表设备控制状态处于运行状态
  673. //D5000 = 2, 代表设备控制状态处于故障状态
  674. //D5000 = 3,代表设备控制状态处于缺料状态
  675. //D5000 = 4, 代表设备控制状态处于待机状态
  676. //D5000 = 5,代表设备控制状态处于维修状态
  677. return deviceState != 1;
  678. }
  679. /// <summary>
  680. /// 检查是否可采集产品数据 - 不取新值
  681. /// </summary>
  682. /// <returns></returns>
  683. public bool CheckCanCollData(int deviceState)
  684. {
  685. return deviceState == 0; // 点检时该值不为0
  686. }
  687. /// <summary>
  688. /// 采集到的设备状态
  689. /// </summary>
  690. private string _DeviceStates = "未知状态";
  691. private string _DeviceStates_Old = "未知状态";
  692. private string _DeviceStates2 = "未知状态";
  693. private string _DeviceStates_Old2 = "未知状态";
  694. private static string AlarmStateCode=""; //记录出发故障时的其中一笔警报,上传设备状态用
  695. private static string AlarmStateName = ""; //记录出发故障时的其中一笔警报,上传设备状态用
  696. /// <summary>
  697. /// 获取设备报警数据与获取设备运行信息
  698. /// </summary>
  699. private async void ReadAlarmAllPLC()
  700. {
  701. /// 获取设备报警数据与状态信息
  702. string stationNameStr = "获取设备报警数据与状态信息";
  703. // 已连接到PLC
  704. while (IsRun)
  705. {
  706. try
  707. {
  708. #region 报警数据
  709. try
  710. {
  711. //_FaultDatas = new uint[] { 4, 0, 30, 10 };
  712. if (_FaultDatas.Length > 0)
  713. {
  714. ReadPLCAlarmToIot(_FaultDatas, _FaultDatas_Old, stationNameStr,"left");
  715. }
  716. else
  717. {
  718. AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!");
  719. }
  720. if (_FaultDatas2.Length > 0)
  721. {
  722. ReadPLCAlarmToIot(_FaultDatas2, _FaultDatas_Old2, stationNameStr,"right");
  723. }
  724. else
  725. {
  726. AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!");
  727. }
  728. }
  729. catch (Exception ex)
  730. {
  731. string str = ex.StackTrace;
  732. AddMessage_Station(stationNameStr, LogType.Error,
  733. $"【报警日志】{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" +
  734. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  735. }
  736. #endregion 报警数据
  737. #region 设备状态
  738. //if (!GlobalContext._IsCon_plc1Alarm)
  739. //{
  740. // UpdatePLCMonitor(1, -2, 0);
  741. // continue;
  742. //}
  743. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  744. {
  745. if (plcEIP != null)
  746. {
  747. if (plcEIP.IsConnected)
  748. {
  749. #region 主页展示设备运行状态并上传到IOT中,有双工位left就是左工位,没有双工位left就是单工位
  750. switch (xmDeviceStateData.left)
  751. {
  752. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  753. _DeviceStates = "未初始化状态";
  754. lblDeviceStates.Text = _DeviceStates;
  755. break;
  756. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  757. _DeviceStates = "初始化状态";
  758. lblDeviceStates.Text = _DeviceStates;
  759. break;
  760. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  761. _DeviceStates = "初始化完成状态";
  762. lblDeviceStates.Text = _DeviceStates;
  763. break;
  764. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  765. _DeviceStates = "运行状态";
  766. lblDeviceStates.Text = _DeviceStates;
  767. break;
  768. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  769. _DeviceStates = "暂停状态";
  770. lblDeviceStates.Text = _DeviceStates;
  771. break;
  772. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  773. _DeviceStates = "故障状态";
  774. lblDeviceStates.Text = _DeviceStates;
  775. break;
  776. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  777. _DeviceStates = "警报状态";
  778. lblDeviceStates.Text = _DeviceStates;
  779. break;
  780. }
  781. if (!_DeviceStates.Equals(_DeviceStates_Old))
  782. {
  783. var iotResult =
  784. SaveDeviceStateData(stationNameStr, xmDeviceStateData.left, "left"); // 上传+保存
  785. if (iotResult.Item1 == 1)
  786. {
  787. _DeviceStates_Old = _DeviceStates;
  788. AddMessage_Station(stationNameStr, LogType.Info,
  789. "【设备状态】" + stationNameStr + $"_上传设备状态到Iot成功!");
  790. }
  791. else
  792. AddMessage_Station(stationNameStr, LogType.Info,
  793. "【设备状态】" + stationNameStr +
  794. $"_上传设备状态到Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  795. }
  796. #endregion 主页展示设备运行状态并上传到IOT中
  797. #region 右工位
  798. //if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  799. //{
  800. // switch (xmDeviceStateData.right)
  801. // {
  802. // case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  803. // _DeviceStates2 = "未初始化状态";
  804. // lblDeviceStates2.Text = _DeviceStates2;
  805. // break;
  806. // case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  807. // _DeviceStates2 = "初始化状态";
  808. // lblDeviceStates2.Text = _DeviceStates2;
  809. // break;
  810. // case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  811. // _DeviceStates2 = "初始化完成状态";
  812. // lblDeviceStates2.Text = _DeviceStates2;
  813. // break;
  814. // case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  815. // _DeviceStates2 = "运行状态";
  816. // lblDeviceStates2.Text = _DeviceStates2;
  817. // break;
  818. // case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  819. // _DeviceStates2 = "暂停状态";
  820. // lblDeviceStates2.Text = _DeviceStates2;
  821. // break;
  822. // case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  823. // _DeviceStates2 = "故障状态";
  824. // lblDeviceStates2.Text = _DeviceStates2;
  825. // break;
  826. // case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  827. // _DeviceStates2 = "警报状态";
  828. // lblDeviceStates2.Text = _DeviceStates2;
  829. // break;
  830. // }
  831. // if (!_DeviceStates2.Equals(_DeviceStates_Old2))
  832. // {
  833. // var iotResult = SaveDeviceStateData(stationNameStr, xmDeviceStateData.left,
  834. // "right"); // 上传+保存
  835. // if (iotResult.Item1 == 1)
  836. // {
  837. // _DeviceStates_Old2 = _DeviceStates2;
  838. // AddMessage_Station(stationNameStr, LogType.Info,
  839. // "【设备状态】" + stationNameStr + $"_上传Iot成功!");
  840. // }
  841. // else
  842. // AddMessage_Station(stationNameStr, LogType.Info,
  843. // "【设备状态】" + stationNameStr +
  844. // $"_上传Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  845. // }
  846. //}
  847. #endregion 右工位
  848. }
  849. }
  850. }
  851. #endregion
  852. }
  853. catch (Exception ex)
  854. {
  855. //AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  856. AddMessage_Station(stationNameStr, LogType.Error,
  857. $"PLC1_{stationNameStr}_采集运行数据与报警数据出错!错误信息:" + ex.Message.ToString());
  858. }
  859. Thread.Sleep(IntervalAlarm);
  860. }
  861. }
  862. #endregion 轮询PLC
  863. #region 下发订单信息
  864. ///// <summary>
  865. ///// 壳体上料(下发工单)的交互逻辑
  866. ///// </summary>
  867. ///// <param name="no"></param>
  868. ///// <exception cref="NotImplementedException"></exception>
  869. //private void ReadStation_DownOrderInfo(int plcNo)
  870. //{
  871. // // [S1] Tray盘上料装备(板测)
  872. // // [S2] FCT(板测)
  873. // // [S3] 值板机
  874. // // [S4] 取放桁架
  875. // // [S5] Tray盘下料装备
  876. // /// 上位机心跳
  877. // /// 获取设备报警数据与状态信息
  878. // string stationNameStr = "[S0]壳体上料";
  879. // while (IsRun)
  880. // {
  881. // try
  882. // {
  883. // if (!GlobalContext._IsCon_Funs1)
  884. // {
  885. // UpdatePLCMonitor(plcNo, 0);
  886. // continue;
  887. // }
  888. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  889. // {
  890. // #region 壳体上料(下发工单)
  891. // try
  892. // {
  893. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  894. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  895. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  896. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  897. // // 重置数据和信号
  898. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  899. // {
  900. // // 清空写给PLC的数据
  901. // int[] i497 = new int[1] { 0 };
  902. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  903. // // MES_Flag重置为0
  904. // int[] i500 = new int[1] { 0 };
  905. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  906. // }
  907. // }
  908. // catch (Exception ex)
  909. // {
  910. // string str = ex.StackTrace;
  911. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  912. // }
  913. // #endregion 壳体上料(下发工单)
  914. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  915. // }
  916. // else
  917. // {
  918. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  919. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  920. //
  921. // Funs[plcNo].Connect();
  922. // }
  923. // }
  924. // catch (Exception ex)
  925. // {
  926. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  927. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  928. //
  929. // Funs[plcNo].ReConnect();
  930. // }
  931. // Thread.Sleep(IntervalReadPLC);
  932. // }
  933. //}
  934. ///// <summary>
  935. ///// 下发订单信息到PLC
  936. ///// </summary>
  937. ///// <param name="no">PLC编号</param>
  938. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  939. //{
  940. // try
  941. // {
  942. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  943. // {
  944. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  945. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  946. // }
  947. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  948. // }
  949. // catch (Exception ex)
  950. // {
  951. // string str = ex.StackTrace;
  952. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  953. // }
  954. //}
  955. /// <summary>
  956. /// 下发清料信号
  957. /// </summary>
  958. /// <param name="no">PLC编号</param>
  959. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  960. {
  961. try
  962. {
  963. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  964. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  965. return true;
  966. }
  967. catch (Exception ex)
  968. {
  969. string str = ex.StackTrace;
  970. AddMessage_Station(stationNameStr, LogType.Error,
  971. "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  972. str.Length - str.LastIndexOf("\\") - 1));
  973. return false;
  974. }
  975. }
  976. #endregion 下发订单信息
  977. #region Xiaomi 贲流
  978. #region 公共方法
  979. private static bool ProgressState = false;
  980. private static readonly object lockObj = new object(); // 锁对象
  981. private static bool isCollectingFlagLeft;
  982. private static bool isCollectingFlagRight;
  983. private bool OpenDailogFalg = true; //是否开启扫码弹窗标识
  984. private static int res = 0;
  985. public static bool StopWhile =false;
  986. public void ConnectToIOT()
  987. {
  988. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  989. // fds
  990. param.parameter.fds.address = GlobalContext.address;
  991. param.parameter.fds.appId = GlobalContext.appId;
  992. param.parameter.fds.appKey = GlobalContext.appKey;
  993. // mes
  994. param.parameter.mes.address = GlobalContext.ServerIp;
  995. param.parameter.mes.appId = GlobalContext.MESAppId;
  996. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  997. // mqtt
  998. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  999. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  1000. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  1001. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  1002. // 设备配置
  1003. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  1004. if (GlobalContext.IsUsePLC1)
  1005. {
  1006. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  1007. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  1008. xiaomiParm.workstation = GlobalContext.S1_work_station; //工站
  1009. }
  1010. if (GlobalContext.IsUsePLC2)
  1011. {
  1012. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  1013. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  1014. xiaomiParm.workstation = GlobalContext.S2_work_station; //工站
  1015. }
  1016. if (GlobalContext.IsUsePLC3)
  1017. {
  1018. param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
  1019. //param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
  1020. }
  1021. if (GlobalContext.IsUsePLC4)
  1022. {
  1023. param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
  1024. param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
  1025. xiaomiParm.workstation = GlobalContext.s4_work_station; //工站
  1026. }
  1027. if (GlobalContext.IsUsePLC5)
  1028. {
  1029. param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
  1030. param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
  1031. xiaomiParm.workstation = GlobalContext.s5_work_station; //工站
  1032. }
  1033. if (GlobalContext.IsUsePLC6)
  1034. {
  1035. param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
  1036. param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
  1037. xiaomiParm.workstation = GlobalContext.s6_work_station; //工站
  1038. }
  1039. if (GlobalContext.IsUsePLC7)
  1040. {
  1041. param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  1042. //param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  1043. xiaomiParm.stationCode = GlobalContext.s7_1_station;
  1044. }
  1045. if (GlobalContext.IsUsePLC8)
  1046. {
  1047. param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
  1048. param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
  1049. xiaomiParm.workstation = GlobalContext.s8_work_station; //工站
  1050. }
  1051. if (GlobalContext.IsUsePLC9)
  1052. {
  1053. param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
  1054. param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
  1055. xiaomiParm.workstation = GlobalContext.s9_work_station; //工站
  1056. }
  1057. param.parameter.equipment.project = GlobalContext.Project_Code;
  1058. param.parameter.equipment.productMode = "debug";
  1059. param.parameter.other.logLevel = 0;
  1060. param.parameter.other.LogPath = GlobalContext.MqttLogDir;
  1061. XiaomiMqttClient_Extend.ParameterConfig(param);
  1062. }
  1063. /// <summary>
  1064. /// float[]转为string
  1065. /// </summary>
  1066. public string FloatArrayToString(float[] nScrewResults)
  1067. {
  1068. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  1069. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  1070. }
  1071. /// <summary>
  1072. /// short[]转为string
  1073. /// </summary>
  1074. public string ShortArrayToString(short[] nScrewResults)
  1075. {
  1076. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  1077. return string.Join(",", nScrewResults);
  1078. }
  1079. /// <summary>
  1080. /// 写入PLC重复三次
  1081. /// </summary>
  1082. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount,
  1083. T inObj)
  1084. {
  1085. int i = 0;
  1086. int nRet = 0;
  1087. string strRet = "";
  1088. try
  1089. {
  1090. while (i < 3) // 最多上传三次
  1091. {
  1092. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  1093. if (nRet == 0) //成功
  1094. {
  1095. break;
  1096. }
  1097. else
  1098. {
  1099. AddMessage_Station(stationNameStr, LogType.Error,
  1100. $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1101. i++;
  1102. }
  1103. }
  1104. return (nRet, strRet);
  1105. }
  1106. catch (Exception ex)
  1107. {
  1108. return (1, ex.Message);
  1109. }
  1110. }
  1111. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes,
  1112. short[] nScrewOrders, short[] nScrewResults)
  1113. {
  1114. try
  1115. {
  1116. // 获取当前日期
  1117. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1118. // 构建保存路径
  1119. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  1120. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction, "螺丝Mes数据");
  1121. // 确保目录存在
  1122. Directory.CreateDirectory(savePath);
  1123. // 文件名
  1124. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  1125. string filePath = Path.Combine(savePath, fileName);
  1126. // 确保不会超出数组长度,只取前14个或数组的实际长度
  1127. int count = Math.Min(14, fScrewTimes.Length);
  1128. using (StreamWriter sw = new StreamWriter(filePath))
  1129. {
  1130. for (int i = 0; i < count; i++)
  1131. {
  1132. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  1133. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  1134. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  1135. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  1136. sw.WriteLine(); // 空行分隔不同螺丝的信息
  1137. }
  1138. }
  1139. return (0, "");
  1140. }
  1141. catch (Exception ex)
  1142. {
  1143. return (1, ex.Message);
  1144. }
  1145. }
  1146. public Dictionary<string, string> GetLastLineCompensation(string path, string direction, string sn)
  1147. {
  1148. // 创建字典存储补偿点及其对应的值
  1149. Dictionary<string, string> compensationDict = new Dictionary<string, string>();
  1150. try
  1151. {
  1152. //string path = GlobalContext.MESLaserRPath;
  1153. // 获取当前日期并格式化为 "yyyy-MM-dd" 格式
  1154. string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
  1155. string filename = $"Laser-{currentDate}-W0.txt";
  1156. // 拼接完整路径
  1157. string fullPath = Path.Combine(path, filename);
  1158. string lastNonEmptyLine = "";
  1159. // 判断文件是否存在
  1160. if (File.Exists(fullPath))
  1161. {
  1162. //读取文件内容
  1163. string[] lines = File.ReadAllLines(fullPath);
  1164. // 获取最后一行数据(忽略标题行)
  1165. if (lines.Length > 1)
  1166. {
  1167. string lastLine = "";
  1168. for (int i = lines.Length - 1; i > 0; i--)
  1169. {
  1170. if (!string.IsNullOrEmpty(lines[i]))
  1171. {
  1172. lastLine = lines[i];
  1173. break;
  1174. }
  1175. }
  1176. // 将最后一行按逗号分隔
  1177. string[] values = lastLine.Split(',');
  1178. values[1] = sn;
  1179. string key = "三点激光_" + direction; // 构造键名
  1180. string value = string.Join(",", values); // 获取值并去除多余空格
  1181. compensationDict[key] = value;
  1182. //// 提取“1点补偿”到“6点补偿”的值
  1183. //for (int i = 2; i <= 7 && i < values.Length; i++) // 从索引2开始,最多提取6个值
  1184. //{
  1185. // string key = $"{i - 1}点补偿"; // 构造键名
  1186. // string value = values[i].Trim(); // 获取值并去除多余空格
  1187. // compensationDict[key] = value;
  1188. //}
  1189. }
  1190. }
  1191. else
  1192. {
  1193. Console.WriteLine($"文件不存在: {fullPath}");
  1194. }
  1195. }
  1196. catch (Exception ex)
  1197. {
  1198. // 捕获异常并输出错误信息
  1199. Console.WriteLine($"发生错误: {ex.Message}");
  1200. }
  1201. return compensationDict;
  1202. }
  1203. public int PCBStationOutData(BarcodeSet_t Barcode, IoT_DataSet_t iotData)
  1204. {
  1205. int res = 0;
  1206. string jsonstr1 = "";
  1207. try
  1208. {
  1209. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1210. outRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备id(可配置)
  1211. outRequest_Body.stationId = GlobalContext.s5_station; // ⼯位ID(可配置)
  1212. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1213. outRequest_Body.clientTime =
  1214. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1215. outRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
  1216. int a1Result = (int)iotData.testStatus;
  1217. //bool pass = a1Result == 1;
  1218. //outRequest_Body.state = pass ? "PASS" : "FAIL"; ; // 出站条件 PASS或FAIL
  1219. outRequest_Body.state = "PASS";
  1220. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1221. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1222. XmStationOut_KeyMaterial keyMaterial = new XmStationOut_KeyMaterial();
  1223. keyMaterial.bindSort = 1;
  1224. keyMaterial.materialSn = Barcode.strProductBarcode;
  1225. outRequest_Body.unitData.keyMaterial.Add(keyMaterial); // 产品码
  1226. jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1227. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1228. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1229. if (response != null && response.header.code == "200")
  1230. {
  1231. res = 1;
  1232. AddMessage(LogType.Info,
  1233. "上传PCB出站数据到MES服务器---成功!请求信息:" + jsonstr1 + ",返回信息:" +
  1234. JsonConvert.SerializeObject(response.body));
  1235. }
  1236. else
  1237. {
  1238. res = 0;
  1239. AddMessage(LogType.Error,
  1240. "上传PCB出站数据到MES服务器---失败!错误信息:" + response.header.desc + ",请求信息:" + jsonstr1 + ",返回信息:" +
  1241. JsonConvert.SerializeObject(response.body));
  1242. }
  1243. }
  1244. catch (Exception e)
  1245. {
  1246. res = 0;
  1247. AddMessage(LogType.Info, "上传PCB出站数据到MES服务器---失败!请求信息:" + jsonstr1 + ",返回信息:" + e.Message);
  1248. }
  1249. return res;
  1250. }
  1251. public int PCBStationInData(BarcodeSet_t Barcode, IoT_DataSet_t iotData)
  1252. {
  1253. int res = 0;
  1254. string json_Body = "";
  1255. try
  1256. {
  1257. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1258. inRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  1259. inRequest_Body.stationId = GlobalContext.s5_station; // ⼯位ID(可配置)
  1260. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1261. inRequest_Body.clientTime =
  1262. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1263. inRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
  1264. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1265. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1266. json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1267. var response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1268. string resultJson = JsonConvert.SerializeObject(response);
  1269. if (response != null && response.header.code == "200")
  1270. {
  1271. res = 1;
  1272. AddMessage(LogType.Info,
  1273. "上传PCB进站数据到MES服务器---成功!请求信息:" + json_Body + ",返回信息:" +
  1274. JsonConvert.SerializeObject(response.body));
  1275. }
  1276. else
  1277. {
  1278. res = 0;
  1279. AddMessage(LogType.Error,
  1280. "上传PCB进站数据到MES服务器---失败!错误信息:" + response.header.desc + ",请求信息:" + json_Body + ",返回信息:" +
  1281. JsonConvert.SerializeObject(response.body));
  1282. }
  1283. }
  1284. catch (Exception e)
  1285. {
  1286. res = 0;
  1287. AddMessage(LogType.Info, "上传PCB进站数据到MES服务器---失败!请求信息:" + json_Body + ",返回信息:" + e.Message);
  1288. }
  1289. return res;
  1290. }
  1291. /// <summary>
  1292. /// 调用进站接口并保存进站数据
  1293. /// </summary>
  1294. /// <param name="stationNameStr">工站信息</param>
  1295. /// <param name="workorder_code">工单号</param>
  1296. /// <param name="mtltmrk">型号(物料号)</param>
  1297. /// <param name="sn">产品SN</param>
  1298. /// <param name="items">进站数据</param>
  1299. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1300. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn,
  1301. List<TestItem> items, string MachineId, string StationId, bool pass, string slot)
  1302. {
  1303. int result = 0;
  1304. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1305. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1306. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1307. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1308. inRequest_Body.clientTime =
  1309. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1310. inRequest_Body.unitSn = sn; // 产品SN
  1311. inRequest_Body.uuidInspection = uuid;
  1312. inRequest_Body.state = pass ? "PASS" : "FAIL";
  1313. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1314. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1315. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1316. StationIn stationIn = new StationIn()
  1317. {
  1318. Workorder_code = workorder_code, // 车间订单号
  1319. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1320. Sn = sn, // SN
  1321. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1322. Parameter_values = items, // 进站数据
  1323. Write_user = inRequest_Body.userId, // 员工Id
  1324. Test_time = inRequest_Body.clientTime // 进站时间
  1325. };
  1326. // 本地数据
  1327. string sql = stationIn.ToStringInsert(0);
  1328. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1329. result = ret == "成功" ? 1 : 6;
  1330. #region MES
  1331. if (GlobalContext.IsSendStationIn)
  1332. {
  1333. try
  1334. {
  1335. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1336. string resultJson = "";
  1337. string mesRet = string.Empty;
  1338. int i = 0;
  1339. while (i < 2) // 1009会多次尝试上传
  1340. {
  1341. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1342. resultJson = JsonConvert.SerializeObject(response);
  1343. if (response != null && response.header.code == "200")
  1344. break;
  1345. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1346. i++;
  1347. i++;
  1348. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1349. // 记录失败原因
  1350. OnMessage(LogType.Error, $"上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:{mesRet},请求参数:{json_Body}");
  1351. }
  1352. if (response?.header?.code == "200")
  1353. {
  1354. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1355. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1356. result = ret_Upd == "成功" ? 1 : 6;
  1357. AddMessage(LogType.Info,
  1358. $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功,返回参数:{resultJson},请求参数:{json_Body}");
  1359. }
  1360. else
  1361. {
  1362. result = 5;
  1363. AddMessage(LogType.Info,
  1364. $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息: {mesRet},请求参数:{json_Body}");
  1365. }
  1366. string sql_response =
  1367. stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1368. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1369. }
  1370. catch (Exception ex)
  1371. {
  1372. result = 6;
  1373. string str = ex.StackTrace;
  1374. AddMessage_Station(stationNameStr, LogType.Error,
  1375. $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1376. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1377. }
  1378. }
  1379. #endregion
  1380. #region IOT
  1381. //过站结果
  1382. if (GlobalContext.IsMqttSendProcessData)
  1383. {
  1384. PassStationResultRequest request = new PassStationResultRequest();
  1385. request.project_code = GlobalContext.Project_Code; // 项⽬编码
  1386. request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
  1387. request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
  1388. request.line_code = GlobalContext.LineCode; // 线体编码
  1389. request.work_station = xiaomiParm.workstation; // ⼯站ID
  1390. request.device_code = xiaomiParm.deviceCode; // 装备编码
  1391. request.station = xiaomiParm.stationCode;
  1392. request.process_time =
  1393. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
  1394. request.slot = slot; // 槽位编码
  1395. request.sn = sn; // 产品SN
  1396. // request.enter_status = inpass ? "PASS" : "FAIL"; // 进站状态
  1397. request.enter_status = pass ? "PASS" : "FAIL"; // 进站状态
  1398. request.result = ""; // 出站条件 PASS或FAIL; // 过站结果
  1399. request.work_type = "OUT_STATION"; // 作业类型
  1400. // 上传过站结果
  1401. (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
  1402. if (iotResult.Item1 != 0)
  1403. {
  1404. OnMessage(LogType.Info,
  1405. $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}] 进站结果[{request.enter_status}] 出站结果[{request.result}]");
  1406. }
  1407. }
  1408. #endregion
  1409. return result;
  1410. }
  1411. /// <summary>
  1412. /// 选择如何记录出站数据
  1413. /// </summary>
  1414. /// <param name="items">出站数据</param>
  1415. /// <param name="equipmentCode">设备编号</param>
  1416. /// <param name="processItem">测试项目</param>
  1417. /// <param name="workorder_code">车间订单号</param>
  1418. /// <param name="batch_num">批次号</param>
  1419. /// <param name="mtltmrk">型号</param>
  1420. /// <param name="proDate">日期</param>
  1421. /// <param name="supplierCode">供应商代码</param>
  1422. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1423. /// <returns>上传成功时返回1;失败返回0</returns>
  1424. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode,
  1425. string processItem,
  1426. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1427. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId,
  1428. string StationId, string PartBarcode, string jsonParm, string direction = "")
  1429. {
  1430. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num,
  1431. mtltmrk,
  1432. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode, jsonParm,
  1433. direction);
  1434. }
  1435. /// <summary>
  1436. /// 添加出站数据(提交到MES+本地保存到数据库)
  1437. /// </summary>
  1438. /// <param name="items">出站数据</param>
  1439. /// <param name="equipmentCode">设备编号</param>
  1440. /// <param name="processItem">测试项目</param>
  1441. /// <param name="workorder_code">车间订单号</param>
  1442. /// <param name="batch_num">批次号</param>
  1443. /// <param name="mtltmrk">型号</param>
  1444. /// <param name="proDate">日期</param>
  1445. /// <param name="supplierCode">供应商代码</param>
  1446. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1447. /// <returns>上传成功时返回1;失败返回0</returns>
  1448. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1449. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1450. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot,
  1451. string machineId, string stationId, string partBarcode, string jsonParm, string direction = "")
  1452. {
  1453. int upload = 0;
  1454. int result = 0;
  1455. ProcessData processData = new ProcessData()
  1456. {
  1457. Equipment_code = equipmentCode,
  1458. Workorder_code = workorder_code,
  1459. Batch_number = batch_num,
  1460. Sn = sn, // SN
  1461. Testitem = processItem,
  1462. Parameter_values = items,
  1463. Write_user = GlobalContext.CurrentUser,
  1464. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1465. };
  1466. // 本地数据
  1467. string sql = processData.ToStringInsert(upload);
  1468. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1469. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1470. #region MES
  1471. if (GlobalContext.IsSendProcessData)
  1472. {
  1473. try
  1474. {
  1475. string id = processData.ID.Copy();
  1476. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1477. if (direction == "Right")
  1478. outRequest_Body.uuidInspection = uuid2;
  1479. else
  1480. outRequest_Body.uuidInspection = uuid;
  1481. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1482. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1483. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1484. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1485. outRequest_Body.unitSn = sn; // 产品SN
  1486. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1487. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1488. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1489. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1490. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1491. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1492. if (!string.IsNullOrEmpty(partBarcode))
  1493. {
  1494. outRequest_Body.unitData.keyMaterial.Add(
  1495. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1496. {
  1497. bindSort = 1,
  1498. materialSn = partBarcode
  1499. }); // 设备数据 - 部件码
  1500. }
  1501. //OP30站读txt数据
  1502. if (stationNameStr.Contains("OP31") || stationNameStr.Contains("OP32"))
  1503. {
  1504. string path = "";
  1505. if (direction == "Left")
  1506. {
  1507. string pathStr = GlobalContext.MESLaserLPath;
  1508. path = DecFileName(pathStr);
  1509. }
  1510. else {
  1511. string pathStr = GlobalContext.MESLaserRPath;
  1512. path = DecFileName(pathStr);
  1513. }
  1514. //字典存储数据
  1515. Dictionary<string, string> compensationDict = GetLastLineCompensation(path, direction, sn);
  1516. foreach (var kvp in compensationDict)
  1517. {
  1518. outRequest_Body.unitData.processData.Add(
  1519. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1520. {
  1521. dataName = kvp.Key.ToString(),
  1522. dataValue = kvp.Value.ToString()
  1523. });
  1524. }
  1525. }
  1526. //过站明细
  1527. if (GlobalContext.IsSendProcessDetail)
  1528. {
  1529. if (jsonParm.Length > 0)
  1530. {
  1531. //jsonParm = "{\"fGlueSupplySpeed\":0.63,\"fAB_AirPress\":0.0,\"fAB_AirPressDiff\":0.0,\"fMesHeightInfos\":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],\"fIntervalWeights\":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],\"fRemainGlues\":[600.0,600.0]}";
  1532. // 解析JSON字符串为字典
  1533. jsonParm = jsonParm.Replace("[", "\"[");
  1534. jsonParm = jsonParm.Replace("]", "]\"");
  1535. var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonParm);
  1536. foreach (var kvp in dictionary)
  1537. {
  1538. outRequest_Body.unitData.processData.Add(
  1539. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1540. {
  1541. dataName = kvp.Key.ToString(),
  1542. dataValue = string.IsNullOrEmpty(kvp.Value) ? "" : kvp.Value.ToString()
  1543. });
  1544. }
  1545. }
  1546. }
  1547. if (GlobalContext.MESIsSendUpFile)
  1548. {
  1549. foreach (var item in fileUploadData.fileData)
  1550. {
  1551. if (!string.IsNullOrEmpty(item.FileName))
  1552. {
  1553. outRequest_Body.unitData.fileData.Add(
  1554. new XmStationOut_FileData()
  1555. {
  1556. fileName = item.FileName,
  1557. fileId = item.FileId,
  1558. bucket = item.Bucket
  1559. });
  1560. }
  1561. }
  1562. }
  1563. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1564. if (GlobalContext.IsSendProcessData)
  1565. {
  1566. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1567. string mesRet = string.Empty;
  1568. int i = 0;
  1569. while (i < 2) // 1009会多次尝试上传
  1570. {
  1571. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1572. if (response != null && response.header.code == "200")
  1573. {
  1574. OnMessage(LogType.Info,
  1575. $"【出站数据 SN {sn}】上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" +
  1576. JsonConvert.SerializeObject(response.body));
  1577. break;
  1578. }
  1579. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1580. i++;
  1581. i++;
  1582. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1583. // 记录失败原因
  1584. OnMessage(LogType.Error,
  1585. $"【出站数据 SN {sn}】上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1586. }
  1587. if (response?.header?.code == "200")
  1588. {
  1589. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1590. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1591. result = 1;
  1592. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1593. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1594. }
  1595. else
  1596. {
  1597. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1598. }
  1599. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(
  1600. JsonConvert.SerializeObject(outRequest_Body),
  1601. JsonConvert.SerializeObject(response), id);
  1602. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1603. }
  1604. }
  1605. catch (Exception ex)
  1606. {
  1607. string str = ex.StackTrace;
  1608. AddMessage_Station(stationNameStr, LogType.Error,
  1609. $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1610. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1611. }
  1612. }
  1613. #endregion
  1614. #region IOT
  1615. //过站明细
  1616. if (GlobalContext.IsMqttSendProcessData)
  1617. {
  1618. PassStationDetailRequest request = new PassStationDetailRequest();
  1619. if (direction == "Right")
  1620. request.pass_station_id = uuid2;
  1621. else
  1622. request.pass_station_id = uuid;
  1623. request.sn = sn; // 产品SN
  1624. request.slot = vehicleSlot; // 槽位编码
  1625. request.function_name = "Machine_加⼯模块";
  1626. request.status = "PASS";
  1627. (int, string) iotResult = (0, "");
  1628. if (jsonParm.Length > 0)
  1629. {
  1630. // 解析JSON字符串为字典
  1631. var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonParm);
  1632. foreach (var kvp in dictionary)
  1633. {
  1634. test_item_num += 1;
  1635. request.test_item_num = test_item_num.ToString();
  1636. request.test_item = kvp.Key.ToString();
  1637. request.result_val = string.IsNullOrEmpty(kvp.Value) ? "" : kvp.Value.ToString();
  1638. request.description = request.test_item;
  1639. // 上传过站明细
  1640. iotResult = XiaomiMqttClient_Extend.Write_PassStationDetail(request);
  1641. if (iotResult.Item1 != 0)
  1642. {
  1643. OnMessage(LogType.Info,
  1644. $"【IOT过站明细】上传失败!错误原因:{iotResult.Item2},过站明细;产品码[{sn}] 测试项目[{request.test_item}] 测试值[{request.result_val}]");
  1645. }
  1646. }
  1647. }
  1648. }
  1649. //过站结果
  1650. if (GlobalContext.IsMqttSendProcessData)
  1651. {
  1652. PassStationResultRequest request = new PassStationResultRequest();
  1653. request.project_code = GlobalContext.Project_Code; // 项⽬编码
  1654. request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
  1655. request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
  1656. request.line_code = GlobalContext.LineCode; // 线体编码
  1657. request.work_station = xiaomiParm.workstation; // ⼯站ID
  1658. request.device_code = xiaomiParm.deviceCode; // 装备编码
  1659. request.station = xiaomiParm.stationCode;
  1660. request.process_time =
  1661. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
  1662. request.slot = vehicleSlot; // 槽位编码
  1663. request.sn = sn; // 产品SN
  1664. // request.enter_status = inpass ? "PASS" : "FAIL"; // 进站状态
  1665. request.enter_status = ""; // 进站状态
  1666. request.result = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL; // 过站结果
  1667. request.work_type = "OUT_STATION"; // 作业类型
  1668. // 上传过站结果
  1669. (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
  1670. if (iotResult.Item1 != 0)
  1671. {
  1672. OnMessage(LogType.Info,
  1673. $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}] 进站结果[{request.enter_status}] 出站结果[{request.result}]");
  1674. }
  1675. }
  1676. #endregion
  1677. return result;
  1678. }
  1679. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1680. //{
  1681. // Stopwatch stopwatch = new Stopwatch();
  1682. // stopwatch.Start();
  1683. // try
  1684. // {
  1685. // // 初始化 AtlasScrew 实例
  1686. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1687. // atlasScrew1.Initial();
  1688. // // 存储结果的列表
  1689. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1690. // // 存储角度和扭力的字符串列表
  1691. // List<string> angleStrs = new List<string>();
  1692. // List<string> torqueStrs = new List<string>();
  1693. // // 上一次获取的数据
  1694. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1695. // while (isExitAtlasLeft) // 检查是否收集数据
  1696. // {
  1697. // // 获取当前数据
  1698. // var currentResult = atlasScrew1.GetResults();
  1699. // // 判断是否为新数据
  1700. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1701. // {
  1702. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1703. // // 更新角度和扭力的字符串列表
  1704. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1705. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1706. // // 计算角度、扭力、起始扭力和最大扭力
  1707. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1708. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1709. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1710. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1711. // // 将新数据添加到结果列表
  1712. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1713. // // 更新上一次获取的数据
  1714. // lastResult = currentResult;
  1715. // }
  1716. // // 等待一段时间后再次检查
  1717. // Thread.Sleep(20); // 轮询间隔时间
  1718. // // 如果触发了出站,则退出循环
  1719. // if (!isExitAtlasLeft)
  1720. // {
  1721. // break;
  1722. // }
  1723. // }
  1724. // // 生成文件名
  1725. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1726. // // 写入数据到文件
  1727. // using (StreamWriter writer = new StreamWriter(fileName))
  1728. // {
  1729. // // 写入标题行
  1730. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1731. // // 写入每一行数据
  1732. // foreach (var result in results)
  1733. // {
  1734. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1735. // }
  1736. // }
  1737. // stopwatch.Stop();
  1738. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1739. // }
  1740. // catch (Exception ex)
  1741. // {
  1742. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1743. // }
  1744. // finally
  1745. // {
  1746. // // 重置标志变量
  1747. // isExitAtlasLeft = false;
  1748. // }
  1749. //}
  1750. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1751. //{
  1752. // Stopwatch stopwatch = new Stopwatch();
  1753. // stopwatch.Start();
  1754. // try
  1755. // {
  1756. // // 初始化 AtlasScrew 实例
  1757. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1758. // atlasScrew2.Initial();
  1759. // // 存储结果的列表
  1760. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1761. // // 上一次获取的数据
  1762. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1763. // while (isExitAtlasRight) // 检查是否收集数据
  1764. // {
  1765. // // 获取当前数据
  1766. // var currentResult = atlasScrew2.GetResults();
  1767. // // 判断是否为新数据
  1768. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1769. // {
  1770. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1771. // // 将新数据写入PLC
  1772. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1773. // // 将新数据添加到结果列表
  1774. // results.Add(currentResult);
  1775. // // 更新上一次获取的数据
  1776. // lastResult = currentResult;
  1777. // }
  1778. // // 等待一段时间后再次检查
  1779. // Thread.Sleep(20); // 轮询间隔时间
  1780. // // 如果触发了出站,则退出循环
  1781. // if (!isExitAtlasRight)
  1782. // {
  1783. // break;
  1784. // }
  1785. // }
  1786. // // 将所有数据写入文件
  1787. // //WriteDataToFile(sn, direction, results);
  1788. // stopwatch.Stop();
  1789. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1790. // }
  1791. // catch (Exception ex)
  1792. // {
  1793. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1794. // }
  1795. // finally
  1796. // {
  1797. // // 重置标志变量
  1798. // isExitAtlasRight = false;
  1799. // }
  1800. //}
  1801. /// <summary>
  1802. ///字符串中文乱码解决
  1803. /// </summary>
  1804. /// <param name="str"></param>
  1805. /// <returns></returns>
  1806. public static string DecFileName(string str)
  1807. {
  1808. Encoding utf8 = Encoding.GetEncoding("gbk");
  1809. byte[] btArr = utf8.GetBytes(str);
  1810. return Encoding.UTF8.GetString(btArr);
  1811. }
  1812. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1813. {
  1814. Stopwatch stopwatch = new Stopwatch();
  1815. stopwatch.Start();
  1816. int nRet = 0;
  1817. string strRet = "";
  1818. try
  1819. {
  1820. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1821. while (isCollectingFlagLeft)
  1822. {
  1823. // 从缓存中获取所有未处理的数据
  1824. var cachedData = atlasScrew.GetCachedDataLeft();
  1825. foreach (var currentResult in cachedData)
  1826. {
  1827. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1828. {
  1829. continue; // 跳过无效数据
  1830. }
  1831. OnMessage(LogType.Info,
  1832. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1833. // 写入PLC
  1834. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1835. {
  1836. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1837. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1838. };
  1839. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1840. if (nRet != 0)
  1841. {
  1842. OnMessage(LogType.Info,
  1843. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1844. }
  1845. else
  1846. {
  1847. OnMessage(LogType.Info,
  1848. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1849. }
  1850. // 构建保存路径
  1851. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1852. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1853. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1854. Directory.CreateDirectory(savePath); // 确保目录存在
  1855. // 构建文件名(以 SN + 序号命名)
  1856. string fileName = $"{sn}_{fileCounter}.txt";
  1857. string filePath = Path.Combine(savePath, fileName);
  1858. // 写入文件
  1859. using (StreamWriter writer = new StreamWriter(filePath))
  1860. {
  1861. writer.WriteLine("精度, 扭力");
  1862. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1863. for (int i = 0;
  1864. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  1865. i++)
  1866. {
  1867. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1868. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1869. writer.WriteLine($"{precision}, {torque}");
  1870. }
  1871. }
  1872. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1873. // 增加文件计数器
  1874. fileCounter++;
  1875. }
  1876. // 如果没有更多数据,则短暂休眠以节省资源
  1877. if (!cachedData.Any())
  1878. {
  1879. Thread.Sleep(10); // 根据需要调整休眠时间
  1880. }
  1881. // 如果触发了出站,则退出循环
  1882. if (!isCollectingFlagLeft)
  1883. {
  1884. break;
  1885. }
  1886. }
  1887. stopwatch.Stop();
  1888. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1889. }
  1890. catch (Exception ex)
  1891. {
  1892. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1893. }
  1894. finally
  1895. {
  1896. isCollectingFlagLeft = false;
  1897. }
  1898. }
  1899. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1900. {
  1901. Stopwatch stopwatch = new Stopwatch();
  1902. stopwatch.Start();
  1903. int nRet = 0;
  1904. string strRet = "";
  1905. try
  1906. {
  1907. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1908. while (isCollectingFlagRight)
  1909. {
  1910. // 从缓存中获取所有未处理的数据
  1911. var cachedData = atlasScrew.GetCachedDataLeft();
  1912. foreach (var currentResult in cachedData)
  1913. {
  1914. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1915. {
  1916. continue; // 跳过无效数据
  1917. }
  1918. OnMessage(LogType.Info,
  1919. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1920. // 写入PLC
  1921. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1922. {
  1923. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1924. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1925. };
  1926. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1927. if (nRet != 0)
  1928. {
  1929. OnMessage(LogType.Info,
  1930. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1931. }
  1932. else
  1933. {
  1934. OnMessage(LogType.Info,
  1935. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1936. }
  1937. // 构建保存路径
  1938. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1939. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1940. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1941. Directory.CreateDirectory(savePath); // 确保目录存在
  1942. // 构建文件名(以 SN + 序号命名)
  1943. string fileName = $"{sn}_{fileCounter}.txt";
  1944. string filePath = Path.Combine(savePath, fileName);
  1945. // 写入文件
  1946. using (StreamWriter writer = new StreamWriter(filePath))
  1947. {
  1948. writer.WriteLine("精度, 扭力");
  1949. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1950. for (int i = 0;
  1951. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  1952. i++)
  1953. {
  1954. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1955. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1956. writer.WriteLine($"{precision}, {torque}");
  1957. }
  1958. }
  1959. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1960. // 增加文件计数器
  1961. fileCounter++;
  1962. }
  1963. // 如果没有更多数据,则短暂休眠以节省资源
  1964. if (!cachedData.Any())
  1965. {
  1966. Thread.Sleep(10); // 根据需要调整休眠时间
  1967. }
  1968. // 如果触发了出站,则退出循环
  1969. if (!isCollectingFlagRight)
  1970. {
  1971. break;
  1972. }
  1973. }
  1974. stopwatch.Stop();
  1975. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1976. }
  1977. catch (Exception ex)
  1978. {
  1979. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1980. }
  1981. finally
  1982. {
  1983. isCollectingFlagRight = false;
  1984. }
  1985. }
  1986. public static (int, string) CompressFolder(string folderPath, string zipFilePath)
  1987. {
  1988. try
  1989. {
  1990. // 创建zip文件,将指定文件夹内的所有内容压缩到这个zip文件中
  1991. System.IO.Compression.ZipFile.CreateFromDirectory(folderPath, zipFilePath);
  1992. return (1, "文件夹已成功压缩!");
  1993. }
  1994. catch (Exception ex)
  1995. {
  1996. return (0, "文件压缩出错!" + ex.Message);
  1997. }
  1998. }
  1999. /// <summary>
  2000. /// 上传文件
  2001. /// </summary>
  2002. /// <param name="BarcodeSet_t">条码集合</param>
  2003. /// <param name="stationCode">工站编号</param>
  2004. /// <param name="stationName">工站名称</param>
  2005. /// <param name="path">文件路径</param>
  2006. public async Task<(int, string)> SaveDBbyFileInfo(BarcodeSet_t BarcodeSet, string stationCode,
  2007. string stationName, int pass, string path, string guid = "")
  2008. {
  2009. string sql, filename = "";
  2010. int result = 0;
  2011. var formData = new MultipartFormDataContent();
  2012. string msg = "";
  2013. string file_category = "IMAGE"; //IMAGE 、TEXT 、UNKNOWN
  2014. string file_type = "IMAGE";
  2015. string project = GlobalContext.ProgramName;
  2016. string run_mode = GlobalContext.run_mode;
  2017. string product_mode = GlobalContext.product_mode;
  2018. string pass_result = (pass == 1 ? "PASS" : "Fail");
  2019. string device_code = xiaomiParm.deviceCode;
  2020. string sn = BarcodeSet.strProductBarcode;
  2021. string staion_id = xiaomiParm.stationCode;
  2022. string bucket =
  2023. $"{file_category}/{file_type}/{project}/{product_mode}/{run_mode}/{pass_result}/{device_code}/{sn}/{staion_id}";
  2024. // 获取所有图片文件
  2025. if (guid == "")
  2026. {
  2027. guid = Guid.NewGuid().ToString();
  2028. }
  2029. try
  2030. {
  2031. if (GlobalContext.MESIsSendUpFile)
  2032. {
  2033. List<string> imageFiles = GetAllImageFiles(path);
  2034. string toPath = GlobalContext.MqttFileBackupLogDir;
  2035. filename =
  2036. $"{xiaomiParm.workstation}_{file_type}_{sn}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";
  2037. //string directoryPath = Path.GetDirectoryName(path);
  2038. string strFilePath = toPath + "\\" + filename;
  2039. if (imageFiles.Count > 0)
  2040. {
  2041. var r = CompressFolder(path, strFilePath);
  2042. if (r.Item1 == 0)
  2043. {
  2044. return (0, r.Item2);
  2045. }
  2046. else
  2047. {
  2048. msg = r.Item2 + "\r\n";
  2049. }
  2050. }
  2051. else
  2052. {
  2053. return (0, "文件不存在!");
  2054. }
  2055. FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
  2056. fileUpload_X5.bucket = bucket;
  2057. fileUpload_X5.name = filename;
  2058. fileUpload_X5.uuid = guid.ToString();
  2059. ///需要上传文件
  2060. FileInfo file = new FileInfo(strFilePath);
  2061. string fileMd5Hex = GetMD5Hex(file);
  2062. fileUpload_X5.md5 = fileMd5Hex;
  2063. fileUpload_X5.uploadCloud = true;
  2064. fileUpload_X5.informMqtt = true;
  2065. FileMqttPayload fileMqttPayload = new FileMqttPayload();
  2066. fileMqttPayload.factory = GlobalContext.Factory_Code;
  2067. fileMqttPayload.project_name = GlobalContext.Project_Code;
  2068. fileMqttPayload.product_mode = GlobalContext.product_mode;
  2069. fileMqttPayload.line_no = GlobalContext.LineCode;
  2070. fileMqttPayload.work_station_no = xiaomiParm.workstation;
  2071. fileMqttPayload.equipment_no = xiaomiParm.deviceCode;
  2072. fileMqttPayload.station_no = xiaomiParm.stationCode;
  2073. fileMqttPayload.file_id = guid;
  2074. fileMqttPayload.file_name = filename;
  2075. fileMqttPayload.sn = BarcodeSet.strProductBarcode;
  2076. //fileMqttPayload.opt_time = "";
  2077. //fileMqttPayload.file_type = "";
  2078. //fileMqttPayload.file_category = "";
  2079. //fileMqttPayload.tag = "";
  2080. fileMqttPayload.reference_info.pass_station_id = uuid;
  2081. var fileresult = await
  2082. XiaomiMESHttp_UpLoadFile.FileUoladToMes(strFilePath, fileUpload_X5, fileMqttPayload);
  2083. if (fileresult.Item1 != 1)
  2084. {
  2085. return (0, msg + fileresult.Item2 + "\r\n");
  2086. }
  2087. else
  2088. {
  2089. msg = msg + fileresult.Item2 + "\r\n";
  2090. }
  2091. foreach (var imageFile in imageFiles)
  2092. {
  2093. if (File.Exists(imageFile))
  2094. {
  2095. //删除文件
  2096. (bool, string) newResult = DeleteFile(imageFile);
  2097. if (!newResult.Item1)
  2098. {
  2099. return (0, Path.GetFileName(imageFile) + newResult.Item2);
  2100. }
  2101. }
  2102. }
  2103. }
  2104. return (1, msg);
  2105. }
  2106. catch (Exception e)
  2107. {
  2108. return (0,
  2109. filename + $"文件上传错误!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode},错误原因:" +
  2110. e.Message);
  2111. }
  2112. }
  2113. /// <summary>
  2114. /// 获取路径下的所有图片
  2115. /// </summary>
  2116. /// <param name="directoryPath"></param>
  2117. /// <returns></returns>
  2118. public List<string> GetAllImageFiles(string directoryPath)
  2119. {
  2120. var imageExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
  2121. { ".jpg", ".jpeg", ".png", ".bmp", ".gif", ".tiff" };
  2122. var imageFiles = new List<string>();
  2123. try
  2124. {
  2125. // 遍历目录及子目录中的所有文件
  2126. foreach (string file in Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories))
  2127. {
  2128. // 获取文件扩展名并检查是否为图片格式
  2129. string extension = Path.GetExtension(file);
  2130. if (imageExtensions.Contains(extension))
  2131. {
  2132. imageFiles.Add(file);
  2133. }
  2134. }
  2135. }
  2136. catch (Exception ex)
  2137. {
  2138. OnMessage(LogType.Error, $"图片查询发生错误: {ex.Message}");
  2139. }
  2140. return imageFiles;
  2141. }
  2142. /// <summary>
  2143. /// 实例化报警字典
  2144. /// </summary>
  2145. private (bool, string) InitalDicAlarm()
  2146. {
  2147. #region 加载报警表
  2148. string excelPath = "";
  2149. switch (GlobalContext.IsUsePLCNow)
  2150. {
  2151. case 1:
  2152. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_10_壳体清洁上料.xlsx";
  2153. break;
  2154. case 2:
  2155. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_20_上盖板上料装备.xlsx";
  2156. break;
  2157. case 3:
  2158. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_30_点散热胶装备.xlsx";
  2159. break;
  2160. case 4:
  2161. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_40_胶线检测.xlsx";
  2162. break;
  2163. case 5:
  2164. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_50_ADD板上料组装装备.xlsx";
  2165. break;
  2166. case 6:
  2167. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_60_组上盖板.xlsx";
  2168. break;
  2169. case 7:
  2170. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_70_上盖板锁螺丝.xlsx";
  2171. break;
  2172. case 8:
  2173. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_80_NG下料.xlsx";
  2174. break;
  2175. case 9:
  2176. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_90_半成品下料.xlsx";
  2177. break;
  2178. default:
  2179. return (false, $"不支持当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请在设置页切换到正确的plc后重启该软件!");
  2180. }
  2181. if (!File.Exists(excelPath))
  2182. return (false, $"未找到当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请检查文件路径:'{excelPath}'。");
  2183. DataTable DtModel = NPOIHelper.ReadExcel(excelPath);
  2184. if (DtModel == null || DtModel.Rows.Count < 1)
  2185. return (false, $"报警点位表未包含任何报警数据!请检查‘{excelPath}’文件!");
  2186. // 检查列名
  2187. List<string> isNeedParms = new List<string>()
  2188. {
  2189. "设备分类名称", "设备分类编码", "分类层级1", "分类层级2", "分类层级3", "分类层级4", "事件名称", "事件ID", "描述", "标签", "PLC地址", "工位"
  2190. }; // 必须要有的列
  2191. // 指定列名 + 检查列是否完整
  2192. DataRow dtRowName = DtModel.Rows[0];
  2193. int count = DtModel.Columns.Count;
  2194. for (int i = 0; i < count; i++)
  2195. {
  2196. string columeName = dtRowName[i]?.ToString();
  2197. if (!string.IsNullOrEmpty(columeName))
  2198. DtModel.Columns[i].ColumnName = columeName;
  2199. if ((!string.IsNullOrEmpty(columeName)) && isNeedParms.Count > 0 && isNeedParms.Contains(columeName))
  2200. isNeedParms.Remove(columeName);
  2201. }
  2202. DtModel.Rows.RemoveAt(0);
  2203. if (isNeedParms.Count > 0)
  2204. {
  2205. string msg1 = string.Join(",", isNeedParms);
  2206. return (false, $"报警点位表未包含列:{msg1}!请检查‘{excelPath}’文件!");
  2207. }
  2208. #endregion 加载报警表
  2209. List<Alarm> keyValues1 = new List<Alarm>();
  2210. for (int i = 0; i < DtModel.Rows.Count; i++)
  2211. {
  2212. Alarm alarm = new Alarm();
  2213. alarm.plcName = DtModel.Rows[i]["设备分类名称"]?.ToString(); // 设备名;
  2214. string type1Str = DtModel.Rows[i]["分类层级1"]?.ToString(); // 分类层级1;
  2215. alarm.type1CH = type1Str; // 分类层级1 中文
  2216. alarm.type1 = type1Str; // 分类层级1
  2217. if (!string.IsNullOrEmpty(type1Str) && type1Str.Contains("\n"))
  2218. {
  2219. string[] type1Strs = type1Str.Split('\n');
  2220. if (type1Strs.Length >= 2)
  2221. {
  2222. alarm.type1CH = type1Strs[0].Trim(); // 分类层级1 中文
  2223. alarm.type1 = type1Strs[1].Trim(); // 分类层级1
  2224. if (string.IsNullOrEmpty(alarm.type1))
  2225. alarm.type1 = alarm.type1CH;
  2226. }
  2227. }
  2228. string type2Str = DtModel.Rows[i]["分类层级2"]?.ToString(); // 分类层级2;电气控制 electric_control
  2229. alarm.type2CH = type2Str; // 分类层级2 中文
  2230. alarm.type2 = type2Str; // 分类层级2
  2231. if (!string.IsNullOrEmpty(type2Str) && type2Str.Contains("\n"))
  2232. {
  2233. string[] type2Strs = type2Str.Split('\n');
  2234. if (type2Strs.Length >= 2)
  2235. {
  2236. alarm.type2CH = type2Strs[0].Trim(); // 分类层级2 中文
  2237. alarm.type2 = type2Strs[1].Trim(); // 分类层级2
  2238. if (string.IsNullOrEmpty(alarm.type2))
  2239. alarm.type2 = alarm.type2CH;
  2240. }
  2241. }
  2242. string type3Str = DtModel.Rows[i]["分类层级3"]?.ToString(); // 分类层级3;故障 Fault
  2243. alarm.type3CH = type3Str; // 分类层级3 中文
  2244. alarm.type3 = type3Str; // 分类层级3
  2245. if (!string.IsNullOrEmpty(type3Str) && type3Str.Contains("\n"))
  2246. {
  2247. string[] type3Strs = type3Str.Split('\n');
  2248. if (type3Strs.Length >= 2)
  2249. {
  2250. alarm.type3CH = type3Strs[0].Trim(); // 分类层级3 中文
  2251. alarm.type3 = type3Strs[1].Trim(); // 分类层级3
  2252. if (string.IsNullOrEmpty(alarm.type3))
  2253. alarm.type3 = alarm.type3CH;
  2254. }
  2255. }
  2256. string faultStr = DtModel.Rows[i]["分类层级4"]?.ToString(); // 故障部件;overall_module
  2257. alarm.type4 = faultStr; // 分类层级4 中文
  2258. alarm.type4CH = faultStr; // 分类层级4
  2259. if (!string.IsNullOrEmpty(faultStr) && faultStr.Contains("\n"))
  2260. {
  2261. string[] faultStrs = faultStr.Split('\n');
  2262. if (faultStrs.Length >= 2)
  2263. {
  2264. alarm.type4CH = faultStrs[0].Trim(); // 故障部件;overall_module
  2265. alarm.type4 = faultStrs[1].Trim(); // 故障部件
  2266. if (string.IsNullOrEmpty(alarm.type4))
  2267. alarm.type4 = alarm.type4CH;
  2268. }
  2269. }
  2270. alarm.fault_code = DtModel.Rows[i]["事件ID"]?.ToString(); // 故障编码;A40001
  2271. alarm.fault_name = DtModel.Rows[i]["事件名称"]?.ToString(); // 故障名称;AL[1000]_系统_HMI急停故障
  2272. alarm.fault_desc = alarm.fault_name; // 故障描述;AL[1000]_系统_HMI急停故障
  2273. string plcAdress = DtModel.Rows[i]["PLC地址"]?.ToString();
  2274. alarm.PLC地址 = plcAdress;
  2275. plcAdress = plcAdress.Replace("fault_codes[", "");
  2276. plcAdress = plcAdress.Replace("]", "");
  2277. alarm.group_index = Convert.ToInt32(plcAdress.Split(".")[0]);
  2278. keyValues1.Add(alarm);
  2279. }
  2280. DicAlarms_Cur.Add(GlobalContext.IsUseStationName, keyValues1); // 这里使用线体代替工位
  2281. return (true, "报警字典表初始化成功!");
  2282. }
  2283. private async void ReadPLCAlarmToIot(uint[] FaultData, uint[] FaultDataOld, string stationNameStr,string flag)
  2284. {
  2285. DateTime dtNow = DateTime.Now;
  2286. try
  2287. {
  2288. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  2289. List<(int, int)> AlarmIndexList = new List<(int, int)>(); //收集所有报警信息的位置
  2290. AlarmData alarmData = new AlarmData();
  2291. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  2292. bool isNoAlarm = false; //是否有报警
  2293. string binaryString = "";
  2294. bool isNoNewAlarm = false; //是否有新的报警
  2295. if (FaultData.Length > 0)
  2296. {
  2297. foreach (var item in FaultData)
  2298. {
  2299. if (item > 0)
  2300. {
  2301. isNoAlarm = true;
  2302. break;
  2303. }
  2304. else {
  2305. isNoAlarm = false;
  2306. }
  2307. }
  2308. if (!FaultData.SequenceEqual(FaultDataOld))
  2309. {
  2310. isNoNewAlarm = true;
  2311. isNeedUpdUI = true;
  2312. }
  2313. if (FaultData.Length > 0 && isNoAlarm && isNoNewAlarm)
  2314. {
  2315. //解析报警信息,分析当前报警在字典中的定位
  2316. for (int i = 0; i <= FaultData.Length - 1; i++)
  2317. {
  2318. var num = 0;
  2319. if (FaultData[i] > 0)
  2320. {
  2321. //转换二进制
  2322. binaryString = Convert.ToString(FaultData[i], 2);
  2323. for (int j = binaryString.Length - 1; j >= 0; j--)
  2324. {
  2325. num++;
  2326. char s = binaryString[j];
  2327. if (binaryString[j] == '1')
  2328. {
  2329. //记录1的位置
  2330. AlarmIndexList.Add((i, num - 1));
  2331. }
  2332. }
  2333. }
  2334. }
  2335. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  2336. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.IsUseStationName];
  2337. foreach ((int index, int row) in AlarmIndexList)
  2338. {
  2339. var tempDic = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList();
  2340. for (int i = 0; i < tempDic.Count - 1; i++) // 读取
  2341. {
  2342. //若报警字典第[group_index]个数据,第[i]行与AlarmIndexList中的定位匹配,则添加进对应行的报警数据
  2343. if (tempDic[i].group_index == index && i == row)
  2344. {
  2345. dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据 =
  2346. new AlarmData()
  2347. {
  2348. GUID = Guid.NewGuid().ToString(),
  2349. LineName = GlobalContext.IsUseStationName, // 工站
  2350. PlcStation = tempDic[i].plcName, // 工站全称;[S1]
  2351. Type1 = tempDic[i].type1, // 故障层级1
  2352. Type2 = tempDic[i].type2, // 故障层级2
  2353. Type3 = tempDic[i].type3, // 故障层级3
  2354. Type4 = tempDic[i].type4, // 故障层级4
  2355. AlarmType = tempDic[i].fault_code, // 报警类型
  2356. AlarmDesc = tempDic[i].fault_name, // 报警内容
  2357. StartTime = dtNow // 开始时间
  2358. };
  2359. // 传输到页面
  2360. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  2361. {
  2362. 线体名称 = tempDic[i].plcName,
  2363. 报警类型 = tempDic[i].fault_code,
  2364. 报警内容 = tempDic[i].fault_name,
  2365. 开始时间 = dtNow
  2366. });
  2367. // 新增到数据库
  2368. //var data1 = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据;
  2369. //SaveAlarmDataByDB(stationNameStr, data1, false);
  2370. //OnMessage(LogType.Info, $"更新{BodyAlarm}完毕!");
  2371. }
  2372. }
  2373. }
  2374. //筛选含报警数据的字典
  2375. var dicAlarms_Cur = dicAlarms_Cur_PLC1.Where(x => x.报警数据 != null).ToList();
  2376. if (dicAlarms_Cur.Count > 0)
  2377. {
  2378. string stationId = "";
  2379. foreach (var item in dicAlarms_Cur)
  2380. {
  2381. if (!string.IsNullOrEmpty(xiaomiParm.stationCode))
  2382. {
  2383. stationId = xiaomiParm.stationCode;
  2384. //上传
  2385. SaveAlarmDataByDB(GlobalContext.IsUseStationName, stationId, item.报警数据, false);
  2386. }
  2387. else {
  2388. if (flag == "left")
  2389. {
  2390. if (GlobalContext.IsUsePLC3)
  2391. stationId = GlobalContext.s3_1_station;
  2392. if (GlobalContext.IsUsePLC7)
  2393. stationId = GlobalContext.s7_1_station;
  2394. //上传
  2395. SaveAlarmDataByDB(GlobalContext.IsUseStationName, stationId, item.报警数据, false);
  2396. }
  2397. else {
  2398. if (GlobalContext.IsUsePLC3)
  2399. stationId = GlobalContext.s3_2_station;
  2400. if (GlobalContext.IsUsePLC7)
  2401. stationId = GlobalContext.s7_2_station;
  2402. //上传
  2403. SaveAlarmDataByDB(GlobalContext.IsUseStationName, stationId, item.报警数据, false);
  2404. }
  2405. }
  2406. }
  2407. }
  2408. // 有新报警则更新
  2409. if (isNeedUpdUI)
  2410. // UI展示 - 展示到设备状态页
  2411. await Task.Run(() =>
  2412. {
  2413. try
  2414. {
  2415. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  2416. {
  2417. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  2418. if (Form_Main.formDevAlarm.Visible)
  2419. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  2420. }
  2421. }
  2422. catch
  2423. {
  2424. }
  2425. });
  2426. if (flag == "left")
  2427. {
  2428. _FaultDatas_Old = FaultData.ToArray();
  2429. }
  2430. else {
  2431. _FaultDatas_Old2 = FaultData.ToArray();
  2432. }
  2433. }
  2434. }
  2435. //FaultLogRequest request = new FaultLogRequest();
  2436. //request.station = mesStation; // 工位
  2437. //request.fault_name = xmFaultName; // 故障名称(同数据字典中的事件名称)
  2438. //request.fault_code = xmFaultCode2; // 故障编码(A,B,C,D,E)
  2439. //request.fault_cmpnt = xmFaultCmpnt; // 故障部件
  2440. //request.fault_desc = xmFaultDesc; // 故障描述
  2441. //request.fault_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 故障发生时间 2022-06-01 14:27:57.283
  2442. // // 上传
  2443. //(int, string) iotResult = XiaomiMqttClient_Extend.Write_FaultLog(request, type1, type2, type3, request.fault_cmpnt, deciveCode);
  2444. }
  2445. catch (Exception ex)
  2446. {
  2447. string str = ex.StackTrace;
  2448. AddMessage_Station(stationNameStr, LogType.Error,
  2449. $"{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" +
  2450. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2451. }
  2452. }
  2453. public void operateToIot(string action, string stationNameStr)
  2454. {
  2455. OperateLogRequest request = new OperateLogRequest();
  2456. request.software_version = "V" + Application.ProductVersion; // 软件版本号;如:V1.2.4
  2457. request.operate_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 操作时间(2022-06-01 14:27:57.283)
  2458. request.operate_action = action; // 操作动作(对应软件开启/关闭/重新加载项⽬;startup、shutdown、reload)
  2459. //request.current_process = Process.GetCurrentProcess()?.Id.ToString(); // 当前进程;进程ID
  2460. request.current_process = Application.ProductName;
  2461. request.operate_desc = stationNameStr; // 操作描述;如:供应商软件开启/关闭/重新加载项⽬
  2462. request.operate_result = "success"; // 操作结果
  2463. request.operator_name = "default"; // 操作账号名;填当前操作⽤⼾,如⽆则填default
  2464. // 上传
  2465. (int, string) iotResult = XiaomiMqttClient_Extend.Write_OperateLog(request);
  2466. if (iotResult.Item1 != 0)
  2467. {
  2468. AddMessage(LogType.Info, "【操作记录】上传失败!错误原因:" + iotResult.Item2 + "操作状态:" + stationNameStr);
  2469. }
  2470. }
  2471. private void 通用节拍接口(int plcNo, string stationNameStr, string tagMesCommName, string CarrierBarcode,
  2472. IoT_DataSet_t iot_data, out int res)
  2473. {
  2474. Stopwatch stopwatch1 = new Stopwatch();
  2475. Stopwatch stopwatch2 = new Stopwatch();
  2476. string resultStr = string.Empty;
  2477. try
  2478. {
  2479. string oEEType = iot_data.beatAction.ToString(); // 节拍类型(plc写入)
  2480. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode); //产品SN
  2481. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  2482. (short, string) result = (0, "");
  2483. // 上传开始节拍
  2484. result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2485. //上传结束节拍
  2486. switch (oEEType)
  2487. {
  2488. case "1":
  2489. Enum.TryParse("2", out deviceOEE);
  2490. result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2491. break;
  2492. case "5":
  2493. Enum.TryParse("6", out deviceOEE);
  2494. result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2495. break;
  2496. }
  2497. if (result.Item1 == 1)
  2498. {
  2499. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]上传成功!");
  2500. //写入PLC
  2501. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2502. iotData.machineState = iot_data.machineState;
  2503. iotData.work_type = iot_data.work_type;
  2504. iotData.testStatus = iot_data.testStatus;
  2505. iotData.beatAction = 0;
  2506. iotData.beatReturn = 1; //OK
  2507. iotData.fault_codes = iot_data.fault_codes;
  2508. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2509. if (PLCresult.Item1 == 0)
  2510. {
  2511. res = 1;
  2512. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]写入成功!");
  2513. }
  2514. else
  2515. {
  2516. res = 0;
  2517. }
  2518. }
  2519. else
  2520. {
  2521. res = 0;
  2522. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]接口出错!错误信息:" + result.Item2);
  2523. //写入PLC
  2524. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2525. iotData.machineState = iot_data.machineState;
  2526. iotData.work_type = iot_data.work_type;
  2527. iotData.testStatus = iot_data.testStatus;
  2528. iotData.beatAction = 0;
  2529. iotData.beatReturn = 2; //NG
  2530. iotData.fault_codes = iot_data.fault_codes;
  2531. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2532. }
  2533. }
  2534. catch (Exception ex)
  2535. {
  2536. res = 0;
  2537. string str = ex.StackTrace;
  2538. AddMessage_Station(stationNameStr, LogType.Error,
  2539. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  2540. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2541. //写入PLC
  2542. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2543. iotData.machineState = iot_data.machineState;
  2544. iotData.work_type = iot_data.work_type;
  2545. iotData.testStatus = iot_data.testStatus;
  2546. iotData.beatAction = 0;
  2547. iotData.beatReturn = 2; //NG
  2548. iotData.fault_codes = iot_data.fault_codes;
  2549. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2550. }
  2551. }
  2552. /// <summary>
  2553. /// 去除常见特殊字符,如 \r, \n, \t 等
  2554. /// </summary>
  2555. /// <param name="format"></param>
  2556. /// <returns></returns>
  2557. private static string FormatStrbyPLC(string format)
  2558. {
  2559. string cleanedString = "";
  2560. if (!string.IsNullOrEmpty(format))
  2561. {
  2562. cleanedString = Regex.Replace(format, @"[\r\n\t]", "");
  2563. }
  2564. return cleanedString;
  2565. }
  2566. #endregion
  2567. #region S1
  2568. /// <summary>
  2569. /// [S1] 壳体清洁上料装备
  2570. /// </summary>
  2571. /// <param name="plcNo">PLC编号</param>
  2572. private void ReadStation_S1(int plcNo)
  2573. {
  2574. string stationCode = "[OP10]";
  2575. string stationName = "壳体清洁上料";
  2576. string stationNameStr = stationCode + stationName;
  2577. string tagBaseName = "g_OP10_MES"; //标签变量名称
  2578. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2579. string tagAgvCommName = "agvCommFrmPC";
  2580. string tagiotComnName = "iotData";
  2581. string tagBarsetName = "BarcodeSet";
  2582. string CarrierBarcode = "";
  2583. string ProductBarcode = "";
  2584. // 触发信号字典
  2585. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2586. s1PLCSignal_Old.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2587. // PLC数据字典 赋值
  2588. s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2589. s1PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  2590. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  2591. (int, string) result;
  2592. while (true)
  2593. {
  2594. try
  2595. {
  2596. if (!GlobalContext._IsCon_Funs1)
  2597. {
  2598. UpdatePLCMonitor(1, plcNo, 0);
  2599. continue;
  2600. }
  2601. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2602. {
  2603. Stopwatch stopwatch1 = new Stopwatch();
  2604. Stopwatch stopwatch2 = new Stopwatch();
  2605. stopwatch1.Start();
  2606. stopwatch2.Start();
  2607. #region 一次性读取所有数据
  2608. // 一次性读取所有数据
  2609. result = FunsEip[plcNo]
  2610. .Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2611. if (result.Item1 != 0)
  2612. {
  2613. //richTextBox1.AppendText("\n" + strRet);
  2614. }
  2615. else
  2616. {
  2617. //richTextBox1.AppendText("\n" + "读取成功");
  2618. stPLC_MesData.BarcodeSet.strProductBarcode =
  2619. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  2620. stPLC_MesData.BarcodeSet.strPartBarcode =
  2621. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  2622. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  2623. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  2624. stPLC_MesData.BarcodeSet.strPCBBarcode =
  2625. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  2626. //设备状态
  2627. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  2628. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  2629. ? XiaomiDeviceState.Unknown
  2630. : (XiaomiDeviceState)xmDeviceStateInt;
  2631. // 载具SN
  2632. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode.ToString();
  2633. // 物料码(物料码还未绑定载具SN时必填)
  2634. ProductBarcode = stPLC_MesData.BarcodeSet.strProductBarcode;
  2635. // 节拍
  2636. s1PLCData["a1OEEType"] = stPLC_MesData.iotData.beatAction;
  2637. //报警信息
  2638. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  2639. }
  2640. #endregion 一次性读取所有数据
  2641. stopwatch2.Stop();
  2642. #region 进站
  2643. try
  2644. {
  2645. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2646. {
  2647. lock (lockObj)
  2648. {
  2649. if (!ProgressState)
  2650. {
  2651. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  2652. ProgressState = true;
  2653. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData,
  2654. tagBaseName + "." + tagMesCommName, out ProgressState));
  2655. }
  2656. }
  2657. }
  2658. }
  2659. catch (Exception ex)
  2660. {
  2661. ProgressState = false;
  2662. string str = ex.StackTrace;
  2663. AddMessage_Station(stationNameStr, LogType.Error,
  2664. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2665. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2666. }
  2667. #endregion 进站
  2668. #region 出站
  2669. try
  2670. {
  2671. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2672. {
  2673. lock (lockObj)
  2674. {
  2675. if (!ProgressState)
  2676. {
  2677. ProgressState = true;
  2678. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData,
  2679. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  2680. out ProgressState));
  2681. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  2682. }
  2683. }
  2684. }
  2685. }
  2686. catch (Exception ex)
  2687. {
  2688. ProgressState = false;
  2689. string str = ex.StackTrace;
  2690. AddMessage_Station(stationNameStr, LogType.Error,
  2691. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2692. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2693. }
  2694. #endregion 出站
  2695. #region 节拍接口
  2696. try
  2697. {
  2698. if (stPLC_MesData.iotData.beatAction > 0)
  2699. {
  2700. int a1OEEType = Convert.ToInt32(s1PLCData["a1OEEType"]);
  2701. int a1OEETypeGOld = Convert.ToInt32(s1PLCSignal_Old["a1OEEType"]);
  2702. if (a1OEEType != a1OEETypeGOld)
  2703. {
  2704. s1PLCData["OEETypeFlag"] = "1";
  2705. }
  2706. else
  2707. {
  2708. s1PLCData["OEETypeFlag"] = "0";
  2709. }
  2710. if (s1PLCData["OEETypeFlag"].ToString() == "1" && (a1OEEType == 1 || a1OEEType == 3 || a1OEEType == 4 || a1OEEType == 5))
  2711. {
  2712. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  2713. if (res == 1)
  2714. {
  2715. s1PLCSignal_Old["a1OEEType"] = s1PLCData["a1OEEType"];
  2716. }
  2717. else {
  2718. s1PLCSignal_Old["a1OEEType"] = 0;
  2719. }
  2720. }
  2721. }
  2722. else {
  2723. s1PLCSignal_Old["a1OEEType"] = 0;
  2724. }
  2725. }
  2726. catch (Exception ex)
  2727. {
  2728. string str = ex.StackTrace;
  2729. AddMessage_Station(stationNameStr, LogType.Error,
  2730. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  2731. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2732. }
  2733. #endregion
  2734. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2735. stopwatch1.Stop();
  2736. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2737. }
  2738. else
  2739. {
  2740. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2741. AddMessage_Station(stationNameStr, LogType.Info,
  2742. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2743. FunsEip[plcNo].Connect(); // 重连
  2744. }
  2745. }
  2746. catch (Exception ex)
  2747. {
  2748. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2749. AddMessage_Station(stationNameStr, LogType.Error,
  2750. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2751. }
  2752. Thread.Sleep(IntervalReadPLC);
  2753. }
  2754. }
  2755. /// <summary>
  2756. /// [S1] 壳体清洁上料 - 进站
  2757. /// </summary>
  2758. /// <param name="plcNo">PLC编号</param>
  2759. /// <param name="stationNameStr">工站全称</param>
  2760. /// <param name="stPLC_MesData"></param>
  2761. /// <param name="tagMesCommName"></param>
  2762. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  2763. out bool ProgressState)
  2764. {
  2765. Stopwatch stopwatch1 = new Stopwatch();
  2766. Stopwatch stopwatch2 = new Stopwatch();
  2767. try
  2768. {
  2769. stopwatch1.Start();
  2770. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2771. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  2772. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2773. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  2774. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  2775. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2776. bool pass = a1Result == 1;
  2777. if (string.IsNullOrEmpty(sn))
  2778. {
  2779. ProgressState = false;
  2780. AddMessage(LogType.Error, $"{stationNameStr}_未能查到产品码");
  2781. Thread.Sleep(10000);
  2782. return;
  2783. }
  2784. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  2785. // sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2786. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2787. //绑定载具和产品
  2788. ResponseMessage message = new ResponseMessage();
  2789. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  2790. if (message.result == false)
  2791. {
  2792. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  2793. ProgressState = false;
  2794. Thread.Sleep(10000);
  2795. return;
  2796. }
  2797. // 产品SN进站
  2798. List<TestItem> item = new List<TestItem>();
  2799. stopwatch2.Start();
  2800. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  2801. item, MachineId, StationId, pass, "01-SLOT-01");
  2802. stopwatch2.Stop();
  2803. //指令执行结果 1:OK 110:失败
  2804. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2805. if (mesResultFrmWeb == 1)
  2806. {
  2807. if (a1Result == 1)
  2808. {
  2809. mesResultFrmWeb = 1;
  2810. }
  2811. else
  2812. {
  2813. mesResultFrmWeb = 110;
  2814. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  2815. }
  2816. }
  2817. //进站结果写入PLC
  2818. CommandFromPLC resultToPlC = new CommandFromPLC();
  2819. resultToPlC.cmd = 0;
  2820. resultToPlC.cmdParam = 0;
  2821. resultToPlC.cmdResult = mesResultFrmWeb;
  2822. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2823. }
  2824. catch (Exception ex)
  2825. {
  2826. string str = ex.StackTrace;
  2827. AddMessage(LogType.Error,
  2828. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  2829. str.Length - str.LastIndexOf("\\") - 1));
  2830. CommandFromPLC resultToPlC = new CommandFromPLC();
  2831. resultToPlC.cmd = 0;
  2832. resultToPlC.cmdParam = 0; //指令参数
  2833. resultToPlC.cmdResult = 110;
  2834. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2835. }
  2836. stopwatch1.Stop();
  2837. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2838. AddMessage(LogType.Info,
  2839. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  2840. stopwatch2.ElapsedMilliseconds + "ms");
  2841. ProgressState = false;
  2842. }
  2843. /// <summary>
  2844. /// [S1] 壳体清洁上料 - 出站接口
  2845. /// </summary>
  2846. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  2847. string stationCode, string stationName, out bool ProgressState)
  2848. {
  2849. Stopwatch stopwatch1 = new Stopwatch();
  2850. Stopwatch stopwatch2 = new Stopwatch();
  2851. try
  2852. {
  2853. stopwatch1.Start();
  2854. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2855. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2856. string processItem = stationName; // 项目
  2857. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2858. string supplierCode = ""; // 供应商代码
  2859. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  2860. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  2861. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  2862. string sn = string.Empty;
  2863. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2864. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  2865. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  2866. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2867. //a1Result = 1;
  2868. bool pass = a1Result == 1;
  2869. //根据载具码获取产品码
  2870. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2871. if (string.IsNullOrEmpty(strProductBarcode))
  2872. {
  2873. ProgressState = false;
  2874. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  2875. Thread.Sleep(10000);
  2876. return;
  2877. }
  2878. sn = strProductBarcode;
  2879. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2880. List<TestItem> items = new List<TestItem>();
  2881. items.Add(new TestItem()
  2882. {
  2883. Parameter_name = "载具码",
  2884. Parameter_value = CarrierBarcode,
  2885. Parameter_unit = ""
  2886. });
  2887. items.Add(new TestItem()
  2888. {
  2889. Parameter_name = "产品码",
  2890. Parameter_value = sn,
  2891. Parameter_unit = ""
  2892. });
  2893. #region 转换过站明细字符串
  2894. //创建字典
  2895. var dic = new Dictionary<string, string>();
  2896. // 获取结构体类型
  2897. FieldInfo[] fields = typeof(OP10_DataSet_t).GetFields();
  2898. // 遍历变量名转换成字典描述
  2899. foreach (FieldInfo field in fields)
  2900. {
  2901. //获取枚举描述
  2902. string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
  2903. typeof(XiaomiMESEnum_ProcessData.Enum_10_ProcessData));
  2904. //获取过站明细的值
  2905. object valueObj = field.GetValue(stPLC_MesData.mesData);
  2906. dic.Add(name, valueObj.ToString());
  2907. }
  2908. string paramJson = JsonConvert.SerializeObject(dic);
  2909. #endregion
  2910. //出站接口
  2911. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2912. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  2913. MachineId, StationId, "", paramJson);
  2914. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2915. if (mesResultFrmWeb == 1)
  2916. {
  2917. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  2918. if (mesResultFrmWeb == 110)
  2919. {
  2920. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  2921. }
  2922. }
  2923. stopwatch2.Start();
  2924. //进站结果写入PLC
  2925. CommandFromPLC resultToPlC = new CommandFromPLC();
  2926. resultToPlC.cmd = 0;
  2927. resultToPlC.cmdParam = 0; //指令参数
  2928. resultToPlC.cmdResult = mesResultFrmWeb;
  2929. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2930. stopwatch2.Stop();
  2931. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2932. //保存PLC返回MES数据到本地
  2933. ResponseMessage message = new ResponseMessage();
  2934. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  2935. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress,
  2936. stPLC_MesData.mesData.fCleanSpeed,
  2937. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime,
  2938. stPLC_MesData.mesData.nCleanCount,
  2939. stPLC_MesData.mesData.nRemainCount);
  2940. if (message.result == false)
  2941. {
  2942. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2943. }
  2944. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  2945. }
  2946. catch (Exception ex)
  2947. {
  2948. stopwatch2.Start();
  2949. CommandFromPLC resultToPlC = new CommandFromPLC();
  2950. resultToPlC.cmd = 0;
  2951. resultToPlC.cmdParam = 0; //指令参数
  2952. resultToPlC.cmdResult = 110;
  2953. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2954. stopwatch2.Stop();
  2955. string str = ex.StackTrace;
  2956. AddMessage(LogType.Error,
  2957. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  2958. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2959. }
  2960. stopwatch1.Stop();
  2961. AddMessage(LogType.Info,
  2962. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  2963. stopwatch2.ElapsedMilliseconds + "ms");
  2964. ProgressState = false;
  2965. uuid = "";
  2966. }
  2967. #endregion
  2968. #region S2
  2969. /// <summary>
  2970. /// [S2] 上盖板上料装备
  2971. /// </summary>
  2972. /// <param name="plcNo">PLC编号</param>
  2973. private void ReadStation_S2(int plcNo)
  2974. {
  2975. string stationCode = "[OP20]";
  2976. string stationName = "上盖板上料装备";
  2977. string stationNameStr = stationCode + stationName;
  2978. string tagBaseName = "g_OP20_MES"; //标签变量名称
  2979. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2980. string tagAgvCommName = "agvCommFrmPC";
  2981. string tagiotComnName = "iotData";
  2982. string tagBarsetName = "BarcodeSet";
  2983. string CarrierBarcode = "";
  2984. // 触发信号字典
  2985. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2986. s2PLCSignal_Old.Add("a2OEEType", 0); // 节拍类型(plc写入)
  2987. // PLC数据字典 赋值
  2988. s2PLCData.Add("a2OEEType", 0); // 节拍类型(plc写入)
  2989. s2PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  2990. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  2991. (int, string) result;
  2992. while (true)
  2993. {
  2994. try
  2995. {
  2996. if (!GlobalContext._IsCon_Funs2)
  2997. {
  2998. UpdatePLCMonitor(1, plcNo, 0);
  2999. continue;
  3000. }
  3001. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3002. {
  3003. Stopwatch stopwatch1 = new Stopwatch();
  3004. Stopwatch stopwatch2 = new Stopwatch();
  3005. stopwatch1.Start();
  3006. stopwatch2.Start();
  3007. #region 一次性读取所有数据
  3008. // 一次性读取所有数据
  3009. result = FunsEip[plcNo]
  3010. .Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3011. if (result.Item1 != 0)
  3012. {
  3013. //richTextBox1.AppendText("\n" + strRet);
  3014. }
  3015. else
  3016. {
  3017. //richTextBox1.AppendText("\n" + "读取成功");
  3018. stPLC_MesData.BarcodeSet.strProductBarcode =
  3019. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  3020. stPLC_MesData.BarcodeSet.strPartBarcode =
  3021. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  3022. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  3023. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  3024. stPLC_MesData.BarcodeSet.strPCBBarcode =
  3025. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  3026. //设备状态
  3027. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  3028. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  3029. ? XiaomiDeviceState.Unknown
  3030. : (XiaomiDeviceState)xmDeviceStateInt;
  3031. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  3032. s2PLCData["a2OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  3033. //报警信息
  3034. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  3035. }
  3036. #endregion 一次性读取所有数据
  3037. stopwatch2.Stop();
  3038. #region 进站
  3039. try
  3040. {
  3041. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3042. {
  3043. lock (lockObj)
  3044. {
  3045. if (!ProgressState)
  3046. {
  3047. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3048. ProgressState = true;
  3049. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData,
  3050. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  3051. out ProgressState));
  3052. }
  3053. }
  3054. }
  3055. }
  3056. catch (Exception ex)
  3057. {
  3058. ProgressState = false;
  3059. string str = ex.StackTrace;
  3060. AddMessage_Station(stationNameStr, LogType.Error,
  3061. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3062. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3063. }
  3064. #endregion 进站
  3065. #region 出站
  3066. try
  3067. {
  3068. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3069. {
  3070. lock (lockObj)
  3071. {
  3072. if (!ProgressState)
  3073. {
  3074. ProgressState = true;
  3075. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData,
  3076. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  3077. out ProgressState));
  3078. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  3079. }
  3080. }
  3081. }
  3082. }
  3083. catch (Exception ex)
  3084. {
  3085. ProgressState = false;
  3086. string str = ex.StackTrace;
  3087. AddMessage_Station(stationNameStr, LogType.Error,
  3088. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3089. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3090. }
  3091. #endregion 出站
  3092. #region 节拍接口
  3093. try
  3094. {
  3095. if (stPLC_MesData.iotData.beatAction > 0)
  3096. {
  3097. int a2OEEType = Convert.ToInt32(s2PLCData["a2OEEType"]);
  3098. int a2OEETypeGOld = Convert.ToInt32(s2PLCSignal_Old["a2OEEType"]);
  3099. if (a2OEEType != a2OEETypeGOld)
  3100. {
  3101. s2PLCData["OEETypeFlag"] = "1";
  3102. }
  3103. else
  3104. {
  3105. s2PLCData["OEETypeFlag"] = "0";
  3106. }
  3107. if (s2PLCData["OEETypeFlag"].ToString() == "1" && (a2OEEType == 1 || a2OEEType == 3 || a2OEEType == 4 || a2OEEType == 5))
  3108. {
  3109. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  3110. if (res == 1)
  3111. {
  3112. s2PLCSignal_Old["a2OEEType"] = s2PLCData["a2OEEType"];
  3113. }
  3114. else
  3115. {
  3116. s2PLCSignal_Old["a2OEEType"] = 0;
  3117. }
  3118. }
  3119. }
  3120. else {
  3121. s2PLCSignal_Old["a2OEEType"] = 0;
  3122. }
  3123. }
  3124. catch (Exception ex)
  3125. {
  3126. string str = ex.StackTrace;
  3127. AddMessage_Station(stationNameStr, LogType.Error,
  3128. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3129. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3130. }
  3131. #endregion
  3132. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3133. stopwatch1.Stop();
  3134. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  3135. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3136. }
  3137. else
  3138. {
  3139. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3140. AddMessage_Station(stationNameStr, LogType.Info,
  3141. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3142. FunsEip[plcNo].Connect();
  3143. }
  3144. }
  3145. catch (Exception ex)
  3146. {
  3147. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3148. AddMessage_Station(stationNameStr, LogType.Error,
  3149. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3150. //Funs[plcNo].ReConnect();
  3151. }
  3152. Thread.Sleep(IntervalReadPLC);
  3153. }
  3154. }
  3155. /// <summary>
  3156. /// [S2] 上盖板上料装备
  3157. /// </summary>
  3158. /// <param name="plcNo">PLC编号</param>
  3159. /// <param name="stationNameStr">工站全称</param>
  3160. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  3161. string tagBarsetName, out bool ProgressState)
  3162. {
  3163. Stopwatch stopwatch1 = new Stopwatch();
  3164. Stopwatch stopwatch2 = new Stopwatch();
  3165. try
  3166. {
  3167. stopwatch1.Start();
  3168. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3169. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  3170. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  3171. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3172. bool pass = a1Result == 1;
  3173. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  3174. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  3175. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3176. //根据载具码获取产品码
  3177. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3178. if (string.IsNullOrEmpty(strProductBarcode))
  3179. {
  3180. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3181. ProgressState = false;
  3182. Thread.Sleep(10000);
  3183. return;
  3184. }
  3185. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  3186. //if (sn != strProductBarcode)
  3187. //{
  3188. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  3189. //}
  3190. sn = strProductBarcode;
  3191. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3192. // 产品SN(物料码)校验
  3193. List<TestItem> item = new List<TestItem>();
  3194. stopwatch2.Start();
  3195. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3196. item, MachineId, StationId, pass, "01-SLOT-01");
  3197. stopwatch2.Stop();
  3198. //指令执行结果 1:OK 110:失败
  3199. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3200. if (mesResultFrmWeb == 1)
  3201. {
  3202. if (a1Result == 1)
  3203. {
  3204. mesResultFrmWeb = 1;
  3205. }
  3206. else
  3207. {
  3208. mesResultFrmWeb = 110;
  3209. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3210. }
  3211. }
  3212. //进站结果写入PLC
  3213. CommandFromPLC resultToPlC = new CommandFromPLC();
  3214. resultToPlC.cmd = 0;
  3215. resultToPlC.cmdParam = 0; //指令参数
  3216. resultToPlC.cmdResult = mesResultFrmWeb;
  3217. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3218. }
  3219. catch (Exception ex)
  3220. {
  3221. string str = ex.StackTrace;
  3222. AddMessage(LogType.Error,
  3223. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3224. str.Length - str.LastIndexOf("\\") - 1));
  3225. CommandFromPLC resultToPlC = new CommandFromPLC();
  3226. resultToPlC.cmd = 0;
  3227. resultToPlC.cmdParam = 0; //指令参数
  3228. resultToPlC.cmdResult = 110;
  3229. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3230. }
  3231. stopwatch1.Stop();
  3232. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3233. AddMessage(LogType.Info,
  3234. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3235. stopwatch2.ElapsedMilliseconds + "ms");
  3236. ProgressState = false;
  3237. }
  3238. /// <summary>
  3239. /// [S2] 上盖板上料装备 - 出站接口
  3240. /// </summary>
  3241. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  3242. string stationCode, string stationName, out bool ProgressState)
  3243. {
  3244. Stopwatch stopwatch1 = new Stopwatch();
  3245. Stopwatch stopwatch2 = new Stopwatch();
  3246. try
  3247. {
  3248. stopwatch1.Start();
  3249. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3250. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3251. string processItem = stationName; // 测试项目
  3252. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3253. string supplierCode = ""; // 供应商代码
  3254. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3255. string batch_num = GlobalContext.BatchNumber; // 批次号
  3256. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3257. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3258. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3259. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  3260. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  3261. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  3262. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3263. bool pass = a1Result == 1;
  3264. //根据载具码获取产品码
  3265. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3266. if (string.IsNullOrEmpty(strProductBarcode))
  3267. {
  3268. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3269. ProgressState = false;
  3270. Thread.Sleep(10000);
  3271. return;
  3272. }
  3273. sn = strProductBarcode;
  3274. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3275. List<TestItem> items = new List<TestItem>();
  3276. items.Add(new TestItem()
  3277. {
  3278. Parameter_name = "载具码",
  3279. Parameter_value = CarrierBarcode,
  3280. Parameter_unit = ""
  3281. });
  3282. items.Add(new TestItem()
  3283. {
  3284. Parameter_name = "产品码",
  3285. Parameter_value = sn,
  3286. Parameter_unit = ""
  3287. });
  3288. items.Add(new TestItem()
  3289. {
  3290. Parameter_name = "部件码",
  3291. Parameter_value = PartBarcode,
  3292. Parameter_unit = ""
  3293. });
  3294. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3295. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3296. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  3297. MachineId, StationId, PartBarcode, paramJson);
  3298. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3299. if (mesResultFrmWeb == 1)
  3300. {
  3301. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3302. if (mesResultFrmWeb == 110)
  3303. {
  3304. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  3305. }
  3306. }
  3307. stopwatch2.Start();
  3308. //进站结果写入PLC
  3309. CommandFromPLC resultToPlC = new CommandFromPLC();
  3310. resultToPlC.cmd = 0;
  3311. resultToPlC.cmdParam = 0; //指令参数
  3312. resultToPlC.cmdResult = mesResultFrmWeb;
  3313. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3314. stopwatch2.Stop();
  3315. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3316. //保存PLC返回MES数据到本地
  3317. ResponseMessage message = new ResponseMessage();
  3318. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  3319. stPLC_MesData.mesData.nRemainCount);
  3320. if (message.result == false)
  3321. {
  3322. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3323. }
  3324. if (!string.IsNullOrEmpty(PartBarcode))
  3325. {
  3326. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  3327. if (message.result == false)
  3328. {
  3329. AddMessage(LogType.Error, message.text);
  3330. }
  3331. }
  3332. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3333. }
  3334. catch (Exception ex)
  3335. {
  3336. stopwatch2.Start();
  3337. CommandFromPLC resultToPlC = new CommandFromPLC();
  3338. resultToPlC.cmd = 0;
  3339. resultToPlC.cmdParam = 0; //指令参数
  3340. resultToPlC.cmdResult = 110;
  3341. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3342. stopwatch2.Stop();
  3343. string str = ex.StackTrace;
  3344. AddMessage(LogType.Error,
  3345. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3346. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3347. }
  3348. stopwatch1.Stop();
  3349. AddMessage(LogType.Info,
  3350. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3351. stopwatch2.ElapsedMilliseconds + "ms");
  3352. ProgressState = false;
  3353. uuid = "";
  3354. }
  3355. #endregion
  3356. #region S3
  3357. /// <summary>
  3358. /// [S3] 点散热胶装备
  3359. /// </summary>
  3360. /// <param name="plcNo">PLC编号</param>
  3361. private void ReadStation_S3(int plcNo)
  3362. {
  3363. string stationCode = "[OP30]";
  3364. string stationName = "点散热胶装备";
  3365. string stationNameStr = stationCode + stationName;
  3366. string tagBaseName = "g_OP30_MES"; //标签变量名称
  3367. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3368. string tagAgvCommName = "agvCommFrmPC";
  3369. string tagiotComnName = "iotData";
  3370. string tagBarsetName = "BarcodeSet";
  3371. string CarrierBarcode_Left = "";
  3372. string CarrierBarcode_Right = "";
  3373. s3PLCSignal_Old.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
  3374. s3PLCSignal_Old.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
  3375. // PLC数据字典 赋值
  3376. s3PLCData.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
  3377. s3PLCData.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
  3378. s5PLCData.Add("OEETypeFlag_left", 0); // 节拍标识 0 不上传 ,1 上传
  3379. s5PLCData.Add("OEETypeFlag_right", 0); // 节拍标识 0 不上传 ,1 上传
  3380. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  3381. (int, string) result;
  3382. while (true)
  3383. {
  3384. try
  3385. {
  3386. if (!GlobalContext._IsCon_Funs2)
  3387. {
  3388. UpdatePLCMonitor(1, plcNo, 0);
  3389. continue;
  3390. }
  3391. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3392. {
  3393. Stopwatch stopwatch1 = new Stopwatch();
  3394. Stopwatch stopwatch2 = new Stopwatch();
  3395. stopwatch1.Start();
  3396. stopwatch2.Start();
  3397. #region 一次性读取所有数据
  3398. // 一次性读取所有数据
  3399. result = FunsEip[plcNo]
  3400. .Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3401. if (result.Item1 != 0)
  3402. {
  3403. //richTextBox1.AppendText("\n" + strRet);
  3404. }
  3405. else
  3406. {
  3407. //测试数据
  3408. //stPLC_MesData.Left.mesCommFrmPLC.cmd = 2;
  3409. //stPLC_MesData.Left.BarcodeSet.strCarrierBarcode = "A123456";
  3410. //stPLC_MesData.Left.BarcodeSet.strPCBBarcode = "A1507V000239";
  3411. //stPLC_MesData.Left.iotData.beatAction = 1;
  3412. //stPLC_MesData.Left.iotData.beatAction = 2;
  3413. //stPLC_MesData.Left.BarcodeSet.strCarrierBarcode = "A123456";
  3414. #region 去除扫码产生的特殊字符
  3415. stPLC_MesData.Left.BarcodeSet.strProductBarcode =
  3416. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strProductBarcode);
  3417. stPLC_MesData.Left.BarcodeSet.strPartBarcode =
  3418. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPartBarcode);
  3419. stPLC_MesData.Left.BarcodeSet.strCarrierBarcode =
  3420. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strCarrierBarcode);
  3421. stPLC_MesData.Left.BarcodeSet.strPCBBarcode =
  3422. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPCBBarcode);
  3423. stPLC_MesData.Right.BarcodeSet.strProductBarcode =
  3424. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strProductBarcode);
  3425. stPLC_MesData.Right.BarcodeSet.strPartBarcode =
  3426. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPartBarcode);
  3427. stPLC_MesData.Right.BarcodeSet.strCarrierBarcode =
  3428. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strCarrierBarcode);
  3429. stPLC_MesData.Right.BarcodeSet.strPCBBarcode =
  3430. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPCBBarcode);
  3431. #endregion
  3432. //richTextBox1.AppendText("\n" + "读取成功");
  3433. //设备状态
  3434. int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  3435. int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  3436. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  3437. ? XiaomiDeviceState.Unknown
  3438. : (XiaomiDeviceState)xmDeviceStateInt_L;
  3439. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  3440. ? XiaomiDeviceState.Unknown
  3441. : (XiaomiDeviceState)xmDeviceStateInt_R;
  3442. //载具SN
  3443. CarrierBarcode_Left = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode;
  3444. CarrierBarcode_Right = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode;
  3445. // 节拍
  3446. s3PLCData["a3OEEType_left"] = stPLC_MesData.Left.iotData.beatAction;
  3447. s3PLCData["a3OEEType_right"] = stPLC_MesData.Right.iotData.beatAction;
  3448. //报警信息
  3449. _FaultDatas = stPLC_MesData.Left.iotData.fault_codes;
  3450. _FaultDatas2 = stPLC_MesData.Right.iotData.fault_codes;
  3451. //_FaultDatas = new uint[] { 2, 0, 16, 0, 0, 0, 0, 0, 0, 0 };
  3452. //_FaultDatas2 = new uint[] { 2, 0, 16, 0, 0, 0, 0, 0, 0, 0 };
  3453. }
  3454. #endregion 一次性读取所有数据
  3455. stopwatch2.Stop();
  3456. #region 左边进站
  3457. try
  3458. {
  3459. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3460. {
  3461. lock (lockObj)
  3462. {
  3463. if (!ProgressState)
  3464. {
  3465. stationCode = "[OP31]";
  3466. stationName = "点散热胶装备1";
  3467. stationNameStr = stationCode + stationName;
  3468. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3469. ProgressState = true;
  3470. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left,
  3471. tagBaseName + ".Left." + tagMesCommName,
  3472. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  3473. }
  3474. }
  3475. }
  3476. }
  3477. catch (Exception ex)
  3478. {
  3479. ProgressState = false;
  3480. string str = ex.StackTrace;
  3481. AddMessage_Station(stationNameStr, LogType.Error,
  3482. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3483. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3484. }
  3485. #endregion 左边进站
  3486. #region 左边出站
  3487. try
  3488. {
  3489. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3490. {
  3491. lock (lockObj)
  3492. {
  3493. if (!ProgressState)
  3494. {
  3495. stationCode = "[OP31]";
  3496. stationName = "点散热胶装备1";
  3497. stationNameStr = stationCode + stationName;
  3498. ProgressState = true;
  3499. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left,
  3500. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  3501. out ProgressState));
  3502. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  3503. }
  3504. }
  3505. }
  3506. }
  3507. catch (Exception ex)
  3508. {
  3509. ProgressState = false;
  3510. string str = ex.StackTrace;
  3511. AddMessage_Station(stationNameStr, LogType.Error,
  3512. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3513. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3514. }
  3515. #endregion 左边出站
  3516. #region 右边进站
  3517. try
  3518. {
  3519. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3520. {
  3521. lock (lockObj)
  3522. {
  3523. if (!ProgressState)
  3524. {
  3525. uuid2 = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3526. stationCode = "[OP32]";
  3527. stationName = "点散热胶装备2";
  3528. stationNameStr = stationCode + stationName;
  3529. ProgressState = true;
  3530. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right,
  3531. tagBaseName + ".Right." + tagMesCommName,
  3532. tagBaseName + ".Right." + tagBarsetName, "Right", out ProgressState));
  3533. }
  3534. }
  3535. }
  3536. }
  3537. catch (Exception ex)
  3538. {
  3539. ProgressState = false;
  3540. string str = ex.StackTrace;
  3541. AddMessage_Station(stationNameStr, LogType.Error,
  3542. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3543. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3544. }
  3545. #endregion 右边进站
  3546. #region 右边出站
  3547. try
  3548. {
  3549. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3550. {
  3551. lock (lockObj)
  3552. {
  3553. if (!ProgressState)
  3554. {
  3555. stationCode = "[OP32]";
  3556. stationName = "点散热胶装备2";
  3557. stationNameStr = stationCode + stationName;
  3558. ProgressState = true;
  3559. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right,
  3560. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  3561. out ProgressState));
  3562. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  3563. }
  3564. }
  3565. }
  3566. }
  3567. catch (Exception ex)
  3568. {
  3569. string str = ex.StackTrace;
  3570. AddMessage_Station(stationNameStr, LogType.Error,
  3571. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3572. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3573. }
  3574. #endregion 右边出站
  3575. #region 节拍接口
  3576. try
  3577. {
  3578. #region 左工位 节拍
  3579. if (stPLC_MesData.Left.iotData.beatAction > 0)
  3580. {
  3581. stationCode = "[OP31]";
  3582. stationName = "点散热胶装备1";
  3583. stationNameStr = stationCode + stationName;
  3584. int a3OEEType_left = Convert.ToInt32(s3PLCData["a3OEEType_left"]);
  3585. int a3OEETypeGOld_left = Convert.ToInt32(s3PLCSignal_Old["a3OEEType_left"]);
  3586. if (a3OEEType_left != a3OEETypeGOld_left)
  3587. {
  3588. s3PLCData["OEETypeFlag_left"] = "1";
  3589. }
  3590. else
  3591. {
  3592. s3PLCData["OEETypeFlag_left"] = "0";
  3593. }
  3594. if (s3PLCData["OEETypeFlag_left"].ToString() == "1" && (a3OEEType_left == 1 || a3OEEType_left == 3 || a3OEEType_left == 4 || a3OEEType_left == 5))
  3595. {
  3596. 通用节拍接口(plcNo, stationNameStr,
  3597. tagBaseName + ".Left." + tagiotComnName, CarrierBarcode_Left,
  3598. stPLC_MesData.Left.iotData, out res);
  3599. if (res == 1)
  3600. {
  3601. s3PLCSignal_Old["a3OEEType_left"] = a3OEEType_left;
  3602. }
  3603. else {
  3604. s3PLCSignal_Old["a3OEEType_left"] = 0;
  3605. }
  3606. }
  3607. }
  3608. else
  3609. {
  3610. s3PLCSignal_Old["a3OEEType_left"] = 0;
  3611. }
  3612. #endregion 左工位 节拍
  3613. #region 右工位 节拍
  3614. if (stPLC_MesData.Right.iotData.beatAction > 0)
  3615. {
  3616. stationCode = "[OP32]";
  3617. stationName = "点散热胶装备2";
  3618. stationNameStr = stationCode + stationName;
  3619. int a3OEEType_right = Convert.ToInt32(s3PLCData["a3OEEType_right"]);
  3620. int a3OEETypeGOld_right = Convert.ToInt32(s3PLCSignal_Old["a3OEEType_right"]);
  3621. if (a3OEEType_right != a3OEETypeGOld_right)
  3622. {
  3623. s3PLCData["OEETypeFlag_right"] = "1";
  3624. }
  3625. else
  3626. {
  3627. s3PLCData["OEETypeFlag_right"] = "0";
  3628. }
  3629. if (s3PLCData["OEETypeFlag_right"].ToString() == "1" && (a3OEEType_right == 1 || a3OEEType_right == 3 || a3OEEType_right == 4 || a3OEEType_right == 5))
  3630. {
  3631. 通用节拍接口(plcNo, stationNameStr,
  3632. tagBaseName + ".Right." + tagiotComnName, CarrierBarcode_Right,
  3633. stPLC_MesData.Right.iotData, out res);
  3634. if (res == 1)
  3635. {
  3636. s3PLCSignal_Old["a3OEEType_right"] = a3OEEType_right;
  3637. }
  3638. else {
  3639. s3PLCSignal_Old["a3OEEType_right"] = 0;
  3640. }
  3641. }
  3642. }
  3643. else
  3644. {
  3645. s3PLCSignal_Old["a3OEEType_right"] = 0;
  3646. }
  3647. #endregion 右工位 节拍
  3648. }
  3649. catch (Exception ex)
  3650. {
  3651. string str = ex.StackTrace;
  3652. AddMessage_Station(stationNameStr, LogType.Error,
  3653. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3654. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3655. }
  3656. #endregion
  3657. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3658. stopwatch1.Stop();
  3659. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  3660. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3661. }
  3662. else
  3663. {
  3664. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3665. AddMessage_Station(stationNameStr, LogType.Info,
  3666. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3667. FunsEip[plcNo].Connect();
  3668. }
  3669. }
  3670. catch (Exception ex)
  3671. {
  3672. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3673. AddMessage_Station(stationNameStr, LogType.Error,
  3674. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3675. //Funs[plcNo].ReConnect();
  3676. }
  3677. Thread.Sleep(IntervalReadPLC);
  3678. }
  3679. }
  3680. /// <summary>
  3681. /// [S3] 点散热胶装备 - 进站
  3682. /// </summary>
  3683. /// <param name="plcNo">PLC编号</param>
  3684. /// <param name="stationNameStr">工站全称</param>
  3685. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  3686. string tagBarsetName, string direction, out bool ProgressState)
  3687. {
  3688. Stopwatch stopwatch1 = new Stopwatch();
  3689. Stopwatch stopwatch2 = new Stopwatch();
  3690. try
  3691. {
  3692. stopwatch1.Start();
  3693. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  3694. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3695. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  3696. string StationId = string.Empty;
  3697. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3698. bool pass = a1Result == 1;
  3699. string slot = "";
  3700. if (direction == "Left")
  3701. {
  3702. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  3703. slot = "01-SLOT-01";
  3704. }
  3705. if (direction == "Right")
  3706. {
  3707. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  3708. slot = "01-SLOT-02";
  3709. }
  3710. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3711. //载具码验证产品码
  3712. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3713. if (string.IsNullOrEmpty(strProductBarcode))
  3714. {
  3715. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3716. ProgressState = false;
  3717. Thread.Sleep(10000);
  3718. return;
  3719. }
  3720. sn = strProductBarcode;
  3721. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  3722. // 产品SN(物料码)校验
  3723. List<TestItem> item = new List<TestItem>();
  3724. stopwatch2.Start();
  3725. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3726. item, MachineId, StationId, pass, slot);
  3727. stopwatch2.Stop();
  3728. //指令执行结果 1:OK 110:失败
  3729. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3730. if (mesResultFrmWeb == 1)
  3731. {
  3732. if (a1Result == 1)
  3733. {
  3734. mesResultFrmWeb = 1;
  3735. }
  3736. else
  3737. {
  3738. mesResultFrmWeb = 110;
  3739. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3740. }
  3741. }
  3742. //进站结果写入PLC
  3743. CommandFromPLC resultToPlC = new CommandFromPLC();
  3744. resultToPlC.cmd = 0;
  3745. resultToPlC.cmdParam = 0; //指令参数
  3746. resultToPlC.cmdResult = mesResultFrmWeb;
  3747. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3748. }
  3749. catch (Exception ex)
  3750. {
  3751. string str = ex.StackTrace;
  3752. AddMessage(LogType.Error,
  3753. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3754. str.Length - str.LastIndexOf("\\") - 1));
  3755. CommandFromPLC resultToPlC = new CommandFromPLC();
  3756. resultToPlC.cmd = 0;
  3757. resultToPlC.cmdParam = 0; //指令参数
  3758. resultToPlC.cmdResult = 110;
  3759. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3760. }
  3761. stopwatch1.Stop();
  3762. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3763. AddMessage(LogType.Info,
  3764. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3765. stopwatch2.ElapsedMilliseconds + "ms");
  3766. ProgressState = false;
  3767. }
  3768. /// <summary>
  3769. /// [S3] 点散热胶装备 - 出站
  3770. /// </summary>
  3771. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  3772. string stationCode, string stationName, string direction, out bool ProgressState)
  3773. {
  3774. Stopwatch stopwatch1 = new Stopwatch();
  3775. Stopwatch stopwatch2 = new Stopwatch();
  3776. try
  3777. {
  3778. stopwatch1.Start();
  3779. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  3780. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3781. string processItem = stationName; // 测试项目
  3782. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3783. string supplierCode = ""; // 供应商代码
  3784. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3785. string batch_num = GlobalContext.BatchNumber; // 批次号
  3786. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3787. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3788. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3789. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  3790. string StationId = string.Empty;
  3791. if (direction == "Left")
  3792. {
  3793. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  3794. }
  3795. if (direction == "Right")
  3796. {
  3797. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  3798. }
  3799. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3800. bool pass = a1Result == 1;
  3801. //根据载具码获取产品码
  3802. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3803. if (string.IsNullOrEmpty(strProductBarcode))
  3804. {
  3805. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3806. ProgressState = false;
  3807. Thread.Sleep(10000);
  3808. return;
  3809. }
  3810. Console.WriteLine($"异常1:{strProductBarcode}");
  3811. sn = strProductBarcode;
  3812. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3813. List<TestItem> items = new List<TestItem>();
  3814. items.Add(new TestItem()
  3815. {
  3816. Parameter_name = "载具码",
  3817. Parameter_value = CarrierBarcode,
  3818. Parameter_unit = ""
  3819. });
  3820. items.Add(new TestItem()
  3821. {
  3822. Parameter_name = "产品码",
  3823. Parameter_value = sn,
  3824. Parameter_unit = ""
  3825. });
  3826. //if (direction == "Right")
  3827. //{
  3828. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData).Replace("null","0");
  3829. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3830. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  3831. MachineId, StationId, "", paramJson, direction);
  3832. //}
  3833. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3834. if (mesResultFrmWeb == 1)
  3835. {
  3836. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3837. if (mesResultFrmWeb == 110)
  3838. {
  3839. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  3840. }
  3841. }
  3842. stopwatch2.Start();
  3843. //进站结果写入PLC
  3844. CommandFromPLC resultToPlC = new CommandFromPLC();
  3845. resultToPlC.cmd = 0;
  3846. resultToPlC.cmdParam = 0; //指令参数
  3847. resultToPlC.cmdResult = mesResultFrmWeb;
  3848. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3849. stopwatch2.Stop();
  3850. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  3851. //保存PLC返回MES数据到本地
  3852. ResponseMessage message = new ResponseMessage();
  3853. if (direction == "Left")
  3854. {
  3855. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  3856. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  3857. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  3858. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  3859. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  3860. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  3861. if (message.result == false)
  3862. {
  3863. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3864. }
  3865. }
  3866. if (direction == "Right")
  3867. {
  3868. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  3869. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  3870. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  3871. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  3872. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  3873. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  3874. if (message.result == false)
  3875. {
  3876. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3877. }
  3878. }
  3879. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3880. }
  3881. catch (Exception ex)
  3882. {
  3883. stopwatch2.Start();
  3884. CommandFromPLC resultToPlC = new CommandFromPLC();
  3885. resultToPlC.cmd = 0;
  3886. resultToPlC.cmdParam = 0; //指令参数
  3887. resultToPlC.cmdResult = 110;
  3888. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3889. stopwatch2.Stop();
  3890. string str = ex.StackTrace;
  3891. AddMessage(LogType.Error,
  3892. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3893. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3894. }
  3895. stopwatch1.Stop();
  3896. AddMessage(LogType.Info,
  3897. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3898. stopwatch2.ElapsedMilliseconds + "ms");
  3899. ProgressState = false;
  3900. if (direction == "Left") uuid = "";
  3901. if (direction == "Right") uuid2 = "";
  3902. }
  3903. #endregion S3
  3904. #region S4
  3905. /// <summary>
  3906. /// [S4] 点胶检测设备
  3907. /// </summary>
  3908. /// <param name="plcNo">PLC编号</param>
  3909. private void ReadStation_S4(int plcNo)
  3910. {
  3911. string stationCode = "[OP40]";
  3912. string stationName = "胶线检测";
  3913. string stationNameStr = stationCode + stationName;
  3914. string tagBaseName = "g_OP40_MES"; //标签变量名称
  3915. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3916. string tagAgvCommName = "agvCommFrmPC";
  3917. string tagiotComnName = "iotData";
  3918. string tagBarsetName = "BarcodeSet";
  3919. string CarrierBarcode = "";
  3920. // 触发信号字典
  3921. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  3922. s4PLCSignal_Old.Add("a4OEEType", 0); // 节拍类型(plc写入)
  3923. // PLC数据字典 赋值
  3924. s4PLCData.Add("a4OEEType", 0); // 节拍类型(plc写入)
  3925. s4PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  3926. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  3927. (int, string) result;
  3928. while (true)
  3929. {
  3930. try
  3931. {
  3932. if (!GlobalContext._IsCon_Funs1)
  3933. {
  3934. UpdatePLCMonitor(1, plcNo, 0);
  3935. continue;
  3936. }
  3937. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3938. {
  3939. Stopwatch stopwatch1 = new Stopwatch();
  3940. Stopwatch stopwatch2 = new Stopwatch();
  3941. stopwatch1.Start();
  3942. stopwatch2.Start();
  3943. #region 一次性读取所有数据
  3944. // 一次性读取所有数据
  3945. result = FunsEip[plcNo]
  3946. .Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3947. if (result.Item1 != 0)
  3948. {
  3949. //richTextBox1.AppendText("\n" + strRet);
  3950. }
  3951. else
  3952. {
  3953. //去除扫码产生的特殊字符
  3954. stPLC_MesData.BarcodeSet.strProductBarcode =
  3955. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  3956. stPLC_MesData.BarcodeSet.strPartBarcode =
  3957. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  3958. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  3959. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  3960. stPLC_MesData.BarcodeSet.strPCBBarcode =
  3961. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  3962. //richTextBox1.AppendText("\n" + "读取成功");
  3963. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  3964. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  3965. ? XiaomiDeviceState.Unknown
  3966. : (XiaomiDeviceState)xmDeviceStateInt;
  3967. // 载具SN
  3968. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode;
  3969. // 节拍
  3970. s4PLCData["a4OEEType"] = stPLC_MesData.iotData.beatAction;
  3971. //报警信息
  3972. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  3973. }
  3974. #endregion 一次性读取所有数据
  3975. stopwatch2.Stop();
  3976. #region 进站
  3977. try
  3978. {
  3979. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3980. {
  3981. lock (lockObj)
  3982. {
  3983. if (!ProgressState)
  3984. {
  3985. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3986. ProgressState = true;
  3987. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData,
  3988. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  3989. out ProgressState));
  3990. }
  3991. }
  3992. }
  3993. }
  3994. catch (Exception ex)
  3995. {
  3996. ProgressState = false;
  3997. string str = ex.StackTrace;
  3998. AddMessage_Station(stationNameStr, LogType.Error,
  3999. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4000. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4001. }
  4002. #endregion 进站
  4003. #region 出站
  4004. try
  4005. {
  4006. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4007. {
  4008. lock (lockObj)
  4009. {
  4010. if (!ProgressState)
  4011. {
  4012. ProgressState = true;
  4013. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData,
  4014. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4015. out ProgressState));
  4016. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4017. }
  4018. }
  4019. }
  4020. }
  4021. catch (Exception ex)
  4022. {
  4023. string str = ex.StackTrace;
  4024. AddMessage_Station(stationNameStr, LogType.Error,
  4025. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4026. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4027. }
  4028. #endregion 出站
  4029. #region 节拍接口
  4030. try
  4031. {
  4032. if (stPLC_MesData.iotData.beatAction > 0)
  4033. {
  4034. int a4OEEType = Convert.ToInt32(s4PLCData["a4OEEType"]);
  4035. int a4OEETypeGOld = Convert.ToInt32(s4PLCSignal_Old["a4OEEType"]);
  4036. //若设备紧急复原后节拍重置
  4037. if (a4OEEType == 1)
  4038. {
  4039. a4OEETypeGOld = 0;
  4040. }
  4041. if (a4OEEType != a4OEETypeGOld)
  4042. {
  4043. s4PLCData["OEETypeFlag"] = "1";
  4044. }
  4045. else
  4046. {
  4047. s4PLCData["OEETypeFlag"] = "0";
  4048. }
  4049. if (s4PLCData["OEETypeFlag"].ToString() == "1" && (a4OEEType == 1 || a4OEEType == 3 || a4OEEType == 4 || a4OEEType == 5))
  4050. {
  4051. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  4052. if (res == 1)
  4053. {
  4054. s4PLCSignal_Old["a4OEEType"] = s4PLCData["a4OEEType"];
  4055. }
  4056. else
  4057. {
  4058. s4PLCSignal_Old["a4OEEType"] = 0;
  4059. }
  4060. }
  4061. }
  4062. else {
  4063. s4PLCSignal_Old["a4OEEType"] = 0;
  4064. }
  4065. }
  4066. catch (Exception ex)
  4067. {
  4068. string str = ex.StackTrace;
  4069. AddMessage_Station(stationNameStr, LogType.Error,
  4070. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4071. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4072. }
  4073. #endregion
  4074. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4075. stopwatch1.Stop();
  4076. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4077. }
  4078. else
  4079. {
  4080. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4081. AddMessage_Station(stationNameStr, LogType.Info,
  4082. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4083. FunsEip[plcNo].Connect(); // 重连
  4084. }
  4085. }
  4086. catch (Exception ex)
  4087. {
  4088. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4089. AddMessage_Station(stationNameStr, LogType.Error,
  4090. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4091. }
  4092. Thread.Sleep(IntervalReadPLC);
  4093. }
  4094. }
  4095. /// <summary>
  4096. /// [S4] 点胶检测设备 - 进站
  4097. /// </summary>
  4098. /// <param name="plcNo">PLC编号</param>
  4099. /// <param name="stationNameStr">工站全称</param>
  4100. /// <param name="stPLC_MesData"></param>
  4101. /// <param name="tagMesCommName"></param>
  4102. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  4103. string tagBarsetName, out bool ProgressState)
  4104. {
  4105. Stopwatch stopwatch1 = new Stopwatch();
  4106. Stopwatch stopwatch2 = new Stopwatch();
  4107. try
  4108. {
  4109. stopwatch1.Start();
  4110. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4111. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4112. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  4113. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  4114. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4115. bool pass = a1Result == 1;
  4116. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4117. //载具码验证产品码
  4118. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4119. if (string.IsNullOrEmpty(strProductBarcode))
  4120. {
  4121. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4122. ProgressState = false;
  4123. Thread.Sleep(10000);
  4124. return;
  4125. }
  4126. sn = strProductBarcode;
  4127. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4128. // 产品SN(物料码)校验
  4129. List<TestItem> item = new List<TestItem>();
  4130. stopwatch2.Start();
  4131. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  4132. item, MachineId, StationId, pass, "01-SLOT-01");
  4133. stopwatch2.Stop();
  4134. //指令执行结果 1:OK 110:失败
  4135. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4136. if (mesResultFrmWeb == 1)
  4137. {
  4138. if (a1Result == 1)
  4139. {
  4140. mesResultFrmWeb = 1;
  4141. }
  4142. else
  4143. {
  4144. mesResultFrmWeb = 110;
  4145. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  4146. }
  4147. }
  4148. //进站结果写入PLC
  4149. CommandFromPLC resultToPlC = new CommandFromPLC();
  4150. resultToPlC.cmd = 0;
  4151. resultToPlC.cmdParam = 0; //指令参数
  4152. resultToPlC.cmdResult = mesResultFrmWeb;
  4153. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4154. }
  4155. catch (Exception ex)
  4156. {
  4157. string str = ex.StackTrace;
  4158. AddMessage(LogType.Error,
  4159. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4160. str.Length - str.LastIndexOf("\\") - 1));
  4161. CommandFromPLC resultToPlC = new CommandFromPLC();
  4162. resultToPlC.cmd = 0;
  4163. resultToPlC.cmdParam = 0; //指令参数
  4164. resultToPlC.cmdResult = 110;
  4165. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4166. }
  4167. stopwatch1.Stop();
  4168. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4169. AddMessage(LogType.Info,
  4170. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4171. stopwatch2.ElapsedMilliseconds + "ms");
  4172. ProgressState = false;
  4173. }
  4174. /// <summary>
  4175. /// [S4] 点胶检测设备 - 出站接口
  4176. /// </summary>
  4177. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  4178. string stationCode, string stationName, out bool ProgressState)
  4179. {
  4180. Stopwatch stopwatch1 = new Stopwatch();
  4181. Stopwatch stopwatch2 = new Stopwatch();
  4182. try
  4183. {
  4184. stopwatch1.Start();
  4185. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4186. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4187. string processItem = stationName; // 测试项目
  4188. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4189. string supplierCode = ""; // 供应商代码
  4190. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4191. string batch_num = GlobalContext.BatchNumber; // 批次号
  4192. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4193. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4194. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4195. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  4196. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  4197. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4198. bool pass = a1Result == 1;
  4199. //根据载具码获取产品码
  4200. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4201. if (string.IsNullOrEmpty(strProductBarcode))
  4202. {
  4203. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4204. ProgressState = false;
  4205. Thread.Sleep(10000);
  4206. return;
  4207. }
  4208. sn = strProductBarcode;
  4209. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4210. List<TestItem> items = new List<TestItem>();
  4211. items.Add(new TestItem()
  4212. {
  4213. Parameter_name = "载具码",
  4214. Parameter_value = CarrierBarcode,
  4215. Parameter_unit = ""
  4216. });
  4217. items.Add(new TestItem()
  4218. {
  4219. Parameter_name = "产品码",
  4220. Parameter_value = sn,
  4221. Parameter_unit = ""
  4222. });
  4223. #region 上传图片
  4224. if (GlobalContext.MQTTIsSendUpFile)
  4225. {
  4226. string[] urlarry = GlobalContext.UpFilePath.Split(",");
  4227. fileUploadData.fileData.Clear();
  4228. foreach (var item in urlarry)
  4229. {
  4230. if (!string.IsNullOrEmpty(item))
  4231. {
  4232. //上传图片
  4233. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName, a1Result,
  4234. item, uuid).Result;
  4235. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  4236. }
  4237. }
  4238. }
  4239. #endregion
  4240. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4241. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4242. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode,
  4243. "01-SLOT-01", MachineId, StationId, "", paramJson);
  4244. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4245. if (mesResultFrmWeb == 1)
  4246. {
  4247. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  4248. if (mesResultFrmWeb == 110)
  4249. {
  4250. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  4251. }
  4252. }
  4253. stopwatch2.Start();
  4254. //进站结果写入PLC
  4255. CommandFromPLC resultToPlC = new CommandFromPLC();
  4256. resultToPlC.cmd = 0;
  4257. resultToPlC.cmdParam = 0; //指令参数
  4258. resultToPlC.cmdResult = mesResultFrmWeb;
  4259. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4260. stopwatch2.Stop();
  4261. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4262. //保存PLC返回MES数据到本地
  4263. ResponseMessage message = new ResponseMessage();
  4264. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  4265. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  4266. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  4267. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  4268. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  4269. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  4270. if (message.result == false)
  4271. {
  4272. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4273. }
  4274. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4275. }
  4276. catch (Exception ex)
  4277. {
  4278. stopwatch2.Start();
  4279. CommandFromPLC resultToPlC = new CommandFromPLC();
  4280. resultToPlC.cmd = 0;
  4281. resultToPlC.cmdParam = 0; //指令参数
  4282. resultToPlC.cmdResult = 110;
  4283. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4284. stopwatch2.Stop();
  4285. string str = ex.StackTrace;
  4286. AddMessage(LogType.Error,
  4287. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4288. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4289. }
  4290. stopwatch1.Stop();
  4291. AddMessage(LogType.Info,
  4292. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4293. stopwatch2.ElapsedMilliseconds + "ms");
  4294. ProgressState = false;
  4295. uuid = "";
  4296. }
  4297. #endregion
  4298. #region S5
  4299. private static bool isPCBStation = false; //控制PCB是否进出站的标识
  4300. /// <summary>
  4301. /// [S5] 点胶检测设备
  4302. /// </summary>
  4303. /// <param name="plcNo">PLC编号</param>
  4304. private void ReadStation_S5(int plcNo)
  4305. {
  4306. string stationCode = "[OP50]";
  4307. string stationName = "ADD板上料组装装备";
  4308. string stationNameStr = stationCode + stationName;
  4309. string tagBaseName = "g_OP50_MES"; //标签变量名称
  4310. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4311. string tagAgvCommName = "agvCommFrmPC";
  4312. string tagiotComnName = "iotData";
  4313. string tagBarsetName = "BarcodeSet";
  4314. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  4315. string CarrierBarcode = "";
  4316. // 触发信号字典
  4317. s5PLCSignal_Old.Add("a5OEEType", 0); // 节拍类型(plc写入)
  4318. // PLC数据字典 赋值
  4319. s5PLCData.Add("a5OEEType", 0); // 节拍类型(plc写入)
  4320. s5PLCData.Add("OEETypeFlag", 0); // 节拍标识 0 不上传 ,1 上传
  4321. (int, string) result;
  4322. while (true)
  4323. {
  4324. try
  4325. {
  4326. if (!GlobalContext._IsCon_Funs1)
  4327. {
  4328. UpdatePLCMonitor(1, plcNo, 0);
  4329. continue;
  4330. }
  4331. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4332. {
  4333. Stopwatch stopwatch1 = new Stopwatch();
  4334. Stopwatch stopwatch2 = new Stopwatch();
  4335. stopwatch1.Start();
  4336. stopwatch2.Start();
  4337. #region 一次性读取所有数据
  4338. // 一次性读取所有数据
  4339. result = FunsEip[plcNo]
  4340. .Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4341. if (result.Item1 != 0)
  4342. {
  4343. }
  4344. else
  4345. {
  4346. //测试数据
  4347. //stPLC_MesData.mesCommFrmPLC.cmd = 2;
  4348. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A235461";
  4349. //stPLC_MesData.BarcodeSet.strPCBBarcode = "A1507V000239";
  4350. //stPLC_MesData.iotData.beatAction = 1;
  4351. //stPLC_MesData.iotData.beatAction = 2;
  4352. //stPLC_MesData.iotData.beatAction = 3;
  4353. //stPLC_MesData.iotData.beatAction = 4;
  4354. //stPLC_MesData.iotData.beatAction = 5;
  4355. //stPLC_MesData.iotData.beatAction = 6;
  4356. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
  4357. #region 去除扫码产生的特殊字符
  4358. stPLC_MesData.BarcodeSet.strProductBarcode =
  4359. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  4360. stPLC_MesData.BarcodeSet.strPartBarcode =
  4361. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  4362. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  4363. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  4364. stPLC_MesData.BarcodeSet.strPCBBarcode =
  4365. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  4366. #endregion
  4367. //richTextBox1.AppendText("\n" + "读取成功");
  4368. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  4369. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  4370. ? XiaomiDeviceState.Unknown
  4371. : (XiaomiDeviceState)xmDeviceStateInt;
  4372. // 节拍
  4373. s5PLCData["a5OEEType"] = stPLC_MesData.iotData.beatAction;
  4374. //载具码
  4375. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode.ToString();
  4376. //报警信息
  4377. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  4378. }
  4379. #endregion 一次性读取所有数据
  4380. stopwatch2.Stop();
  4381. #region 进站
  4382. try
  4383. {
  4384. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4385. {
  4386. lock (lockObj)
  4387. {
  4388. if (!ProgressState)
  4389. {
  4390. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  4391. ProgressState = true;
  4392. string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
  4393. if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
  4394. {
  4395. ProgressState = true;
  4396. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData,
  4397. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  4398. out ProgressState));
  4399. }
  4400. }
  4401. }
  4402. }
  4403. }
  4404. catch (Exception ex)
  4405. {
  4406. ProgressState = false;
  4407. string str = ex.StackTrace;
  4408. AddMessage_Station(stationNameStr, LogType.Error,
  4409. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4410. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4411. }
  4412. #endregion 进站
  4413. #region 出站
  4414. try
  4415. {
  4416. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4417. {
  4418. lock (lockObj)
  4419. {
  4420. if (!ProgressState)
  4421. {
  4422. ProgressState = true;
  4423. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData,
  4424. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4425. out ProgressState));
  4426. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4427. }
  4428. }
  4429. }
  4430. }
  4431. catch (Exception ex)
  4432. {
  4433. ProgressState = false;
  4434. string str = ex.StackTrace;
  4435. AddMessage_Station(stationNameStr, LogType.Error,
  4436. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4437. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4438. }
  4439. #endregion 出站
  4440. #region 节拍接口
  4441. try
  4442. {
  4443. if (stPLC_MesData.iotData.beatAction > 0)
  4444. {
  4445. int a5OEEType = Convert.ToInt32(s5PLCData["a5OEEType"]);
  4446. int a5OEETypeGOld = Convert.ToInt32(s5PLCSignal_Old["a5OEEType"]);
  4447. if (a5OEEType != a5OEETypeGOld)
  4448. {
  4449. s5PLCData["OEETypeFlag"] = "1";
  4450. }
  4451. else
  4452. {
  4453. s5PLCData["OEETypeFlag"] = "0";
  4454. }
  4455. if (s5PLCData["OEETypeFlag"].ToString() == "1" && (a5OEEType == 1 || a5OEEType == 3 || a5OEEType == 4 || a5OEEType == 5))
  4456. {
  4457. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  4458. if (res == 1)
  4459. {
  4460. s5PLCSignal_Old["a5OEEType"] = s5PLCData["a5OEEType"];
  4461. }
  4462. else {
  4463. s5PLCSignal_Old["a5OEEType"] = 0;
  4464. }
  4465. }
  4466. }
  4467. else {
  4468. s5PLCSignal_Old["a5OEEType"] = 0;
  4469. }
  4470. }
  4471. catch (Exception ex)
  4472. {
  4473. string str = ex.StackTrace;
  4474. AddMessage_Station(stationNameStr, LogType.Error,
  4475. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4476. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4477. }
  4478. #endregion
  4479. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4480. stopwatch1.Stop();
  4481. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4482. }
  4483. else
  4484. {
  4485. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4486. AddMessage_Station(stationNameStr, LogType.Info,
  4487. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4488. FunsEip[plcNo].Connect(); // 重连
  4489. }
  4490. }
  4491. catch (Exception ex)
  4492. {
  4493. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4494. AddMessage_Station(stationNameStr, LogType.Error,
  4495. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4496. }
  4497. Thread.Sleep(IntervalReadPLC);
  4498. }
  4499. }
  4500. /// <summary>
  4501. /// [S5] 点胶检测设备 - 进站
  4502. /// </summary>
  4503. /// <param name="plcNo">PLC编号</param>
  4504. /// <param name="stationNameStr">工站全称</param>
  4505. /// <param name="stPLC_MesData"></param>
  4506. /// <param name="tagMesCommName"></param>
  4507. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  4508. string tagBarsetName, out bool ProgressState)
  4509. {
  4510. Stopwatch stopwatch1 = new Stopwatch();
  4511. Stopwatch stopwatch2 = new Stopwatch();
  4512. try
  4513. {
  4514. stopwatch1.Start();
  4515. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4516. //string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4517. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  4518. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  4519. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  4520. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码
  4521. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  4522. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4523. bool pass = a1Result == 1;
  4524. AddMessage(LogType.Info, $"ADD板编码(PCB码):{pcbBarcode}");
  4525. //绑定载具和产品
  4526. //ResponseMessage message = new ResponseMessage();
  4527. //message = SQLHelper.PCBCarrierBind(strCarrierBarcode, pcbBarcode);
  4528. //if (message.result == false)
  4529. //{
  4530. // AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  4531. // ProgressState = false;
  4532. // Thread.Sleep(10000);
  4533. // return;
  4534. //}
  4535. //载具码验证产品码 //载具码验证产品码
  4536. //string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4537. //if (string.IsNullOrEmpty(strProductBarcode))
  4538. //{
  4539. // AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4540. //}
  4541. //sn = strProductBarcode;
  4542. //AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4543. // 产品SN(物料码)校验
  4544. List<TestItem> item = new List<TestItem>();
  4545. stopwatch2.Start();
  4546. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  4547. pcbBarcode,
  4548. item, MachineId, StationId, pass, "01-SLOT-01");
  4549. stopwatch2.Stop();
  4550. //指令执行结果 1:OK 110:失败
  4551. byte mesResultFrmWeb = (byte)(result == 1 ? 2 : 120);
  4552. if (mesResultFrmWeb == 1)
  4553. {
  4554. if (a1Result == 1)
  4555. {
  4556. mesResultFrmWeb = 2;
  4557. }
  4558. else
  4559. {
  4560. mesResultFrmWeb = 120;
  4561. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  4562. }
  4563. }
  4564. //进站结果写入PLC
  4565. CommandFromPLC resultToPlC = new CommandFromPLC();
  4566. resultToPlC.cmd = 0;
  4567. resultToPlC.cmdParam = 0; //指令参数
  4568. resultToPlC.cmdResult = mesResultFrmWeb;
  4569. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4570. }
  4571. catch (Exception ex)
  4572. {
  4573. string str = ex.StackTrace;
  4574. AddMessage(LogType.Error,
  4575. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4576. str.Length - str.LastIndexOf("\\") - 1));
  4577. CommandFromPLC resultToPlC = new CommandFromPLC();
  4578. resultToPlC.cmd = 0;
  4579. resultToPlC.cmdParam = 0; //指令参数
  4580. resultToPlC.cmdResult = 120;
  4581. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4582. }
  4583. stopwatch1.Stop();
  4584. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4585. AddMessage(LogType.Info,
  4586. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4587. stopwatch2.ElapsedMilliseconds + "ms");
  4588. ProgressState = false;
  4589. }
  4590. /// <summary>
  4591. /// [S5] 点胶检测设备 - 出站接口
  4592. /// </summary>
  4593. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  4594. string stationCode, string stationName, out bool ProgressState)
  4595. {
  4596. Stopwatch stopwatch1 = new Stopwatch();
  4597. Stopwatch stopwatch2 = new Stopwatch();
  4598. try
  4599. {
  4600. stopwatch1.Start();
  4601. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4602. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4603. string processItem = stationName; // 测试项目
  4604. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4605. string supplierCode = ""; // 供应商代码
  4606. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4607. string batch_num = GlobalContext.BatchNumber; // 批次号
  4608. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4609. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4610. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 部件条码;
  4611. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4612. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  4613. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  4614. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  4615. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4616. bool pass = a1Result == 1;
  4617. CommandFromPLC resultToPlC = new CommandFromPLC();
  4618. //根据载具码获取产品码
  4619. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4620. if (string.IsNullOrEmpty(strProductBarcode))
  4621. {
  4622. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4623. ProgressState = false;
  4624. Thread.Sleep(10000);
  4625. return;
  4626. }
  4627. stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
  4628. sn = strProductBarcode;
  4629. //数据库绑定载具和PCB
  4630. ResponseMessage message = new ResponseMessage();
  4631. message = SQLHelper.PCBCarrierBind(CarrierBarcode, pcbBarcode);
  4632. if (message.result == false)
  4633. {
  4634. AddMessage(LogType.Error, stationNameStr + "_PCB码数据库绑定失败,错误:" + message.text);
  4635. ProgressState = true; //防止循环报错
  4636. return;
  4637. }
  4638. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn};PCB码:{pcbBarcode}");
  4639. List<TestItem> items = new List<TestItem>();
  4640. items.Add(new TestItem()
  4641. {
  4642. Parameter_name = "载具码",
  4643. Parameter_value = CarrierBarcode,
  4644. Parameter_unit = ""
  4645. });
  4646. items.Add(new TestItem()
  4647. {
  4648. Parameter_name = "产品码",
  4649. Parameter_value = sn,
  4650. Parameter_unit = ""
  4651. });
  4652. items.Add(new TestItem()
  4653. {
  4654. Parameter_name = "PCB码",
  4655. Parameter_value = pcbBarcode,
  4656. Parameter_unit = ""
  4657. });
  4658. #region 上传图片
  4659. if (GlobalContext.MQTTIsSendUpFile)
  4660. {
  4661. string[] urlarry = GlobalContext.UpFilePath.Split(",");
  4662. fileUploadData.fileData.Clear();
  4663. foreach (var item in urlarry)
  4664. {
  4665. if (!string.IsNullOrEmpty(item))
  4666. {
  4667. //上传图片
  4668. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName, a1Result,
  4669. item, uuid).Result;
  4670. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  4671. }
  4672. }
  4673. }
  4674. #endregion
  4675. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4676. int result1 = 0;
  4677. byte mesResultFrmWeb = 0;
  4678. if (stPLC_MesData.mesCommFrmPLC.cmdParam == 2)
  4679. {
  4680. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem, workorder_code,
  4681. batch_num
  4682. , mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId,
  4683. PartBarcode, paramJson);
  4684. }
  4685. else if (stPLC_MesData.mesCommFrmPLC.cmdParam == 1)
  4686. {
  4687. result1 = PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  4688. }
  4689. mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4690. //进站结果写入PLC
  4691. resultToPlC.cmd = 0;
  4692. resultToPlC.cmdParam = 0; //指令参数
  4693. resultToPlC.cmdResult = mesResultFrmWeb;
  4694. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4695. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4696. //保存PLC返回MES数据到本地
  4697. //ResponseMessage message = new ResponseMessage();
  4698. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  4699. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB,
  4700. stPLC_MesData.mesData.nRemainCount, "");
  4701. if (message.result == false)
  4702. {
  4703. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4704. }
  4705. //保存部件码信息
  4706. if (!string.IsNullOrEmpty(PartBarcode))
  4707. {
  4708. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  4709. if (message.result == false)
  4710. {
  4711. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  4712. }
  4713. }
  4714. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4715. }
  4716. catch (Exception ex)
  4717. {
  4718. stopwatch2.Start();
  4719. CommandFromPLC resultToPlC = new CommandFromPLC();
  4720. resultToPlC.cmd = 0;
  4721. resultToPlC.cmdParam = 0; //指令参数
  4722. resultToPlC.cmdResult = 110;
  4723. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4724. stopwatch2.Stop();
  4725. string str = ex.StackTrace;
  4726. AddMessage(LogType.Error,
  4727. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4728. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4729. }
  4730. stopwatch1.Stop();
  4731. AddMessage(LogType.Info,
  4732. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4733. stopwatch2.ElapsedMilliseconds + "ms");
  4734. ProgressState = false;
  4735. uuid = "";
  4736. }
  4737. private int S5_PCB进出站(OP50_MesData_t stPLC_MesData, int plcNo, string stationNameStr, string tagBaseName,
  4738. string tagMesCommName)
  4739. {
  4740. string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
  4741. if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
  4742. {
  4743. string strProductBarcode =
  4744. SQLHelper.GetProductBarcodeByCarrierCode(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  4745. stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
  4746. CommandFromPLC resultToPlC = new CommandFromPLC();
  4747. resultToPlC.cmd = 0;
  4748. resultToPlC.cmdParam = 0; //指令参数
  4749. if (GlobalContext.IsSendStationIn)
  4750. {
  4751. #region 进站
  4752. //int res1 = PCBStationInData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  4753. //if (res1 == 1)
  4754. //{
  4755. // resultToPlC.cmdResult = 2;//OK
  4756. // WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  4757. //}
  4758. //else
  4759. //{
  4760. // resultToPlC.cmdResult = 120;
  4761. // WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  4762. // return 2;
  4763. //}
  4764. #endregion
  4765. #region 出站
  4766. int res2 = PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  4767. if (res2 == 1)
  4768. {
  4769. resultToPlC.cmdResult = 2; //OK
  4770. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  4771. return 1;
  4772. }
  4773. else
  4774. {
  4775. resultToPlC.cmdResult = 120;
  4776. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  4777. return 2;
  4778. }
  4779. #endregion
  4780. }
  4781. else
  4782. {
  4783. return 2;
  4784. }
  4785. }
  4786. else
  4787. {
  4788. return 2;
  4789. }
  4790. }
  4791. #endregion
  4792. #region S6
  4793. private Dictionary<string, object> s6PLCData = new Dictionary<string, object>();
  4794. private Dictionary<string, object> s6PLCSignal_Old = new Dictionary<string, object>();
  4795. /// <summary>
  4796. /// [S6] 顶盖装配设备
  4797. /// </summary>
  4798. /// <param name="plcNo">PLC编号</param>
  4799. public void ReadStation_S6(int plcNo)
  4800. {
  4801. string stationCode = "[OP70]";
  4802. string stationName = "组上盖板";
  4803. string stationNameStr = stationCode + stationName;
  4804. string tagBaseName = "g_OP60_MES"; //标签变量名称
  4805. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4806. string tagAgvCommName = "agvCommFrmPC";
  4807. string tagiotComnName = "iotData";
  4808. string tagBarsetName = "BarcodeSet";
  4809. string CarrierBarcode = "";
  4810. // 触发信号字典
  4811. s6PLCSignal_Old.Add("a6OEEType", 0); // 节拍类型(plc写入)
  4812. // PLC数据字典 赋值
  4813. s6PLCData.Add("a6OEEType", 0); // 节拍类型(plc写入)
  4814. s6PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  4815. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  4816. (int, string) result;
  4817. while (true)
  4818. {
  4819. try
  4820. {
  4821. if (!GlobalContext._IsCon_Funs1)
  4822. {
  4823. UpdatePLCMonitor(1, plcNo, 0);
  4824. continue;
  4825. }
  4826. if (StopWhile)
  4827. {
  4828. continue;
  4829. }
  4830. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4831. {
  4832. Stopwatch stopwatch1 = new Stopwatch();
  4833. Stopwatch stopwatch2 = new Stopwatch();
  4834. stopwatch1.Start();
  4835. stopwatch2.Start();
  4836. #region 一次性读取所有数据
  4837. // 一次性读取所有数据
  4838. result = FunsEip[plcNo]
  4839. .Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4840. if (result.Item1 != 0)
  4841. {
  4842. //richTextBox1.AppendText("\n" + strRet);
  4843. }
  4844. else
  4845. {
  4846. //测试
  4847. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
  4848. //stPLC_MesData.mesCommFrmPLC.cmd = 1;
  4849. //去除扫码产生的特殊字符
  4850. stPLC_MesData.BarcodeSet.strProductBarcode =
  4851. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  4852. stPLC_MesData.BarcodeSet.strPartBarcode =
  4853. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  4854. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  4855. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  4856. stPLC_MesData.BarcodeSet.strPCBBarcode =
  4857. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  4858. //richTextBox1.AppendText("\n" + "读取成功");
  4859. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  4860. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  4861. ? XiaomiDeviceState.Unknown
  4862. : (XiaomiDeviceState)xmDeviceStateInt;
  4863. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  4864. s6PLCData["a6OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  4865. //报警信息
  4866. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  4867. }
  4868. #endregion 一次性读取所有数据
  4869. stopwatch2.Stop();
  4870. #region 进站
  4871. try
  4872. {
  4873. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4874. {
  4875. lock (lockObj)
  4876. {
  4877. if (!ProgressState)
  4878. {
  4879. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  4880. ProgressState = true;
  4881. //载具码验证产品码
  4882. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData,
  4883. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  4884. out ProgressState));
  4885. }
  4886. }
  4887. }
  4888. }
  4889. catch (Exception ex)
  4890. {
  4891. ProgressState = false;
  4892. string str = ex.StackTrace;
  4893. AddMessage_Station(stationNameStr, LogType.Error,
  4894. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4895. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4896. }
  4897. #endregion 进站
  4898. #region 出站
  4899. try
  4900. {
  4901. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4902. {
  4903. lock (lockObj)
  4904. {
  4905. if (!ProgressState)
  4906. {
  4907. ProgressState = true;
  4908. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData,
  4909. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4910. out ProgressState));
  4911. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4912. }
  4913. }
  4914. }
  4915. }
  4916. catch (Exception ex)
  4917. {
  4918. ProgressState = false;
  4919. string str = ex.StackTrace;
  4920. AddMessage_Station(stationNameStr, LogType.Error,
  4921. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4922. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4923. }
  4924. #endregion 出站
  4925. #region 节拍接口
  4926. try
  4927. {
  4928. if (stPLC_MesData.iotData.beatAction > 0)
  4929. {
  4930. int a6OEEType = Convert.ToInt32(s6PLCData["a6OEEType"]);
  4931. int a6OEETypeGOld = Convert.ToInt32(s6PLCSignal_Old["a6OEEType"]);
  4932. if (a6OEEType != a6OEETypeGOld)
  4933. {
  4934. s6PLCData["OEETypeFlag"] = "1";
  4935. }
  4936. else
  4937. {
  4938. s6PLCData["OEETypeFlag"] = "0";
  4939. }
  4940. if (s6PLCData["OEETypeFlag"].ToString() == "1" && (a6OEEType == 1 || a6OEEType == 3 || a6OEEType == 4 || a6OEEType == 5))
  4941. {
  4942. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  4943. if (res == 1)
  4944. {
  4945. s6PLCSignal_Old["a6OEEType"] = s6PLCData["a6OEEType"];
  4946. }
  4947. else
  4948. {
  4949. s6PLCSignal_Old["a6OEEType"] = 0;
  4950. }
  4951. }
  4952. }
  4953. else {
  4954. s6PLCSignal_Old["a6OEEType"] = 0;
  4955. }
  4956. }
  4957. catch (Exception ex)
  4958. {
  4959. string str = ex.StackTrace;
  4960. AddMessage_Station(stationNameStr, LogType.Error,
  4961. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4962. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4963. }
  4964. #endregion
  4965. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4966. stopwatch1.Stop();
  4967. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4968. }
  4969. else
  4970. {
  4971. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4972. AddMessage_Station(stationNameStr, LogType.Info,
  4973. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4974. FunsEip[plcNo].Connect(); // 重连
  4975. }
  4976. }
  4977. catch (Exception ex)
  4978. {
  4979. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4980. AddMessage_Station(stationNameStr, LogType.Error,
  4981. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4982. }
  4983. Thread.Sleep(IntervalReadPLC);
  4984. }
  4985. }
  4986. /// <summary>
  4987. /// [S6] 顶盖装配设备 - 进站
  4988. /// </summary>
  4989. /// <param name="plcNo">PLC编号</param>
  4990. /// <param name="stationNameStr">工站全称</param>
  4991. /// <param name="stPLC_MesData"></param>
  4992. /// <param name="tagMesCommName"></param>
  4993. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  4994. string tagBarsetName, out bool ProgressState)
  4995. {
  4996. Stopwatch stopwatch1 = new Stopwatch();
  4997. Stopwatch stopwatch2 = new Stopwatch();
  4998. try
  4999. {
  5000. stopwatch1.Start();
  5001. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  5002. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5003. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  5004. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  5005. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5006. bool pass = a1Result == 1;
  5007. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  5008. string ProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  5009. string PCBBarcode = SQLHelper.GetPCBBarcodeByCarrierCode(strCarrierBarcode);
  5010. //strCarrierBarcode = "N801A-003";
  5011. //载具码验证产品码
  5012. if (string.IsNullOrEmpty(ProductBarcode))
  5013. {
  5014. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5015. ProgressState = false;
  5016. Thread.Sleep(10000);
  5017. return;
  5018. }
  5019. sn = ProductBarcode;
  5020. if (OpenDailogFalg)
  5021. {
  5022. using (var dialog = new BandBarodeDialog(strCarrierBarcode, ProductBarcode, PCBBarcode))
  5023. {
  5024. var rs = dialog.ShowDialog();
  5025. if (rs == DialogResult.OK)
  5026. {
  5027. AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode}");
  5028. OpenDailogFalg = false; //关闭扫码
  5029. StopWhile = false;//开启while循环
  5030. }
  5031. else
  5032. {
  5033. ProgressState = false;
  5034. return;
  5035. }
  5036. }
  5037. }
  5038. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5039. // 产品SN(物料码)校验
  5040. List<TestItem> item = new List<TestItem>();
  5041. stopwatch2.Start();
  5042. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  5043. item, MachineId, StationId, pass, "01-SLOT-01");
  5044. stopwatch2.Stop();
  5045. //指令执行结果 1:OK 110:失败
  5046. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5047. if (mesResultFrmWeb == 1)
  5048. {
  5049. if (a1Result == 1)
  5050. {
  5051. mesResultFrmWeb = 1;
  5052. }
  5053. else
  5054. {
  5055. mesResultFrmWeb = 110;
  5056. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  5057. }
  5058. }
  5059. //进站结果写入PLC
  5060. CommandFromPLC resultToPlC = new CommandFromPLC();
  5061. resultToPlC.cmd = 0;
  5062. resultToPlC.cmdParam = 0; //指令参数
  5063. resultToPlC.cmdResult = mesResultFrmWeb;
  5064. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5065. }
  5066. catch (Exception ex)
  5067. {
  5068. string str = ex.StackTrace;
  5069. AddMessage(LogType.Error,
  5070. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  5071. str.Length - str.LastIndexOf("\\") - 1));
  5072. CommandFromPLC resultToPlC = new CommandFromPLC();
  5073. resultToPlC.cmd = 0;
  5074. resultToPlC.cmdParam = 0; //指令参数
  5075. resultToPlC.cmdResult = 110;
  5076. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5077. }
  5078. stopwatch1.Stop();
  5079. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  5080. AddMessage(LogType.Info,
  5081. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5082. stopwatch2.ElapsedMilliseconds + "ms");
  5083. ProgressState = false;
  5084. }
  5085. /// <summary>
  5086. /// [S6] 顶盖装配设备 - 出站接口
  5087. /// </summary>
  5088. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  5089. string stationCode, string stationName, out bool ProgressState)
  5090. {
  5091. Stopwatch stopwatch1 = new Stopwatch();
  5092. Stopwatch stopwatch2 = new Stopwatch();
  5093. try
  5094. {
  5095. stopwatch1.Start();
  5096. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  5097. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5098. string processItem = stationName; // 测试项目
  5099. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5100. string supplierCode = ""; // 供应商代码
  5101. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5102. string batch_num = GlobalContext.BatchNumber; // 批次号
  5103. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5104. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5105. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5106. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  5107. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  5108. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5109. bool pass = a1Result == 1;
  5110. //根据载具码获取产品码
  5111. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5112. if (string.IsNullOrEmpty(strProductBarcode))
  5113. {
  5114. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5115. ProgressState = false;
  5116. Thread.Sleep(10000);
  5117. return;
  5118. }
  5119. sn = strProductBarcode;
  5120. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  5121. List<TestItem> items = new List<TestItem>();
  5122. items.Add(new TestItem()
  5123. {
  5124. Parameter_name = "载具码",
  5125. Parameter_value = CarrierBarcode,
  5126. Parameter_unit = ""
  5127. });
  5128. items.Add(new TestItem()
  5129. {
  5130. Parameter_name = "产品码",
  5131. Parameter_value = sn,
  5132. Parameter_unit = ""
  5133. });
  5134. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  5135. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  5136. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  5137. MachineId, StationId, "", paramJson);
  5138. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5139. if (mesResultFrmWeb == 1)
  5140. {
  5141. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  5142. if (mesResultFrmWeb==110)
  5143. {
  5144. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  5145. }
  5146. }
  5147. stopwatch2.Start();
  5148. //进站结果写入PLC
  5149. CommandFromPLC resultToPlC = new CommandFromPLC();
  5150. resultToPlC.cmd = 0;
  5151. resultToPlC.cmdParam = 0; //指令参数
  5152. resultToPlC.cmdResult = mesResultFrmWeb;
  5153. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5154. stopwatch2.Stop();
  5155. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  5156. //保存PLC返回MES数据到本地
  5157. ResponseMessage message = new ResponseMessage();
  5158. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  5159. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  5160. }
  5161. catch (Exception ex)
  5162. {
  5163. stopwatch2.Start();
  5164. CommandFromPLC resultToPlC = new CommandFromPLC();
  5165. resultToPlC.cmd = 0;
  5166. resultToPlC.cmdParam = 0; //指令参数
  5167. resultToPlC.cmdResult = 110;
  5168. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5169. stopwatch2.Stop();
  5170. string str = ex.StackTrace;
  5171. AddMessage(LogType.Error,
  5172. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5173. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5174. }
  5175. stopwatch1.Stop();
  5176. AddMessage(LogType.Info,
  5177. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5178. stopwatch2.ElapsedMilliseconds + "ms");
  5179. ProgressState = false;
  5180. uuid = "";
  5181. OpenDailogFalg = true; //开启下一个物料的扫码
  5182. }
  5183. #endregion
  5184. #region S7
  5185. private Dictionary<string, object> s7PLCSignal_Old = new Dictionary<string, object>();
  5186. private Dictionary<string, object> s7PLCData = new Dictionary<string, object>();
  5187. /// <summary>
  5188. /// [S7] 锁螺丝设备
  5189. /// </summary>
  5190. /// <param name="plcNo">PLC编号</param>
  5191. private void ReadStation_S7(int plcNo)
  5192. {
  5193. string stationCode = "[OP80]";
  5194. string stationName = "上盖板锁螺丝";
  5195. string stationNameStr = stationCode + stationName;
  5196. string tagBaseName = "g_OP70_MES"; //标签变量名称
  5197. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5198. string tagAgvCommName = "agvCommFrmPC";
  5199. string tagBarsetName = "BarcodeSet";
  5200. string tagiotComnName = "iotData";
  5201. string tagScrewDataset = "screwDataset";
  5202. string CarrierBarcode_Left = "";
  5203. string CarrierBarcode_Right = "";
  5204. s7PLCSignal_Old.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
  5205. s7PLCSignal_Old.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
  5206. // PLC数据字典 赋值
  5207. s7PLCData.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
  5208. s7PLCData.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
  5209. s5PLCData.Add("OEETypeFlag_left", 0); // 节拍标识 0 不上传 ,1 上传
  5210. s5PLCData.Add("OEETypeFlag_right", 0); // 节拍标识 0 不上传 ,1 上传
  5211. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  5212. (int, string) result;
  5213. AtlasScrew atlasScrewLeft = new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort,
  5214. 3000, 3000, "Left");
  5215. atlasScrewLeft.Initial();
  5216. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort,
  5217. 3000, 3000, "Right");
  5218. atlasScrewRight.Initial();
  5219. while (true)
  5220. {
  5221. try
  5222. {
  5223. if (!GlobalContext._IsCon_Funs1)
  5224. {
  5225. UpdatePLCMonitor(1, plcNo, 0);
  5226. continue;
  5227. }
  5228. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5229. {
  5230. Stopwatch stopwatch1 = new Stopwatch();
  5231. Stopwatch stopwatch2 = new Stopwatch();
  5232. stopwatch1.Start();
  5233. stopwatch2.Start();
  5234. #region 一次性读取所有数据
  5235. // 一次性读取所有数据
  5236. result = FunsEip[plcNo]
  5237. .Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  5238. if (result.Item1 != 0)
  5239. {
  5240. //richTextBox1.AppendText("\n" + strRet);
  5241. }
  5242. else
  5243. {
  5244. #region 去除扫码产生的特殊字符
  5245. stPLC_MesData.Left.BarcodeSet.strProductBarcode =
  5246. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strProductBarcode);
  5247. stPLC_MesData.Left.BarcodeSet.strPartBarcode =
  5248. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPartBarcode);
  5249. stPLC_MesData.Left.BarcodeSet.strCarrierBarcode =
  5250. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strCarrierBarcode);
  5251. stPLC_MesData.Left.BarcodeSet.strPCBBarcode =
  5252. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPCBBarcode);
  5253. stPLC_MesData.Right.BarcodeSet.strProductBarcode =
  5254. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strProductBarcode);
  5255. stPLC_MesData.Right.BarcodeSet.strPartBarcode =
  5256. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPartBarcode);
  5257. stPLC_MesData.Right.BarcodeSet.strCarrierBarcode =
  5258. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strCarrierBarcode);
  5259. stPLC_MesData.Right.BarcodeSet.strPCBBarcode =
  5260. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPCBBarcode);
  5261. #endregion
  5262. int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  5263. int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  5264. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  5265. ? XiaomiDeviceState.Unknown
  5266. : (XiaomiDeviceState)xmDeviceStateInt_L;
  5267. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  5268. ? XiaomiDeviceState.Unknown
  5269. : (XiaomiDeviceState)xmDeviceStateInt_R;
  5270. s7PLCData["a7OEEPartNo"] =
  5271. stPLC_MesData.Left.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  5272. // 载具SN
  5273. CarrierBarcode_Left = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode;
  5274. CarrierBarcode_Right = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode;
  5275. // 节拍
  5276. s7PLCData["a7OEEType"] = stPLC_MesData.Left.iotData.beatAction;
  5277. s7PLCData["a7OEEType_left"] = stPLC_MesData.Left .iotData.beatAction;
  5278. s7PLCData["a7OEEType_right"] = stPLC_MesData.Right.iotData.beatAction;
  5279. //报警信息
  5280. _FaultDatas = stPLC_MesData.Left.iotData.fault_codes;
  5281. _FaultDatas2 = stPLC_MesData.Right.iotData.fault_codes;
  5282. }
  5283. #endregion 一次性读取所有数据
  5284. stopwatch2.Stop();
  5285. #region 左边进站
  5286. try
  5287. {
  5288. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5289. {
  5290. lock (lockObj)
  5291. {
  5292. if (!ProgressState)
  5293. {
  5294. stationCode = "[OP81]";
  5295. stationName = "上盖板锁螺丝1";
  5296. stationNameStr = stationCode + stationName;
  5297. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  5298. ProgressState = true;
  5299. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left,
  5300. tagBaseName + ".Left." + tagMesCommName,
  5301. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState,
  5302. atlasScrewLeft));
  5303. }
  5304. }
  5305. }
  5306. }
  5307. catch (Exception ex)
  5308. {
  5309. ProgressState = false;
  5310. string str = ex.StackTrace;
  5311. AddMessage_Station(stationNameStr, LogType.Error,
  5312. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5313. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5314. }
  5315. #endregion 左边进站
  5316. #region 左边出站
  5317. try
  5318. {
  5319. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5320. {
  5321. lock (lockObj)
  5322. {
  5323. if (!ProgressState)
  5324. {
  5325. stationCode = "[OP81]";
  5326. stationName = "上盖板锁螺丝1";
  5327. stationNameStr = stationCode + stationName;
  5328. ProgressState = true;
  5329. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left,
  5330. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  5331. out ProgressState));
  5332. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  5333. }
  5334. }
  5335. }
  5336. }
  5337. catch (Exception ex)
  5338. {
  5339. ProgressState = false;
  5340. string str = ex.StackTrace;
  5341. AddMessage_Station(stationNameStr, LogType.Error,
  5342. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5343. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5344. }
  5345. #endregion 左边出站
  5346. #region 右边进站
  5347. try
  5348. {
  5349. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5350. {
  5351. lock (lockObj)
  5352. {
  5353. if (!ProgressState)
  5354. {
  5355. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  5356. stationCode = "[OP82]";
  5357. stationName = "上盖板锁螺丝2";
  5358. stationNameStr = stationCode + stationName;
  5359. ProgressState = true;
  5360. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right,
  5361. tagBaseName + ".Right." + tagMesCommName,
  5362. tagBaseName + ".Right" + tagBarsetName, "Right", out ProgressState,
  5363. atlasScrewRight));
  5364. }
  5365. }
  5366. }
  5367. }
  5368. catch (Exception ex)
  5369. {
  5370. ProgressState = false;
  5371. string str = ex.StackTrace;
  5372. AddMessage_Station(stationNameStr, LogType.Error,
  5373. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5374. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5375. }
  5376. #endregion 右边进站
  5377. #region 右边出站
  5378. try
  5379. {
  5380. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5381. {
  5382. lock (lockObj)
  5383. {
  5384. if (!ProgressState)
  5385. {
  5386. stationCode = "[OP82]";
  5387. stationName = "上盖板锁螺丝2";
  5388. stationNameStr = stationCode + stationName;
  5389. ProgressState = true;
  5390. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right,
  5391. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  5392. out ProgressState));
  5393. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  5394. }
  5395. }
  5396. }
  5397. }
  5398. catch (Exception ex)
  5399. {
  5400. ProgressState = false;
  5401. string str = ex.StackTrace;
  5402. AddMessage_Station(stationNameStr, LogType.Error,
  5403. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5404. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5405. }
  5406. #endregion 右边出站
  5407. #region 节拍接口
  5408. try
  5409. {
  5410. #region 左工位 节拍
  5411. if (stPLC_MesData.Left.iotData.beatAction > 0)
  5412. {
  5413. stationCode = "[OP81]";
  5414. stationName = "上盖板锁螺丝1";
  5415. stationNameStr = stationCode + stationName;
  5416. int a7OEEType_left = Convert.ToInt32(s7PLCData["a7OEEType_left"]);
  5417. int a7OEETypeGOld_left = Convert.ToInt32(s7PLCSignal_Old["a7OEEType_left"]);
  5418. if (a7OEEType_left != a7OEETypeGOld_left)
  5419. {
  5420. if (a7OEEType_left != a7OEETypeGOld_left)
  5421. s7PLCData["OEETypeFlag_left"] = "1";
  5422. else
  5423. s7PLCData["OEETypeFlag_left"] = "0";
  5424. if (s7PLCData["OEETypeFlag_left"].ToString() == "1" && (a7OEEType_left == 1 || a7OEEType_left == 3 || a7OEEType_left == 4 || a7OEEType_left == 5))
  5425. {
  5426. int res = 0;
  5427. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagiotComnName, CarrierBarcode_Left,
  5428. stPLC_MesData.Left.iotData, out res);
  5429. if (res == 1)
  5430. {
  5431. s7PLCSignal_Old["a7OEEType_left"] = s7PLCData["a7OEEType_left"];
  5432. }
  5433. else {
  5434. s7PLCSignal_Old["a7OEEType_left"] = 0;
  5435. }
  5436. }
  5437. }
  5438. }
  5439. else
  5440. {
  5441. s7PLCSignal_Old["a7OEEType_left"] = 0;
  5442. }
  5443. #endregion 左工位 节拍
  5444. #region 右工位 节拍
  5445. if (stPLC_MesData.Right.iotData.beatAction > 0)
  5446. {
  5447. stationCode = "[OP82]";
  5448. stationName = "上盖板锁螺丝2";
  5449. stationNameStr = stationCode + stationName;
  5450. int a7OEEType_right = Convert.ToInt32(s7PLCData["a7OEEType_right"]);
  5451. int a7OEETypeGOld_right = Convert.ToInt32(s7PLCSignal_Old["a7OEEType_right"]);
  5452. if (a7OEEType_right != a7OEETypeGOld_right)
  5453. {
  5454. if (a7OEEType_right != a7OEETypeGOld_right)
  5455. s7PLCData["a7OEEType_right"] = "1";
  5456. else
  5457. s7PLCData["a7OEEType_right"] = "0";
  5458. if (s7PLCData["a7OEEType_right"].ToString() == "1" && (a7OEEType_right == 1 || a7OEEType_right == 3 || a7OEEType_right == 4 || a7OEEType_right == 5))
  5459. {
  5460. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagiotComnName, CarrierBarcode_Left,
  5461. stPLC_MesData.Right.iotData, out res);
  5462. if (res == 1)
  5463. {
  5464. s7PLCSignal_Old["a7OEEType_right"] = s7PLCData["a7OEEType_right"];
  5465. }
  5466. else {
  5467. s7PLCSignal_Old["a7OEEType_right"] = 0;
  5468. }
  5469. }
  5470. }
  5471. }
  5472. else
  5473. {
  5474. s7PLCSignal_Old["a7OEEType_right"] = 0;
  5475. }
  5476. #endregion 右工位 节拍
  5477. }
  5478. catch (Exception ex)
  5479. {
  5480. string str = ex.StackTrace;
  5481. AddMessage_Station(stationNameStr, LogType.Error,
  5482. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  5483. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5484. }
  5485. #endregion
  5486. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5487. stopwatch1.Stop();
  5488. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5489. }
  5490. else
  5491. {
  5492. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5493. AddMessage_Station(stationNameStr, LogType.Info,
  5494. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5495. FunsEip[plcNo].Connect(); // 重连
  5496. }
  5497. }
  5498. catch (Exception ex)
  5499. {
  5500. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5501. AddMessage_Station(stationNameStr, LogType.Error,
  5502. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5503. }
  5504. Thread.Sleep(IntervalReadPLC);
  5505. }
  5506. }
  5507. /// <summary>
  5508. /// [S7] 锁螺丝设备 - 进站
  5509. /// </summary>
  5510. /// <param name="plcNo">PLC编号</param>
  5511. /// <param name="stationNameStr">工站全称</param>
  5512. /// <param name="stPLC_MesData"></param>
  5513. /// <param name="tagMesCommName"></param>
  5514. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  5515. string tagBarsetName, string direction, out bool ProgressState, AtlasScrew atlasScrew)
  5516. {
  5517. Stopwatch stopwatch1 = new Stopwatch();
  5518. Stopwatch stopwatch2 = new Stopwatch();
  5519. string atlasSn = string.Empty;
  5520. try
  5521. {
  5522. stopwatch1.Start();
  5523. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  5524. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5525. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  5526. string StationId = string.Empty; // 工位ID(可配置)
  5527. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5528. bool pass = a1Result == 1;
  5529. if (direction == "Left")
  5530. {
  5531. StationId = GlobalContext.S7_StationId_1;
  5532. }
  5533. if (direction == "Right")
  5534. {
  5535. StationId = GlobalContext.S7_StationId_2;
  5536. }
  5537. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  5538. //载具码验证产品码
  5539. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  5540. if (string.IsNullOrEmpty(strProductBarcode))
  5541. {
  5542. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5543. ProgressState = false;
  5544. Thread.Sleep(10000);
  5545. return;
  5546. }
  5547. sn = strProductBarcode;
  5548. atlasSn = strProductBarcode;
  5549. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5550. string slot = "";
  5551. if (direction == "Left")
  5552. {
  5553. isCollectingFlagLeft = false; //采集螺丝数据结束
  5554. slot = "01-SLOT-01";
  5555. }
  5556. if (direction == "Right")
  5557. {
  5558. isCollectingFlagRight = false; //采集螺丝数据结束
  5559. slot = "01-SLOT-02";
  5560. }
  5561. // 产品SN(物料码)校验
  5562. List<TestItem> item = new List<TestItem>();
  5563. stopwatch2.Start();
  5564. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  5565. item, MachineId, StationId, pass, slot);
  5566. stopwatch2.Stop();
  5567. //指令执行结果 1:OK 110:失败
  5568. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5569. if (mesResultFrmWeb == 1)
  5570. {
  5571. if (a1Result == 1)
  5572. {
  5573. mesResultFrmWeb = 1;
  5574. }
  5575. else
  5576. {
  5577. mesResultFrmWeb = 110;
  5578. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  5579. }
  5580. }
  5581. //进站结果写入PLC
  5582. CommandFromPLC resultToPlC = new CommandFromPLC();
  5583. resultToPlC.cmd = 0;
  5584. resultToPlC.cmdParam = 0; //指令参数
  5585. resultToPlC.cmdResult = mesResultFrmWeb;
  5586. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5587. }
  5588. catch (Exception ex)
  5589. {
  5590. string str = ex.StackTrace;
  5591. AddMessage(LogType.Error,
  5592. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  5593. str.Length - str.LastIndexOf("\\") - 1));
  5594. CommandFromPLC resultToPlC = new CommandFromPLC();
  5595. resultToPlC.cmd = 0;
  5596. resultToPlC.cmdParam = 0; //指令参数
  5597. resultToPlC.cmdResult = 110;
  5598. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5599. }
  5600. stopwatch1.Stop();
  5601. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  5602. AddMessage(LogType.Info,
  5603. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5604. stopwatch2.ElapsedMilliseconds + "ms");
  5605. ProgressState = false;
  5606. //开始采集螺丝数据
  5607. if (direction == "Left")
  5608. {
  5609. isCollectingFlagLeft = true;
  5610. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  5611. }
  5612. if (direction == "Right")
  5613. {
  5614. isCollectingFlagRight = true;
  5615. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  5616. }
  5617. }
  5618. /// <summary>
  5619. /// [S7] 锁螺丝设备 - 出站
  5620. /// </summary>
  5621. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  5622. string stationCode, string stationName, string direction, out bool ProgressState)
  5623. {
  5624. Stopwatch stopwatch1 = new Stopwatch();
  5625. Stopwatch stopwatch2 = new Stopwatch();
  5626. try
  5627. {
  5628. stopwatch1.Start();
  5629. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  5630. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5631. string processItem = stationName; // 测试项目
  5632. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5633. string supplierCode = ""; // 供应商代码
  5634. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5635. string batch_num = GlobalContext.BatchNumber; // 批次号
  5636. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5637. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5638. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5639. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  5640. string StationId = string.Empty; // 工位ID(可配置)
  5641. if (direction == "Left")
  5642. {
  5643. StationId = GlobalContext.S7_StationId_1;
  5644. }
  5645. if (direction == "Right")
  5646. {
  5647. StationId = GlobalContext.S7_StationId_2;
  5648. }
  5649. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5650. //a1Result = 1;
  5651. bool pass = a1Result == 1;
  5652. //根据载具码获取产品码
  5653. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5654. if (string.IsNullOrEmpty(strProductBarcode))
  5655. {
  5656. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5657. ProgressState = false;
  5658. Thread.Sleep(10000);
  5659. return;
  5660. }
  5661. sn = strProductBarcode;
  5662. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  5663. List<TestItem> items = new List<TestItem>();
  5664. items.Add(new TestItem()
  5665. {
  5666. Parameter_name = "载具码",
  5667. Parameter_value = CarrierBarcode,
  5668. Parameter_unit = ""
  5669. });
  5670. items.Add(new TestItem()
  5671. {
  5672. Parameter_name = "产品码",
  5673. Parameter_value = sn,
  5674. Parameter_unit = ""
  5675. });
  5676. //if (direction == "Right")
  5677. //{
  5678. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  5679. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem, workorder_code,
  5680. batch_num, mtltmrk, plcDate_YMD, supplierCode
  5681. , sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  5682. //}
  5683. //if (direction == "Left")
  5684. //{
  5685. // isCollectingFlagLeft = false;//采集螺丝数据结束
  5686. //}
  5687. //if (direction == "Right")
  5688. //{
  5689. // isCollectingFlagRight = false;//采集螺丝数据结束
  5690. //}
  5691. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5692. if (mesResultFrmWeb == 1)
  5693. {
  5694. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  5695. if (mesResultFrmWeb == 110)
  5696. {
  5697. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  5698. }
  5699. }
  5700. stopwatch2.Start();
  5701. //进站结果写入PLC
  5702. CommandFromPLC resultToPlC = new CommandFromPLC();
  5703. resultToPlC.cmd = 0;
  5704. resultToPlC.cmdParam = 0; //指令参数
  5705. resultToPlC.cmdResult = mesResultFrmWeb;
  5706. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5707. stopwatch2.Stop();
  5708. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  5709. //保存PLC返回MES数据到本地
  5710. ResponseMessage message = new ResponseMessage();
  5711. if (direction == "Left")
  5712. {
  5713. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  5714. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  5715. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  5716. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  5717. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  5718. //if (message.result == false)
  5719. //{
  5720. // AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  5721. //}
  5722. }
  5723. if (direction == "Right")
  5724. {
  5725. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  5726. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  5727. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  5728. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  5729. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  5730. //if (message.result == false)
  5731. //{
  5732. // AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  5733. //}
  5734. }
  5735. //保存螺丝数据到txt
  5736. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes,
  5737. stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  5738. if (result.Item1 != 0)
  5739. {
  5740. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  5741. }
  5742. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_保存加工数据到本地成功");
  5743. }
  5744. catch (Exception ex)
  5745. {
  5746. stopwatch2.Start();
  5747. CommandFromPLC resultToPlC = new CommandFromPLC();
  5748. resultToPlC.cmd = 0;
  5749. resultToPlC.cmdParam = 0; //指令参数
  5750. resultToPlC.cmdResult = 110;
  5751. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5752. stopwatch2.Stop();
  5753. string str = ex.StackTrace;
  5754. AddMessage(LogType.Error,
  5755. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5756. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5757. }
  5758. stopwatch1.Stop();
  5759. AddMessage(LogType.Info,
  5760. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5761. stopwatch2.ElapsedMilliseconds + "ms");
  5762. ProgressState = false;
  5763. if (direction == "Left") uuid = "";
  5764. if (direction == "Right") uuid2 = "";
  5765. }
  5766. #endregion
  5767. #region S8
  5768. private Dictionary<string, object> s8PLCData = new Dictionary<string, object>();
  5769. private Dictionary<string, object> s8PLCSignal_Old = new Dictionary<string, object>();
  5770. /// <summary>
  5771. /// [S8] 3D螺丝高度检测设备
  5772. /// </summary>
  5773. /// <param name="plcNo">PLC编号</param>
  5774. private void ReadStation_S8(int plcNo)
  5775. {
  5776. string stationCode = "[OP90]";
  5777. string stationName = "NG下料";
  5778. string stationNameStr = stationCode + stationName;
  5779. string tagBaseName = "g_OP80_MES"; //标签变量名称
  5780. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5781. string tagAgvCommName = "agvCommFrmPC";
  5782. string tagiotComnName = "iotData";
  5783. string tagBarsetName = "BarcodeSet";
  5784. string CarrierBarcode = "";
  5785. // 触发信号字典
  5786. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5787. s8PLCSignal_Old.Add("a8OEEType", 0); // 节拍类型(plc写入)
  5788. // PLC数据字典 赋值
  5789. s8PLCData.Add("a8OEEType", 0); // 节拍类型(plc写入)
  5790. s8PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  5791. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  5792. (int, string) result;
  5793. while (true)
  5794. {
  5795. try
  5796. {
  5797. if (!GlobalContext._IsCon_Funs1)
  5798. {
  5799. UpdatePLCMonitor(1, plcNo, 0);
  5800. continue;
  5801. }
  5802. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5803. {
  5804. Stopwatch stopwatch1 = new Stopwatch();
  5805. Stopwatch stopwatch2 = new Stopwatch();
  5806. stopwatch1.Start();
  5807. stopwatch2.Start();
  5808. #region 一次性读取所有数据
  5809. // 一次性读取所有数据
  5810. result = FunsEip[plcNo]
  5811. .Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  5812. if (result.Item1 != 0)
  5813. {
  5814. //richTextBox1.AppendText("\n" + strRet);
  5815. }
  5816. else
  5817. {
  5818. //去除扫码产生的特殊字符
  5819. stPLC_MesData.BarcodeSet.strProductBarcode =
  5820. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  5821. stPLC_MesData.BarcodeSet.strPartBarcode =
  5822. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  5823. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  5824. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  5825. stPLC_MesData.BarcodeSet.strPCBBarcode =
  5826. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  5827. }
  5828. #endregion 一次性读取所有数据
  5829. stopwatch2.Stop();
  5830. //richTextBox1.AppendText("\n" + "读取成功");
  5831. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  5832. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  5833. ? XiaomiDeviceState.Unknown
  5834. : (XiaomiDeviceState)xmDeviceStateInt;
  5835. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  5836. s8PLCData["a8OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  5837. //报警信息
  5838. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  5839. stopwatch2.Stop();
  5840. #region 进站
  5841. try
  5842. {
  5843. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5844. {
  5845. lock (lockObj)
  5846. {
  5847. if (!ProgressState)
  5848. {
  5849. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  5850. ProgressState = true;
  5851. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData,
  5852. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  5853. out ProgressState));
  5854. }
  5855. }
  5856. }
  5857. }
  5858. catch (Exception ex)
  5859. {
  5860. ProgressState = false;
  5861. string str = ex.StackTrace;
  5862. AddMessage_Station(stationNameStr, LogType.Error,
  5863. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5864. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5865. }
  5866. #endregion 进站
  5867. #region 出站
  5868. try
  5869. {
  5870. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5871. {
  5872. lock (lockObj)
  5873. {
  5874. if (!ProgressState)
  5875. {
  5876. ProgressState = true;
  5877. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData,
  5878. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  5879. out ProgressState));
  5880. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  5881. }
  5882. }
  5883. }
  5884. }
  5885. catch (Exception ex)
  5886. {
  5887. ProgressState = false;
  5888. string str = ex.StackTrace;
  5889. AddMessage_Station(stationNameStr, LogType.Error,
  5890. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5891. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5892. }
  5893. #endregion 出站
  5894. #region 节拍接口
  5895. try
  5896. {
  5897. int a8OEEType = Convert.ToInt32(s8PLCData["a8OEEType"]);
  5898. int a8OEETypeGOld = Convert.ToInt32(s8PLCSignal_Old["a8OEEType"]);
  5899. if (stPLC_MesData.iotData.beatAction > 0)
  5900. {
  5901. if (a8OEEType != a8OEETypeGOld)
  5902. {
  5903. s8PLCData["OEETypeFlag"] = "1";
  5904. }
  5905. else
  5906. {
  5907. s8PLCData["OEETypeFlag"] = "0";
  5908. }
  5909. if (s8PLCData["OEETypeFlag"].ToString() == "1" && (a8OEEType == 1 || a8OEEType == 3 || a8OEEType == 4 || a8OEEType == 5))
  5910. {
  5911. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  5912. CarrierBarcode, stPLC_MesData.iotData, out res);
  5913. if (res == 1)
  5914. {
  5915. s8PLCSignal_Old["a8OEEType"] = s8PLCData["a8OEEType"];
  5916. }
  5917. else
  5918. {
  5919. s8PLCSignal_Old["a8OEEType"] = 0;
  5920. }
  5921. }
  5922. }
  5923. else {
  5924. s8PLCSignal_Old["a8OEEType"] = 0;
  5925. }
  5926. }
  5927. catch (Exception ex)
  5928. {
  5929. string str = ex.StackTrace;
  5930. AddMessage_Station(stationNameStr, LogType.Error,
  5931. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  5932. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5933. }
  5934. #endregion
  5935. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5936. stopwatch1.Stop();
  5937. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5938. }
  5939. else
  5940. {
  5941. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5942. AddMessage_Station(stationNameStr, LogType.Info,
  5943. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5944. FunsEip[plcNo].Connect(); // 重连
  5945. }
  5946. }
  5947. catch (Exception ex)
  5948. {
  5949. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5950. AddMessage_Station(stationNameStr, LogType.Error,
  5951. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5952. }
  5953. Thread.Sleep(IntervalReadPLC);
  5954. }
  5955. }
  5956. /// <summary>
  5957. /// [S8] 3D螺丝高度检测设备 - 进站
  5958. /// </summary>
  5959. /// <param name="plcNo">PLC编号</param>
  5960. /// <param name="stationNameStr">工站全称</param>
  5961. /// <param name="stPLC_MesData"></param>
  5962. /// <param name="tagMesCommName"></param>
  5963. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  5964. string tagBarsetName, out bool ProgressState)
  5965. {
  5966. Stopwatch stopwatch1 = new Stopwatch();
  5967. Stopwatch stopwatch2 = new Stopwatch();
  5968. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5969. bool pass = a1Result == 1;
  5970. try
  5971. {
  5972. stopwatch1.Start();
  5973. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  5974. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5975. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  5976. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  5977. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  5978. //载具码验证产品码
  5979. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  5980. if (string.IsNullOrEmpty(strProductBarcode))
  5981. {
  5982. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5983. ProgressState = false;
  5984. Thread.Sleep(10000);
  5985. return;
  5986. }
  5987. sn = strProductBarcode;
  5988. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5989. // 产品SN(物料码)校验
  5990. List<TestItem> item = new List<TestItem>();
  5991. stopwatch2.Start();
  5992. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  5993. sn,
  5994. item, MachineId, StationId, pass, "01-SLOT-01");
  5995. stopwatch2.Stop();
  5996. //指令执行结果 1:OK 110:失败
  5997. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5998. if (mesResultFrmWeb == 1)
  5999. {
  6000. if (a1Result == 1)
  6001. {
  6002. mesResultFrmWeb = 1;
  6003. }
  6004. else
  6005. {
  6006. mesResultFrmWeb = 110;
  6007. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  6008. }
  6009. }
  6010. //进站结果写入PLC
  6011. CommandFromPLC resultToPlC = new CommandFromPLC();
  6012. resultToPlC.cmd = 0;
  6013. resultToPlC.cmdParam = 0; //指令参数
  6014. resultToPlC.cmdResult = mesResultFrmWeb;
  6015. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6016. }
  6017. catch (Exception ex)
  6018. {
  6019. string str = ex.StackTrace;
  6020. AddMessage(LogType.Error,
  6021. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(
  6022. str.LastIndexOf("\\") + 1,
  6023. str.Length - str.LastIndexOf("\\") - 1));
  6024. CommandFromPLC resultToPlC = new CommandFromPLC();
  6025. resultToPlC.cmd = 0;
  6026. resultToPlC.cmdParam = 0; //指令参数
  6027. resultToPlC.cmdResult = 110;
  6028. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6029. }
  6030. stopwatch1.Stop();
  6031. AddMessage(LogType.Info,
  6032. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  6033. stopwatch2.ElapsedMilliseconds + "ms");
  6034. ProgressState = false;
  6035. }
  6036. /// <summary>
  6037. /// [S8] 3D螺丝高度检测设备 - 出站接口
  6038. /// </summary>
  6039. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  6040. string stationCode, string stationName, out bool ProgressState)
  6041. {
  6042. Stopwatch stopwatch1 = new Stopwatch();
  6043. Stopwatch stopwatch2 = new Stopwatch();
  6044. try
  6045. {
  6046. stopwatch1.Start();
  6047. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  6048. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6049. string processItem = stationName; // 测试项目
  6050. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6051. string supplierCode = ""; // 供应商代码
  6052. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6053. string batch_num = GlobalContext.BatchNumber; // 批次号
  6054. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6055. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  6056. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  6057. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  6058. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  6059. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6060. bool pass = a1Result == 1;
  6061. //根据载具码获取产品码
  6062. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  6063. if (string.IsNullOrEmpty(strProductBarcode))
  6064. {
  6065. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6066. ProgressState = false;
  6067. Thread.Sleep(10000);
  6068. return;
  6069. }
  6070. sn = strProductBarcode;
  6071. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  6072. List<TestItem> items = new List<TestItem>();
  6073. items.Add(new TestItem()
  6074. {
  6075. Parameter_name = "载具码",
  6076. Parameter_value = CarrierBarcode,
  6077. Parameter_unit = ""
  6078. });
  6079. items.Add(new TestItem()
  6080. {
  6081. Parameter_name = "产品码",
  6082. Parameter_value = sn,
  6083. Parameter_unit = ""
  6084. });
  6085. #region 上传图片
  6086. if (GlobalContext.MQTTIsSendUpFile)
  6087. {
  6088. string[] urlarry = GlobalContext.UpFilePath.Split(",");
  6089. fileUploadData.fileData.Clear();
  6090. foreach (var item in urlarry)
  6091. {
  6092. if (!string.IsNullOrEmpty(item))
  6093. {
  6094. //上传图片
  6095. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName,
  6096. a1Result, item, uuid).Result;
  6097. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  6098. }
  6099. }
  6100. }
  6101. #endregion
  6102. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  6103. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6104. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  6105. MachineId, StationId, "", paramJson);
  6106. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  6107. if (mesResultFrmWeb == 1)
  6108. {
  6109. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  6110. if (mesResultFrmWeb == 110)
  6111. {
  6112. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  6113. }
  6114. }
  6115. stopwatch2.Start();
  6116. //进站结果写入PLC
  6117. CommandFromPLC resultToPlC = new CommandFromPLC();
  6118. resultToPlC.cmd = 0;
  6119. resultToPlC.cmdParam = 0; //指令参数
  6120. resultToPlC.cmdResult = mesResultFrmWeb;
  6121. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6122. stopwatch2.Stop();
  6123. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  6124. //保存PLC返回MES数据到本地
  6125. ResponseMessage message = new ResponseMessage();
  6126. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  6127. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  6128. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  6129. if (message.result == false)
  6130. {
  6131. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  6132. }
  6133. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  6134. }
  6135. catch (Exception ex)
  6136. {
  6137. stopwatch2.Start();
  6138. CommandFromPLC resultToPlC = new CommandFromPLC();
  6139. resultToPlC.cmd = 0;
  6140. resultToPlC.cmdParam = 0; //指令参数
  6141. resultToPlC.cmdResult = 110;
  6142. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6143. stopwatch2.Stop();
  6144. string str = ex.StackTrace;
  6145. AddMessage(LogType.Error,
  6146. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  6147. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6148. }
  6149. stopwatch1.Stop();
  6150. AddMessage(LogType.Info,
  6151. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6152. stopwatch2.ElapsedMilliseconds + "ms");
  6153. ProgressState = false;
  6154. uuid = "";
  6155. }
  6156. #endregion
  6157. #region S9
  6158. private Dictionary<string, object> s9PLCData = new Dictionary<string, object>();
  6159. private Dictionary<string, object> s9PLCSignal_Old = new Dictionary<string, object>();
  6160. /// <summary>
  6161. /// [S9] 下料设备
  6162. /// </summary>
  6163. /// <param name="plcNo">PLC编号</param>
  6164. private void ReadStation_S9(int plcNo)
  6165. {
  6166. string stationCode = "[OP100]";
  6167. string stationName = "半成品下料";
  6168. string stationNameStr = stationCode + stationName;
  6169. string tagBaseName = "g_OP90_MES"; //标签变量名称
  6170. string tagMesCommName = "mesCommToPC"; //标签变量名称
  6171. string tagAgvCommName = "agvCommFrmPC";
  6172. string tagiotComnName = "iotData";
  6173. string tagBarsetName = "BarcodeSet";
  6174. string CarrierBarcode = "";
  6175. // 触发信号字典
  6176. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6177. s9PLCSignal_Old.Add("a9OEEType", 0); // 节拍类型(plc写入)
  6178. // PLC数据字典 赋值
  6179. s9PLCData.Add("a9OEEType", 0); // 节拍类型(plc写入)
  6180. s9PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  6181. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  6182. (int, string) result;
  6183. while (true)
  6184. {
  6185. try
  6186. {
  6187. if (!GlobalContext._IsCon_Funs1)
  6188. {
  6189. UpdatePLCMonitor(1, plcNo, 0);
  6190. continue;
  6191. }
  6192. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  6193. {
  6194. Stopwatch stopwatch1 = new Stopwatch();
  6195. Stopwatch stopwatch2 = new Stopwatch();
  6196. stopwatch1.Start();
  6197. stopwatch2.Start();
  6198. #region 一次性读取所有数据
  6199. // 一次性读取所有数据
  6200. result = FunsEip[plcNo]
  6201. .Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  6202. if (result.Item1 != 0)
  6203. {
  6204. //richTextBox1.AppendText("\n" + strRet);
  6205. }
  6206. else
  6207. {
  6208. //去除扫码产生的特殊字符
  6209. stPLC_MesData.BarcodeSet.strProductBarcode =
  6210. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  6211. stPLC_MesData.BarcodeSet.strPartBarcode =
  6212. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  6213. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  6214. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  6215. stPLC_MesData.BarcodeSet.strPCBBarcode =
  6216. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  6217. //richTextBox1.AppendText("\n" + "读取成功");
  6218. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  6219. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  6220. ? XiaomiDeviceState.Unknown
  6221. : (XiaomiDeviceState)xmDeviceStateInt;
  6222. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  6223. s9PLCData["a9OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  6224. //报警信息
  6225. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  6226. }
  6227. #endregion 一次性读取所有数据
  6228. stopwatch2.Stop();
  6229. #region 进站
  6230. try
  6231. {
  6232. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  6233. {
  6234. lock (lockObj)
  6235. {
  6236. if (!ProgressState)
  6237. {
  6238. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  6239. ProgressState = true;
  6240. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData,
  6241. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  6242. out ProgressState));
  6243. }
  6244. }
  6245. }
  6246. }
  6247. catch (Exception ex)
  6248. {
  6249. ProgressState = false;
  6250. string str = ex.StackTrace;
  6251. AddMessage_Station(stationNameStr, LogType.Error,
  6252. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6253. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6254. }
  6255. #endregion 进站
  6256. #region 出站
  6257. try
  6258. {
  6259. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  6260. {
  6261. lock (lockObj)
  6262. {
  6263. if (!ProgressState)
  6264. {
  6265. ProgressState = true;
  6266. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData,
  6267. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  6268. out ProgressState));
  6269. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  6270. }
  6271. }
  6272. }
  6273. }
  6274. catch (Exception ex)
  6275. {
  6276. ProgressState = false;
  6277. string str = ex.StackTrace;
  6278. AddMessage_Station(stationNameStr, LogType.Error,
  6279. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6280. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6281. }
  6282. #endregion 出站
  6283. #region 节拍接口
  6284. try
  6285. {
  6286. if (stPLC_MesData.iotData.beatAction > 0)
  6287. {
  6288. int a9OEEType = Convert.ToInt32(s9PLCData["a9OEEType"]);
  6289. int a9OEETypeGOld = Convert.ToInt32(s9PLCSignal_Old["a9OEEType"]);
  6290. if (a9OEEType != a9OEETypeGOld)
  6291. {
  6292. s9PLCData["OEETypeFlag"] = "1";
  6293. }
  6294. else
  6295. {
  6296. s9PLCData["OEETypeFlag"] = "0";
  6297. }
  6298. if (s9PLCData["OEETypeFlag"].ToString() == "1" && (a9OEEType == 1 || a9OEEType == 3 || a9OEEType == 4 || a9OEEType == 5))
  6299. {
  6300. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  6301. CarrierBarcode, stPLC_MesData.iotData, out res);
  6302. if (res == 1)
  6303. {
  6304. s9PLCSignal_Old["a9OEEType"] = s9PLCData["a9OEEType"];
  6305. }
  6306. else
  6307. {
  6308. s9PLCSignal_Old["a9OEEType"] = 0;
  6309. }
  6310. }
  6311. }
  6312. else {
  6313. s9PLCSignal_Old["a9OEEType"] = 0;
  6314. }
  6315. }
  6316. catch (Exception ex)
  6317. {
  6318. string str = ex.StackTrace;
  6319. AddMessage_Station(stationNameStr, LogType.Error,
  6320. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  6321. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6322. }
  6323. #endregion
  6324. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6325. stopwatch1.Stop();
  6326. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6327. }
  6328. else
  6329. {
  6330. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6331. AddMessage_Station(stationNameStr, LogType.Info,
  6332. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6333. FunsEip[plcNo].Connect(); // 重连
  6334. }
  6335. }
  6336. catch (Exception ex)
  6337. {
  6338. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6339. AddMessage_Station(stationNameStr, LogType.Error,
  6340. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6341. }
  6342. Thread.Sleep(IntervalReadPLC);
  6343. }
  6344. }
  6345. /// <summary>
  6346. /// [S9] 下料设备 - 进站
  6347. /// </summary>
  6348. /// <param name="plcNo">PLC编号</param>
  6349. /// <param name="stationNameStr">工站全称</param>
  6350. /// <param name="stPLC_MesData"></param>
  6351. /// <param name="tagMesCommName"></param>
  6352. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  6353. string tagBarsetName, out bool ProgressState)
  6354. {
  6355. Stopwatch stopwatch1 = new Stopwatch();
  6356. Stopwatch stopwatch2 = new Stopwatch();
  6357. try
  6358. {
  6359. stopwatch1.Start();
  6360. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  6361. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  6362. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  6363. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  6364. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6365. bool pass = a1Result == 1;
  6366. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  6367. //载具码验证产品码
  6368. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  6369. if (string.IsNullOrEmpty(strProductBarcode))
  6370. {
  6371. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6372. ProgressState = false;
  6373. Thread.Sleep(10000);
  6374. return;
  6375. }
  6376. sn = strProductBarcode;
  6377. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  6378. // 产品SN(物料码)校验
  6379. List<TestItem> item = new List<TestItem>();
  6380. stopwatch2.Start();
  6381. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  6382. item, MachineId, StationId, pass, "01-SLOT-01");
  6383. stopwatch2.Stop();
  6384. //指令执行结果 1:OK 110:失败
  6385. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  6386. if (mesResultFrmWeb == 1)
  6387. {
  6388. if (a1Result == 1)
  6389. {
  6390. mesResultFrmWeb = 1;
  6391. }
  6392. else
  6393. {
  6394. mesResultFrmWeb = 110;
  6395. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  6396. }
  6397. }
  6398. //进站结果写入PLC
  6399. CommandFromPLC resultToPlC = new CommandFromPLC();
  6400. resultToPlC.cmd = 0;
  6401. resultToPlC.cmdParam = 0; //指令参数
  6402. resultToPlC.cmdResult = mesResultFrmWeb;
  6403. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6404. }
  6405. catch (Exception ex)
  6406. {
  6407. string str = ex.StackTrace;
  6408. AddMessage(LogType.Error,
  6409. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  6410. str.Length - str.LastIndexOf("\\") - 1));
  6411. CommandFromPLC resultToPlC = new CommandFromPLC();
  6412. resultToPlC.cmd = 0;
  6413. resultToPlC.cmdParam = 0; //指令参数
  6414. resultToPlC.cmdResult = 110;
  6415. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6416. }
  6417. stopwatch1.Stop();
  6418. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  6419. AddMessage(LogType.Info,
  6420. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  6421. stopwatch2.ElapsedMilliseconds + "ms");
  6422. ProgressState = false;
  6423. }
  6424. /// <summary>
  6425. /// [S9] 下料设备 - 出站接口
  6426. /// </summary>
  6427. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  6428. string stationCode, string stationName, out bool ProgressState)
  6429. {
  6430. Stopwatch stopwatch1 = new Stopwatch();
  6431. Stopwatch stopwatch2 = new Stopwatch();
  6432. try
  6433. {
  6434. stopwatch1.Start();
  6435. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  6436. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6437. string processItem = stationName; // 测试项目
  6438. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6439. string supplierCode = ""; // 供应商代码
  6440. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6441. string batch_num = GlobalContext.BatchNumber; // 批次号
  6442. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6443. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  6444. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  6445. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  6446. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  6447. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6448. bool pass = a1Result == 1;
  6449. //根据载具码获取产品码
  6450. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  6451. if (string.IsNullOrEmpty(strProductBarcode))
  6452. {
  6453. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6454. ProgressState = false;
  6455. Thread.Sleep(10000);
  6456. return;
  6457. }
  6458. sn = strProductBarcode;
  6459. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  6460. List<TestItem> items = new List<TestItem>();
  6461. items.Add(new TestItem()
  6462. {
  6463. Parameter_name = "载具码",
  6464. Parameter_value = CarrierBarcode,
  6465. Parameter_unit = ""
  6466. });
  6467. items.Add(new TestItem()
  6468. {
  6469. Parameter_name = "产品码",
  6470. Parameter_value = sn,
  6471. Parameter_unit = ""
  6472. });
  6473. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  6474. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6475. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  6476. MachineId, StationId, "", paramJson);
  6477. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  6478. if (mesResultFrmWeb == 1)
  6479. {
  6480. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  6481. if (mesResultFrmWeb == 110)
  6482. {
  6483. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  6484. }
  6485. }
  6486. stopwatch2.Start();
  6487. //进站结果写入PLC
  6488. CommandFromPLC resultToPlC = new CommandFromPLC();
  6489. resultToPlC.cmd = 0;
  6490. resultToPlC.cmdParam = 0; //指令参数
  6491. resultToPlC.cmdResult = mesResultFrmWeb;
  6492. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6493. stopwatch2.Stop();
  6494. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  6495. //保存PLC返回MES数据到本地
  6496. ResponseMessage message = new ResponseMessage();
  6497. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  6498. stPLC_MesData.mesData.nRemainCount);
  6499. if (message.result == false)
  6500. {
  6501. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  6502. }
  6503. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  6504. if (result1 == 1)
  6505. {
  6506. //载具码解除绑定
  6507. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  6508. if (message.result == false)
  6509. {
  6510. AddMessage(LogType.Error, message.text);
  6511. }
  6512. }
  6513. }
  6514. catch (Exception ex)
  6515. {
  6516. stopwatch2.Start();
  6517. CommandFromPLC resultToPlC = new CommandFromPLC();
  6518. resultToPlC.cmd = 0;
  6519. resultToPlC.cmdParam = 0; //指令参数
  6520. resultToPlC.cmdResult = 110;
  6521. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6522. stopwatch2.Stop();
  6523. string str = ex.StackTrace;
  6524. AddMessage(LogType.Error,
  6525. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  6526. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6527. }
  6528. stopwatch1.Stop();
  6529. AddMessage(LogType.Info,
  6530. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6531. stopwatch2.ElapsedMilliseconds + "ms");
  6532. ProgressState = false;
  6533. uuid = "";
  6534. }
  6535. #endregion
  6536. #endregion Xiaomi
  6537. #region PLC1 张超凡
  6538. #region [S1] Tray盘上料装备(板测)
  6539. /// <summary>
  6540. /// S1工位的数据- 触发信号上次的值
  6541. /// </summary>
  6542. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  6543. /// <summary>
  6544. /// S1工位的数据(含触发信号)
  6545. /// </summary>
  6546. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  6547. /// <summary>
  6548. /// S1工位的数据- 回写点位
  6549. /// </summary>
  6550. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6551. ///// <summary>
  6552. ///// 触发信号
  6553. ///// </summary>
  6554. //private ManualResetEvent[] MreTasks;
  6555. /// <summary>
  6556. /// [S1] Tray盘上料装备(板测)
  6557. /// </summary>
  6558. /// <param name="plcNo">PLC编号</param>
  6559. //private void ReadStation_S1(int plcNo)
  6560. //{
  6561. // // [S1] Tray盘上料装备
  6562. // // [S2] FCT
  6563. // // [S3] 值板机
  6564. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6565. // // [S5] Tray盘下料装备
  6566. // string stationCode = "[S1]";
  6567. // string stationName = "Tray盘上料装备";
  6568. // string stationNameStr = stationCode + stationName;
  6569. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6570. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6571. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  6572. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  6573. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6574. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  6575. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6576. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  6577. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  6578. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  6579. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  6580. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6581. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  6582. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  6583. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  6584. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  6585. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  6586. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  6587. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6588. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  6589. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  6590. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  6591. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  6592. // s1PLCData.Add("a1Result", 0); // 产品结果
  6593. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  6594. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  6595. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  6596. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  6597. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  6598. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6599. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  6600. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  6601. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  6602. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  6603. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  6604. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  6605. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  6606. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  6607. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  6608. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  6609. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  6610. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6611. // while (IsRun)
  6612. // {
  6613. // try
  6614. // {
  6615. // if (!GlobalContext._IsCon_Funs1)
  6616. // {
  6617. // UpdatePLCMonitor(1, plcNo, 0);
  6618. // continue;
  6619. // }
  6620. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6621. // {
  6622. // Stopwatch stopwatch1 = new Stopwatch();
  6623. // Stopwatch stopwatch2 = new Stopwatch();
  6624. // stopwatch1.Start();
  6625. // stopwatch2.Start();
  6626. // #region 一次性读取所有数据
  6627. // // 一次性读取所有数据
  6628. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6629. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6630. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6631. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  6632. // int[] datas = data1.Concat(data2).ToArray();
  6633. // datas = datas.Concat(data3).ToArray();
  6634. // datas = datas.Concat(data4).ToArray();
  6635. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  6636. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  6637. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  6638. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  6639. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  6640. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  6641. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  6642. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  6643. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  6644. // s1PLCData["a1MES_FLAG"] = datas[109];
  6645. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  6646. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  6647. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  6648. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  6649. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  6650. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  6651. // s1PLCData["a1Result"] = datas[170];
  6652. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  6653. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  6654. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  6655. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  6656. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  6657. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  6658. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  6659. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  6660. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  6661. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  6662. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  6663. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  6664. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  6665. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  6666. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  6667. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  6668. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  6669. // s1PLCData["a1AGVUpStart"] = datas[308];
  6670. // s1PLCData["a1AGVUpEnd"] = datas[309];
  6671. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  6672. // s1PLCData["a1AGVDownStart"] = datas[321];
  6673. // s1PLCData["a1AGVDownEnd"] = datas[322];
  6674. // #endregion 一次性读取所有数据
  6675. // stopwatch2.Stop();
  6676. // #region 回写操作,写后清空flag
  6677. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  6678. // #endregion 回写操作,写后清空flag
  6679. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  6680. // try
  6681. // {
  6682. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  6683. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  6684. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  6685. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  6686. // {
  6687. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  6688. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  6689. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  6690. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  6691. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  6692. // }
  6693. // }
  6694. // catch (Exception ex)
  6695. // {
  6696. // // 6代表上位机报警
  6697. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  6698. // string str = ex.StackTrace;
  6699. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6700. // }
  6701. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  6702. // #region 上料进站校验
  6703. // try
  6704. // {
  6705. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  6706. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  6707. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  6708. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  6709. // {
  6710. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  6711. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  6712. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  6713. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  6714. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  6715. // }
  6716. // }
  6717. // catch (Exception ex)
  6718. // {
  6719. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  6720. // string str = ex.StackTrace;
  6721. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6722. // }
  6723. // #endregion 上料进站校验
  6724. // #region Tray盘上料装备-出站接口
  6725. // try
  6726. // {
  6727. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  6728. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  6729. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  6730. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  6731. // {
  6732. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  6733. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6734. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  6735. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  6736. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  6737. // }
  6738. // }
  6739. // catch (Exception ex)
  6740. // {
  6741. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  6742. // string str = ex.StackTrace;
  6743. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6744. // }
  6745. // #endregion Tray盘上料装备-出站接口
  6746. // #region Tray盘上料装备-将SN发给ICT标机
  6747. // try
  6748. // {
  6749. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  6750. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  6751. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  6752. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  6753. // {
  6754. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  6755. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  6756. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  6757. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  6758. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  6759. // }
  6760. // }
  6761. // catch (Exception ex)
  6762. // {
  6763. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  6764. // string str = ex.StackTrace;
  6765. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6766. // }
  6767. // #endregion Tray盘上料装备-将SN发给ICT标机
  6768. // #region Tray盘上料装备-点检数据
  6769. // //try
  6770. // //{
  6771. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  6772. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  6773. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  6774. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  6775. // // if (pLC_Flag && !mES_Flag) // 1 0
  6776. // // {
  6777. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  6778. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  6779. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  6780. // // }
  6781. // // else if (!pLC_Flag && mES_Flag) // 0 1
  6782. // // {
  6783. // // // 清空写给PLC的数据
  6784. // // // MES_Flag重置为0
  6785. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  6786. // // }
  6787. // //}
  6788. // //catch (Exception ex)
  6789. // //{
  6790. // // // MES_Flag 为2上位机报错
  6791. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  6792. // // string str = ex.StackTrace;
  6793. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6794. // //}
  6795. // #endregion Tray盘上料装备-点检数据
  6796. // #region 节拍接口
  6797. // try
  6798. // {
  6799. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  6800. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  6801. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  6802. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  6803. // {
  6804. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  6805. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6806. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  6807. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  6808. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  6809. // }
  6810. // }
  6811. // catch (Exception ex)
  6812. // {
  6813. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  6814. // string str = ex.StackTrace;
  6815. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6816. // }
  6817. // #endregion 节拍接口
  6818. // #region AGV上料
  6819. // // AGV上料叫AGV信号
  6820. // try
  6821. // {
  6822. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  6823. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  6824. // if (a1AGVUpCall != a1AGVUpCallOld)
  6825. // {
  6826. // if (a1AGVUpCall == 1) // 0->1
  6827. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  6828. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  6829. // }
  6830. // }
  6831. // catch (Exception ex)
  6832. // {
  6833. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  6834. // string str = ex.StackTrace;
  6835. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6836. // }
  6837. // // AGV上料完成信号
  6838. // try
  6839. // {
  6840. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  6841. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  6842. // if (a1AGVUpEnd != a1AGVUpEndOld)
  6843. // {
  6844. // if (a1AGVUpEnd == 1) // 0->1
  6845. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  6846. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  6847. // }
  6848. // }
  6849. // catch (Exception ex)
  6850. // {
  6851. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  6852. // string str = ex.StackTrace;
  6853. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6854. // }
  6855. // #endregion AGV上料
  6856. // #region AGV下料
  6857. // // AGV下料叫agv信号
  6858. // try
  6859. // {
  6860. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  6861. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  6862. // if (a1AGVDownCall != a1AGVDownCallOld)
  6863. // {
  6864. // if (a1AGVDownCall == 1) // 0->1
  6865. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  6866. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  6867. // }
  6868. // }
  6869. // catch (Exception ex)
  6870. // {
  6871. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  6872. // string str = ex.StackTrace;
  6873. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6874. // }
  6875. // // AGV下料完成信号
  6876. // try
  6877. // {
  6878. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  6879. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  6880. // if (a1AGVDownEnd != a1AGVDownEndOld)
  6881. // {
  6882. // if (a1AGVDownEnd == 1) // 0->1
  6883. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  6884. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  6885. // }
  6886. // }
  6887. // catch (Exception ex)
  6888. // {
  6889. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  6890. // string str = ex.StackTrace;
  6891. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6892. // }
  6893. // #endregion AGV下料
  6894. // #region 心跳
  6895. // try
  6896. // {
  6897. // short states = 0;
  6898. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  6899. // }
  6900. // catch (Exception ex)
  6901. // {
  6902. // string str = ex.StackTrace;
  6903. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6904. // }
  6905. // #endregion 心跳
  6906. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6907. // stopwatch1.Stop();
  6908. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  6909. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6910. // }
  6911. // else
  6912. // {
  6913. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6914. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6915. // Funs[plcNo].Connect(); // 重连
  6916. // }
  6917. // }
  6918. // catch (Exception ex)
  6919. // {
  6920. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6921. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6922. // Funs[plcNo].ReConnect();
  6923. // }
  6924. // Thread.Sleep(IntervalReadPLC);
  6925. // }
  6926. //}
  6927. /// <summary>
  6928. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  6929. /// </summary>
  6930. /// <param name="plcNo">PLC编号</param>
  6931. /// <param name="stationNameStr">工站全称</param>
  6932. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  6933. {
  6934. Stopwatch stopwatch1 = new Stopwatch();
  6935. Stopwatch stopwatch2 = new Stopwatch();
  6936. try
  6937. {
  6938. stopwatch1.Start();
  6939. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  6940. sn = sn.Replace("\0", "");
  6941. #region 查询载具上的产品信息
  6942. string cavityData = string.Empty;
  6943. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6944. if (string.IsNullOrEmpty(cavityData))
  6945. cavityData = "";
  6946. if (snResult != 0)
  6947. {
  6948. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6949. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  6950. writeToPLC_Flag1.Adress = 2003;
  6951. writeToPLC_Flag1.Value = (short)6;
  6952. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  6953. stopwatch1.Stop();
  6954. AddMessage(LogType.Info,
  6955. stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  6956. "ms");
  6957. return;
  6958. }
  6959. #endregion 查询载具上的产品信息
  6960. string[] cavitySNs = cavityData.Split('.');
  6961. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  6962. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  6963. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  6964. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  6965. if (cavitySNs != null && cavitySNs.Length >= 2)
  6966. {
  6967. a1CavitySN1_VehicleStates = cavitySNs[0];
  6968. a1CavitySN2_VehicleStates = cavitySNs[1];
  6969. a1CavityResult1_VehicleStates = 2;
  6970. a1CavityResult2_VehicleStates = 2;
  6971. }
  6972. if (a1CavitySN1_VehicleStates == "假产品")
  6973. a1CavityResult1_VehicleStates = 3;
  6974. if (a1CavitySN2_VehicleStates == "假产品")
  6975. a1CavityResult2_VehicleStates = 3;
  6976. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6977. // 回写
  6978. stopwatch2.Start();
  6979. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  6980. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  6981. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  6982. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  6983. //// MES_Flag
  6984. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  6985. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6986. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  6987. writeToPLC_Flag.Adress = 2003;
  6988. writeToPLC_Flag.Value = mES_Flag;
  6989. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  6990. {
  6991. Name = "a1CavitySN1_VehicleStates",
  6992. Adress = 2024,
  6993. ValueType = PLCValueType.String,
  6994. ValueTypeStrLength = 20,
  6995. Value = a1CavitySN1_VehicleStates
  6996. });
  6997. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  6998. {
  6999. Name = "a1CavitySN2_VehicleStates",
  7000. Adress = 2044,
  7001. ValueType = PLCValueType.String,
  7002. ValueTypeStrLength = 20,
  7003. Value = a1CavitySN2_VehicleStates
  7004. });
  7005. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  7006. {
  7007. Name = "a1CavityResult1_VehicleStates",
  7008. Adress = 2064,
  7009. ValueType = PLCValueType.Short,
  7010. Value = a1CavityResult1_VehicleStates
  7011. });
  7012. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  7013. {
  7014. Name = "a1CavityResult2_VehicleStates",
  7015. Adress = 2065,
  7016. ValueType = PLCValueType.Short,
  7017. Value = a1CavityResult2_VehicleStates
  7018. });
  7019. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  7020. stopwatch2.Stop();
  7021. }
  7022. catch (Exception ex)
  7023. {
  7024. string str = ex.StackTrace;
  7025. AddMessage_Station(stationNameStr, LogType.Error,
  7026. $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" +
  7027. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7028. // MES_Flag
  7029. stopwatch2.Start();
  7030. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7031. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7032. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  7033. writeToPLC_Flag.Adress = 2003;
  7034. writeToPLC_Flag.Value = (short)6;
  7035. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  7036. stopwatch2.Stop();
  7037. }
  7038. stopwatch1.Stop();
  7039. AddMessage(LogType.Info,
  7040. stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7041. stopwatch2.ElapsedMilliseconds + "ms");
  7042. }
  7043. /// <summary>
  7044. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  7045. /// </summary>
  7046. /// <param name="plcNo">PLC编号</param>
  7047. /// <param name="stationNameStr">工站全称</param>
  7048. private void S1上料进站校验(int plcNo, string stationNameStr)
  7049. {
  7050. Stopwatch stopwatch1 = new Stopwatch();
  7051. Stopwatch stopwatch2 = new Stopwatch();
  7052. try
  7053. {
  7054. stopwatch1.Start();
  7055. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  7056. sn = sn.Replace("\0", "");
  7057. // 保存进站数据+调用进站MES接口
  7058. List<TestItem> item = new List<TestItem>();
  7059. stopwatch2.Start();
  7060. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  7061. item, out string errorMsg);
  7062. stopwatch2.Stop();
  7063. short a1MES_FLAG_Check = (short)result;
  7064. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7065. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7066. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  7067. writeToPLC_Flag.Adress = 2077;
  7068. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  7069. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  7070. }
  7071. catch (Exception ex)
  7072. {
  7073. string str = ex.StackTrace;
  7074. AddMessage_Station(stationNameStr, LogType.Error,
  7075. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  7076. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7077. // MES_Flag
  7078. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7079. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7080. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  7081. writeToPLC_Flag.Adress = 2077;
  7082. writeToPLC_Flag.Value = (short)6;
  7083. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  7084. }
  7085. stopwatch1.Stop();
  7086. AddMessage(LogType.Info,
  7087. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  7088. stopwatch2.ElapsedMilliseconds + "ms");
  7089. }
  7090. /// <summary>
  7091. /// [S1] Tray盘上料装备(板测)- 出站接口
  7092. /// </summary>
  7093. /// <param name="plcNo"></param>
  7094. /// <param name="stationCode"></param>
  7095. /// <param name="stationName"></param>
  7096. private void S1出站接口(int plcNo, string stationCode, string stationName)
  7097. {
  7098. Stopwatch stopwatch1 = new Stopwatch();
  7099. Stopwatch stopwatch2 = new Stopwatch();
  7100. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7101. string stationNameStr = stationCode + stationName;
  7102. string processItem = stationName; // 测试项目
  7103. try
  7104. {
  7105. stopwatch1.Start();
  7106. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7107. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7108. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7109. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7110. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  7111. sn = sn.Replace("\0", "");
  7112. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  7113. partNo1 = partNo1.Replace("\0", "");
  7114. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  7115. partNo2 = partNo2.Replace("\0", "");
  7116. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  7117. bool pass = a1Result == 1;
  7118. stopwatch2.Start();
  7119. // 产品1
  7120. List<TestItem> items = new List<TestItem>();
  7121. items.Add(new TestItem()
  7122. {
  7123. Parameter_name = "载具码",
  7124. Parameter_value = sn,
  7125. Parameter_unit = ""
  7126. });
  7127. items.Add(new TestItem()
  7128. {
  7129. Parameter_name = "载具穴号",
  7130. Parameter_value = "1",
  7131. Parameter_unit = ""
  7132. });
  7133. items.Add(new TestItem()
  7134. {
  7135. Parameter_name = "产品结果",
  7136. Parameter_value = a1Result == 1 ? "OK" : "NG",
  7137. Parameter_unit = ""
  7138. });
  7139. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  7140. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  7141. // 产品2
  7142. items = new List<TestItem>();
  7143. items.Add(new TestItem()
  7144. {
  7145. Parameter_name = "载具码",
  7146. Parameter_value = sn,
  7147. Parameter_unit = ""
  7148. });
  7149. items.Add(new TestItem()
  7150. {
  7151. Parameter_name = "载具穴号",
  7152. Parameter_value = "2",
  7153. Parameter_unit = ""
  7154. });
  7155. items.Add(new TestItem()
  7156. {
  7157. Parameter_name = "产品结果",
  7158. Parameter_value = a1Result == 1 ? "OK" : "NG",
  7159. Parameter_unit = ""
  7160. });
  7161. int result2 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  7162. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  7163. short result = 0;
  7164. List<int> results = new List<int>() { result1, result2 };
  7165. if (result1 == 1 && result2 == 1)
  7166. result = 1;
  7167. else if (results.Contains(3))
  7168. result = 3;
  7169. else if (results.Contains(2))
  7170. result = 2;
  7171. else if (results.Contains(4))
  7172. result = 4;
  7173. else
  7174. result = 4;
  7175. stopwatch2.Stop();
  7176. #region 存储绑定数据到 边线MES系统中
  7177. if (result == 1)
  7178. {
  7179. string data = string.Concat(partNo1, ".", partNo2);
  7180. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7181. if (resultMesR != 0)
  7182. {
  7183. result = 4;
  7184. AddMessage_Station(stationNameStr, LogType.Error,
  7185. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  7186. }
  7187. }
  7188. #endregion 存储绑定数据到 边线MES系统中
  7189. // MES_Flag 为MES报错
  7190. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7191. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  7192. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7193. writeToPLC_Flag.Name = "a1MES_FLAG";
  7194. writeToPLC_Flag.Adress = 2109;
  7195. writeToPLC_Flag.Value = result;
  7196. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  7197. OnMessage(LogType.Debug,
  7198. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7199. }
  7200. catch (Exception ex)
  7201. {
  7202. stopwatch2.Restart();
  7203. // MES_Flag 为4上位机报错
  7204. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  7205. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7206. writeToPLC_Flag.Name = "a1MES_FLAG";
  7207. writeToPLC_Flag.Adress = 2109;
  7208. writeToPLC_Flag.Value = (short)4;
  7209. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  7210. stopwatch2.Stop();
  7211. string str = ex.StackTrace;
  7212. AddMessage_Station(stationNameStr, LogType.Error,
  7213. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  7214. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7215. }
  7216. stopwatch1.Stop();
  7217. AddMessage(LogType.Info,
  7218. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  7219. stopwatch2.ElapsedMilliseconds + "ms");
  7220. }
  7221. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  7222. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  7223. //{
  7224. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7225. // string stationNameStr = stationCode + stationName;
  7226. // string processItem = stationName; // 测试项目
  7227. // try
  7228. // {
  7229. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7230. // string accno = "1"; // 工序编号
  7231. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  7232. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  7233. // List<OneCheckItem> items = new List<OneCheckItem>()
  7234. // {
  7235. // new OneCheckItem()
  7236. // {
  7237. // Onecheck_name="胶圈装配行程设定上限",
  7238. // Onecheck_content="上限值",
  7239. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  7240. // },
  7241. // };
  7242. // OneCheckData oneCheckData = new OneCheckData()
  7243. // {
  7244. // Line_code = GlobalContext.LineCode,
  7245. // Line_name = GlobalContext.LineName,
  7246. // Equipment_code = equipmentCode,
  7247. // Equipment_name = equipmentCode,
  7248. // Workorder_code = workorder_code,
  7249. // Procedure_code = accno,
  7250. // Procedure_name = processItem,
  7251. // Oneckeck_values = items,
  7252. // Onecheck_empcode = "",
  7253. // Onecheck_empname = "",
  7254. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  7255. // };
  7256. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  7257. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  7258. // short result = result1 == 1 ? (short)1 : (short)2;
  7259. // // MES_Flag 为4MES报错
  7260. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  7261. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7262. // }
  7263. // catch (Exception ex)
  7264. // {
  7265. // // MES_Flag 为2上位机报错
  7266. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  7267. // string str = ex.StackTrace;
  7268. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7269. // }
  7270. //}
  7271. // ReadStation_S1_2 节拍接口+AGV
  7272. /// <summary>
  7273. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  7274. /// </summary>
  7275. /// <param name="plcNo">PLC编号</param>
  7276. /// <param name="stationNameStr">工站全称</param>
  7277. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  7278. {
  7279. Stopwatch stopwatch1 = new Stopwatch();
  7280. Stopwatch stopwatch2 = new Stopwatch();
  7281. try
  7282. {
  7283. stopwatch1.Start();
  7284. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  7285. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  7286. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  7287. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  7288. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  7289. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  7290. // ZS 将SN发给ICT标机(串口)
  7291. short a1MES_FLAG_ICT = 1;
  7292. stopwatch2.Start();
  7293. // MES_Flag
  7294. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  7295. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7296. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  7297. writeToPLC_Flag.Adress = 2182;
  7298. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  7299. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  7300. stopwatch2.Stop();
  7301. }
  7302. catch (Exception ex)
  7303. {
  7304. string str = ex.StackTrace;
  7305. AddMessage_Station(stationNameStr, LogType.Error,
  7306. $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" +
  7307. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7308. stopwatch2.Start();
  7309. // MES_Flag
  7310. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  7311. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7312. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  7313. writeToPLC_Flag.Adress = 2182;
  7314. writeToPLC_Flag.Value = (short)4;
  7315. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  7316. stopwatch2.Stop();
  7317. }
  7318. stopwatch1.Stop();
  7319. AddMessage(LogType.Info,
  7320. stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7321. stopwatch2.ElapsedMilliseconds + "ms");
  7322. }
  7323. /// <summary>
  7324. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  7325. /// </summary>
  7326. /// <param name="plcNo">PLC编号</param>
  7327. /// <param name="stationNameStr">工站全称</param>
  7328. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  7329. {
  7330. Stopwatch stopwatch1 = new Stopwatch();
  7331. Stopwatch stopwatch2 = new Stopwatch();
  7332. try
  7333. {
  7334. stopwatch1.Start();
  7335. // ZS 呼叫AGV
  7336. short a1AGVUpCall = 2;
  7337. stopwatch2.Start();
  7338. // a1AGVUpCall
  7339. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7340. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7341. writeToPLC_Flag.Name = "a1AGVUpCall";
  7342. writeToPLC_Flag.Adress = 2307;
  7343. writeToPLC_Flag.Value = a1AGVUpCall;
  7344. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  7345. stopwatch2.Stop();
  7346. }
  7347. catch (Exception ex)
  7348. {
  7349. string str = ex.StackTrace;
  7350. AddMessage_Station(stationNameStr, LogType.Error,
  7351. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  7352. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7353. // a1AGVUpCall
  7354. stopwatch2.Start();
  7355. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  7356. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7357. writeToPLC_Flag.Name = "a1AGVUpCall";
  7358. writeToPLC_Flag.Adress = 2307;
  7359. writeToPLC_Flag.Value = (short)4;
  7360. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  7361. stopwatch2.Stop();
  7362. }
  7363. stopwatch1.Stop();
  7364. AddMessage(LogType.Info,
  7365. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7366. stopwatch2.ElapsedMilliseconds + "ms");
  7367. }
  7368. /// <summary>
  7369. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  7370. /// </summary>
  7371. /// <param name="plcNo">PLC编号</param>
  7372. /// <param name="stationNameStr">工站全称</param>
  7373. private void S1AGV上料完成(int plcNo, string stationNameStr)
  7374. {
  7375. Stopwatch stopwatch1 = new Stopwatch();
  7376. Stopwatch stopwatch2 = new Stopwatch();
  7377. try
  7378. {
  7379. stopwatch1.Start();
  7380. // ZS AGV上料完成,让小车离开
  7381. short a1AGVUpEnd = 2;
  7382. stopwatch2.Start();
  7383. // a1AGVUpEnd
  7384. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7385. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7386. writeToPLC_Flag.Name = "a1AGVUpEnd";
  7387. writeToPLC_Flag.Adress = 2309;
  7388. writeToPLC_Flag.Value = a1AGVUpEnd;
  7389. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  7390. stopwatch2.Stop();
  7391. }
  7392. catch (Exception ex)
  7393. {
  7394. string str = ex.StackTrace;
  7395. AddMessage_Station(stationNameStr, LogType.Error,
  7396. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  7397. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7398. // a1AGVUpEnd
  7399. stopwatch2.Start();
  7400. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  7401. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7402. writeToPLC_Flag.Name = "a1AGVUpEnd";
  7403. writeToPLC_Flag.Adress = 2309;
  7404. writeToPLC_Flag.Value = (short)4;
  7405. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  7406. stopwatch2.Stop();
  7407. }
  7408. stopwatch1.Stop();
  7409. AddMessage(LogType.Info,
  7410. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7411. stopwatch2.ElapsedMilliseconds + "ms");
  7412. }
  7413. /// <summary>
  7414. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  7415. /// </summary>
  7416. /// <param name="plcNo">PLC编号</param>
  7417. /// <param name="stationNameStr">工站全称</param>
  7418. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  7419. {
  7420. Stopwatch stopwatch1 = new Stopwatch();
  7421. Stopwatch stopwatch2 = new Stopwatch();
  7422. try
  7423. {
  7424. stopwatch1.Start();
  7425. // ZS 呼叫AGV
  7426. short a1AGVDownCall = 2;
  7427. stopwatch2.Start();
  7428. // a1AGVDownCall
  7429. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7430. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7431. writeToPLC_Flag.Name = "a1AGVDownCall";
  7432. writeToPLC_Flag.Adress = 2320;
  7433. writeToPLC_Flag.Value = a1AGVDownCall;
  7434. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  7435. stopwatch2.Stop();
  7436. }
  7437. catch (Exception ex)
  7438. {
  7439. string str = ex.StackTrace;
  7440. AddMessage_Station(stationNameStr, LogType.Error,
  7441. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  7442. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7443. // a1AGVDownCall
  7444. stopwatch2.Start();
  7445. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  7446. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7447. writeToPLC_Flag.Name = "a1AGVDownCall";
  7448. writeToPLC_Flag.Adress = 2320;
  7449. writeToPLC_Flag.Value = (short)4;
  7450. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  7451. stopwatch2.Stop();
  7452. }
  7453. stopwatch1.Stop();
  7454. AddMessage(LogType.Info,
  7455. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7456. stopwatch2.ElapsedMilliseconds + "ms");
  7457. }
  7458. /// <summary>
  7459. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  7460. /// </summary>
  7461. /// <param name="plcNo">PLC编号</param>
  7462. /// <param name="stationNameStr">工站全称</param>
  7463. private void S1AGV下料完成(int plcNo, string stationNameStr)
  7464. {
  7465. Stopwatch stopwatch1 = new Stopwatch();
  7466. Stopwatch stopwatch2 = new Stopwatch();
  7467. try
  7468. {
  7469. stopwatch1.Start();
  7470. // ZS AGV上料完成,让小车离开
  7471. short a1AGVDownEnd = 2;
  7472. stopwatch2.Start();
  7473. // a1AGVDownEnd
  7474. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7475. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7476. writeToPLC_Flag.Name = "a1AGVDownEnd";
  7477. writeToPLC_Flag.Adress = 2322;
  7478. writeToPLC_Flag.Value = a1AGVDownEnd;
  7479. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  7480. stopwatch2.Stop();
  7481. }
  7482. catch (Exception ex)
  7483. {
  7484. string str = ex.StackTrace;
  7485. AddMessage_Station(stationNameStr, LogType.Error,
  7486. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  7487. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7488. // a1AGVDownEnd
  7489. stopwatch2.Start();
  7490. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  7491. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7492. writeToPLC_Flag.Name = "a1AGVDownEnd";
  7493. writeToPLC_Flag.Adress = 2322;
  7494. writeToPLC_Flag.Value = (short)4;
  7495. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  7496. stopwatch2.Stop();
  7497. }
  7498. stopwatch1.Stop();
  7499. AddMessage(LogType.Info,
  7500. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7501. stopwatch2.ElapsedMilliseconds + "ms");
  7502. }
  7503. #endregion [S1] Tray盘上料装备(板测)
  7504. #endregion PLC1 张超凡
  7505. #region PLC2 李晓奇
  7506. #region [S2] FCT(板测)
  7507. /// <summary>
  7508. /// S2工位的数据- 触发信号上次的值
  7509. /// </summary>
  7510. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  7511. /// <summary>
  7512. /// S2工位的数据(含触发信号)
  7513. /// </summary>
  7514. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  7515. /// <summary>
  7516. /// S2工位的数据- 回写点位
  7517. /// </summary>
  7518. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  7519. /// <summary>
  7520. /// [S2] FCT(板测)
  7521. /// </summary>
  7522. /// <param name="plcNo">PLC编号</param>
  7523. //private void ReadStation_S2(int plcNo)
  7524. //{
  7525. // // [S1] Tray盘上料装备
  7526. // // [S2] FCT
  7527. // // [S3] 值板机
  7528. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  7529. // // [S5] Tray盘下料装备
  7530. // /// 上位机心跳
  7531. // /// 获取设备报警数据与状态信息
  7532. // string stationCode = "[S2]";
  7533. // string stationName = "FCT";
  7534. // string stationNameStr = stationCode + stationName;
  7535. // #region 创建字典
  7536. // // 触发信号字典 赋值
  7537. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  7538. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  7539. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  7540. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  7541. // // PLC数据字典 赋值
  7542. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  7543. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  7544. // s2PLCData.Add("b1ProductSN_Check", 0);
  7545. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  7546. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  7547. // s2PLCData.Add("b1ProductSN_Unbind", "");
  7548. // s2PLCData.Add("b1ProductSN_Bind", "");
  7549. // s2PLCData.Add("b1Part1SN_Bind", "");
  7550. // s2PLCData.Add("b1Part2SN_Bind", "");
  7551. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  7552. // s2PLCData.Add("b1MES_FLAG", 0);
  7553. // s2PLCData.Add("b1ProductSN", 0);
  7554. // s2PLCData.Add("b1Part1Result", 0);
  7555. // s2PLCData.Add("b1Part2Result", 0);
  7556. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  7557. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  7558. // s2PLCData.Add("b1OEEProductSN", "");
  7559. // s2PLCData.Add("b1OEEType", 0);
  7560. // #endregion 创建字典
  7561. // while (IsRun)
  7562. // {
  7563. // try
  7564. // {
  7565. // if (!GlobalContext._IsCon_Funs2)
  7566. // {
  7567. // UpdatePLCMonitor(1, plcNo, 0);
  7568. // continue;
  7569. // }
  7570. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  7571. // {
  7572. // Stopwatch stopwatch1 = new Stopwatch();
  7573. // Stopwatch stopwatch2 = new Stopwatch();
  7574. // stopwatch1.Start();
  7575. // stopwatch2.Start();
  7576. // #region 一次性读取所有数据
  7577. // // 一次性读取所有数据
  7578. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  7579. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  7580. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  7581. // int[] datas = data1.Concat(data2).ToArray();
  7582. // datas = datas.Concat(data3).ToArray();
  7583. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  7584. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  7585. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  7586. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  7587. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  7588. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  7589. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  7590. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  7591. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  7592. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  7593. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  7594. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  7595. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  7596. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  7597. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  7598. // s2PLCData["b1MES_FLAG"] = datas[169];
  7599. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  7600. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  7601. // s2PLCData["b1Part1Result"] = datas[190];
  7602. // s2PLCData["b1Part2Result"] = datas[191];
  7603. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  7604. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  7605. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  7606. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  7607. // s2PLCData["b1OEEType"] = datas[224];
  7608. // #endregion 一次性读取所有数据
  7609. // stopwatch2.Stop();
  7610. // #region 回写操作,写后清空flag
  7611. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  7612. // #endregion 回写操作,写后清空flag
  7613. // #region 进站校验
  7614. // try
  7615. // {
  7616. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  7617. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  7618. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  7619. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  7620. // {
  7621. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  7622. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  7623. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  7624. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  7625. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  7626. // }
  7627. // }
  7628. // catch (Exception ex)
  7629. // {
  7630. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7631. // string str = ex.StackTrace;
  7632. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7633. // }
  7634. // #endregion 进站校验
  7635. // #region 二穴载具解绑/绑定(产品换载具)
  7636. // try
  7637. // {
  7638. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  7639. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  7640. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  7641. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  7642. // {
  7643. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  7644. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  7645. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  7646. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  7647. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  7648. // }
  7649. // }
  7650. // catch (Exception ex)
  7651. // {
  7652. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7653. // string str = ex.StackTrace;
  7654. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7655. // }
  7656. // #endregion 二穴载具解绑/绑定(产品换载具)
  7657. // #region FCT-出站接口
  7658. // try
  7659. // {
  7660. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  7661. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  7662. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  7663. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  7664. // {
  7665. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  7666. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  7667. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  7668. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  7669. // }
  7670. // }
  7671. // catch (Exception ex)
  7672. // {
  7673. // // MES_Flag 为6上位机报错
  7674. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  7675. // string str = ex.StackTrace;
  7676. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7677. // }
  7678. // #endregion FCT-出站接口
  7679. // #region 节拍接口
  7680. // try
  7681. // {
  7682. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  7683. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  7684. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  7685. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  7686. // {
  7687. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  7688. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7689. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  7690. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  7691. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  7692. // }
  7693. // }
  7694. // catch (Exception ex)
  7695. // {
  7696. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  7697. // string str = ex.StackTrace;
  7698. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7699. // }
  7700. // #endregion 节拍接口
  7701. // #region 心跳
  7702. // try
  7703. // {
  7704. // short states = 0;
  7705. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7706. // }
  7707. // catch (Exception ex)
  7708. // {
  7709. // string str = ex.StackTrace;
  7710. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7711. // }
  7712. // #endregion 心跳
  7713. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7714. // stopwatch1.Stop();
  7715. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7716. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7717. // }
  7718. // else
  7719. // {
  7720. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7721. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  7722. // Funs[plcNo].Connect();
  7723. // }
  7724. // }
  7725. // catch (Exception ex)
  7726. // {
  7727. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7728. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  7729. // Funs[plcNo].ReConnect();
  7730. // }
  7731. // Thread.Sleep(IntervalReadPLC);
  7732. // }
  7733. //}
  7734. /// <summary>
  7735. /// [S2] FCT(板测)- 进站校验
  7736. /// </summary>
  7737. /// <param name="plcNo">PLC编号</param>
  7738. /// <param name="stationNameStr">工站全称</param>
  7739. private void S2进站校验(int plcNo, string stationNameStr)
  7740. {
  7741. Stopwatch stopwatch1 = new Stopwatch();
  7742. Stopwatch stopwatch2 = new Stopwatch();
  7743. try
  7744. {
  7745. stopwatch1.Start();
  7746. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  7747. sn = sn.Replace("\0", "");
  7748. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  7749. // 查询物料码By载具码 并判断是不是假产品
  7750. string cavityData = string.Empty;
  7751. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  7752. if (string.IsNullOrEmpty(cavityData))
  7753. cavityData = "";
  7754. if (snResult != 0)
  7755. {
  7756. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7757. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  7758. writeToPLC_Flag1.Adress = 2003;
  7759. writeToPLC_Flag1.Value = (short)6;
  7760. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  7761. stopwatch1.Stop();
  7762. AddMessage(LogType.Info,
  7763. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7764. return;
  7765. }
  7766. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  7767. string[] cavitySNs = cavityData.Split('.');
  7768. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  7769. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  7770. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  7771. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  7772. if (cavitySNs != null && cavitySNs.Length >= 2)
  7773. {
  7774. b1Part1SN_Check = cavitySNs[0];
  7775. b1Part2SN_Check = cavitySNs[1];
  7776. b1Part1Result_Check = 2;
  7777. b1Part2Result_Check = 2;
  7778. }
  7779. if (b1Part1SN_Check == "假产品")
  7780. b1Part1Result_Check = 3;
  7781. if (b1Part2SN_Check == "假产品")
  7782. b1Part2Result_Check = 3;
  7783. // 调用MES进站
  7784. stopwatch2.Start();
  7785. // 调用MES进站 - 产品1
  7786. List<TestItem> item;
  7787. int result1 = b1Part1Result_Check;
  7788. if (result1 != 3)
  7789. {
  7790. item = new List<TestItem>();
  7791. item.Add(new TestItem()
  7792. {
  7793. Parameter_name = "载具码",
  7794. Parameter_value = sn,
  7795. });
  7796. item.Add(new TestItem()
  7797. {
  7798. Parameter_name = "载具穴号",
  7799. Parameter_value = "1",
  7800. });
  7801. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  7802. b1Part1SN_Check, item, out string errorMsg);
  7803. }
  7804. // 调用MES进站 - 产品2
  7805. int result2 = b1Part2Result_Check;
  7806. if (result2 != 3)
  7807. {
  7808. item = new List<TestItem>();
  7809. item.Add(new TestItem()
  7810. {
  7811. Parameter_name = "载具码",
  7812. Parameter_value = sn,
  7813. });
  7814. item.Add(new TestItem()
  7815. {
  7816. Parameter_name = "载具穴号",
  7817. Parameter_value = "2",
  7818. });
  7819. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  7820. b1Part2SN_Check, item, out string errorMsg);
  7821. }
  7822. stopwatch2.Stop();
  7823. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  7824. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  7825. int result = result1;
  7826. if (result == 1)
  7827. result = result2;
  7828. short b1MES_FLAG_Check = (short)result;
  7829. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  7830. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  7831. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  7832. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  7833. //// MES_Flag
  7834. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7835. WriteToPLC_Flag
  7836. writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7837. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  7838. writeToPLC_Flag.Adress = 2003;
  7839. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  7840. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7841. {
  7842. Name = "b1Part1SN_Check",
  7843. Adress = 2024,
  7844. ValueType = PLCValueType.String,
  7845. ValueTypeStrLength = 20,
  7846. Value = b1Part1SN_Check
  7847. });
  7848. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7849. {
  7850. Name = "b1Part2SN_Check",
  7851. Adress = 2044,
  7852. ValueType = PLCValueType.String,
  7853. ValueTypeStrLength = 20,
  7854. Value = b1Part2SN_Check
  7855. });
  7856. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7857. {
  7858. Name = "b1Part1Result_Check",
  7859. Adress = 2064,
  7860. ValueType = PLCValueType.Short,
  7861. Value = b1Part1Result_Check
  7862. });
  7863. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7864. {
  7865. Name = "b1Part2Result_Check",
  7866. Adress = 2065,
  7867. ValueType = PLCValueType.Short,
  7868. Value = b1Part2Result_Check
  7869. });
  7870. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  7871. }
  7872. catch (Exception ex)
  7873. {
  7874. string str = ex.StackTrace;
  7875. AddMessage_Station(stationNameStr, LogType.Error,
  7876. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  7877. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7878. // MES_Flag
  7879. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7880. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7881. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  7882. writeToPLC_Flag.Adress = 2003;
  7883. writeToPLC_Flag.Value = (short)6;
  7884. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  7885. }
  7886. stopwatch1.Stop();
  7887. AddMessage(LogType.Info,
  7888. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  7889. stopwatch2.ElapsedMilliseconds + "ms");
  7890. }
  7891. /// <summary>
  7892. /// [S2] FCT(板测)- 二穴载具解绑绑定
  7893. /// </summary>
  7894. /// <param name="plcNo">PLC编号</param>
  7895. /// <param name="stationNameStr">工站全称</param>
  7896. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  7897. {
  7898. Stopwatch stopwatch1 = new Stopwatch();
  7899. Stopwatch stopwatch2 = new Stopwatch();
  7900. try
  7901. {
  7902. stopwatch1.Start();
  7903. // 产品换载具
  7904. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  7905. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  7906. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  7907. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  7908. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  7909. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  7910. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  7911. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  7912. stopwatch2.Start();
  7913. #region 查询载具上的产品信息
  7914. //string cavityData = string.Empty;
  7915. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  7916. //if (string.IsNullOrEmpty(cavityData))
  7917. // cavityData = "";
  7918. //if (snResult != 0)
  7919. //{
  7920. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7921. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  7922. // writeToPLC_Flag.Adress = 2077;
  7923. // writeToPLC_Flag.Value = (short)6;
  7924. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  7925. // stopwatch1.Stop();
  7926. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7927. // return;
  7928. //}
  7929. #endregion 查询载具上的产品信息
  7930. #region 解绑(边线MES系统)
  7931. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  7932. if (snResult != 0)
  7933. {
  7934. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7935. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  7936. writeToPLC_Flag1.Adress = 2077;
  7937. writeToPLC_Flag1.Value = (short)6;
  7938. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  7939. stopwatch1.Stop();
  7940. AddMessage(LogType.Info,
  7941. stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" +
  7942. stopwatch1.ElapsedMilliseconds + "ms");
  7943. return;
  7944. }
  7945. #endregion 解绑(边线MES系统)
  7946. #region 存储绑定数据到 边线MES系统中
  7947. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  7948. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  7949. if (snResult != 0)
  7950. {
  7951. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7952. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  7953. writeToPLC_Flag1.Adress = 2077;
  7954. writeToPLC_Flag1.Value = (short)6;
  7955. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  7956. stopwatch1.Stop();
  7957. AddMessage(LogType.Info,
  7958. stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" +
  7959. stopwatch1.ElapsedMilliseconds + "ms");
  7960. return;
  7961. }
  7962. #endregion 存储绑定数据到 边线MES系统中
  7963. stopwatch2.Stop();
  7964. short b1MES_FLAG_Unbind = 1;
  7965. // MES_Flag
  7966. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7967. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7968. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  7969. writeToPLC_Flag.Adress = 2077;
  7970. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  7971. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  7972. }
  7973. catch (Exception ex)
  7974. {
  7975. string str = ex.StackTrace;
  7976. AddMessage_Station(stationNameStr, LogType.Error,
  7977. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" +
  7978. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7979. // MES_Flag
  7980. stopwatch2.Start();
  7981. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7982. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7983. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  7984. writeToPLC_Flag.Adress = 2077;
  7985. writeToPLC_Flag.Value = (short)6;
  7986. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  7987. stopwatch2.Stop();
  7988. }
  7989. stopwatch1.Stop();
  7990. AddMessage(LogType.Info,
  7991. stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7992. stopwatch2.ElapsedMilliseconds + "ms");
  7993. }
  7994. //// 上次采集到的SN
  7995. //private string sn_FCT = string.Empty;
  7996. /// <summary>
  7997. /// [S2] FCT(板测)- 出站数据
  7998. /// </summary>
  7999. private void S2出站接口(int plcNo, string stationCode, string stationName)
  8000. {
  8001. Stopwatch stopwatch1 = new Stopwatch();
  8002. Stopwatch stopwatch2 = new Stopwatch();
  8003. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8004. string stationNameStr = stationCode + stationName;
  8005. string processItem = stationName; // 测试项目
  8006. try
  8007. {
  8008. stopwatch1.Start();
  8009. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8010. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8011. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8012. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8013. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  8014. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  8015. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  8016. bool pass1 = b1Part1Result == 1;
  8017. bool pass2 = b1Part2Result == 1;
  8018. #region 根据 载具SN 查 物料SN
  8019. string cavityData = string.Empty;
  8020. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  8021. if (string.IsNullOrEmpty(cavityData))
  8022. cavityData = "";
  8023. if (snResult != 0)
  8024. {
  8025. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8026. writeToPLC_Flag1.Name = "b1MES_FLAG";
  8027. writeToPLC_Flag1.Adress = 2169;
  8028. writeToPLC_Flag1.Value = (short)4;
  8029. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  8030. stopwatch1.Stop();
  8031. AddMessage(LogType.Info,
  8032. stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8033. "ms");
  8034. return;
  8035. }
  8036. #endregion 根据 载具SN 查 物料SN
  8037. string[] cavitySNs = cavityData.Split('.');
  8038. string b1ProductSN1 = string.Empty;
  8039. string b1ProductSN2 = string.Empty;
  8040. if (cavitySNs != null && cavitySNs.Length >= 2)
  8041. {
  8042. b1ProductSN1 = cavitySNs[0];
  8043. b1ProductSN2 = cavitySNs[1];
  8044. }
  8045. stopwatch2.Start();
  8046. // 产品1
  8047. int result1 = 0;
  8048. if (b1ProductSN1 == "假产品")
  8049. result1 = 1;
  8050. else
  8051. {
  8052. List<TestItem> items1 = new List<TestItem>();
  8053. items1.Add(new TestItem()
  8054. {
  8055. Parameter_name = "载具码",
  8056. Parameter_value = b1ProductSN.ToString(),
  8057. Parameter_unit = ""
  8058. });
  8059. items1.Add(new TestItem()
  8060. {
  8061. Parameter_name = "载具穴号",
  8062. Parameter_value = "1",
  8063. Parameter_unit = ""
  8064. });
  8065. items1.Add(new TestItem()
  8066. {
  8067. Parameter_name = "产品结果",
  8068. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  8069. Parameter_unit = ""
  8070. });
  8071. result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  8072. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  8073. }
  8074. // 产品2
  8075. int result2 = 0;
  8076. if (b1ProductSN1 == "假产品")
  8077. result2 = 1;
  8078. else
  8079. {
  8080. List<TestItem> items2 = new List<TestItem>();
  8081. items2.Add(new TestItem()
  8082. {
  8083. Parameter_name = "载具码",
  8084. Parameter_value = b1ProductSN.ToString(),
  8085. Parameter_unit = ""
  8086. });
  8087. items2.Add(new TestItem()
  8088. {
  8089. Parameter_name = "载具穴号",
  8090. Parameter_value = "2",
  8091. Parameter_unit = ""
  8092. });
  8093. items2.Add(new TestItem()
  8094. {
  8095. Parameter_name = "产品结果",
  8096. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  8097. Parameter_unit = ""
  8098. });
  8099. result2 = SwitctProcessData_old(stationNameStr, items2, equipmentCode, processItem
  8100. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  8101. }
  8102. short result = 0;
  8103. List<int> results = new List<int>() { result1, result2 };
  8104. if (result1 == 1 && result2 == 1)
  8105. result = 1;
  8106. else if (results.Contains(3))
  8107. result = 3;
  8108. else if (results.Contains(2))
  8109. result = 2;
  8110. else if (results.Contains(4))
  8111. result = 4;
  8112. else
  8113. result = 4;
  8114. stopwatch2.Stop();
  8115. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8116. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8117. writeToPLC_Flag.Name = "b1MES_FLAG";
  8118. writeToPLC_Flag.Adress = 2169;
  8119. writeToPLC_Flag.Value = result;
  8120. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  8121. OnMessage(LogType.Debug,
  8122. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8123. }
  8124. catch (Exception ex)
  8125. {
  8126. stopwatch2.Restart();
  8127. // MES_Flag 为4上位机报错
  8128. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  8129. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8130. writeToPLC_Flag.Name = "b1MES_FLAG";
  8131. writeToPLC_Flag.Adress = 2169;
  8132. writeToPLC_Flag.Value = (short)4;
  8133. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  8134. stopwatch2.Stop();
  8135. string str = ex.StackTrace;
  8136. AddMessage_Station(stationNameStr, LogType.Error,
  8137. $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  8138. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8139. }
  8140. stopwatch1.Stop();
  8141. AddMessage(LogType.Info,
  8142. stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  8143. stopwatch2.ElapsedMilliseconds + "ms");
  8144. }
  8145. #endregion [S2] FCT(板测)
  8146. #endregion PLC2 李晓奇
  8147. #region PLC3 刘永村
  8148. #region [S3] 值板机
  8149. /// <summary>
  8150. /// S3工位的数据- 触发信号上次的值
  8151. /// </summary>
  8152. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  8153. /// <summary>
  8154. /// S3工位的数据(含触发信号)
  8155. /// </summary>
  8156. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  8157. /// <summary>
  8158. /// S3工位的数据- 回写点位
  8159. /// </summary>
  8160. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8161. /// <summary>
  8162. /// [S3] 值板机
  8163. /// </summary>
  8164. /// <param name="plcNo">PLC编号</param>
  8165. //private void ReadStation_S3(int plcNo)
  8166. //{
  8167. // // [S1] Tray盘上料装备
  8168. // // [S2] FCT
  8169. // // [S3] 值板机
  8170. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8171. // // [S5] Tray盘下料装备
  8172. // /// 上位机心跳
  8173. // /// 获取设备报警数据与状态信息
  8174. // string stationCode = "[S3]";
  8175. // string stationName = "值板机";
  8176. // string stationNameStr = stationCode + stationName;
  8177. // #region 创建字典
  8178. // // 触发信号字典 赋值
  8179. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8180. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  8181. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  8182. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8183. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8184. // // PLC数据字典 赋值
  8185. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8186. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  8187. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8188. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  8189. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  8190. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8191. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8192. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  8193. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  8194. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8195. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  8196. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  8197. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8198. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8199. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  8200. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  8201. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  8202. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8203. // s3PLCData.Add("c1Result", 0); // 产品结果
  8204. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8205. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  8206. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  8207. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  8208. // #endregion 创建字典
  8209. // while (IsRun)
  8210. // {
  8211. // try
  8212. // {
  8213. // if (!GlobalContext._IsCon_Funs3)
  8214. // {
  8215. // UpdatePLCMonitor(1, plcNo, 0);
  8216. // continue;
  8217. // }
  8218. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8219. // {
  8220. // Stopwatch stopwatch1 = new Stopwatch();
  8221. // Stopwatch stopwatch2 = new Stopwatch();
  8222. // stopwatch1.Start();
  8223. // stopwatch2.Start();
  8224. // #region 一次性读取所有数据
  8225. // // 一次性读取所有数据
  8226. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  8227. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8228. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  8229. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  8230. // int[] datas = data1.Concat(data2).ToArray();
  8231. // datas = datas.Concat(data3).ToArray();
  8232. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  8233. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  8234. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8235. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  8236. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  8237. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  8238. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8239. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  8240. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  8241. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  8242. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  8243. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8244. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  8245. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  8246. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  8247. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  8248. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8249. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  8250. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  8251. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  8252. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  8253. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  8254. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  8255. // #endregion 一次性读取所有数据
  8256. // stopwatch2.Stop();
  8257. // #region 回写操作,写后清空flag
  8258. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  8259. // #endregion 回写操作,写后清空flag
  8260. // #region S3进站校验
  8261. // try
  8262. // {
  8263. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  8264. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  8265. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  8266. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  8267. // {
  8268. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  8269. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8270. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  8271. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8272. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  8273. // }
  8274. // }
  8275. // catch (Exception ex)
  8276. // {
  8277. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8278. // string str = ex.StackTrace;
  8279. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8280. // }
  8281. // #endregion S3进站校验
  8282. // #region S3二穴载具解绑
  8283. // try
  8284. // {
  8285. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  8286. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  8287. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  8288. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  8289. // {
  8290. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  8291. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  8292. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  8293. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  8294. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  8295. // }
  8296. // }
  8297. // catch (Exception ex)
  8298. // {
  8299. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  8300. // string str = ex.StackTrace;
  8301. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8302. // }
  8303. // #endregion S3二穴载具解绑
  8304. // #region S3二穴载具绑定
  8305. // try
  8306. // {
  8307. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  8308. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  8309. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  8310. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  8311. // {
  8312. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  8313. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  8314. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  8315. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  8316. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  8317. // }
  8318. // }
  8319. // catch (Exception ex)
  8320. // {
  8321. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  8322. // string str = ex.StackTrace;
  8323. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8324. // }
  8325. // #endregion S3二穴载具绑定
  8326. // #region S3出站接口(+一穴载具绑定)
  8327. // try
  8328. // {
  8329. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  8330. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  8331. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  8332. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  8333. // {
  8334. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  8335. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8336. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  8337. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  8338. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  8339. // }
  8340. // }
  8341. // catch (Exception ex)
  8342. // {
  8343. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  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 S3出站接口(+一穴载具绑定)
  8348. // #region S3节拍接口
  8349. // try
  8350. // {
  8351. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  8352. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  8353. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  8354. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  8355. // {
  8356. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  8357. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8358. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  8359. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  8360. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  8361. // }
  8362. // }
  8363. // catch (Exception ex)
  8364. // {
  8365. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  8366. // string str = ex.StackTrace;
  8367. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8368. // }
  8369. // #endregion S3节拍接口
  8370. // #region 心跳
  8371. // try
  8372. // {
  8373. // short states = 0;
  8374. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  8375. // }
  8376. // catch (Exception ex)
  8377. // {
  8378. // string str = ex.StackTrace;
  8379. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8380. // }
  8381. // #endregion 心跳
  8382. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  8383. // stopwatch1.Stop();
  8384. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  8385. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  8386. // }
  8387. // else
  8388. // {
  8389. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8390. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  8391. // Funs[plcNo].Connect();
  8392. // }
  8393. // }
  8394. // catch (Exception ex)
  8395. // {
  8396. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8397. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  8398. // Funs[plcNo].ReConnect();
  8399. // }
  8400. // Thread.Sleep(IntervalReadPLC);
  8401. // }
  8402. //}
  8403. /// <summary>
  8404. /// [S3] 值板机- 进站校验
  8405. /// </summary>
  8406. /// <param name="plcNo">PLC编号</param>
  8407. /// <param name="stationNameStr">工站全称</param>
  8408. private void S3进站校验(int plcNo, string stationNameStr)
  8409. {
  8410. Stopwatch stopwatch1 = new Stopwatch();
  8411. Stopwatch stopwatch2 = new Stopwatch();
  8412. try
  8413. {
  8414. stopwatch1.Start();
  8415. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  8416. sn = sn.Replace("\0", "");
  8417. #region 查询载具上的产品信息
  8418. string cavityData = string.Empty;
  8419. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  8420. if (string.IsNullOrEmpty(cavityData))
  8421. cavityData = "";
  8422. if (snResult != 0)
  8423. {
  8424. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8425. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  8426. writeToPLC_Flag1.Adress = 2003;
  8427. writeToPLC_Flag1.Value = (short)6;
  8428. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  8429. stopwatch1.Stop();
  8430. AddMessage(LogType.Info,
  8431. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8432. return;
  8433. }
  8434. #endregion 查询载具上的产品信息
  8435. string[] cavitySNs = cavityData.Split('.');
  8436. string part1Str = ""; // 产品1的SN码
  8437. string part2Str = ""; // 产品2的SN码
  8438. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  8439. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  8440. if (cavitySNs != null && cavitySNs.Length >= 2)
  8441. {
  8442. part1Str = cavitySNs[0];
  8443. part2Str = cavitySNs[1];
  8444. c1Part1Result_Check = 2;
  8445. c1Part2Result_Check = 2;
  8446. }
  8447. if (part1Str == "假产品")
  8448. c1Part1Result_Check = 3;
  8449. if (part2Str == "假产品")
  8450. c1Part2Result_Check = 3;
  8451. // 调用MES进站
  8452. stopwatch2.Start();
  8453. // 调用MES进站 - 产品1
  8454. List<TestItem> item;
  8455. int result1 = c1Part1Result_Check;
  8456. if (result1 != 3)
  8457. {
  8458. item = new List<TestItem>();
  8459. item.Add(new TestItem()
  8460. {
  8461. Parameter_name = "载具码",
  8462. Parameter_value = sn,
  8463. });
  8464. item.Add(new TestItem()
  8465. {
  8466. Parameter_name = "载具穴号",
  8467. Parameter_value = "1",
  8468. });
  8469. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8470. part1Str, item, out string errorMsg);
  8471. }
  8472. // 调用MES进站 - 产品2
  8473. int result2 = c1Part2Result_Check;
  8474. if (result2 != 3)
  8475. {
  8476. item = new List<TestItem>();
  8477. item.Add(new TestItem()
  8478. {
  8479. Parameter_name = "载具码",
  8480. Parameter_value = sn,
  8481. });
  8482. item.Add(new TestItem()
  8483. {
  8484. Parameter_name = "载具穴号",
  8485. Parameter_value = "2",
  8486. });
  8487. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8488. part2Str, item, out string errorMsg);
  8489. }
  8490. stopwatch2.Stop();
  8491. if (result1 == 2)
  8492. c1Part1Result_Check = 2;
  8493. if (result2 == 2)
  8494. c1Part2Result_Check = 2;
  8495. int result = result1;
  8496. if (result == 1)
  8497. result = result2;
  8498. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  8499. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  8500. short c1MES_FLAG_Check = (short)result;
  8501. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  8502. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  8503. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  8504. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  8505. //// MES_Flag
  8506. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8507. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8508. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  8509. writeToPLC_Flag.Adress = 2003;
  8510. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  8511. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8512. {
  8513. Name = "c1Part1Result_Check",
  8514. Adress = 2024,
  8515. ValueType = PLCValueType.Short,
  8516. Value = c1Part1Result_Check
  8517. });
  8518. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8519. {
  8520. Name = "c1Part2Result_Check",
  8521. Adress = 2025,
  8522. ValueType = PLCValueType.Short,
  8523. Value = c1Part2Result_Check
  8524. });
  8525. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8526. {
  8527. Name = "c1Part1Num_Check",
  8528. Adress = 2026,
  8529. ValueType = PLCValueType.Short,
  8530. Value = c1Part1Num_Check
  8531. });
  8532. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8533. {
  8534. Name = "c1Part2Num_Check",
  8535. Adress = 2027,
  8536. ValueType = PLCValueType.Short,
  8537. Value = c1Part2Num_Check
  8538. });
  8539. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  8540. }
  8541. catch (Exception ex)
  8542. {
  8543. string str = ex.StackTrace;
  8544. AddMessage_Station(stationNameStr, LogType.Error,
  8545. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  8546. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8547. // MES_Flag
  8548. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8549. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8550. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  8551. writeToPLC_Flag.Adress = 2003;
  8552. writeToPLC_Flag.Value = (short)6;
  8553. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  8554. }
  8555. stopwatch1.Stop();
  8556. AddMessage(LogType.Info,
  8557. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  8558. stopwatch2.ElapsedMilliseconds + "ms");
  8559. }
  8560. /// <summary>
  8561. /// [S3] 值板机 - 二穴载具解绑
  8562. /// </summary>
  8563. /// <param name="plcNo">PLC编号</param>
  8564. /// <param name="stationNameStr">工站全称</param>
  8565. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  8566. {
  8567. Stopwatch stopwatch1 = new Stopwatch();
  8568. Stopwatch stopwatch2 = new Stopwatch();
  8569. try
  8570. {
  8571. stopwatch1.Start();
  8572. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  8573. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8574. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8575. // 解绑
  8576. #region 查询载具上的产品信息
  8577. string cavityData = string.Empty;
  8578. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8579. if (string.IsNullOrEmpty(cavityData))
  8580. cavityData = "";
  8581. if (snResult != 0)
  8582. {
  8583. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8584. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  8585. writeToPLC_Flag1.Adress = 2082;
  8586. writeToPLC_Flag1.Value = (short)6;
  8587. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  8588. stopwatch1.Stop();
  8589. AddMessage(LogType.Info,
  8590. stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8591. "ms");
  8592. return;
  8593. }
  8594. #endregion 查询载具上的产品信息
  8595. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  8596. #region 解绑
  8597. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  8598. {
  8599. // 删除
  8600. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8601. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  8602. }
  8603. else
  8604. {
  8605. string data_new = string.Join(".", cavitySNs);
  8606. // 删除再插入
  8607. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8608. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  8609. OnMessage(LogType.Debug,
  8610. $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  8611. }
  8612. #endregion 解绑
  8613. short c1MES_FLAG_Unbind = 1;
  8614. stopwatch2.Start();
  8615. // MES_Flag
  8616. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8617. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8618. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  8619. writeToPLC_Flag.Adress = 2082;
  8620. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  8621. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  8622. stopwatch2.Stop();
  8623. }
  8624. catch (Exception ex)
  8625. {
  8626. string str = ex.StackTrace;
  8627. AddMessage_Station(stationNameStr, LogType.Error,
  8628. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" +
  8629. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8630. // MES_Flag
  8631. stopwatch2.Start();
  8632. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  8633. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8634. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  8635. writeToPLC_Flag.Adress = 2082;
  8636. writeToPLC_Flag.Value = (short)6;
  8637. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  8638. stopwatch2.Stop();
  8639. }
  8640. stopwatch1.Stop();
  8641. AddMessage(LogType.Info,
  8642. stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8643. stopwatch2.ElapsedMilliseconds + "ms");
  8644. }
  8645. /// <summary>
  8646. /// [S3] 值板机 - 二穴载具绑定
  8647. /// </summary>
  8648. /// <param name="plcNo">PLC编号</param>
  8649. /// <param name="stationNameStr">工站全称</param>
  8650. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  8651. {
  8652. Stopwatch stopwatch1 = new Stopwatch();
  8653. Stopwatch stopwatch2 = new Stopwatch();
  8654. try
  8655. {
  8656. stopwatch1.Start();
  8657. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  8658. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8659. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  8660. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  8661. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8662. stopwatch2.Start();
  8663. #region 查询载具上的产品信息
  8664. string cavityData = string.Empty;
  8665. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8666. if (string.IsNullOrEmpty(cavityData))
  8667. cavityData = "";
  8668. if (snResult != 0)
  8669. {
  8670. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8671. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  8672. writeToPLC_Flag1.Adress = 2115;
  8673. writeToPLC_Flag1.Value = (short)6;
  8674. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  8675. stopwatch1.Stop();
  8676. AddMessage(LogType.Info,
  8677. stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8678. "ms");
  8679. return;
  8680. }
  8681. #endregion 查询载具上的产品信息
  8682. // 产品换载具
  8683. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  8684. string partSn1 = "";
  8685. string partSn2 = "";
  8686. if (cavitySNs != null && cavitySNs.Length >= 2)
  8687. {
  8688. partSn1 = cavitySNs[0];
  8689. partSn2 = cavitySNs[1];
  8690. }
  8691. string data_new = string.Empty;
  8692. // 是否是两个穴位交换
  8693. if (c1CavityReverse_Bind == 1)
  8694. {
  8695. // 交换
  8696. data_new = string.Concat(partSn2, ".", partSn1);
  8697. }
  8698. else
  8699. {
  8700. // 不交换
  8701. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  8702. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  8703. cavitySNs[c1VehicleCavityFr_Bind] = "";
  8704. data_new = string.Join(".", cavitySNs);
  8705. }
  8706. // 删除再插入
  8707. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8708. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  8709. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  8710. stopwatch2.Stop();
  8711. short c1MES_FLAG_Bind = 1;
  8712. // MES_Flag
  8713. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8714. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8715. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  8716. writeToPLC_Flag.Adress = 2115;
  8717. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  8718. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  8719. }
  8720. catch (Exception ex)
  8721. {
  8722. string str = ex.StackTrace;
  8723. AddMessage_Station(stationNameStr, LogType.Error,
  8724. $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" +
  8725. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8726. // MES_Flag
  8727. stopwatch2.Start();
  8728. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  8729. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8730. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  8731. writeToPLC_Flag.Adress = 2115;
  8732. writeToPLC_Flag.Value = (short)6;
  8733. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  8734. stopwatch2.Stop();
  8735. }
  8736. stopwatch1.Stop();
  8737. AddMessage(LogType.Info,
  8738. stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8739. stopwatch2.ElapsedMilliseconds + "ms");
  8740. }
  8741. //// 上次采集到的SN
  8742. //private string sn_值板机 = string.Empty;
  8743. /// <summary>
  8744. /// [S3] 值板机 - 出站接口
  8745. /// </summary>
  8746. /// <param name="plcNo">PLC编号</param>
  8747. private void S3出站接口(int plcNo, string stationCode, string stationName)
  8748. {
  8749. Stopwatch stopwatch1 = new Stopwatch();
  8750. Stopwatch stopwatch2 = new Stopwatch();
  8751. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8752. string stationNameStr = stationCode + stationName;
  8753. string processItem = stationName; // 测试项目
  8754. try
  8755. {
  8756. stopwatch1.Start();
  8757. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8758. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8759. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8760. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8761. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  8762. sn = sn.Replace("\0", "");
  8763. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  8764. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8765. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8766. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  8767. bool pass = c1Result == 1;
  8768. // 查sn
  8769. #region 查询载具上的产品信息
  8770. string cavityData = string.Empty;
  8771. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8772. if (string.IsNullOrEmpty(cavityData))
  8773. cavityData = "";
  8774. if (snResult != 0)
  8775. {
  8776. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8777. writeToPLC_Flag1.Name = "c1MES_FLAG";
  8778. writeToPLC_Flag1.Adress = 2150;
  8779. writeToPLC_Flag1.Value = (short)4;
  8780. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  8781. stopwatch1.Stop();
  8782. AddMessage(LogType.Info,
  8783. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8784. return;
  8785. }
  8786. #endregion 查询载具上的产品信息
  8787. string[] cavitySNs = cavityData.Split('.');
  8788. string productSN = "";
  8789. if (cavitySNs != null && cavitySNs.Length >= 2)
  8790. {
  8791. productSN = cavitySNs[c1VehicleCavity];
  8792. cavitySNs[c1VehicleCavity] = "";
  8793. }
  8794. stopwatch2.Start();
  8795. List<TestItem> items = new List<TestItem>();
  8796. items.Add(new TestItem()
  8797. {
  8798. Parameter_name = "二穴载具码",
  8799. Parameter_value = c1ProductSN_Check,
  8800. Parameter_unit = ""
  8801. });
  8802. items.Add(new TestItem()
  8803. {
  8804. Parameter_name = "二穴载具穴号",
  8805. Parameter_value = c1VehicleCavity.ToString(),
  8806. Parameter_unit = ""
  8807. });
  8808. items.Add(new TestItem()
  8809. {
  8810. Parameter_name = "一穴载具码",
  8811. Parameter_value = sn,
  8812. Parameter_unit = ""
  8813. });
  8814. items.Add(new TestItem()
  8815. {
  8816. Parameter_name = "一穴载具穴号",
  8817. Parameter_value = "1",
  8818. Parameter_unit = ""
  8819. });
  8820. items.Add(new TestItem()
  8821. {
  8822. Parameter_name = "产品结果",
  8823. Parameter_value = c1Result == 1 ? "OK" : "NG",
  8824. Parameter_unit = ""
  8825. });
  8826. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  8827. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  8828. short result = (short)result1;
  8829. stopwatch2.Stop();
  8830. #region 存储绑定数据到 边线MES系统中
  8831. if (result == 1)
  8832. {
  8833. string data = string.Concat(productSN);
  8834. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  8835. if (resultMesR != 0)
  8836. {
  8837. result = 4;
  8838. AddMessage_Station(stationNameStr, LogType.Error,
  8839. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  8840. }
  8841. }
  8842. #endregion 存储绑定数据到 边线MES系统中
  8843. #region 产品从 来源载具(二穴载具)中删除
  8844. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  8845. {
  8846. // 删除
  8847. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8848. OnMessage(LogType.Debug,
  8849. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  8850. }
  8851. else
  8852. {
  8853. string data_new = string.Join(".", cavitySNs);
  8854. // 删除再插入
  8855. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8856. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  8857. OnMessage(LogType.Debug,
  8858. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  8859. }
  8860. #endregion 产品从 来源载具(二穴载具)中删除
  8861. // MES_Flag 为MES报错
  8862. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8863. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  8864. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8865. writeToPLC_Flag.Name = "c1MES_FLAG";
  8866. writeToPLC_Flag.Adress = 2150;
  8867. writeToPLC_Flag.Value = result;
  8868. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  8869. OnMessage(LogType.Debug,
  8870. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8871. }
  8872. catch (Exception ex)
  8873. {
  8874. stopwatch2.Restart();
  8875. // MES_Flag 为4上位机报错
  8876. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  8877. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8878. writeToPLC_Flag.Name = "c1MES_FLAG";
  8879. writeToPLC_Flag.Adress = 2150;
  8880. writeToPLC_Flag.Value = (short)4;
  8881. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  8882. stopwatch2.Stop();
  8883. string str = ex.StackTrace;
  8884. AddMessage_Station(stationNameStr, LogType.Error,
  8885. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  8886. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8887. }
  8888. stopwatch1.Stop();
  8889. AddMessage(LogType.Info,
  8890. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  8891. stopwatch2.ElapsedMilliseconds + "ms");
  8892. }
  8893. #endregion [S3] 值板机
  8894. #endregion PLC3 刘永村
  8895. #region PLC4 刘果段
  8896. #region [S4] 取放桁架
  8897. /// <summary>
  8898. /// S4工位的数据- 触发信号上次的值
  8899. /// </summary>
  8900. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  8901. /// <summary>
  8902. /// S4工位的数据(含触发信号)
  8903. /// </summary>
  8904. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  8905. /// <summary>
  8906. /// S4工位的数据- 回写点位
  8907. /// </summary>
  8908. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8909. /// <summary>
  8910. /// [S4] 取放桁架
  8911. /// </summary>
  8912. /// <param name="plcNo">PLC编号</param>
  8913. //private void ReadStation_S4(int plcNo)
  8914. //{
  8915. // // [S1] Tray盘上料装备
  8916. // // [S2] FCT
  8917. // // [S3] 值板机
  8918. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8919. // // [S5] Tray盘下料装备
  8920. // /// 上位机心跳
  8921. // /// 获取设备报警数据与状态信息
  8922. // string stationCode = "[S4_1]";
  8923. // string stationName = "载具下线装备";
  8924. // string stationNameStr = stationCode + stationName;
  8925. // string stationCode2 = "[S4_2]";
  8926. // string stationName2 = "桁架";
  8927. // string stationNameStr2 = stationCode2 + stationName2;
  8928. // string stationCode3 = "[S4_3]";
  8929. // string stationName3 = "提升机1";
  8930. // string stationNameStr3 = stationCode3 + stationName3;
  8931. // string stationCode4 = "[S4_4]";
  8932. // string stationName4 = "提升机2";
  8933. // string stationNameStr4 = stationCode4 + stationName4;
  8934. // string stationCode5 = "[S4_5]";
  8935. // string stationName5 = "载具上线装备";
  8936. // string stationNameStr5 = stationCode5 + stationName5;
  8937. // #region 创建字典
  8938. // // 触发信号字典 赋值
  8939. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  8940. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  8941. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8942. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8943. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  8944. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  8945. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  8946. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  8947. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  8948. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  8949. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8950. // // PLC数据字典 赋值
  8951. // // 载具下线装备(弹夹上线)
  8952. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  8953. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  8954. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  8955. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  8956. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8957. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  8958. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  8959. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  8960. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  8961. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  8962. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  8963. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  8964. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  8965. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  8966. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  8967. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  8968. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  8969. // s4PLCData.Add("d1Result", 0); // 产品结果
  8970. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8971. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  8972. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  8973. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  8974. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  8975. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  8976. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  8977. // // 真空标机(提升机)
  8978. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  8979. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  8980. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  8981. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  8982. // s4PLCData.Add("d3Result", 0); // 产品结果
  8983. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  8984. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  8985. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  8986. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  8987. // s4PLCData.Add("d4Result", 0); // 产品结果
  8988. // // 载具上线装备(弹夹下线)
  8989. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  8990. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  8991. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  8992. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  8993. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  8994. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  8995. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  8996. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  8997. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  8998. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  8999. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  9000. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  9001. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  9002. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  9003. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  9004. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  9005. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  9006. // s4PLCData.Add("d5Result", 0); // 产品结果
  9007. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9008. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  9009. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  9010. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  9011. // #endregion 创建字典
  9012. // while (IsRun)
  9013. // {
  9014. // try
  9015. // {
  9016. // if (!GlobalContext._IsCon_Funs4)
  9017. // {
  9018. // UpdatePLCMonitor(1, plcNo, 0);
  9019. // continue;
  9020. // }
  9021. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  9022. // {
  9023. // Stopwatch stopwatch1 = new Stopwatch();
  9024. // Stopwatch stopwatch2 = new Stopwatch();
  9025. // stopwatch1.Start();
  9026. // stopwatch2.Start();
  9027. // #region 一次性读取所有数据
  9028. // // 载具下线装备(弹夹上线)
  9029. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  9030. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  9031. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  9032. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  9033. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  9034. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  9035. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  9036. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  9037. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  9038. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  9039. // int[] datas = data1.Concat(data2).ToArray();
  9040. // datas = datas.Concat(data3).ToArray();
  9041. // datas = datas.Concat(data4).ToArray();
  9042. // datas = datas.Concat(data5).ToArray();
  9043. // datas = datas.Concat(data6).ToArray();
  9044. // datas = datas.Concat(data7).ToArray();
  9045. // datas = datas.Concat(data8).ToArray();
  9046. // datas = datas.Concat(data9).ToArray();
  9047. // datas = datas.Concat(data10).ToArray();
  9048. // // 载具下线装备(弹夹上线)
  9049. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  9050. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  9051. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  9052. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  9053. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  9054. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  9055. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  9056. // s4PLCData["d1MES_FLAG"] = datas[65];
  9057. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  9058. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  9059. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  9060. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  9061. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  9062. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  9063. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  9064. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  9065. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  9066. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  9067. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  9068. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  9069. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  9070. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  9071. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  9072. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  9073. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  9074. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  9075. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  9076. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  9077. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  9078. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  9079. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  9080. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  9081. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  9082. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  9083. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  9084. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  9085. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  9086. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  9087. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  9088. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  9089. // s4PLCData["d1Result"] = datas[386];
  9090. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  9091. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  9092. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  9093. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  9094. // s4PLCData["d1OEEType"] = datas[419];
  9095. // // 桁架(查询标机中弹夹的状态)
  9096. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  9097. // s4PLCData["d2BulletclipStates"] = datas[431];
  9098. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  9099. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  9100. // // 真空标机
  9101. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  9102. // s4PLCData["d3MES_FLAG"] = datas[463];
  9103. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  9104. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  9105. // s4PLCData["d3Result"] = datas[484];
  9106. // s4PLCData["d3Type"] = datas[485];
  9107. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  9108. // s4PLCData["d4MES_FLAG"] = datas[496];
  9109. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  9110. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  9111. // s4PLCData["d4Result"] = datas[517];
  9112. // s4PLCData["d4Type"] = datas[518];
  9113. // // 载具上线装备(弹夹下线)
  9114. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  9115. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  9116. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  9117. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  9118. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  9119. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  9120. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  9121. // s4PLCData["d5MES_FLAG"] = datas[591];
  9122. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  9123. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  9124. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  9125. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  9126. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  9127. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  9128. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  9129. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  9130. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  9131. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  9132. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  9133. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  9134. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  9135. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  9136. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  9137. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  9138. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  9139. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  9140. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  9141. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  9142. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  9143. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  9144. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  9145. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  9146. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  9147. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  9148. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  9149. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  9150. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  9151. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  9152. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  9153. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  9154. // s4PLCData["d5Result"] = datas[912];
  9155. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  9156. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  9157. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  9158. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  9159. // s4PLCData["d5OEEType"] = datas[945];
  9160. // #endregion 一次性读取所有数据
  9161. // stopwatch2.Stop();
  9162. // #region 回写操作,写后清空flag
  9163. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  9164. // #endregion 回写操作,写后清空flag
  9165. // // N801A-S4_1 弹夹扫码
  9166. // #region N801A-S4_1 弹夹扫码
  9167. // try
  9168. // {
  9169. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  9170. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  9171. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  9172. // {
  9173. // if (d1BulletclipScanCode == 1) // 0->1
  9174. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  9175. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  9176. // }
  9177. // }
  9178. // catch (Exception ex)
  9179. // {
  9180. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  9181. // string str = ex.StackTrace;
  9182. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9183. // }
  9184. // #endregion N801A-S4_1 弹夹扫码
  9185. // // N801A-S4_1 载具扫码
  9186. // #region N801A-S4_1 载具扫码
  9187. // try
  9188. // {
  9189. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  9190. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  9191. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  9192. // {
  9193. // if (d1VehicleScanCode == 1) // 0->1
  9194. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  9195. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  9196. // }
  9197. // }
  9198. // catch (Exception ex)
  9199. // {
  9200. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  9201. // string str = ex.StackTrace;
  9202. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9203. // }
  9204. // #endregion N801A-S4_1 载具扫码
  9205. // // N801A-S4_1 出站接口
  9206. // #region N801A-S4_1 出站接口
  9207. // try
  9208. // {
  9209. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  9210. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  9211. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  9212. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  9213. // {
  9214. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  9215. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  9216. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  9217. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  9218. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  9219. // }
  9220. // }
  9221. // catch (Exception ex)
  9222. // {
  9223. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  9224. // string str = ex.StackTrace;
  9225. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9226. // }
  9227. // #endregion N801A-S4_1 出站接口
  9228. // // N801A-S4_1 节拍接口
  9229. // #region N801A-S4_1 节拍接口
  9230. // try
  9231. // {
  9232. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  9233. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  9234. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  9235. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  9236. // {
  9237. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  9238. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  9239. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  9240. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  9241. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  9242. // }
  9243. // }
  9244. // catch (Exception ex)
  9245. // {
  9246. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  9247. // string str = ex.StackTrace;
  9248. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9249. // }
  9250. // #endregion N801A-S4_1 节拍接口
  9251. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  9252. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  9253. // try
  9254. // {
  9255. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  9256. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  9257. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  9258. // {
  9259. // if (d2BulletclipScanCode == 1) // 0->1
  9260. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  9261. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  9262. // }
  9263. // }
  9264. // catch (Exception ex)
  9265. // {
  9266. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  9267. // string str = ex.StackTrace;
  9268. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9269. // }
  9270. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  9271. // // N801A-S4_3 真空标机1 数据
  9272. // #region N801A-S4_3 真空标机1
  9273. // try
  9274. // {
  9275. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  9276. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  9277. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  9278. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  9279. // {
  9280. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  9281. // {
  9282. // int stationType = (int)s4PLCData["d3Type"];
  9283. // if (stationType == 1)
  9284. // {
  9285. // // S4_3进站接口
  9286. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  9287. // }
  9288. // else if (stationType == 2)
  9289. // {
  9290. // // S4_3出站接口
  9291. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  9292. // }
  9293. // }
  9294. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  9295. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  9296. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  9297. // }
  9298. // }
  9299. // catch (Exception ex)
  9300. // {
  9301. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  9302. // string str = ex.StackTrace;
  9303. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9304. // }
  9305. // #endregion N801A-S4_3 真空标机1
  9306. // // N801A-S4_4 真空标机2 数据
  9307. // #region N801A-S4_4 真空标机2
  9308. // try
  9309. // {
  9310. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  9311. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  9312. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  9313. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  9314. // {
  9315. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  9316. // {
  9317. // int stationType = (int)s4PLCData["d4Type"];
  9318. // if (stationType == 1)
  9319. // {
  9320. // // S4_4进站接口
  9321. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  9322. // }
  9323. // else if (stationType == 2)
  9324. // {
  9325. // // S4_4出站接口
  9326. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  9327. // }
  9328. // }
  9329. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  9330. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  9331. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  9332. // }
  9333. // }
  9334. // catch (Exception ex)
  9335. // {
  9336. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  9337. // string str = ex.StackTrace;
  9338. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9339. // }
  9340. // #endregion N801A-S4_4 真空标机2
  9341. // // N801A-S4_5 弹夹扫码 数据
  9342. // #region N801A-S4_5 弹夹扫码
  9343. // try
  9344. // {
  9345. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  9346. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  9347. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  9348. // {
  9349. // if (d5BulletclipScanCode == 1) // 0->1
  9350. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  9351. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  9352. // }
  9353. // }
  9354. // catch (Exception ex)
  9355. // {
  9356. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  9357. // string str = ex.StackTrace;
  9358. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9359. // }
  9360. // #endregion N801A-S4_5 弹夹扫码
  9361. // // N801A-S4_5 载具扫码 数据
  9362. // #region N801A-S4_5 载具扫码
  9363. // try
  9364. // {
  9365. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  9366. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  9367. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  9368. // {
  9369. // if (d5VehicleScanCode == 1) // 0->1
  9370. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  9371. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  9372. // }
  9373. // }
  9374. // catch (Exception ex)
  9375. // {
  9376. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  9377. // string str = ex.StackTrace;
  9378. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9379. // }
  9380. // #endregion N801A-S4_5 载具扫码
  9381. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  9382. // #region N801A-S4_5 出站接口
  9383. // try
  9384. // {
  9385. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  9386. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  9387. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  9388. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  9389. // {
  9390. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  9391. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  9392. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  9393. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  9394. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  9395. // }
  9396. // }
  9397. // catch (Exception ex)
  9398. // {
  9399. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  9400. // string str = ex.StackTrace;
  9401. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9402. // }
  9403. // #endregion N801A-S4_5 出站接口
  9404. // // N801A-S4_5 节拍接口 数据
  9405. // #region N801A-S4_5 节拍接口
  9406. // try
  9407. // {
  9408. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  9409. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  9410. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  9411. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  9412. // {
  9413. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  9414. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  9415. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  9416. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  9417. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  9418. // }
  9419. // }
  9420. // catch (Exception ex)
  9421. // {
  9422. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  9423. // string str = ex.StackTrace;
  9424. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9425. // }
  9426. // #endregion N801A-S4_5 节拍接口
  9427. // #region 心跳
  9428. // try
  9429. // {
  9430. // short states = 0;
  9431. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  9432. // }
  9433. // catch (Exception ex)
  9434. // {
  9435. // string str = ex.StackTrace;
  9436. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9437. // }
  9438. // #endregion 心跳
  9439. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  9440. // stopwatch1.Stop();
  9441. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  9442. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  9443. // }
  9444. // else
  9445. // {
  9446. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9447. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  9448. // Funs[plcNo].Connect();
  9449. // }
  9450. // }
  9451. // catch (Exception ex)
  9452. // {
  9453. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9454. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  9455. // Funs[plcNo].ReConnect();
  9456. // }
  9457. // Thread.Sleep(IntervalReadPLC);
  9458. // }
  9459. //}
  9460. /// <summary>
  9461. /// [S4] 取放桁架 - S4_1弹夹扫码
  9462. /// </summary>
  9463. /// <param name="plcNo">PLC编号</param>
  9464. /// <param name="stationNameStr">工站全称</param>
  9465. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  9466. {
  9467. Stopwatch stopwatch1 = new Stopwatch();
  9468. Stopwatch stopwatch2 = new Stopwatch();
  9469. try
  9470. {
  9471. stopwatch1.Start();
  9472. // ZS 弹夹扫码
  9473. string d1BulletclipCode = " "; // 扫到的码
  9474. short d1BulletclipScanCode = 2;
  9475. stopwatch2.Start();
  9476. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  9477. //// MES_Flag
  9478. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  9479. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9480. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  9481. writeToPLC_Flag.Adress = 2002;
  9482. writeToPLC_Flag.Value = d1BulletclipScanCode;
  9483. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  9484. {
  9485. Name = "d1BulletclipCode",
  9486. Adress = 2003,
  9487. ValueType = PLCValueType.String,
  9488. ValueTypeStrLength = 20,
  9489. Value = d1BulletclipCode
  9490. });
  9491. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  9492. stopwatch2.Stop();
  9493. }
  9494. catch (Exception ex)
  9495. {
  9496. string str = ex.StackTrace;
  9497. AddMessage_Station(stationNameStr, LogType.Error,
  9498. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  9499. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9500. stopwatch2.Start();
  9501. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  9502. //// MES_Flag
  9503. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  9504. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9505. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  9506. writeToPLC_Flag.Adress = 2002;
  9507. writeToPLC_Flag.Value = (short)6;
  9508. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  9509. {
  9510. Name = "d1BulletclipCode",
  9511. Adress = 2003,
  9512. ValueType = PLCValueType.String,
  9513. ValueTypeStrLength = 20,
  9514. Value = " "
  9515. });
  9516. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  9517. stopwatch2.Stop();
  9518. }
  9519. stopwatch1.Stop();
  9520. AddMessage(LogType.Info,
  9521. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9522. stopwatch2.ElapsedMilliseconds + "ms");
  9523. }
  9524. /// <summary>
  9525. /// [S4] 取放桁架 - S4_1载具扫码
  9526. /// </summary>
  9527. /// <param name="plcNo">PLC编号</param>
  9528. /// <param name="stationNameStr">工站全称</param>
  9529. private void S4_1载具扫码(int plcNo, string stationNameStr)
  9530. {
  9531. Stopwatch stopwatch1 = new Stopwatch();
  9532. Stopwatch stopwatch2 = new Stopwatch();
  9533. try
  9534. {
  9535. stopwatch1.Start();
  9536. // ZS 载具扫码
  9537. string d1VehicleCode = ""; // 扫到的码
  9538. short d1VehicleScanCode = 2;
  9539. #region 进站
  9540. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  9541. {
  9542. #region 查询载具上的产品信息
  9543. string cavityData = string.Empty;
  9544. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  9545. if (string.IsNullOrEmpty(cavityData))
  9546. cavityData = "";
  9547. if (snResult != 0)
  9548. {
  9549. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9550. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  9551. writeToPLC_Flag1.Adress = 2033;
  9552. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  9553. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9554. {
  9555. Name = "d1VehicleCode",
  9556. Adress = 2034,
  9557. ValueType = PLCValueType.String,
  9558. ValueTypeStrLength = 20,
  9559. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  9560. });
  9561. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  9562. stopwatch1.Stop();
  9563. AddMessage(LogType.Info,
  9564. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9565. "ms");
  9566. return;
  9567. }
  9568. string[] cavitySNs = cavityData.Split('.');
  9569. string partNo = "";
  9570. if (cavitySNs != null && cavitySNs.Length >= 1)
  9571. {
  9572. partNo = cavitySNs[0];
  9573. }
  9574. #endregion 查询载具上的产品信息
  9575. List<TestItem> item = new List<TestItem>();
  9576. item.Add(new TestItem()
  9577. {
  9578. Parameter_name = "载具码",
  9579. Parameter_value = d1VehicleCode,
  9580. });
  9581. item.Add(new TestItem()
  9582. {
  9583. Parameter_name = "载具穴号",
  9584. Parameter_value = "1",
  9585. });
  9586. stopwatch2.Start();
  9587. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  9588. partNo, item, out string errorMsg);
  9589. stopwatch2.Stop();
  9590. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  9591. }
  9592. #endregion 进站
  9593. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  9594. //// MES_Flag
  9595. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  9596. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9597. writeToPLC_Flag.Name = "d1VehicleScanCode";
  9598. writeToPLC_Flag.Adress = 2033;
  9599. writeToPLC_Flag.Value = d1VehicleScanCode;
  9600. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9601. {
  9602. Name = "d1VehicleCode",
  9603. Adress = 2034,
  9604. ValueType = PLCValueType.String,
  9605. ValueTypeStrLength = 20,
  9606. Value = d1VehicleCode
  9607. });
  9608. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  9609. }
  9610. catch (Exception ex)
  9611. {
  9612. string str = ex.StackTrace;
  9613. AddMessage_Station(stationNameStr, LogType.Error,
  9614. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  9615. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9616. stopwatch2.Start();
  9617. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  9618. //// MES_Flag
  9619. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  9620. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9621. writeToPLC_Flag.Name = "d1VehicleScanCode";
  9622. writeToPLC_Flag.Adress = 2033;
  9623. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  9624. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9625. {
  9626. Name = "d1VehicleCode",
  9627. Adress = 2034,
  9628. ValueType = PLCValueType.String,
  9629. ValueTypeStrLength = 20,
  9630. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  9631. });
  9632. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  9633. stopwatch2.Stop();
  9634. }
  9635. stopwatch1.Stop();
  9636. AddMessage(LogType.Info,
  9637. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9638. stopwatch2.ElapsedMilliseconds + "ms");
  9639. }
  9640. // 上次采集到的SN
  9641. //private string sn_S4_1出站接口 = string.Empty;
  9642. /// <summary>
  9643. /// [S4] 取放桁架 - S4_1出站接口
  9644. /// </summary>
  9645. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  9646. {
  9647. Stopwatch stopwatch1 = new Stopwatch();
  9648. Stopwatch stopwatch2 = new Stopwatch();
  9649. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9650. string stationNameStr = stationCode + stationName;
  9651. string processItem = stationName; // 测试项目
  9652. try
  9653. {
  9654. stopwatch1.Start();
  9655. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9656. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9657. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9658. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9659. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  9660. sn = sn.Replace("\0", "");
  9661. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  9662. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  9663. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  9664. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  9665. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  9666. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  9667. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  9668. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  9669. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  9670. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  9671. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  9672. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  9673. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  9674. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  9675. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  9676. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  9677. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  9678. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  9679. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  9680. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  9681. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  9682. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  9683. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  9684. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  9685. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  9686. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  9687. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  9688. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  9689. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  9690. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  9691. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  9692. bool pass = d1Result == 1;
  9693. // 存 载具SN列表
  9694. List<string> vehicleCodes = new List<string>()
  9695. {
  9696. d1VehicleCode1, d1VehicleCode2, d1VehicleCode3, d1VehicleCode4, d1VehicleCode5,
  9697. d1VehicleCode6, d1VehicleCode7, d1VehicleCode8, d1VehicleCode9, d1VehicleCode10,
  9698. d1VehicleCode11, d1VehicleCode12, d1VehicleCode13, d1VehicleCode14, d1VehicleCode15
  9699. };
  9700. // 统一查 产品SN列表
  9701. List<string> partNos = new List<string>();
  9702. foreach (string vehicleCode in vehicleCodes)
  9703. {
  9704. if (string.IsNullOrEmpty(vehicleCode))
  9705. partNos.Add("");
  9706. else
  9707. {
  9708. string partNo = "";
  9709. #region 查询载具上的产品信息
  9710. string cavityData = string.Empty;
  9711. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  9712. if (string.IsNullOrEmpty(cavityData))
  9713. cavityData = "";
  9714. if (snResult != 0)
  9715. {
  9716. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9717. writeToPLC_Flag1.Name = "d1MES_FLAG";
  9718. writeToPLC_Flag1.Adress = 2065;
  9719. writeToPLC_Flag1.Value = (short)4;
  9720. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  9721. stopwatch1.Stop();
  9722. AddMessage(LogType.Info,
  9723. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9724. "ms");
  9725. return;
  9726. }
  9727. string[] cavitySNs = cavityData.Split('.');
  9728. if (cavitySNs != null && cavitySNs.Length >= 1)
  9729. partNo = cavitySNs[0];
  9730. #endregion 查询载具上的产品信息
  9731. partNos.Add(partNo);
  9732. }
  9733. }
  9734. // 统一上传
  9735. stopwatch2.Start();
  9736. List<int> results = new List<int>();
  9737. for (int i = 0; i < partNos.Count; i++)
  9738. {
  9739. string index = (i + 1).ToString(); // 弹夹穴号
  9740. if (string.IsNullOrEmpty(partNos[i]))
  9741. results.Add(1);
  9742. else
  9743. {
  9744. List<TestItem> items1 = new List<TestItem>();
  9745. items1.Add(new TestItem()
  9746. {
  9747. Parameter_name = "弹夹码",
  9748. Parameter_value = sn,
  9749. Parameter_unit = ""
  9750. });
  9751. items1.Add(new TestItem()
  9752. {
  9753. Parameter_name = "弹夹穴号",
  9754. Parameter_value = index,
  9755. Parameter_unit = ""
  9756. });
  9757. items1.Add(new TestItem()
  9758. {
  9759. Parameter_name = "载具码",
  9760. Parameter_value = vehicleCodes[i],
  9761. Parameter_unit = ""
  9762. });
  9763. items1.Add(new TestItem()
  9764. {
  9765. Parameter_name = "载具穴号",
  9766. Parameter_value = "1",
  9767. Parameter_unit = ""
  9768. });
  9769. items1.Add(new TestItem()
  9770. {
  9771. Parameter_name = "产品结果",
  9772. Parameter_value = d1Result == 1 ? "OK" : "NG",
  9773. Parameter_unit = ""
  9774. });
  9775. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  9776. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  9777. results.Add(result1);
  9778. }
  9779. }
  9780. short result = 0;
  9781. if (results.All(a => a == 1))
  9782. result = 1;
  9783. else if (results.Contains(3))
  9784. result = 3;
  9785. else if (results.Contains(2))
  9786. result = 2;
  9787. else if (results.Contains(4))
  9788. result = 4;
  9789. else
  9790. result = 4;
  9791. stopwatch2.Stop();
  9792. #region 存储绑定数据到 边线MES系统中
  9793. if (result == 1)
  9794. {
  9795. string data = string.Join(".", vehicleCodes);
  9796. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  9797. if (resultMesR != 0)
  9798. {
  9799. result = 4;
  9800. AddMessage_Station(stationNameStr, LogType.Error,
  9801. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  9802. }
  9803. }
  9804. #endregion 存储绑定数据到 边线MES系统中
  9805. // MES_Flag 为4MES报错
  9806. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9807. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9808. writeToPLC_Flag.Name = "d1MES_FLAG";
  9809. writeToPLC_Flag.Adress = 2065;
  9810. writeToPLC_Flag.Value = result;
  9811. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  9812. OnMessage(LogType.Debug,
  9813. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9814. }
  9815. catch (Exception ex)
  9816. {
  9817. stopwatch2.Restart();
  9818. // MES_Flag 为4上位机报错
  9819. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  9820. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9821. writeToPLC_Flag.Name = "d1MES_FLAG";
  9822. writeToPLC_Flag.Adress = 2065;
  9823. writeToPLC_Flag.Value = (short)4;
  9824. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  9825. stopwatch2.Stop();
  9826. string str = ex.StackTrace;
  9827. AddMessage_Station(stationNameStr, LogType.Error,
  9828. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  9829. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9830. }
  9831. stopwatch1.Stop();
  9832. AddMessage(LogType.Info,
  9833. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  9834. stopwatch2.ElapsedMilliseconds + "ms");
  9835. }
  9836. /// <summary>
  9837. /// [S4] 取放桁架 - S4_1节拍接口
  9838. /// </summary>
  9839. /// <param name="plcNo">PLC编号</param>
  9840. /// <param name="stationNameStr">工站全称</param>
  9841. private void S4_1节拍接口(int plcNo, string stationNameStr)
  9842. {
  9843. Stopwatch stopwatch1 = new Stopwatch();
  9844. Stopwatch stopwatch2 = new Stopwatch();
  9845. string resultStr = string.Empty;
  9846. try
  9847. {
  9848. stopwatch1.Start();
  9849. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  9850. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  9851. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  9852. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9853. if (!actionBool)
  9854. {
  9855. stopwatch2.Start();
  9856. // MES_Flag
  9857. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9858. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9859. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  9860. writeToPLC_Flag1.Adress = 2398;
  9861. writeToPLC_Flag1.Value = (short)4;
  9862. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  9863. stopwatch2.Stop();
  9864. AddMessage(LogType.Info,
  9865. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  9866. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9867. return;
  9868. }
  9869. string d1OEEPartNo = string.Empty; // 物料码
  9870. if (string.IsNullOrEmpty(d1OEEProductSN))
  9871. {
  9872. stopwatch2.Start();
  9873. // MES_Flag
  9874. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9875. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9876. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  9877. writeToPLC_Flag1.Adress = 2398;
  9878. writeToPLC_Flag1.Value = (short)1;
  9879. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  9880. stopwatch2.Stop();
  9881. AddMessage(LogType.Info,
  9882. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9883. stopwatch2.ElapsedMilliseconds + "ms");
  9884. return;
  9885. }
  9886. else
  9887. {
  9888. // 查产品SN ZS
  9889. d1OEEPartNo = "Test";
  9890. }
  9891. short d1OEEMES_FLAG = 0;
  9892. // 上传OEE
  9893. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  9894. d1OEEMES_FLAG = result.Item1;
  9895. resultStr = result.Item2;
  9896. stopwatch2.Start();
  9897. // MES_Flag
  9898. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9899. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9900. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  9901. writeToPLC_Flag.Adress = 2398;
  9902. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  9903. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  9904. stopwatch2.Stop();
  9905. }
  9906. catch (Exception ex)
  9907. {
  9908. string str = ex.StackTrace;
  9909. AddMessage_Station(stationNameStr, LogType.Error,
  9910. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  9911. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9912. // MES_Flag
  9913. stopwatch2.Start();
  9914. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  9915. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9916. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  9917. writeToPLC_Flag.Adress = 2398;
  9918. writeToPLC_Flag.Value = (short)4;
  9919. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  9920. stopwatch2.Stop();
  9921. }
  9922. stopwatch1.Stop();
  9923. AddMessage(LogType.Info,
  9924. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9925. stopwatch2.ElapsedMilliseconds + "ms");
  9926. }
  9927. /// <summary>
  9928. /// [S4] 取放桁架 - S4_2桁架
  9929. /// </summary>
  9930. /// <param name="plcNo">PLC编号</param>
  9931. /// <param name="stationNameStr">工站全称</param>
  9932. private void S4_2桁架(int plcNo, string stationNameStr)
  9933. {
  9934. Stopwatch stopwatch1 = new Stopwatch();
  9935. Stopwatch stopwatch2 = new Stopwatch();
  9936. try
  9937. {
  9938. stopwatch1.Start();
  9939. // ZS 弹夹扫码
  9940. string d2BulletclipCode = " "; // 扫到的码
  9941. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  9942. short d2BulletclipScanCode = 2;
  9943. stopwatch2.Start();
  9944. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  9945. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  9946. //// MES_Flag
  9947. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  9948. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9949. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  9950. writeToPLC_Flag.Adress = 2430;
  9951. writeToPLC_Flag.Value = d2BulletclipScanCode;
  9952. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9953. {
  9954. Name = "d2BulletclipCode",
  9955. Adress = 2432,
  9956. ValueType = PLCValueType.String,
  9957. ValueTypeStrLength = 20,
  9958. Value = d2BulletclipCode
  9959. });
  9960. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9961. {
  9962. Name = "d2BulletclipStates",
  9963. Adress = 2431,
  9964. ValueType = PLCValueType.Short,
  9965. Value = d2BulletclipStates
  9966. });
  9967. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  9968. stopwatch2.Stop();
  9969. }
  9970. catch (Exception ex)
  9971. {
  9972. string str = ex.StackTrace;
  9973. AddMessage_Station(stationNameStr, LogType.Error,
  9974. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  9975. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9976. stopwatch2.Start();
  9977. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  9978. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  9979. // MES_Flag
  9980. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  9981. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9982. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  9983. writeToPLC_Flag.Adress = 2430;
  9984. writeToPLC_Flag.Value = (short)6;
  9985. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9986. {
  9987. Name = "d2BulletclipCode",
  9988. Adress = 2432,
  9989. ValueType = PLCValueType.String,
  9990. ValueTypeStrLength = 20,
  9991. Value = " "
  9992. });
  9993. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9994. {
  9995. Name = "d2BulletclipStates",
  9996. Adress = 2431,
  9997. ValueType = PLCValueType.Short,
  9998. Value = (short)0
  9999. });
  10000. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  10001. stopwatch2.Stop();
  10002. }
  10003. stopwatch1.Stop();
  10004. AddMessage(LogType.Info,
  10005. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10006. stopwatch2.ElapsedMilliseconds + "ms");
  10007. }
  10008. // 上次采集到的SN
  10009. //private string sn_S4_3进站接口 = string.Empty;
  10010. /// <summary>
  10011. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  10012. /// </summary>
  10013. private void S4_3进站接口(int plcNo, string stationNameStr)
  10014. {
  10015. Stopwatch stopwatch1 = new Stopwatch();
  10016. Stopwatch stopwatch2 = new Stopwatch();
  10017. try
  10018. {
  10019. stopwatch1.Start();
  10020. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  10021. sn = sn.Replace("\0", "");
  10022. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  10023. #region 查询15个载具码
  10024. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10025. string vehicleData = string.Empty;
  10026. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10027. if (string.IsNullOrEmpty(vehicleData))
  10028. vehicleData = "";
  10029. if (snResult != 0)
  10030. {
  10031. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10032. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10033. writeToPLC_Flag1.Adress = 2463;
  10034. writeToPLC_Flag1.Value = (short)4;
  10035. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10036. stopwatch1.Stop();
  10037. AddMessage(LogType.Info,
  10038. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10039. return;
  10040. }
  10041. string[] cavitySNs = vehicleData.Split('.');
  10042. if (cavitySNs != null && cavitySNs.Length > 0)
  10043. {
  10044. for (int i = 0; i < cavitySNs.Length; i++)
  10045. {
  10046. if (string.IsNullOrEmpty(cavitySNs[i]))
  10047. vehicleCodes.Add("");
  10048. else
  10049. vehicleCodes.Add(cavitySNs[i]);
  10050. }
  10051. }
  10052. #endregion 查询15个载具码
  10053. #region 查询15个产品SN
  10054. List<string> portNos = new List<string>(); // 15个产品SN
  10055. foreach (string vehicleCode in vehicleCodes)
  10056. {
  10057. if (string.IsNullOrEmpty(vehicleCode))
  10058. portNos.Add("");
  10059. else
  10060. {
  10061. // 查询
  10062. string cavityData = string.Empty;
  10063. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10064. if (string.IsNullOrEmpty(cavityData))
  10065. cavityData = "";
  10066. if (snResult1 != 0)
  10067. {
  10068. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10069. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10070. writeToPLC_Flag1.Adress = 2463;
  10071. writeToPLC_Flag1.Value = (short)4;
  10072. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10073. stopwatch1.Stop();
  10074. AddMessage(LogType.Info,
  10075. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  10076. stopwatch1.ElapsedMilliseconds + "ms");
  10077. return;
  10078. }
  10079. string[] partSNs = cavityData.Split('.');
  10080. if (partSNs != null && partSNs.Length >= 1)
  10081. portNos.Add(partSNs[0]);
  10082. else
  10083. portNos.Add("");
  10084. }
  10085. }
  10086. #endregion 查询15个产品SN
  10087. // 调用MES进站(最多15个)
  10088. stopwatch2.Start();
  10089. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  10090. for (int i = 0; i < vehicleCodes.Count; i++)
  10091. {
  10092. // 循环进站
  10093. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  10094. {
  10095. // 产品SN(物料码)校验
  10096. string portNo = portNos[i];
  10097. List<TestItem> item = new List<TestItem>();
  10098. item.Add(new TestItem()
  10099. {
  10100. Parameter_name = "弹夹码",
  10101. Parameter_value = sn,
  10102. });
  10103. item.Add(new TestItem()
  10104. {
  10105. Parameter_name = "弹夹穴位",
  10106. Parameter_value = (i + 1).ToString(),
  10107. });
  10108. item.Add(new TestItem()
  10109. {
  10110. Parameter_name = "载具码",
  10111. Parameter_value = vehicleCodes[i],
  10112. });
  10113. item.Add(new TestItem()
  10114. {
  10115. Parameter_name = "载具穴号",
  10116. Parameter_value = "1",
  10117. });
  10118. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  10119. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  10120. }
  10121. }
  10122. stopwatch2.Stop();
  10123. short result = 0;
  10124. bool haveMesWarn = results.Contains(5);
  10125. bool havePCWarn = results.Contains(6);
  10126. if (haveMesWarn)
  10127. result = 2; // 5->2
  10128. else if (havePCWarn)
  10129. result = 6; // 6->4
  10130. else
  10131. result = 1;
  10132. // MES_Flag 为4MES报错
  10133. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10134. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10135. writeToPLC_Flag.Name = "d3MES_FLAG";
  10136. writeToPLC_Flag.Adress = 2463;
  10137. writeToPLC_Flag.Value = result;
  10138. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10139. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10140. }
  10141. catch (Exception ex)
  10142. {
  10143. stopwatch2.Stop();
  10144. // MES_Flag 为4上位机报错
  10145. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  10146. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10147. writeToPLC_Flag.Name = "d3MES_FLAG";
  10148. writeToPLC_Flag.Adress = 2463;
  10149. writeToPLC_Flag.Value = (short)4;
  10150. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10151. string str = ex.StackTrace;
  10152. AddMessage_Station(stationNameStr, LogType.Error,
  10153. $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10154. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10155. }
  10156. stopwatch1.Stop();
  10157. AddMessage(LogType.Info,
  10158. stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  10159. stopwatch2.ElapsedMilliseconds + "ms");
  10160. }
  10161. // 上次采集到的SN
  10162. //private string sn_S4_3出站接口 = string.Empty;
  10163. /// <summary>
  10164. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  10165. /// </summary>
  10166. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  10167. {
  10168. Stopwatch stopwatch1 = new Stopwatch();
  10169. Stopwatch stopwatch2 = new Stopwatch();
  10170. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10171. string stationNameStr = stationCode + stationName;
  10172. string processItem = stationName; // 测试项目
  10173. try
  10174. {
  10175. stopwatch1.Start();
  10176. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10177. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10178. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10179. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10180. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  10181. sn = sn.Replace("\0", "");
  10182. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  10183. bool isPass = d3Result == 1; // 产品结果 bool
  10184. #region 查询15个载具码
  10185. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10186. string vehicleData = string.Empty;
  10187. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10188. if (string.IsNullOrEmpty(vehicleData))
  10189. vehicleData = "";
  10190. if (snResult1 != 0)
  10191. {
  10192. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10193. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10194. writeToPLC_Flag1.Adress = 2463;
  10195. writeToPLC_Flag1.Value = (short)4;
  10196. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10197. stopwatch1.Stop();
  10198. AddMessage(LogType.Info,
  10199. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10200. return;
  10201. }
  10202. string[] cavitySNs = vehicleData.Split('.');
  10203. if (cavitySNs != null && cavitySNs.Length > 0)
  10204. {
  10205. for (int i = 0; i < cavitySNs.Length; i++)
  10206. {
  10207. if (string.IsNullOrEmpty(cavitySNs[i]))
  10208. vehicleCodes.Add("");
  10209. else
  10210. vehicleCodes.Add(cavitySNs[i]);
  10211. }
  10212. }
  10213. #endregion 查询15个载具码
  10214. // 统一查 产品SN列表
  10215. List<string> partNos = new List<string>();
  10216. foreach (string vehicleCode in vehicleCodes)
  10217. {
  10218. if (string.IsNullOrEmpty(vehicleCode))
  10219. partNos.Add("");
  10220. else
  10221. {
  10222. string partNo = "";
  10223. #region 查询载具上的产品信息
  10224. string cavityData = string.Empty;
  10225. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10226. if (string.IsNullOrEmpty(cavityData))
  10227. cavityData = "";
  10228. if (snResult != 0)
  10229. {
  10230. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10231. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10232. writeToPLC_Flag1.Adress = 2463;
  10233. writeToPLC_Flag1.Value = (short)4;
  10234. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10235. stopwatch1.Stop();
  10236. AddMessage(LogType.Info,
  10237. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10238. "ms");
  10239. return;
  10240. }
  10241. string[] partSNs = cavityData.Split('.');
  10242. if (partSNs != null && partSNs.Length >= 1)
  10243. partNo = partSNs[0];
  10244. #endregion 查询载具上的产品信息
  10245. partNos.Add(partNo);
  10246. }
  10247. }
  10248. // 统一上传 - 调用MES出站
  10249. stopwatch2.Start();
  10250. List<int> results = new List<int>();
  10251. for (int i = 0; i < partNos.Count; i++)
  10252. {
  10253. string index = (i + 1).ToString(); // 弹夹穴号
  10254. if (string.IsNullOrEmpty(partNos[i]))
  10255. results.Add(1);
  10256. else
  10257. {
  10258. List<TestItem> items1 = new List<TestItem>();
  10259. items1.Add(new TestItem()
  10260. {
  10261. Parameter_name = "弹夹码",
  10262. Parameter_value = sn,
  10263. Parameter_unit = ""
  10264. });
  10265. items1.Add(new TestItem()
  10266. {
  10267. Parameter_name = "弹夹穴号",
  10268. Parameter_value = index,
  10269. Parameter_unit = ""
  10270. });
  10271. items1.Add(new TestItem()
  10272. {
  10273. Parameter_name = "载具码",
  10274. Parameter_value = vehicleCodes[i],
  10275. Parameter_unit = ""
  10276. });
  10277. items1.Add(new TestItem()
  10278. {
  10279. Parameter_name = "载具穴号",
  10280. Parameter_value = "1",
  10281. Parameter_unit = ""
  10282. });
  10283. items1.Add(new TestItem()
  10284. {
  10285. Parameter_name = "产品结果",
  10286. Parameter_value = d3Result == 1 ? "OK" : "NG",
  10287. Parameter_unit = ""
  10288. });
  10289. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  10290. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  10291. results.Add(result1);
  10292. }
  10293. }
  10294. short result = 0;
  10295. if (results.All(a => a == 1))
  10296. result = 1;
  10297. else if (results.Contains(3))
  10298. result = 3;
  10299. else if (results.Contains(2))
  10300. result = 2;
  10301. else if (results.Contains(4))
  10302. result = 4;
  10303. else
  10304. result = 4;
  10305. stopwatch2.Stop();
  10306. // MES_Flag 为4MES报错
  10307. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10308. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10309. writeToPLC_Flag.Name = "d3MES_FLAG";
  10310. writeToPLC_Flag.Adress = 2463;
  10311. writeToPLC_Flag.Value = result;
  10312. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10313. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10314. }
  10315. catch (Exception ex)
  10316. {
  10317. stopwatch2.Restart();
  10318. // MES_Flag 为4上位机报错
  10319. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  10320. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10321. writeToPLC_Flag.Name = "d3MES_FLAG";
  10322. writeToPLC_Flag.Adress = 2463;
  10323. writeToPLC_Flag.Value = (short)4;
  10324. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10325. string str = ex.StackTrace;
  10326. AddMessage_Station(stationNameStr, LogType.Error,
  10327. $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10328. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10329. stopwatch2.Stop();
  10330. }
  10331. stopwatch1.Stop();
  10332. AddMessage(LogType.Info,
  10333. stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10334. stopwatch2.ElapsedMilliseconds + "ms");
  10335. }
  10336. // 上次采集到的SN
  10337. //private string sn_S4_4进站接口 = string.Empty;
  10338. /// <summary>
  10339. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  10340. /// </summary>
  10341. private void S4_4进站接口(int plcNo, string stationNameStr)
  10342. {
  10343. Stopwatch stopwatch1 = new Stopwatch();
  10344. Stopwatch stopwatch2 = new Stopwatch();
  10345. try
  10346. {
  10347. stopwatch1.Start();
  10348. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  10349. sn = sn.Replace("\0", "");
  10350. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  10351. #region 查询15个载具码
  10352. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10353. string vehicleData = string.Empty;
  10354. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10355. if (string.IsNullOrEmpty(vehicleData))
  10356. vehicleData = "";
  10357. if (snResult != 0)
  10358. {
  10359. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10360. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10361. writeToPLC_Flag1.Adress = 2463;
  10362. writeToPLC_Flag1.Value = (short)4;
  10363. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10364. stopwatch1.Stop();
  10365. AddMessage(LogType.Info,
  10366. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10367. return;
  10368. }
  10369. string[] cavitySNs = vehicleData.Split('.');
  10370. if (cavitySNs != null && cavitySNs.Length > 0)
  10371. {
  10372. for (int i = 0; i < cavitySNs.Length; i++)
  10373. {
  10374. if (string.IsNullOrEmpty(cavitySNs[i]))
  10375. vehicleCodes.Add("");
  10376. else
  10377. vehicleCodes.Add(cavitySNs[i]);
  10378. }
  10379. }
  10380. #endregion 查询15个载具码
  10381. #region 查询15个产品SN
  10382. List<string> portNos = new List<string>(); // 15个产品SN
  10383. foreach (string vehicleCode in vehicleCodes)
  10384. {
  10385. if (string.IsNullOrEmpty(vehicleCode))
  10386. portNos.Add("");
  10387. else
  10388. {
  10389. // 查询
  10390. string cavityData = string.Empty;
  10391. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10392. if (string.IsNullOrEmpty(cavityData))
  10393. cavityData = "";
  10394. if (snResult1 != 0)
  10395. {
  10396. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10397. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10398. writeToPLC_Flag1.Adress = 2463;
  10399. writeToPLC_Flag1.Value = (short)4;
  10400. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10401. stopwatch1.Stop();
  10402. AddMessage(LogType.Info,
  10403. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  10404. stopwatch1.ElapsedMilliseconds + "ms");
  10405. return;
  10406. }
  10407. string[] partSNs = cavityData.Split('.');
  10408. if (partSNs != null && partSNs.Length >= 1)
  10409. portNos.Add(partSNs[0]);
  10410. else
  10411. portNos.Add("");
  10412. }
  10413. }
  10414. #endregion 查询15个产品SN
  10415. // 调用MES进站(最多15个)
  10416. stopwatch2.Start();
  10417. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  10418. for (int i = 0; i < vehicleCodes.Count; i++)
  10419. {
  10420. // 循环进站
  10421. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  10422. {
  10423. // 产品SN(物料码)校验
  10424. string portNo = portNos[i];
  10425. List<TestItem> item = new List<TestItem>();
  10426. item.Add(new TestItem()
  10427. {
  10428. Parameter_name = "弹夹码",
  10429. Parameter_value = sn,
  10430. });
  10431. item.Add(new TestItem()
  10432. {
  10433. Parameter_name = "弹夹穴位",
  10434. Parameter_value = (i + 1).ToString(),
  10435. });
  10436. item.Add(new TestItem()
  10437. {
  10438. Parameter_name = "载具码",
  10439. Parameter_value = vehicleCodes[i],
  10440. });
  10441. item.Add(new TestItem()
  10442. {
  10443. Parameter_name = "载具穴号",
  10444. Parameter_value = "1",
  10445. });
  10446. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  10447. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  10448. }
  10449. }
  10450. stopwatch2.Stop();
  10451. short result = 0;
  10452. bool haveMesWarn = results.Contains(5);
  10453. bool havePCWarn = results.Contains(6);
  10454. if (haveMesWarn)
  10455. result = 2; // 5->2
  10456. else if (havePCWarn)
  10457. result = 6; // 6->4
  10458. else
  10459. result = 1;
  10460. // MES_Flag 为4MES报错
  10461. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10462. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10463. writeToPLC_Flag.Name = "d4MES_FLAG";
  10464. writeToPLC_Flag.Adress = 2496;
  10465. writeToPLC_Flag.Value = result;
  10466. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10467. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10468. }
  10469. catch (Exception ex)
  10470. {
  10471. stopwatch2.Stop();
  10472. // MES_Flag 为4上位机报错
  10473. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  10474. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10475. writeToPLC_Flag.Name = "d4MES_FLAG";
  10476. writeToPLC_Flag.Adress = 2496;
  10477. writeToPLC_Flag.Value = (short)4;
  10478. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10479. string str = ex.StackTrace;
  10480. AddMessage_Station(stationNameStr, LogType.Error,
  10481. $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10482. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10483. }
  10484. stopwatch1.Stop();
  10485. AddMessage(LogType.Info,
  10486. stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  10487. stopwatch2.ElapsedMilliseconds + "ms");
  10488. }
  10489. // 上次采集到的SN
  10490. //private string sn_S4_4出站接口 = string.Empty;
  10491. /// <summary>
  10492. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  10493. /// </summary>
  10494. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  10495. {
  10496. Stopwatch stopwatch1 = new Stopwatch();
  10497. Stopwatch stopwatch2 = new Stopwatch();
  10498. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10499. string stationNameStr = stationCode + stationName;
  10500. string processItem = stationName; // 测试项目
  10501. try
  10502. {
  10503. stopwatch1.Start();
  10504. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10505. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10506. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10507. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10508. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  10509. sn = sn.Replace("\0", "");
  10510. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  10511. bool isPass = d4Result == 1; // 产品结果 bool
  10512. #region 查询15个载具码
  10513. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10514. string vehicleData = string.Empty;
  10515. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10516. if (string.IsNullOrEmpty(vehicleData))
  10517. vehicleData = "";
  10518. if (snResult1 != 0)
  10519. {
  10520. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10521. writeToPLC_Flag1.Name = "d4MES_FLAG";
  10522. writeToPLC_Flag1.Adress = 2496;
  10523. writeToPLC_Flag1.Value = (short)4;
  10524. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  10525. stopwatch1.Stop();
  10526. AddMessage(LogType.Info,
  10527. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10528. return;
  10529. }
  10530. string[] cavitySNs = vehicleData.Split('.');
  10531. if (cavitySNs != null && cavitySNs.Length > 0)
  10532. {
  10533. for (int i = 0; i < cavitySNs.Length; i++)
  10534. {
  10535. if (string.IsNullOrEmpty(cavitySNs[i]))
  10536. vehicleCodes.Add("");
  10537. else
  10538. vehicleCodes.Add(cavitySNs[i]);
  10539. }
  10540. }
  10541. #endregion 查询15个载具码
  10542. // 统一查 产品SN列表
  10543. List<string> partNos = new List<string>();
  10544. foreach (string vehicleCode in vehicleCodes)
  10545. {
  10546. if (string.IsNullOrEmpty(vehicleCode))
  10547. partNos.Add("");
  10548. else
  10549. {
  10550. string partNo = "";
  10551. #region 查询载具上的产品信息
  10552. string cavityData = string.Empty;
  10553. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10554. if (string.IsNullOrEmpty(cavityData))
  10555. cavityData = "";
  10556. if (snResult != 0)
  10557. {
  10558. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10559. writeToPLC_Flag1.Name = "d4MES_FLAG";
  10560. writeToPLC_Flag1.Adress = 2496;
  10561. writeToPLC_Flag1.Value = (short)4;
  10562. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  10563. stopwatch1.Stop();
  10564. AddMessage(LogType.Info,
  10565. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10566. "ms");
  10567. return;
  10568. }
  10569. string[] partSNs = cavityData.Split('.');
  10570. if (partSNs != null && partSNs.Length >= 1)
  10571. partNo = partSNs[0];
  10572. #endregion 查询载具上的产品信息
  10573. partNos.Add(partNo);
  10574. }
  10575. }
  10576. // 调用MES出站
  10577. stopwatch2.Start();
  10578. // 统一上传
  10579. List<int> results = new List<int>();
  10580. for (int i = 0; i < partNos.Count; i++)
  10581. {
  10582. string index = (i + 1).ToString(); // 弹夹穴号
  10583. if (string.IsNullOrEmpty(partNos[i]))
  10584. results.Add(1);
  10585. else
  10586. {
  10587. List<TestItem> items1 = new List<TestItem>();
  10588. items1.Add(new TestItem()
  10589. {
  10590. Parameter_name = "弹夹码",
  10591. Parameter_value = sn,
  10592. Parameter_unit = ""
  10593. });
  10594. items1.Add(new TestItem()
  10595. {
  10596. Parameter_name = "弹夹穴号",
  10597. Parameter_value = index,
  10598. Parameter_unit = ""
  10599. });
  10600. items1.Add(new TestItem()
  10601. {
  10602. Parameter_name = "载具码",
  10603. Parameter_value = vehicleCodes[i],
  10604. Parameter_unit = ""
  10605. });
  10606. items1.Add(new TestItem()
  10607. {
  10608. Parameter_name = "载具穴号",
  10609. Parameter_value = "1",
  10610. Parameter_unit = ""
  10611. });
  10612. items1.Add(new TestItem()
  10613. {
  10614. Parameter_name = "产品结果",
  10615. Parameter_value = d4Result == 1 ? "OK" : "NG",
  10616. Parameter_unit = ""
  10617. });
  10618. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  10619. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  10620. results.Add(result1);
  10621. }
  10622. }
  10623. short result = 0;
  10624. if (results.All(a => a == 1))
  10625. result = 1;
  10626. else if (results.Contains(3))
  10627. result = 3;
  10628. else if (results.Contains(2))
  10629. result = 2;
  10630. else if (results.Contains(4))
  10631. result = 4;
  10632. else
  10633. result = 4;
  10634. stopwatch2.Stop();
  10635. // MES_Flag 为4MES报错
  10636. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10637. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10638. writeToPLC_Flag.Name = "d4MES_FLAG";
  10639. writeToPLC_Flag.Adress = 2496;
  10640. writeToPLC_Flag.Value = result;
  10641. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10642. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10643. }
  10644. catch (Exception ex)
  10645. {
  10646. stopwatch2.Restart();
  10647. // MES_Flag 为4上位机报错
  10648. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  10649. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10650. writeToPLC_Flag.Name = "d4MES_FLAG";
  10651. writeToPLC_Flag.Adress = 2496;
  10652. writeToPLC_Flag.Value = (short)4;
  10653. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10654. string str = ex.StackTrace;
  10655. AddMessage_Station(stationNameStr, LogType.Error,
  10656. $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10657. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10658. stopwatch2.Stop();
  10659. }
  10660. stopwatch1.Stop();
  10661. AddMessage(LogType.Info,
  10662. stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10663. stopwatch2.ElapsedMilliseconds + "ms");
  10664. }
  10665. /// <summary>
  10666. /// [S4] 取放桁架 - S4_5弹夹扫码
  10667. /// </summary>
  10668. /// <param name="plcNo">PLC编号</param>
  10669. /// <param name="stationNameStr">工站全称</param>
  10670. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  10671. {
  10672. Stopwatch stopwatch1 = new Stopwatch();
  10673. Stopwatch stopwatch2 = new Stopwatch();
  10674. try
  10675. {
  10676. stopwatch1.Start();
  10677. // ZS 弹夹扫码
  10678. string d5BulletclipCode = " "; // 扫到的码
  10679. short d5BulletclipScanCode = 2;
  10680. stopwatch2.Start();
  10681. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  10682. //// MES_Flag
  10683. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10684. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10685. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  10686. writeToPLC_Flag.Adress = 2528;
  10687. writeToPLC_Flag.Value = d5BulletclipScanCode;
  10688. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10689. {
  10690. Name = "d5BulletclipCode",
  10691. Adress = 2529,
  10692. ValueType = PLCValueType.String,
  10693. ValueTypeStrLength = 20,
  10694. Value = d5BulletclipCode
  10695. });
  10696. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  10697. stopwatch2.Stop();
  10698. }
  10699. catch (Exception ex)
  10700. {
  10701. string str = ex.StackTrace;
  10702. AddMessage_Station(stationNameStr, LogType.Error,
  10703. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10704. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10705. stopwatch2.Start();
  10706. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  10707. //// MES_Flag
  10708. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  10709. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10710. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  10711. writeToPLC_Flag.Adress = 2528;
  10712. writeToPLC_Flag.Value = (short)6;
  10713. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10714. {
  10715. Name = "d5BulletclipCode",
  10716. Adress = 2529,
  10717. ValueType = PLCValueType.String,
  10718. ValueTypeStrLength = 20,
  10719. Value = " "
  10720. });
  10721. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  10722. stopwatch2.Stop();
  10723. }
  10724. stopwatch1.Stop();
  10725. AddMessage(LogType.Info,
  10726. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10727. stopwatch2.ElapsedMilliseconds + "ms");
  10728. }
  10729. /// <summary>
  10730. /// [S4] 取放桁架 - S4_5载具扫码
  10731. /// </summary>
  10732. /// <param name="plcNo">PLC编号</param>
  10733. /// <param name="stationNameStr">工站全称</param>
  10734. private void S4_5载具扫码(int plcNo, string stationNameStr)
  10735. {
  10736. Stopwatch stopwatch1 = new Stopwatch();
  10737. Stopwatch stopwatch2 = new Stopwatch();
  10738. try
  10739. {
  10740. stopwatch1.Start();
  10741. // ZS 载具扫码
  10742. string d5VehicleCode = " "; // 扫到的码
  10743. short d5VehicleScanCode = 2;
  10744. #region 进站
  10745. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  10746. {
  10747. // 查产品SN
  10748. #region 查询载具上的产品信息
  10749. string cavityData = string.Empty;
  10750. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  10751. if (string.IsNullOrEmpty(cavityData))
  10752. cavityData = "";
  10753. if (snResult != 0)
  10754. {
  10755. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10756. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  10757. writeToPLC_Flag1.Adress = 2559;
  10758. writeToPLC_Flag1.Value = (short)6;
  10759. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10760. {
  10761. Name = "d5VehicleCode",
  10762. Adress = 2560,
  10763. ValueType = PLCValueType.String,
  10764. ValueTypeStrLength = 20,
  10765. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  10766. });
  10767. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  10768. stopwatch1.Stop();
  10769. AddMessage(LogType.Info,
  10770. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10771. "ms");
  10772. return;
  10773. }
  10774. string[] cavitySNs = cavityData.Split('.');
  10775. string partNo = "";
  10776. if (cavitySNs != null && cavitySNs.Length >= 1)
  10777. {
  10778. partNo = cavitySNs[0];
  10779. }
  10780. #endregion 查询载具上的产品信息
  10781. List<TestItem> item = new List<TestItem>();
  10782. item.Add(new TestItem()
  10783. {
  10784. Parameter_name = "载具码",
  10785. Parameter_value = d5VehicleCode,
  10786. });
  10787. item.Add(new TestItem()
  10788. {
  10789. Parameter_name = "载具穴号",
  10790. Parameter_value = "1",
  10791. });
  10792. stopwatch2.Start();
  10793. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  10794. partNo, item, out string errorMsg);
  10795. stopwatch2.Stop();
  10796. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  10797. }
  10798. #endregion 进站
  10799. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  10800. //// MES_Flag
  10801. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10802. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10803. writeToPLC_Flag.Name = "d5VehicleScanCode";
  10804. writeToPLC_Flag.Adress = 2559;
  10805. writeToPLC_Flag.Value = d5VehicleScanCode;
  10806. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10807. {
  10808. Name = "d5VehicleCode",
  10809. Adress = 2560,
  10810. ValueType = PLCValueType.String,
  10811. ValueTypeStrLength = 20,
  10812. Value = d5VehicleCode
  10813. });
  10814. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  10815. }
  10816. catch (Exception ex)
  10817. {
  10818. string str = ex.StackTrace;
  10819. AddMessage_Station(stationNameStr, LogType.Error,
  10820. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10821. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10822. stopwatch2.Start();
  10823. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  10824. //// MES_Flag
  10825. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  10826. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10827. writeToPLC_Flag.Name = "d5VehicleScanCode";
  10828. writeToPLC_Flag.Adress = 2559;
  10829. writeToPLC_Flag.Value = (short)6;
  10830. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10831. {
  10832. Name = "d5VehicleCode",
  10833. Adress = 2560,
  10834. ValueType = PLCValueType.String,
  10835. ValueTypeStrLength = 20,
  10836. Value = " "
  10837. });
  10838. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  10839. stopwatch2.Stop();
  10840. }
  10841. stopwatch1.Stop();
  10842. AddMessage(LogType.Info,
  10843. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10844. stopwatch2.ElapsedMilliseconds + "ms");
  10845. }
  10846. // 上次采集到的SN
  10847. //private string sn_S4_5出站接口 = string.Empty;
  10848. /// <summary>
  10849. /// [S4] 取放桁架 - S4_5出站接口
  10850. /// </summary>
  10851. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  10852. {
  10853. Stopwatch stopwatch1 = new Stopwatch();
  10854. Stopwatch stopwatch2 = new Stopwatch();
  10855. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10856. string stationNameStr = stationCode + stationName;
  10857. string processItem = stationName; // 测试项目
  10858. try
  10859. {
  10860. stopwatch1.Start();
  10861. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10862. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10863. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10864. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10865. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  10866. sn = sn.Replace("\0", "");
  10867. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  10868. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  10869. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  10870. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  10871. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  10872. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  10873. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  10874. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  10875. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  10876. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  10877. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  10878. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  10879. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  10880. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  10881. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  10882. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  10883. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  10884. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  10885. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  10886. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  10887. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  10888. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  10889. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  10890. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  10891. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  10892. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  10893. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  10894. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  10895. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  10896. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  10897. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  10898. bool pass = d5Result == 1;
  10899. // 存 载具SN列表
  10900. List<string> vehicleCodes = new List<string>()
  10901. {
  10902. d5VehicleCode1, d5VehicleCode2, d5VehicleCode3, d5VehicleCode4, d5VehicleCode5,
  10903. d5VehicleCode6, d5VehicleCode7, d5VehicleCode8, d5VehicleCode9, d5VehicleCode10,
  10904. d5VehicleCode11, d5VehicleCode12, d5VehicleCode13, d5VehicleCode14, d5VehicleCode15
  10905. };
  10906. // 统一查 产品SN列表
  10907. List<string> partNos = new List<string>();
  10908. foreach (string vehicleCode in vehicleCodes)
  10909. {
  10910. if (string.IsNullOrEmpty(vehicleCode))
  10911. partNos.Add("");
  10912. else
  10913. {
  10914. string partNo = "";
  10915. #region 查询载具上的产品信息
  10916. string cavityData = string.Empty;
  10917. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10918. if (string.IsNullOrEmpty(cavityData))
  10919. cavityData = "";
  10920. if (snResult != 0)
  10921. {
  10922. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10923. writeToPLC_Flag1.Name = "d5MES_FLAG";
  10924. writeToPLC_Flag1.Adress = 2591;
  10925. writeToPLC_Flag1.Value = (short)4;
  10926. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  10927. stopwatch1.Stop();
  10928. AddMessage(LogType.Info,
  10929. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10930. "ms");
  10931. return;
  10932. }
  10933. string[] cavitySNs = cavityData.Split('.');
  10934. if (cavitySNs != null && cavitySNs.Length >= 1)
  10935. partNo = cavitySNs[0];
  10936. #endregion 查询载具上的产品信息
  10937. partNos.Add(partNo);
  10938. }
  10939. }
  10940. // 统一上传
  10941. stopwatch2.Start();
  10942. List<int> results = new List<int>();
  10943. for (int i = 0; i < partNos.Count; i++)
  10944. {
  10945. string index = (i + 1).ToString(); // 弹夹穴号
  10946. if (string.IsNullOrEmpty(partNos[i]))
  10947. results.Add(1);
  10948. else
  10949. {
  10950. List<TestItem> items1 = new List<TestItem>();
  10951. items1.Add(new TestItem()
  10952. {
  10953. Parameter_name = "弹夹码",
  10954. Parameter_value = sn,
  10955. Parameter_unit = ""
  10956. });
  10957. items1.Add(new TestItem()
  10958. {
  10959. Parameter_name = "弹夹穴号",
  10960. Parameter_value = index,
  10961. Parameter_unit = ""
  10962. });
  10963. items1.Add(new TestItem()
  10964. {
  10965. Parameter_name = "载具码",
  10966. Parameter_value = vehicleCodes[i],
  10967. Parameter_unit = ""
  10968. });
  10969. items1.Add(new TestItem()
  10970. {
  10971. Parameter_name = "载具穴号",
  10972. Parameter_value = "1",
  10973. Parameter_unit = ""
  10974. });
  10975. items1.Add(new TestItem()
  10976. {
  10977. Parameter_name = "产品结果",
  10978. Parameter_value = d5Result == 1 ? "OK" : "NG",
  10979. Parameter_unit = ""
  10980. });
  10981. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  10982. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  10983. results.Add(result1);
  10984. }
  10985. }
  10986. short result = 0;
  10987. if (results.All(a => a == 1))
  10988. result = 1;
  10989. else if (results.Contains(3))
  10990. result = 3;
  10991. else if (results.Contains(2))
  10992. result = 2;
  10993. else if (results.Contains(4))
  10994. result = 4;
  10995. else
  10996. result = 4;
  10997. stopwatch2.Stop();
  10998. #region 存储绑定数据到 边线MES系统中
  10999. if (result == 1)
  11000. {
  11001. // 删除绑定信息
  11002. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  11003. if (resultMesR != 0)
  11004. {
  11005. result = 4;
  11006. AddMessage_Station(stationNameStr, LogType.Error,
  11007. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  11008. }
  11009. }
  11010. #endregion 存储绑定数据到 边线MES系统中
  11011. // MES_Flag 为4MES报错
  11012. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11013. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11014. writeToPLC_Flag.Name = "d5MES_FLAG";
  11015. writeToPLC_Flag.Adress = 2591;
  11016. writeToPLC_Flag.Value = result;
  11017. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  11018. OnMessage(LogType.Debug,
  11019. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  11020. }
  11021. catch (Exception ex)
  11022. {
  11023. stopwatch2.Restart();
  11024. // MES_Flag 为4上位机报错
  11025. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  11026. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11027. writeToPLC_Flag.Name = "d5MES_FLAG";
  11028. writeToPLC_Flag.Adress = 2591;
  11029. writeToPLC_Flag.Value = (short)4;
  11030. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  11031. stopwatch2.Stop();
  11032. string str = ex.StackTrace;
  11033. AddMessage_Station(stationNameStr, LogType.Error,
  11034. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11035. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11036. }
  11037. stopwatch1.Stop();
  11038. AddMessage(LogType.Info,
  11039. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11040. stopwatch2.ElapsedMilliseconds + "ms");
  11041. }
  11042. /// <summary>
  11043. /// [S4] 取放桁架 - S4_5节拍接口
  11044. /// </summary>
  11045. /// <param name="plcNo">PLC编号</param>
  11046. /// <param name="stationNameStr">工站全称</param>
  11047. private void S4_5节拍接口(int plcNo, string stationNameStr)
  11048. {
  11049. Stopwatch stopwatch1 = new Stopwatch();
  11050. Stopwatch stopwatch2 = new Stopwatch();
  11051. string resultStr = string.Empty;
  11052. try
  11053. {
  11054. stopwatch1.Start();
  11055. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  11056. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  11057. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  11058. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  11059. if (!actionBool)
  11060. {
  11061. stopwatch2.Start();
  11062. // MES_Flag
  11063. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  11064. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11065. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  11066. writeToPLC_Flag1.Adress = 2924;
  11067. writeToPLC_Flag1.Value = (short)4;
  11068. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  11069. stopwatch2.Stop();
  11070. AddMessage(LogType.Info,
  11071. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  11072. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  11073. return;
  11074. }
  11075. string d5OEEPartNo = string.Empty; // 物料码
  11076. if (string.IsNullOrEmpty(d5OEEProductSN))
  11077. {
  11078. stopwatch2.Start();
  11079. // MES_Flag
  11080. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11081. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11082. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  11083. writeToPLC_Flag1.Adress = 2924;
  11084. writeToPLC_Flag1.Value = (short)1;
  11085. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  11086. stopwatch2.Stop();
  11087. AddMessage(LogType.Info,
  11088. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11089. stopwatch2.ElapsedMilliseconds + "ms");
  11090. return;
  11091. }
  11092. else
  11093. {
  11094. // 查产品SN
  11095. d5OEEPartNo = "Test"; // ZS
  11096. }
  11097. short d5OEEMES_FLAG = 0;
  11098. // 上传OEE
  11099. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  11100. d5OEEMES_FLAG = result.Item1;
  11101. resultStr = result.Item2;
  11102. stopwatch2.Start();
  11103. // MES_Flag
  11104. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11105. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11106. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  11107. writeToPLC_Flag.Adress = 2924;
  11108. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  11109. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  11110. stopwatch2.Stop();
  11111. }
  11112. catch (Exception ex)
  11113. {
  11114. string str = ex.StackTrace;
  11115. AddMessage_Station(stationNameStr, LogType.Error,
  11116. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  11117. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11118. // MES_Flag
  11119. stopwatch2.Start();
  11120. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  11121. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11122. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  11123. writeToPLC_Flag.Adress = 2924;
  11124. writeToPLC_Flag.Value = (short)4;
  11125. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  11126. stopwatch2.Stop();
  11127. }
  11128. stopwatch1.Stop();
  11129. AddMessage(LogType.Info,
  11130. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11131. stopwatch2.ElapsedMilliseconds + "ms");
  11132. }
  11133. #endregion [S4] 取放桁架
  11134. #endregion PLC4 刘果段
  11135. #region PLC5 张超凡
  11136. #region [S5] Tray盘下料装备
  11137. /// <summary>
  11138. /// S5工位的数据- 触发信号上次的值
  11139. /// </summary>
  11140. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  11141. /// <summary>
  11142. /// S5工位的数据(含触发信号)
  11143. /// </summary>
  11144. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  11145. /// <summary>
  11146. /// S5工位的数据- 回写点位
  11147. /// </summary>
  11148. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  11149. /// <summary>
  11150. /// [S5] Tray盘下料装备
  11151. /// </summary>
  11152. /// <param name="plcNo">PLC编号</param>
  11153. //private void ReadStation_S5(int plcNo)
  11154. //{
  11155. // // [S1] Tray盘上料装备
  11156. // // [S2] FCT
  11157. // // [S3] 值板机
  11158. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  11159. // // [S5] Tray盘下料装备
  11160. // /// 上位机心跳
  11161. // /// 获取设备报警数据与状态信息
  11162. // string stationCode = "[S5]";
  11163. // string stationName = "Tray盘下料装备";
  11164. // string stationNameStr = stationCode + stationName;
  11165. // #region 创建字典
  11166. // // 触发信号字典 赋值
  11167. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  11168. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  11169. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  11170. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  11171. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  11172. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  11173. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  11174. // // PLC数据字典 赋值
  11175. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  11176. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  11177. // s5PLCData.Add("e1ProductSN_Check", ""); //
  11178. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  11179. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  11180. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  11181. // s5PLCData.Add("e1PartNo", ""); // 物料码
  11182. // s5PLCData.Add("e1Result", 0); // 产品结果
  11183. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  11184. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  11185. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  11186. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  11187. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  11188. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  11189. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  11190. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  11191. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  11192. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  11193. // #endregion 创建字典
  11194. // while (IsRun)
  11195. // {
  11196. // try
  11197. // {
  11198. // if (!GlobalContext._IsCon_Funs5)
  11199. // {
  11200. // UpdatePLCMonitor(1, plcNo, 0);
  11201. // continue;
  11202. // }
  11203. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  11204. // {
  11205. // Stopwatch stopwatch1 = new Stopwatch();
  11206. // Stopwatch stopwatch2 = new Stopwatch();
  11207. // stopwatch1.Start();
  11208. // stopwatch2.Start();
  11209. // #region 一次性读取所有数据
  11210. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  11211. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  11212. // int[] datas = data1.Concat(data2).ToArray();
  11213. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  11214. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  11215. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  11216. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  11217. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  11218. // s5PLCData["e1MES_FLAG"] = datas[35];
  11219. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  11220. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  11221. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  11222. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  11223. // s5PLCData["e1Result"] = datas[76];
  11224. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  11225. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  11226. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  11227. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  11228. // s5PLCData["e1OEEType"] = datas[109];
  11229. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  11230. // s5PLCData["e1AGVUpStart"] = datas[121];
  11231. // s5PLCData["e1AGVUpEnd"] = datas[122];
  11232. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  11233. // s5PLCData["e1AGVDownStart"] = datas[134];
  11234. // s5PLCData["e1AGVDownEnd"] = datas[135];
  11235. // #endregion 一次性读取所有数据
  11236. // stopwatch2.Stop();
  11237. // #region 回写操作,写后清空flag
  11238. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  11239. // #endregion 回写操作,写后清空flag
  11240. // #region 进站校验
  11241. // try
  11242. // {
  11243. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  11244. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  11245. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  11246. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  11247. // {
  11248. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  11249. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  11250. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  11251. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  11252. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  11253. // }
  11254. // }
  11255. // catch (Exception ex)
  11256. // {
  11257. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  11258. // string str = ex.StackTrace;
  11259. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11260. // }
  11261. // #endregion 进站校验
  11262. // #region 出站接口
  11263. // try
  11264. // {
  11265. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  11266. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  11267. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  11268. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  11269. // {
  11270. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  11271. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  11272. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  11273. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  11274. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  11275. // }
  11276. // }
  11277. // catch (Exception ex)
  11278. // {
  11279. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  11280. // string str = ex.StackTrace;
  11281. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11282. // }
  11283. // #endregion 出站接口
  11284. // #region 节拍接口
  11285. // try
  11286. // {
  11287. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  11288. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  11289. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  11290. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  11291. // {
  11292. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  11293. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  11294. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  11295. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  11296. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  11297. // }
  11298. // }
  11299. // catch (Exception ex)
  11300. // {
  11301. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  11302. // string str = ex.StackTrace;
  11303. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11304. // }
  11305. // #endregion 节拍接口
  11306. // #region AGV上料
  11307. // // AGV上料叫AGV信号
  11308. // try
  11309. // {
  11310. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  11311. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  11312. // if (e1AGVUpCall != e1AGVUpCallOld)
  11313. // {
  11314. // if (e1AGVUpCall == 1) // 0->1
  11315. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  11316. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  11317. // }
  11318. // }
  11319. // catch (Exception ex)
  11320. // {
  11321. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  11322. // string str = ex.StackTrace;
  11323. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11324. // }
  11325. // // AGV上料完成信号
  11326. // try
  11327. // {
  11328. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  11329. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  11330. // if (e1AGVUpEnd != e1AGVUpEndOld)
  11331. // {
  11332. // if (e1AGVUpEnd == 1) // 0->1
  11333. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  11334. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  11335. // }
  11336. // }
  11337. // catch (Exception ex)
  11338. // {
  11339. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  11340. // string str = ex.StackTrace;
  11341. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11342. // }
  11343. // #endregion AGV上料
  11344. // #region AGV下料
  11345. // // AGV下料叫agv信号
  11346. // try
  11347. // {
  11348. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  11349. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  11350. // if (e1AGVDownCall != e1AGVDownCallOld)
  11351. // {
  11352. // if (e1AGVDownCall == 1) // 0->1
  11353. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  11354. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  11355. // }
  11356. // }
  11357. // catch (Exception ex)
  11358. // {
  11359. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  11360. // string str = ex.StackTrace;
  11361. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11362. // }
  11363. // // AGV下料完成信号
  11364. // try
  11365. // {
  11366. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  11367. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  11368. // if (e1AGVDownEnd != e1AGVDownEndOld)
  11369. // {
  11370. // if (e1AGVDownEnd == 1) // 0->1
  11371. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  11372. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  11373. // }
  11374. // }
  11375. // catch (Exception ex)
  11376. // {
  11377. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  11378. // string str = ex.StackTrace;
  11379. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11380. // }
  11381. // #endregion AGV下料
  11382. // #region 心跳
  11383. // try
  11384. // {
  11385. // short states = 0;
  11386. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  11387. // }
  11388. // catch (Exception ex)
  11389. // {
  11390. // string str = ex.StackTrace;
  11391. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11392. // }
  11393. // #endregion 心跳
  11394. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  11395. // stopwatch1.Stop();
  11396. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  11397. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  11398. // }
  11399. // else
  11400. // {
  11401. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  11402. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  11403. // Funs[plcNo].Connect();
  11404. // }
  11405. // }
  11406. // catch (Exception ex)
  11407. // {
  11408. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  11409. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  11410. // Funs[plcNo].ReConnect();
  11411. // }
  11412. // Thread.Sleep(IntervalReadPLC);
  11413. // }
  11414. //}
  11415. /// <summary>
  11416. /// [S5] Tray盘下料装备 - 进站校验
  11417. /// </summary>
  11418. /// <param name="plcNo">PLC编号</param>
  11419. /// <param name="stationNameStr">工站全称</param>
  11420. private void S5进站校验(int plcNo, string stationNameStr)
  11421. {
  11422. Stopwatch stopwatch1 = new Stopwatch();
  11423. Stopwatch stopwatch2 = new Stopwatch();
  11424. try
  11425. {
  11426. stopwatch1.Start();
  11427. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  11428. sn = sn.Replace("\0", "");
  11429. // 获取产品SN By 载具码
  11430. #region 查询载具上的产品信息
  11431. string cavityData = string.Empty;
  11432. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  11433. if (string.IsNullOrEmpty(cavityData))
  11434. cavityData = "";
  11435. if (snResult != 0)
  11436. {
  11437. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11438. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  11439. writeToPLC_Flag1.Adress = 2003;
  11440. writeToPLC_Flag1.Value = (short)6;
  11441. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  11442. stopwatch1.Stop();
  11443. AddMessage(LogType.Info,
  11444. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11445. return;
  11446. }
  11447. string[] cavitySNs = cavityData.Split('.');
  11448. string partNo = string.Empty;
  11449. if (cavitySNs != null && cavitySNs.Length >= 1)
  11450. partNo = cavitySNs[0];
  11451. #endregion 查询载具上的产品信息
  11452. // 产品SN(物料码)校验
  11453. List<TestItem> item = new List<TestItem>();
  11454. item.Add(new TestItem()
  11455. {
  11456. Parameter_name = "载具码",
  11457. Parameter_value = sn,
  11458. });
  11459. item.Add(new TestItem()
  11460. {
  11461. Parameter_name = "载具穴号",
  11462. Parameter_value = "1",
  11463. });
  11464. stopwatch2.Start();
  11465. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  11466. partNo, item, out string errorMsg);
  11467. stopwatch2.Stop();
  11468. short e1MES_FLAG_Check = (short)result;
  11469. // MES_Flag
  11470. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  11471. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11472. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  11473. writeToPLC_Flag.Adress = 2003;
  11474. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  11475. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  11476. }
  11477. catch (Exception ex)
  11478. {
  11479. string str = ex.StackTrace;
  11480. AddMessage_Station(stationNameStr, LogType.Error,
  11481. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  11482. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11483. // MES_Flag
  11484. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  11485. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11486. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  11487. writeToPLC_Flag.Adress = 2003;
  11488. writeToPLC_Flag.Value = (short)6;
  11489. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  11490. }
  11491. stopwatch1.Stop();
  11492. AddMessage(LogType.Info,
  11493. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  11494. stopwatch2.ElapsedMilliseconds + "ms");
  11495. }
  11496. /// <summary>
  11497. /// [S5] Tray盘下料装备 - 出站接口
  11498. /// </summary>
  11499. /// <param name="plcNo"></param>
  11500. /// <param name="stationCode"></param>
  11501. /// <param name="stationName"></param>
  11502. private void S5出站接口(int plcNo, string stationCode, string stationName)
  11503. {
  11504. Stopwatch stopwatch1 = new Stopwatch();
  11505. Stopwatch stopwatch2 = new Stopwatch();
  11506. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  11507. string stationNameStr = stationCode + stationName;
  11508. string processItem = stationName; // 测试项目
  11509. try
  11510. {
  11511. stopwatch1.Start();
  11512. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  11513. //string batch_num = GlobalContext.BatchNumber; // 批次号
  11514. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  11515. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  11516. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  11517. sn = sn.Replace("\0", "");
  11518. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  11519. //partNo = partNo.Replace("\0", "");
  11520. #region 查询载具上的产品信息
  11521. string cavityData = string.Empty;
  11522. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  11523. if (string.IsNullOrEmpty(cavityData))
  11524. cavityData = "";
  11525. if (snResult != 0)
  11526. {
  11527. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11528. writeToPLC_Flag1.Name = "e1MES_FLAG";
  11529. writeToPLC_Flag1.Adress = 2035;
  11530. writeToPLC_Flag1.Value = (short)4;
  11531. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  11532. stopwatch1.Stop();
  11533. AddMessage(LogType.Info,
  11534. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11535. return;
  11536. }
  11537. string[] cavitySNs = cavityData.Split('.');
  11538. string partNo = string.Empty;
  11539. if (cavitySNs != null && cavitySNs.Length >= 1)
  11540. partNo = cavitySNs[0];
  11541. #endregion 查询载具上的产品信息
  11542. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  11543. bool pass = e1Result == 1;
  11544. stopwatch2.Start();
  11545. // 上传MES
  11546. List<TestItem> items = new List<TestItem>();
  11547. items.Add(new TestItem()
  11548. {
  11549. Parameter_name = "载具码",
  11550. Parameter_value = sn,
  11551. Parameter_unit = ""
  11552. });
  11553. items.Add(new TestItem()
  11554. {
  11555. Parameter_name = "载具穴号",
  11556. Parameter_value = "1",
  11557. Parameter_unit = ""
  11558. });
  11559. items.Add(new TestItem()
  11560. {
  11561. Parameter_name = "产品结果",
  11562. Parameter_value = e1Result == 1 ? "OK" : "NG",
  11563. Parameter_unit = ""
  11564. });
  11565. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  11566. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  11567. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  11568. short result = result1 == 1 ? (short)1 : (short)3;
  11569. stopwatch2.Stop();
  11570. #region 存储绑定数据到 边线MES系统中
  11571. if (result == 1)
  11572. {
  11573. // 删除绑定信息
  11574. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  11575. if (resultMesR != 0)
  11576. {
  11577. result = 4;
  11578. AddMessage_Station(stationNameStr, LogType.Error,
  11579. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  11580. }
  11581. }
  11582. #endregion 存储绑定数据到 边线MES系统中
  11583. // MES_Flag 为MES报错
  11584. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11585. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  11586. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11587. writeToPLC_Flag.Name = "e1MES_FLAG";
  11588. writeToPLC_Flag.Adress = 2035;
  11589. writeToPLC_Flag.Value = result;
  11590. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  11591. OnMessage(LogType.Debug,
  11592. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  11593. }
  11594. catch (Exception ex)
  11595. {
  11596. stopwatch2.Restart();
  11597. // MES_Flag 为4上位机报错
  11598. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  11599. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11600. writeToPLC_Flag.Name = "e1MES_FLAG";
  11601. writeToPLC_Flag.Adress = 2035;
  11602. writeToPLC_Flag.Value = (short)4;
  11603. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  11604. stopwatch2.Stop();
  11605. string str = ex.StackTrace;
  11606. AddMessage_Station(stationNameStr, LogType.Error,
  11607. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11608. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11609. }
  11610. stopwatch1.Stop();
  11611. AddMessage(LogType.Info,
  11612. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11613. stopwatch2.ElapsedMilliseconds + "ms");
  11614. }
  11615. /// <summary>
  11616. /// [S5] Tray盘下料装备 - 节拍接口
  11617. /// </summary>
  11618. /// <param name="plcNo">PLC编号</param>
  11619. /// <param name="stationNameStr">工站全称</param>
  11620. //private void S5节拍接口(int plcNo, string stationNameStr)
  11621. //{
  11622. // Stopwatch stopwatch1 = new Stopwatch();
  11623. // Stopwatch stopwatch2 = new Stopwatch();
  11624. // string resultStr = string.Empty;
  11625. // try
  11626. // {
  11627. // stopwatch1.Start();
  11628. // string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  11629. // string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  11630. // e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  11631. // bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  11632. // if (!actionBool)
  11633. // {
  11634. // stopwatch2.Start();
  11635. // // MES_Flag
  11636. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11637. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11638. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  11639. // writeToPLC_Flag1.Adress = 2088;
  11640. // writeToPLC_Flag1.Value = (short)4;
  11641. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  11642. // stopwatch2.Stop();
  11643. // AddMessage(LogType.Info,
  11644. // stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  11645. // "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  11646. // return;
  11647. // }
  11648. // string e1OEEPartNo = string.Empty; // 物料码
  11649. // if (string.IsNullOrEmpty(e1OEEProductSN))
  11650. // {
  11651. // stopwatch2.Start();
  11652. // // MES_Flag
  11653. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11654. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11655. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  11656. // writeToPLC_Flag1.Adress = 2088;
  11657. // writeToPLC_Flag1.Value = (short)1;
  11658. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  11659. // stopwatch2.Stop();
  11660. // AddMessage(LogType.Info,
  11661. // stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11662. // stopwatch2.ElapsedMilliseconds + "ms");
  11663. // return;
  11664. // }
  11665. // else
  11666. // {
  11667. // // 查产品SN
  11668. // e1OEEPartNo = "Test"; // ZS
  11669. // }
  11670. // short e1OEEMES_FLAG = 0;
  11671. // // 上传OEE
  11672. // (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  11673. // e1OEEMES_FLAG = result.Item1;
  11674. // resultStr = result.Item2;
  11675. // stopwatch2.Start();
  11676. // // MES_Flag
  11677. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11678. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11679. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  11680. // writeToPLC_Flag.Adress = 2088;
  11681. // writeToPLC_Flag.Value = e1OEEMES_FLAG;
  11682. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  11683. // stopwatch2.Stop();
  11684. // }
  11685. // catch (Exception ex)
  11686. // {
  11687. // string str = ex.StackTrace;
  11688. // AddMessage_Station(stationNameStr, LogType.Error,
  11689. // $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  11690. // str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11691. // // MES_Flag
  11692. // stopwatch2.Start();
  11693. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  11694. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11695. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  11696. // writeToPLC_Flag.Adress = 2088;
  11697. // writeToPLC_Flag.Value = (short)4;
  11698. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  11699. // stopwatch2.Stop();
  11700. // }
  11701. // stopwatch1.Stop();
  11702. // AddMessage(LogType.Info,
  11703. // stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11704. // stopwatch2.ElapsedMilliseconds + "ms");
  11705. //}
  11706. /// <summary>
  11707. /// [S5] Tray盘下料装备 - AGV上料叫agv
  11708. /// </summary>
  11709. /// <param name="plcNo">PLC编号</param>
  11710. /// <param name="stationNameStr">工站全称</param>
  11711. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  11712. {
  11713. Stopwatch stopwatch1 = new Stopwatch();
  11714. Stopwatch stopwatch2 = new Stopwatch();
  11715. try
  11716. {
  11717. stopwatch1.Start();
  11718. // ZS 呼叫AGV
  11719. short e1AGVUpCall = 2;
  11720. stopwatch2.Start();
  11721. // e1AGVUpCall
  11722. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11723. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11724. writeToPLC_Flag.Name = "e1AGVUpCall";
  11725. writeToPLC_Flag.Adress = 2120;
  11726. writeToPLC_Flag.Value = e1AGVUpCall;
  11727. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  11728. stopwatch2.Stop();
  11729. }
  11730. catch (Exception ex)
  11731. {
  11732. string str = ex.StackTrace;
  11733. AddMessage_Station(stationNameStr, LogType.Error,
  11734. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  11735. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11736. // e1AGVUpCall
  11737. stopwatch2.Start();
  11738. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  11739. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11740. writeToPLC_Flag.Name = "e1AGVUpCall";
  11741. writeToPLC_Flag.Adress = 2120;
  11742. writeToPLC_Flag.Value = (short)4;
  11743. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  11744. stopwatch2.Stop();
  11745. }
  11746. stopwatch1.Stop();
  11747. AddMessage(LogType.Info,
  11748. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11749. stopwatch2.ElapsedMilliseconds + "ms");
  11750. }
  11751. /// <summary>
  11752. /// [S5] Tray盘下料装备 - AGV上料完成
  11753. /// </summary>
  11754. /// <param name="plcNo">PLC编号</param>
  11755. /// <param name="stationNameStr">工站全称</param>
  11756. private void S5AGV上料完成(int plcNo, string stationNameStr)
  11757. {
  11758. Stopwatch stopwatch1 = new Stopwatch();
  11759. Stopwatch stopwatch2 = new Stopwatch();
  11760. try
  11761. {
  11762. stopwatch1.Start();
  11763. // ZS AGV上料完成,让小车离开
  11764. short e1AGVUpEnd = 2;
  11765. stopwatch2.Start();
  11766. // e1AGVUpEnd
  11767. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11768. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11769. writeToPLC_Flag.Name = "e1AGVUpEnd";
  11770. writeToPLC_Flag.Adress = 2122;
  11771. writeToPLC_Flag.Value = e1AGVUpEnd;
  11772. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  11773. stopwatch2.Stop();
  11774. }
  11775. catch (Exception ex)
  11776. {
  11777. string str = ex.StackTrace;
  11778. AddMessage_Station(stationNameStr, LogType.Error,
  11779. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  11780. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11781. // e1AGVUpEnd
  11782. stopwatch2.Start();
  11783. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  11784. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11785. writeToPLC_Flag.Name = "e1AGVUpEnd";
  11786. writeToPLC_Flag.Adress = 2122;
  11787. writeToPLC_Flag.Value = (short)4;
  11788. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  11789. stopwatch2.Stop();
  11790. }
  11791. stopwatch1.Stop();
  11792. AddMessage(LogType.Info,
  11793. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11794. stopwatch2.ElapsedMilliseconds + "ms");
  11795. }
  11796. /// <summary>
  11797. /// [S5] Tray盘下料装备 - AGV下料叫agv
  11798. /// </summary>
  11799. /// <param name="plcNo">PLC编号</param>
  11800. /// <param name="stationNameStr">工站全称</param>
  11801. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  11802. {
  11803. Stopwatch stopwatch1 = new Stopwatch();
  11804. Stopwatch stopwatch2 = new Stopwatch();
  11805. try
  11806. {
  11807. stopwatch1.Start();
  11808. // ZS 呼叫AGV
  11809. short e1AGVDownCall = 2;
  11810. stopwatch2.Start();
  11811. // e1AGVDownCall
  11812. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11813. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11814. writeToPLC_Flag.Name = "e1AGVDownCall";
  11815. writeToPLC_Flag.Adress = 2133;
  11816. writeToPLC_Flag.Value = e1AGVDownCall;
  11817. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  11818. stopwatch2.Stop();
  11819. }
  11820. catch (Exception ex)
  11821. {
  11822. string str = ex.StackTrace;
  11823. AddMessage_Station(stationNameStr, LogType.Error,
  11824. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  11825. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11826. // e1AGVDownCall
  11827. stopwatch2.Start();
  11828. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  11829. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11830. writeToPLC_Flag.Name = "e1AGVDownCall";
  11831. writeToPLC_Flag.Adress = 2133;
  11832. writeToPLC_Flag.Value = (short)4;
  11833. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  11834. stopwatch2.Stop();
  11835. }
  11836. stopwatch1.Stop();
  11837. AddMessage(LogType.Info,
  11838. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11839. stopwatch2.ElapsedMilliseconds + "ms");
  11840. }
  11841. /// <summary>
  11842. /// [S5] Tray盘下料装备 - AGV下料完成
  11843. /// </summary>
  11844. /// <param name="plcNo">PLC编号</param>
  11845. /// <param name="stationNameStr">工站全称</param>
  11846. private void S5AGV下料完成(int plcNo, string stationNameStr)
  11847. {
  11848. Stopwatch stopwatch1 = new Stopwatch();
  11849. Stopwatch stopwatch2 = new Stopwatch();
  11850. try
  11851. {
  11852. stopwatch1.Start();
  11853. // ZS AGV上料完成,让小车离开
  11854. short e1AGVDownEnd = 2;
  11855. stopwatch2.Start();
  11856. // e1AGVDownEnd
  11857. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11858. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11859. writeToPLC_Flag.Name = "e1AGVDownEnd";
  11860. writeToPLC_Flag.Adress = 2135;
  11861. writeToPLC_Flag.Value = e1AGVDownEnd;
  11862. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  11863. stopwatch2.Stop();
  11864. }
  11865. catch (Exception ex)
  11866. {
  11867. string str = ex.StackTrace;
  11868. AddMessage_Station(stationNameStr, LogType.Error,
  11869. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  11870. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11871. // e1AGVDownEnd
  11872. stopwatch2.Start();
  11873. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  11874. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11875. writeToPLC_Flag.Name = "e1AGVDownEnd";
  11876. writeToPLC_Flag.Adress = 2135;
  11877. writeToPLC_Flag.Value = (short)4;
  11878. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  11879. stopwatch2.Stop();
  11880. }
  11881. stopwatch1.Stop();
  11882. AddMessage(LogType.Info,
  11883. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11884. stopwatch2.ElapsedMilliseconds + "ms");
  11885. }
  11886. #endregion [S5] Tray盘下料装备
  11887. #endregion PLC5 张超凡
  11888. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  11889. /// <summary>
  11890. /// PLC读取到的数据 -添加数据
  11891. /// </summary>
  11892. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  11893. {
  11894. if (sxPlcData.ContainsKey(newKey))
  11895. sxPlcData[newKey] = newValue;
  11896. else
  11897. sxPlcData.Add(newKey, newValue);
  11898. }
  11899. /// <summary>
  11900. /// PLC需要写入的数据 -添加数据
  11901. /// </summary>
  11902. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey,
  11903. WriteToPLC_Flag newValue)
  11904. {
  11905. if (sxPLCWriteData.ContainsKey(newKey))
  11906. sxPLCWriteData[newKey] = newValue;
  11907. else
  11908. sxPLCWriteData.Add(newKey, newValue);
  11909. }
  11910. /// <summary>
  11911. /// PLC回写操作,写后清空flag
  11912. /// </summary>
  11913. /// <param name="modbusClient">modbus对象</param>
  11914. /// <param name="pLCReadDatas">读取到的数据字典</param>
  11915. /// <param name="pLCWriteDatas">需要写入的数据</param>
  11916. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas,
  11917. ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  11918. {
  11919. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  11920. {
  11921. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  11922. for (int i = 0; i < pLCWriteDatas.Count; i++)
  11923. {
  11924. string mesFlagName = pLCWriteDatas[i].Name;
  11925. int mesFlagAdress = pLCWriteDatas[i].Adress;
  11926. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  11927. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  11928. {
  11929. // 先回写数据
  11930. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  11931. for (int j = 0; j < writeToPLCDatas.Count; j++)
  11932. {
  11933. int mesDataAdress = writeToPLCDatas[j].Adress;
  11934. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  11935. switch (mesDataType)
  11936. {
  11937. case PLCValueType.Short:
  11938. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  11939. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  11940. break;
  11941. case PLCValueType.String:
  11942. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  11943. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  11944. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr,
  11945. mesDataValueStrLength);
  11946. break;
  11947. }
  11948. }
  11949. // 再回写信号
  11950. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  11951. // 存储读取数据的字典
  11952. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  11953. // 存储写入数据的字典 - 清空写入值
  11954. pLCWriteDatas[i].Value = (short)0;
  11955. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  11956. }
  11957. }
  11958. }
  11959. }
  11960. /// <summary>
  11961. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  11962. /// </summary>
  11963. /// <param name="no">3</param>
  11964. /// <param name="stationCode">设备编号</param>
  11965. /// <param name="stationNameStr">设备名称</param>
  11966. /// <param name="plcOrder">车间订单号</param>
  11967. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  11968. {
  11969. try
  11970. {
  11971. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  11972. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  11973. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  11974. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  11975. int result1 = 0;
  11976. switch (stationCode)
  11977. {
  11978. case 2:
  11979. case 3:
  11980. case 4:
  11981. case 6:
  11982. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  11983. break;
  11984. case 102:
  11985. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  11986. break;
  11987. case 103:
  11988. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  11989. break;
  11990. case 104:
  11991. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  11992. break;
  11993. case 106:
  11994. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  11995. break;
  11996. default:
  11997. // MES_Flag 为“6未找到正确设备编号”
  11998. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  11999. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  12000. return;
  12001. }
  12002. short result = result1 == 1 ? (short)1 : (short)2;
  12003. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  12004. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  12005. }
  12006. catch (Exception ex)
  12007. {
  12008. // MES_Flag 为2上位机报错
  12009. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  12010. string str = ex.StackTrace;
  12011. AddMessage_Station(stationNameStr, LogType.Error,
  12012. $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  12013. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12014. }
  12015. }
  12016. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  12017. #region UI刷新
  12018. /// <summary>
  12019. /// 更新商品信息的UI + 下发产品信息(SN)
  12020. /// </summary>
  12021. private void UpdateProductInfo()
  12022. {
  12023. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  12024. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  12025. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  12026. //txt_CurSupplierCode.Text = ""; // 供应商代号
  12027. }
  12028. /// <summary>
  12029. /// 更新PLC连接状态的UI
  12030. /// </summary>
  12031. /// <param name="no">PLC编号</param>
  12032. /// <param name="status">状态</param>
  12033. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  12034. {
  12035. if (this != null && !this.IsDisposed)
  12036. {
  12037. switch (imgNo)
  12038. {
  12039. case 1:
  12040. this.BeginInvoke(new Action(() => { picPLC.Image = imageListState.Images[status]; }));
  12041. break;
  12042. case 2:
  12043. this.BeginInvoke(new Action(() => { pictureBox2.Image = imageListState.Images[status]; }));
  12044. break;
  12045. case 3:
  12046. this.BeginInvoke(new Action(() => { pictureBox3.Image = imageListState.Images[status]; }));
  12047. break;
  12048. case 4:
  12049. this.BeginInvoke(new Action(() => { pictureBox4.Image = imageListState.Images[status]; }));
  12050. break;
  12051. case 5:
  12052. this.BeginInvoke(new Action(() => { pictureBox5.Image = imageListState.Images[status]; }));
  12053. break;
  12054. case 6:
  12055. this.BeginInvoke(new Action(() => { pictureBox6.Image = imageListState.Images[status]; }));
  12056. break;
  12057. case 7:
  12058. this.BeginInvoke(new Action(() => { pictureBox7.Image = imageListState.Images[status]; }));
  12059. break;
  12060. case 8:
  12061. this.BeginInvoke(new Action(() => { pictureBox8.Image = imageListState.Images[status]; }));
  12062. break;
  12063. default:
  12064. break;
  12065. }
  12066. }
  12067. Task.Run(() => // 更新PLC交互页的指示灯
  12068. {
  12069. try
  12070. {
  12071. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  12072. {
  12073. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  12074. }
  12075. }
  12076. catch
  12077. {
  12078. }
  12079. });
  12080. }
  12081. #endregion UI刷新
  12082. #region 日志
  12083. /// <summary>
  12084. /// 添加各工位运行日志(同步至PLC交互页面)
  12085. /// </summary>
  12086. /// <param name="stationNameStr">工站名称</param>
  12087. /// <param name="logType">日志类型</param>
  12088. /// <param name="message">日志内容</param>
  12089. /// <param name="snNumber">产品数字SN</param>
  12090. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  12091. {
  12092. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")))
  12093. {
  12094. AddMessage(logType, message); // 首页展示+日志记录
  12095. }
  12096. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  12097. {
  12098. StationName = stationNameStr,
  12099. SnNumber = snNumber,
  12100. Message = message,
  12101. CreateTime = DateTime.Now
  12102. };
  12103. // PLC交互页展示
  12104. Task.Run(() =>
  12105. {
  12106. try
  12107. {
  12108. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  12109. {
  12110. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  12111. }
  12112. }
  12113. catch
  12114. {
  12115. }
  12116. });
  12117. }
  12118. /// <summary>
  12119. /// 添加运行日志
  12120. /// </summary>
  12121. /// <param name="logType">日志类型</param>
  12122. /// <param name="message">日志内容</param>
  12123. public void AddMessage(LogType logType, string message)
  12124. {
  12125. OnMessage(logType, message);
  12126. string date = DateTime.Now.ToString("yyyy/MM/dd");
  12127. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  12128. string msgShow = time + "--> " + message + "\r\n";
  12129. try
  12130. {
  12131. this.BeginInvoke(new Action(() =>
  12132. {
  12133. systemLog.Rows.Insert(0, date, time, message);
  12134. if (systemLog.Rows.Count >= 100)
  12135. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  12136. }));
  12137. }
  12138. catch (Exception ex) { }
  12139. }
  12140. /// <summary>
  12141. /// 添加运行日志-保存
  12142. /// </summary>
  12143. /// <param name="logType">日志类型</param>
  12144. /// <param name="message">日志内容</param>
  12145. private void OnMessage(LogType logType, string msg)
  12146. {
  12147. MessageEvent?.Invoke(logType, msg);
  12148. }
  12149. /// <summary>
  12150. /// 保存PLC写入日志
  12151. /// </summary>
  12152. /// <param name="logType"></param>
  12153. /// <param name="logValue"></param>
  12154. private void WritePLCLog(LogType logType, string logValue)
  12155. {
  12156. switch ((int)logType)
  12157. {
  12158. case 0:
  12159. _PLCLogNet.WriteDebug(logValue);
  12160. break;
  12161. case 1:
  12162. _PLCLogNet.WriteInfo(logValue);
  12163. break;
  12164. case 2:
  12165. _PLCLogNet.WriteWarn(logValue);
  12166. break;
  12167. case 3:
  12168. _PLCLogNet.WriteError(logValue);
  12169. break;
  12170. default:
  12171. _PLCLogNet.WriteFatal(logValue);
  12172. break;
  12173. }
  12174. }
  12175. /// <summary>
  12176. /// IOT Mqtt回调方法- With DataId
  12177. /// </summary>
  12178. /// <param name="id"></param>
  12179. /// <param name="v"></param>
  12180. /// <param name="dataId"></param>
  12181. public void CallbackWithDataId(string id, string msg, string dataId)
  12182. {
  12183. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  12184. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  12185. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  12186. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  12187. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  12188. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  12189. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  12190. }
  12191. /// <summary>
  12192. /// AGV Mqtt回调方法- 记录Log并处理数据
  12193. /// </summary>
  12194. /// <param name="obj"></param>
  12195. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  12196. {
  12197. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  12198. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  12199. // 接收到的信息
  12200. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  12201. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  12202. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  12203. {
  12204. }
  12205. }
  12206. #endregion 日志
  12207. //private void button1_Click(object sender, EventArgs e)
  12208. //{
  12209. // OpenDailogFalg=true;
  12210. // if (OpenDailogFalg)
  12211. // {
  12212. // using (var dialog = new BandBarodeDialog())
  12213. // {
  12214. // string strCarrierBarcode = "N801A-003";
  12215. // dialog._CarrierBarcode = strCarrierBarcode;
  12216. // string sn = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  12217. // dialog._ProductBarcode = sn;
  12218. // var rs = dialog.ShowDialog();
  12219. // if (rs == DialogResult.OK)
  12220. // {
  12221. // AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  12222. // OpenDailogFalg = false;//关闭扫码
  12223. // }
  12224. // }
  12225. // }
  12226. //}
  12227. }
  12228. }