Form_Home.cs 700 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. //using System.Text;
  8. using Microsoft.Win32;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using HslCommunication.LogNet;
  13. using MainForm.FaForm;
  14. using Sunny.UI;
  15. using MainForm.ClassFile.XiaomiAPI;
  16. using System.Diagnostics;
  17. using MainForm.Models;
  18. using SqlSugar;
  19. using EasyModbus;
  20. using ModBusClientSimple.Util;
  21. using csharp_networkprotocol_hpsocket;
  22. using MqttnetServerWin;
  23. using Sunny.UI.Win32;
  24. using MainForm.ClassFile.XiaomiAPI_AGV;
  25. using MainForm.ClassFile.XiaomiAPI_RouteCom;
  26. using HslCommunication.Controls;
  27. using EIP_Protocol;
  28. using MainForm.ClassFile.XiaomiAPI_MES;
  29. using NPOI.Util;
  30. using static MainForm.SQLHelper;
  31. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
  32. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
  33. using MainForm.ClassFile.ProjectClass;
  34. using CommonLib;
  35. using Org.BouncyCastle.Asn1.IsisMtt;
  36. using System.Web.Services.Description;
  37. using System.Numerics;
  38. using MathNet.Numerics.RootFinding;
  39. using HslCommunication.Enthernet;
  40. using BZFAStandardLib;
  41. using MainForm.ClassFile;
  42. using NPOI.SS.Formula.Functions;
  43. using static MainForm.ClassFile.XiaomiAPI.XiaomiMqttClient_Extend;
  44. using System.Net.Http;
  45. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_UpLoadFile;
  46. using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
  47. using System.Reflection;
  48. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
  49. using FaFrameUI;
  50. using System.Security.Policy;
  51. using static MainForm.ClassFile.XiaomiClass.MesHelper;
  52. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
  53. using System.Drawing.Imaging;
  54. using System.Drawing;
  55. using ICSharpCode.SharpZipLib.Zip;
  56. using System.Text.RegularExpressions;
  57. /*
  58. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  59. */
  60. namespace MainForm
  61. {
  62. /// <summary>
  63. /// 记录日志的委托
  64. /// </summary>
  65. /// <param name="logType">日志类型</param>
  66. /// <param name="message">日志信息</param>
  67. public delegate void HomeMessageHandler(LogType logType, string message);
  68. /// <summary>
  69. /// 主页窗体
  70. /// </summary>
  71. public partial class Form_Home : Form
  72. {
  73. #region 常量
  74. //文本常量
  75. private const string Head = "开始采集";
  76. private const string Tail = "采集完成";
  77. private const string Body = "工位出站数据";
  78. private const string BodyCheck = "工位点检数据";
  79. private const string BodyRun = "整线运行数据";
  80. private const string BodyAlarm = "整线报警数据";
  81. #endregion 常量
  82. #region 变量
  83. /// <summary>
  84. /// 委托-记录日志的方法
  85. /// </summary>
  86. public event HomeMessageHandler MessageEvent;
  87. /// <summary>
  88. /// 日志接口
  89. /// </summary>
  90. ILogNet _PLCLogNet;
  91. /// <summary>
  92. /// 用于记录IOT MQTT日志
  93. /// </summary>
  94. ILogNet _IOTMqttLogNet;
  95. /// <summary>
  96. /// 用于记录AGV MQTT日志
  97. /// </summary>
  98. ILogNet _AGVMqttLogNet;
  99. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  100. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  101. // 间隔时间
  102. private int IntervalReadPLC = 300; //ms 读PLC
  103. private int IntervalMonitorMES = 1000; //ms MES心跳
  104. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  105. /// <summary>
  106. /// 设备报警数据
  107. /// </summary>
  108. uint[] _FaultDatas = { };
  109. uint[] _FaultDatas_Old = { };
  110. uint[] _FaultDatas2 = { };
  111. uint[] _FaultDatas_Old2 = { };
  112. // 软件状态
  113. private bool IsRun = true;
  114. #region PLC 与 TCP对象
  115. // 定义一个字典,存plc对象(通讯)
  116. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  117. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  118. // 定义TCPClient对象列表
  119. Dictionary<int, HPSocket_TcpClientHelper>
  120. _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  121. // 定义MQTTHelper对象
  122. MQTTHelper _MQTTHelper = new MQTTHelper();
  123. #endregion PLC 与 TCP对象
  124. /// <summary>
  125. /// 上次的设备运行信息
  126. /// </summary>
  127. private string lineWorkingData1_OldStr = string.Empty;
  128. /// <summary>
  129. /// 设备报警字典-当前结果
  130. /// Dictionary<工位代码,List<报警信息>>
  131. /// </summary>
  132. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  133. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  134. /// <summary>
  135. /// 单机用-设备状态
  136. /// </summary>
  137. //XiaomiDeviceState xmDeviceState = XiaomiDeviceState.Uninitialized;
  138. XiaomiDeviceStateData xmDeviceStateData = new XiaomiDeviceStateData();
  139. private int test_item_num = 0; //iot 过站数据序号
  140. public static string uuid = ""; //单工位或左工位
  141. public static string uuid2 = ""; //右工位
  142. private bool inpass = false; //保存进站测试状态
  143. public static XiaoMiParm xiaomiParm = new XiaoMiParm();
  144. //记录上传附件的信息
  145. public static FileUpload_FileData fileUploadData = new FileUpload_FileData();
  146. #endregion 变量
  147. #region 窗体基础事件
  148. /// <summary>
  149. /// 初始化
  150. /// </summary>
  151. public Form_Home()
  152. {
  153. InitializeComponent();
  154. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  155. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  156. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  157. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  158. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  159. }
  160. /// <summary>
  161. /// 窗体加载事件
  162. /// </summary>
  163. public void Form_Home_Load(object sender, EventArgs e)
  164. {
  165. try
  166. {
  167. AddMessage(LogType.Info, "开始初始化程序");
  168. //组建plc对象字典
  169. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  170. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  171. if (GlobalContext.IsUsePLC1)
  172. {
  173. GlobalContext.IsUsePLCNow = 1;
  174. GlobalContext.IsUseStationName = "[OP10]壳体清洁上料";
  175. FunsEip.Add(GlobalContext.IsUsePLCNow,
  176. new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  177. }
  178. if (GlobalContext.IsUsePLC2)
  179. {
  180. GlobalContext.IsUsePLCNow = 2;
  181. GlobalContext.IsUseStationName = "[OP20]上盖板上料装备";
  182. FunsEip.Add(GlobalContext.IsUsePLCNow,
  183. new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  184. }
  185. if (GlobalContext.IsUsePLC3)
  186. {
  187. GlobalContext.IsUsePLCNow = 3;
  188. GlobalContext.IsUseStationName = "[OP30]点散热胶装备";
  189. FunsEip.Add(GlobalContext.IsUsePLCNow,
  190. new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  191. }
  192. if (GlobalContext.IsUsePLC4)
  193. {
  194. GlobalContext.IsUsePLCNow = 4;
  195. GlobalContext.IsUseStationName = "[OP40]胶线检测";
  196. FunsEip.Add(GlobalContext.IsUsePLCNow,
  197. new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  198. }
  199. if (GlobalContext.IsUsePLC5)
  200. {
  201. GlobalContext.IsUsePLCNow = 5;
  202. GlobalContext.IsUseStationName = "[OP50]ADD板上料组装装备";
  203. FunsEip.Add(GlobalContext.IsUsePLCNow,
  204. new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  205. }
  206. if (GlobalContext.IsUsePLC6)
  207. {
  208. GlobalContext.IsUsePLCNow = 6;
  209. GlobalContext.IsUseStationName = "[OP70]组上盖板";
  210. FunsEip.Add(GlobalContext.IsUsePLCNow,
  211. new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  212. }
  213. if (GlobalContext.IsUsePLC7)
  214. {
  215. GlobalContext.IsUsePLCNow = 7;
  216. GlobalContext.IsUseStationName = "[OP80]上盖板锁螺丝";
  217. FunsEip.Add(GlobalContext.IsUsePLCNow,
  218. new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  219. }
  220. if (GlobalContext.IsUsePLC8)
  221. {
  222. GlobalContext.IsUsePLCNow = 8;
  223. GlobalContext.IsUseStationName = "[OP90]NG下料";
  224. FunsEip.Add(GlobalContext.IsUsePLCNow,
  225. new Inovance_EIP(GlobalContext.PC8Address,
  226. GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  227. }
  228. if (GlobalContext.IsUsePLC9)
  229. {
  230. GlobalContext.IsUsePLCNow = 9;
  231. GlobalContext.IsUseStationName = "[OP100]半成品下料";
  232. FunsEip.Add(GlobalContext.IsUsePLCNow,
  233. new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  234. }
  235. (bool, string) DicResult = InitalDicAlarm(); // 实例化报警字典
  236. AddMessage(LogType.Info, DicResult.Item2);
  237. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  238. {
  239. if (plcEIP != null)
  240. {
  241. try
  242. {
  243. (int, string) result = plcEIP.Connect();
  244. }
  245. catch (Exception ex)
  246. {
  247. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  248. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
  249. MessageBoxOptions.ServiceNotification);
  250. }
  251. }
  252. }
  253. // 采集任务
  254. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  255. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  256. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  257. if (GlobalContext.IsUsePLC1)
  258. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  259. if (GlobalContext.IsUsePLC2)
  260. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  261. if (GlobalContext.IsUsePLC3)
  262. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  263. if (GlobalContext.IsUsePLC4)
  264. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  265. if (GlobalContext.IsUsePLC5)
  266. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  267. if (GlobalContext.IsUsePLC6)
  268. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  269. if (GlobalContext.IsUsePLC7)
  270. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  271. if (GlobalContext.IsUsePLC8)
  272. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  273. if (GlobalContext.IsUsePLC9)
  274. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  275. #region 初始化
  276. try
  277. {
  278. // 开启MES(Http)
  279. if (GlobalContext.IsUseMES)
  280. {
  281. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  282. if (mesret)
  283. {
  284. picMESStatus.Image = imageListState.Images[1];
  285. GlobalContext.MESIsConnect = true;
  286. AddMessage(LogType.Info, "小米MES初始连接成功!");
  287. }
  288. else
  289. {
  290. picMESStatus.Image = imageListState.Images[0];
  291. GlobalContext.MESIsConnect = false;
  292. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  293. }
  294. }
  295. // 开启IOT(MQTT)
  296. if (GlobalContext.IsUseIot)
  297. {
  298. string addr = GlobalContext.MQTTServerHost;
  299. int port = GlobalContext.MQTTServerPort;
  300. //生产环境需要修改
  301. (int, string) qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666,
  302. GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  303. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult.Item1;
  304. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  305. {
  306. picIot.Image = imageListState.Images[1];
  307. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  308. // 设置回调函数
  309. //XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  310. // 配置参数
  311. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  312. // fds
  313. param.parameter.fds.address = GlobalContext.address;
  314. param.parameter.fds.appId = GlobalContext.appId;
  315. param.parameter.fds.appKey = GlobalContext.appKey;
  316. // mes
  317. param.parameter.mes.address = GlobalContext.ServerIp;
  318. param.parameter.mes.appId = GlobalContext.MESAppId;
  319. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  320. // mqtt
  321. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  322. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  323. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  324. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  325. // 设备配置
  326. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  327. if (GlobalContext.IsUsePLC1)
  328. {
  329. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  330. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  331. xiaomiParm.workstation = GlobalContext.S1_work_station; //工站
  332. }
  333. if (GlobalContext.IsUsePLC2)
  334. {
  335. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  336. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  337. xiaomiParm.workstation = GlobalContext.S2_work_station; //工站
  338. }
  339. if (GlobalContext.IsUsePLC3)
  340. {
  341. param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
  342. //param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
  343. }
  344. if (GlobalContext.IsUsePLC4)
  345. {
  346. param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
  347. param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
  348. xiaomiParm.workstation = GlobalContext.s4_work_station; //工站
  349. }
  350. if (GlobalContext.IsUsePLC5)
  351. {
  352. param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
  353. param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
  354. xiaomiParm.workstation = GlobalContext.s5_work_station; //工站
  355. }
  356. if (GlobalContext.IsUsePLC6)
  357. {
  358. param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
  359. param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
  360. xiaomiParm.workstation = GlobalContext.s6_work_station; //工站
  361. }
  362. if (GlobalContext.IsUsePLC7)
  363. {
  364. param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  365. //param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  366. xiaomiParm.stationCode = GlobalContext.s7_1_station;
  367. }
  368. if (GlobalContext.IsUsePLC8)
  369. {
  370. param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
  371. param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
  372. xiaomiParm.workstation = GlobalContext.s8_work_station; //工站
  373. }
  374. if (GlobalContext.IsUsePLC9)
  375. {
  376. param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
  377. param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
  378. xiaomiParm.workstation = GlobalContext.s9_work_station; //工站
  379. }
  380. param.parameter.equipment.project = GlobalContext.Project_Code;
  381. param.parameter.equipment.productMode = "debug";
  382. param.parameter.other.logLevel = 0;
  383. param.parameter.other.LogPath = GlobalContext.MqttLogDir;
  384. XiaomiMqttClient_Extend.ParameterConfig(param);
  385. //保存全局变量
  386. xiaomiParm.stationCode = param.parameter.equipment.stationCode;
  387. xiaomiParm.deviceCode = param.parameter.equipment.deviceCode;
  388. }
  389. else
  390. {
  391. picIot.Image = imageListState.Images[0];
  392. AddMessage(LogType.Info,
  393. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  394. }
  395. }
  396. // 开启AGV(Http与MQTT)
  397. if (GlobalContext.IsUseAGV)
  398. {
  399. // AGV HTTP
  400. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  401. if (mesret1)
  402. {
  403. picAgvHttp.Image = imageListState.Images[1];
  404. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  405. }
  406. else
  407. {
  408. picAgvHttp.Image = imageListState.Images[0];
  409. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  410. }
  411. string agvMqttIp = GlobalContext.MQTTServerHost;
  412. int agvMqttPort = GlobalContext.MQTTServerPort;
  413. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  414. ResultData_MQTT result_MQTT = _MQTTHelper
  415. .CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  416. // AGV MQTT
  417. if (result_MQTT.ResultCode == 1)
  418. {
  419. picAgvMqtt.Image = imageListState.Images[1];
  420. GlobalContext.AGVMQTTIsConnect = true;
  421. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  422. ResultData_MQTT result =
  423. XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  424. AddMessage(LogType.Info,
  425. $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  426. }
  427. else
  428. {
  429. picAgvMqtt.Image = imageListState.Images[0];
  430. GlobalContext.AGVMQTTIsConnect = false;
  431. AddMessage(LogType.Info,
  432. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  433. }
  434. }
  435. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  436. Task.Run(MonitorMESConnect);
  437. // 查询PLC连接状态
  438. foreach (int plcNo in FunsEip.Keys)
  439. {
  440. bool connected = FunsEip[plcNo].IsConnected;
  441. if (connected)
  442. {
  443. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  444. AddMessage(LogType.Info, msg);
  445. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  446. }
  447. else
  448. {
  449. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  450. AddMessage(LogType.Info, msg);
  451. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  452. }
  453. }
  454. // PLC4时 初始化扫码器TCP
  455. //if (GlobalContext.IsUsePLC4)
  456. // HpTCPClientInit();
  457. // 开启PLC的业务处理线程-监听PLC点位+状态
  458. foreach (Task task in TaskReadProcess)
  459. {
  460. if (task != null)
  461. task.Start();
  462. }
  463. //// 开启iot的线程
  464. TaskReadAlarm.Start();
  465. ////下传MES信息给1工位(先判断下plc对象数量)
  466. //if (Funs.Count > 1)
  467. // DownLoadProductInfo(1);
  468. if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  469. {
  470. state_l.Text = "设备状态(左):";
  471. state_r.Text = "设备状态(右):";
  472. state_r.Visible = true;
  473. lblDeviceStates2.Visible = true;
  474. }
  475. //上传操作记录
  476. operateToIot("startup", "开启");
  477. AddMessage(LogType.Info, "程序初始化完成");
  478. }
  479. catch (Exception ex)
  480. {
  481. string str = ex.StackTrace;
  482. this.BeginInvoke(new Action(() =>
  483. {
  484. AddMessage(LogType.Error,
  485. "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  486. str.Length - str.LastIndexOf("\\") - 1));
  487. }));
  488. }
  489. #endregion
  490. }
  491. catch (Exception ex)
  492. {
  493. string str = ex.StackTrace;
  494. OnMessage(LogType.Info,
  495. "主窗体的首页初始化出错!异常位置:" +
  496. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" +
  497. ex.Message.ToString());
  498. if (ex.Message != null && ex.Message.Contains("timed out"))
  499. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  500. else
  501. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  502. }
  503. }
  504. /// <summary>
  505. /// 窗体关闭事件
  506. /// </summary>
  507. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  508. {
  509. Closed2();
  510. }
  511. public void Closed2()
  512. {
  513. try
  514. {
  515. IsRun = false;
  516. Thread.Sleep(IntervalReadPLC);
  517. // 断开TCP
  518. int count = _HPSocket_TcpClients.Count();
  519. for (int i = 0; i < count; i++)
  520. {
  521. try
  522. {
  523. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  524. {
  525. _HPSocket_TcpClients[i].Stop();
  526. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  527. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  528. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  529. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  530. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  531. }
  532. }
  533. catch
  534. {
  535. }
  536. }
  537. // 关闭Iot
  538. try
  539. {
  540. XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath,
  541. GlobalContext.MqttServerName);
  542. }
  543. catch
  544. {
  545. }
  546. // 关闭AGV Mqtt
  547. try
  548. {
  549. _MQTTHelper.DisconnectAsync_Client().Wait();
  550. }
  551. catch
  552. {
  553. }
  554. }
  555. catch
  556. {
  557. }
  558. }
  559. #endregion 窗体基础事件
  560. #region 监控MES状态
  561. /// <summary>
  562. /// 监控MES连接状态
  563. /// </summary>
  564. private void MonitorMESConnect()
  565. {
  566. while (IsRun) // 运行被控线程
  567. {
  568. try
  569. {
  570. // 开启MES(Http)
  571. if (GlobalContext.IsUseMES)
  572. {
  573. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  574. if (mesret)
  575. {
  576. picMESStatus.Image = imageListState.Images[1];
  577. GlobalContext.MESIsConnect = true;
  578. }
  579. else
  580. {
  581. picMESStatus.Image = imageListState.Images[0];
  582. GlobalContext.MESIsConnect = false;
  583. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  584. }
  585. }
  586. // 开启IOT(MQTT)
  587. if (GlobalContext.IsUseIot)
  588. {
  589. bool iIot = XiaomiMqttClient.IsOpen;
  590. if (iIot)
  591. picIot.Image = imageListState.Images[1];
  592. else
  593. {
  594. picIot.Image = imageListState.Images[0];
  595. OnMessage(LogType.Info,
  596. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  597. }
  598. }
  599. // 开启AGV(Http与MQTT)
  600. if (GlobalContext.IsUseAGV)
  601. {
  602. // AGV Http
  603. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  604. if (mesret1)
  605. picAgvHttp.Image = imageListState.Images[1];
  606. else
  607. {
  608. picAgvHttp.Image = imageListState.Images[0];
  609. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  610. }
  611. // AGV MQTT
  612. if (GlobalContext.AGVMQTTIsConnect)
  613. picAgvMqtt.Image = imageListState.Images[1];
  614. else
  615. {
  616. picAgvMqtt.Image = imageListState.Images[0];
  617. OnMessage(LogType.Info,
  618. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  619. }
  620. }
  621. }
  622. catch (Exception ex)
  623. {
  624. string str = ex.StackTrace;
  625. AddMessage(LogType.Error,
  626. "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  627. str.Length - str.LastIndexOf("\\") - 1));
  628. }
  629. Thread.Sleep(IntervalMonitorMES);
  630. }
  631. }
  632. #endregion 监控MES连接状态
  633. #region 采集设备状态、运行数据、报警数据
  634. /// <summary>
  635. /// 请求设备状态 5000
  636. /// </summary>
  637. /// <param name="no">1</param>
  638. /// <param name="stationNameStr"></param>
  639. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  640. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  641. {
  642. try
  643. {
  644. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  645. {
  646. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  647. return result;
  648. }
  649. else
  650. {
  651. return 0;
  652. }
  653. }
  654. catch (Exception ex)
  655. {
  656. string str = ex.StackTrace;
  657. AddMessage_Station(stationNameStr, LogType.Error,
  658. "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  659. str.Length - str.LastIndexOf("\\") - 1));
  660. return 0;
  661. }
  662. }
  663. /// <summary>
  664. /// 检查是否可采集点检数据 - 不取新值
  665. /// 5000不为1时可点检
  666. /// </summary>
  667. /// <returns></returns>
  668. public bool CheckCanSpotcheck1(int deviceState)
  669. {
  670. //return true;
  671. //D5000 = 1,代表设备控制状态处于运行状态
  672. //D5000 = 2, 代表设备控制状态处于故障状态
  673. //D5000 = 3,代表设备控制状态处于缺料状态
  674. //D5000 = 4, 代表设备控制状态处于待机状态
  675. //D5000 = 5,代表设备控制状态处于维修状态
  676. return deviceState != 1;
  677. }
  678. /// <summary>
  679. /// 检查是否可采集产品数据 - 不取新值
  680. /// </summary>
  681. /// <returns></returns>
  682. public bool CheckCanCollData(int deviceState)
  683. {
  684. return deviceState == 0; // 点检时该值不为0
  685. }
  686. /// <summary>
  687. /// 采集到的设备状态
  688. /// </summary>
  689. private string _DeviceStates = "未知状态";
  690. private string _DeviceStates_Old = "未知状态";
  691. private string _DeviceStates2 = "未知状态";
  692. private string _DeviceStates_Old2 = "未知状态";
  693. /// <summary>
  694. /// 获取设备报警数据与获取设备运行信息
  695. /// </summary>
  696. private async void ReadAlarmAllPLC()
  697. {
  698. /// 获取设备报警数据与状态信息
  699. string stationNameStr = "获取设备报警数据与状态信息";
  700. // 已连接到PLC
  701. while (IsRun)
  702. {
  703. try
  704. {
  705. #region 报警数据
  706. try
  707. {
  708. //_FaultDatas = new uint[] { 4, 0, 30, 10 };
  709. if (_FaultDatas.Length > 0)
  710. {
  711. ReadPLCAlarmToIot(_FaultDatas, _FaultDatas_Old, stationNameStr,"left");
  712. }
  713. else
  714. {
  715. AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!");
  716. }
  717. if (_FaultDatas2.Length > 0)
  718. {
  719. ReadPLCAlarmToIot(_FaultDatas2, _FaultDatas_Old2, stationNameStr,"right");
  720. }
  721. else
  722. {
  723. AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!");
  724. }
  725. }
  726. catch (Exception ex)
  727. {
  728. string str = ex.StackTrace;
  729. AddMessage_Station(stationNameStr, LogType.Error,
  730. $"【报警日志】{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" +
  731. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  732. }
  733. #endregion 报警数据
  734. #region 设备状态
  735. //if (!GlobalContext._IsCon_plc1Alarm)
  736. //{
  737. // UpdatePLCMonitor(1, -2, 0);
  738. // continue;
  739. //}
  740. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  741. {
  742. if (plcEIP != null)
  743. {
  744. if (plcEIP.IsConnected)
  745. {
  746. #region 主页展示设备运行状态并上传到IOT中,有双工位left就是左工位,没有双工位left就是单工位
  747. switch (xmDeviceStateData.left)
  748. {
  749. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  750. _DeviceStates = "未初始化状态";
  751. lblDeviceStates.Text = _DeviceStates;
  752. break;
  753. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  754. _DeviceStates = "初始化状态";
  755. lblDeviceStates.Text = _DeviceStates;
  756. break;
  757. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  758. _DeviceStates = "初始化完成状态";
  759. lblDeviceStates.Text = _DeviceStates;
  760. break;
  761. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  762. _DeviceStates = "运行状态";
  763. lblDeviceStates.Text = _DeviceStates;
  764. break;
  765. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  766. _DeviceStates = "暂停状态";
  767. lblDeviceStates.Text = _DeviceStates;
  768. break;
  769. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  770. _DeviceStates = "故障状态";
  771. lblDeviceStates.Text = _DeviceStates;
  772. break;
  773. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  774. _DeviceStates = "警报状态";
  775. lblDeviceStates.Text = _DeviceStates;
  776. break;
  777. }
  778. if (!_DeviceStates.Equals(_DeviceStates_Old))
  779. {
  780. var iotResult =
  781. SaveDeviceStateData(stationNameStr, xmDeviceStateData.left, "left"); // 上传+保存
  782. if (iotResult.Item1 == 1)
  783. {
  784. _DeviceStates_Old = _DeviceStates;
  785. AddMessage_Station(stationNameStr, LogType.Info,
  786. "【设备状态】" + stationNameStr + $"_上传设备状态到Iot成功!");
  787. }
  788. else
  789. AddMessage_Station(stationNameStr, LogType.Info,
  790. "【设备状态】" + stationNameStr +
  791. $"_上传设备状态到Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  792. }
  793. #endregion 主页展示设备运行状态并上传到IOT中
  794. #region 右工位
  795. if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  796. {
  797. switch (xmDeviceStateData.right)
  798. {
  799. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  800. _DeviceStates2 = "未初始化状态";
  801. lblDeviceStates2.Text = _DeviceStates2;
  802. break;
  803. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  804. _DeviceStates2 = "初始化状态";
  805. lblDeviceStates2.Text = _DeviceStates2;
  806. break;
  807. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  808. _DeviceStates2 = "初始化完成状态";
  809. lblDeviceStates2.Text = _DeviceStates2;
  810. break;
  811. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  812. _DeviceStates2 = "运行状态";
  813. lblDeviceStates2.Text = _DeviceStates2;
  814. break;
  815. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  816. _DeviceStates2 = "暂停状态";
  817. lblDeviceStates2.Text = _DeviceStates2;
  818. break;
  819. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  820. _DeviceStates2 = "故障状态";
  821. lblDeviceStates2.Text = _DeviceStates2;
  822. break;
  823. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  824. _DeviceStates2 = "警报状态";
  825. lblDeviceStates2.Text = _DeviceStates2;
  826. break;
  827. }
  828. if (!_DeviceStates2.Equals(_DeviceStates_Old2))
  829. {
  830. var iotResult = SaveDeviceStateData(stationNameStr, xmDeviceStateData.left,
  831. "right"); // 上传+保存
  832. if (iotResult.Item1 == 1)
  833. {
  834. _DeviceStates_Old2 = _DeviceStates2;
  835. AddMessage_Station(stationNameStr, LogType.Info,
  836. "【设备状态】" + stationNameStr + $"_上传Iot成功!");
  837. }
  838. else
  839. AddMessage_Station(stationNameStr, LogType.Info,
  840. "【设备状态】" + stationNameStr +
  841. $"_上传Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  842. }
  843. }
  844. #endregion 右工位
  845. }
  846. }
  847. }
  848. #endregion
  849. //if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  850. //{
  851. // DateTime dtNow = DateTime.Now;
  852. // //#region 获取设备运行信息
  853. // //try
  854. // //{
  855. // // LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  856. // // lineWorkingData1.GUID = Guid.NewGuid().ToString();
  857. // // lineWorkingData1.LineName = GlobalContext.LineCode;
  858. // // //
  859. // // lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  860. // // lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  861. // // lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  862. // // lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  863. // // lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  864. // // lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  865. // // lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  866. // // lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  867. // // lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  868. // // lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  869. // // lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  870. // // lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  871. // // lineWorkingData1.CreateTime = DateTime.Now;
  872. // // string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  873. // // // UI展示-展示到设备状态页
  874. // // if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  875. // // {
  876. // // // 查询数据库最新一条数据,确定是不是更新
  877. // // string qSql = @"SELECT top(1) [GUID]
  878. // // ,[LineName]
  879. // // ,[BootTimeLong]
  880. // // ,[NormalTimeLong]
  881. // // ,[StandbyTimeLong]
  882. // // ,[FaultTimeLong]
  883. // // ,[MaterialShortageTimeLong]
  884. // // ,[MaintenanceTimeLong]
  885. // // ,[FaultNumber]
  886. // // ,[OutputNumber]
  887. // // ,[QualifiedNumber]
  888. // // ,[QualifiedRate]
  889. // // ,[DesignRhythm]
  890. // // ,[RealityRhythm]
  891. // // ,[CreateTime]
  892. // // FROM [LineWorkingData]
  893. // // where [CreateTime] > '{0}'
  894. // // and [LineName]='{1}'
  895. // // order by [CreateTime] desc
  896. // // ";
  897. // // qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  898. // // var ds = SQLHelper_New.Query(qSql, null);
  899. // // if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  900. // // {
  901. // // var dataDBlast = new LineWorkingData_ThisTime();
  902. // // dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  903. // // dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  904. // // dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  905. // // dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  906. // // if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  907. // // {
  908. // // dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  909. // // dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  910. // // dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  911. // // dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  912. // // dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  913. // // dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  914. // // dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  915. // // dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  916. // // dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  917. // // dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  918. // // dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  919. // // dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  920. // // string usql = dataDBlast.ToStringUpdate();
  921. // // SQLHelper_New.ExecuteSQL(usql, null);
  922. // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  923. // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  924. // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  925. // // }
  926. // // }
  927. // // else
  928. // // {
  929. // // // 插入
  930. // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  931. // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  932. // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  933. // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  934. // // }
  935. // // }
  936. // // else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  937. // // {
  938. // // LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  939. // // //// 本次开机设备运行情况
  940. // // //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  941. // // //Task.Run(() =>
  942. // // //{
  943. // // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  944. // // // {
  945. // // // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  946. // // // }
  947. // // //});
  948. // // // 本日设备运行情况
  949. // // // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  950. // // if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  951. // // {
  952. // // // 更新
  953. // // lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  954. // // lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  955. // // lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  956. // // lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  957. // // lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  958. // // lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  959. // // lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  960. // // lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  961. // // lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  962. // // lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  963. // // lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  964. // // lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  965. // // SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  966. // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  967. // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  968. // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  969. // // }
  970. // // else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  971. // // {
  972. // // // 插入
  973. // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  974. // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  975. // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  976. // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  977. // // }
  978. // // await Task.Run(() =>
  979. // // {
  980. // // try
  981. // // {
  982. // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  983. // // {
  984. // // Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  985. // // }
  986. // // }
  987. // // catch { }
  988. // // });
  989. // // }
  990. // //}
  991. // //catch (Exception ex)
  992. // //{
  993. // // string str = ex.StackTrace;
  994. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  995. // //}
  996. // //#endregion 获取设备运行信息
  997. // #region 报警数据
  998. // try
  999. // {
  1000. // List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  1001. // bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  1002. // // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  1003. // var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  1004. // for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  1005. // {
  1006. // short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  1007. // dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  1008. // if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  1009. // {
  1010. // isNeedUpdUI = true; // 需要更新历史报警UI信息
  1011. // // 记录
  1012. // dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  1013. // switch (dicAlarms_Cur_PLC1[i].是否报警)
  1014. // {
  1015. // case true: // 报警
  1016. // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  1017. // {
  1018. // GUID = Guid.NewGuid().ToString(),
  1019. // LineName = GlobalContext.LineCode, // 线体
  1020. // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  1021. // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  1022. // StartTime = dtNow // 开始时间
  1023. // };
  1024. // // 传输到页面
  1025. // deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  1026. // {
  1027. // 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  1028. // 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  1029. // 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  1030. // 开始时间 = dtNow
  1031. // });
  1032. // // 新增到数据库
  1033. // var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  1034. // SaveAlarmDataByDB(stationNameStr, data1, false);
  1035. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  1036. // break;
  1037. // case false: // 消除报警
  1038. // if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  1039. // {
  1040. // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  1041. // {
  1042. // GUID = Guid.NewGuid().ToString(),
  1043. // LineName = GlobalContext.LineCode, // 线体
  1044. // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  1045. // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  1046. // StartTime = dtNow, // 开始时间
  1047. // EndTime = dtNow, // 开始时间
  1048. // PersistTime = 1, // 耗时1s
  1049. // };
  1050. // // 新增
  1051. // var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  1052. // SaveAlarmDataByDB(stationNameStr, data2, false);
  1053. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  1054. // }
  1055. // else
  1056. // {
  1057. // dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  1058. // dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  1059. // - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  1060. // // 修改
  1061. // var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  1062. // SaveAlarmDataByDB(stationNameStr, data3, true);
  1063. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  1064. // }
  1065. // break;
  1066. // default:
  1067. // break;
  1068. // }
  1069. // }
  1070. // }
  1071. // DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  1072. // // 有新报警则更新
  1073. // if (isNeedUpdUI)
  1074. // {
  1075. // // UI展示 - 展示到设备状态页
  1076. // await Task.Run(() =>
  1077. // {
  1078. // try
  1079. // {
  1080. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  1081. // {
  1082. // Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  1083. // if (Form_Main.formDevAlarm.Visible)
  1084. // {
  1085. // Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  1086. // }
  1087. // }
  1088. // }
  1089. // catch { }
  1090. // });
  1091. // }
  1092. // }
  1093. // catch (Exception ex)
  1094. // {
  1095. // string str = ex.StackTrace;
  1096. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1097. // }
  1098. // #endregion 报警数据
  1099. // UpdatePLCMonitor(1, -2, 1);
  1100. //}
  1101. //else
  1102. //{
  1103. // UpdatePLCMonitor(1, -2, 0);
  1104. //}
  1105. }
  1106. catch (Exception ex)
  1107. {
  1108. //AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1109. AddMessage_Station(stationNameStr, LogType.Error,
  1110. $"PLC1_{stationNameStr}_采集运行数据与报警数据出错!错误信息:" + ex.Message.ToString());
  1111. }
  1112. Thread.Sleep(IntervalAlarm);
  1113. }
  1114. }
  1115. #endregion 轮询PLC
  1116. #region 下发订单信息
  1117. ///// <summary>
  1118. ///// 壳体上料(下发工单)的交互逻辑
  1119. ///// </summary>
  1120. ///// <param name="no"></param>
  1121. ///// <exception cref="NotImplementedException"></exception>
  1122. //private void ReadStation_DownOrderInfo(int plcNo)
  1123. //{
  1124. // // [S1] Tray盘上料装备(板测)
  1125. // // [S2] FCT(板测)
  1126. // // [S3] 值板机
  1127. // // [S4] 取放桁架
  1128. // // [S5] Tray盘下料装备
  1129. // /// 上位机心跳
  1130. // /// 获取设备报警数据与状态信息
  1131. // string stationNameStr = "[S0]壳体上料";
  1132. // while (IsRun)
  1133. // {
  1134. // try
  1135. // {
  1136. // if (!GlobalContext._IsCon_Funs1)
  1137. // {
  1138. // UpdatePLCMonitor(plcNo, 0);
  1139. // continue;
  1140. // }
  1141. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  1142. // {
  1143. // #region 壳体上料(下发工单)
  1144. // try
  1145. // {
  1146. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  1147. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  1148. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  1149. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  1150. // // 重置数据和信号
  1151. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  1152. // {
  1153. // // 清空写给PLC的数据
  1154. // int[] i497 = new int[1] { 0 };
  1155. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  1156. // // MES_Flag重置为0
  1157. // int[] i500 = new int[1] { 0 };
  1158. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  1159. // }
  1160. // }
  1161. // catch (Exception ex)
  1162. // {
  1163. // string str = ex.StackTrace;
  1164. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1165. // }
  1166. // #endregion 壳体上料(下发工单)
  1167. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1168. // }
  1169. // else
  1170. // {
  1171. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  1172. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1173. //
  1174. // Funs[plcNo].Connect();
  1175. // }
  1176. // }
  1177. // catch (Exception ex)
  1178. // {
  1179. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  1180. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1181. //
  1182. // Funs[plcNo].ReConnect();
  1183. // }
  1184. // Thread.Sleep(IntervalReadPLC);
  1185. // }
  1186. //}
  1187. ///// <summary>
  1188. ///// 下发订单信息到PLC
  1189. ///// </summary>
  1190. ///// <param name="no">PLC编号</param>
  1191. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  1192. //{
  1193. // try
  1194. // {
  1195. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  1196. // {
  1197. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  1198. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  1199. // }
  1200. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  1201. // }
  1202. // catch (Exception ex)
  1203. // {
  1204. // string str = ex.StackTrace;
  1205. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1206. // }
  1207. //}
  1208. /// <summary>
  1209. /// 下发清料信号
  1210. /// </summary>
  1211. /// <param name="no">PLC编号</param>
  1212. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  1213. {
  1214. try
  1215. {
  1216. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  1217. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  1218. return true;
  1219. }
  1220. catch (Exception ex)
  1221. {
  1222. string str = ex.StackTrace;
  1223. AddMessage_Station(stationNameStr, LogType.Error,
  1224. "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  1225. str.Length - str.LastIndexOf("\\") - 1));
  1226. return false;
  1227. }
  1228. }
  1229. #endregion 下发订单信息
  1230. #region Xiaomi 贲流
  1231. #region 公共方法
  1232. private static bool ProgressState = false;
  1233. private static readonly object lockObj = new object(); // 锁对象
  1234. private static bool isCollectingFlagLeft;
  1235. private static bool isCollectingFlagRight;
  1236. private bool OpenDailogFalg = true; //是否开启扫码弹窗标识
  1237. private static int res = 0;
  1238. public static bool StopWhile =false;
  1239. public void ConnectToIOT()
  1240. {
  1241. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  1242. // fds
  1243. param.parameter.fds.address = GlobalContext.address;
  1244. param.parameter.fds.appId = GlobalContext.appId;
  1245. param.parameter.fds.appKey = GlobalContext.appKey;
  1246. // mes
  1247. param.parameter.mes.address = GlobalContext.ServerIp;
  1248. param.parameter.mes.appId = GlobalContext.MESAppId;
  1249. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  1250. // mqtt
  1251. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  1252. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  1253. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  1254. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  1255. // 设备配置
  1256. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  1257. if (GlobalContext.IsUsePLC1)
  1258. {
  1259. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  1260. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  1261. xiaomiParm.workstation = GlobalContext.S1_work_station; //工站
  1262. }
  1263. if (GlobalContext.IsUsePLC2)
  1264. {
  1265. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  1266. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  1267. xiaomiParm.workstation = GlobalContext.S2_work_station; //工站
  1268. }
  1269. if (GlobalContext.IsUsePLC3)
  1270. {
  1271. param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
  1272. //param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
  1273. }
  1274. if (GlobalContext.IsUsePLC4)
  1275. {
  1276. param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
  1277. param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
  1278. xiaomiParm.workstation = GlobalContext.s4_work_station; //工站
  1279. }
  1280. if (GlobalContext.IsUsePLC5)
  1281. {
  1282. param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
  1283. param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
  1284. xiaomiParm.workstation = GlobalContext.s5_work_station; //工站
  1285. }
  1286. if (GlobalContext.IsUsePLC6)
  1287. {
  1288. param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
  1289. param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
  1290. xiaomiParm.workstation = GlobalContext.s6_work_station; //工站
  1291. }
  1292. if (GlobalContext.IsUsePLC7)
  1293. {
  1294. param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  1295. //param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  1296. xiaomiParm.stationCode = GlobalContext.s7_1_station;
  1297. }
  1298. if (GlobalContext.IsUsePLC8)
  1299. {
  1300. param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
  1301. param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
  1302. xiaomiParm.workstation = GlobalContext.s8_work_station; //工站
  1303. }
  1304. if (GlobalContext.IsUsePLC9)
  1305. {
  1306. param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
  1307. param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
  1308. xiaomiParm.workstation = GlobalContext.s9_work_station; //工站
  1309. }
  1310. param.parameter.equipment.project = GlobalContext.Project_Code;
  1311. param.parameter.equipment.productMode = "debug";
  1312. param.parameter.other.logLevel = 0;
  1313. param.parameter.other.LogPath = GlobalContext.MqttLogDir;
  1314. XiaomiMqttClient_Extend.ParameterConfig(param);
  1315. }
  1316. /// <summary>
  1317. /// float[]转为string
  1318. /// </summary>
  1319. public string FloatArrayToString(float[] nScrewResults)
  1320. {
  1321. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  1322. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  1323. }
  1324. /// <summary>
  1325. /// short[]转为string
  1326. /// </summary>
  1327. public string ShortArrayToString(short[] nScrewResults)
  1328. {
  1329. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  1330. return string.Join(",", nScrewResults);
  1331. }
  1332. /// <summary>
  1333. /// 写入PLC重复三次
  1334. /// </summary>
  1335. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount,
  1336. T inObj)
  1337. {
  1338. int i = 0;
  1339. int nRet = 0;
  1340. string strRet = "";
  1341. try
  1342. {
  1343. while (i < 3) // 最多上传三次
  1344. {
  1345. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  1346. if (nRet == 0) //成功
  1347. {
  1348. break;
  1349. }
  1350. else
  1351. {
  1352. AddMessage_Station(stationNameStr, LogType.Error,
  1353. $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1354. i++;
  1355. }
  1356. }
  1357. return (nRet, strRet);
  1358. }
  1359. catch (Exception ex)
  1360. {
  1361. return (1, ex.Message);
  1362. }
  1363. }
  1364. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes,
  1365. short[] nScrewOrders, short[] nScrewResults)
  1366. {
  1367. try
  1368. {
  1369. // 获取当前日期
  1370. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1371. // 构建保存路径
  1372. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  1373. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction, "螺丝Mes数据");
  1374. // 确保目录存在
  1375. Directory.CreateDirectory(savePath);
  1376. // 文件名
  1377. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  1378. string filePath = Path.Combine(savePath, fileName);
  1379. // 确保不会超出数组长度,只取前14个或数组的实际长度
  1380. int count = Math.Min(14, fScrewTimes.Length);
  1381. using (StreamWriter sw = new StreamWriter(filePath))
  1382. {
  1383. for (int i = 0; i < count; i++)
  1384. {
  1385. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  1386. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  1387. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  1388. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  1389. sw.WriteLine(); // 空行分隔不同螺丝的信息
  1390. }
  1391. }
  1392. return (0, "");
  1393. }
  1394. catch (Exception ex)
  1395. {
  1396. return (1, ex.Message);
  1397. }
  1398. }
  1399. public Dictionary<string, string> GetLastLineCompensation(string path, string direction, string sn)
  1400. {
  1401. // 创建字典存储补偿点及其对应的值
  1402. Dictionary<string, string> compensationDict = new Dictionary<string, string>();
  1403. try
  1404. {
  1405. //string path = GlobalContext.MESLaserRPath;
  1406. // 获取当前日期并格式化为 "yyyy-MM-dd" 格式
  1407. string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
  1408. string filename = $"Laser-{currentDate}-W0.txt";
  1409. // 拼接完整路径
  1410. string fullPath = Path.Combine(path, filename);
  1411. string lastNonEmptyLine = "";
  1412. // 判断文件是否存在
  1413. if (File.Exists(fullPath))
  1414. {
  1415. //读取文件内容
  1416. string[] lines = File.ReadAllLines(fullPath);
  1417. // 获取最后一行数据(忽略标题行)
  1418. if (lines.Length > 1)
  1419. {
  1420. string lastLine = "";
  1421. for (int i = lines.Length - 1; i > 0; i--)
  1422. {
  1423. if (!string.IsNullOrEmpty(lines[i]))
  1424. {
  1425. lastLine = lines[i];
  1426. break;
  1427. }
  1428. }
  1429. // 将最后一行按逗号分隔
  1430. string[] values = lastLine.Split(',');
  1431. values[1] = sn;
  1432. string key = "三点激光_" + direction; // 构造键名
  1433. string value = string.Join(",", values); // 获取值并去除多余空格
  1434. compensationDict[key] = value;
  1435. //// 提取“1点补偿”到“6点补偿”的值
  1436. //for (int i = 2; i <= 7 && i < values.Length; i++) // 从索引2开始,最多提取6个值
  1437. //{
  1438. // string key = $"{i - 1}点补偿"; // 构造键名
  1439. // string value = values[i].Trim(); // 获取值并去除多余空格
  1440. // compensationDict[key] = value;
  1441. //}
  1442. }
  1443. }
  1444. else
  1445. {
  1446. Console.WriteLine($"文件不存在: {fullPath}");
  1447. }
  1448. }
  1449. catch (Exception ex)
  1450. {
  1451. // 捕获异常并输出错误信息
  1452. Console.WriteLine($"发生错误: {ex.Message}");
  1453. }
  1454. return compensationDict;
  1455. }
  1456. public int PCBStationOutData(BarcodeSet_t Barcode, IoT_DataSet_t iotData)
  1457. {
  1458. int res = 0;
  1459. string jsonstr1 = "";
  1460. try
  1461. {
  1462. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1463. outRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备id(可配置)
  1464. outRequest_Body.stationId = GlobalContext.s5_station; // ⼯位ID(可配置)
  1465. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1466. outRequest_Body.clientTime =
  1467. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1468. outRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
  1469. int a1Result = (int)iotData.testStatus;
  1470. //bool pass = a1Result == 1;
  1471. //outRequest_Body.state = pass ? "PASS" : "FAIL"; ; // 出站条件 PASS或FAIL
  1472. outRequest_Body.state = "PASS";
  1473. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1474. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1475. XmStationOut_KeyMaterial keyMaterial = new XmStationOut_KeyMaterial();
  1476. keyMaterial.bindSort = 1;
  1477. keyMaterial.materialSn = Barcode.strProductBarcode;
  1478. outRequest_Body.unitData.keyMaterial.Add(keyMaterial); // 产品码
  1479. jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1480. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1481. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1482. if (response != null && response.header.code == "200")
  1483. {
  1484. res = 1;
  1485. AddMessage(LogType.Info,
  1486. "上传PCB出站数据到MES服务器---成功!请求信息:" + jsonstr1 + ",返回信息:" +
  1487. JsonConvert.SerializeObject(response.body));
  1488. }
  1489. else
  1490. {
  1491. res = 0;
  1492. AddMessage(LogType.Error,
  1493. "上传PCB出站数据到MES服务器---失败!错误信息:" + response.header.desc + ",请求信息:" + jsonstr1 + ",返回信息:" +
  1494. JsonConvert.SerializeObject(response.body));
  1495. }
  1496. }
  1497. catch (Exception e)
  1498. {
  1499. res = 0;
  1500. AddMessage(LogType.Info, "上传PCB出站数据到MES服务器---失败!请求信息:" + jsonstr1 + ",返回信息:" + e.Message);
  1501. }
  1502. return res;
  1503. }
  1504. public int PCBStationInData(BarcodeSet_t Barcode, IoT_DataSet_t iotData)
  1505. {
  1506. int res = 0;
  1507. string json_Body = "";
  1508. try
  1509. {
  1510. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1511. inRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  1512. inRequest_Body.stationId = GlobalContext.s5_station; // ⼯位ID(可配置)
  1513. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1514. inRequest_Body.clientTime =
  1515. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1516. inRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
  1517. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1518. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1519. json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1520. var response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1521. string resultJson = JsonConvert.SerializeObject(response);
  1522. if (response != null && response.header.code == "200")
  1523. {
  1524. res = 1;
  1525. AddMessage(LogType.Info,
  1526. "上传PCB进站数据到MES服务器---成功!请求信息:" + json_Body + ",返回信息:" +
  1527. JsonConvert.SerializeObject(response.body));
  1528. }
  1529. else
  1530. {
  1531. res = 0;
  1532. AddMessage(LogType.Error,
  1533. "上传PCB进站数据到MES服务器---失败!错误信息:" + response.header.desc + ",请求信息:" + json_Body + ",返回信息:" +
  1534. JsonConvert.SerializeObject(response.body));
  1535. }
  1536. }
  1537. catch (Exception e)
  1538. {
  1539. res = 0;
  1540. AddMessage(LogType.Info, "上传PCB进站数据到MES服务器---失败!请求信息:" + json_Body + ",返回信息:" + e.Message);
  1541. }
  1542. return res;
  1543. }
  1544. /// <summary>
  1545. /// 调用进站接口并保存进站数据
  1546. /// </summary>
  1547. /// <param name="stationNameStr">工站信息</param>
  1548. /// <param name="workorder_code">工单号</param>
  1549. /// <param name="mtltmrk">型号(物料号)</param>
  1550. /// <param name="sn">产品SN</param>
  1551. /// <param name="items">进站数据</param>
  1552. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1553. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn,
  1554. List<TestItem> items, string MachineId, string StationId, bool pass, string slot)
  1555. {
  1556. int result = 0;
  1557. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1558. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1559. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1560. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1561. inRequest_Body.clientTime =
  1562. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1563. inRequest_Body.unitSn = sn; // 产品SN
  1564. inRequest_Body.uuidInspection = uuid;
  1565. inRequest_Body.state = pass ? "PASS" : "FAIL";
  1566. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1567. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1568. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1569. StationIn stationIn = new StationIn()
  1570. {
  1571. Workorder_code = workorder_code, // 车间订单号
  1572. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1573. Sn = sn, // SN
  1574. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1575. Parameter_values = items, // 进站数据
  1576. Write_user = inRequest_Body.userId, // 员工Id
  1577. Test_time = inRequest_Body.clientTime // 进站时间
  1578. };
  1579. // 本地数据
  1580. string sql = stationIn.ToStringInsert(0);
  1581. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1582. result = ret == "成功" ? 1 : 6;
  1583. #region MES
  1584. if (GlobalContext.IsSendStationIn)
  1585. {
  1586. try
  1587. {
  1588. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1589. string resultJson = "";
  1590. string mesRet = string.Empty;
  1591. int i = 0;
  1592. while (i < 2) // 1009会多次尝试上传
  1593. {
  1594. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1595. resultJson = JsonConvert.SerializeObject(response);
  1596. if (response != null && response.header.code == "200")
  1597. break;
  1598. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1599. i++;
  1600. i++;
  1601. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1602. // 记录失败原因
  1603. OnMessage(LogType.Error, $"上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:{mesRet},请求参数:{json_Body}");
  1604. }
  1605. if (response?.header?.code == "200")
  1606. {
  1607. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1608. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1609. result = ret_Upd == "成功" ? 1 : 6;
  1610. AddMessage(LogType.Info,
  1611. $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功,返回参数:{resultJson},请求参数:{json_Body}");
  1612. }
  1613. else
  1614. {
  1615. result = 5;
  1616. AddMessage(LogType.Info,
  1617. $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息: {mesRet},请求参数:{json_Body}");
  1618. }
  1619. string sql_response =
  1620. stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1621. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1622. }
  1623. catch (Exception ex)
  1624. {
  1625. result = 6;
  1626. string str = ex.StackTrace;
  1627. AddMessage_Station(stationNameStr, LogType.Error,
  1628. $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1629. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1630. }
  1631. }
  1632. #endregion
  1633. #region IOT
  1634. //过站结果
  1635. if (GlobalContext.IsMqttSendProcessData)
  1636. {
  1637. PassStationResultRequest request = new PassStationResultRequest();
  1638. request.project_code = GlobalContext.Project_Code; // 项⽬编码
  1639. request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
  1640. request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
  1641. request.line_code = GlobalContext.LineCode; // 线体编码
  1642. request.work_station = xiaomiParm.workstation; // ⼯站ID
  1643. request.device_code = xiaomiParm.deviceCode; // 装备编码
  1644. request.station = xiaomiParm.stationCode;
  1645. request.process_time =
  1646. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
  1647. request.slot = slot; // 槽位编码
  1648. request.sn = sn; // 产品SN
  1649. // request.enter_status = inpass ? "PASS" : "FAIL"; // 进站状态
  1650. request.enter_status = pass ? "PASS" : "FAIL"; // 进站状态
  1651. request.result = ""; // 出站条件 PASS或FAIL; // 过站结果
  1652. request.work_type = "OUT_STATION"; // 作业类型
  1653. // 上传过站结果
  1654. (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
  1655. if (iotResult.Item1 != 0)
  1656. {
  1657. OnMessage(LogType.Info,
  1658. $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}] 进站结果[{request.enter_status}] 出站结果[{request.result}]");
  1659. }
  1660. }
  1661. #endregion
  1662. return result;
  1663. }
  1664. /// <summary>
  1665. /// 选择如何记录出站数据
  1666. /// </summary>
  1667. /// <param name="items">出站数据</param>
  1668. /// <param name="equipmentCode">设备编号</param>
  1669. /// <param name="processItem">测试项目</param>
  1670. /// <param name="workorder_code">车间订单号</param>
  1671. /// <param name="batch_num">批次号</param>
  1672. /// <param name="mtltmrk">型号</param>
  1673. /// <param name="proDate">日期</param>
  1674. /// <param name="supplierCode">供应商代码</param>
  1675. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1676. /// <returns>上传成功时返回1;失败返回0</returns>
  1677. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode,
  1678. string processItem,
  1679. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1680. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId,
  1681. string StationId, string PartBarcode, string jsonParm, string direction = "")
  1682. {
  1683. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num,
  1684. mtltmrk,
  1685. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode, jsonParm,
  1686. direction);
  1687. }
  1688. /// <summary>
  1689. /// 添加出站数据(提交到MES+本地保存到数据库)
  1690. /// </summary>
  1691. /// <param name="items">出站数据</param>
  1692. /// <param name="equipmentCode">设备编号</param>
  1693. /// <param name="processItem">测试项目</param>
  1694. /// <param name="workorder_code">车间订单号</param>
  1695. /// <param name="batch_num">批次号</param>
  1696. /// <param name="mtltmrk">型号</param>
  1697. /// <param name="proDate">日期</param>
  1698. /// <param name="supplierCode">供应商代码</param>
  1699. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1700. /// <returns>上传成功时返回1;失败返回0</returns>
  1701. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1702. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1703. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot,
  1704. string machineId, string stationId, string partBarcode, string jsonParm, string direction = "")
  1705. {
  1706. int upload = 0;
  1707. int result = 0;
  1708. ProcessData processData = new ProcessData()
  1709. {
  1710. Equipment_code = equipmentCode,
  1711. Workorder_code = workorder_code,
  1712. Batch_number = batch_num,
  1713. Sn = sn, // SN
  1714. Testitem = processItem,
  1715. Parameter_values = items,
  1716. Write_user = GlobalContext.CurrentUser,
  1717. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1718. };
  1719. // 本地数据
  1720. string sql = processData.ToStringInsert(upload);
  1721. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1722. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1723. #region MES
  1724. if (GlobalContext.IsSendProcessData)
  1725. {
  1726. try
  1727. {
  1728. string id = processData.ID.Copy();
  1729. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1730. if (direction == "Right")
  1731. outRequest_Body.uuidInspection = uuid2;
  1732. else
  1733. outRequest_Body.uuidInspection = uuid;
  1734. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1735. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1736. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1737. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1738. outRequest_Body.unitSn = sn; // 产品SN
  1739. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1740. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1741. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1742. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1743. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1744. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1745. if (!string.IsNullOrEmpty(partBarcode))
  1746. {
  1747. outRequest_Body.unitData.keyMaterial.Add(
  1748. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1749. {
  1750. bindSort = 1,
  1751. materialSn = partBarcode
  1752. }); // 设备数据 - 部件码
  1753. }
  1754. //OP30站读txt数据
  1755. if (stationNameStr.Contains("OP30"))
  1756. {
  1757. string path = "";
  1758. if (direction == "Left")
  1759. path = GlobalContext.MESLaserLPath;
  1760. else
  1761. path = GlobalContext.MESLaserRPath;
  1762. //字典存储数据
  1763. Dictionary<string, string> compensationDict = GetLastLineCompensation(path, direction, sn);
  1764. foreach (var kvp in compensationDict)
  1765. {
  1766. outRequest_Body.unitData.processData.Add(
  1767. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1768. {
  1769. dataName = kvp.Key.ToString(),
  1770. dataValue = kvp.Value.ToString()
  1771. });
  1772. }
  1773. }
  1774. //过站明细
  1775. if (GlobalContext.IsSendProcessDetail)
  1776. {
  1777. if (jsonParm.Length > 0)
  1778. {
  1779. //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]}";
  1780. // 解析JSON字符串为字典
  1781. jsonParm = jsonParm.Replace("[", "\"[");
  1782. jsonParm = jsonParm.Replace("]", "]\"");
  1783. var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonParm);
  1784. foreach (var kvp in dictionary)
  1785. {
  1786. outRequest_Body.unitData.processData.Add(
  1787. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1788. {
  1789. dataName = kvp.Key.ToString(),
  1790. dataValue = string.IsNullOrEmpty(kvp.Value) ? "" : kvp.Value.ToString()
  1791. });
  1792. }
  1793. }
  1794. }
  1795. if (GlobalContext.MESIsSendUpFile)
  1796. {
  1797. foreach (var item in fileUploadData.fileData)
  1798. {
  1799. if (!string.IsNullOrEmpty(item.FileName))
  1800. {
  1801. outRequest_Body.unitData.fileData.Add(
  1802. new XmStationOut_FileData()
  1803. {
  1804. fileName = item.FileName,
  1805. fileId = item.FileId,
  1806. bucket = item.Bucket
  1807. });
  1808. }
  1809. }
  1810. }
  1811. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1812. if (GlobalContext.IsSendProcessData)
  1813. {
  1814. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1815. string mesRet = string.Empty;
  1816. int i = 0;
  1817. while (i < 2) // 1009会多次尝试上传
  1818. {
  1819. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1820. if (response != null && response.header.code == "200")
  1821. {
  1822. OnMessage(LogType.Info,
  1823. $"【出站数据 SN {sn}】上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" +
  1824. JsonConvert.SerializeObject(response.body));
  1825. break;
  1826. }
  1827. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1828. i++;
  1829. i++;
  1830. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1831. // 记录失败原因
  1832. OnMessage(LogType.Error,
  1833. $"【出站数据 SN {sn}】上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1834. }
  1835. if (response?.header?.code == "200")
  1836. {
  1837. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1838. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1839. result = 1;
  1840. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1841. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1842. }
  1843. else
  1844. {
  1845. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1846. }
  1847. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(
  1848. JsonConvert.SerializeObject(outRequest_Body),
  1849. JsonConvert.SerializeObject(response), id);
  1850. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1851. }
  1852. }
  1853. catch (Exception ex)
  1854. {
  1855. string str = ex.StackTrace;
  1856. AddMessage_Station(stationNameStr, LogType.Error,
  1857. $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1858. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1859. }
  1860. }
  1861. #endregion
  1862. #region IOT
  1863. //过站明细
  1864. if (GlobalContext.IsMqttSendProcessData)
  1865. {
  1866. PassStationDetailRequest request = new PassStationDetailRequest();
  1867. if (direction == "Right")
  1868. request.pass_station_id = uuid2;
  1869. else
  1870. request.pass_station_id = uuid;
  1871. request.sn = sn; // 产品SN
  1872. request.slot = vehicleSlot; // 槽位编码
  1873. request.function_name = "Machine_加⼯模块";
  1874. request.status = "PASS";
  1875. (int, string) iotResult = (0, "");
  1876. if (jsonParm.Length > 0)
  1877. {
  1878. // 解析JSON字符串为字典
  1879. var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonParm);
  1880. foreach (var kvp in dictionary)
  1881. {
  1882. test_item_num += 1;
  1883. request.test_item_num = test_item_num.ToString();
  1884. request.test_item = kvp.Key.ToString();
  1885. request.result_val = string.IsNullOrEmpty(kvp.Value) ? "" : kvp.Value.ToString();
  1886. request.description = request.test_item;
  1887. // 上传过站明细
  1888. iotResult = XiaomiMqttClient_Extend.Write_PassStationDetail(request);
  1889. if (iotResult.Item1 != 0)
  1890. {
  1891. OnMessage(LogType.Info,
  1892. $"【IOT过站明细】上传失败!错误原因:{iotResult.Item2},过站明细;产品码[{sn}] 测试项目[{request.test_item}] 测试值[{request.result_val}]");
  1893. }
  1894. }
  1895. }
  1896. }
  1897. //过站结果
  1898. if (GlobalContext.IsMqttSendProcessData)
  1899. {
  1900. PassStationResultRequest request = new PassStationResultRequest();
  1901. request.project_code = GlobalContext.Project_Code; // 项⽬编码
  1902. request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
  1903. request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
  1904. request.line_code = GlobalContext.LineCode; // 线体编码
  1905. request.work_station = xiaomiParm.workstation; // ⼯站ID
  1906. request.device_code = xiaomiParm.deviceCode; // 装备编码
  1907. request.station = xiaomiParm.stationCode;
  1908. request.process_time =
  1909. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
  1910. request.slot = vehicleSlot; // 槽位编码
  1911. request.sn = sn; // 产品SN
  1912. // request.enter_status = inpass ? "PASS" : "FAIL"; // 进站状态
  1913. request.enter_status = ""; // 进站状态
  1914. request.result = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL; // 过站结果
  1915. request.work_type = "OUT_STATION"; // 作业类型
  1916. // 上传过站结果
  1917. (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
  1918. if (iotResult.Item1 != 0)
  1919. {
  1920. OnMessage(LogType.Info,
  1921. $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}] 进站结果[{request.enter_status}] 出站结果[{request.result}]");
  1922. }
  1923. }
  1924. #endregion
  1925. return result;
  1926. }
  1927. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1928. //{
  1929. // Stopwatch stopwatch = new Stopwatch();
  1930. // stopwatch.Start();
  1931. // try
  1932. // {
  1933. // // 初始化 AtlasScrew 实例
  1934. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1935. // atlasScrew1.Initial();
  1936. // // 存储结果的列表
  1937. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1938. // // 存储角度和扭力的字符串列表
  1939. // List<string> angleStrs = new List<string>();
  1940. // List<string> torqueStrs = new List<string>();
  1941. // // 上一次获取的数据
  1942. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1943. // while (isExitAtlasLeft) // 检查是否收集数据
  1944. // {
  1945. // // 获取当前数据
  1946. // var currentResult = atlasScrew1.GetResults();
  1947. // // 判断是否为新数据
  1948. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1949. // {
  1950. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1951. // // 更新角度和扭力的字符串列表
  1952. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1953. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1954. // // 计算角度、扭力、起始扭力和最大扭力
  1955. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1956. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1957. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1958. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1959. // // 将新数据添加到结果列表
  1960. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1961. // // 更新上一次获取的数据
  1962. // lastResult = currentResult;
  1963. // }
  1964. // // 等待一段时间后再次检查
  1965. // Thread.Sleep(20); // 轮询间隔时间
  1966. // // 如果触发了出站,则退出循环
  1967. // if (!isExitAtlasLeft)
  1968. // {
  1969. // break;
  1970. // }
  1971. // }
  1972. // // 生成文件名
  1973. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1974. // // 写入数据到文件
  1975. // using (StreamWriter writer = new StreamWriter(fileName))
  1976. // {
  1977. // // 写入标题行
  1978. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1979. // // 写入每一行数据
  1980. // foreach (var result in results)
  1981. // {
  1982. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1983. // }
  1984. // }
  1985. // stopwatch.Stop();
  1986. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1987. // }
  1988. // catch (Exception ex)
  1989. // {
  1990. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1991. // }
  1992. // finally
  1993. // {
  1994. // // 重置标志变量
  1995. // isExitAtlasLeft = false;
  1996. // }
  1997. //}
  1998. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1999. //{
  2000. // Stopwatch stopwatch = new Stopwatch();
  2001. // stopwatch.Start();
  2002. // try
  2003. // {
  2004. // // 初始化 AtlasScrew 实例
  2005. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  2006. // atlasScrew2.Initial();
  2007. // // 存储结果的列表
  2008. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  2009. // // 上一次获取的数据
  2010. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  2011. // while (isExitAtlasRight) // 检查是否收集数据
  2012. // {
  2013. // // 获取当前数据
  2014. // var currentResult = atlasScrew2.GetResults();
  2015. // // 判断是否为新数据
  2016. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  2017. // {
  2018. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  2019. // // 将新数据写入PLC
  2020. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  2021. // // 将新数据添加到结果列表
  2022. // results.Add(currentResult);
  2023. // // 更新上一次获取的数据
  2024. // lastResult = currentResult;
  2025. // }
  2026. // // 等待一段时间后再次检查
  2027. // Thread.Sleep(20); // 轮询间隔时间
  2028. // // 如果触发了出站,则退出循环
  2029. // if (!isExitAtlasRight)
  2030. // {
  2031. // break;
  2032. // }
  2033. // }
  2034. // // 将所有数据写入文件
  2035. // //WriteDataToFile(sn, direction, results);
  2036. // stopwatch.Stop();
  2037. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  2038. // }
  2039. // catch (Exception ex)
  2040. // {
  2041. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  2042. // }
  2043. // finally
  2044. // {
  2045. // // 重置标志变量
  2046. // isExitAtlasRight = false;
  2047. // }
  2048. //}
  2049. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  2050. {
  2051. Stopwatch stopwatch = new Stopwatch();
  2052. stopwatch.Start();
  2053. int nRet = 0;
  2054. string strRet = "";
  2055. try
  2056. {
  2057. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  2058. while (isCollectingFlagLeft)
  2059. {
  2060. // 从缓存中获取所有未处理的数据
  2061. var cachedData = atlasScrew.GetCachedDataLeft();
  2062. foreach (var currentResult in cachedData)
  2063. {
  2064. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  2065. {
  2066. continue; // 跳过无效数据
  2067. }
  2068. OnMessage(LogType.Info,
  2069. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  2070. // 写入PLC
  2071. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  2072. {
  2073. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  2074. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  2075. };
  2076. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  2077. if (nRet != 0)
  2078. {
  2079. OnMessage(LogType.Info,
  2080. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  2081. }
  2082. else
  2083. {
  2084. OnMessage(LogType.Info,
  2085. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  2086. }
  2087. // 构建保存路径
  2088. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  2089. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  2090. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  2091. Directory.CreateDirectory(savePath); // 确保目录存在
  2092. // 构建文件名(以 SN + 序号命名)
  2093. string fileName = $"{sn}_{fileCounter}.txt";
  2094. string filePath = Path.Combine(savePath, fileName);
  2095. // 写入文件
  2096. using (StreamWriter writer = new StreamWriter(filePath))
  2097. {
  2098. writer.WriteLine("精度, 扭力");
  2099. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  2100. for (int i = 0;
  2101. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  2102. i++)
  2103. {
  2104. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  2105. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  2106. writer.WriteLine($"{precision}, {torque}");
  2107. }
  2108. }
  2109. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  2110. // 增加文件计数器
  2111. fileCounter++;
  2112. }
  2113. // 如果没有更多数据,则短暂休眠以节省资源
  2114. if (!cachedData.Any())
  2115. {
  2116. Thread.Sleep(10); // 根据需要调整休眠时间
  2117. }
  2118. // 如果触发了出站,则退出循环
  2119. if (!isCollectingFlagLeft)
  2120. {
  2121. break;
  2122. }
  2123. }
  2124. stopwatch.Stop();
  2125. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  2126. }
  2127. catch (Exception ex)
  2128. {
  2129. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  2130. }
  2131. finally
  2132. {
  2133. isCollectingFlagLeft = false;
  2134. }
  2135. }
  2136. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  2137. {
  2138. Stopwatch stopwatch = new Stopwatch();
  2139. stopwatch.Start();
  2140. int nRet = 0;
  2141. string strRet = "";
  2142. try
  2143. {
  2144. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  2145. while (isCollectingFlagRight)
  2146. {
  2147. // 从缓存中获取所有未处理的数据
  2148. var cachedData = atlasScrew.GetCachedDataLeft();
  2149. foreach (var currentResult in cachedData)
  2150. {
  2151. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  2152. {
  2153. continue; // 跳过无效数据
  2154. }
  2155. OnMessage(LogType.Info,
  2156. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  2157. // 写入PLC
  2158. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  2159. {
  2160. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  2161. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  2162. };
  2163. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  2164. if (nRet != 0)
  2165. {
  2166. OnMessage(LogType.Info,
  2167. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  2168. }
  2169. else
  2170. {
  2171. OnMessage(LogType.Info,
  2172. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  2173. }
  2174. // 构建保存路径
  2175. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  2176. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  2177. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  2178. Directory.CreateDirectory(savePath); // 确保目录存在
  2179. // 构建文件名(以 SN + 序号命名)
  2180. string fileName = $"{sn}_{fileCounter}.txt";
  2181. string filePath = Path.Combine(savePath, fileName);
  2182. // 写入文件
  2183. using (StreamWriter writer = new StreamWriter(filePath))
  2184. {
  2185. writer.WriteLine("精度, 扭力");
  2186. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  2187. for (int i = 0;
  2188. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  2189. i++)
  2190. {
  2191. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  2192. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  2193. writer.WriteLine($"{precision}, {torque}");
  2194. }
  2195. }
  2196. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  2197. // 增加文件计数器
  2198. fileCounter++;
  2199. }
  2200. // 如果没有更多数据,则短暂休眠以节省资源
  2201. if (!cachedData.Any())
  2202. {
  2203. Thread.Sleep(10); // 根据需要调整休眠时间
  2204. }
  2205. // 如果触发了出站,则退出循环
  2206. if (!isCollectingFlagRight)
  2207. {
  2208. break;
  2209. }
  2210. }
  2211. stopwatch.Stop();
  2212. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  2213. }
  2214. catch (Exception ex)
  2215. {
  2216. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  2217. }
  2218. finally
  2219. {
  2220. isCollectingFlagRight = false;
  2221. }
  2222. }
  2223. public static (int, string) CompressFolder(string folderPath, string zipFilePath)
  2224. {
  2225. try
  2226. {
  2227. // 创建zip文件,将指定文件夹内的所有内容压缩到这个zip文件中
  2228. System.IO.Compression.ZipFile.CreateFromDirectory(folderPath, zipFilePath);
  2229. return (1, "文件夹已成功压缩!");
  2230. }
  2231. catch (Exception ex)
  2232. {
  2233. return (0, "文件压缩出错!" + ex.Message);
  2234. }
  2235. }
  2236. /// <summary>
  2237. /// 上传文件
  2238. /// </summary>
  2239. /// <param name="BarcodeSet_t">条码集合</param>
  2240. /// <param name="stationCode">工站编号</param>
  2241. /// <param name="stationName">工站名称</param>
  2242. /// <param name="path">文件路径</param>
  2243. public async Task<(int, string)> SaveDBbyFileInfo(BarcodeSet_t BarcodeSet, string stationCode,
  2244. string stationName, int pass, string path, string guid = "")
  2245. {
  2246. string sql, filename = "";
  2247. int result = 0;
  2248. var formData = new MultipartFormDataContent();
  2249. string msg = "";
  2250. string file_category = "IMAGE"; //IMAGE 、TEXT 、UNKNOWN
  2251. string file_type = "IMAGE";
  2252. string project = GlobalContext.ProgramName;
  2253. string run_mode = GlobalContext.run_mode;
  2254. string product_mode = GlobalContext.product_mode;
  2255. string pass_result = (pass == 1 ? "PASS" : "Fail");
  2256. string device_code = xiaomiParm.deviceCode;
  2257. string sn = BarcodeSet.strProductBarcode;
  2258. string staion_id = xiaomiParm.stationCode;
  2259. string bucket =
  2260. $"{file_category}/{file_type}/{project}/{product_mode}/{run_mode}/{pass_result}/{device_code}/{sn}/{staion_id}";
  2261. // 获取所有图片文件
  2262. if (guid == "")
  2263. {
  2264. guid = Guid.NewGuid().ToString();
  2265. }
  2266. try
  2267. {
  2268. if (GlobalContext.MESIsSendUpFile)
  2269. {
  2270. List<string> imageFiles = GetAllImageFiles(path);
  2271. string toPath = GlobalContext.MqttFileBackupLogDir;
  2272. filename =
  2273. $"{xiaomiParm.workstation}_{file_type}_{sn}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";
  2274. //string directoryPath = Path.GetDirectoryName(path);
  2275. string strFilePath = toPath + "\\" + filename;
  2276. if (imageFiles.Count > 0)
  2277. {
  2278. var r = CompressFolder(path, strFilePath);
  2279. if (r.Item1 == 0)
  2280. {
  2281. return (0, r.Item2);
  2282. }
  2283. else
  2284. {
  2285. msg = r.Item2 + "\r\n";
  2286. }
  2287. }
  2288. else
  2289. {
  2290. return (0, "文件不存在!");
  2291. }
  2292. FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
  2293. fileUpload_X5.bucket = bucket;
  2294. fileUpload_X5.name = filename;
  2295. fileUpload_X5.uuid = guid.ToString();
  2296. ///需要上传文件
  2297. FileInfo file = new FileInfo(strFilePath);
  2298. string fileMd5Hex = GetMD5Hex(file);
  2299. fileUpload_X5.md5 = fileMd5Hex;
  2300. fileUpload_X5.uploadCloud = true;
  2301. fileUpload_X5.informMqtt = true;
  2302. FileMqttPayload fileMqttPayload = new FileMqttPayload();
  2303. fileMqttPayload.factory = GlobalContext.Factory_Code;
  2304. fileMqttPayload.project_name = GlobalContext.Project_Code;
  2305. fileMqttPayload.product_mode = GlobalContext.product_mode;
  2306. fileMqttPayload.line_no = GlobalContext.LineCode;
  2307. fileMqttPayload.work_station_no = xiaomiParm.workstation;
  2308. fileMqttPayload.equipment_no = xiaomiParm.deviceCode;
  2309. fileMqttPayload.station_no = xiaomiParm.stationCode;
  2310. fileMqttPayload.file_id = guid;
  2311. fileMqttPayload.file_name = filename;
  2312. fileMqttPayload.sn = BarcodeSet.strProductBarcode;
  2313. //fileMqttPayload.opt_time = "";
  2314. //fileMqttPayload.file_type = "";
  2315. //fileMqttPayload.file_category = "";
  2316. //fileMqttPayload.tag = "";
  2317. fileMqttPayload.reference_info.pass_station_id = uuid;
  2318. var fileresult = await
  2319. XiaomiMESHttp_UpLoadFile.FileUoladToMes(strFilePath, fileUpload_X5, fileMqttPayload);
  2320. if (fileresult.Item1 != 1)
  2321. {
  2322. return (0, msg + fileresult.Item2 + "\r\n");
  2323. }
  2324. else
  2325. {
  2326. msg = msg + fileresult.Item2 + "\r\n";
  2327. }
  2328. foreach (var imageFile in imageFiles)
  2329. {
  2330. if (File.Exists(imageFile))
  2331. {
  2332. //删除文件
  2333. (bool, string) newResult = DeleteFile(imageFile);
  2334. if (!newResult.Item1)
  2335. {
  2336. return (0, Path.GetFileName(imageFile) + newResult.Item2);
  2337. }
  2338. }
  2339. }
  2340. }
  2341. return (1, msg);
  2342. }
  2343. catch (Exception e)
  2344. {
  2345. return (0,
  2346. filename + $"文件上传错误!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode},错误原因:" +
  2347. e.Message);
  2348. }
  2349. }
  2350. /// <summary>
  2351. /// 获取路径下的所有图片
  2352. /// </summary>
  2353. /// <param name="directoryPath"></param>
  2354. /// <returns></returns>
  2355. public List<string> GetAllImageFiles(string directoryPath)
  2356. {
  2357. var imageExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
  2358. { ".jpg", ".jpeg", ".png", ".bmp", ".gif", ".tiff" };
  2359. var imageFiles = new List<string>();
  2360. try
  2361. {
  2362. // 遍历目录及子目录中的所有文件
  2363. foreach (string file in Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories))
  2364. {
  2365. // 获取文件扩展名并检查是否为图片格式
  2366. string extension = Path.GetExtension(file);
  2367. if (imageExtensions.Contains(extension))
  2368. {
  2369. imageFiles.Add(file);
  2370. }
  2371. }
  2372. }
  2373. catch (Exception ex)
  2374. {
  2375. OnMessage(LogType.Error, $"图片查询发生错误: {ex.Message}");
  2376. }
  2377. return imageFiles;
  2378. }
  2379. /// <summary>
  2380. /// 实例化报警字典
  2381. /// </summary>
  2382. private (bool, string) InitalDicAlarm()
  2383. {
  2384. #region 加载报警表
  2385. string excelPath = "";
  2386. switch (GlobalContext.IsUsePLCNow)
  2387. {
  2388. case 1:
  2389. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_10_壳体清洁上料.xlsx";
  2390. break;
  2391. case 2:
  2392. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_20_上盖板上料装备.xlsx";
  2393. break;
  2394. case 3:
  2395. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_30_点散热胶装备.xlsx";
  2396. break;
  2397. case 4:
  2398. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_40_胶线检测.xlsx";
  2399. break;
  2400. case 5:
  2401. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_50_ADD板上料组装装备.xlsx";
  2402. break;
  2403. case 6:
  2404. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_60_组上盖板.xlsx";
  2405. break;
  2406. case 7:
  2407. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_70_上盖板锁螺丝.xlsx";
  2408. break;
  2409. case 8:
  2410. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_80_NG下料.xlsx";
  2411. break;
  2412. case 9:
  2413. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_90_半成品下料.xlsx";
  2414. break;
  2415. default:
  2416. return (false, $"不支持当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请在设置页切换到正确的plc后重启该软件!");
  2417. }
  2418. if (!File.Exists(excelPath))
  2419. return (false, $"未找到当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请检查文件路径:'{excelPath}'。");
  2420. DataTable DtModel = NPOIHelper.ReadExcel(excelPath);
  2421. if (DtModel == null || DtModel.Rows.Count < 1)
  2422. return (false, $"报警点位表未包含任何报警数据!请检查‘{excelPath}’文件!");
  2423. // 检查列名
  2424. List<string> isNeedParms = new List<string>()
  2425. {
  2426. "设备分类名称", "设备分类编码", "分类层级1", "分类层级2", "分类层级3", "分类层级4", "事件名称", "事件ID", "描述", "标签", "PLC地址", "工位"
  2427. }; // 必须要有的列
  2428. // 指定列名 + 检查列是否完整
  2429. DataRow dtRowName = DtModel.Rows[0];
  2430. int count = DtModel.Columns.Count;
  2431. for (int i = 0; i < count; i++)
  2432. {
  2433. string columeName = dtRowName[i]?.ToString();
  2434. if (!string.IsNullOrEmpty(columeName))
  2435. DtModel.Columns[i].ColumnName = columeName;
  2436. if ((!string.IsNullOrEmpty(columeName)) && isNeedParms.Count > 0 && isNeedParms.Contains(columeName))
  2437. isNeedParms.Remove(columeName);
  2438. }
  2439. DtModel.Rows.RemoveAt(0);
  2440. if (isNeedParms.Count > 0)
  2441. {
  2442. string msg1 = string.Join(",", isNeedParms);
  2443. return (false, $"报警点位表未包含列:{msg1}!请检查‘{excelPath}’文件!");
  2444. }
  2445. #endregion 加载报警表
  2446. List<Alarm> keyValues1 = new List<Alarm>();
  2447. for (int i = 0; i < DtModel.Rows.Count; i++)
  2448. {
  2449. Alarm alarm = new Alarm();
  2450. alarm.plcName = DtModel.Rows[i]["设备分类名称"]?.ToString(); // 设备名;
  2451. string type1Str = DtModel.Rows[i]["分类层级1"]?.ToString(); // 分类层级1;
  2452. alarm.type1CH = type1Str; // 分类层级1 中文
  2453. alarm.type1 = type1Str; // 分类层级1
  2454. if (!string.IsNullOrEmpty(type1Str) && type1Str.Contains("\n"))
  2455. {
  2456. string[] type1Strs = type1Str.Split('\n');
  2457. if (type1Strs.Length >= 2)
  2458. {
  2459. alarm.type1CH = type1Strs[0].Trim(); // 分类层级1 中文
  2460. alarm.type1 = type1Strs[1].Trim(); // 分类层级1
  2461. if (string.IsNullOrEmpty(alarm.type1))
  2462. alarm.type1 = alarm.type1CH;
  2463. }
  2464. }
  2465. string type2Str = DtModel.Rows[i]["分类层级2"]?.ToString(); // 分类层级2;电气控制 electric_control
  2466. alarm.type2CH = type2Str; // 分类层级2 中文
  2467. alarm.type2 = type2Str; // 分类层级2
  2468. if (!string.IsNullOrEmpty(type2Str) && type2Str.Contains("\n"))
  2469. {
  2470. string[] type2Strs = type2Str.Split('\n');
  2471. if (type2Strs.Length >= 2)
  2472. {
  2473. alarm.type2CH = type2Strs[0].Trim(); // 分类层级2 中文
  2474. alarm.type2 = type2Strs[1].Trim(); // 分类层级2
  2475. if (string.IsNullOrEmpty(alarm.type2))
  2476. alarm.type2 = alarm.type2CH;
  2477. }
  2478. }
  2479. string type3Str = DtModel.Rows[i]["分类层级3"]?.ToString(); // 分类层级3;故障 Fault
  2480. alarm.type3CH = type3Str; // 分类层级3 中文
  2481. alarm.type3 = type3Str; // 分类层级3
  2482. if (!string.IsNullOrEmpty(type3Str) && type3Str.Contains("\n"))
  2483. {
  2484. string[] type3Strs = type3Str.Split('\n');
  2485. if (type3Strs.Length >= 2)
  2486. {
  2487. alarm.type3CH = type3Strs[0].Trim(); // 分类层级3 中文
  2488. alarm.type3 = type3Strs[1].Trim(); // 分类层级3
  2489. if (string.IsNullOrEmpty(alarm.type3))
  2490. alarm.type3 = alarm.type3CH;
  2491. }
  2492. }
  2493. string faultStr = DtModel.Rows[i]["分类层级4"]?.ToString(); // 故障部件;overall_module
  2494. alarm.type4 = faultStr; // 分类层级4 中文
  2495. alarm.type4CH = faultStr; // 分类层级4
  2496. if (!string.IsNullOrEmpty(faultStr) && faultStr.Contains("\n"))
  2497. {
  2498. string[] faultStrs = faultStr.Split('\n');
  2499. if (faultStrs.Length >= 2)
  2500. {
  2501. alarm.type4CH = faultStrs[0].Trim(); // 故障部件;overall_module
  2502. alarm.type4 = faultStrs[1].Trim(); // 故障部件
  2503. if (string.IsNullOrEmpty(alarm.type4))
  2504. alarm.type4 = alarm.type4CH;
  2505. }
  2506. }
  2507. alarm.fault_code = DtModel.Rows[i]["事件ID"]?.ToString(); // 故障编码;A40001
  2508. alarm.fault_name = DtModel.Rows[i]["事件名称"]?.ToString(); // 故障名称;AL[1000]_系统_HMI急停故障
  2509. alarm.fault_desc = alarm.fault_name; // 故障描述;AL[1000]_系统_HMI急停故障
  2510. string plcAdress = DtModel.Rows[i]["PLC地址"]?.ToString();
  2511. alarm.PLC地址 = plcAdress;
  2512. plcAdress = plcAdress.Replace("fault_codes[", "");
  2513. plcAdress = plcAdress.Replace("]", "");
  2514. alarm.group_index = Convert.ToInt32(plcAdress.Split(".")[0]);
  2515. keyValues1.Add(alarm);
  2516. }
  2517. DicAlarms_Cur.Add(GlobalContext.IsUseStationName, keyValues1); // 这里使用线体代替工位
  2518. return (true, "报警字典表初始化成功!");
  2519. }
  2520. private async void ReadPLCAlarmToIot(uint[] FaultData, uint[] FaultDataOld, string stationNameStr,string flag)
  2521. {
  2522. DateTime dtNow = DateTime.Now;
  2523. try
  2524. {
  2525. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  2526. List<(int, int)> AlarmIndexList = new List<(int, int)>(); //收集所有报警信息的位置
  2527. AlarmData alarmData = new AlarmData();
  2528. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  2529. bool isNoAlarm = false; //是否有报警
  2530. string binaryString = "";
  2531. bool isNoNewAlarm = false; //是否有新的报警
  2532. if (FaultData.Length > 0)
  2533. {
  2534. foreach (var item in FaultData)
  2535. {
  2536. if (item > 0)
  2537. {
  2538. isNoAlarm = true;
  2539. break;
  2540. }
  2541. else {
  2542. isNoAlarm = false;
  2543. }
  2544. }
  2545. if (!FaultData.SequenceEqual(FaultDataOld))
  2546. {
  2547. isNoNewAlarm = true;
  2548. isNeedUpdUI = true;
  2549. }
  2550. if (FaultData.Length > 0 && isNoAlarm && isNoNewAlarm)
  2551. {
  2552. //解析报警信息,分析当前报警在字典中的定位
  2553. for (int i = 0; i <= FaultData.Length - 1; i++)
  2554. {
  2555. var num = 0;
  2556. if (FaultData[i] > 0)
  2557. {
  2558. //转换二进制
  2559. binaryString = Convert.ToString(FaultData[i], 2);
  2560. for (int j = binaryString.Length - 1; j >= 0; j--)
  2561. {
  2562. num++;
  2563. char s = binaryString[j];
  2564. if (binaryString[j] == '1')
  2565. {
  2566. //记录1的位置
  2567. AlarmIndexList.Add((i, num - 1));
  2568. }
  2569. }
  2570. }
  2571. }
  2572. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  2573. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.IsUseStationName];
  2574. foreach ((int index, int row) in AlarmIndexList)
  2575. {
  2576. var tempDic = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList();
  2577. for (int i = 0; i < tempDic.Count - 1; i++) // 读取
  2578. {
  2579. //若报警字典第[group_index]个数据,第[i]行与AlarmIndexList中的定位匹配,则添加进对应行的报警数据
  2580. if (tempDic[i].group_index == index && i == row)
  2581. {
  2582. dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据 =
  2583. new AlarmData()
  2584. {
  2585. GUID = Guid.NewGuid().ToString(),
  2586. LineName = GlobalContext.IsUseStationName, // 工站
  2587. PlcStation = tempDic[i].plcName, // 工站全称;[S1]
  2588. Type1 = tempDic[i].type1, // 故障层级1
  2589. Type2 = tempDic[i].type2, // 故障层级2
  2590. Type3 = tempDic[i].type3, // 故障层级3
  2591. Type4 = tempDic[i].type4, // 故障层级4
  2592. AlarmType = tempDic[i].fault_code, // 报警类型
  2593. AlarmDesc = tempDic[i].fault_name, // 报警内容
  2594. StartTime = dtNow // 开始时间
  2595. };
  2596. // 传输到页面
  2597. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  2598. {
  2599. 线体名称 = tempDic[i].plcName,
  2600. 报警类型 = tempDic[i].fault_code,
  2601. 报警内容 = tempDic[i].fault_name,
  2602. 开始时间 = dtNow
  2603. });
  2604. // 新增到数据库
  2605. //var data1 = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据;
  2606. //SaveAlarmDataByDB(stationNameStr, data1, false);
  2607. //OnMessage(LogType.Info, $"更新{BodyAlarm}完毕!");
  2608. }
  2609. }
  2610. }
  2611. //筛选含报警数据的字典
  2612. var dicAlarms_Cur = dicAlarms_Cur_PLC1.Where(x => x.报警数据 != null).ToList();
  2613. if (dicAlarms_Cur.Count > 0)
  2614. {
  2615. string stationId = "";
  2616. foreach (var item in dicAlarms_Cur)
  2617. {
  2618. if (!string.IsNullOrEmpty(xiaomiParm.stationCode))
  2619. {
  2620. stationId = xiaomiParm.stationCode;
  2621. //上传
  2622. SaveAlarmDataByDB(GlobalContext.IsUseStationName, stationId, item.报警数据, false);
  2623. }
  2624. else {
  2625. if (flag == "left")
  2626. {
  2627. if (GlobalContext.IsUsePLC3)
  2628. stationId = GlobalContext.s3_1_station;
  2629. if (GlobalContext.IsUsePLC7)
  2630. stationId = GlobalContext.s7_1_station;
  2631. //上传
  2632. SaveAlarmDataByDB(GlobalContext.IsUseStationName, stationId, item.报警数据, false);
  2633. }
  2634. else {
  2635. if (GlobalContext.IsUsePLC3)
  2636. stationId = GlobalContext.s3_2_station;
  2637. if (GlobalContext.IsUsePLC7)
  2638. stationId = GlobalContext.s7_2_station;
  2639. //上传
  2640. SaveAlarmDataByDB(GlobalContext.IsUseStationName, stationId, item.报警数据, false);
  2641. }
  2642. }
  2643. }
  2644. }
  2645. // 有新报警则更新
  2646. if (isNeedUpdUI)
  2647. // UI展示 - 展示到设备状态页
  2648. await Task.Run(() =>
  2649. {
  2650. try
  2651. {
  2652. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  2653. {
  2654. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  2655. if (Form_Main.formDevAlarm.Visible)
  2656. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  2657. }
  2658. }
  2659. catch
  2660. {
  2661. }
  2662. });
  2663. if (flag == "left")
  2664. {
  2665. _FaultDatas_Old = FaultData.ToArray();
  2666. }
  2667. else {
  2668. _FaultDatas_Old2 = FaultData.ToArray();
  2669. }
  2670. }
  2671. }
  2672. //FaultLogRequest request = new FaultLogRequest();
  2673. //request.station = mesStation; // 工位
  2674. //request.fault_name = xmFaultName; // 故障名称(同数据字典中的事件名称)
  2675. //request.fault_code = xmFaultCode2; // 故障编码(A,B,C,D,E)
  2676. //request.fault_cmpnt = xmFaultCmpnt; // 故障部件
  2677. //request.fault_desc = xmFaultDesc; // 故障描述
  2678. //request.fault_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 故障发生时间 2022-06-01 14:27:57.283
  2679. // // 上传
  2680. //(int, string) iotResult = XiaomiMqttClient_Extend.Write_FaultLog(request, type1, type2, type3, request.fault_cmpnt, deciveCode);
  2681. }
  2682. catch (Exception ex)
  2683. {
  2684. string str = ex.StackTrace;
  2685. AddMessage_Station(stationNameStr, LogType.Error,
  2686. $"{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" +
  2687. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2688. }
  2689. }
  2690. public void operateToIot(string action, string stationNameStr)
  2691. {
  2692. OperateLogRequest request = new OperateLogRequest();
  2693. request.software_version = "V" + Application.ProductVersion; // 软件版本号;如:V1.2.4
  2694. request.operate_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 操作时间(2022-06-01 14:27:57.283)
  2695. request.operate_action = action; // 操作动作(对应软件开启/关闭/重新加载项⽬;startup、shutdown、reload)
  2696. //request.current_process = Process.GetCurrentProcess()?.Id.ToString(); // 当前进程;进程ID
  2697. request.current_process = Application.ProductName;
  2698. request.operate_desc = stationNameStr; // 操作描述;如:供应商软件开启/关闭/重新加载项⽬
  2699. request.operate_result = "success"; // 操作结果
  2700. request.operator_name = "default"; // 操作账号名;填当前操作⽤⼾,如⽆则填default
  2701. // 上传
  2702. (int, string) iotResult = XiaomiMqttClient_Extend.Write_OperateLog(request);
  2703. if (iotResult.Item1 != 0)
  2704. {
  2705. AddMessage(LogType.Info, "【操作记录】上传失败!错误原因:" + iotResult.Item2 + "操作状态:" + stationNameStr);
  2706. }
  2707. }
  2708. private void 通用节拍接口(int plcNo, string stationNameStr, string tagMesCommName, string CarrierBarcode,
  2709. IoT_DataSet_t iot_data, out int res)
  2710. {
  2711. Stopwatch stopwatch1 = new Stopwatch();
  2712. Stopwatch stopwatch2 = new Stopwatch();
  2713. string resultStr = string.Empty;
  2714. try
  2715. {
  2716. string oEEType = iot_data.beatAction.ToString(); // 节拍类型(plc写入)
  2717. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode); //产品SN
  2718. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  2719. (short, string) result = (0, "");
  2720. // 上传开始节拍
  2721. result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2722. //上传结束节拍
  2723. switch (oEEType)
  2724. {
  2725. case "1":
  2726. Enum.TryParse("2", out deviceOEE);
  2727. result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2728. break;
  2729. case "5":
  2730. Enum.TryParse("6", out deviceOEE);
  2731. result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2732. break;
  2733. }
  2734. if (result.Item1 == 1)
  2735. {
  2736. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]上传成功!");
  2737. //写入PLC
  2738. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2739. iotData.machineState = iot_data.machineState;
  2740. iotData.work_type = iot_data.work_type;
  2741. iotData.testStatus = iot_data.testStatus;
  2742. iotData.beatAction = iot_data.beatAction;
  2743. iotData.beatReturn = 1; //OK
  2744. iotData.fault_codes = iot_data.fault_codes;
  2745. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2746. if (PLCresult.Item1 == 0)
  2747. {
  2748. res = 1;
  2749. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]写入成功!");
  2750. }
  2751. else
  2752. {
  2753. res = 0;
  2754. }
  2755. }
  2756. else
  2757. {
  2758. res = 0;
  2759. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]接口出错!错误信息:" + result.Item2);
  2760. //写入PLC
  2761. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2762. iotData.machineState = iot_data.machineState;
  2763. iotData.work_type = iot_data.work_type;
  2764. iotData.testStatus = iot_data.testStatus;
  2765. iotData.beatAction = iot_data.beatAction;
  2766. iotData.beatReturn = 2; //NG
  2767. iotData.fault_codes = iot_data.fault_codes;
  2768. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2769. }
  2770. }
  2771. catch (Exception ex)
  2772. {
  2773. res = 0;
  2774. string str = ex.StackTrace;
  2775. AddMessage_Station(stationNameStr, LogType.Error,
  2776. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  2777. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2778. //写入PLC
  2779. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2780. iotData.machineState = iot_data.machineState;
  2781. iotData.work_type = iot_data.work_type;
  2782. iotData.testStatus = iot_data.testStatus;
  2783. iotData.beatAction = iot_data.beatAction;
  2784. iotData.beatReturn = 2; //NG
  2785. iotData.fault_codes = iot_data.fault_codes;
  2786. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2787. }
  2788. }
  2789. /// <summary>
  2790. /// 去除常见特殊字符,如 \r, \n, \t 等
  2791. /// </summary>
  2792. /// <param name="format"></param>
  2793. /// <returns></returns>
  2794. private static string FormatStrbyPLC(string format)
  2795. {
  2796. string cleanedString = "";
  2797. if (!string.IsNullOrEmpty(format))
  2798. {
  2799. cleanedString = Regex.Replace(format, @"[\r\n\t]", "");
  2800. }
  2801. return cleanedString;
  2802. }
  2803. #endregion
  2804. #region S1
  2805. /// <summary>
  2806. /// [S1] 壳体清洁上料装备
  2807. /// </summary>
  2808. /// <param name="plcNo">PLC编号</param>
  2809. private void ReadStation_S1(int plcNo)
  2810. {
  2811. string stationCode = "[OP10]";
  2812. string stationName = "壳体清洁上料";
  2813. string stationNameStr = stationCode + stationName;
  2814. string tagBaseName = "g_OP10_MES"; //标签变量名称
  2815. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2816. string tagAgvCommName = "agvCommFrmPC";
  2817. string tagiotComnName = "iotData";
  2818. string tagBarsetName = "BarcodeSet";
  2819. string CarrierBarcode = "";
  2820. string ProductBarcode = "";
  2821. // 触发信号字典
  2822. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2823. s1PLCSignal_Old.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2824. // PLC数据字典 赋值
  2825. s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2826. s1PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  2827. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  2828. (int, string) result;
  2829. while (true)
  2830. {
  2831. try
  2832. {
  2833. if (!GlobalContext._IsCon_Funs1)
  2834. {
  2835. UpdatePLCMonitor(1, plcNo, 0);
  2836. continue;
  2837. }
  2838. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2839. {
  2840. Stopwatch stopwatch1 = new Stopwatch();
  2841. Stopwatch stopwatch2 = new Stopwatch();
  2842. stopwatch1.Start();
  2843. stopwatch2.Start();
  2844. #region 一次性读取所有数据
  2845. // 一次性读取所有数据
  2846. result = FunsEip[plcNo]
  2847. .Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2848. if (result.Item1 != 0)
  2849. {
  2850. //richTextBox1.AppendText("\n" + strRet);
  2851. }
  2852. else
  2853. {
  2854. //richTextBox1.AppendText("\n" + "读取成功");
  2855. stPLC_MesData.BarcodeSet.strProductBarcode =
  2856. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  2857. stPLC_MesData.BarcodeSet.strPartBarcode =
  2858. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  2859. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  2860. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  2861. stPLC_MesData.BarcodeSet.strPCBBarcode =
  2862. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  2863. //设备状态
  2864. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  2865. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  2866. ? XiaomiDeviceState.Unknown
  2867. : (XiaomiDeviceState)xmDeviceStateInt;
  2868. // 载具SN
  2869. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode.ToString();
  2870. // 物料码(物料码还未绑定载具SN时必填)
  2871. ProductBarcode = stPLC_MesData.BarcodeSet.strProductBarcode;
  2872. // 节拍
  2873. s1PLCData["a1OEEType"] = stPLC_MesData.iotData.beatAction;
  2874. //报警信息
  2875. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  2876. }
  2877. #endregion 一次性读取所有数据
  2878. stopwatch2.Stop();
  2879. #region 进站
  2880. try
  2881. {
  2882. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2883. {
  2884. lock (lockObj)
  2885. {
  2886. if (!ProgressState)
  2887. {
  2888. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  2889. ProgressState = true;
  2890. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData,
  2891. tagBaseName + "." + tagMesCommName, out ProgressState));
  2892. }
  2893. }
  2894. }
  2895. }
  2896. catch (Exception ex)
  2897. {
  2898. ProgressState = false;
  2899. string str = ex.StackTrace;
  2900. AddMessage_Station(stationNameStr, LogType.Error,
  2901. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2902. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2903. }
  2904. #endregion 进站
  2905. #region 出站
  2906. try
  2907. {
  2908. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2909. {
  2910. lock (lockObj)
  2911. {
  2912. if (!ProgressState)
  2913. {
  2914. ProgressState = true;
  2915. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData,
  2916. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  2917. out ProgressState));
  2918. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  2919. }
  2920. }
  2921. }
  2922. }
  2923. catch (Exception ex)
  2924. {
  2925. ProgressState = false;
  2926. string str = ex.StackTrace;
  2927. AddMessage_Station(stationNameStr, LogType.Error,
  2928. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2929. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2930. }
  2931. #endregion 出站
  2932. #region 节拍接口
  2933. try
  2934. {
  2935. if (stPLC_MesData.iotData.beatAction > 0)
  2936. {
  2937. int a1OEEType = Convert.ToInt32(s1PLCData["a1OEEType"]);
  2938. int a1OEETypeGOld = Convert.ToInt32(s1PLCSignal_Old["a1OEEType"]);
  2939. if (a1OEEType != a1OEETypeGOld)
  2940. {
  2941. s1PLCData["OEETypeFlag"] = "1";
  2942. }
  2943. else
  2944. {
  2945. s1PLCData["OEETypeFlag"] = "0";
  2946. }
  2947. if (s1PLCData["OEETypeFlag"].ToString() == "1" && (a1OEEType == 1 || a1OEEType == 3 || a1OEEType == 4 || a1OEEType == 5))
  2948. {
  2949. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  2950. if (res == 1)
  2951. {
  2952. s1PLCSignal_Old["a1OEEType"] = s1PLCData["a1OEEType"];
  2953. }
  2954. else {
  2955. s1PLCSignal_Old["a1OEEType"] = 0;
  2956. }
  2957. }
  2958. }
  2959. else {
  2960. s1PLCSignal_Old["a1OEEType"] = 0;
  2961. }
  2962. }
  2963. catch (Exception ex)
  2964. {
  2965. string str = ex.StackTrace;
  2966. AddMessage_Station(stationNameStr, LogType.Error,
  2967. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  2968. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2969. }
  2970. #endregion
  2971. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2972. stopwatch1.Stop();
  2973. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2974. }
  2975. else
  2976. {
  2977. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2978. AddMessage_Station(stationNameStr, LogType.Info,
  2979. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2980. FunsEip[plcNo].Connect(); // 重连
  2981. }
  2982. }
  2983. catch (Exception ex)
  2984. {
  2985. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2986. AddMessage_Station(stationNameStr, LogType.Error,
  2987. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2988. }
  2989. Thread.Sleep(IntervalReadPLC);
  2990. }
  2991. }
  2992. /// <summary>
  2993. /// [S1] 壳体清洁上料 - 进站
  2994. /// </summary>
  2995. /// <param name="plcNo">PLC编号</param>
  2996. /// <param name="stationNameStr">工站全称</param>
  2997. /// <param name="stPLC_MesData"></param>
  2998. /// <param name="tagMesCommName"></param>
  2999. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  3000. out bool ProgressState)
  3001. {
  3002. Stopwatch stopwatch1 = new Stopwatch();
  3003. Stopwatch stopwatch2 = new Stopwatch();
  3004. try
  3005. {
  3006. stopwatch1.Start();
  3007. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3008. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  3009. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3010. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  3011. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  3012. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3013. bool pass = a1Result == 1;
  3014. if (string.IsNullOrEmpty(sn))
  3015. {
  3016. ProgressState = false;
  3017. AddMessage(LogType.Error, $"{stationNameStr}_未能查到产品码");
  3018. Thread.Sleep(10000);
  3019. return;
  3020. }
  3021. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  3022. // sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  3023. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3024. //绑定载具和产品
  3025. ResponseMessage message = new ResponseMessage();
  3026. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  3027. if (message.result == false)
  3028. {
  3029. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  3030. ProgressState = false;
  3031. Thread.Sleep(10000);
  3032. return;
  3033. }
  3034. // 产品SN进站
  3035. List<TestItem> item = new List<TestItem>();
  3036. stopwatch2.Start();
  3037. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3038. item, MachineId, StationId, pass, "01-SLOT-01");
  3039. stopwatch2.Stop();
  3040. //指令执行结果 1:OK 110:失败
  3041. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3042. if (mesResultFrmWeb == 1)
  3043. {
  3044. if (a1Result == 1)
  3045. {
  3046. mesResultFrmWeb = 1;
  3047. }
  3048. else
  3049. {
  3050. mesResultFrmWeb = 110;
  3051. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3052. }
  3053. }
  3054. //进站结果写入PLC
  3055. CommandFromPLC resultToPlC = new CommandFromPLC();
  3056. resultToPlC.cmd = 0;
  3057. resultToPlC.cmdParam = 0;
  3058. resultToPlC.cmdResult = mesResultFrmWeb;
  3059. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3060. }
  3061. catch (Exception ex)
  3062. {
  3063. string str = ex.StackTrace;
  3064. AddMessage(LogType.Error,
  3065. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3066. str.Length - str.LastIndexOf("\\") - 1));
  3067. CommandFromPLC resultToPlC = new CommandFromPLC();
  3068. resultToPlC.cmd = 0;
  3069. resultToPlC.cmdParam = 0; //指令参数
  3070. resultToPlC.cmdResult = 110;
  3071. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3072. }
  3073. stopwatch1.Stop();
  3074. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3075. AddMessage(LogType.Info,
  3076. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3077. stopwatch2.ElapsedMilliseconds + "ms");
  3078. ProgressState = false;
  3079. }
  3080. /// <summary>
  3081. /// [S1] 壳体清洁上料 - 出站接口
  3082. /// </summary>
  3083. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  3084. string stationCode, string stationName, out bool ProgressState)
  3085. {
  3086. Stopwatch stopwatch1 = new Stopwatch();
  3087. Stopwatch stopwatch2 = new Stopwatch();
  3088. try
  3089. {
  3090. stopwatch1.Start();
  3091. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3092. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3093. string processItem = stationName; // 项目
  3094. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3095. string supplierCode = ""; // 供应商代码
  3096. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  3097. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  3098. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  3099. string sn = string.Empty;
  3100. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3101. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  3102. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  3103. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3104. //a1Result = 1;
  3105. bool pass = a1Result == 1;
  3106. //根据载具码获取产品码
  3107. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3108. if (string.IsNullOrEmpty(strProductBarcode))
  3109. {
  3110. ProgressState = false;
  3111. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3112. Thread.Sleep(10000);
  3113. return;
  3114. }
  3115. sn = strProductBarcode;
  3116. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3117. List<TestItem> items = new List<TestItem>();
  3118. items.Add(new TestItem()
  3119. {
  3120. Parameter_name = "载具码",
  3121. Parameter_value = CarrierBarcode,
  3122. Parameter_unit = ""
  3123. });
  3124. items.Add(new TestItem()
  3125. {
  3126. Parameter_name = "产品码",
  3127. Parameter_value = sn,
  3128. Parameter_unit = ""
  3129. });
  3130. #region 转换过站明细字符串
  3131. //创建字典
  3132. var dic = new Dictionary<string, string>();
  3133. // 获取结构体类型
  3134. FieldInfo[] fields = typeof(OP10_DataSet_t).GetFields();
  3135. // 遍历变量名转换成字典描述
  3136. foreach (FieldInfo field in fields)
  3137. {
  3138. //获取枚举描述
  3139. string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
  3140. typeof(XiaomiMESEnum_ProcessData.Enum_10_ProcessData));
  3141. //获取过站明细的值
  3142. object valueObj = field.GetValue(stPLC_MesData.mesData);
  3143. dic.Add(name, valueObj.ToString());
  3144. }
  3145. string paramJson = JsonConvert.SerializeObject(dic);
  3146. #endregion
  3147. //出站接口
  3148. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3149. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  3150. MachineId, StationId, "", paramJson);
  3151. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3152. if (mesResultFrmWeb == 1)
  3153. {
  3154. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3155. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  3156. }
  3157. stopwatch2.Start();
  3158. //进站结果写入PLC
  3159. CommandFromPLC resultToPlC = new CommandFromPLC();
  3160. resultToPlC.cmd = 0;
  3161. resultToPlC.cmdParam = 0; //指令参数
  3162. resultToPlC.cmdResult = mesResultFrmWeb;
  3163. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3164. stopwatch2.Stop();
  3165. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3166. //保存PLC返回MES数据到本地
  3167. ResponseMessage message = new ResponseMessage();
  3168. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  3169. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress,
  3170. stPLC_MesData.mesData.fCleanSpeed,
  3171. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime,
  3172. stPLC_MesData.mesData.nCleanCount,
  3173. stPLC_MesData.mesData.nRemainCount);
  3174. if (message.result == false)
  3175. {
  3176. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3177. }
  3178. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  3179. }
  3180. catch (Exception ex)
  3181. {
  3182. stopwatch2.Start();
  3183. CommandFromPLC resultToPlC = new CommandFromPLC();
  3184. resultToPlC.cmd = 0;
  3185. resultToPlC.cmdParam = 0; //指令参数
  3186. resultToPlC.cmdResult = 110;
  3187. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3188. stopwatch2.Stop();
  3189. string str = ex.StackTrace;
  3190. AddMessage(LogType.Error,
  3191. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3192. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3193. }
  3194. stopwatch1.Stop();
  3195. AddMessage(LogType.Info,
  3196. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3197. stopwatch2.ElapsedMilliseconds + "ms");
  3198. ProgressState = false;
  3199. uuid = "";
  3200. }
  3201. #endregion
  3202. #region S2
  3203. /// <summary>
  3204. /// [S2] 上盖板上料装备
  3205. /// </summary>
  3206. /// <param name="plcNo">PLC编号</param>
  3207. private void ReadStation_S2(int plcNo)
  3208. {
  3209. string stationCode = "[OP20]";
  3210. string stationName = "上盖板上料装备";
  3211. string stationNameStr = stationCode + stationName;
  3212. string tagBaseName = "g_OP20_MES"; //标签变量名称
  3213. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3214. string tagAgvCommName = "agvCommFrmPC";
  3215. string tagiotComnName = "iotData";
  3216. string tagBarsetName = "BarcodeSet";
  3217. string CarrierBarcode = "";
  3218. // 触发信号字典
  3219. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  3220. s2PLCSignal_Old.Add("a2OEEType", 0); // 节拍类型(plc写入)
  3221. // PLC数据字典 赋值
  3222. s2PLCData.Add("a2OEEType", 0); // 节拍类型(plc写入)
  3223. s2PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  3224. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  3225. (int, string) result;
  3226. while (true)
  3227. {
  3228. try
  3229. {
  3230. if (!GlobalContext._IsCon_Funs2)
  3231. {
  3232. UpdatePLCMonitor(1, plcNo, 0);
  3233. continue;
  3234. }
  3235. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3236. {
  3237. Stopwatch stopwatch1 = new Stopwatch();
  3238. Stopwatch stopwatch2 = new Stopwatch();
  3239. stopwatch1.Start();
  3240. stopwatch2.Start();
  3241. #region 一次性读取所有数据
  3242. // 一次性读取所有数据
  3243. result = FunsEip[plcNo]
  3244. .Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3245. if (result.Item1 != 0)
  3246. {
  3247. //richTextBox1.AppendText("\n" + strRet);
  3248. }
  3249. else
  3250. {
  3251. //richTextBox1.AppendText("\n" + "读取成功");
  3252. stPLC_MesData.BarcodeSet.strProductBarcode =
  3253. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  3254. stPLC_MesData.BarcodeSet.strPartBarcode =
  3255. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  3256. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  3257. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  3258. stPLC_MesData.BarcodeSet.strPCBBarcode =
  3259. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  3260. //设备状态
  3261. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  3262. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  3263. ? XiaomiDeviceState.Unknown
  3264. : (XiaomiDeviceState)xmDeviceStateInt;
  3265. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  3266. s2PLCData["a2OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  3267. //报警信息
  3268. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  3269. }
  3270. #endregion 一次性读取所有数据
  3271. stopwatch2.Stop();
  3272. #region 进站
  3273. try
  3274. {
  3275. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3276. {
  3277. lock (lockObj)
  3278. {
  3279. if (!ProgressState)
  3280. {
  3281. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3282. ProgressState = true;
  3283. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData,
  3284. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  3285. out ProgressState));
  3286. }
  3287. }
  3288. }
  3289. }
  3290. catch (Exception ex)
  3291. {
  3292. ProgressState = false;
  3293. string str = ex.StackTrace;
  3294. AddMessage_Station(stationNameStr, LogType.Error,
  3295. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3296. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3297. }
  3298. #endregion 进站
  3299. #region 出站
  3300. try
  3301. {
  3302. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3303. {
  3304. lock (lockObj)
  3305. {
  3306. if (!ProgressState)
  3307. {
  3308. ProgressState = true;
  3309. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData,
  3310. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  3311. out ProgressState));
  3312. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  3313. }
  3314. }
  3315. }
  3316. }
  3317. catch (Exception ex)
  3318. {
  3319. ProgressState = false;
  3320. string str = ex.StackTrace;
  3321. AddMessage_Station(stationNameStr, LogType.Error,
  3322. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3323. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3324. }
  3325. #endregion 出站
  3326. #region 节拍接口
  3327. try
  3328. {
  3329. if (stPLC_MesData.iotData.beatAction > 0)
  3330. {
  3331. int a2OEEType = Convert.ToInt32(s2PLCData["a2OEEType"]);
  3332. int a2OEETypeGOld = Convert.ToInt32(s2PLCSignal_Old["a2OEEType"]);
  3333. if (a2OEEType != a2OEETypeGOld)
  3334. {
  3335. s2PLCData["OEETypeFlag"] = "1";
  3336. }
  3337. else
  3338. {
  3339. s2PLCData["OEETypeFlag"] = "0";
  3340. }
  3341. if (s2PLCData["OEETypeFlag"].ToString() == "1" && (a2OEEType == 1 || a2OEEType == 3 || a2OEEType == 4 || a2OEEType == 5))
  3342. {
  3343. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  3344. if (res == 1)
  3345. {
  3346. s2PLCSignal_Old["a2OEEType"] = s2PLCData["a2OEEType"];
  3347. }
  3348. else
  3349. {
  3350. s2PLCSignal_Old["a2OEEType"] = 0;
  3351. }
  3352. }
  3353. }
  3354. else {
  3355. s2PLCSignal_Old["a2OEEType"] = 0;
  3356. }
  3357. }
  3358. catch (Exception ex)
  3359. {
  3360. string str = ex.StackTrace;
  3361. AddMessage_Station(stationNameStr, LogType.Error,
  3362. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3363. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3364. }
  3365. #endregion
  3366. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3367. stopwatch1.Stop();
  3368. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  3369. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3370. }
  3371. else
  3372. {
  3373. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3374. AddMessage_Station(stationNameStr, LogType.Info,
  3375. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3376. FunsEip[plcNo].Connect();
  3377. }
  3378. }
  3379. catch (Exception ex)
  3380. {
  3381. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3382. AddMessage_Station(stationNameStr, LogType.Error,
  3383. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3384. //Funs[plcNo].ReConnect();
  3385. }
  3386. Thread.Sleep(IntervalReadPLC);
  3387. }
  3388. }
  3389. /// <summary>
  3390. /// [S2] 上盖板上料装备
  3391. /// </summary>
  3392. /// <param name="plcNo">PLC编号</param>
  3393. /// <param name="stationNameStr">工站全称</param>
  3394. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  3395. string tagBarsetName, out bool ProgressState)
  3396. {
  3397. Stopwatch stopwatch1 = new Stopwatch();
  3398. Stopwatch stopwatch2 = new Stopwatch();
  3399. try
  3400. {
  3401. stopwatch1.Start();
  3402. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3403. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  3404. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  3405. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3406. bool pass = a1Result == 1;
  3407. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  3408. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  3409. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3410. //根据载具码获取产品码
  3411. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3412. if (string.IsNullOrEmpty(strProductBarcode))
  3413. {
  3414. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3415. ProgressState = false;
  3416. Thread.Sleep(10000);
  3417. return;
  3418. }
  3419. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  3420. //if (sn != strProductBarcode)
  3421. //{
  3422. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  3423. //}
  3424. sn = strProductBarcode;
  3425. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3426. // 产品SN(物料码)校验
  3427. List<TestItem> item = new List<TestItem>();
  3428. stopwatch2.Start();
  3429. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3430. item, MachineId, StationId, pass, "01-SLOT-01");
  3431. stopwatch2.Stop();
  3432. //指令执行结果 1:OK 110:失败
  3433. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3434. if (mesResultFrmWeb == 1)
  3435. {
  3436. if (a1Result == 1)
  3437. {
  3438. mesResultFrmWeb = 1;
  3439. }
  3440. else
  3441. {
  3442. mesResultFrmWeb = 110;
  3443. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3444. }
  3445. }
  3446. //进站结果写入PLC
  3447. CommandFromPLC resultToPlC = new CommandFromPLC();
  3448. resultToPlC.cmd = 0;
  3449. resultToPlC.cmdParam = 0; //指令参数
  3450. resultToPlC.cmdResult = mesResultFrmWeb;
  3451. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3452. }
  3453. catch (Exception ex)
  3454. {
  3455. string str = ex.StackTrace;
  3456. AddMessage(LogType.Error,
  3457. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3458. str.Length - str.LastIndexOf("\\") - 1));
  3459. CommandFromPLC resultToPlC = new CommandFromPLC();
  3460. resultToPlC.cmd = 0;
  3461. resultToPlC.cmdParam = 0; //指令参数
  3462. resultToPlC.cmdResult = 110;
  3463. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3464. }
  3465. stopwatch1.Stop();
  3466. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3467. AddMessage(LogType.Info,
  3468. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3469. stopwatch2.ElapsedMilliseconds + "ms");
  3470. ProgressState = false;
  3471. }
  3472. /// <summary>
  3473. /// [S2] 上盖板上料装备 - 出站接口
  3474. /// </summary>
  3475. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  3476. string stationCode, string stationName, out bool ProgressState)
  3477. {
  3478. Stopwatch stopwatch1 = new Stopwatch();
  3479. Stopwatch stopwatch2 = new Stopwatch();
  3480. try
  3481. {
  3482. stopwatch1.Start();
  3483. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3484. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3485. string processItem = stationName; // 测试项目
  3486. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3487. string supplierCode = ""; // 供应商代码
  3488. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3489. string batch_num = GlobalContext.BatchNumber; // 批次号
  3490. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3491. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3492. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3493. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  3494. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  3495. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  3496. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3497. bool pass = a1Result == 1;
  3498. //根据载具码获取产品码
  3499. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3500. if (string.IsNullOrEmpty(strProductBarcode))
  3501. {
  3502. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3503. ProgressState = false;
  3504. Thread.Sleep(10000);
  3505. return;
  3506. }
  3507. sn = strProductBarcode;
  3508. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3509. List<TestItem> items = new List<TestItem>();
  3510. items.Add(new TestItem()
  3511. {
  3512. Parameter_name = "载具码",
  3513. Parameter_value = CarrierBarcode,
  3514. Parameter_unit = ""
  3515. });
  3516. items.Add(new TestItem()
  3517. {
  3518. Parameter_name = "产品码",
  3519. Parameter_value = sn,
  3520. Parameter_unit = ""
  3521. });
  3522. items.Add(new TestItem()
  3523. {
  3524. Parameter_name = "部件码",
  3525. Parameter_value = PartBarcode,
  3526. Parameter_unit = ""
  3527. });
  3528. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3529. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3530. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  3531. MachineId, StationId, PartBarcode, paramJson);
  3532. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3533. if (mesResultFrmWeb == 1)
  3534. {
  3535. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3536. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  3537. }
  3538. stopwatch2.Start();
  3539. //进站结果写入PLC
  3540. CommandFromPLC resultToPlC = new CommandFromPLC();
  3541. resultToPlC.cmd = 0;
  3542. resultToPlC.cmdParam = 0; //指令参数
  3543. resultToPlC.cmdResult = mesResultFrmWeb;
  3544. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3545. stopwatch2.Stop();
  3546. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3547. //保存PLC返回MES数据到本地
  3548. ResponseMessage message = new ResponseMessage();
  3549. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  3550. stPLC_MesData.mesData.nRemainCount);
  3551. if (message.result == false)
  3552. {
  3553. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3554. }
  3555. if (!string.IsNullOrEmpty(PartBarcode))
  3556. {
  3557. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  3558. if (message.result == false)
  3559. {
  3560. AddMessage(LogType.Error, message.text);
  3561. }
  3562. }
  3563. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3564. }
  3565. catch (Exception ex)
  3566. {
  3567. stopwatch2.Start();
  3568. CommandFromPLC resultToPlC = new CommandFromPLC();
  3569. resultToPlC.cmd = 0;
  3570. resultToPlC.cmdParam = 0; //指令参数
  3571. resultToPlC.cmdResult = 110;
  3572. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3573. stopwatch2.Stop();
  3574. string str = ex.StackTrace;
  3575. AddMessage(LogType.Error,
  3576. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3577. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3578. }
  3579. stopwatch1.Stop();
  3580. AddMessage(LogType.Info,
  3581. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3582. stopwatch2.ElapsedMilliseconds + "ms");
  3583. ProgressState = false;
  3584. uuid = "";
  3585. }
  3586. #endregion
  3587. #region S3
  3588. /// <summary>
  3589. /// [S3] 点散热胶装备
  3590. /// </summary>
  3591. /// <param name="plcNo">PLC编号</param>
  3592. private void ReadStation_S3(int plcNo)
  3593. {
  3594. string stationCode = "[OP30]";
  3595. string stationName = "点散热胶装备";
  3596. string stationNameStr = stationCode + stationName;
  3597. string tagBaseName = "g_OP30_MES"; //标签变量名称
  3598. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3599. string tagAgvCommName = "agvCommFrmPC";
  3600. string tagiotComnName = "iotData";
  3601. string tagBarsetName = "BarcodeSet";
  3602. string CarrierBarcode_Left = "";
  3603. string CarrierBarcode_Right = "";
  3604. s3PLCSignal_Old.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
  3605. s3PLCSignal_Old.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
  3606. // PLC数据字典 赋值
  3607. s3PLCData.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
  3608. s3PLCData.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
  3609. s5PLCData.Add("OEETypeFlag_left", 0); // 节拍标识 0 不上传 ,1 上传
  3610. s5PLCData.Add("OEETypeFlag_right", 0); // 节拍标识 0 不上传 ,1 上传
  3611. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  3612. (int, string) result;
  3613. while (true)
  3614. {
  3615. try
  3616. {
  3617. if (!GlobalContext._IsCon_Funs2)
  3618. {
  3619. UpdatePLCMonitor(1, plcNo, 0);
  3620. continue;
  3621. }
  3622. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3623. {
  3624. Stopwatch stopwatch1 = new Stopwatch();
  3625. Stopwatch stopwatch2 = new Stopwatch();
  3626. stopwatch1.Start();
  3627. stopwatch2.Start();
  3628. #region 一次性读取所有数据
  3629. // 一次性读取所有数据
  3630. result = FunsEip[plcNo]
  3631. .Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3632. if (result.Item1 != 0)
  3633. {
  3634. //richTextBox1.AppendText("\n" + strRet);
  3635. }
  3636. else
  3637. {
  3638. //测试数据
  3639. //stPLC_MesData.Left.mesCommFrmPLC.cmd = 2;
  3640. //stPLC_MesData.Left.BarcodeSet.strCarrierBarcode = "A123456";
  3641. //stPLC_MesData.Left.BarcodeSet.strPCBBarcode = "A1507V000239";
  3642. //stPLC_MesData.Left.iotData.beatAction = 1;
  3643. //stPLC_MesData.Left.iotData.beatAction = 2;
  3644. //stPLC_MesData.Left.BarcodeSet.strCarrierBarcode = "A123456";
  3645. #region 去除扫码产生的特殊字符
  3646. stPLC_MesData.Left.BarcodeSet.strProductBarcode =
  3647. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strProductBarcode);
  3648. stPLC_MesData.Left.BarcodeSet.strPartBarcode =
  3649. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPartBarcode);
  3650. stPLC_MesData.Left.BarcodeSet.strCarrierBarcode =
  3651. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strCarrierBarcode);
  3652. stPLC_MesData.Left.BarcodeSet.strPCBBarcode =
  3653. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPCBBarcode);
  3654. stPLC_MesData.Right.BarcodeSet.strProductBarcode =
  3655. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strProductBarcode);
  3656. stPLC_MesData.Right.BarcodeSet.strPartBarcode =
  3657. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPartBarcode);
  3658. stPLC_MesData.Right.BarcodeSet.strCarrierBarcode =
  3659. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strCarrierBarcode);
  3660. stPLC_MesData.Right.BarcodeSet.strPCBBarcode =
  3661. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPCBBarcode);
  3662. #endregion
  3663. //richTextBox1.AppendText("\n" + "读取成功");
  3664. //设备状态
  3665. int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  3666. int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  3667. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  3668. ? XiaomiDeviceState.Unknown
  3669. : (XiaomiDeviceState)xmDeviceStateInt_L;
  3670. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  3671. ? XiaomiDeviceState.Unknown
  3672. : (XiaomiDeviceState)xmDeviceStateInt_R;
  3673. //载具SN
  3674. CarrierBarcode_Left = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode;
  3675. CarrierBarcode_Right = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode;
  3676. // 节拍
  3677. s3PLCData["a3OEEType_left"] = stPLC_MesData.Left.iotData.beatAction;
  3678. s3PLCData["a3OEEType_right"] = stPLC_MesData.Right.iotData.beatAction;
  3679. //报警信息
  3680. _FaultDatas = stPLC_MesData.Left.iotData.fault_codes;
  3681. _FaultDatas2 = stPLC_MesData.Right.iotData.fault_codes;
  3682. //_FaultDatas = new uint[] { 2, 0, 16, 0, 0, 0, 0, 0, 0, 0 };
  3683. //_FaultDatas2 = new uint[] { 2, 0, 16, 0, 0, 0, 0, 0, 0, 0 };
  3684. }
  3685. #endregion 一次性读取所有数据
  3686. stopwatch2.Stop();
  3687. #region 左边进站
  3688. try
  3689. {
  3690. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3691. {
  3692. lock (lockObj)
  3693. {
  3694. if (!ProgressState)
  3695. {
  3696. stationCode = "[OP31]";
  3697. stationName = "点散热胶装备1";
  3698. stationNameStr = stationCode + stationName;
  3699. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3700. ProgressState = true;
  3701. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left,
  3702. tagBaseName + ".Left." + tagMesCommName,
  3703. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  3704. }
  3705. }
  3706. }
  3707. }
  3708. catch (Exception ex)
  3709. {
  3710. ProgressState = false;
  3711. string str = ex.StackTrace;
  3712. AddMessage_Station(stationNameStr, LogType.Error,
  3713. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3714. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3715. }
  3716. #endregion 左边进站
  3717. #region 左边出站
  3718. try
  3719. {
  3720. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3721. {
  3722. lock (lockObj)
  3723. {
  3724. if (!ProgressState)
  3725. {
  3726. stationCode = "[OP31]";
  3727. stationName = "点散热胶装备1";
  3728. stationNameStr = stationCode + stationName;
  3729. ProgressState = true;
  3730. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left,
  3731. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  3732. out ProgressState));
  3733. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  3734. }
  3735. }
  3736. }
  3737. }
  3738. catch (Exception ex)
  3739. {
  3740. ProgressState = false;
  3741. string str = ex.StackTrace;
  3742. AddMessage_Station(stationNameStr, LogType.Error,
  3743. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3744. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3745. }
  3746. #endregion 左边出站
  3747. #region 右边进站
  3748. try
  3749. {
  3750. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3751. {
  3752. lock (lockObj)
  3753. {
  3754. if (!ProgressState)
  3755. {
  3756. uuid2 = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3757. stationCode = "[OP32]";
  3758. stationName = "点散热胶装备2";
  3759. stationNameStr = stationCode + stationName;
  3760. ProgressState = true;
  3761. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right,
  3762. tagBaseName + ".Right." + tagMesCommName,
  3763. tagBaseName + ".Right." + tagBarsetName, "Right", out ProgressState));
  3764. }
  3765. }
  3766. }
  3767. }
  3768. catch (Exception ex)
  3769. {
  3770. ProgressState = false;
  3771. string str = ex.StackTrace;
  3772. AddMessage_Station(stationNameStr, LogType.Error,
  3773. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3774. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3775. }
  3776. #endregion 右边进站
  3777. #region 右边出站
  3778. try
  3779. {
  3780. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3781. {
  3782. lock (lockObj)
  3783. {
  3784. if (!ProgressState)
  3785. {
  3786. stationCode = "[OP32]";
  3787. stationName = "点散热胶装备2";
  3788. stationNameStr = stationCode + stationName;
  3789. ProgressState = true;
  3790. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right,
  3791. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  3792. out ProgressState));
  3793. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  3794. }
  3795. }
  3796. }
  3797. }
  3798. catch (Exception ex)
  3799. {
  3800. string str = ex.StackTrace;
  3801. AddMessage_Station(stationNameStr, LogType.Error,
  3802. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3803. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3804. }
  3805. #endregion 右边出站
  3806. #region 节拍接口
  3807. try
  3808. {
  3809. #region 左工位 节拍
  3810. if (stPLC_MesData.Left.iotData.beatAction > 0)
  3811. {
  3812. stationCode = "[OP31]";
  3813. stationName = "点散热胶装备1";
  3814. stationNameStr = stationCode + stationName;
  3815. int a3OEEType_left = Convert.ToInt32(s3PLCData["a3OEEType_left"]);
  3816. int a3OEETypeGOld_left = Convert.ToInt32(s3PLCSignal_Old["a3OEEType_left"]);
  3817. if (a3OEEType_left != a3OEETypeGOld_left)
  3818. {
  3819. s3PLCData["OEETypeFlag_left"] = "1";
  3820. }
  3821. else
  3822. {
  3823. s3PLCData["OEETypeFlag_left"] = "0";
  3824. }
  3825. if (s3PLCData["OEETypeFlag_left"].ToString() == "1" && (a3OEEType_left == 1 || a3OEEType_left == 3 || a3OEEType_left == 4 || a3OEEType_left == 5))
  3826. {
  3827. 通用节拍接口(plcNo, stationNameStr,
  3828. tagBaseName + ".Left." + tagiotComnName, CarrierBarcode_Left,
  3829. stPLC_MesData.Left.iotData, out res);
  3830. if (res == 1)
  3831. {
  3832. s3PLCSignal_Old["a3OEEType_left"] = a3OEEType_left;
  3833. }
  3834. else {
  3835. s3PLCSignal_Old["a3OEEType_left"] = 0;
  3836. }
  3837. }
  3838. }
  3839. else
  3840. {
  3841. s3PLCSignal_Old["a3OEEType_left"] = 0;
  3842. }
  3843. #endregion 左工位 节拍
  3844. #region 右工位 节拍
  3845. if (stPLC_MesData.Right.iotData.beatAction > 0)
  3846. {
  3847. stationCode = "[OP32]";
  3848. stationName = "点散热胶装备2";
  3849. stationNameStr = stationCode + stationName;
  3850. int a3OEEType_right = Convert.ToInt32(s3PLCData["a3OEEType_right"]);
  3851. int a3OEETypeGOld_right = Convert.ToInt32(s3PLCSignal_Old["a3OEEType_right"]);
  3852. if (a3OEEType_right != a3OEETypeGOld_right)
  3853. {
  3854. s3PLCData["OEETypeFlag_right"] = "1";
  3855. }
  3856. else
  3857. {
  3858. s3PLCData["OEETypeFlag_right"] = "0";
  3859. }
  3860. if (s3PLCData["OEETypeFlag_right"].ToString() == "1" && (a3OEEType_right == 1 || a3OEEType_right == 3 || a3OEEType_right == 4 || a3OEEType_right == 5))
  3861. {
  3862. 通用节拍接口(plcNo, stationNameStr,
  3863. tagBaseName + ".Right." + tagiotComnName, CarrierBarcode_Right,
  3864. stPLC_MesData.Right.iotData, out res);
  3865. if (res == 1)
  3866. {
  3867. s3PLCSignal_Old["a3OEEType_right"] = a3OEEType_right;
  3868. }
  3869. else {
  3870. s3PLCSignal_Old["a3OEEType_right"] = 0;
  3871. }
  3872. }
  3873. }
  3874. else
  3875. {
  3876. s3PLCSignal_Old["a3OEEType_right"] = 0;
  3877. }
  3878. #endregion 右工位 节拍
  3879. }
  3880. catch (Exception ex)
  3881. {
  3882. string str = ex.StackTrace;
  3883. AddMessage_Station(stationNameStr, LogType.Error,
  3884. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3885. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3886. }
  3887. #endregion
  3888. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3889. stopwatch1.Stop();
  3890. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  3891. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3892. }
  3893. else
  3894. {
  3895. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3896. AddMessage_Station(stationNameStr, LogType.Info,
  3897. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3898. FunsEip[plcNo].Connect();
  3899. }
  3900. }
  3901. catch (Exception ex)
  3902. {
  3903. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3904. AddMessage_Station(stationNameStr, LogType.Error,
  3905. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3906. //Funs[plcNo].ReConnect();
  3907. }
  3908. Thread.Sleep(IntervalReadPLC);
  3909. }
  3910. }
  3911. /// <summary>
  3912. /// [S3] 点散热胶装备 - 进站
  3913. /// </summary>
  3914. /// <param name="plcNo">PLC编号</param>
  3915. /// <param name="stationNameStr">工站全称</param>
  3916. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  3917. string tagBarsetName, string direction, out bool ProgressState)
  3918. {
  3919. Stopwatch stopwatch1 = new Stopwatch();
  3920. Stopwatch stopwatch2 = new Stopwatch();
  3921. try
  3922. {
  3923. stopwatch1.Start();
  3924. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  3925. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3926. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  3927. string StationId = string.Empty;
  3928. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3929. bool pass = a1Result == 1;
  3930. string slot = "";
  3931. if (direction == "Left")
  3932. {
  3933. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  3934. slot = "01-SLOT-01";
  3935. }
  3936. if (direction == "Right")
  3937. {
  3938. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  3939. slot = "01-SLOT-02";
  3940. }
  3941. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3942. //载具码验证产品码
  3943. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3944. if (string.IsNullOrEmpty(strProductBarcode))
  3945. {
  3946. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3947. ProgressState = false;
  3948. Thread.Sleep(10000);
  3949. return;
  3950. }
  3951. sn = strProductBarcode;
  3952. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  3953. // 产品SN(物料码)校验
  3954. List<TestItem> item = new List<TestItem>();
  3955. stopwatch2.Start();
  3956. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3957. item, MachineId, StationId, pass, slot);
  3958. stopwatch2.Stop();
  3959. //指令执行结果 1:OK 110:失败
  3960. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3961. if (mesResultFrmWeb == 1)
  3962. {
  3963. if (a1Result == 1)
  3964. {
  3965. mesResultFrmWeb = 1;
  3966. }
  3967. else
  3968. {
  3969. mesResultFrmWeb = 110;
  3970. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3971. }
  3972. }
  3973. //进站结果写入PLC
  3974. CommandFromPLC resultToPlC = new CommandFromPLC();
  3975. resultToPlC.cmd = 0;
  3976. resultToPlC.cmdParam = 0; //指令参数
  3977. resultToPlC.cmdResult = mesResultFrmWeb;
  3978. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3979. }
  3980. catch (Exception ex)
  3981. {
  3982. string str = ex.StackTrace;
  3983. AddMessage(LogType.Error,
  3984. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3985. str.Length - str.LastIndexOf("\\") - 1));
  3986. CommandFromPLC resultToPlC = new CommandFromPLC();
  3987. resultToPlC.cmd = 0;
  3988. resultToPlC.cmdParam = 0; //指令参数
  3989. resultToPlC.cmdResult = 110;
  3990. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3991. }
  3992. stopwatch1.Stop();
  3993. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3994. AddMessage(LogType.Info,
  3995. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3996. stopwatch2.ElapsedMilliseconds + "ms");
  3997. ProgressState = false;
  3998. }
  3999. /// <summary>
  4000. /// [S3] 点散热胶装备 - 出站
  4001. /// </summary>
  4002. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  4003. string stationCode, string stationName, string direction, out bool ProgressState)
  4004. {
  4005. Stopwatch stopwatch1 = new Stopwatch();
  4006. Stopwatch stopwatch2 = new Stopwatch();
  4007. try
  4008. {
  4009. stopwatch1.Start();
  4010. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  4011. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4012. string processItem = stationName; // 测试项目
  4013. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4014. string supplierCode = ""; // 供应商代码
  4015. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4016. string batch_num = GlobalContext.BatchNumber; // 批次号
  4017. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4018. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4019. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4020. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  4021. string StationId = string.Empty;
  4022. if (direction == "Left")
  4023. {
  4024. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  4025. }
  4026. if (direction == "Right")
  4027. {
  4028. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  4029. }
  4030. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4031. bool pass = a1Result == 1;
  4032. //根据载具码获取产品码
  4033. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4034. if (string.IsNullOrEmpty(strProductBarcode))
  4035. {
  4036. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4037. ProgressState = false;
  4038. Thread.Sleep(10000);
  4039. return;
  4040. }
  4041. Console.WriteLine($"异常1:{strProductBarcode}");
  4042. sn = strProductBarcode;
  4043. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4044. List<TestItem> items = new List<TestItem>();
  4045. items.Add(new TestItem()
  4046. {
  4047. Parameter_name = "载具码",
  4048. Parameter_value = CarrierBarcode,
  4049. Parameter_unit = ""
  4050. });
  4051. items.Add(new TestItem()
  4052. {
  4053. Parameter_name = "产品码",
  4054. Parameter_value = sn,
  4055. Parameter_unit = ""
  4056. });
  4057. //if (direction == "Right")
  4058. //{
  4059. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData).Replace("null","0");
  4060. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4061. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  4062. MachineId, StationId, "", paramJson, direction);
  4063. //}
  4064. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4065. if (mesResultFrmWeb == 1)
  4066. {
  4067. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  4068. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  4069. }
  4070. stopwatch2.Start();
  4071. //进站结果写入PLC
  4072. CommandFromPLC resultToPlC = new CommandFromPLC();
  4073. resultToPlC.cmd = 0;
  4074. resultToPlC.cmdParam = 0; //指令参数
  4075. resultToPlC.cmdResult = mesResultFrmWeb;
  4076. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4077. stopwatch2.Stop();
  4078. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  4079. //保存PLC返回MES数据到本地
  4080. ResponseMessage message = new ResponseMessage();
  4081. if (direction == "Left")
  4082. {
  4083. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  4084. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  4085. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  4086. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  4087. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  4088. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  4089. if (message.result == false)
  4090. {
  4091. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4092. }
  4093. }
  4094. if (direction == "Right")
  4095. {
  4096. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  4097. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  4098. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  4099. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  4100. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  4101. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  4102. if (message.result == false)
  4103. {
  4104. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4105. }
  4106. }
  4107. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4108. }
  4109. catch (Exception ex)
  4110. {
  4111. stopwatch2.Start();
  4112. CommandFromPLC resultToPlC = new CommandFromPLC();
  4113. resultToPlC.cmd = 0;
  4114. resultToPlC.cmdParam = 0; //指令参数
  4115. resultToPlC.cmdResult = 110;
  4116. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4117. stopwatch2.Stop();
  4118. string str = ex.StackTrace;
  4119. AddMessage(LogType.Error,
  4120. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4121. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4122. }
  4123. stopwatch1.Stop();
  4124. AddMessage(LogType.Info,
  4125. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4126. stopwatch2.ElapsedMilliseconds + "ms");
  4127. ProgressState = false;
  4128. if (direction == "Left") uuid = "";
  4129. if (direction == "Right") uuid2 = "";
  4130. }
  4131. #endregion S3
  4132. #region S4
  4133. /// <summary>
  4134. /// [S4] 点胶检测设备
  4135. /// </summary>
  4136. /// <param name="plcNo">PLC编号</param>
  4137. private void ReadStation_S4(int plcNo)
  4138. {
  4139. string stationCode = "[OP40]";
  4140. string stationName = "胶线检测";
  4141. string stationNameStr = stationCode + stationName;
  4142. string tagBaseName = "g_OP40_MES"; //标签变量名称
  4143. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4144. string tagAgvCommName = "agvCommFrmPC";
  4145. string tagiotComnName = "iotData";
  4146. string tagBarsetName = "BarcodeSet";
  4147. string CarrierBarcode = "";
  4148. // 触发信号字典
  4149. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4150. s4PLCSignal_Old.Add("a4OEEType", 0); // 节拍类型(plc写入)
  4151. // PLC数据字典 赋值
  4152. s4PLCData.Add("a4OEEType", 0); // 节拍类型(plc写入)
  4153. s4PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  4154. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  4155. (int, string) result;
  4156. while (true)
  4157. {
  4158. try
  4159. {
  4160. if (!GlobalContext._IsCon_Funs1)
  4161. {
  4162. UpdatePLCMonitor(1, plcNo, 0);
  4163. continue;
  4164. }
  4165. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4166. {
  4167. Stopwatch stopwatch1 = new Stopwatch();
  4168. Stopwatch stopwatch2 = new Stopwatch();
  4169. stopwatch1.Start();
  4170. stopwatch2.Start();
  4171. #region 一次性读取所有数据
  4172. // 一次性读取所有数据
  4173. result = FunsEip[plcNo]
  4174. .Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4175. if (result.Item1 != 0)
  4176. {
  4177. //richTextBox1.AppendText("\n" + strRet);
  4178. }
  4179. else
  4180. {
  4181. //去除扫码产生的特殊字符
  4182. stPLC_MesData.BarcodeSet.strProductBarcode =
  4183. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  4184. stPLC_MesData.BarcodeSet.strPartBarcode =
  4185. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  4186. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  4187. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  4188. stPLC_MesData.BarcodeSet.strPCBBarcode =
  4189. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  4190. //richTextBox1.AppendText("\n" + "读取成功");
  4191. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  4192. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  4193. ? XiaomiDeviceState.Unknown
  4194. : (XiaomiDeviceState)xmDeviceStateInt;
  4195. // 载具SN
  4196. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode;
  4197. // 节拍
  4198. s4PLCData["a4OEEType"] = stPLC_MesData.iotData.beatAction;
  4199. //报警信息
  4200. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  4201. }
  4202. #endregion 一次性读取所有数据
  4203. stopwatch2.Stop();
  4204. #region 进站
  4205. try
  4206. {
  4207. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4208. {
  4209. lock (lockObj)
  4210. {
  4211. if (!ProgressState)
  4212. {
  4213. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  4214. ProgressState = true;
  4215. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData,
  4216. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  4217. out ProgressState));
  4218. }
  4219. }
  4220. }
  4221. }
  4222. catch (Exception ex)
  4223. {
  4224. ProgressState = false;
  4225. string str = ex.StackTrace;
  4226. AddMessage_Station(stationNameStr, LogType.Error,
  4227. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4228. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4229. }
  4230. #endregion 进站
  4231. #region 出站
  4232. try
  4233. {
  4234. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4235. {
  4236. lock (lockObj)
  4237. {
  4238. if (!ProgressState)
  4239. {
  4240. ProgressState = true;
  4241. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData,
  4242. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4243. out ProgressState));
  4244. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4245. }
  4246. }
  4247. }
  4248. }
  4249. catch (Exception ex)
  4250. {
  4251. string str = ex.StackTrace;
  4252. AddMessage_Station(stationNameStr, LogType.Error,
  4253. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4254. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4255. }
  4256. #endregion 出站
  4257. #region 节拍接口
  4258. try
  4259. {
  4260. if (stPLC_MesData.iotData.beatAction > 0)
  4261. {
  4262. int a4OEEType = Convert.ToInt32(s4PLCData["a4OEEType"]);
  4263. int a4OEETypeGOld = Convert.ToInt32(s4PLCSignal_Old["a4OEEType"]);
  4264. //若设备紧急复原后节拍重置
  4265. if (a4OEEType == 1)
  4266. {
  4267. a4OEETypeGOld = 0;
  4268. }
  4269. if (a4OEEType != a4OEETypeGOld)
  4270. {
  4271. s4PLCData["OEETypeFlag"] = "1";
  4272. }
  4273. else
  4274. {
  4275. s4PLCData["OEETypeFlag"] = "0";
  4276. }
  4277. if (s4PLCData["OEETypeFlag"].ToString() == "1" && (a4OEEType == 1 || a4OEEType == 3 || a4OEEType == 4 || a4OEEType == 5))
  4278. {
  4279. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  4280. if (res == 1)
  4281. {
  4282. s4PLCSignal_Old["a4OEEType"] = s4PLCData["a4OEEType"];
  4283. }
  4284. else
  4285. {
  4286. s4PLCSignal_Old["a4OEEType"] = 0;
  4287. }
  4288. }
  4289. }
  4290. else {
  4291. s4PLCSignal_Old["a4OEEType"] = 0;
  4292. }
  4293. }
  4294. catch (Exception ex)
  4295. {
  4296. string str = ex.StackTrace;
  4297. AddMessage_Station(stationNameStr, LogType.Error,
  4298. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4299. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4300. }
  4301. #endregion
  4302. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4303. stopwatch1.Stop();
  4304. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4305. }
  4306. else
  4307. {
  4308. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4309. AddMessage_Station(stationNameStr, LogType.Info,
  4310. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4311. FunsEip[plcNo].Connect(); // 重连
  4312. }
  4313. }
  4314. catch (Exception ex)
  4315. {
  4316. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4317. AddMessage_Station(stationNameStr, LogType.Error,
  4318. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4319. }
  4320. Thread.Sleep(IntervalReadPLC);
  4321. }
  4322. }
  4323. /// <summary>
  4324. /// [S4] 点胶检测设备 - 进站
  4325. /// </summary>
  4326. /// <param name="plcNo">PLC编号</param>
  4327. /// <param name="stationNameStr">工站全称</param>
  4328. /// <param name="stPLC_MesData"></param>
  4329. /// <param name="tagMesCommName"></param>
  4330. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  4331. string tagBarsetName, out bool ProgressState)
  4332. {
  4333. Stopwatch stopwatch1 = new Stopwatch();
  4334. Stopwatch stopwatch2 = new Stopwatch();
  4335. try
  4336. {
  4337. stopwatch1.Start();
  4338. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4339. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4340. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  4341. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  4342. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4343. bool pass = a1Result == 1;
  4344. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4345. //载具码验证产品码
  4346. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4347. if (string.IsNullOrEmpty(strProductBarcode))
  4348. {
  4349. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4350. ProgressState = false;
  4351. Thread.Sleep(10000);
  4352. return;
  4353. }
  4354. sn = strProductBarcode;
  4355. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4356. // 产品SN(物料码)校验
  4357. List<TestItem> item = new List<TestItem>();
  4358. stopwatch2.Start();
  4359. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  4360. item, MachineId, StationId, pass, "01-SLOT-01");
  4361. stopwatch2.Stop();
  4362. //指令执行结果 1:OK 110:失败
  4363. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4364. if (mesResultFrmWeb == 1)
  4365. {
  4366. if (a1Result == 1)
  4367. {
  4368. mesResultFrmWeb = 1;
  4369. }
  4370. else
  4371. {
  4372. mesResultFrmWeb = 110;
  4373. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  4374. }
  4375. }
  4376. //进站结果写入PLC
  4377. CommandFromPLC resultToPlC = new CommandFromPLC();
  4378. resultToPlC.cmd = 0;
  4379. resultToPlC.cmdParam = 0; //指令参数
  4380. resultToPlC.cmdResult = mesResultFrmWeb;
  4381. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4382. }
  4383. catch (Exception ex)
  4384. {
  4385. string str = ex.StackTrace;
  4386. AddMessage(LogType.Error,
  4387. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4388. str.Length - str.LastIndexOf("\\") - 1));
  4389. CommandFromPLC resultToPlC = new CommandFromPLC();
  4390. resultToPlC.cmd = 0;
  4391. resultToPlC.cmdParam = 0; //指令参数
  4392. resultToPlC.cmdResult = 110;
  4393. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4394. }
  4395. stopwatch1.Stop();
  4396. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4397. AddMessage(LogType.Info,
  4398. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4399. stopwatch2.ElapsedMilliseconds + "ms");
  4400. ProgressState = false;
  4401. }
  4402. /// <summary>
  4403. /// [S4] 点胶检测设备 - 出站接口
  4404. /// </summary>
  4405. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  4406. string stationCode, string stationName, out bool ProgressState)
  4407. {
  4408. Stopwatch stopwatch1 = new Stopwatch();
  4409. Stopwatch stopwatch2 = new Stopwatch();
  4410. try
  4411. {
  4412. stopwatch1.Start();
  4413. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4414. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4415. string processItem = stationName; // 测试项目
  4416. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4417. string supplierCode = ""; // 供应商代码
  4418. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4419. string batch_num = GlobalContext.BatchNumber; // 批次号
  4420. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4421. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4422. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4423. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  4424. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  4425. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4426. bool pass = a1Result == 1;
  4427. //根据载具码获取产品码
  4428. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4429. if (string.IsNullOrEmpty(strProductBarcode))
  4430. {
  4431. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4432. ProgressState = false;
  4433. Thread.Sleep(10000);
  4434. return;
  4435. }
  4436. sn = strProductBarcode;
  4437. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4438. List<TestItem> items = new List<TestItem>();
  4439. items.Add(new TestItem()
  4440. {
  4441. Parameter_name = "载具码",
  4442. Parameter_value = CarrierBarcode,
  4443. Parameter_unit = ""
  4444. });
  4445. items.Add(new TestItem()
  4446. {
  4447. Parameter_name = "产品码",
  4448. Parameter_value = sn,
  4449. Parameter_unit = ""
  4450. });
  4451. #region 上传图片
  4452. if (GlobalContext.MQTTIsSendUpFile)
  4453. {
  4454. string[] urlarry = GlobalContext.UpFilePath.Split(",");
  4455. fileUploadData.fileData.Clear();
  4456. foreach (var item in urlarry)
  4457. {
  4458. if (!string.IsNullOrEmpty(item))
  4459. {
  4460. //上传图片
  4461. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName, a1Result,
  4462. item, uuid).Result;
  4463. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  4464. }
  4465. }
  4466. }
  4467. #endregion
  4468. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4469. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4470. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode,
  4471. "01-SLOT-01", MachineId, StationId, "", paramJson);
  4472. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4473. if (mesResultFrmWeb == 1)
  4474. {
  4475. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  4476. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  4477. }
  4478. stopwatch2.Start();
  4479. //进站结果写入PLC
  4480. CommandFromPLC resultToPlC = new CommandFromPLC();
  4481. resultToPlC.cmd = 0;
  4482. resultToPlC.cmdParam = 0; //指令参数
  4483. resultToPlC.cmdResult = mesResultFrmWeb;
  4484. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4485. stopwatch2.Stop();
  4486. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4487. //保存PLC返回MES数据到本地
  4488. ResponseMessage message = new ResponseMessage();
  4489. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  4490. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  4491. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  4492. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  4493. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  4494. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  4495. if (message.result == false)
  4496. {
  4497. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4498. }
  4499. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4500. }
  4501. catch (Exception ex)
  4502. {
  4503. stopwatch2.Start();
  4504. CommandFromPLC resultToPlC = new CommandFromPLC();
  4505. resultToPlC.cmd = 0;
  4506. resultToPlC.cmdParam = 0; //指令参数
  4507. resultToPlC.cmdResult = 110;
  4508. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4509. stopwatch2.Stop();
  4510. string str = ex.StackTrace;
  4511. AddMessage(LogType.Error,
  4512. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4513. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4514. }
  4515. stopwatch1.Stop();
  4516. AddMessage(LogType.Info,
  4517. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4518. stopwatch2.ElapsedMilliseconds + "ms");
  4519. ProgressState = false;
  4520. uuid = "";
  4521. }
  4522. #endregion
  4523. #region S5
  4524. private static bool isPCBStation = false; //控制PCB是否进出站的标识
  4525. /// <summary>
  4526. /// [S5] 点胶检测设备
  4527. /// </summary>
  4528. /// <param name="plcNo">PLC编号</param>
  4529. private void ReadStation_S5(int plcNo)
  4530. {
  4531. string stationCode = "[OP50]";
  4532. string stationName = "ADD板上料组装装备";
  4533. string stationNameStr = stationCode + stationName;
  4534. string tagBaseName = "g_OP50_MES"; //标签变量名称
  4535. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4536. string tagAgvCommName = "agvCommFrmPC";
  4537. string tagiotComnName = "iotData";
  4538. string tagBarsetName = "BarcodeSet";
  4539. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  4540. string CarrierBarcode = "";
  4541. // 触发信号字典
  4542. s5PLCSignal_Old.Add("a5OEEType", 0); // 节拍类型(plc写入)
  4543. // PLC数据字典 赋值
  4544. s5PLCData.Add("a5OEEType", 0); // 节拍类型(plc写入)
  4545. s5PLCData.Add("OEETypeFlag", 0); // 节拍标识 0 不上传 ,1 上传
  4546. (int, string) result;
  4547. while (true)
  4548. {
  4549. try
  4550. {
  4551. if (!GlobalContext._IsCon_Funs1)
  4552. {
  4553. UpdatePLCMonitor(1, plcNo, 0);
  4554. continue;
  4555. }
  4556. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4557. {
  4558. Stopwatch stopwatch1 = new Stopwatch();
  4559. Stopwatch stopwatch2 = new Stopwatch();
  4560. stopwatch1.Start();
  4561. stopwatch2.Start();
  4562. #region 一次性读取所有数据
  4563. // 一次性读取所有数据
  4564. result = FunsEip[plcNo]
  4565. .Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4566. if (result.Item1 != 0)
  4567. {
  4568. }
  4569. else
  4570. {
  4571. //测试数据
  4572. //stPLC_MesData.mesCommFrmPLC.cmd = 2;
  4573. stPLC_MesData.BarcodeSet.strCarrierBarcode = "A235461";
  4574. stPLC_MesData.BarcodeSet.strPCBBarcode = "A1507V000239";
  4575. //stPLC_MesData.iotData.beatAction = 1;
  4576. //stPLC_MesData.iotData.beatAction = 2;
  4577. //stPLC_MesData.iotData.beatAction = 3;
  4578. //stPLC_MesData.iotData.beatAction = 4;
  4579. //stPLC_MesData.iotData.beatAction = 5;
  4580. //stPLC_MesData.iotData.beatAction = 6;
  4581. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
  4582. #region 去除扫码产生的特殊字符
  4583. stPLC_MesData.BarcodeSet.strProductBarcode =
  4584. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  4585. stPLC_MesData.BarcodeSet.strPartBarcode =
  4586. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  4587. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  4588. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  4589. stPLC_MesData.BarcodeSet.strPCBBarcode =
  4590. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  4591. #endregion
  4592. //richTextBox1.AppendText("\n" + "读取成功");
  4593. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  4594. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  4595. ? XiaomiDeviceState.Unknown
  4596. : (XiaomiDeviceState)xmDeviceStateInt;
  4597. // 节拍
  4598. s5PLCData["a5OEEType"] = stPLC_MesData.iotData.beatAction;
  4599. //载具码
  4600. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode.ToString();
  4601. //报警信息
  4602. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  4603. }
  4604. #endregion 一次性读取所有数据
  4605. stopwatch2.Stop();
  4606. #region 进站
  4607. try
  4608. {
  4609. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4610. {
  4611. lock (lockObj)
  4612. {
  4613. if (!ProgressState)
  4614. {
  4615. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  4616. ProgressState = true;
  4617. string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
  4618. if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
  4619. {
  4620. ProgressState = true;
  4621. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData,
  4622. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  4623. out ProgressState));
  4624. }
  4625. }
  4626. }
  4627. }
  4628. }
  4629. catch (Exception ex)
  4630. {
  4631. ProgressState = false;
  4632. string str = ex.StackTrace;
  4633. AddMessage_Station(stationNameStr, LogType.Error,
  4634. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4635. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4636. }
  4637. #endregion 进站
  4638. #region 出站
  4639. try
  4640. {
  4641. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4642. {
  4643. lock (lockObj)
  4644. {
  4645. if (!ProgressState)
  4646. {
  4647. ProgressState = true;
  4648. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData,
  4649. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4650. out ProgressState));
  4651. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4652. }
  4653. }
  4654. }
  4655. }
  4656. catch (Exception ex)
  4657. {
  4658. ProgressState = false;
  4659. string str = ex.StackTrace;
  4660. AddMessage_Station(stationNameStr, LogType.Error,
  4661. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4662. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4663. }
  4664. #endregion 出站
  4665. #region 节拍接口
  4666. try
  4667. {
  4668. if (stPLC_MesData.iotData.beatAction > 0)
  4669. {
  4670. int a5OEEType = Convert.ToInt32(s5PLCData["a5OEEType"]);
  4671. int a5OEETypeGOld = Convert.ToInt32(s5PLCSignal_Old["a5OEEType"]);
  4672. if (a5OEEType != a5OEETypeGOld)
  4673. {
  4674. s5PLCData["OEETypeFlag"] = "1";
  4675. }
  4676. else
  4677. {
  4678. s5PLCData["OEETypeFlag"] = "0";
  4679. }
  4680. if (s5PLCData["OEETypeFlag"].ToString() == "1" && (a5OEEType == 1 || a5OEEType == 3 || a5OEEType == 4 || a5OEEType == 5))
  4681. {
  4682. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  4683. if (res == 1)
  4684. {
  4685. s5PLCSignal_Old["a5OEEType"] = s5PLCData["a5OEEType"];
  4686. }
  4687. else {
  4688. s5PLCSignal_Old["a5OEEType"] = 0;
  4689. }
  4690. }
  4691. }
  4692. else {
  4693. s5PLCSignal_Old["a5OEEType"] = 0;
  4694. }
  4695. }
  4696. catch (Exception ex)
  4697. {
  4698. string str = ex.StackTrace;
  4699. AddMessage_Station(stationNameStr, LogType.Error,
  4700. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4701. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4702. }
  4703. #endregion
  4704. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4705. stopwatch1.Stop();
  4706. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4707. }
  4708. else
  4709. {
  4710. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4711. AddMessage_Station(stationNameStr, LogType.Info,
  4712. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4713. FunsEip[plcNo].Connect(); // 重连
  4714. }
  4715. }
  4716. catch (Exception ex)
  4717. {
  4718. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4719. AddMessage_Station(stationNameStr, LogType.Error,
  4720. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4721. }
  4722. Thread.Sleep(IntervalReadPLC);
  4723. }
  4724. }
  4725. /// <summary>
  4726. /// [S5] 点胶检测设备 - 进站
  4727. /// </summary>
  4728. /// <param name="plcNo">PLC编号</param>
  4729. /// <param name="stationNameStr">工站全称</param>
  4730. /// <param name="stPLC_MesData"></param>
  4731. /// <param name="tagMesCommName"></param>
  4732. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  4733. string tagBarsetName, out bool ProgressState)
  4734. {
  4735. Stopwatch stopwatch1 = new Stopwatch();
  4736. Stopwatch stopwatch2 = new Stopwatch();
  4737. try
  4738. {
  4739. stopwatch1.Start();
  4740. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4741. //string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4742. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  4743. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  4744. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  4745. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码
  4746. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  4747. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4748. bool pass = a1Result == 1;
  4749. AddMessage(LogType.Info, $"ADD板编码(PCB码):{pcbBarcode}");
  4750. //绑定载具和产品
  4751. //ResponseMessage message = new ResponseMessage();
  4752. //message = SQLHelper.PCBCarrierBind(strCarrierBarcode, pcbBarcode);
  4753. //if (message.result == false)
  4754. //{
  4755. // AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  4756. // ProgressState = false;
  4757. // Thread.Sleep(10000);
  4758. // return;
  4759. //}
  4760. //载具码验证产品码 //载具码验证产品码
  4761. //string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4762. //if (string.IsNullOrEmpty(strProductBarcode))
  4763. //{
  4764. // AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4765. //}
  4766. //sn = strProductBarcode;
  4767. //AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4768. // 产品SN(物料码)校验
  4769. List<TestItem> item = new List<TestItem>();
  4770. stopwatch2.Start();
  4771. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  4772. pcbBarcode,
  4773. item, MachineId, StationId, pass, "01-SLOT-01");
  4774. stopwatch2.Stop();
  4775. //指令执行结果 1:OK 110:失败
  4776. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4777. if (mesResultFrmWeb == 1)
  4778. {
  4779. if (a1Result == 1)
  4780. {
  4781. mesResultFrmWeb = 1;
  4782. }
  4783. else
  4784. {
  4785. mesResultFrmWeb = 110;
  4786. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  4787. }
  4788. }
  4789. //进站结果写入PLC
  4790. CommandFromPLC resultToPlC = new CommandFromPLC();
  4791. resultToPlC.cmd = 0;
  4792. resultToPlC.cmdParam = 0; //指令参数
  4793. resultToPlC.cmdResult = mesResultFrmWeb;
  4794. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4795. }
  4796. catch (Exception ex)
  4797. {
  4798. string str = ex.StackTrace;
  4799. AddMessage(LogType.Error,
  4800. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4801. str.Length - str.LastIndexOf("\\") - 1));
  4802. CommandFromPLC resultToPlC = new CommandFromPLC();
  4803. resultToPlC.cmd = 0;
  4804. resultToPlC.cmdParam = 0; //指令参数
  4805. resultToPlC.cmdResult = 110;
  4806. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4807. }
  4808. stopwatch1.Stop();
  4809. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4810. AddMessage(LogType.Info,
  4811. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4812. stopwatch2.ElapsedMilliseconds + "ms");
  4813. ProgressState = false;
  4814. }
  4815. /// <summary>
  4816. /// [S5] 点胶检测设备 - 出站接口
  4817. /// </summary>
  4818. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  4819. string stationCode, string stationName, out bool ProgressState)
  4820. {
  4821. Stopwatch stopwatch1 = new Stopwatch();
  4822. Stopwatch stopwatch2 = new Stopwatch();
  4823. try
  4824. {
  4825. stopwatch1.Start();
  4826. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4827. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4828. string processItem = stationName; // 测试项目
  4829. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4830. string supplierCode = ""; // 供应商代码
  4831. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4832. string batch_num = GlobalContext.BatchNumber; // 批次号
  4833. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4834. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4835. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 部件条码;
  4836. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4837. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  4838. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  4839. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  4840. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4841. bool pass = a1Result == 1;
  4842. CommandFromPLC resultToPlC = new CommandFromPLC();
  4843. //根据载具码获取产品码
  4844. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4845. if (string.IsNullOrEmpty(strProductBarcode))
  4846. {
  4847. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4848. ProgressState = false;
  4849. Thread.Sleep(10000);
  4850. return;
  4851. }
  4852. stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
  4853. sn = strProductBarcode;
  4854. //数据库绑定载具和PCB
  4855. ResponseMessage message = new ResponseMessage();
  4856. message = SQLHelper.PCBCarrierBind(CarrierBarcode, pcbBarcode);
  4857. if (message.result == false)
  4858. {
  4859. AddMessage(LogType.Error, stationNameStr + "_PCB码数据库绑定失败,错误:" + message.text);
  4860. ProgressState = true; //防止循环报错
  4861. return;
  4862. }
  4863. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn};PCB码:{pcbBarcode}");
  4864. List<TestItem> items = new List<TestItem>();
  4865. items.Add(new TestItem()
  4866. {
  4867. Parameter_name = "载具码",
  4868. Parameter_value = CarrierBarcode,
  4869. Parameter_unit = ""
  4870. });
  4871. items.Add(new TestItem()
  4872. {
  4873. Parameter_name = "产品码",
  4874. Parameter_value = sn,
  4875. Parameter_unit = ""
  4876. });
  4877. items.Add(new TestItem()
  4878. {
  4879. Parameter_name = "PCB码",
  4880. Parameter_value = pcbBarcode,
  4881. Parameter_unit = ""
  4882. });
  4883. #region 上传图片
  4884. if (GlobalContext.MQTTIsSendUpFile)
  4885. {
  4886. string[] urlarry = GlobalContext.UpFilePath.Split(",");
  4887. fileUploadData.fileData.Clear();
  4888. foreach (var item in urlarry)
  4889. {
  4890. if (!string.IsNullOrEmpty(item))
  4891. {
  4892. //上传图片
  4893. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName, a1Result,
  4894. item, uuid).Result;
  4895. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  4896. }
  4897. }
  4898. }
  4899. #endregion
  4900. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4901. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4902. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  4903. MachineId, StationId, PartBarcode, paramJson);
  4904. byte mesResultFrmWeb = 0;
  4905. if (stPLC_MesData.mesCommFrmPLC.cmdParam == 2)
  4906. {
  4907. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem, workorder_code,
  4908. batch_num
  4909. , mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId,
  4910. PartBarcode, paramJson);
  4911. }
  4912. else if (stPLC_MesData.mesCommFrmPLC.cmdParam == 1)
  4913. {
  4914. result1 = PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  4915. }
  4916. mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4917. //进站结果写入PLC
  4918. resultToPlC.cmd = 0;
  4919. resultToPlC.cmdParam = 0; //指令参数
  4920. resultToPlC.cmdResult = mesResultFrmWeb;
  4921. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4922. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4923. //保存PLC返回MES数据到本地
  4924. //ResponseMessage message = new ResponseMessage();
  4925. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  4926. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB,
  4927. stPLC_MesData.mesData.nRemainCount, "");
  4928. if (message.result == false)
  4929. {
  4930. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4931. }
  4932. //保存部件码信息
  4933. if (!string.IsNullOrEmpty(PartBarcode))
  4934. {
  4935. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  4936. if (message.result == false)
  4937. {
  4938. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  4939. }
  4940. }
  4941. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4942. }
  4943. catch (Exception ex)
  4944. {
  4945. stopwatch2.Start();
  4946. CommandFromPLC resultToPlC = new CommandFromPLC();
  4947. resultToPlC.cmd = 0;
  4948. resultToPlC.cmdParam = 0; //指令参数
  4949. resultToPlC.cmdResult = 110;
  4950. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4951. stopwatch2.Stop();
  4952. string str = ex.StackTrace;
  4953. AddMessage(LogType.Error,
  4954. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4955. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4956. }
  4957. stopwatch1.Stop();
  4958. AddMessage(LogType.Info,
  4959. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4960. stopwatch2.ElapsedMilliseconds + "ms");
  4961. ProgressState = false;
  4962. uuid = "";
  4963. }
  4964. private int S5_PCB进出站(OP50_MesData_t stPLC_MesData, int plcNo, string stationNameStr, string tagBaseName,
  4965. string tagMesCommName)
  4966. {
  4967. string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
  4968. if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
  4969. {
  4970. string strProductBarcode =
  4971. SQLHelper.GetProductBarcodeByCarrierCode(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  4972. stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
  4973. CommandFromPLC resultToPlC = new CommandFromPLC();
  4974. resultToPlC.cmd = 0;
  4975. resultToPlC.cmdParam = 0; //指令参数
  4976. if (GlobalContext.IsSendStationIn)
  4977. {
  4978. #region 进站
  4979. //int res1 = PCBStationInData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  4980. //if (res1 == 1)
  4981. //{
  4982. // resultToPlC.cmdResult = 2;//OK
  4983. // WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  4984. //}
  4985. //else
  4986. //{
  4987. // resultToPlC.cmdResult = 120;
  4988. // WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  4989. // return 2;
  4990. //}
  4991. #endregion
  4992. #region 出站
  4993. int res2 = PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  4994. if (res2 == 1)
  4995. {
  4996. resultToPlC.cmdResult = 2; //OK
  4997. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  4998. return 1;
  4999. }
  5000. else
  5001. {
  5002. resultToPlC.cmdResult = 120;
  5003. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  5004. return 2;
  5005. }
  5006. #endregion
  5007. }
  5008. else
  5009. {
  5010. return 2;
  5011. }
  5012. }
  5013. else
  5014. {
  5015. return 2;
  5016. }
  5017. }
  5018. #endregion
  5019. #region S6
  5020. private Dictionary<string, object> s6PLCData = new Dictionary<string, object>();
  5021. private Dictionary<string, object> s6PLCSignal_Old = new Dictionary<string, object>();
  5022. /// <summary>
  5023. /// [S6] 顶盖装配设备
  5024. /// </summary>
  5025. /// <param name="plcNo">PLC编号</param>
  5026. public void ReadStation_S6(int plcNo)
  5027. {
  5028. string stationCode = "[OP70]";
  5029. string stationName = "组上盖板";
  5030. string stationNameStr = stationCode + stationName;
  5031. string tagBaseName = "g_OP60_MES"; //标签变量名称
  5032. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5033. string tagAgvCommName = "agvCommFrmPC";
  5034. string tagiotComnName = "iotData";
  5035. string tagBarsetName = "BarcodeSet";
  5036. string CarrierBarcode = "";
  5037. // 触发信号字典
  5038. s6PLCSignal_Old.Add("a6OEEType", 0); // 节拍类型(plc写入)
  5039. // PLC数据字典 赋值
  5040. s6PLCData.Add("a6OEEType", 0); // 节拍类型(plc写入)
  5041. s6PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  5042. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  5043. (int, string) result;
  5044. while (true)
  5045. {
  5046. try
  5047. {
  5048. if (!GlobalContext._IsCon_Funs1)
  5049. {
  5050. UpdatePLCMonitor(1, plcNo, 0);
  5051. continue;
  5052. }
  5053. if (StopWhile)
  5054. {
  5055. continue;
  5056. }
  5057. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5058. {
  5059. Stopwatch stopwatch1 = new Stopwatch();
  5060. Stopwatch stopwatch2 = new Stopwatch();
  5061. stopwatch1.Start();
  5062. stopwatch2.Start();
  5063. #region 一次性读取所有数据
  5064. // 一次性读取所有数据
  5065. result = FunsEip[plcNo]
  5066. .Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  5067. if (result.Item1 != 0)
  5068. {
  5069. //richTextBox1.AppendText("\n" + strRet);
  5070. }
  5071. else
  5072. {
  5073. //测试
  5074. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
  5075. //stPLC_MesData.mesCommFrmPLC.cmd = 1;
  5076. //去除扫码产生的特殊字符
  5077. stPLC_MesData.BarcodeSet.strProductBarcode =
  5078. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  5079. stPLC_MesData.BarcodeSet.strPartBarcode =
  5080. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  5081. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  5082. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  5083. stPLC_MesData.BarcodeSet.strPCBBarcode =
  5084. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  5085. //richTextBox1.AppendText("\n" + "读取成功");
  5086. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  5087. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  5088. ? XiaomiDeviceState.Unknown
  5089. : (XiaomiDeviceState)xmDeviceStateInt;
  5090. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  5091. s6PLCData["a6OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  5092. //报警信息
  5093. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  5094. }
  5095. #endregion 一次性读取所有数据
  5096. stopwatch2.Stop();
  5097. #region 进站
  5098. try
  5099. {
  5100. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5101. {
  5102. lock (lockObj)
  5103. {
  5104. if (!ProgressState)
  5105. {
  5106. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  5107. ProgressState = true;
  5108. //载具码验证产品码
  5109. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData,
  5110. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  5111. out ProgressState));
  5112. }
  5113. }
  5114. }
  5115. }
  5116. catch (Exception ex)
  5117. {
  5118. ProgressState = false;
  5119. string str = ex.StackTrace;
  5120. AddMessage_Station(stationNameStr, LogType.Error,
  5121. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5122. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5123. }
  5124. #endregion 进站
  5125. #region 出站
  5126. try
  5127. {
  5128. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5129. {
  5130. lock (lockObj)
  5131. {
  5132. if (!ProgressState)
  5133. {
  5134. ProgressState = true;
  5135. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData,
  5136. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  5137. out ProgressState));
  5138. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  5139. }
  5140. }
  5141. }
  5142. }
  5143. catch (Exception ex)
  5144. {
  5145. ProgressState = false;
  5146. string str = ex.StackTrace;
  5147. AddMessage_Station(stationNameStr, LogType.Error,
  5148. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5149. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5150. }
  5151. #endregion 出站
  5152. #region 节拍接口
  5153. try
  5154. {
  5155. if (stPLC_MesData.iotData.beatAction > 0)
  5156. {
  5157. int a6OEEType = Convert.ToInt32(s6PLCData["a6OEEType"]);
  5158. int a6OEETypeGOld = Convert.ToInt32(s6PLCSignal_Old["a6OEEType"]);
  5159. if (a6OEEType != a6OEETypeGOld)
  5160. {
  5161. s6PLCData["OEETypeFlag"] = "1";
  5162. }
  5163. else
  5164. {
  5165. s6PLCData["OEETypeFlag"] = "0";
  5166. }
  5167. if (s6PLCData["OEETypeFlag"].ToString() == "1" && (a6OEEType == 1 || a6OEEType == 3 || a6OEEType == 4 || a6OEEType == 5))
  5168. {
  5169. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  5170. if (res == 1)
  5171. {
  5172. s6PLCSignal_Old["a6OEEType"] = s6PLCData["a6OEEType"];
  5173. }
  5174. else
  5175. {
  5176. s6PLCSignal_Old["a6OEEType"] = 0;
  5177. }
  5178. }
  5179. }
  5180. else {
  5181. s6PLCSignal_Old["a6OEEType"] = 0;
  5182. }
  5183. }
  5184. catch (Exception ex)
  5185. {
  5186. string str = ex.StackTrace;
  5187. AddMessage_Station(stationNameStr, LogType.Error,
  5188. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  5189. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5190. }
  5191. #endregion
  5192. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5193. stopwatch1.Stop();
  5194. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5195. }
  5196. else
  5197. {
  5198. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5199. AddMessage_Station(stationNameStr, LogType.Info,
  5200. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5201. FunsEip[plcNo].Connect(); // 重连
  5202. }
  5203. }
  5204. catch (Exception ex)
  5205. {
  5206. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5207. AddMessage_Station(stationNameStr, LogType.Error,
  5208. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5209. }
  5210. Thread.Sleep(IntervalReadPLC);
  5211. }
  5212. }
  5213. /// <summary>
  5214. /// [S6] 顶盖装配设备 - 进站
  5215. /// </summary>
  5216. /// <param name="plcNo">PLC编号</param>
  5217. /// <param name="stationNameStr">工站全称</param>
  5218. /// <param name="stPLC_MesData"></param>
  5219. /// <param name="tagMesCommName"></param>
  5220. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  5221. string tagBarsetName, out bool ProgressState)
  5222. {
  5223. Stopwatch stopwatch1 = new Stopwatch();
  5224. Stopwatch stopwatch2 = new Stopwatch();
  5225. try
  5226. {
  5227. stopwatch1.Start();
  5228. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  5229. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5230. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  5231. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  5232. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5233. bool pass = a1Result == 1;
  5234. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  5235. string ProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  5236. string PCBBarcode = SQLHelper.GetPCBBarcodeByCarrierCode(strCarrierBarcode);
  5237. //strCarrierBarcode = "N801A-003";
  5238. //载具码验证产品码
  5239. if (string.IsNullOrEmpty(ProductBarcode))
  5240. {
  5241. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5242. ProgressState = false;
  5243. Thread.Sleep(10000);
  5244. return;
  5245. }
  5246. sn = ProductBarcode;
  5247. if (OpenDailogFalg)
  5248. {
  5249. using (var dialog = new BandBarodeDialog(strCarrierBarcode, ProductBarcode, PCBBarcode))
  5250. {
  5251. var rs = dialog.ShowDialog();
  5252. if (rs == DialogResult.OK)
  5253. {
  5254. AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode}");
  5255. OpenDailogFalg = false; //关闭扫码
  5256. StopWhile = false;//开启while循环
  5257. }
  5258. else
  5259. {
  5260. ProgressState = false;
  5261. return;
  5262. }
  5263. }
  5264. }
  5265. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5266. // 产品SN(物料码)校验
  5267. List<TestItem> item = new List<TestItem>();
  5268. stopwatch2.Start();
  5269. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  5270. item, MachineId, StationId, pass, "01-SLOT-01");
  5271. stopwatch2.Stop();
  5272. //指令执行结果 1:OK 110:失败
  5273. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5274. if (mesResultFrmWeb == 1)
  5275. {
  5276. if (a1Result == 1)
  5277. {
  5278. mesResultFrmWeb = 1;
  5279. }
  5280. else
  5281. {
  5282. mesResultFrmWeb = 110;
  5283. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  5284. }
  5285. }
  5286. //进站结果写入PLC
  5287. CommandFromPLC resultToPlC = new CommandFromPLC();
  5288. resultToPlC.cmd = 0;
  5289. resultToPlC.cmdParam = 0; //指令参数
  5290. resultToPlC.cmdResult = mesResultFrmWeb;
  5291. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5292. }
  5293. catch (Exception ex)
  5294. {
  5295. string str = ex.StackTrace;
  5296. AddMessage(LogType.Error,
  5297. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  5298. str.Length - str.LastIndexOf("\\") - 1));
  5299. CommandFromPLC resultToPlC = new CommandFromPLC();
  5300. resultToPlC.cmd = 0;
  5301. resultToPlC.cmdParam = 0; //指令参数
  5302. resultToPlC.cmdResult = 110;
  5303. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5304. }
  5305. stopwatch1.Stop();
  5306. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  5307. AddMessage(LogType.Info,
  5308. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5309. stopwatch2.ElapsedMilliseconds + "ms");
  5310. ProgressState = false;
  5311. }
  5312. /// <summary>
  5313. /// [S6] 顶盖装配设备 - 出站接口
  5314. /// </summary>
  5315. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  5316. string stationCode, string stationName, out bool ProgressState)
  5317. {
  5318. Stopwatch stopwatch1 = new Stopwatch();
  5319. Stopwatch stopwatch2 = new Stopwatch();
  5320. try
  5321. {
  5322. stopwatch1.Start();
  5323. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  5324. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5325. string processItem = stationName; // 测试项目
  5326. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5327. string supplierCode = ""; // 供应商代码
  5328. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5329. string batch_num = GlobalContext.BatchNumber; // 批次号
  5330. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5331. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5332. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5333. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  5334. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  5335. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5336. bool pass = a1Result == 1;
  5337. //根据载具码获取产品码
  5338. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5339. if (string.IsNullOrEmpty(strProductBarcode))
  5340. {
  5341. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5342. ProgressState = false;
  5343. Thread.Sleep(10000);
  5344. return;
  5345. }
  5346. sn = strProductBarcode;
  5347. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  5348. List<TestItem> items = new List<TestItem>();
  5349. items.Add(new TestItem()
  5350. {
  5351. Parameter_name = "载具码",
  5352. Parameter_value = CarrierBarcode,
  5353. Parameter_unit = ""
  5354. });
  5355. items.Add(new TestItem()
  5356. {
  5357. Parameter_name = "产品码",
  5358. Parameter_value = sn,
  5359. Parameter_unit = ""
  5360. });
  5361. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  5362. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  5363. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  5364. MachineId, StationId, "", paramJson);
  5365. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5366. if (mesResultFrmWeb == 1)
  5367. {
  5368. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  5369. if (mesResultFrmWeb==110)
  5370. {
  5371. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  5372. }
  5373. }
  5374. stopwatch2.Start();
  5375. //进站结果写入PLC
  5376. CommandFromPLC resultToPlC = new CommandFromPLC();
  5377. resultToPlC.cmd = 0;
  5378. resultToPlC.cmdParam = 0; //指令参数
  5379. resultToPlC.cmdResult = mesResultFrmWeb;
  5380. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5381. stopwatch2.Stop();
  5382. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  5383. //保存PLC返回MES数据到本地
  5384. ResponseMessage message = new ResponseMessage();
  5385. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  5386. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  5387. }
  5388. catch (Exception ex)
  5389. {
  5390. stopwatch2.Start();
  5391. CommandFromPLC resultToPlC = new CommandFromPLC();
  5392. resultToPlC.cmd = 0;
  5393. resultToPlC.cmdParam = 0; //指令参数
  5394. resultToPlC.cmdResult = 110;
  5395. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5396. stopwatch2.Stop();
  5397. string str = ex.StackTrace;
  5398. AddMessage(LogType.Error,
  5399. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5400. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5401. }
  5402. stopwatch1.Stop();
  5403. AddMessage(LogType.Info,
  5404. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5405. stopwatch2.ElapsedMilliseconds + "ms");
  5406. ProgressState = false;
  5407. uuid = "";
  5408. OpenDailogFalg = true; //开启下一个物料的扫码
  5409. }
  5410. #endregion
  5411. #region S7
  5412. private Dictionary<string, object> s7PLCSignal_Old = new Dictionary<string, object>();
  5413. private Dictionary<string, object> s7PLCData = new Dictionary<string, object>();
  5414. /// <summary>
  5415. /// [S7] 锁螺丝设备
  5416. /// </summary>
  5417. /// <param name="plcNo">PLC编号</param>
  5418. private void ReadStation_S7(int plcNo)
  5419. {
  5420. string stationCode = "[OP80]";
  5421. string stationName = "上盖板锁螺丝";
  5422. string stationNameStr = stationCode + stationName;
  5423. string tagBaseName = "g_OP70_MES"; //标签变量名称
  5424. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5425. string tagAgvCommName = "agvCommFrmPC";
  5426. string tagBarsetName = "BarcodeSet";
  5427. string tagiotComnName = "iotData";
  5428. string tagScrewDataset = "screwDataset";
  5429. string CarrierBarcode_Left = "";
  5430. string CarrierBarcode_Right = "";
  5431. s7PLCSignal_Old.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
  5432. s7PLCSignal_Old.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
  5433. // PLC数据字典 赋值
  5434. s7PLCData.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
  5435. s7PLCData.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
  5436. s5PLCData.Add("OEETypeFlag_left", 0); // 节拍标识 0 不上传 ,1 上传
  5437. s5PLCData.Add("OEETypeFlag_right", 0); // 节拍标识 0 不上传 ,1 上传
  5438. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  5439. (int, string) result;
  5440. AtlasScrew atlasScrewLeft = new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort,
  5441. 3000, 3000, "Left");
  5442. atlasScrewLeft.Initial();
  5443. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort,
  5444. 3000, 3000, "Right");
  5445. atlasScrewRight.Initial();
  5446. while (true)
  5447. {
  5448. try
  5449. {
  5450. if (!GlobalContext._IsCon_Funs1)
  5451. {
  5452. UpdatePLCMonitor(1, plcNo, 0);
  5453. continue;
  5454. }
  5455. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5456. {
  5457. Stopwatch stopwatch1 = new Stopwatch();
  5458. Stopwatch stopwatch2 = new Stopwatch();
  5459. stopwatch1.Start();
  5460. stopwatch2.Start();
  5461. #region 一次性读取所有数据
  5462. // 一次性读取所有数据
  5463. result = FunsEip[plcNo]
  5464. .Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  5465. if (result.Item1 != 0)
  5466. {
  5467. //richTextBox1.AppendText("\n" + strRet);
  5468. }
  5469. else
  5470. {
  5471. #region 去除扫码产生的特殊字符
  5472. stPLC_MesData.Left.BarcodeSet.strProductBarcode =
  5473. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strProductBarcode);
  5474. stPLC_MesData.Left.BarcodeSet.strPartBarcode =
  5475. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPartBarcode);
  5476. stPLC_MesData.Left.BarcodeSet.strCarrierBarcode =
  5477. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strCarrierBarcode);
  5478. stPLC_MesData.Left.BarcodeSet.strPCBBarcode =
  5479. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPCBBarcode);
  5480. stPLC_MesData.Right.BarcodeSet.strProductBarcode =
  5481. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strProductBarcode);
  5482. stPLC_MesData.Right.BarcodeSet.strPartBarcode =
  5483. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPartBarcode);
  5484. stPLC_MesData.Right.BarcodeSet.strCarrierBarcode =
  5485. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strCarrierBarcode);
  5486. stPLC_MesData.Right.BarcodeSet.strPCBBarcode =
  5487. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPCBBarcode);
  5488. #endregion
  5489. int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  5490. int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  5491. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  5492. ? XiaomiDeviceState.Unknown
  5493. : (XiaomiDeviceState)xmDeviceStateInt_L;
  5494. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  5495. ? XiaomiDeviceState.Unknown
  5496. : (XiaomiDeviceState)xmDeviceStateInt_R;
  5497. s7PLCData["a7OEEPartNo"] =
  5498. stPLC_MesData.Left.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  5499. // 载具SN
  5500. CarrierBarcode_Left = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode;
  5501. CarrierBarcode_Right = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode;
  5502. // 节拍
  5503. s7PLCData["a7OEEType"] = stPLC_MesData.Left.iotData.beatAction;
  5504. s7PLCData["a7OEEType_right"] = stPLC_MesData.Right.iotData.beatAction;
  5505. //报警信息
  5506. _FaultDatas = stPLC_MesData.Left.iotData.fault_codes;
  5507. _FaultDatas2 = stPLC_MesData.Right.iotData.fault_codes;
  5508. }
  5509. #endregion 一次性读取所有数据
  5510. stopwatch2.Stop();
  5511. #region 左边进站
  5512. try
  5513. {
  5514. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5515. {
  5516. lock (lockObj)
  5517. {
  5518. if (!ProgressState)
  5519. {
  5520. stationCode = "[OP81]";
  5521. stationName = "上盖板锁螺丝1";
  5522. stationNameStr = stationCode + stationName;
  5523. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  5524. ProgressState = true;
  5525. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left,
  5526. tagBaseName + ".Left." + tagMesCommName,
  5527. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState,
  5528. atlasScrewLeft));
  5529. }
  5530. }
  5531. }
  5532. }
  5533. catch (Exception ex)
  5534. {
  5535. ProgressState = false;
  5536. string str = ex.StackTrace;
  5537. AddMessage_Station(stationNameStr, LogType.Error,
  5538. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5539. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5540. }
  5541. #endregion 左边进站
  5542. #region 左边出站
  5543. try
  5544. {
  5545. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5546. {
  5547. lock (lockObj)
  5548. {
  5549. if (!ProgressState)
  5550. {
  5551. stationCode = "[OP81]";
  5552. stationName = "上盖板锁螺丝1";
  5553. stationNameStr = stationCode + stationName;
  5554. ProgressState = true;
  5555. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left,
  5556. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  5557. out ProgressState));
  5558. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  5559. }
  5560. }
  5561. }
  5562. }
  5563. catch (Exception ex)
  5564. {
  5565. ProgressState = false;
  5566. string str = ex.StackTrace;
  5567. AddMessage_Station(stationNameStr, LogType.Error,
  5568. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5569. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5570. }
  5571. #endregion 左边出站
  5572. #region 右边进站
  5573. try
  5574. {
  5575. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5576. {
  5577. lock (lockObj)
  5578. {
  5579. if (!ProgressState)
  5580. {
  5581. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  5582. stationCode = "[OP82]";
  5583. stationName = "上盖板锁螺丝2";
  5584. stationNameStr = stationCode + stationName;
  5585. ProgressState = true;
  5586. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right,
  5587. tagBaseName + ".Right." + tagMesCommName,
  5588. tagBaseName + ".Right" + tagBarsetName, "Right", out ProgressState,
  5589. atlasScrewRight));
  5590. }
  5591. }
  5592. }
  5593. }
  5594. catch (Exception ex)
  5595. {
  5596. ProgressState = false;
  5597. string str = ex.StackTrace;
  5598. AddMessage_Station(stationNameStr, LogType.Error,
  5599. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5600. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5601. }
  5602. #endregion 右边进站
  5603. #region 右边出站
  5604. try
  5605. {
  5606. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5607. {
  5608. lock (lockObj)
  5609. {
  5610. if (!ProgressState)
  5611. {
  5612. stationCode = "[OP82]";
  5613. stationName = "上盖板锁螺丝2";
  5614. stationNameStr = stationCode + stationName;
  5615. ProgressState = true;
  5616. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right,
  5617. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  5618. out ProgressState));
  5619. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  5620. }
  5621. }
  5622. }
  5623. }
  5624. catch (Exception ex)
  5625. {
  5626. ProgressState = false;
  5627. string str = ex.StackTrace;
  5628. AddMessage_Station(stationNameStr, LogType.Error,
  5629. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5630. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5631. }
  5632. #endregion 右边出站
  5633. #region 节拍接口
  5634. try
  5635. {
  5636. #region 左工位 节拍
  5637. if (stPLC_MesData.Left.iotData.beatAction > 0)
  5638. {
  5639. stationCode = "[OP81]";
  5640. stationName = "上盖板锁螺丝1";
  5641. stationNameStr = stationCode + stationName;
  5642. int a7OEEType_left = Convert.ToInt32(s7PLCData["a7OEEType_left"]);
  5643. int a7OEETypeGOld_left = Convert.ToInt32(s7PLCSignal_Old["a7OEEType_left"]);
  5644. if (a7OEEType_left != a7OEETypeGOld_left)
  5645. {
  5646. if (a7OEEType_left != a7OEETypeGOld_left)
  5647. s7PLCData["OEETypeFlag_left"] = "1";
  5648. else
  5649. s7PLCData["OEETypeFlag_left"] = "0";
  5650. if (s7PLCData["OEETypeFlag_left"].ToString() == "1" && (a7OEEType_left == 1 || a7OEEType_left == 3 || a7OEEType_left == 4 || a7OEEType_left == 5))
  5651. {
  5652. int res = 0;
  5653. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagiotComnName, CarrierBarcode_Left,
  5654. stPLC_MesData.Left.iotData, out res);
  5655. if (res == 1)
  5656. {
  5657. s7PLCSignal_Old["a7OEEType_left"] = s7PLCData["a7OEEType_left"];
  5658. }
  5659. else {
  5660. s7PLCSignal_Old["a7OEEType_left"] = 0;
  5661. }
  5662. }
  5663. }
  5664. }
  5665. else
  5666. {
  5667. s7PLCSignal_Old["a7OEEType_left"] = 0;
  5668. }
  5669. #endregion 左工位 节拍
  5670. #region 右工位 节拍
  5671. if (stPLC_MesData.Right.iotData.beatAction > 0)
  5672. {
  5673. stationCode = "[OP82]";
  5674. stationName = "上盖板锁螺丝2";
  5675. stationNameStr = stationCode + stationName;
  5676. int a7OEEType_right = Convert.ToInt32(s7PLCData["a7OEEType_right"]);
  5677. int a7OEETypeGOld_right = Convert.ToInt32(s7PLCSignal_Old["a7OEEType_right"]);
  5678. if (a7OEEType_right != a7OEETypeGOld_right)
  5679. {
  5680. if (a7OEEType_right != a7OEETypeGOld_right)
  5681. s7PLCData["a7OEEType_right"] = "1";
  5682. else
  5683. s7PLCData["a7OEEType_right"] = "0";
  5684. if (s7PLCData["a7OEEType_right"].ToString() == "1" && (a7OEEType_right == 1 || a7OEEType_right == 3 || a7OEEType_right == 4 || a7OEEType_right == 5))
  5685. {
  5686. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagiotComnName, CarrierBarcode_Left,
  5687. stPLC_MesData.Right.iotData, out res);
  5688. if (res == 1)
  5689. {
  5690. s7PLCSignal_Old["a7OEEType_right"] = s7PLCData["a7OEEType_right"];
  5691. }
  5692. else {
  5693. s7PLCSignal_Old["a7OEEType_right"] = 0;
  5694. }
  5695. }
  5696. }
  5697. }
  5698. else
  5699. {
  5700. s7PLCSignal_Old["a7OEEType_right"] = 0;
  5701. }
  5702. #endregion 右工位 节拍
  5703. }
  5704. catch (Exception ex)
  5705. {
  5706. string str = ex.StackTrace;
  5707. AddMessage_Station(stationNameStr, LogType.Error,
  5708. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  5709. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5710. }
  5711. #endregion
  5712. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5713. stopwatch1.Stop();
  5714. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5715. }
  5716. else
  5717. {
  5718. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5719. AddMessage_Station(stationNameStr, LogType.Info,
  5720. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5721. FunsEip[plcNo].Connect(); // 重连
  5722. }
  5723. }
  5724. catch (Exception ex)
  5725. {
  5726. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5727. AddMessage_Station(stationNameStr, LogType.Error,
  5728. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5729. }
  5730. Thread.Sleep(IntervalReadPLC);
  5731. }
  5732. }
  5733. /// <summary>
  5734. /// [S7] 锁螺丝设备 - 进站
  5735. /// </summary>
  5736. /// <param name="plcNo">PLC编号</param>
  5737. /// <param name="stationNameStr">工站全称</param>
  5738. /// <param name="stPLC_MesData"></param>
  5739. /// <param name="tagMesCommName"></param>
  5740. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  5741. string tagBarsetName, string direction, out bool ProgressState, AtlasScrew atlasScrew)
  5742. {
  5743. Stopwatch stopwatch1 = new Stopwatch();
  5744. Stopwatch stopwatch2 = new Stopwatch();
  5745. string atlasSn = string.Empty;
  5746. try
  5747. {
  5748. stopwatch1.Start();
  5749. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  5750. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5751. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  5752. string StationId = string.Empty; // 工位ID(可配置)
  5753. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5754. bool pass = a1Result == 1;
  5755. if (direction == "Left")
  5756. {
  5757. StationId = GlobalContext.S7_StationId_1;
  5758. }
  5759. if (direction == "Right")
  5760. {
  5761. StationId = GlobalContext.S7_StationId_2;
  5762. }
  5763. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  5764. //载具码验证产品码
  5765. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  5766. if (string.IsNullOrEmpty(strProductBarcode))
  5767. {
  5768. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5769. ProgressState = false;
  5770. Thread.Sleep(10000);
  5771. return;
  5772. }
  5773. sn = strProductBarcode;
  5774. atlasSn = strProductBarcode;
  5775. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5776. string slot = "";
  5777. if (direction == "Left")
  5778. {
  5779. isCollectingFlagLeft = false; //采集螺丝数据结束
  5780. slot = "01-SLOT-01";
  5781. }
  5782. if (direction == "Right")
  5783. {
  5784. isCollectingFlagRight = false; //采集螺丝数据结束
  5785. slot = "01-SLOT-02";
  5786. }
  5787. // 产品SN(物料码)校验
  5788. List<TestItem> item = new List<TestItem>();
  5789. stopwatch2.Start();
  5790. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  5791. item, MachineId, StationId, pass, slot);
  5792. stopwatch2.Stop();
  5793. //指令执行结果 1:OK 110:失败
  5794. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5795. if (mesResultFrmWeb == 1)
  5796. {
  5797. if (a1Result == 1)
  5798. {
  5799. mesResultFrmWeb = 1;
  5800. }
  5801. else
  5802. {
  5803. mesResultFrmWeb = 110;
  5804. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  5805. }
  5806. }
  5807. //进站结果写入PLC
  5808. CommandFromPLC resultToPlC = new CommandFromPLC();
  5809. resultToPlC.cmd = 0;
  5810. resultToPlC.cmdParam = 0; //指令参数
  5811. resultToPlC.cmdResult = mesResultFrmWeb;
  5812. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5813. }
  5814. catch (Exception ex)
  5815. {
  5816. string str = ex.StackTrace;
  5817. AddMessage(LogType.Error,
  5818. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  5819. str.Length - str.LastIndexOf("\\") - 1));
  5820. CommandFromPLC resultToPlC = new CommandFromPLC();
  5821. resultToPlC.cmd = 0;
  5822. resultToPlC.cmdParam = 0; //指令参数
  5823. resultToPlC.cmdResult = 110;
  5824. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5825. }
  5826. stopwatch1.Stop();
  5827. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  5828. AddMessage(LogType.Info,
  5829. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5830. stopwatch2.ElapsedMilliseconds + "ms");
  5831. ProgressState = false;
  5832. //开始采集螺丝数据
  5833. if (direction == "Left")
  5834. {
  5835. isCollectingFlagLeft = true;
  5836. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  5837. }
  5838. if (direction == "Right")
  5839. {
  5840. isCollectingFlagRight = true;
  5841. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  5842. }
  5843. }
  5844. /// <summary>
  5845. /// [S7] 锁螺丝设备 - 出站
  5846. /// </summary>
  5847. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  5848. string stationCode, string stationName, string direction, out bool ProgressState)
  5849. {
  5850. Stopwatch stopwatch1 = new Stopwatch();
  5851. Stopwatch stopwatch2 = new Stopwatch();
  5852. try
  5853. {
  5854. stopwatch1.Start();
  5855. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  5856. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5857. string processItem = stationName; // 测试项目
  5858. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5859. string supplierCode = ""; // 供应商代码
  5860. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5861. string batch_num = GlobalContext.BatchNumber; // 批次号
  5862. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5863. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5864. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5865. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  5866. string StationId = string.Empty; // 工位ID(可配置)
  5867. if (direction == "Left")
  5868. {
  5869. StationId = GlobalContext.S7_StationId_1;
  5870. }
  5871. if (direction == "Right")
  5872. {
  5873. StationId = GlobalContext.S7_StationId_2;
  5874. }
  5875. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5876. //a1Result = 1;
  5877. bool pass = a1Result == 1;
  5878. //根据载具码获取产品码
  5879. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5880. if (string.IsNullOrEmpty(strProductBarcode))
  5881. {
  5882. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5883. ProgressState = false;
  5884. Thread.Sleep(10000);
  5885. return;
  5886. }
  5887. sn = strProductBarcode;
  5888. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  5889. List<TestItem> items = new List<TestItem>();
  5890. items.Add(new TestItem()
  5891. {
  5892. Parameter_name = "载具码",
  5893. Parameter_value = CarrierBarcode,
  5894. Parameter_unit = ""
  5895. });
  5896. items.Add(new TestItem()
  5897. {
  5898. Parameter_name = "产品码",
  5899. Parameter_value = sn,
  5900. Parameter_unit = ""
  5901. });
  5902. //if (direction == "Right")
  5903. //{
  5904. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  5905. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem, workorder_code,
  5906. batch_num, mtltmrk, plcDate_YMD, supplierCode
  5907. , sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  5908. //}
  5909. //if (direction == "Left")
  5910. //{
  5911. // isCollectingFlagLeft = false;//采集螺丝数据结束
  5912. //}
  5913. //if (direction == "Right")
  5914. //{
  5915. // isCollectingFlagRight = false;//采集螺丝数据结束
  5916. //}
  5917. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5918. if (mesResultFrmWeb == 1)
  5919. {
  5920. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  5921. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  5922. }
  5923. stopwatch2.Start();
  5924. //进站结果写入PLC
  5925. CommandFromPLC resultToPlC = new CommandFromPLC();
  5926. resultToPlC.cmd = 0;
  5927. resultToPlC.cmdParam = 0; //指令参数
  5928. resultToPlC.cmdResult = mesResultFrmWeb;
  5929. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5930. stopwatch2.Stop();
  5931. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  5932. //保存PLC返回MES数据到本地
  5933. ResponseMessage message = new ResponseMessage();
  5934. if (direction == "Left")
  5935. {
  5936. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  5937. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  5938. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  5939. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  5940. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  5941. //if (message.result == false)
  5942. //{
  5943. // AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  5944. //}
  5945. }
  5946. if (direction == "Right")
  5947. {
  5948. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  5949. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  5950. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  5951. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  5952. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  5953. //if (message.result == false)
  5954. //{
  5955. // AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  5956. //}
  5957. }
  5958. //保存螺丝数据到txt
  5959. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes,
  5960. stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  5961. if (result.Item1 != 0)
  5962. {
  5963. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  5964. }
  5965. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_保存加工数据到本地成功");
  5966. }
  5967. catch (Exception ex)
  5968. {
  5969. stopwatch2.Start();
  5970. CommandFromPLC resultToPlC = new CommandFromPLC();
  5971. resultToPlC.cmd = 0;
  5972. resultToPlC.cmdParam = 0; //指令参数
  5973. resultToPlC.cmdResult = 110;
  5974. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5975. stopwatch2.Stop();
  5976. string str = ex.StackTrace;
  5977. AddMessage(LogType.Error,
  5978. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5979. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5980. }
  5981. stopwatch1.Stop();
  5982. AddMessage(LogType.Info,
  5983. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5984. stopwatch2.ElapsedMilliseconds + "ms");
  5985. ProgressState = false;
  5986. if (direction == "Left") uuid = "";
  5987. if (direction == "Right") uuid2 = "";
  5988. }
  5989. #endregion
  5990. #region S8
  5991. private Dictionary<string, object> s8PLCData = new Dictionary<string, object>();
  5992. private Dictionary<string, object> s8PLCSignal_Old = new Dictionary<string, object>();
  5993. /// <summary>
  5994. /// [S8] 3D螺丝高度检测设备
  5995. /// </summary>
  5996. /// <param name="plcNo">PLC编号</param>
  5997. private void ReadStation_S8(int plcNo)
  5998. {
  5999. string stationCode = "[OP90]";
  6000. string stationName = "NG下料";
  6001. string stationNameStr = stationCode + stationName;
  6002. string tagBaseName = "g_OP80_MES"; //标签变量名称
  6003. string tagMesCommName = "mesCommToPC"; //标签变量名称
  6004. string tagAgvCommName = "agvCommFrmPC";
  6005. string tagiotComnName = "iotData";
  6006. string tagBarsetName = "BarcodeSet";
  6007. string CarrierBarcode = "";
  6008. // 触发信号字典
  6009. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6010. s8PLCSignal_Old.Add("a8OEEType", 0); // 节拍类型(plc写入)
  6011. // PLC数据字典 赋值
  6012. s8PLCData.Add("a8OEEType", 0); // 节拍类型(plc写入)
  6013. s8PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  6014. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  6015. (int, string) result;
  6016. while (true)
  6017. {
  6018. try
  6019. {
  6020. if (!GlobalContext._IsCon_Funs1)
  6021. {
  6022. UpdatePLCMonitor(1, plcNo, 0);
  6023. continue;
  6024. }
  6025. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  6026. {
  6027. Stopwatch stopwatch1 = new Stopwatch();
  6028. Stopwatch stopwatch2 = new Stopwatch();
  6029. stopwatch1.Start();
  6030. stopwatch2.Start();
  6031. #region 一次性读取所有数据
  6032. // 一次性读取所有数据
  6033. result = FunsEip[plcNo]
  6034. .Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  6035. if (result.Item1 != 0)
  6036. {
  6037. //richTextBox1.AppendText("\n" + strRet);
  6038. }
  6039. else
  6040. {
  6041. //去除扫码产生的特殊字符
  6042. stPLC_MesData.BarcodeSet.strProductBarcode =
  6043. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  6044. stPLC_MesData.BarcodeSet.strPartBarcode =
  6045. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  6046. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  6047. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  6048. stPLC_MesData.BarcodeSet.strPCBBarcode =
  6049. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  6050. }
  6051. #endregion 一次性读取所有数据
  6052. stopwatch2.Stop();
  6053. //richTextBox1.AppendText("\n" + "读取成功");
  6054. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  6055. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  6056. ? XiaomiDeviceState.Unknown
  6057. : (XiaomiDeviceState)xmDeviceStateInt;
  6058. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  6059. s8PLCData["a8OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  6060. //报警信息
  6061. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  6062. stopwatch2.Stop();
  6063. #region 进站
  6064. try
  6065. {
  6066. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  6067. {
  6068. lock (lockObj)
  6069. {
  6070. if (!ProgressState)
  6071. {
  6072. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  6073. ProgressState = true;
  6074. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData,
  6075. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  6076. out ProgressState));
  6077. }
  6078. }
  6079. }
  6080. }
  6081. catch (Exception ex)
  6082. {
  6083. ProgressState = false;
  6084. string str = ex.StackTrace;
  6085. AddMessage_Station(stationNameStr, LogType.Error,
  6086. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6087. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6088. }
  6089. #endregion 进站
  6090. #region 出站
  6091. try
  6092. {
  6093. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  6094. {
  6095. lock (lockObj)
  6096. {
  6097. if (!ProgressState)
  6098. {
  6099. ProgressState = true;
  6100. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData,
  6101. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  6102. out ProgressState));
  6103. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  6104. uuid = "";
  6105. }
  6106. }
  6107. }
  6108. }
  6109. catch (Exception ex)
  6110. {
  6111. ProgressState = false;
  6112. string str = ex.StackTrace;
  6113. AddMessage_Station(stationNameStr, LogType.Error,
  6114. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6115. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6116. }
  6117. #endregion 出站
  6118. #region 节拍接口
  6119. try
  6120. {
  6121. int a8OEEType = Convert.ToInt32(s8PLCData["a8OEEType"]);
  6122. int a8OEETypeGOld = Convert.ToInt32(s8PLCSignal_Old["a8OEEType"]);
  6123. if (stPLC_MesData.iotData.beatAction > 0)
  6124. {
  6125. if (a8OEEType != a8OEETypeGOld)
  6126. {
  6127. s8PLCData["OEETypeFlag"] = "1";
  6128. }
  6129. else
  6130. {
  6131. s8PLCData["OEETypeFlag"] = "0";
  6132. }
  6133. if (s8PLCData["OEETypeFlag"].ToString() == "1" && (a8OEEType == 1 || a8OEEType == 3 || a8OEEType == 4 || a8OEEType == 5))
  6134. {
  6135. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  6136. CarrierBarcode, stPLC_MesData.iotData, out res);
  6137. if (res == 1)
  6138. {
  6139. s8PLCSignal_Old["a8OEEType"] = s8PLCData["a8OEEType"];
  6140. }
  6141. else
  6142. {
  6143. s8PLCSignal_Old["a8OEEType"] = 0;
  6144. }
  6145. }
  6146. }
  6147. else {
  6148. s8PLCSignal_Old["a8OEEType"] = 0;
  6149. }
  6150. }
  6151. catch (Exception ex)
  6152. {
  6153. string str = ex.StackTrace;
  6154. AddMessage_Station(stationNameStr, LogType.Error,
  6155. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  6156. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6157. }
  6158. #endregion
  6159. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6160. stopwatch1.Stop();
  6161. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6162. }
  6163. else
  6164. {
  6165. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6166. AddMessage_Station(stationNameStr, LogType.Info,
  6167. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6168. FunsEip[plcNo].Connect(); // 重连
  6169. }
  6170. }
  6171. catch (Exception ex)
  6172. {
  6173. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6174. AddMessage_Station(stationNameStr, LogType.Error,
  6175. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6176. }
  6177. Thread.Sleep(IntervalReadPLC);
  6178. }
  6179. }
  6180. /// <summary>
  6181. /// [S8] 3D螺丝高度检测设备 - 进站
  6182. /// </summary>
  6183. /// <param name="plcNo">PLC编号</param>
  6184. /// <param name="stationNameStr">工站全称</param>
  6185. /// <param name="stPLC_MesData"></param>
  6186. /// <param name="tagMesCommName"></param>
  6187. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  6188. string tagBarsetName, out bool ProgressState)
  6189. {
  6190. Stopwatch stopwatch1 = new Stopwatch();
  6191. Stopwatch stopwatch2 = new Stopwatch();
  6192. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6193. bool pass = a1Result == 1;
  6194. try
  6195. {
  6196. stopwatch1.Start();
  6197. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  6198. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  6199. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  6200. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  6201. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  6202. //载具码验证产品码
  6203. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  6204. if (string.IsNullOrEmpty(strProductBarcode))
  6205. {
  6206. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6207. ProgressState = false;
  6208. Thread.Sleep(10000);
  6209. return;
  6210. }
  6211. sn = strProductBarcode;
  6212. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  6213. // 产品SN(物料码)校验
  6214. List<TestItem> item = new List<TestItem>();
  6215. stopwatch2.Start();
  6216. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  6217. sn,
  6218. item, MachineId, StationId, pass, "01-SLOT-01");
  6219. stopwatch2.Stop();
  6220. //指令执行结果 1:OK 110:失败
  6221. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  6222. if (mesResultFrmWeb == 1)
  6223. {
  6224. if (a1Result == 1)
  6225. {
  6226. mesResultFrmWeb = 1;
  6227. }
  6228. else
  6229. {
  6230. mesResultFrmWeb = 110;
  6231. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  6232. }
  6233. }
  6234. //进站结果写入PLC
  6235. CommandFromPLC resultToPlC = new CommandFromPLC();
  6236. resultToPlC.cmd = 0;
  6237. resultToPlC.cmdParam = 0; //指令参数
  6238. resultToPlC.cmdResult = mesResultFrmWeb;
  6239. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6240. }
  6241. catch (Exception ex)
  6242. {
  6243. string str = ex.StackTrace;
  6244. AddMessage(LogType.Error,
  6245. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(
  6246. str.LastIndexOf("\\") + 1,
  6247. str.Length - str.LastIndexOf("\\") - 1));
  6248. CommandFromPLC resultToPlC = new CommandFromPLC();
  6249. resultToPlC.cmd = 0;
  6250. resultToPlC.cmdParam = 0; //指令参数
  6251. resultToPlC.cmdResult = 110;
  6252. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6253. }
  6254. stopwatch1.Stop();
  6255. AddMessage(LogType.Info,
  6256. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  6257. stopwatch2.ElapsedMilliseconds + "ms");
  6258. ProgressState = false;
  6259. }
  6260. /// <summary>
  6261. /// [S8] 3D螺丝高度检测设备 - 出站接口
  6262. /// </summary>
  6263. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  6264. string stationCode, string stationName, out bool ProgressState)
  6265. {
  6266. Stopwatch stopwatch1 = new Stopwatch();
  6267. Stopwatch stopwatch2 = new Stopwatch();
  6268. try
  6269. {
  6270. stopwatch1.Start();
  6271. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  6272. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6273. string processItem = stationName; // 测试项目
  6274. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6275. string supplierCode = ""; // 供应商代码
  6276. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6277. string batch_num = GlobalContext.BatchNumber; // 批次号
  6278. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6279. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  6280. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  6281. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  6282. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  6283. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6284. bool pass = a1Result == 1;
  6285. //根据载具码获取产品码
  6286. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  6287. if (string.IsNullOrEmpty(strProductBarcode))
  6288. {
  6289. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6290. ProgressState = false;
  6291. Thread.Sleep(10000);
  6292. return;
  6293. }
  6294. sn = strProductBarcode;
  6295. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  6296. List<TestItem> items = new List<TestItem>();
  6297. items.Add(new TestItem()
  6298. {
  6299. Parameter_name = "载具码",
  6300. Parameter_value = CarrierBarcode,
  6301. Parameter_unit = ""
  6302. });
  6303. items.Add(new TestItem()
  6304. {
  6305. Parameter_name = "产品码",
  6306. Parameter_value = sn,
  6307. Parameter_unit = ""
  6308. });
  6309. #region 上传图片
  6310. if (GlobalContext.MQTTIsSendUpFile)
  6311. {
  6312. string[] urlarry = GlobalContext.UpFilePath.Split(",");
  6313. fileUploadData.fileData.Clear();
  6314. foreach (var item in urlarry)
  6315. {
  6316. if (!string.IsNullOrEmpty(item))
  6317. {
  6318. //上传图片
  6319. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName,
  6320. a1Result, item, uuid).Result;
  6321. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  6322. }
  6323. }
  6324. }
  6325. #endregion
  6326. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  6327. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6328. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  6329. MachineId, StationId, "", paramJson);
  6330. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  6331. if (mesResultFrmWeb == 1)
  6332. {
  6333. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  6334. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  6335. }
  6336. stopwatch2.Start();
  6337. //进站结果写入PLC
  6338. CommandFromPLC resultToPlC = new CommandFromPLC();
  6339. resultToPlC.cmd = 0;
  6340. resultToPlC.cmdParam = 0; //指令参数
  6341. resultToPlC.cmdResult = mesResultFrmWeb;
  6342. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6343. stopwatch2.Stop();
  6344. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  6345. //保存PLC返回MES数据到本地
  6346. ResponseMessage message = new ResponseMessage();
  6347. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  6348. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  6349. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  6350. if (message.result == false)
  6351. {
  6352. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  6353. }
  6354. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  6355. }
  6356. catch (Exception ex)
  6357. {
  6358. stopwatch2.Start();
  6359. CommandFromPLC resultToPlC = new CommandFromPLC();
  6360. resultToPlC.cmd = 0;
  6361. resultToPlC.cmdParam = 0; //指令参数
  6362. resultToPlC.cmdResult = 110;
  6363. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6364. stopwatch2.Stop();
  6365. string str = ex.StackTrace;
  6366. AddMessage(LogType.Error,
  6367. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  6368. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6369. }
  6370. stopwatch1.Stop();
  6371. AddMessage(LogType.Info,
  6372. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6373. stopwatch2.ElapsedMilliseconds + "ms");
  6374. ProgressState = false;
  6375. }
  6376. #endregion
  6377. #region S9
  6378. private Dictionary<string, object> s9PLCData = new Dictionary<string, object>();
  6379. private Dictionary<string, object> s9PLCSignal_Old = new Dictionary<string, object>();
  6380. /// <summary>
  6381. /// [S9] 下料设备
  6382. /// </summary>
  6383. /// <param name="plcNo">PLC编号</param>
  6384. private void ReadStation_S9(int plcNo)
  6385. {
  6386. string stationCode = "[OP100]";
  6387. string stationName = "半成品下料";
  6388. string stationNameStr = stationCode + stationName;
  6389. string tagBaseName = "g_OP90_MES"; //标签变量名称
  6390. string tagMesCommName = "mesCommToPC"; //标签变量名称
  6391. string tagAgvCommName = "agvCommFrmPC";
  6392. string tagiotComnName = "iotData";
  6393. string tagBarsetName = "BarcodeSet";
  6394. string CarrierBarcode = "";
  6395. // 触发信号字典
  6396. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6397. s9PLCSignal_Old.Add("a9OEEType", 0); // 节拍类型(plc写入)
  6398. // PLC数据字典 赋值
  6399. s9PLCData.Add("a9OEEType", 0); // 节拍类型(plc写入)
  6400. s9PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  6401. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  6402. (int, string) result;
  6403. while (true)
  6404. {
  6405. try
  6406. {
  6407. if (!GlobalContext._IsCon_Funs1)
  6408. {
  6409. UpdatePLCMonitor(1, plcNo, 0);
  6410. continue;
  6411. }
  6412. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  6413. {
  6414. Stopwatch stopwatch1 = new Stopwatch();
  6415. Stopwatch stopwatch2 = new Stopwatch();
  6416. stopwatch1.Start();
  6417. stopwatch2.Start();
  6418. #region 一次性读取所有数据
  6419. // 一次性读取所有数据
  6420. result = FunsEip[plcNo]
  6421. .Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  6422. if (result.Item1 != 0)
  6423. {
  6424. //richTextBox1.AppendText("\n" + strRet);
  6425. }
  6426. else
  6427. {
  6428. //去除扫码产生的特殊字符
  6429. stPLC_MesData.BarcodeSet.strProductBarcode =
  6430. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  6431. stPLC_MesData.BarcodeSet.strPartBarcode =
  6432. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  6433. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  6434. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  6435. stPLC_MesData.BarcodeSet.strPCBBarcode =
  6436. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  6437. //richTextBox1.AppendText("\n" + "读取成功");
  6438. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  6439. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  6440. ? XiaomiDeviceState.Unknown
  6441. : (XiaomiDeviceState)xmDeviceStateInt;
  6442. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  6443. s9PLCData["a9OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  6444. //报警信息
  6445. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  6446. }
  6447. #endregion 一次性读取所有数据
  6448. stopwatch2.Stop();
  6449. #region 进站
  6450. try
  6451. {
  6452. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  6453. {
  6454. lock (lockObj)
  6455. {
  6456. if (!ProgressState)
  6457. {
  6458. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  6459. ProgressState = true;
  6460. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData,
  6461. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  6462. out ProgressState));
  6463. }
  6464. }
  6465. }
  6466. }
  6467. catch (Exception ex)
  6468. {
  6469. ProgressState = false;
  6470. string str = ex.StackTrace;
  6471. AddMessage_Station(stationNameStr, LogType.Error,
  6472. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6473. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6474. }
  6475. #endregion 进站
  6476. #region 出站
  6477. try
  6478. {
  6479. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  6480. {
  6481. lock (lockObj)
  6482. {
  6483. if (!ProgressState)
  6484. {
  6485. ProgressState = true;
  6486. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData,
  6487. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  6488. out ProgressState));
  6489. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  6490. }
  6491. }
  6492. }
  6493. }
  6494. catch (Exception ex)
  6495. {
  6496. ProgressState = false;
  6497. string str = ex.StackTrace;
  6498. AddMessage_Station(stationNameStr, LogType.Error,
  6499. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6500. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6501. }
  6502. #endregion 出站
  6503. #region 节拍接口
  6504. try
  6505. {
  6506. if (stPLC_MesData.iotData.beatAction > 0)
  6507. {
  6508. int a9OEEType = Convert.ToInt32(s9PLCData["a9OEEType"]);
  6509. int a9OEETypeGOld = Convert.ToInt32(s9PLCSignal_Old["a9OEEType"]);
  6510. if (a9OEEType != a9OEETypeGOld)
  6511. {
  6512. s9PLCData["OEETypeFlag"] = "1";
  6513. }
  6514. else
  6515. {
  6516. s9PLCData["OEETypeFlag"] = "0";
  6517. }
  6518. if (s9PLCData["OEETypeFlag"].ToString() == "1" && (a9OEEType == 1 || a9OEEType == 3 || a9OEEType == 4 || a9OEEType == 5))
  6519. {
  6520. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  6521. CarrierBarcode, stPLC_MesData.iotData, out res);
  6522. if (res == 1)
  6523. {
  6524. s9PLCSignal_Old["a9OEEType"] = s9PLCData["a9OEEType"];
  6525. }
  6526. else
  6527. {
  6528. s9PLCSignal_Old["a9OEEType"] = 0;
  6529. }
  6530. }
  6531. }
  6532. else {
  6533. s9PLCSignal_Old["a9OEEType"] = 0;
  6534. }
  6535. }
  6536. catch (Exception ex)
  6537. {
  6538. string str = ex.StackTrace;
  6539. AddMessage_Station(stationNameStr, LogType.Error,
  6540. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  6541. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6542. }
  6543. #endregion
  6544. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6545. stopwatch1.Stop();
  6546. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6547. }
  6548. else
  6549. {
  6550. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6551. AddMessage_Station(stationNameStr, LogType.Info,
  6552. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6553. FunsEip[plcNo].Connect(); // 重连
  6554. }
  6555. }
  6556. catch (Exception ex)
  6557. {
  6558. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6559. AddMessage_Station(stationNameStr, LogType.Error,
  6560. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6561. }
  6562. Thread.Sleep(IntervalReadPLC);
  6563. }
  6564. }
  6565. /// <summary>
  6566. /// [S9] 下料设备 - 进站
  6567. /// </summary>
  6568. /// <param name="plcNo">PLC编号</param>
  6569. /// <param name="stationNameStr">工站全称</param>
  6570. /// <param name="stPLC_MesData"></param>
  6571. /// <param name="tagMesCommName"></param>
  6572. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  6573. string tagBarsetName, out bool ProgressState)
  6574. {
  6575. Stopwatch stopwatch1 = new Stopwatch();
  6576. Stopwatch stopwatch2 = new Stopwatch();
  6577. try
  6578. {
  6579. stopwatch1.Start();
  6580. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  6581. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  6582. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  6583. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  6584. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6585. bool pass = a1Result == 1;
  6586. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  6587. //载具码验证产品码
  6588. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  6589. if (string.IsNullOrEmpty(strProductBarcode))
  6590. {
  6591. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6592. ProgressState = false;
  6593. Thread.Sleep(10000);
  6594. return;
  6595. }
  6596. sn = strProductBarcode;
  6597. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  6598. // 产品SN(物料码)校验
  6599. List<TestItem> item = new List<TestItem>();
  6600. stopwatch2.Start();
  6601. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  6602. item, MachineId, StationId, pass, "01-SLOT-01");
  6603. stopwatch2.Stop();
  6604. //指令执行结果 1:OK 110:失败
  6605. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  6606. if (mesResultFrmWeb == 1)
  6607. {
  6608. if (a1Result == 1)
  6609. {
  6610. mesResultFrmWeb = 1;
  6611. }
  6612. else
  6613. {
  6614. mesResultFrmWeb = 110;
  6615. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  6616. }
  6617. }
  6618. //进站结果写入PLC
  6619. CommandFromPLC resultToPlC = new CommandFromPLC();
  6620. resultToPlC.cmd = 0;
  6621. resultToPlC.cmdParam = 0; //指令参数
  6622. resultToPlC.cmdResult = mesResultFrmWeb;
  6623. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6624. }
  6625. catch (Exception ex)
  6626. {
  6627. string str = ex.StackTrace;
  6628. AddMessage(LogType.Error,
  6629. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  6630. str.Length - str.LastIndexOf("\\") - 1));
  6631. CommandFromPLC resultToPlC = new CommandFromPLC();
  6632. resultToPlC.cmd = 0;
  6633. resultToPlC.cmdParam = 0; //指令参数
  6634. resultToPlC.cmdResult = 110;
  6635. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6636. }
  6637. stopwatch1.Stop();
  6638. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  6639. AddMessage(LogType.Info,
  6640. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  6641. stopwatch2.ElapsedMilliseconds + "ms");
  6642. ProgressState = false;
  6643. }
  6644. /// <summary>
  6645. /// [S9] 下料设备 - 出站接口
  6646. /// </summary>
  6647. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  6648. string stationCode, string stationName, out bool ProgressState)
  6649. {
  6650. Stopwatch stopwatch1 = new Stopwatch();
  6651. Stopwatch stopwatch2 = new Stopwatch();
  6652. try
  6653. {
  6654. stopwatch1.Start();
  6655. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  6656. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6657. string processItem = stationName; // 测试项目
  6658. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6659. string supplierCode = ""; // 供应商代码
  6660. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6661. string batch_num = GlobalContext.BatchNumber; // 批次号
  6662. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6663. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  6664. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  6665. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  6666. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  6667. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6668. bool pass = a1Result == 1;
  6669. //根据载具码获取产品码
  6670. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  6671. if (string.IsNullOrEmpty(strProductBarcode))
  6672. {
  6673. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6674. ProgressState = false;
  6675. Thread.Sleep(10000);
  6676. return;
  6677. }
  6678. sn = strProductBarcode;
  6679. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  6680. List<TestItem> items = new List<TestItem>();
  6681. items.Add(new TestItem()
  6682. {
  6683. Parameter_name = "载具码",
  6684. Parameter_value = CarrierBarcode,
  6685. Parameter_unit = ""
  6686. });
  6687. items.Add(new TestItem()
  6688. {
  6689. Parameter_name = "产品码",
  6690. Parameter_value = sn,
  6691. Parameter_unit = ""
  6692. });
  6693. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  6694. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6695. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  6696. MachineId, StationId, "", paramJson);
  6697. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  6698. if (mesResultFrmWeb == 1)
  6699. {
  6700. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  6701. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  6702. }
  6703. stopwatch2.Start();
  6704. //进站结果写入PLC
  6705. CommandFromPLC resultToPlC = new CommandFromPLC();
  6706. resultToPlC.cmd = 0;
  6707. resultToPlC.cmdParam = 0; //指令参数
  6708. resultToPlC.cmdResult = mesResultFrmWeb;
  6709. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6710. stopwatch2.Stop();
  6711. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  6712. //保存PLC返回MES数据到本地
  6713. ResponseMessage message = new ResponseMessage();
  6714. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  6715. stPLC_MesData.mesData.nRemainCount);
  6716. if (message.result == false)
  6717. {
  6718. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  6719. }
  6720. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  6721. if (result1 == 1)
  6722. {
  6723. //载具码解除绑定
  6724. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  6725. if (message.result == false)
  6726. {
  6727. AddMessage(LogType.Error, message.text);
  6728. }
  6729. }
  6730. }
  6731. catch (Exception ex)
  6732. {
  6733. stopwatch2.Start();
  6734. CommandFromPLC resultToPlC = new CommandFromPLC();
  6735. resultToPlC.cmd = 0;
  6736. resultToPlC.cmdParam = 0; //指令参数
  6737. resultToPlC.cmdResult = 110;
  6738. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6739. stopwatch2.Stop();
  6740. string str = ex.StackTrace;
  6741. AddMessage(LogType.Error,
  6742. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  6743. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6744. }
  6745. stopwatch1.Stop();
  6746. AddMessage(LogType.Info,
  6747. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6748. stopwatch2.ElapsedMilliseconds + "ms");
  6749. ProgressState = false;
  6750. uuid = "";
  6751. }
  6752. #endregion
  6753. #endregion Xiaomi
  6754. #region PLC1 张超凡
  6755. #region [S1] Tray盘上料装备(板测)
  6756. /// <summary>
  6757. /// S1工位的数据- 触发信号上次的值
  6758. /// </summary>
  6759. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  6760. /// <summary>
  6761. /// S1工位的数据(含触发信号)
  6762. /// </summary>
  6763. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  6764. /// <summary>
  6765. /// S1工位的数据- 回写点位
  6766. /// </summary>
  6767. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6768. ///// <summary>
  6769. ///// 触发信号
  6770. ///// </summary>
  6771. //private ManualResetEvent[] MreTasks;
  6772. /// <summary>
  6773. /// [S1] Tray盘上料装备(板测)
  6774. /// </summary>
  6775. /// <param name="plcNo">PLC编号</param>
  6776. //private void ReadStation_S1(int plcNo)
  6777. //{
  6778. // // [S1] Tray盘上料装备
  6779. // // [S2] FCT
  6780. // // [S3] 值板机
  6781. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6782. // // [S5] Tray盘下料装备
  6783. // string stationCode = "[S1]";
  6784. // string stationName = "Tray盘上料装备";
  6785. // string stationNameStr = stationCode + stationName;
  6786. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6787. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6788. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  6789. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  6790. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6791. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  6792. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6793. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  6794. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  6795. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  6796. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  6797. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6798. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  6799. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  6800. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  6801. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  6802. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  6803. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  6804. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6805. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  6806. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  6807. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  6808. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  6809. // s1PLCData.Add("a1Result", 0); // 产品结果
  6810. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  6811. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  6812. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  6813. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  6814. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  6815. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6816. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  6817. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  6818. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  6819. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  6820. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  6821. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  6822. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  6823. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  6824. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  6825. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  6826. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  6827. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6828. // while (IsRun)
  6829. // {
  6830. // try
  6831. // {
  6832. // if (!GlobalContext._IsCon_Funs1)
  6833. // {
  6834. // UpdatePLCMonitor(1, plcNo, 0);
  6835. // continue;
  6836. // }
  6837. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6838. // {
  6839. // Stopwatch stopwatch1 = new Stopwatch();
  6840. // Stopwatch stopwatch2 = new Stopwatch();
  6841. // stopwatch1.Start();
  6842. // stopwatch2.Start();
  6843. // #region 一次性读取所有数据
  6844. // // 一次性读取所有数据
  6845. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6846. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6847. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6848. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  6849. // int[] datas = data1.Concat(data2).ToArray();
  6850. // datas = datas.Concat(data3).ToArray();
  6851. // datas = datas.Concat(data4).ToArray();
  6852. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  6853. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  6854. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  6855. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  6856. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  6857. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  6858. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  6859. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  6860. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  6861. // s1PLCData["a1MES_FLAG"] = datas[109];
  6862. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  6863. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  6864. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  6865. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  6866. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  6867. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  6868. // s1PLCData["a1Result"] = datas[170];
  6869. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  6870. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  6871. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  6872. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  6873. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  6874. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  6875. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  6876. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  6877. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  6878. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  6879. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  6880. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  6881. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  6882. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  6883. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  6884. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  6885. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  6886. // s1PLCData["a1AGVUpStart"] = datas[308];
  6887. // s1PLCData["a1AGVUpEnd"] = datas[309];
  6888. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  6889. // s1PLCData["a1AGVDownStart"] = datas[321];
  6890. // s1PLCData["a1AGVDownEnd"] = datas[322];
  6891. // #endregion 一次性读取所有数据
  6892. // stopwatch2.Stop();
  6893. // #region 回写操作,写后清空flag
  6894. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  6895. // #endregion 回写操作,写后清空flag
  6896. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  6897. // try
  6898. // {
  6899. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  6900. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  6901. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  6902. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  6903. // {
  6904. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  6905. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  6906. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  6907. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  6908. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  6909. // }
  6910. // }
  6911. // catch (Exception ex)
  6912. // {
  6913. // // 6代表上位机报警
  6914. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  6915. // string str = ex.StackTrace;
  6916. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6917. // }
  6918. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  6919. // #region 上料进站校验
  6920. // try
  6921. // {
  6922. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  6923. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  6924. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  6925. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  6926. // {
  6927. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  6928. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  6929. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  6930. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  6931. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  6932. // }
  6933. // }
  6934. // catch (Exception ex)
  6935. // {
  6936. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  6937. // string str = ex.StackTrace;
  6938. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6939. // }
  6940. // #endregion 上料进站校验
  6941. // #region Tray盘上料装备-出站接口
  6942. // try
  6943. // {
  6944. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  6945. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  6946. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  6947. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  6948. // {
  6949. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  6950. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6951. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  6952. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  6953. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  6954. // }
  6955. // }
  6956. // catch (Exception ex)
  6957. // {
  6958. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  6959. // string str = ex.StackTrace;
  6960. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6961. // }
  6962. // #endregion Tray盘上料装备-出站接口
  6963. // #region Tray盘上料装备-将SN发给ICT标机
  6964. // try
  6965. // {
  6966. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  6967. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  6968. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  6969. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  6970. // {
  6971. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  6972. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  6973. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  6974. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  6975. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  6976. // }
  6977. // }
  6978. // catch (Exception ex)
  6979. // {
  6980. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  6981. // string str = ex.StackTrace;
  6982. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6983. // }
  6984. // #endregion Tray盘上料装备-将SN发给ICT标机
  6985. // #region Tray盘上料装备-点检数据
  6986. // //try
  6987. // //{
  6988. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  6989. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  6990. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  6991. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  6992. // // if (pLC_Flag && !mES_Flag) // 1 0
  6993. // // {
  6994. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  6995. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  6996. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  6997. // // }
  6998. // // else if (!pLC_Flag && mES_Flag) // 0 1
  6999. // // {
  7000. // // // 清空写给PLC的数据
  7001. // // // MES_Flag重置为0
  7002. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  7003. // // }
  7004. // //}
  7005. // //catch (Exception ex)
  7006. // //{
  7007. // // // MES_Flag 为2上位机报错
  7008. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  7009. // // string str = ex.StackTrace;
  7010. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7011. // //}
  7012. // #endregion Tray盘上料装备-点检数据
  7013. // #region 节拍接口
  7014. // try
  7015. // {
  7016. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  7017. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  7018. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  7019. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  7020. // {
  7021. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  7022. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7023. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  7024. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  7025. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  7026. // }
  7027. // }
  7028. // catch (Exception ex)
  7029. // {
  7030. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  7031. // string str = ex.StackTrace;
  7032. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7033. // }
  7034. // #endregion 节拍接口
  7035. // #region AGV上料
  7036. // // AGV上料叫AGV信号
  7037. // try
  7038. // {
  7039. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  7040. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  7041. // if (a1AGVUpCall != a1AGVUpCallOld)
  7042. // {
  7043. // if (a1AGVUpCall == 1) // 0->1
  7044. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  7045. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  7046. // }
  7047. // }
  7048. // catch (Exception ex)
  7049. // {
  7050. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  7051. // string str = ex.StackTrace;
  7052. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7053. // }
  7054. // // AGV上料完成信号
  7055. // try
  7056. // {
  7057. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  7058. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  7059. // if (a1AGVUpEnd != a1AGVUpEndOld)
  7060. // {
  7061. // if (a1AGVUpEnd == 1) // 0->1
  7062. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  7063. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  7064. // }
  7065. // }
  7066. // catch (Exception ex)
  7067. // {
  7068. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  7069. // string str = ex.StackTrace;
  7070. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7071. // }
  7072. // #endregion AGV上料
  7073. // #region AGV下料
  7074. // // AGV下料叫agv信号
  7075. // try
  7076. // {
  7077. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  7078. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  7079. // if (a1AGVDownCall != a1AGVDownCallOld)
  7080. // {
  7081. // if (a1AGVDownCall == 1) // 0->1
  7082. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  7083. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  7084. // }
  7085. // }
  7086. // catch (Exception ex)
  7087. // {
  7088. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  7089. // string str = ex.StackTrace;
  7090. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7091. // }
  7092. // // AGV下料完成信号
  7093. // try
  7094. // {
  7095. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  7096. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  7097. // if (a1AGVDownEnd != a1AGVDownEndOld)
  7098. // {
  7099. // if (a1AGVDownEnd == 1) // 0->1
  7100. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  7101. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  7102. // }
  7103. // }
  7104. // catch (Exception ex)
  7105. // {
  7106. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  7107. // string str = ex.StackTrace;
  7108. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7109. // }
  7110. // #endregion AGV下料
  7111. // #region 心跳
  7112. // try
  7113. // {
  7114. // short states = 0;
  7115. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7116. // }
  7117. // catch (Exception ex)
  7118. // {
  7119. // string str = ex.StackTrace;
  7120. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7121. // }
  7122. // #endregion 心跳
  7123. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7124. // stopwatch1.Stop();
  7125. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7126. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7127. // }
  7128. // else
  7129. // {
  7130. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7131. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  7132. // Funs[plcNo].Connect(); // 重连
  7133. // }
  7134. // }
  7135. // catch (Exception ex)
  7136. // {
  7137. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7138. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  7139. // Funs[plcNo].ReConnect();
  7140. // }
  7141. // Thread.Sleep(IntervalReadPLC);
  7142. // }
  7143. //}
  7144. /// <summary>
  7145. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  7146. /// </summary>
  7147. /// <param name="plcNo">PLC编号</param>
  7148. /// <param name="stationNameStr">工站全称</param>
  7149. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  7150. {
  7151. Stopwatch stopwatch1 = new Stopwatch();
  7152. Stopwatch stopwatch2 = new Stopwatch();
  7153. try
  7154. {
  7155. stopwatch1.Start();
  7156. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  7157. sn = sn.Replace("\0", "");
  7158. #region 查询载具上的产品信息
  7159. string cavityData = string.Empty;
  7160. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  7161. if (string.IsNullOrEmpty(cavityData))
  7162. cavityData = "";
  7163. if (snResult != 0)
  7164. {
  7165. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7166. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  7167. writeToPLC_Flag1.Adress = 2003;
  7168. writeToPLC_Flag1.Value = (short)6;
  7169. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  7170. stopwatch1.Stop();
  7171. AddMessage(LogType.Info,
  7172. stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  7173. "ms");
  7174. return;
  7175. }
  7176. #endregion 查询载具上的产品信息
  7177. string[] cavitySNs = cavityData.Split('.');
  7178. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  7179. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  7180. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  7181. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  7182. if (cavitySNs != null && cavitySNs.Length >= 2)
  7183. {
  7184. a1CavitySN1_VehicleStates = cavitySNs[0];
  7185. a1CavitySN2_VehicleStates = cavitySNs[1];
  7186. a1CavityResult1_VehicleStates = 2;
  7187. a1CavityResult2_VehicleStates = 2;
  7188. }
  7189. if (a1CavitySN1_VehicleStates == "假产品")
  7190. a1CavityResult1_VehicleStates = 3;
  7191. if (a1CavitySN2_VehicleStates == "假产品")
  7192. a1CavityResult2_VehicleStates = 3;
  7193. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7194. // 回写
  7195. stopwatch2.Start();
  7196. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  7197. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  7198. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  7199. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  7200. //// MES_Flag
  7201. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  7202. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7203. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  7204. writeToPLC_Flag.Adress = 2003;
  7205. writeToPLC_Flag.Value = mES_Flag;
  7206. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7207. {
  7208. Name = "a1CavitySN1_VehicleStates",
  7209. Adress = 2024,
  7210. ValueType = PLCValueType.String,
  7211. ValueTypeStrLength = 20,
  7212. Value = a1CavitySN1_VehicleStates
  7213. });
  7214. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  7215. {
  7216. Name = "a1CavitySN2_VehicleStates",
  7217. Adress = 2044,
  7218. ValueType = PLCValueType.String,
  7219. ValueTypeStrLength = 20,
  7220. Value = a1CavitySN2_VehicleStates
  7221. });
  7222. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  7223. {
  7224. Name = "a1CavityResult1_VehicleStates",
  7225. Adress = 2064,
  7226. ValueType = PLCValueType.Short,
  7227. Value = a1CavityResult1_VehicleStates
  7228. });
  7229. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  7230. {
  7231. Name = "a1CavityResult2_VehicleStates",
  7232. Adress = 2065,
  7233. ValueType = PLCValueType.Short,
  7234. Value = a1CavityResult2_VehicleStates
  7235. });
  7236. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  7237. stopwatch2.Stop();
  7238. }
  7239. catch (Exception ex)
  7240. {
  7241. string str = ex.StackTrace;
  7242. AddMessage_Station(stationNameStr, LogType.Error,
  7243. $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" +
  7244. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7245. // MES_Flag
  7246. stopwatch2.Start();
  7247. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7248. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7249. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  7250. writeToPLC_Flag.Adress = 2003;
  7251. writeToPLC_Flag.Value = (short)6;
  7252. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  7253. stopwatch2.Stop();
  7254. }
  7255. stopwatch1.Stop();
  7256. AddMessage(LogType.Info,
  7257. stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7258. stopwatch2.ElapsedMilliseconds + "ms");
  7259. }
  7260. /// <summary>
  7261. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  7262. /// </summary>
  7263. /// <param name="plcNo">PLC编号</param>
  7264. /// <param name="stationNameStr">工站全称</param>
  7265. private void S1上料进站校验(int plcNo, string stationNameStr)
  7266. {
  7267. Stopwatch stopwatch1 = new Stopwatch();
  7268. Stopwatch stopwatch2 = new Stopwatch();
  7269. try
  7270. {
  7271. stopwatch1.Start();
  7272. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  7273. sn = sn.Replace("\0", "");
  7274. // 保存进站数据+调用进站MES接口
  7275. List<TestItem> item = new List<TestItem>();
  7276. stopwatch2.Start();
  7277. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  7278. item, out string errorMsg);
  7279. stopwatch2.Stop();
  7280. short a1MES_FLAG_Check = (short)result;
  7281. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7282. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7283. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  7284. writeToPLC_Flag.Adress = 2077;
  7285. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  7286. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  7287. }
  7288. catch (Exception ex)
  7289. {
  7290. string str = ex.StackTrace;
  7291. AddMessage_Station(stationNameStr, LogType.Error,
  7292. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  7293. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7294. // MES_Flag
  7295. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7296. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7297. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  7298. writeToPLC_Flag.Adress = 2077;
  7299. writeToPLC_Flag.Value = (short)6;
  7300. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  7301. }
  7302. stopwatch1.Stop();
  7303. AddMessage(LogType.Info,
  7304. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  7305. stopwatch2.ElapsedMilliseconds + "ms");
  7306. }
  7307. /// <summary>
  7308. /// [S1] Tray盘上料装备(板测)- 出站接口
  7309. /// </summary>
  7310. /// <param name="plcNo"></param>
  7311. /// <param name="stationCode"></param>
  7312. /// <param name="stationName"></param>
  7313. private void S1出站接口(int plcNo, string stationCode, string stationName)
  7314. {
  7315. Stopwatch stopwatch1 = new Stopwatch();
  7316. Stopwatch stopwatch2 = new Stopwatch();
  7317. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7318. string stationNameStr = stationCode + stationName;
  7319. string processItem = stationName; // 测试项目
  7320. try
  7321. {
  7322. stopwatch1.Start();
  7323. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7324. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7325. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7326. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7327. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  7328. sn = sn.Replace("\0", "");
  7329. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  7330. partNo1 = partNo1.Replace("\0", "");
  7331. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  7332. partNo2 = partNo2.Replace("\0", "");
  7333. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  7334. bool pass = a1Result == 1;
  7335. stopwatch2.Start();
  7336. // 产品1
  7337. List<TestItem> items = new List<TestItem>();
  7338. items.Add(new TestItem()
  7339. {
  7340. Parameter_name = "载具码",
  7341. Parameter_value = sn,
  7342. Parameter_unit = ""
  7343. });
  7344. items.Add(new TestItem()
  7345. {
  7346. Parameter_name = "载具穴号",
  7347. Parameter_value = "1",
  7348. Parameter_unit = ""
  7349. });
  7350. items.Add(new TestItem()
  7351. {
  7352. Parameter_name = "产品结果",
  7353. Parameter_value = a1Result == 1 ? "OK" : "NG",
  7354. Parameter_unit = ""
  7355. });
  7356. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  7357. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  7358. // 产品2
  7359. items = new List<TestItem>();
  7360. items.Add(new TestItem()
  7361. {
  7362. Parameter_name = "载具码",
  7363. Parameter_value = sn,
  7364. Parameter_unit = ""
  7365. });
  7366. items.Add(new TestItem()
  7367. {
  7368. Parameter_name = "载具穴号",
  7369. Parameter_value = "2",
  7370. Parameter_unit = ""
  7371. });
  7372. items.Add(new TestItem()
  7373. {
  7374. Parameter_name = "产品结果",
  7375. Parameter_value = a1Result == 1 ? "OK" : "NG",
  7376. Parameter_unit = ""
  7377. });
  7378. int result2 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  7379. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  7380. short result = 0;
  7381. List<int> results = new List<int>() { result1, result2 };
  7382. if (result1 == 1 && result2 == 1)
  7383. result = 1;
  7384. else if (results.Contains(3))
  7385. result = 3;
  7386. else if (results.Contains(2))
  7387. result = 2;
  7388. else if (results.Contains(4))
  7389. result = 4;
  7390. else
  7391. result = 4;
  7392. stopwatch2.Stop();
  7393. #region 存储绑定数据到 边线MES系统中
  7394. if (result == 1)
  7395. {
  7396. string data = string.Concat(partNo1, ".", partNo2);
  7397. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7398. if (resultMesR != 0)
  7399. {
  7400. result = 4;
  7401. AddMessage_Station(stationNameStr, LogType.Error,
  7402. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  7403. }
  7404. }
  7405. #endregion 存储绑定数据到 边线MES系统中
  7406. // MES_Flag 为MES报错
  7407. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7408. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  7409. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7410. writeToPLC_Flag.Name = "a1MES_FLAG";
  7411. writeToPLC_Flag.Adress = 2109;
  7412. writeToPLC_Flag.Value = result;
  7413. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  7414. OnMessage(LogType.Debug,
  7415. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7416. }
  7417. catch (Exception ex)
  7418. {
  7419. stopwatch2.Restart();
  7420. // MES_Flag 为4上位机报错
  7421. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  7422. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7423. writeToPLC_Flag.Name = "a1MES_FLAG";
  7424. writeToPLC_Flag.Adress = 2109;
  7425. writeToPLC_Flag.Value = (short)4;
  7426. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  7427. stopwatch2.Stop();
  7428. string str = ex.StackTrace;
  7429. AddMessage_Station(stationNameStr, LogType.Error,
  7430. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  7431. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7432. }
  7433. stopwatch1.Stop();
  7434. AddMessage(LogType.Info,
  7435. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  7436. stopwatch2.ElapsedMilliseconds + "ms");
  7437. }
  7438. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  7439. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  7440. //{
  7441. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7442. // string stationNameStr = stationCode + stationName;
  7443. // string processItem = stationName; // 测试项目
  7444. // try
  7445. // {
  7446. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7447. // string accno = "1"; // 工序编号
  7448. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  7449. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  7450. // List<OneCheckItem> items = new List<OneCheckItem>()
  7451. // {
  7452. // new OneCheckItem()
  7453. // {
  7454. // Onecheck_name="胶圈装配行程设定上限",
  7455. // Onecheck_content="上限值",
  7456. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  7457. // },
  7458. // };
  7459. // OneCheckData oneCheckData = new OneCheckData()
  7460. // {
  7461. // Line_code = GlobalContext.LineCode,
  7462. // Line_name = GlobalContext.LineName,
  7463. // Equipment_code = equipmentCode,
  7464. // Equipment_name = equipmentCode,
  7465. // Workorder_code = workorder_code,
  7466. // Procedure_code = accno,
  7467. // Procedure_name = processItem,
  7468. // Oneckeck_values = items,
  7469. // Onecheck_empcode = "",
  7470. // Onecheck_empname = "",
  7471. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  7472. // };
  7473. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  7474. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  7475. // short result = result1 == 1 ? (short)1 : (short)2;
  7476. // // MES_Flag 为4MES报错
  7477. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  7478. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7479. // }
  7480. // catch (Exception ex)
  7481. // {
  7482. // // MES_Flag 为2上位机报错
  7483. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  7484. // string str = ex.StackTrace;
  7485. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7486. // }
  7487. //}
  7488. // ReadStation_S1_2 节拍接口+AGV
  7489. /// <summary>
  7490. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  7491. /// </summary>
  7492. /// <param name="plcNo">PLC编号</param>
  7493. /// <param name="stationNameStr">工站全称</param>
  7494. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  7495. {
  7496. Stopwatch stopwatch1 = new Stopwatch();
  7497. Stopwatch stopwatch2 = new Stopwatch();
  7498. try
  7499. {
  7500. stopwatch1.Start();
  7501. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  7502. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  7503. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  7504. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  7505. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  7506. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  7507. // ZS 将SN发给ICT标机(串口)
  7508. short a1MES_FLAG_ICT = 1;
  7509. stopwatch2.Start();
  7510. // MES_Flag
  7511. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  7512. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7513. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  7514. writeToPLC_Flag.Adress = 2182;
  7515. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  7516. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  7517. stopwatch2.Stop();
  7518. }
  7519. catch (Exception ex)
  7520. {
  7521. string str = ex.StackTrace;
  7522. AddMessage_Station(stationNameStr, LogType.Error,
  7523. $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" +
  7524. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7525. stopwatch2.Start();
  7526. // MES_Flag
  7527. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  7528. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7529. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  7530. writeToPLC_Flag.Adress = 2182;
  7531. writeToPLC_Flag.Value = (short)4;
  7532. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  7533. stopwatch2.Stop();
  7534. }
  7535. stopwatch1.Stop();
  7536. AddMessage(LogType.Info,
  7537. stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7538. stopwatch2.ElapsedMilliseconds + "ms");
  7539. }
  7540. /// <summary>
  7541. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  7542. /// </summary>
  7543. /// <param name="plcNo">PLC编号</param>
  7544. /// <param name="stationNameStr">工站全称</param>
  7545. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  7546. {
  7547. Stopwatch stopwatch1 = new Stopwatch();
  7548. Stopwatch stopwatch2 = new Stopwatch();
  7549. try
  7550. {
  7551. stopwatch1.Start();
  7552. // ZS 呼叫AGV
  7553. short a1AGVUpCall = 2;
  7554. stopwatch2.Start();
  7555. // a1AGVUpCall
  7556. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7557. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7558. writeToPLC_Flag.Name = "a1AGVUpCall";
  7559. writeToPLC_Flag.Adress = 2307;
  7560. writeToPLC_Flag.Value = a1AGVUpCall;
  7561. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  7562. stopwatch2.Stop();
  7563. }
  7564. catch (Exception ex)
  7565. {
  7566. string str = ex.StackTrace;
  7567. AddMessage_Station(stationNameStr, LogType.Error,
  7568. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  7569. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7570. // a1AGVUpCall
  7571. stopwatch2.Start();
  7572. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  7573. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7574. writeToPLC_Flag.Name = "a1AGVUpCall";
  7575. writeToPLC_Flag.Adress = 2307;
  7576. writeToPLC_Flag.Value = (short)4;
  7577. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  7578. stopwatch2.Stop();
  7579. }
  7580. stopwatch1.Stop();
  7581. AddMessage(LogType.Info,
  7582. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7583. stopwatch2.ElapsedMilliseconds + "ms");
  7584. }
  7585. /// <summary>
  7586. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  7587. /// </summary>
  7588. /// <param name="plcNo">PLC编号</param>
  7589. /// <param name="stationNameStr">工站全称</param>
  7590. private void S1AGV上料完成(int plcNo, string stationNameStr)
  7591. {
  7592. Stopwatch stopwatch1 = new Stopwatch();
  7593. Stopwatch stopwatch2 = new Stopwatch();
  7594. try
  7595. {
  7596. stopwatch1.Start();
  7597. // ZS AGV上料完成,让小车离开
  7598. short a1AGVUpEnd = 2;
  7599. stopwatch2.Start();
  7600. // a1AGVUpEnd
  7601. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7602. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7603. writeToPLC_Flag.Name = "a1AGVUpEnd";
  7604. writeToPLC_Flag.Adress = 2309;
  7605. writeToPLC_Flag.Value = a1AGVUpEnd;
  7606. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  7607. stopwatch2.Stop();
  7608. }
  7609. catch (Exception ex)
  7610. {
  7611. string str = ex.StackTrace;
  7612. AddMessage_Station(stationNameStr, LogType.Error,
  7613. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  7614. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7615. // a1AGVUpEnd
  7616. stopwatch2.Start();
  7617. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  7618. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7619. writeToPLC_Flag.Name = "a1AGVUpEnd";
  7620. writeToPLC_Flag.Adress = 2309;
  7621. writeToPLC_Flag.Value = (short)4;
  7622. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  7623. stopwatch2.Stop();
  7624. }
  7625. stopwatch1.Stop();
  7626. AddMessage(LogType.Info,
  7627. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7628. stopwatch2.ElapsedMilliseconds + "ms");
  7629. }
  7630. /// <summary>
  7631. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  7632. /// </summary>
  7633. /// <param name="plcNo">PLC编号</param>
  7634. /// <param name="stationNameStr">工站全称</param>
  7635. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  7636. {
  7637. Stopwatch stopwatch1 = new Stopwatch();
  7638. Stopwatch stopwatch2 = new Stopwatch();
  7639. try
  7640. {
  7641. stopwatch1.Start();
  7642. // ZS 呼叫AGV
  7643. short a1AGVDownCall = 2;
  7644. stopwatch2.Start();
  7645. // a1AGVDownCall
  7646. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7647. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7648. writeToPLC_Flag.Name = "a1AGVDownCall";
  7649. writeToPLC_Flag.Adress = 2320;
  7650. writeToPLC_Flag.Value = a1AGVDownCall;
  7651. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  7652. stopwatch2.Stop();
  7653. }
  7654. catch (Exception ex)
  7655. {
  7656. string str = ex.StackTrace;
  7657. AddMessage_Station(stationNameStr, LogType.Error,
  7658. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  7659. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7660. // a1AGVDownCall
  7661. stopwatch2.Start();
  7662. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  7663. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7664. writeToPLC_Flag.Name = "a1AGVDownCall";
  7665. writeToPLC_Flag.Adress = 2320;
  7666. writeToPLC_Flag.Value = (short)4;
  7667. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  7668. stopwatch2.Stop();
  7669. }
  7670. stopwatch1.Stop();
  7671. AddMessage(LogType.Info,
  7672. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7673. stopwatch2.ElapsedMilliseconds + "ms");
  7674. }
  7675. /// <summary>
  7676. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  7677. /// </summary>
  7678. /// <param name="plcNo">PLC编号</param>
  7679. /// <param name="stationNameStr">工站全称</param>
  7680. private void S1AGV下料完成(int plcNo, string stationNameStr)
  7681. {
  7682. Stopwatch stopwatch1 = new Stopwatch();
  7683. Stopwatch stopwatch2 = new Stopwatch();
  7684. try
  7685. {
  7686. stopwatch1.Start();
  7687. // ZS AGV上料完成,让小车离开
  7688. short a1AGVDownEnd = 2;
  7689. stopwatch2.Start();
  7690. // a1AGVDownEnd
  7691. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7692. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7693. writeToPLC_Flag.Name = "a1AGVDownEnd";
  7694. writeToPLC_Flag.Adress = 2322;
  7695. writeToPLC_Flag.Value = a1AGVDownEnd;
  7696. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  7697. stopwatch2.Stop();
  7698. }
  7699. catch (Exception ex)
  7700. {
  7701. string str = ex.StackTrace;
  7702. AddMessage_Station(stationNameStr, LogType.Error,
  7703. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  7704. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7705. // a1AGVDownEnd
  7706. stopwatch2.Start();
  7707. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  7708. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7709. writeToPLC_Flag.Name = "a1AGVDownEnd";
  7710. writeToPLC_Flag.Adress = 2322;
  7711. writeToPLC_Flag.Value = (short)4;
  7712. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  7713. stopwatch2.Stop();
  7714. }
  7715. stopwatch1.Stop();
  7716. AddMessage(LogType.Info,
  7717. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7718. stopwatch2.ElapsedMilliseconds + "ms");
  7719. }
  7720. #endregion [S1] Tray盘上料装备(板测)
  7721. #endregion PLC1 张超凡
  7722. #region PLC2 李晓奇
  7723. #region [S2] FCT(板测)
  7724. /// <summary>
  7725. /// S2工位的数据- 触发信号上次的值
  7726. /// </summary>
  7727. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  7728. /// <summary>
  7729. /// S2工位的数据(含触发信号)
  7730. /// </summary>
  7731. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  7732. /// <summary>
  7733. /// S2工位的数据- 回写点位
  7734. /// </summary>
  7735. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  7736. /// <summary>
  7737. /// [S2] FCT(板测)
  7738. /// </summary>
  7739. /// <param name="plcNo">PLC编号</param>
  7740. //private void ReadStation_S2(int plcNo)
  7741. //{
  7742. // // [S1] Tray盘上料装备
  7743. // // [S2] FCT
  7744. // // [S3] 值板机
  7745. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  7746. // // [S5] Tray盘下料装备
  7747. // /// 上位机心跳
  7748. // /// 获取设备报警数据与状态信息
  7749. // string stationCode = "[S2]";
  7750. // string stationName = "FCT";
  7751. // string stationNameStr = stationCode + stationName;
  7752. // #region 创建字典
  7753. // // 触发信号字典 赋值
  7754. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  7755. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  7756. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  7757. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  7758. // // PLC数据字典 赋值
  7759. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  7760. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  7761. // s2PLCData.Add("b1ProductSN_Check", 0);
  7762. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  7763. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  7764. // s2PLCData.Add("b1ProductSN_Unbind", "");
  7765. // s2PLCData.Add("b1ProductSN_Bind", "");
  7766. // s2PLCData.Add("b1Part1SN_Bind", "");
  7767. // s2PLCData.Add("b1Part2SN_Bind", "");
  7768. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  7769. // s2PLCData.Add("b1MES_FLAG", 0);
  7770. // s2PLCData.Add("b1ProductSN", 0);
  7771. // s2PLCData.Add("b1Part1Result", 0);
  7772. // s2PLCData.Add("b1Part2Result", 0);
  7773. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  7774. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  7775. // s2PLCData.Add("b1OEEProductSN", "");
  7776. // s2PLCData.Add("b1OEEType", 0);
  7777. // #endregion 创建字典
  7778. // while (IsRun)
  7779. // {
  7780. // try
  7781. // {
  7782. // if (!GlobalContext._IsCon_Funs2)
  7783. // {
  7784. // UpdatePLCMonitor(1, plcNo, 0);
  7785. // continue;
  7786. // }
  7787. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  7788. // {
  7789. // Stopwatch stopwatch1 = new Stopwatch();
  7790. // Stopwatch stopwatch2 = new Stopwatch();
  7791. // stopwatch1.Start();
  7792. // stopwatch2.Start();
  7793. // #region 一次性读取所有数据
  7794. // // 一次性读取所有数据
  7795. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  7796. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  7797. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  7798. // int[] datas = data1.Concat(data2).ToArray();
  7799. // datas = datas.Concat(data3).ToArray();
  7800. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  7801. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  7802. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  7803. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  7804. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  7805. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  7806. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  7807. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  7808. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  7809. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  7810. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  7811. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  7812. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  7813. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  7814. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  7815. // s2PLCData["b1MES_FLAG"] = datas[169];
  7816. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  7817. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  7818. // s2PLCData["b1Part1Result"] = datas[190];
  7819. // s2PLCData["b1Part2Result"] = datas[191];
  7820. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  7821. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  7822. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  7823. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  7824. // s2PLCData["b1OEEType"] = datas[224];
  7825. // #endregion 一次性读取所有数据
  7826. // stopwatch2.Stop();
  7827. // #region 回写操作,写后清空flag
  7828. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  7829. // #endregion 回写操作,写后清空flag
  7830. // #region 进站校验
  7831. // try
  7832. // {
  7833. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  7834. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  7835. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  7836. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  7837. // {
  7838. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  7839. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  7840. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  7841. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  7842. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  7843. // }
  7844. // }
  7845. // catch (Exception ex)
  7846. // {
  7847. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7848. // string str = ex.StackTrace;
  7849. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7850. // }
  7851. // #endregion 进站校验
  7852. // #region 二穴载具解绑/绑定(产品换载具)
  7853. // try
  7854. // {
  7855. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  7856. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  7857. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  7858. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  7859. // {
  7860. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  7861. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  7862. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  7863. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  7864. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  7865. // }
  7866. // }
  7867. // catch (Exception ex)
  7868. // {
  7869. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7870. // string str = ex.StackTrace;
  7871. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7872. // }
  7873. // #endregion 二穴载具解绑/绑定(产品换载具)
  7874. // #region FCT-出站接口
  7875. // try
  7876. // {
  7877. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  7878. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  7879. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  7880. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  7881. // {
  7882. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  7883. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  7884. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  7885. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  7886. // }
  7887. // }
  7888. // catch (Exception ex)
  7889. // {
  7890. // // MES_Flag 为6上位机报错
  7891. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  7892. // string str = ex.StackTrace;
  7893. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7894. // }
  7895. // #endregion FCT-出站接口
  7896. // #region 节拍接口
  7897. // try
  7898. // {
  7899. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  7900. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  7901. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  7902. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  7903. // {
  7904. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  7905. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7906. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  7907. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  7908. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  7909. // }
  7910. // }
  7911. // catch (Exception ex)
  7912. // {
  7913. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  7914. // string str = ex.StackTrace;
  7915. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7916. // }
  7917. // #endregion 节拍接口
  7918. // #region 心跳
  7919. // try
  7920. // {
  7921. // short states = 0;
  7922. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7923. // }
  7924. // catch (Exception ex)
  7925. // {
  7926. // string str = ex.StackTrace;
  7927. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7928. // }
  7929. // #endregion 心跳
  7930. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7931. // stopwatch1.Stop();
  7932. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7933. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7934. // }
  7935. // else
  7936. // {
  7937. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7938. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  7939. // Funs[plcNo].Connect();
  7940. // }
  7941. // }
  7942. // catch (Exception ex)
  7943. // {
  7944. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7945. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  7946. // Funs[plcNo].ReConnect();
  7947. // }
  7948. // Thread.Sleep(IntervalReadPLC);
  7949. // }
  7950. //}
  7951. /// <summary>
  7952. /// [S2] FCT(板测)- 进站校验
  7953. /// </summary>
  7954. /// <param name="plcNo">PLC编号</param>
  7955. /// <param name="stationNameStr">工站全称</param>
  7956. private void S2进站校验(int plcNo, string stationNameStr)
  7957. {
  7958. Stopwatch stopwatch1 = new Stopwatch();
  7959. Stopwatch stopwatch2 = new Stopwatch();
  7960. try
  7961. {
  7962. stopwatch1.Start();
  7963. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  7964. sn = sn.Replace("\0", "");
  7965. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  7966. // 查询物料码By载具码 并判断是不是假产品
  7967. string cavityData = string.Empty;
  7968. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  7969. if (string.IsNullOrEmpty(cavityData))
  7970. cavityData = "";
  7971. if (snResult != 0)
  7972. {
  7973. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7974. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  7975. writeToPLC_Flag1.Adress = 2003;
  7976. writeToPLC_Flag1.Value = (short)6;
  7977. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  7978. stopwatch1.Stop();
  7979. AddMessage(LogType.Info,
  7980. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7981. return;
  7982. }
  7983. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  7984. string[] cavitySNs = cavityData.Split('.');
  7985. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  7986. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  7987. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  7988. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  7989. if (cavitySNs != null && cavitySNs.Length >= 2)
  7990. {
  7991. b1Part1SN_Check = cavitySNs[0];
  7992. b1Part2SN_Check = cavitySNs[1];
  7993. b1Part1Result_Check = 2;
  7994. b1Part2Result_Check = 2;
  7995. }
  7996. if (b1Part1SN_Check == "假产品")
  7997. b1Part1Result_Check = 3;
  7998. if (b1Part2SN_Check == "假产品")
  7999. b1Part2Result_Check = 3;
  8000. // 调用MES进站
  8001. stopwatch2.Start();
  8002. // 调用MES进站 - 产品1
  8003. List<TestItem> item;
  8004. int result1 = b1Part1Result_Check;
  8005. if (result1 != 3)
  8006. {
  8007. item = new List<TestItem>();
  8008. item.Add(new TestItem()
  8009. {
  8010. Parameter_name = "载具码",
  8011. Parameter_value = sn,
  8012. });
  8013. item.Add(new TestItem()
  8014. {
  8015. Parameter_name = "载具穴号",
  8016. Parameter_value = "1",
  8017. });
  8018. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8019. b1Part1SN_Check, item, out string errorMsg);
  8020. }
  8021. // 调用MES进站 - 产品2
  8022. int result2 = b1Part2Result_Check;
  8023. if (result2 != 3)
  8024. {
  8025. item = new List<TestItem>();
  8026. item.Add(new TestItem()
  8027. {
  8028. Parameter_name = "载具码",
  8029. Parameter_value = sn,
  8030. });
  8031. item.Add(new TestItem()
  8032. {
  8033. Parameter_name = "载具穴号",
  8034. Parameter_value = "2",
  8035. });
  8036. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8037. b1Part2SN_Check, item, out string errorMsg);
  8038. }
  8039. stopwatch2.Stop();
  8040. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  8041. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  8042. int result = result1;
  8043. if (result == 1)
  8044. result = result2;
  8045. short b1MES_FLAG_Check = (short)result;
  8046. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  8047. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  8048. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  8049. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  8050. //// MES_Flag
  8051. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8052. WriteToPLC_Flag
  8053. writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8054. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  8055. writeToPLC_Flag.Adress = 2003;
  8056. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  8057. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8058. {
  8059. Name = "b1Part1SN_Check",
  8060. Adress = 2024,
  8061. ValueType = PLCValueType.String,
  8062. ValueTypeStrLength = 20,
  8063. Value = b1Part1SN_Check
  8064. });
  8065. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8066. {
  8067. Name = "b1Part2SN_Check",
  8068. Adress = 2044,
  8069. ValueType = PLCValueType.String,
  8070. ValueTypeStrLength = 20,
  8071. Value = b1Part2SN_Check
  8072. });
  8073. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8074. {
  8075. Name = "b1Part1Result_Check",
  8076. Adress = 2064,
  8077. ValueType = PLCValueType.Short,
  8078. Value = b1Part1Result_Check
  8079. });
  8080. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8081. {
  8082. Name = "b1Part2Result_Check",
  8083. Adress = 2065,
  8084. ValueType = PLCValueType.Short,
  8085. Value = b1Part2Result_Check
  8086. });
  8087. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  8088. }
  8089. catch (Exception ex)
  8090. {
  8091. string str = ex.StackTrace;
  8092. AddMessage_Station(stationNameStr, LogType.Error,
  8093. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  8094. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8095. // MES_Flag
  8096. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8097. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8098. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  8099. writeToPLC_Flag.Adress = 2003;
  8100. writeToPLC_Flag.Value = (short)6;
  8101. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  8102. }
  8103. stopwatch1.Stop();
  8104. AddMessage(LogType.Info,
  8105. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  8106. stopwatch2.ElapsedMilliseconds + "ms");
  8107. }
  8108. /// <summary>
  8109. /// [S2] FCT(板测)- 二穴载具解绑绑定
  8110. /// </summary>
  8111. /// <param name="plcNo">PLC编号</param>
  8112. /// <param name="stationNameStr">工站全称</param>
  8113. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  8114. {
  8115. Stopwatch stopwatch1 = new Stopwatch();
  8116. Stopwatch stopwatch2 = new Stopwatch();
  8117. try
  8118. {
  8119. stopwatch1.Start();
  8120. // 产品换载具
  8121. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  8122. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  8123. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  8124. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  8125. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  8126. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  8127. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  8128. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  8129. stopwatch2.Start();
  8130. #region 查询载具上的产品信息
  8131. //string cavityData = string.Empty;
  8132. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  8133. //if (string.IsNullOrEmpty(cavityData))
  8134. // cavityData = "";
  8135. //if (snResult != 0)
  8136. //{
  8137. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8138. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  8139. // writeToPLC_Flag.Adress = 2077;
  8140. // writeToPLC_Flag.Value = (short)6;
  8141. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  8142. // stopwatch1.Stop();
  8143. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8144. // return;
  8145. //}
  8146. #endregion 查询载具上的产品信息
  8147. #region 解绑(边线MES系统)
  8148. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  8149. if (snResult != 0)
  8150. {
  8151. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8152. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  8153. writeToPLC_Flag1.Adress = 2077;
  8154. writeToPLC_Flag1.Value = (short)6;
  8155. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  8156. stopwatch1.Stop();
  8157. AddMessage(LogType.Info,
  8158. stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" +
  8159. stopwatch1.ElapsedMilliseconds + "ms");
  8160. return;
  8161. }
  8162. #endregion 解绑(边线MES系统)
  8163. #region 存储绑定数据到 边线MES系统中
  8164. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  8165. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  8166. if (snResult != 0)
  8167. {
  8168. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8169. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  8170. writeToPLC_Flag1.Adress = 2077;
  8171. writeToPLC_Flag1.Value = (short)6;
  8172. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  8173. stopwatch1.Stop();
  8174. AddMessage(LogType.Info,
  8175. stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" +
  8176. stopwatch1.ElapsedMilliseconds + "ms");
  8177. return;
  8178. }
  8179. #endregion 存储绑定数据到 边线MES系统中
  8180. stopwatch2.Stop();
  8181. short b1MES_FLAG_Unbind = 1;
  8182. // MES_Flag
  8183. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8184. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8185. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  8186. writeToPLC_Flag.Adress = 2077;
  8187. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  8188. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  8189. }
  8190. catch (Exception ex)
  8191. {
  8192. string str = ex.StackTrace;
  8193. AddMessage_Station(stationNameStr, LogType.Error,
  8194. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" +
  8195. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8196. // MES_Flag
  8197. stopwatch2.Start();
  8198. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  8199. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8200. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  8201. writeToPLC_Flag.Adress = 2077;
  8202. writeToPLC_Flag.Value = (short)6;
  8203. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  8204. stopwatch2.Stop();
  8205. }
  8206. stopwatch1.Stop();
  8207. AddMessage(LogType.Info,
  8208. stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8209. stopwatch2.ElapsedMilliseconds + "ms");
  8210. }
  8211. //// 上次采集到的SN
  8212. //private string sn_FCT = string.Empty;
  8213. /// <summary>
  8214. /// [S2] FCT(板测)- 出站数据
  8215. /// </summary>
  8216. private void S2出站接口(int plcNo, string stationCode, string stationName)
  8217. {
  8218. Stopwatch stopwatch1 = new Stopwatch();
  8219. Stopwatch stopwatch2 = new Stopwatch();
  8220. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8221. string stationNameStr = stationCode + stationName;
  8222. string processItem = stationName; // 测试项目
  8223. try
  8224. {
  8225. stopwatch1.Start();
  8226. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8227. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8228. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8229. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8230. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  8231. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  8232. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  8233. bool pass1 = b1Part1Result == 1;
  8234. bool pass2 = b1Part2Result == 1;
  8235. #region 根据 载具SN 查 物料SN
  8236. string cavityData = string.Empty;
  8237. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  8238. if (string.IsNullOrEmpty(cavityData))
  8239. cavityData = "";
  8240. if (snResult != 0)
  8241. {
  8242. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8243. writeToPLC_Flag1.Name = "b1MES_FLAG";
  8244. writeToPLC_Flag1.Adress = 2169;
  8245. writeToPLC_Flag1.Value = (short)4;
  8246. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  8247. stopwatch1.Stop();
  8248. AddMessage(LogType.Info,
  8249. stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8250. "ms");
  8251. return;
  8252. }
  8253. #endregion 根据 载具SN 查 物料SN
  8254. string[] cavitySNs = cavityData.Split('.');
  8255. string b1ProductSN1 = string.Empty;
  8256. string b1ProductSN2 = string.Empty;
  8257. if (cavitySNs != null && cavitySNs.Length >= 2)
  8258. {
  8259. b1ProductSN1 = cavitySNs[0];
  8260. b1ProductSN2 = cavitySNs[1];
  8261. }
  8262. stopwatch2.Start();
  8263. // 产品1
  8264. int result1 = 0;
  8265. if (b1ProductSN1 == "假产品")
  8266. result1 = 1;
  8267. else
  8268. {
  8269. List<TestItem> items1 = new List<TestItem>();
  8270. items1.Add(new TestItem()
  8271. {
  8272. Parameter_name = "载具码",
  8273. Parameter_value = b1ProductSN.ToString(),
  8274. Parameter_unit = ""
  8275. });
  8276. items1.Add(new TestItem()
  8277. {
  8278. Parameter_name = "载具穴号",
  8279. Parameter_value = "1",
  8280. Parameter_unit = ""
  8281. });
  8282. items1.Add(new TestItem()
  8283. {
  8284. Parameter_name = "产品结果",
  8285. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  8286. Parameter_unit = ""
  8287. });
  8288. result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  8289. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  8290. }
  8291. // 产品2
  8292. int result2 = 0;
  8293. if (b1ProductSN1 == "假产品")
  8294. result2 = 1;
  8295. else
  8296. {
  8297. List<TestItem> items2 = new List<TestItem>();
  8298. items2.Add(new TestItem()
  8299. {
  8300. Parameter_name = "载具码",
  8301. Parameter_value = b1ProductSN.ToString(),
  8302. Parameter_unit = ""
  8303. });
  8304. items2.Add(new TestItem()
  8305. {
  8306. Parameter_name = "载具穴号",
  8307. Parameter_value = "2",
  8308. Parameter_unit = ""
  8309. });
  8310. items2.Add(new TestItem()
  8311. {
  8312. Parameter_name = "产品结果",
  8313. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  8314. Parameter_unit = ""
  8315. });
  8316. result2 = SwitctProcessData_old(stationNameStr, items2, equipmentCode, processItem
  8317. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  8318. }
  8319. short result = 0;
  8320. List<int> results = new List<int>() { result1, result2 };
  8321. if (result1 == 1 && result2 == 1)
  8322. result = 1;
  8323. else if (results.Contains(3))
  8324. result = 3;
  8325. else if (results.Contains(2))
  8326. result = 2;
  8327. else if (results.Contains(4))
  8328. result = 4;
  8329. else
  8330. result = 4;
  8331. stopwatch2.Stop();
  8332. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8333. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8334. writeToPLC_Flag.Name = "b1MES_FLAG";
  8335. writeToPLC_Flag.Adress = 2169;
  8336. writeToPLC_Flag.Value = result;
  8337. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  8338. OnMessage(LogType.Debug,
  8339. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8340. }
  8341. catch (Exception ex)
  8342. {
  8343. stopwatch2.Restart();
  8344. // MES_Flag 为4上位机报错
  8345. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  8346. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8347. writeToPLC_Flag.Name = "b1MES_FLAG";
  8348. writeToPLC_Flag.Adress = 2169;
  8349. writeToPLC_Flag.Value = (short)4;
  8350. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  8351. stopwatch2.Stop();
  8352. string str = ex.StackTrace;
  8353. AddMessage_Station(stationNameStr, LogType.Error,
  8354. $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  8355. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8356. }
  8357. stopwatch1.Stop();
  8358. AddMessage(LogType.Info,
  8359. stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  8360. stopwatch2.ElapsedMilliseconds + "ms");
  8361. }
  8362. #endregion [S2] FCT(板测)
  8363. #endregion PLC2 李晓奇
  8364. #region PLC3 刘永村
  8365. #region [S3] 值板机
  8366. /// <summary>
  8367. /// S3工位的数据- 触发信号上次的值
  8368. /// </summary>
  8369. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  8370. /// <summary>
  8371. /// S3工位的数据(含触发信号)
  8372. /// </summary>
  8373. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  8374. /// <summary>
  8375. /// S3工位的数据- 回写点位
  8376. /// </summary>
  8377. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8378. /// <summary>
  8379. /// [S3] 值板机
  8380. /// </summary>
  8381. /// <param name="plcNo">PLC编号</param>
  8382. //private void ReadStation_S3(int plcNo)
  8383. //{
  8384. // // [S1] Tray盘上料装备
  8385. // // [S2] FCT
  8386. // // [S3] 值板机
  8387. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8388. // // [S5] Tray盘下料装备
  8389. // /// 上位机心跳
  8390. // /// 获取设备报警数据与状态信息
  8391. // string stationCode = "[S3]";
  8392. // string stationName = "值板机";
  8393. // string stationNameStr = stationCode + stationName;
  8394. // #region 创建字典
  8395. // // 触发信号字典 赋值
  8396. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8397. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  8398. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  8399. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8400. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8401. // // PLC数据字典 赋值
  8402. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8403. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  8404. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8405. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  8406. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  8407. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8408. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8409. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  8410. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  8411. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8412. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  8413. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  8414. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8415. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8416. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  8417. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  8418. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  8419. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8420. // s3PLCData.Add("c1Result", 0); // 产品结果
  8421. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8422. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  8423. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  8424. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  8425. // #endregion 创建字典
  8426. // while (IsRun)
  8427. // {
  8428. // try
  8429. // {
  8430. // if (!GlobalContext._IsCon_Funs3)
  8431. // {
  8432. // UpdatePLCMonitor(1, plcNo, 0);
  8433. // continue;
  8434. // }
  8435. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8436. // {
  8437. // Stopwatch stopwatch1 = new Stopwatch();
  8438. // Stopwatch stopwatch2 = new Stopwatch();
  8439. // stopwatch1.Start();
  8440. // stopwatch2.Start();
  8441. // #region 一次性读取所有数据
  8442. // // 一次性读取所有数据
  8443. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  8444. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8445. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  8446. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  8447. // int[] datas = data1.Concat(data2).ToArray();
  8448. // datas = datas.Concat(data3).ToArray();
  8449. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  8450. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  8451. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8452. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  8453. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  8454. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  8455. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8456. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  8457. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  8458. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  8459. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  8460. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8461. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  8462. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  8463. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  8464. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  8465. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8466. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  8467. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  8468. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  8469. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  8470. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  8471. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  8472. // #endregion 一次性读取所有数据
  8473. // stopwatch2.Stop();
  8474. // #region 回写操作,写后清空flag
  8475. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  8476. // #endregion 回写操作,写后清空flag
  8477. // #region S3进站校验
  8478. // try
  8479. // {
  8480. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  8481. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  8482. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  8483. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  8484. // {
  8485. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  8486. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8487. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  8488. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8489. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  8490. // }
  8491. // }
  8492. // catch (Exception ex)
  8493. // {
  8494. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8495. // string str = ex.StackTrace;
  8496. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8497. // }
  8498. // #endregion S3进站校验
  8499. // #region S3二穴载具解绑
  8500. // try
  8501. // {
  8502. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  8503. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  8504. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  8505. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  8506. // {
  8507. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  8508. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  8509. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  8510. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  8511. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  8512. // }
  8513. // }
  8514. // catch (Exception ex)
  8515. // {
  8516. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  8517. // string str = ex.StackTrace;
  8518. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8519. // }
  8520. // #endregion S3二穴载具解绑
  8521. // #region S3二穴载具绑定
  8522. // try
  8523. // {
  8524. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  8525. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  8526. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  8527. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  8528. // {
  8529. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  8530. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  8531. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  8532. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  8533. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  8534. // }
  8535. // }
  8536. // catch (Exception ex)
  8537. // {
  8538. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  8539. // string str = ex.StackTrace;
  8540. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8541. // }
  8542. // #endregion S3二穴载具绑定
  8543. // #region S3出站接口(+一穴载具绑定)
  8544. // try
  8545. // {
  8546. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  8547. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  8548. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  8549. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  8550. // {
  8551. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  8552. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8553. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  8554. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  8555. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  8556. // }
  8557. // }
  8558. // catch (Exception ex)
  8559. // {
  8560. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  8561. // string str = ex.StackTrace;
  8562. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8563. // }
  8564. // #endregion S3出站接口(+一穴载具绑定)
  8565. // #region S3节拍接口
  8566. // try
  8567. // {
  8568. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  8569. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  8570. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  8571. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  8572. // {
  8573. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  8574. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8575. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  8576. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  8577. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  8578. // }
  8579. // }
  8580. // catch (Exception ex)
  8581. // {
  8582. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  8583. // string str = ex.StackTrace;
  8584. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8585. // }
  8586. // #endregion S3节拍接口
  8587. // #region 心跳
  8588. // try
  8589. // {
  8590. // short states = 0;
  8591. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  8592. // }
  8593. // catch (Exception ex)
  8594. // {
  8595. // string str = ex.StackTrace;
  8596. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8597. // }
  8598. // #endregion 心跳
  8599. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  8600. // stopwatch1.Stop();
  8601. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  8602. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  8603. // }
  8604. // else
  8605. // {
  8606. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8607. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  8608. // Funs[plcNo].Connect();
  8609. // }
  8610. // }
  8611. // catch (Exception ex)
  8612. // {
  8613. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8614. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  8615. // Funs[plcNo].ReConnect();
  8616. // }
  8617. // Thread.Sleep(IntervalReadPLC);
  8618. // }
  8619. //}
  8620. /// <summary>
  8621. /// [S3] 值板机- 进站校验
  8622. /// </summary>
  8623. /// <param name="plcNo">PLC编号</param>
  8624. /// <param name="stationNameStr">工站全称</param>
  8625. private void S3进站校验(int plcNo, string stationNameStr)
  8626. {
  8627. Stopwatch stopwatch1 = new Stopwatch();
  8628. Stopwatch stopwatch2 = new Stopwatch();
  8629. try
  8630. {
  8631. stopwatch1.Start();
  8632. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  8633. sn = sn.Replace("\0", "");
  8634. #region 查询载具上的产品信息
  8635. string cavityData = string.Empty;
  8636. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  8637. if (string.IsNullOrEmpty(cavityData))
  8638. cavityData = "";
  8639. if (snResult != 0)
  8640. {
  8641. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8642. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  8643. writeToPLC_Flag1.Adress = 2003;
  8644. writeToPLC_Flag1.Value = (short)6;
  8645. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  8646. stopwatch1.Stop();
  8647. AddMessage(LogType.Info,
  8648. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8649. return;
  8650. }
  8651. #endregion 查询载具上的产品信息
  8652. string[] cavitySNs = cavityData.Split('.');
  8653. string part1Str = ""; // 产品1的SN码
  8654. string part2Str = ""; // 产品2的SN码
  8655. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  8656. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  8657. if (cavitySNs != null && cavitySNs.Length >= 2)
  8658. {
  8659. part1Str = cavitySNs[0];
  8660. part2Str = cavitySNs[1];
  8661. c1Part1Result_Check = 2;
  8662. c1Part2Result_Check = 2;
  8663. }
  8664. if (part1Str == "假产品")
  8665. c1Part1Result_Check = 3;
  8666. if (part2Str == "假产品")
  8667. c1Part2Result_Check = 3;
  8668. // 调用MES进站
  8669. stopwatch2.Start();
  8670. // 调用MES进站 - 产品1
  8671. List<TestItem> item;
  8672. int result1 = c1Part1Result_Check;
  8673. if (result1 != 3)
  8674. {
  8675. item = new List<TestItem>();
  8676. item.Add(new TestItem()
  8677. {
  8678. Parameter_name = "载具码",
  8679. Parameter_value = sn,
  8680. });
  8681. item.Add(new TestItem()
  8682. {
  8683. Parameter_name = "载具穴号",
  8684. Parameter_value = "1",
  8685. });
  8686. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8687. part1Str, item, out string errorMsg);
  8688. }
  8689. // 调用MES进站 - 产品2
  8690. int result2 = c1Part2Result_Check;
  8691. if (result2 != 3)
  8692. {
  8693. item = new List<TestItem>();
  8694. item.Add(new TestItem()
  8695. {
  8696. Parameter_name = "载具码",
  8697. Parameter_value = sn,
  8698. });
  8699. item.Add(new TestItem()
  8700. {
  8701. Parameter_name = "载具穴号",
  8702. Parameter_value = "2",
  8703. });
  8704. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8705. part2Str, item, out string errorMsg);
  8706. }
  8707. stopwatch2.Stop();
  8708. if (result1 == 2)
  8709. c1Part1Result_Check = 2;
  8710. if (result2 == 2)
  8711. c1Part2Result_Check = 2;
  8712. int result = result1;
  8713. if (result == 1)
  8714. result = result2;
  8715. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  8716. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  8717. short c1MES_FLAG_Check = (short)result;
  8718. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  8719. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  8720. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  8721. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  8722. //// MES_Flag
  8723. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8724. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8725. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  8726. writeToPLC_Flag.Adress = 2003;
  8727. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  8728. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8729. {
  8730. Name = "c1Part1Result_Check",
  8731. Adress = 2024,
  8732. ValueType = PLCValueType.Short,
  8733. Value = c1Part1Result_Check
  8734. });
  8735. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8736. {
  8737. Name = "c1Part2Result_Check",
  8738. Adress = 2025,
  8739. ValueType = PLCValueType.Short,
  8740. Value = c1Part2Result_Check
  8741. });
  8742. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8743. {
  8744. Name = "c1Part1Num_Check",
  8745. Adress = 2026,
  8746. ValueType = PLCValueType.Short,
  8747. Value = c1Part1Num_Check
  8748. });
  8749. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8750. {
  8751. Name = "c1Part2Num_Check",
  8752. Adress = 2027,
  8753. ValueType = PLCValueType.Short,
  8754. Value = c1Part2Num_Check
  8755. });
  8756. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  8757. }
  8758. catch (Exception ex)
  8759. {
  8760. string str = ex.StackTrace;
  8761. AddMessage_Station(stationNameStr, LogType.Error,
  8762. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  8763. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8764. // MES_Flag
  8765. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8766. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8767. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  8768. writeToPLC_Flag.Adress = 2003;
  8769. writeToPLC_Flag.Value = (short)6;
  8770. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  8771. }
  8772. stopwatch1.Stop();
  8773. AddMessage(LogType.Info,
  8774. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  8775. stopwatch2.ElapsedMilliseconds + "ms");
  8776. }
  8777. /// <summary>
  8778. /// [S3] 值板机 - 二穴载具解绑
  8779. /// </summary>
  8780. /// <param name="plcNo">PLC编号</param>
  8781. /// <param name="stationNameStr">工站全称</param>
  8782. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  8783. {
  8784. Stopwatch stopwatch1 = new Stopwatch();
  8785. Stopwatch stopwatch2 = new Stopwatch();
  8786. try
  8787. {
  8788. stopwatch1.Start();
  8789. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  8790. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8791. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8792. // 解绑
  8793. #region 查询载具上的产品信息
  8794. string cavityData = string.Empty;
  8795. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8796. if (string.IsNullOrEmpty(cavityData))
  8797. cavityData = "";
  8798. if (snResult != 0)
  8799. {
  8800. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8801. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  8802. writeToPLC_Flag1.Adress = 2082;
  8803. writeToPLC_Flag1.Value = (short)6;
  8804. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  8805. stopwatch1.Stop();
  8806. AddMessage(LogType.Info,
  8807. stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8808. "ms");
  8809. return;
  8810. }
  8811. #endregion 查询载具上的产品信息
  8812. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  8813. #region 解绑
  8814. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  8815. {
  8816. // 删除
  8817. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8818. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  8819. }
  8820. else
  8821. {
  8822. string data_new = string.Join(".", cavitySNs);
  8823. // 删除再插入
  8824. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8825. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  8826. OnMessage(LogType.Debug,
  8827. $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  8828. }
  8829. #endregion 解绑
  8830. short c1MES_FLAG_Unbind = 1;
  8831. stopwatch2.Start();
  8832. // MES_Flag
  8833. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8834. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8835. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  8836. writeToPLC_Flag.Adress = 2082;
  8837. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  8838. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  8839. stopwatch2.Stop();
  8840. }
  8841. catch (Exception ex)
  8842. {
  8843. string str = ex.StackTrace;
  8844. AddMessage_Station(stationNameStr, LogType.Error,
  8845. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" +
  8846. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8847. // MES_Flag
  8848. stopwatch2.Start();
  8849. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  8850. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8851. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  8852. writeToPLC_Flag.Adress = 2082;
  8853. writeToPLC_Flag.Value = (short)6;
  8854. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  8855. stopwatch2.Stop();
  8856. }
  8857. stopwatch1.Stop();
  8858. AddMessage(LogType.Info,
  8859. stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8860. stopwatch2.ElapsedMilliseconds + "ms");
  8861. }
  8862. /// <summary>
  8863. /// [S3] 值板机 - 二穴载具绑定
  8864. /// </summary>
  8865. /// <param name="plcNo">PLC编号</param>
  8866. /// <param name="stationNameStr">工站全称</param>
  8867. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  8868. {
  8869. Stopwatch stopwatch1 = new Stopwatch();
  8870. Stopwatch stopwatch2 = new Stopwatch();
  8871. try
  8872. {
  8873. stopwatch1.Start();
  8874. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  8875. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8876. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  8877. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  8878. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8879. stopwatch2.Start();
  8880. #region 查询载具上的产品信息
  8881. string cavityData = string.Empty;
  8882. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8883. if (string.IsNullOrEmpty(cavityData))
  8884. cavityData = "";
  8885. if (snResult != 0)
  8886. {
  8887. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8888. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  8889. writeToPLC_Flag1.Adress = 2115;
  8890. writeToPLC_Flag1.Value = (short)6;
  8891. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  8892. stopwatch1.Stop();
  8893. AddMessage(LogType.Info,
  8894. stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8895. "ms");
  8896. return;
  8897. }
  8898. #endregion 查询载具上的产品信息
  8899. // 产品换载具
  8900. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  8901. string partSn1 = "";
  8902. string partSn2 = "";
  8903. if (cavitySNs != null && cavitySNs.Length >= 2)
  8904. {
  8905. partSn1 = cavitySNs[0];
  8906. partSn2 = cavitySNs[1];
  8907. }
  8908. string data_new = string.Empty;
  8909. // 是否是两个穴位交换
  8910. if (c1CavityReverse_Bind == 1)
  8911. {
  8912. // 交换
  8913. data_new = string.Concat(partSn2, ".", partSn1);
  8914. }
  8915. else
  8916. {
  8917. // 不交换
  8918. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  8919. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  8920. cavitySNs[c1VehicleCavityFr_Bind] = "";
  8921. data_new = string.Join(".", cavitySNs);
  8922. }
  8923. // 删除再插入
  8924. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8925. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  8926. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  8927. stopwatch2.Stop();
  8928. short c1MES_FLAG_Bind = 1;
  8929. // MES_Flag
  8930. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8931. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8932. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  8933. writeToPLC_Flag.Adress = 2115;
  8934. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  8935. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  8936. }
  8937. catch (Exception ex)
  8938. {
  8939. string str = ex.StackTrace;
  8940. AddMessage_Station(stationNameStr, LogType.Error,
  8941. $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" +
  8942. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8943. // MES_Flag
  8944. stopwatch2.Start();
  8945. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  8946. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8947. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  8948. writeToPLC_Flag.Adress = 2115;
  8949. writeToPLC_Flag.Value = (short)6;
  8950. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  8951. stopwatch2.Stop();
  8952. }
  8953. stopwatch1.Stop();
  8954. AddMessage(LogType.Info,
  8955. stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8956. stopwatch2.ElapsedMilliseconds + "ms");
  8957. }
  8958. //// 上次采集到的SN
  8959. //private string sn_值板机 = string.Empty;
  8960. /// <summary>
  8961. /// [S3] 值板机 - 出站接口
  8962. /// </summary>
  8963. /// <param name="plcNo">PLC编号</param>
  8964. private void S3出站接口(int plcNo, string stationCode, string stationName)
  8965. {
  8966. Stopwatch stopwatch1 = new Stopwatch();
  8967. Stopwatch stopwatch2 = new Stopwatch();
  8968. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8969. string stationNameStr = stationCode + stationName;
  8970. string processItem = stationName; // 测试项目
  8971. try
  8972. {
  8973. stopwatch1.Start();
  8974. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8975. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8976. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8977. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8978. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  8979. sn = sn.Replace("\0", "");
  8980. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  8981. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8982. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8983. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  8984. bool pass = c1Result == 1;
  8985. // 查sn
  8986. #region 查询载具上的产品信息
  8987. string cavityData = string.Empty;
  8988. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8989. if (string.IsNullOrEmpty(cavityData))
  8990. cavityData = "";
  8991. if (snResult != 0)
  8992. {
  8993. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8994. writeToPLC_Flag1.Name = "c1MES_FLAG";
  8995. writeToPLC_Flag1.Adress = 2150;
  8996. writeToPLC_Flag1.Value = (short)4;
  8997. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  8998. stopwatch1.Stop();
  8999. AddMessage(LogType.Info,
  9000. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9001. return;
  9002. }
  9003. #endregion 查询载具上的产品信息
  9004. string[] cavitySNs = cavityData.Split('.');
  9005. string productSN = "";
  9006. if (cavitySNs != null && cavitySNs.Length >= 2)
  9007. {
  9008. productSN = cavitySNs[c1VehicleCavity];
  9009. cavitySNs[c1VehicleCavity] = "";
  9010. }
  9011. stopwatch2.Start();
  9012. List<TestItem> items = new List<TestItem>();
  9013. items.Add(new TestItem()
  9014. {
  9015. Parameter_name = "二穴载具码",
  9016. Parameter_value = c1ProductSN_Check,
  9017. Parameter_unit = ""
  9018. });
  9019. items.Add(new TestItem()
  9020. {
  9021. Parameter_name = "二穴载具穴号",
  9022. Parameter_value = c1VehicleCavity.ToString(),
  9023. Parameter_unit = ""
  9024. });
  9025. items.Add(new TestItem()
  9026. {
  9027. Parameter_name = "一穴载具码",
  9028. Parameter_value = sn,
  9029. Parameter_unit = ""
  9030. });
  9031. items.Add(new TestItem()
  9032. {
  9033. Parameter_name = "一穴载具穴号",
  9034. Parameter_value = "1",
  9035. Parameter_unit = ""
  9036. });
  9037. items.Add(new TestItem()
  9038. {
  9039. Parameter_name = "产品结果",
  9040. Parameter_value = c1Result == 1 ? "OK" : "NG",
  9041. Parameter_unit = ""
  9042. });
  9043. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  9044. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  9045. short result = (short)result1;
  9046. stopwatch2.Stop();
  9047. #region 存储绑定数据到 边线MES系统中
  9048. if (result == 1)
  9049. {
  9050. string data = string.Concat(productSN);
  9051. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  9052. if (resultMesR != 0)
  9053. {
  9054. result = 4;
  9055. AddMessage_Station(stationNameStr, LogType.Error,
  9056. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  9057. }
  9058. }
  9059. #endregion 存储绑定数据到 边线MES系统中
  9060. #region 产品从 来源载具(二穴载具)中删除
  9061. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  9062. {
  9063. // 删除
  9064. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  9065. OnMessage(LogType.Debug,
  9066. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  9067. }
  9068. else
  9069. {
  9070. string data_new = string.Join(".", cavitySNs);
  9071. // 删除再插入
  9072. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  9073. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  9074. OnMessage(LogType.Debug,
  9075. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  9076. }
  9077. #endregion 产品从 来源载具(二穴载具)中删除
  9078. // MES_Flag 为MES报错
  9079. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9080. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  9081. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9082. writeToPLC_Flag.Name = "c1MES_FLAG";
  9083. writeToPLC_Flag.Adress = 2150;
  9084. writeToPLC_Flag.Value = result;
  9085. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  9086. OnMessage(LogType.Debug,
  9087. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9088. }
  9089. catch (Exception ex)
  9090. {
  9091. stopwatch2.Restart();
  9092. // MES_Flag 为4上位机报错
  9093. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  9094. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9095. writeToPLC_Flag.Name = "c1MES_FLAG";
  9096. writeToPLC_Flag.Adress = 2150;
  9097. writeToPLC_Flag.Value = (short)4;
  9098. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  9099. stopwatch2.Stop();
  9100. string str = ex.StackTrace;
  9101. AddMessage_Station(stationNameStr, LogType.Error,
  9102. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  9103. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9104. }
  9105. stopwatch1.Stop();
  9106. AddMessage(LogType.Info,
  9107. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  9108. stopwatch2.ElapsedMilliseconds + "ms");
  9109. }
  9110. #endregion [S3] 值板机
  9111. #endregion PLC3 刘永村
  9112. #region PLC4 刘果段
  9113. #region [S4] 取放桁架
  9114. /// <summary>
  9115. /// S4工位的数据- 触发信号上次的值
  9116. /// </summary>
  9117. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  9118. /// <summary>
  9119. /// S4工位的数据(含触发信号)
  9120. /// </summary>
  9121. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  9122. /// <summary>
  9123. /// S4工位的数据- 回写点位
  9124. /// </summary>
  9125. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  9126. /// <summary>
  9127. /// [S4] 取放桁架
  9128. /// </summary>
  9129. /// <param name="plcNo">PLC编号</param>
  9130. //private void ReadStation_S4(int plcNo)
  9131. //{
  9132. // // [S1] Tray盘上料装备
  9133. // // [S2] FCT
  9134. // // [S3] 值板机
  9135. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  9136. // // [S5] Tray盘下料装备
  9137. // /// 上位机心跳
  9138. // /// 获取设备报警数据与状态信息
  9139. // string stationCode = "[S4_1]";
  9140. // string stationName = "载具下线装备";
  9141. // string stationNameStr = stationCode + stationName;
  9142. // string stationCode2 = "[S4_2]";
  9143. // string stationName2 = "桁架";
  9144. // string stationNameStr2 = stationCode2 + stationName2;
  9145. // string stationCode3 = "[S4_3]";
  9146. // string stationName3 = "提升机1";
  9147. // string stationNameStr3 = stationCode3 + stationName3;
  9148. // string stationCode4 = "[S4_4]";
  9149. // string stationName4 = "提升机2";
  9150. // string stationNameStr4 = stationCode4 + stationName4;
  9151. // string stationCode5 = "[S4_5]";
  9152. // string stationName5 = "载具上线装备";
  9153. // string stationNameStr5 = stationCode5 + stationName5;
  9154. // #region 创建字典
  9155. // // 触发信号字典 赋值
  9156. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9157. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  9158. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  9159. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9160. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  9161. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  9162. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  9163. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9164. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  9165. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  9166. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9167. // // PLC数据字典 赋值
  9168. // // 载具下线装备(弹夹上线)
  9169. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9170. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  9171. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  9172. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  9173. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  9174. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  9175. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  9176. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  9177. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  9178. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  9179. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  9180. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  9181. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  9182. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  9183. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  9184. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  9185. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  9186. // s4PLCData.Add("d1Result", 0); // 产品结果
  9187. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9188. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  9189. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  9190. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  9191. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  9192. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  9193. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  9194. // // 真空标机(提升机)
  9195. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  9196. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  9197. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  9198. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  9199. // s4PLCData.Add("d3Result", 0); // 产品结果
  9200. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  9201. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  9202. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  9203. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  9204. // s4PLCData.Add("d4Result", 0); // 产品结果
  9205. // // 载具上线装备(弹夹下线)
  9206. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9207. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  9208. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  9209. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  9210. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  9211. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  9212. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  9213. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  9214. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  9215. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  9216. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  9217. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  9218. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  9219. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  9220. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  9221. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  9222. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  9223. // s4PLCData.Add("d5Result", 0); // 产品结果
  9224. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9225. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  9226. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  9227. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  9228. // #endregion 创建字典
  9229. // while (IsRun)
  9230. // {
  9231. // try
  9232. // {
  9233. // if (!GlobalContext._IsCon_Funs4)
  9234. // {
  9235. // UpdatePLCMonitor(1, plcNo, 0);
  9236. // continue;
  9237. // }
  9238. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  9239. // {
  9240. // Stopwatch stopwatch1 = new Stopwatch();
  9241. // Stopwatch stopwatch2 = new Stopwatch();
  9242. // stopwatch1.Start();
  9243. // stopwatch2.Start();
  9244. // #region 一次性读取所有数据
  9245. // // 载具下线装备(弹夹上线)
  9246. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  9247. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  9248. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  9249. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  9250. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  9251. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  9252. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  9253. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  9254. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  9255. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  9256. // int[] datas = data1.Concat(data2).ToArray();
  9257. // datas = datas.Concat(data3).ToArray();
  9258. // datas = datas.Concat(data4).ToArray();
  9259. // datas = datas.Concat(data5).ToArray();
  9260. // datas = datas.Concat(data6).ToArray();
  9261. // datas = datas.Concat(data7).ToArray();
  9262. // datas = datas.Concat(data8).ToArray();
  9263. // datas = datas.Concat(data9).ToArray();
  9264. // datas = datas.Concat(data10).ToArray();
  9265. // // 载具下线装备(弹夹上线)
  9266. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  9267. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  9268. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  9269. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  9270. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  9271. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  9272. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  9273. // s4PLCData["d1MES_FLAG"] = datas[65];
  9274. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  9275. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  9276. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  9277. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  9278. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  9279. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  9280. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  9281. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  9282. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  9283. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  9284. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  9285. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  9286. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  9287. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  9288. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  9289. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  9290. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  9291. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  9292. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  9293. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  9294. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  9295. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  9296. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  9297. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  9298. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  9299. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  9300. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  9301. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  9302. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  9303. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  9304. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  9305. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  9306. // s4PLCData["d1Result"] = datas[386];
  9307. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  9308. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  9309. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  9310. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  9311. // s4PLCData["d1OEEType"] = datas[419];
  9312. // // 桁架(查询标机中弹夹的状态)
  9313. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  9314. // s4PLCData["d2BulletclipStates"] = datas[431];
  9315. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  9316. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  9317. // // 真空标机
  9318. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  9319. // s4PLCData["d3MES_FLAG"] = datas[463];
  9320. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  9321. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  9322. // s4PLCData["d3Result"] = datas[484];
  9323. // s4PLCData["d3Type"] = datas[485];
  9324. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  9325. // s4PLCData["d4MES_FLAG"] = datas[496];
  9326. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  9327. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  9328. // s4PLCData["d4Result"] = datas[517];
  9329. // s4PLCData["d4Type"] = datas[518];
  9330. // // 载具上线装备(弹夹下线)
  9331. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  9332. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  9333. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  9334. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  9335. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  9336. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  9337. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  9338. // s4PLCData["d5MES_FLAG"] = datas[591];
  9339. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  9340. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  9341. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  9342. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  9343. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  9344. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  9345. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  9346. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  9347. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  9348. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  9349. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  9350. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  9351. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  9352. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  9353. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  9354. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  9355. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  9356. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  9357. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  9358. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  9359. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  9360. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  9361. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  9362. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  9363. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  9364. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  9365. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  9366. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  9367. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  9368. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  9369. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  9370. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  9371. // s4PLCData["d5Result"] = datas[912];
  9372. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  9373. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  9374. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  9375. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  9376. // s4PLCData["d5OEEType"] = datas[945];
  9377. // #endregion 一次性读取所有数据
  9378. // stopwatch2.Stop();
  9379. // #region 回写操作,写后清空flag
  9380. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  9381. // #endregion 回写操作,写后清空flag
  9382. // // N801A-S4_1 弹夹扫码
  9383. // #region N801A-S4_1 弹夹扫码
  9384. // try
  9385. // {
  9386. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  9387. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  9388. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  9389. // {
  9390. // if (d1BulletclipScanCode == 1) // 0->1
  9391. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  9392. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  9393. // }
  9394. // }
  9395. // catch (Exception ex)
  9396. // {
  9397. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  9398. // string str = ex.StackTrace;
  9399. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9400. // }
  9401. // #endregion N801A-S4_1 弹夹扫码
  9402. // // N801A-S4_1 载具扫码
  9403. // #region N801A-S4_1 载具扫码
  9404. // try
  9405. // {
  9406. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  9407. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  9408. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  9409. // {
  9410. // if (d1VehicleScanCode == 1) // 0->1
  9411. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  9412. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  9413. // }
  9414. // }
  9415. // catch (Exception ex)
  9416. // {
  9417. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  9418. // string str = ex.StackTrace;
  9419. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9420. // }
  9421. // #endregion N801A-S4_1 载具扫码
  9422. // // N801A-S4_1 出站接口
  9423. // #region N801A-S4_1 出站接口
  9424. // try
  9425. // {
  9426. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  9427. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  9428. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  9429. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  9430. // {
  9431. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  9432. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  9433. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  9434. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  9435. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  9436. // }
  9437. // }
  9438. // catch (Exception ex)
  9439. // {
  9440. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  9441. // string str = ex.StackTrace;
  9442. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9443. // }
  9444. // #endregion N801A-S4_1 出站接口
  9445. // // N801A-S4_1 节拍接口
  9446. // #region N801A-S4_1 节拍接口
  9447. // try
  9448. // {
  9449. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  9450. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  9451. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  9452. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  9453. // {
  9454. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  9455. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  9456. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  9457. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  9458. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  9459. // }
  9460. // }
  9461. // catch (Exception ex)
  9462. // {
  9463. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  9464. // string str = ex.StackTrace;
  9465. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9466. // }
  9467. // #endregion N801A-S4_1 节拍接口
  9468. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  9469. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  9470. // try
  9471. // {
  9472. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  9473. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  9474. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  9475. // {
  9476. // if (d2BulletclipScanCode == 1) // 0->1
  9477. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  9478. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  9479. // }
  9480. // }
  9481. // catch (Exception ex)
  9482. // {
  9483. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  9484. // string str = ex.StackTrace;
  9485. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9486. // }
  9487. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  9488. // // N801A-S4_3 真空标机1 数据
  9489. // #region N801A-S4_3 真空标机1
  9490. // try
  9491. // {
  9492. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  9493. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  9494. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  9495. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  9496. // {
  9497. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  9498. // {
  9499. // int stationType = (int)s4PLCData["d3Type"];
  9500. // if (stationType == 1)
  9501. // {
  9502. // // S4_3进站接口
  9503. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  9504. // }
  9505. // else if (stationType == 2)
  9506. // {
  9507. // // S4_3出站接口
  9508. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  9509. // }
  9510. // }
  9511. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  9512. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  9513. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  9514. // }
  9515. // }
  9516. // catch (Exception ex)
  9517. // {
  9518. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  9519. // string str = ex.StackTrace;
  9520. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9521. // }
  9522. // #endregion N801A-S4_3 真空标机1
  9523. // // N801A-S4_4 真空标机2 数据
  9524. // #region N801A-S4_4 真空标机2
  9525. // try
  9526. // {
  9527. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  9528. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  9529. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  9530. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  9531. // {
  9532. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  9533. // {
  9534. // int stationType = (int)s4PLCData["d4Type"];
  9535. // if (stationType == 1)
  9536. // {
  9537. // // S4_4进站接口
  9538. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  9539. // }
  9540. // else if (stationType == 2)
  9541. // {
  9542. // // S4_4出站接口
  9543. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  9544. // }
  9545. // }
  9546. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  9547. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  9548. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  9549. // }
  9550. // }
  9551. // catch (Exception ex)
  9552. // {
  9553. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  9554. // string str = ex.StackTrace;
  9555. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9556. // }
  9557. // #endregion N801A-S4_4 真空标机2
  9558. // // N801A-S4_5 弹夹扫码 数据
  9559. // #region N801A-S4_5 弹夹扫码
  9560. // try
  9561. // {
  9562. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  9563. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  9564. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  9565. // {
  9566. // if (d5BulletclipScanCode == 1) // 0->1
  9567. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  9568. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  9569. // }
  9570. // }
  9571. // catch (Exception ex)
  9572. // {
  9573. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  9574. // string str = ex.StackTrace;
  9575. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9576. // }
  9577. // #endregion N801A-S4_5 弹夹扫码
  9578. // // N801A-S4_5 载具扫码 数据
  9579. // #region N801A-S4_5 载具扫码
  9580. // try
  9581. // {
  9582. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  9583. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  9584. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  9585. // {
  9586. // if (d5VehicleScanCode == 1) // 0->1
  9587. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  9588. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  9589. // }
  9590. // }
  9591. // catch (Exception ex)
  9592. // {
  9593. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  9594. // string str = ex.StackTrace;
  9595. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9596. // }
  9597. // #endregion N801A-S4_5 载具扫码
  9598. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  9599. // #region N801A-S4_5 出站接口
  9600. // try
  9601. // {
  9602. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  9603. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  9604. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  9605. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  9606. // {
  9607. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  9608. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  9609. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  9610. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  9611. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  9612. // }
  9613. // }
  9614. // catch (Exception ex)
  9615. // {
  9616. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  9617. // string str = ex.StackTrace;
  9618. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9619. // }
  9620. // #endregion N801A-S4_5 出站接口
  9621. // // N801A-S4_5 节拍接口 数据
  9622. // #region N801A-S4_5 节拍接口
  9623. // try
  9624. // {
  9625. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  9626. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  9627. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  9628. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  9629. // {
  9630. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  9631. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  9632. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  9633. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  9634. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  9635. // }
  9636. // }
  9637. // catch (Exception ex)
  9638. // {
  9639. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  9640. // string str = ex.StackTrace;
  9641. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9642. // }
  9643. // #endregion N801A-S4_5 节拍接口
  9644. // #region 心跳
  9645. // try
  9646. // {
  9647. // short states = 0;
  9648. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  9649. // }
  9650. // catch (Exception ex)
  9651. // {
  9652. // string str = ex.StackTrace;
  9653. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9654. // }
  9655. // #endregion 心跳
  9656. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  9657. // stopwatch1.Stop();
  9658. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  9659. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  9660. // }
  9661. // else
  9662. // {
  9663. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9664. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  9665. // Funs[plcNo].Connect();
  9666. // }
  9667. // }
  9668. // catch (Exception ex)
  9669. // {
  9670. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9671. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  9672. // Funs[plcNo].ReConnect();
  9673. // }
  9674. // Thread.Sleep(IntervalReadPLC);
  9675. // }
  9676. //}
  9677. /// <summary>
  9678. /// [S4] 取放桁架 - S4_1弹夹扫码
  9679. /// </summary>
  9680. /// <param name="plcNo">PLC编号</param>
  9681. /// <param name="stationNameStr">工站全称</param>
  9682. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  9683. {
  9684. Stopwatch stopwatch1 = new Stopwatch();
  9685. Stopwatch stopwatch2 = new Stopwatch();
  9686. try
  9687. {
  9688. stopwatch1.Start();
  9689. // ZS 弹夹扫码
  9690. string d1BulletclipCode = " "; // 扫到的码
  9691. short d1BulletclipScanCode = 2;
  9692. stopwatch2.Start();
  9693. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  9694. //// MES_Flag
  9695. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  9696. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9697. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  9698. writeToPLC_Flag.Adress = 2002;
  9699. writeToPLC_Flag.Value = d1BulletclipScanCode;
  9700. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  9701. {
  9702. Name = "d1BulletclipCode",
  9703. Adress = 2003,
  9704. ValueType = PLCValueType.String,
  9705. ValueTypeStrLength = 20,
  9706. Value = d1BulletclipCode
  9707. });
  9708. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  9709. stopwatch2.Stop();
  9710. }
  9711. catch (Exception ex)
  9712. {
  9713. string str = ex.StackTrace;
  9714. AddMessage_Station(stationNameStr, LogType.Error,
  9715. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  9716. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9717. stopwatch2.Start();
  9718. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  9719. //// MES_Flag
  9720. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  9721. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9722. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  9723. writeToPLC_Flag.Adress = 2002;
  9724. writeToPLC_Flag.Value = (short)6;
  9725. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  9726. {
  9727. Name = "d1BulletclipCode",
  9728. Adress = 2003,
  9729. ValueType = PLCValueType.String,
  9730. ValueTypeStrLength = 20,
  9731. Value = " "
  9732. });
  9733. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  9734. stopwatch2.Stop();
  9735. }
  9736. stopwatch1.Stop();
  9737. AddMessage(LogType.Info,
  9738. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9739. stopwatch2.ElapsedMilliseconds + "ms");
  9740. }
  9741. /// <summary>
  9742. /// [S4] 取放桁架 - S4_1载具扫码
  9743. /// </summary>
  9744. /// <param name="plcNo">PLC编号</param>
  9745. /// <param name="stationNameStr">工站全称</param>
  9746. private void S4_1载具扫码(int plcNo, string stationNameStr)
  9747. {
  9748. Stopwatch stopwatch1 = new Stopwatch();
  9749. Stopwatch stopwatch2 = new Stopwatch();
  9750. try
  9751. {
  9752. stopwatch1.Start();
  9753. // ZS 载具扫码
  9754. string d1VehicleCode = ""; // 扫到的码
  9755. short d1VehicleScanCode = 2;
  9756. #region 进站
  9757. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  9758. {
  9759. #region 查询载具上的产品信息
  9760. string cavityData = string.Empty;
  9761. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  9762. if (string.IsNullOrEmpty(cavityData))
  9763. cavityData = "";
  9764. if (snResult != 0)
  9765. {
  9766. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9767. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  9768. writeToPLC_Flag1.Adress = 2033;
  9769. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  9770. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9771. {
  9772. Name = "d1VehicleCode",
  9773. Adress = 2034,
  9774. ValueType = PLCValueType.String,
  9775. ValueTypeStrLength = 20,
  9776. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  9777. });
  9778. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  9779. stopwatch1.Stop();
  9780. AddMessage(LogType.Info,
  9781. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9782. "ms");
  9783. return;
  9784. }
  9785. string[] cavitySNs = cavityData.Split('.');
  9786. string partNo = "";
  9787. if (cavitySNs != null && cavitySNs.Length >= 1)
  9788. {
  9789. partNo = cavitySNs[0];
  9790. }
  9791. #endregion 查询载具上的产品信息
  9792. List<TestItem> item = new List<TestItem>();
  9793. item.Add(new TestItem()
  9794. {
  9795. Parameter_name = "载具码",
  9796. Parameter_value = d1VehicleCode,
  9797. });
  9798. item.Add(new TestItem()
  9799. {
  9800. Parameter_name = "载具穴号",
  9801. Parameter_value = "1",
  9802. });
  9803. stopwatch2.Start();
  9804. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  9805. partNo, item, out string errorMsg);
  9806. stopwatch2.Stop();
  9807. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  9808. }
  9809. #endregion 进站
  9810. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  9811. //// MES_Flag
  9812. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  9813. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9814. writeToPLC_Flag.Name = "d1VehicleScanCode";
  9815. writeToPLC_Flag.Adress = 2033;
  9816. writeToPLC_Flag.Value = d1VehicleScanCode;
  9817. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9818. {
  9819. Name = "d1VehicleCode",
  9820. Adress = 2034,
  9821. ValueType = PLCValueType.String,
  9822. ValueTypeStrLength = 20,
  9823. Value = d1VehicleCode
  9824. });
  9825. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  9826. }
  9827. catch (Exception ex)
  9828. {
  9829. string str = ex.StackTrace;
  9830. AddMessage_Station(stationNameStr, LogType.Error,
  9831. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  9832. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9833. stopwatch2.Start();
  9834. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  9835. //// MES_Flag
  9836. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  9837. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9838. writeToPLC_Flag.Name = "d1VehicleScanCode";
  9839. writeToPLC_Flag.Adress = 2033;
  9840. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  9841. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9842. {
  9843. Name = "d1VehicleCode",
  9844. Adress = 2034,
  9845. ValueType = PLCValueType.String,
  9846. ValueTypeStrLength = 20,
  9847. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  9848. });
  9849. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  9850. stopwatch2.Stop();
  9851. }
  9852. stopwatch1.Stop();
  9853. AddMessage(LogType.Info,
  9854. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9855. stopwatch2.ElapsedMilliseconds + "ms");
  9856. }
  9857. // 上次采集到的SN
  9858. //private string sn_S4_1出站接口 = string.Empty;
  9859. /// <summary>
  9860. /// [S4] 取放桁架 - S4_1出站接口
  9861. /// </summary>
  9862. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  9863. {
  9864. Stopwatch stopwatch1 = new Stopwatch();
  9865. Stopwatch stopwatch2 = new Stopwatch();
  9866. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9867. string stationNameStr = stationCode + stationName;
  9868. string processItem = stationName; // 测试项目
  9869. try
  9870. {
  9871. stopwatch1.Start();
  9872. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9873. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9874. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9875. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9876. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  9877. sn = sn.Replace("\0", "");
  9878. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  9879. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  9880. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  9881. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  9882. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  9883. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  9884. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  9885. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  9886. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  9887. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  9888. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  9889. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  9890. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  9891. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  9892. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  9893. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  9894. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  9895. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  9896. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  9897. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  9898. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  9899. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  9900. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  9901. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  9902. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  9903. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  9904. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  9905. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  9906. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  9907. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  9908. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  9909. bool pass = d1Result == 1;
  9910. // 存 载具SN列表
  9911. List<string> vehicleCodes = new List<string>()
  9912. {
  9913. d1VehicleCode1, d1VehicleCode2, d1VehicleCode3, d1VehicleCode4, d1VehicleCode5,
  9914. d1VehicleCode6, d1VehicleCode7, d1VehicleCode8, d1VehicleCode9, d1VehicleCode10,
  9915. d1VehicleCode11, d1VehicleCode12, d1VehicleCode13, d1VehicleCode14, d1VehicleCode15
  9916. };
  9917. // 统一查 产品SN列表
  9918. List<string> partNos = new List<string>();
  9919. foreach (string vehicleCode in vehicleCodes)
  9920. {
  9921. if (string.IsNullOrEmpty(vehicleCode))
  9922. partNos.Add("");
  9923. else
  9924. {
  9925. string partNo = "";
  9926. #region 查询载具上的产品信息
  9927. string cavityData = string.Empty;
  9928. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  9929. if (string.IsNullOrEmpty(cavityData))
  9930. cavityData = "";
  9931. if (snResult != 0)
  9932. {
  9933. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9934. writeToPLC_Flag1.Name = "d1MES_FLAG";
  9935. writeToPLC_Flag1.Adress = 2065;
  9936. writeToPLC_Flag1.Value = (short)4;
  9937. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  9938. stopwatch1.Stop();
  9939. AddMessage(LogType.Info,
  9940. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9941. "ms");
  9942. return;
  9943. }
  9944. string[] cavitySNs = cavityData.Split('.');
  9945. if (cavitySNs != null && cavitySNs.Length >= 1)
  9946. partNo = cavitySNs[0];
  9947. #endregion 查询载具上的产品信息
  9948. partNos.Add(partNo);
  9949. }
  9950. }
  9951. // 统一上传
  9952. stopwatch2.Start();
  9953. List<int> results = new List<int>();
  9954. for (int i = 0; i < partNos.Count; i++)
  9955. {
  9956. string index = (i + 1).ToString(); // 弹夹穴号
  9957. if (string.IsNullOrEmpty(partNos[i]))
  9958. results.Add(1);
  9959. else
  9960. {
  9961. List<TestItem> items1 = new List<TestItem>();
  9962. items1.Add(new TestItem()
  9963. {
  9964. Parameter_name = "弹夹码",
  9965. Parameter_value = sn,
  9966. Parameter_unit = ""
  9967. });
  9968. items1.Add(new TestItem()
  9969. {
  9970. Parameter_name = "弹夹穴号",
  9971. Parameter_value = index,
  9972. Parameter_unit = ""
  9973. });
  9974. items1.Add(new TestItem()
  9975. {
  9976. Parameter_name = "载具码",
  9977. Parameter_value = vehicleCodes[i],
  9978. Parameter_unit = ""
  9979. });
  9980. items1.Add(new TestItem()
  9981. {
  9982. Parameter_name = "载具穴号",
  9983. Parameter_value = "1",
  9984. Parameter_unit = ""
  9985. });
  9986. items1.Add(new TestItem()
  9987. {
  9988. Parameter_name = "产品结果",
  9989. Parameter_value = d1Result == 1 ? "OK" : "NG",
  9990. Parameter_unit = ""
  9991. });
  9992. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  9993. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  9994. results.Add(result1);
  9995. }
  9996. }
  9997. short result = 0;
  9998. if (results.All(a => a == 1))
  9999. result = 1;
  10000. else if (results.Contains(3))
  10001. result = 3;
  10002. else if (results.Contains(2))
  10003. result = 2;
  10004. else if (results.Contains(4))
  10005. result = 4;
  10006. else
  10007. result = 4;
  10008. stopwatch2.Stop();
  10009. #region 存储绑定数据到 边线MES系统中
  10010. if (result == 1)
  10011. {
  10012. string data = string.Join(".", vehicleCodes);
  10013. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  10014. if (resultMesR != 0)
  10015. {
  10016. result = 4;
  10017. AddMessage_Station(stationNameStr, LogType.Error,
  10018. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  10019. }
  10020. }
  10021. #endregion 存储绑定数据到 边线MES系统中
  10022. // MES_Flag 为4MES报错
  10023. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10024. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10025. writeToPLC_Flag.Name = "d1MES_FLAG";
  10026. writeToPLC_Flag.Adress = 2065;
  10027. writeToPLC_Flag.Value = result;
  10028. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  10029. OnMessage(LogType.Debug,
  10030. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  10031. }
  10032. catch (Exception ex)
  10033. {
  10034. stopwatch2.Restart();
  10035. // MES_Flag 为4上位机报错
  10036. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  10037. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10038. writeToPLC_Flag.Name = "d1MES_FLAG";
  10039. writeToPLC_Flag.Adress = 2065;
  10040. writeToPLC_Flag.Value = (short)4;
  10041. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  10042. stopwatch2.Stop();
  10043. string str = ex.StackTrace;
  10044. AddMessage_Station(stationNameStr, LogType.Error,
  10045. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10046. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10047. }
  10048. stopwatch1.Stop();
  10049. AddMessage(LogType.Info,
  10050. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10051. stopwatch2.ElapsedMilliseconds + "ms");
  10052. }
  10053. /// <summary>
  10054. /// [S4] 取放桁架 - S4_1节拍接口
  10055. /// </summary>
  10056. /// <param name="plcNo">PLC编号</param>
  10057. /// <param name="stationNameStr">工站全称</param>
  10058. private void S4_1节拍接口(int plcNo, string stationNameStr)
  10059. {
  10060. Stopwatch stopwatch1 = new Stopwatch();
  10061. Stopwatch stopwatch2 = new Stopwatch();
  10062. string resultStr = string.Empty;
  10063. try
  10064. {
  10065. stopwatch1.Start();
  10066. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  10067. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  10068. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  10069. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  10070. if (!actionBool)
  10071. {
  10072. stopwatch2.Start();
  10073. // MES_Flag
  10074. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10075. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10076. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  10077. writeToPLC_Flag1.Adress = 2398;
  10078. writeToPLC_Flag1.Value = (short)4;
  10079. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  10080. stopwatch2.Stop();
  10081. AddMessage(LogType.Info,
  10082. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  10083. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  10084. return;
  10085. }
  10086. string d1OEEPartNo = string.Empty; // 物料码
  10087. if (string.IsNullOrEmpty(d1OEEProductSN))
  10088. {
  10089. stopwatch2.Start();
  10090. // MES_Flag
  10091. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10092. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10093. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  10094. writeToPLC_Flag1.Adress = 2398;
  10095. writeToPLC_Flag1.Value = (short)1;
  10096. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  10097. stopwatch2.Stop();
  10098. AddMessage(LogType.Info,
  10099. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10100. stopwatch2.ElapsedMilliseconds + "ms");
  10101. return;
  10102. }
  10103. else
  10104. {
  10105. // 查产品SN ZS
  10106. d1OEEPartNo = "Test";
  10107. }
  10108. short d1OEEMES_FLAG = 0;
  10109. // 上传OEE
  10110. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  10111. d1OEEMES_FLAG = result.Item1;
  10112. resultStr = result.Item2;
  10113. stopwatch2.Start();
  10114. // MES_Flag
  10115. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10116. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10117. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  10118. writeToPLC_Flag.Adress = 2398;
  10119. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  10120. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  10121. stopwatch2.Stop();
  10122. }
  10123. catch (Exception ex)
  10124. {
  10125. string str = ex.StackTrace;
  10126. AddMessage_Station(stationNameStr, LogType.Error,
  10127. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  10128. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10129. // MES_Flag
  10130. stopwatch2.Start();
  10131. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  10132. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10133. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  10134. writeToPLC_Flag.Adress = 2398;
  10135. writeToPLC_Flag.Value = (short)4;
  10136. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  10137. stopwatch2.Stop();
  10138. }
  10139. stopwatch1.Stop();
  10140. AddMessage(LogType.Info,
  10141. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10142. stopwatch2.ElapsedMilliseconds + "ms");
  10143. }
  10144. /// <summary>
  10145. /// [S4] 取放桁架 - S4_2桁架
  10146. /// </summary>
  10147. /// <param name="plcNo">PLC编号</param>
  10148. /// <param name="stationNameStr">工站全称</param>
  10149. private void S4_2桁架(int plcNo, string stationNameStr)
  10150. {
  10151. Stopwatch stopwatch1 = new Stopwatch();
  10152. Stopwatch stopwatch2 = new Stopwatch();
  10153. try
  10154. {
  10155. stopwatch1.Start();
  10156. // ZS 弹夹扫码
  10157. string d2BulletclipCode = " "; // 扫到的码
  10158. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  10159. short d2BulletclipScanCode = 2;
  10160. stopwatch2.Start();
  10161. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  10162. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  10163. //// MES_Flag
  10164. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10165. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10166. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  10167. writeToPLC_Flag.Adress = 2430;
  10168. writeToPLC_Flag.Value = d2BulletclipScanCode;
  10169. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10170. {
  10171. Name = "d2BulletclipCode",
  10172. Adress = 2432,
  10173. ValueType = PLCValueType.String,
  10174. ValueTypeStrLength = 20,
  10175. Value = d2BulletclipCode
  10176. });
  10177. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10178. {
  10179. Name = "d2BulletclipStates",
  10180. Adress = 2431,
  10181. ValueType = PLCValueType.Short,
  10182. Value = d2BulletclipStates
  10183. });
  10184. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  10185. stopwatch2.Stop();
  10186. }
  10187. catch (Exception ex)
  10188. {
  10189. string str = ex.StackTrace;
  10190. AddMessage_Station(stationNameStr, LogType.Error,
  10191. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10192. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10193. stopwatch2.Start();
  10194. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  10195. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  10196. // MES_Flag
  10197. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  10198. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10199. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  10200. writeToPLC_Flag.Adress = 2430;
  10201. writeToPLC_Flag.Value = (short)6;
  10202. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10203. {
  10204. Name = "d2BulletclipCode",
  10205. Adress = 2432,
  10206. ValueType = PLCValueType.String,
  10207. ValueTypeStrLength = 20,
  10208. Value = " "
  10209. });
  10210. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10211. {
  10212. Name = "d2BulletclipStates",
  10213. Adress = 2431,
  10214. ValueType = PLCValueType.Short,
  10215. Value = (short)0
  10216. });
  10217. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  10218. stopwatch2.Stop();
  10219. }
  10220. stopwatch1.Stop();
  10221. AddMessage(LogType.Info,
  10222. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10223. stopwatch2.ElapsedMilliseconds + "ms");
  10224. }
  10225. // 上次采集到的SN
  10226. //private string sn_S4_3进站接口 = string.Empty;
  10227. /// <summary>
  10228. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  10229. /// </summary>
  10230. private void S4_3进站接口(int plcNo, string stationNameStr)
  10231. {
  10232. Stopwatch stopwatch1 = new Stopwatch();
  10233. Stopwatch stopwatch2 = new Stopwatch();
  10234. try
  10235. {
  10236. stopwatch1.Start();
  10237. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  10238. sn = sn.Replace("\0", "");
  10239. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  10240. #region 查询15个载具码
  10241. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10242. string vehicleData = string.Empty;
  10243. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10244. if (string.IsNullOrEmpty(vehicleData))
  10245. vehicleData = "";
  10246. if (snResult != 0)
  10247. {
  10248. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10249. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10250. writeToPLC_Flag1.Adress = 2463;
  10251. writeToPLC_Flag1.Value = (short)4;
  10252. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10253. stopwatch1.Stop();
  10254. AddMessage(LogType.Info,
  10255. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10256. return;
  10257. }
  10258. string[] cavitySNs = vehicleData.Split('.');
  10259. if (cavitySNs != null && cavitySNs.Length > 0)
  10260. {
  10261. for (int i = 0; i < cavitySNs.Length; i++)
  10262. {
  10263. if (string.IsNullOrEmpty(cavitySNs[i]))
  10264. vehicleCodes.Add("");
  10265. else
  10266. vehicleCodes.Add(cavitySNs[i]);
  10267. }
  10268. }
  10269. #endregion 查询15个载具码
  10270. #region 查询15个产品SN
  10271. List<string> portNos = new List<string>(); // 15个产品SN
  10272. foreach (string vehicleCode in vehicleCodes)
  10273. {
  10274. if (string.IsNullOrEmpty(vehicleCode))
  10275. portNos.Add("");
  10276. else
  10277. {
  10278. // 查询
  10279. string cavityData = string.Empty;
  10280. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10281. if (string.IsNullOrEmpty(cavityData))
  10282. cavityData = "";
  10283. if (snResult1 != 0)
  10284. {
  10285. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10286. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10287. writeToPLC_Flag1.Adress = 2463;
  10288. writeToPLC_Flag1.Value = (short)4;
  10289. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10290. stopwatch1.Stop();
  10291. AddMessage(LogType.Info,
  10292. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  10293. stopwatch1.ElapsedMilliseconds + "ms");
  10294. return;
  10295. }
  10296. string[] partSNs = cavityData.Split('.');
  10297. if (partSNs != null && partSNs.Length >= 1)
  10298. portNos.Add(partSNs[0]);
  10299. else
  10300. portNos.Add("");
  10301. }
  10302. }
  10303. #endregion 查询15个产品SN
  10304. // 调用MES进站(最多15个)
  10305. stopwatch2.Start();
  10306. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  10307. for (int i = 0; i < vehicleCodes.Count; i++)
  10308. {
  10309. // 循环进站
  10310. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  10311. {
  10312. // 产品SN(物料码)校验
  10313. string portNo = portNos[i];
  10314. List<TestItem> item = new List<TestItem>();
  10315. item.Add(new TestItem()
  10316. {
  10317. Parameter_name = "弹夹码",
  10318. Parameter_value = sn,
  10319. });
  10320. item.Add(new TestItem()
  10321. {
  10322. Parameter_name = "弹夹穴位",
  10323. Parameter_value = (i + 1).ToString(),
  10324. });
  10325. item.Add(new TestItem()
  10326. {
  10327. Parameter_name = "载具码",
  10328. Parameter_value = vehicleCodes[i],
  10329. });
  10330. item.Add(new TestItem()
  10331. {
  10332. Parameter_name = "载具穴号",
  10333. Parameter_value = "1",
  10334. });
  10335. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  10336. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  10337. }
  10338. }
  10339. stopwatch2.Stop();
  10340. short result = 0;
  10341. bool haveMesWarn = results.Contains(5);
  10342. bool havePCWarn = results.Contains(6);
  10343. if (haveMesWarn)
  10344. result = 2; // 5->2
  10345. else if (havePCWarn)
  10346. result = 6; // 6->4
  10347. else
  10348. result = 1;
  10349. // MES_Flag 为4MES报错
  10350. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10351. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10352. writeToPLC_Flag.Name = "d3MES_FLAG";
  10353. writeToPLC_Flag.Adress = 2463;
  10354. writeToPLC_Flag.Value = result;
  10355. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10356. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10357. }
  10358. catch (Exception ex)
  10359. {
  10360. stopwatch2.Stop();
  10361. // MES_Flag 为4上位机报错
  10362. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  10363. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10364. writeToPLC_Flag.Name = "d3MES_FLAG";
  10365. writeToPLC_Flag.Adress = 2463;
  10366. writeToPLC_Flag.Value = (short)4;
  10367. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10368. string str = ex.StackTrace;
  10369. AddMessage_Station(stationNameStr, LogType.Error,
  10370. $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10371. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10372. }
  10373. stopwatch1.Stop();
  10374. AddMessage(LogType.Info,
  10375. stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  10376. stopwatch2.ElapsedMilliseconds + "ms");
  10377. }
  10378. // 上次采集到的SN
  10379. //private string sn_S4_3出站接口 = string.Empty;
  10380. /// <summary>
  10381. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  10382. /// </summary>
  10383. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  10384. {
  10385. Stopwatch stopwatch1 = new Stopwatch();
  10386. Stopwatch stopwatch2 = new Stopwatch();
  10387. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10388. string stationNameStr = stationCode + stationName;
  10389. string processItem = stationName; // 测试项目
  10390. try
  10391. {
  10392. stopwatch1.Start();
  10393. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10394. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10395. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10396. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10397. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  10398. sn = sn.Replace("\0", "");
  10399. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  10400. bool isPass = d3Result == 1; // 产品结果 bool
  10401. #region 查询15个载具码
  10402. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10403. string vehicleData = string.Empty;
  10404. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10405. if (string.IsNullOrEmpty(vehicleData))
  10406. vehicleData = "";
  10407. if (snResult1 != 0)
  10408. {
  10409. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10410. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10411. writeToPLC_Flag1.Adress = 2463;
  10412. writeToPLC_Flag1.Value = (short)4;
  10413. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10414. stopwatch1.Stop();
  10415. AddMessage(LogType.Info,
  10416. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10417. return;
  10418. }
  10419. string[] cavitySNs = vehicleData.Split('.');
  10420. if (cavitySNs != null && cavitySNs.Length > 0)
  10421. {
  10422. for (int i = 0; i < cavitySNs.Length; i++)
  10423. {
  10424. if (string.IsNullOrEmpty(cavitySNs[i]))
  10425. vehicleCodes.Add("");
  10426. else
  10427. vehicleCodes.Add(cavitySNs[i]);
  10428. }
  10429. }
  10430. #endregion 查询15个载具码
  10431. // 统一查 产品SN列表
  10432. List<string> partNos = new List<string>();
  10433. foreach (string vehicleCode in vehicleCodes)
  10434. {
  10435. if (string.IsNullOrEmpty(vehicleCode))
  10436. partNos.Add("");
  10437. else
  10438. {
  10439. string partNo = "";
  10440. #region 查询载具上的产品信息
  10441. string cavityData = string.Empty;
  10442. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10443. if (string.IsNullOrEmpty(cavityData))
  10444. cavityData = "";
  10445. if (snResult != 0)
  10446. {
  10447. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10448. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10449. writeToPLC_Flag1.Adress = 2463;
  10450. writeToPLC_Flag1.Value = (short)4;
  10451. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10452. stopwatch1.Stop();
  10453. AddMessage(LogType.Info,
  10454. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10455. "ms");
  10456. return;
  10457. }
  10458. string[] partSNs = cavityData.Split('.');
  10459. if (partSNs != null && partSNs.Length >= 1)
  10460. partNo = partSNs[0];
  10461. #endregion 查询载具上的产品信息
  10462. partNos.Add(partNo);
  10463. }
  10464. }
  10465. // 统一上传 - 调用MES出站
  10466. stopwatch2.Start();
  10467. List<int> results = new List<int>();
  10468. for (int i = 0; i < partNos.Count; i++)
  10469. {
  10470. string index = (i + 1).ToString(); // 弹夹穴号
  10471. if (string.IsNullOrEmpty(partNos[i]))
  10472. results.Add(1);
  10473. else
  10474. {
  10475. List<TestItem> items1 = new List<TestItem>();
  10476. items1.Add(new TestItem()
  10477. {
  10478. Parameter_name = "弹夹码",
  10479. Parameter_value = sn,
  10480. Parameter_unit = ""
  10481. });
  10482. items1.Add(new TestItem()
  10483. {
  10484. Parameter_name = "弹夹穴号",
  10485. Parameter_value = index,
  10486. Parameter_unit = ""
  10487. });
  10488. items1.Add(new TestItem()
  10489. {
  10490. Parameter_name = "载具码",
  10491. Parameter_value = vehicleCodes[i],
  10492. Parameter_unit = ""
  10493. });
  10494. items1.Add(new TestItem()
  10495. {
  10496. Parameter_name = "载具穴号",
  10497. Parameter_value = "1",
  10498. Parameter_unit = ""
  10499. });
  10500. items1.Add(new TestItem()
  10501. {
  10502. Parameter_name = "产品结果",
  10503. Parameter_value = d3Result == 1 ? "OK" : "NG",
  10504. Parameter_unit = ""
  10505. });
  10506. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  10507. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  10508. results.Add(result1);
  10509. }
  10510. }
  10511. short result = 0;
  10512. if (results.All(a => a == 1))
  10513. result = 1;
  10514. else if (results.Contains(3))
  10515. result = 3;
  10516. else if (results.Contains(2))
  10517. result = 2;
  10518. else if (results.Contains(4))
  10519. result = 4;
  10520. else
  10521. result = 4;
  10522. stopwatch2.Stop();
  10523. // MES_Flag 为4MES报错
  10524. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10525. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10526. writeToPLC_Flag.Name = "d3MES_FLAG";
  10527. writeToPLC_Flag.Adress = 2463;
  10528. writeToPLC_Flag.Value = result;
  10529. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10530. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10531. }
  10532. catch (Exception ex)
  10533. {
  10534. stopwatch2.Restart();
  10535. // MES_Flag 为4上位机报错
  10536. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  10537. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10538. writeToPLC_Flag.Name = "d3MES_FLAG";
  10539. writeToPLC_Flag.Adress = 2463;
  10540. writeToPLC_Flag.Value = (short)4;
  10541. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10542. string str = ex.StackTrace;
  10543. AddMessage_Station(stationNameStr, LogType.Error,
  10544. $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10545. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10546. stopwatch2.Stop();
  10547. }
  10548. stopwatch1.Stop();
  10549. AddMessage(LogType.Info,
  10550. stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10551. stopwatch2.ElapsedMilliseconds + "ms");
  10552. }
  10553. // 上次采集到的SN
  10554. //private string sn_S4_4进站接口 = string.Empty;
  10555. /// <summary>
  10556. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  10557. /// </summary>
  10558. private void S4_4进站接口(int plcNo, string stationNameStr)
  10559. {
  10560. Stopwatch stopwatch1 = new Stopwatch();
  10561. Stopwatch stopwatch2 = new Stopwatch();
  10562. try
  10563. {
  10564. stopwatch1.Start();
  10565. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  10566. sn = sn.Replace("\0", "");
  10567. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  10568. #region 查询15个载具码
  10569. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10570. string vehicleData = string.Empty;
  10571. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10572. if (string.IsNullOrEmpty(vehicleData))
  10573. vehicleData = "";
  10574. if (snResult != 0)
  10575. {
  10576. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10577. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10578. writeToPLC_Flag1.Adress = 2463;
  10579. writeToPLC_Flag1.Value = (short)4;
  10580. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10581. stopwatch1.Stop();
  10582. AddMessage(LogType.Info,
  10583. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10584. return;
  10585. }
  10586. string[] cavitySNs = vehicleData.Split('.');
  10587. if (cavitySNs != null && cavitySNs.Length > 0)
  10588. {
  10589. for (int i = 0; i < cavitySNs.Length; i++)
  10590. {
  10591. if (string.IsNullOrEmpty(cavitySNs[i]))
  10592. vehicleCodes.Add("");
  10593. else
  10594. vehicleCodes.Add(cavitySNs[i]);
  10595. }
  10596. }
  10597. #endregion 查询15个载具码
  10598. #region 查询15个产品SN
  10599. List<string> portNos = new List<string>(); // 15个产品SN
  10600. foreach (string vehicleCode in vehicleCodes)
  10601. {
  10602. if (string.IsNullOrEmpty(vehicleCode))
  10603. portNos.Add("");
  10604. else
  10605. {
  10606. // 查询
  10607. string cavityData = string.Empty;
  10608. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10609. if (string.IsNullOrEmpty(cavityData))
  10610. cavityData = "";
  10611. if (snResult1 != 0)
  10612. {
  10613. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10614. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10615. writeToPLC_Flag1.Adress = 2463;
  10616. writeToPLC_Flag1.Value = (short)4;
  10617. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10618. stopwatch1.Stop();
  10619. AddMessage(LogType.Info,
  10620. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  10621. stopwatch1.ElapsedMilliseconds + "ms");
  10622. return;
  10623. }
  10624. string[] partSNs = cavityData.Split('.');
  10625. if (partSNs != null && partSNs.Length >= 1)
  10626. portNos.Add(partSNs[0]);
  10627. else
  10628. portNos.Add("");
  10629. }
  10630. }
  10631. #endregion 查询15个产品SN
  10632. // 调用MES进站(最多15个)
  10633. stopwatch2.Start();
  10634. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  10635. for (int i = 0; i < vehicleCodes.Count; i++)
  10636. {
  10637. // 循环进站
  10638. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  10639. {
  10640. // 产品SN(物料码)校验
  10641. string portNo = portNos[i];
  10642. List<TestItem> item = new List<TestItem>();
  10643. item.Add(new TestItem()
  10644. {
  10645. Parameter_name = "弹夹码",
  10646. Parameter_value = sn,
  10647. });
  10648. item.Add(new TestItem()
  10649. {
  10650. Parameter_name = "弹夹穴位",
  10651. Parameter_value = (i + 1).ToString(),
  10652. });
  10653. item.Add(new TestItem()
  10654. {
  10655. Parameter_name = "载具码",
  10656. Parameter_value = vehicleCodes[i],
  10657. });
  10658. item.Add(new TestItem()
  10659. {
  10660. Parameter_name = "载具穴号",
  10661. Parameter_value = "1",
  10662. });
  10663. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  10664. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  10665. }
  10666. }
  10667. stopwatch2.Stop();
  10668. short result = 0;
  10669. bool haveMesWarn = results.Contains(5);
  10670. bool havePCWarn = results.Contains(6);
  10671. if (haveMesWarn)
  10672. result = 2; // 5->2
  10673. else if (havePCWarn)
  10674. result = 6; // 6->4
  10675. else
  10676. result = 1;
  10677. // MES_Flag 为4MES报错
  10678. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10679. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10680. writeToPLC_Flag.Name = "d4MES_FLAG";
  10681. writeToPLC_Flag.Adress = 2496;
  10682. writeToPLC_Flag.Value = result;
  10683. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10684. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10685. }
  10686. catch (Exception ex)
  10687. {
  10688. stopwatch2.Stop();
  10689. // MES_Flag 为4上位机报错
  10690. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  10691. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10692. writeToPLC_Flag.Name = "d4MES_FLAG";
  10693. writeToPLC_Flag.Adress = 2496;
  10694. writeToPLC_Flag.Value = (short)4;
  10695. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10696. string str = ex.StackTrace;
  10697. AddMessage_Station(stationNameStr, LogType.Error,
  10698. $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10699. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10700. }
  10701. stopwatch1.Stop();
  10702. AddMessage(LogType.Info,
  10703. stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  10704. stopwatch2.ElapsedMilliseconds + "ms");
  10705. }
  10706. // 上次采集到的SN
  10707. //private string sn_S4_4出站接口 = string.Empty;
  10708. /// <summary>
  10709. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  10710. /// </summary>
  10711. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  10712. {
  10713. Stopwatch stopwatch1 = new Stopwatch();
  10714. Stopwatch stopwatch2 = new Stopwatch();
  10715. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10716. string stationNameStr = stationCode + stationName;
  10717. string processItem = stationName; // 测试项目
  10718. try
  10719. {
  10720. stopwatch1.Start();
  10721. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10722. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10723. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10724. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10725. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  10726. sn = sn.Replace("\0", "");
  10727. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  10728. bool isPass = d4Result == 1; // 产品结果 bool
  10729. #region 查询15个载具码
  10730. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10731. string vehicleData = string.Empty;
  10732. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10733. if (string.IsNullOrEmpty(vehicleData))
  10734. vehicleData = "";
  10735. if (snResult1 != 0)
  10736. {
  10737. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10738. writeToPLC_Flag1.Name = "d4MES_FLAG";
  10739. writeToPLC_Flag1.Adress = 2496;
  10740. writeToPLC_Flag1.Value = (short)4;
  10741. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  10742. stopwatch1.Stop();
  10743. AddMessage(LogType.Info,
  10744. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10745. return;
  10746. }
  10747. string[] cavitySNs = vehicleData.Split('.');
  10748. if (cavitySNs != null && cavitySNs.Length > 0)
  10749. {
  10750. for (int i = 0; i < cavitySNs.Length; i++)
  10751. {
  10752. if (string.IsNullOrEmpty(cavitySNs[i]))
  10753. vehicleCodes.Add("");
  10754. else
  10755. vehicleCodes.Add(cavitySNs[i]);
  10756. }
  10757. }
  10758. #endregion 查询15个载具码
  10759. // 统一查 产品SN列表
  10760. List<string> partNos = new List<string>();
  10761. foreach (string vehicleCode in vehicleCodes)
  10762. {
  10763. if (string.IsNullOrEmpty(vehicleCode))
  10764. partNos.Add("");
  10765. else
  10766. {
  10767. string partNo = "";
  10768. #region 查询载具上的产品信息
  10769. string cavityData = string.Empty;
  10770. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10771. if (string.IsNullOrEmpty(cavityData))
  10772. cavityData = "";
  10773. if (snResult != 0)
  10774. {
  10775. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10776. writeToPLC_Flag1.Name = "d4MES_FLAG";
  10777. writeToPLC_Flag1.Adress = 2496;
  10778. writeToPLC_Flag1.Value = (short)4;
  10779. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  10780. stopwatch1.Stop();
  10781. AddMessage(LogType.Info,
  10782. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10783. "ms");
  10784. return;
  10785. }
  10786. string[] partSNs = cavityData.Split('.');
  10787. if (partSNs != null && partSNs.Length >= 1)
  10788. partNo = partSNs[0];
  10789. #endregion 查询载具上的产品信息
  10790. partNos.Add(partNo);
  10791. }
  10792. }
  10793. // 调用MES出站
  10794. stopwatch2.Start();
  10795. // 统一上传
  10796. List<int> results = new List<int>();
  10797. for (int i = 0; i < partNos.Count; i++)
  10798. {
  10799. string index = (i + 1).ToString(); // 弹夹穴号
  10800. if (string.IsNullOrEmpty(partNos[i]))
  10801. results.Add(1);
  10802. else
  10803. {
  10804. List<TestItem> items1 = new List<TestItem>();
  10805. items1.Add(new TestItem()
  10806. {
  10807. Parameter_name = "弹夹码",
  10808. Parameter_value = sn,
  10809. Parameter_unit = ""
  10810. });
  10811. items1.Add(new TestItem()
  10812. {
  10813. Parameter_name = "弹夹穴号",
  10814. Parameter_value = index,
  10815. Parameter_unit = ""
  10816. });
  10817. items1.Add(new TestItem()
  10818. {
  10819. Parameter_name = "载具码",
  10820. Parameter_value = vehicleCodes[i],
  10821. Parameter_unit = ""
  10822. });
  10823. items1.Add(new TestItem()
  10824. {
  10825. Parameter_name = "载具穴号",
  10826. Parameter_value = "1",
  10827. Parameter_unit = ""
  10828. });
  10829. items1.Add(new TestItem()
  10830. {
  10831. Parameter_name = "产品结果",
  10832. Parameter_value = d4Result == 1 ? "OK" : "NG",
  10833. Parameter_unit = ""
  10834. });
  10835. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  10836. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  10837. results.Add(result1);
  10838. }
  10839. }
  10840. short result = 0;
  10841. if (results.All(a => a == 1))
  10842. result = 1;
  10843. else if (results.Contains(3))
  10844. result = 3;
  10845. else if (results.Contains(2))
  10846. result = 2;
  10847. else if (results.Contains(4))
  10848. result = 4;
  10849. else
  10850. result = 4;
  10851. stopwatch2.Stop();
  10852. // MES_Flag 为4MES报错
  10853. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10854. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10855. writeToPLC_Flag.Name = "d4MES_FLAG";
  10856. writeToPLC_Flag.Adress = 2496;
  10857. writeToPLC_Flag.Value = result;
  10858. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10859. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10860. }
  10861. catch (Exception ex)
  10862. {
  10863. stopwatch2.Restart();
  10864. // MES_Flag 为4上位机报错
  10865. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  10866. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10867. writeToPLC_Flag.Name = "d4MES_FLAG";
  10868. writeToPLC_Flag.Adress = 2496;
  10869. writeToPLC_Flag.Value = (short)4;
  10870. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10871. string str = ex.StackTrace;
  10872. AddMessage_Station(stationNameStr, LogType.Error,
  10873. $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10874. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10875. stopwatch2.Stop();
  10876. }
  10877. stopwatch1.Stop();
  10878. AddMessage(LogType.Info,
  10879. stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10880. stopwatch2.ElapsedMilliseconds + "ms");
  10881. }
  10882. /// <summary>
  10883. /// [S4] 取放桁架 - S4_5弹夹扫码
  10884. /// </summary>
  10885. /// <param name="plcNo">PLC编号</param>
  10886. /// <param name="stationNameStr">工站全称</param>
  10887. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  10888. {
  10889. Stopwatch stopwatch1 = new Stopwatch();
  10890. Stopwatch stopwatch2 = new Stopwatch();
  10891. try
  10892. {
  10893. stopwatch1.Start();
  10894. // ZS 弹夹扫码
  10895. string d5BulletclipCode = " "; // 扫到的码
  10896. short d5BulletclipScanCode = 2;
  10897. stopwatch2.Start();
  10898. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  10899. //// MES_Flag
  10900. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10901. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10902. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  10903. writeToPLC_Flag.Adress = 2528;
  10904. writeToPLC_Flag.Value = d5BulletclipScanCode;
  10905. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10906. {
  10907. Name = "d5BulletclipCode",
  10908. Adress = 2529,
  10909. ValueType = PLCValueType.String,
  10910. ValueTypeStrLength = 20,
  10911. Value = d5BulletclipCode
  10912. });
  10913. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  10914. stopwatch2.Stop();
  10915. }
  10916. catch (Exception ex)
  10917. {
  10918. string str = ex.StackTrace;
  10919. AddMessage_Station(stationNameStr, LogType.Error,
  10920. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10921. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10922. stopwatch2.Start();
  10923. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  10924. //// MES_Flag
  10925. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  10926. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10927. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  10928. writeToPLC_Flag.Adress = 2528;
  10929. writeToPLC_Flag.Value = (short)6;
  10930. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10931. {
  10932. Name = "d5BulletclipCode",
  10933. Adress = 2529,
  10934. ValueType = PLCValueType.String,
  10935. ValueTypeStrLength = 20,
  10936. Value = " "
  10937. });
  10938. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  10939. stopwatch2.Stop();
  10940. }
  10941. stopwatch1.Stop();
  10942. AddMessage(LogType.Info,
  10943. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10944. stopwatch2.ElapsedMilliseconds + "ms");
  10945. }
  10946. /// <summary>
  10947. /// [S4] 取放桁架 - S4_5载具扫码
  10948. /// </summary>
  10949. /// <param name="plcNo">PLC编号</param>
  10950. /// <param name="stationNameStr">工站全称</param>
  10951. private void S4_5载具扫码(int plcNo, string stationNameStr)
  10952. {
  10953. Stopwatch stopwatch1 = new Stopwatch();
  10954. Stopwatch stopwatch2 = new Stopwatch();
  10955. try
  10956. {
  10957. stopwatch1.Start();
  10958. // ZS 载具扫码
  10959. string d5VehicleCode = " "; // 扫到的码
  10960. short d5VehicleScanCode = 2;
  10961. #region 进站
  10962. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  10963. {
  10964. // 查产品SN
  10965. #region 查询载具上的产品信息
  10966. string cavityData = string.Empty;
  10967. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  10968. if (string.IsNullOrEmpty(cavityData))
  10969. cavityData = "";
  10970. if (snResult != 0)
  10971. {
  10972. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10973. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  10974. writeToPLC_Flag1.Adress = 2559;
  10975. writeToPLC_Flag1.Value = (short)6;
  10976. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10977. {
  10978. Name = "d5VehicleCode",
  10979. Adress = 2560,
  10980. ValueType = PLCValueType.String,
  10981. ValueTypeStrLength = 20,
  10982. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  10983. });
  10984. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  10985. stopwatch1.Stop();
  10986. AddMessage(LogType.Info,
  10987. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10988. "ms");
  10989. return;
  10990. }
  10991. string[] cavitySNs = cavityData.Split('.');
  10992. string partNo = "";
  10993. if (cavitySNs != null && cavitySNs.Length >= 1)
  10994. {
  10995. partNo = cavitySNs[0];
  10996. }
  10997. #endregion 查询载具上的产品信息
  10998. List<TestItem> item = new List<TestItem>();
  10999. item.Add(new TestItem()
  11000. {
  11001. Parameter_name = "载具码",
  11002. Parameter_value = d5VehicleCode,
  11003. });
  11004. item.Add(new TestItem()
  11005. {
  11006. Parameter_name = "载具穴号",
  11007. Parameter_value = "1",
  11008. });
  11009. stopwatch2.Start();
  11010. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  11011. partNo, item, out string errorMsg);
  11012. stopwatch2.Stop();
  11013. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  11014. }
  11015. #endregion 进站
  11016. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  11017. //// MES_Flag
  11018. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  11019. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11020. writeToPLC_Flag.Name = "d5VehicleScanCode";
  11021. writeToPLC_Flag.Adress = 2559;
  11022. writeToPLC_Flag.Value = d5VehicleScanCode;
  11023. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  11024. {
  11025. Name = "d5VehicleCode",
  11026. Adress = 2560,
  11027. ValueType = PLCValueType.String,
  11028. ValueTypeStrLength = 20,
  11029. Value = d5VehicleCode
  11030. });
  11031. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  11032. }
  11033. catch (Exception ex)
  11034. {
  11035. string str = ex.StackTrace;
  11036. AddMessage_Station(stationNameStr, LogType.Error,
  11037. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  11038. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11039. stopwatch2.Start();
  11040. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  11041. //// MES_Flag
  11042. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  11043. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11044. writeToPLC_Flag.Name = "d5VehicleScanCode";
  11045. writeToPLC_Flag.Adress = 2559;
  11046. writeToPLC_Flag.Value = (short)6;
  11047. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  11048. {
  11049. Name = "d5VehicleCode",
  11050. Adress = 2560,
  11051. ValueType = PLCValueType.String,
  11052. ValueTypeStrLength = 20,
  11053. Value = " "
  11054. });
  11055. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  11056. stopwatch2.Stop();
  11057. }
  11058. stopwatch1.Stop();
  11059. AddMessage(LogType.Info,
  11060. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11061. stopwatch2.ElapsedMilliseconds + "ms");
  11062. }
  11063. // 上次采集到的SN
  11064. //private string sn_S4_5出站接口 = string.Empty;
  11065. /// <summary>
  11066. /// [S4] 取放桁架 - S4_5出站接口
  11067. /// </summary>
  11068. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  11069. {
  11070. Stopwatch stopwatch1 = new Stopwatch();
  11071. Stopwatch stopwatch2 = new Stopwatch();
  11072. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  11073. string stationNameStr = stationCode + stationName;
  11074. string processItem = stationName; // 测试项目
  11075. try
  11076. {
  11077. stopwatch1.Start();
  11078. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  11079. //string batch_num = GlobalContext.BatchNumber; // 批次号
  11080. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  11081. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  11082. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  11083. sn = sn.Replace("\0", "");
  11084. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  11085. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  11086. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  11087. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  11088. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  11089. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  11090. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  11091. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  11092. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  11093. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  11094. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  11095. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  11096. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  11097. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  11098. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  11099. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  11100. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  11101. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  11102. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  11103. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  11104. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  11105. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  11106. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  11107. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  11108. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  11109. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  11110. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  11111. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  11112. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  11113. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  11114. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  11115. bool pass = d5Result == 1;
  11116. // 存 载具SN列表
  11117. List<string> vehicleCodes = new List<string>()
  11118. {
  11119. d5VehicleCode1, d5VehicleCode2, d5VehicleCode3, d5VehicleCode4, d5VehicleCode5,
  11120. d5VehicleCode6, d5VehicleCode7, d5VehicleCode8, d5VehicleCode9, d5VehicleCode10,
  11121. d5VehicleCode11, d5VehicleCode12, d5VehicleCode13, d5VehicleCode14, d5VehicleCode15
  11122. };
  11123. // 统一查 产品SN列表
  11124. List<string> partNos = new List<string>();
  11125. foreach (string vehicleCode in vehicleCodes)
  11126. {
  11127. if (string.IsNullOrEmpty(vehicleCode))
  11128. partNos.Add("");
  11129. else
  11130. {
  11131. string partNo = "";
  11132. #region 查询载具上的产品信息
  11133. string cavityData = string.Empty;
  11134. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  11135. if (string.IsNullOrEmpty(cavityData))
  11136. cavityData = "";
  11137. if (snResult != 0)
  11138. {
  11139. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11140. writeToPLC_Flag1.Name = "d5MES_FLAG";
  11141. writeToPLC_Flag1.Adress = 2591;
  11142. writeToPLC_Flag1.Value = (short)4;
  11143. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  11144. stopwatch1.Stop();
  11145. AddMessage(LogType.Info,
  11146. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  11147. "ms");
  11148. return;
  11149. }
  11150. string[] cavitySNs = cavityData.Split('.');
  11151. if (cavitySNs != null && cavitySNs.Length >= 1)
  11152. partNo = cavitySNs[0];
  11153. #endregion 查询载具上的产品信息
  11154. partNos.Add(partNo);
  11155. }
  11156. }
  11157. // 统一上传
  11158. stopwatch2.Start();
  11159. List<int> results = new List<int>();
  11160. for (int i = 0; i < partNos.Count; i++)
  11161. {
  11162. string index = (i + 1).ToString(); // 弹夹穴号
  11163. if (string.IsNullOrEmpty(partNos[i]))
  11164. results.Add(1);
  11165. else
  11166. {
  11167. List<TestItem> items1 = new List<TestItem>();
  11168. items1.Add(new TestItem()
  11169. {
  11170. Parameter_name = "弹夹码",
  11171. Parameter_value = sn,
  11172. Parameter_unit = ""
  11173. });
  11174. items1.Add(new TestItem()
  11175. {
  11176. Parameter_name = "弹夹穴号",
  11177. Parameter_value = index,
  11178. Parameter_unit = ""
  11179. });
  11180. items1.Add(new TestItem()
  11181. {
  11182. Parameter_name = "载具码",
  11183. Parameter_value = vehicleCodes[i],
  11184. Parameter_unit = ""
  11185. });
  11186. items1.Add(new TestItem()
  11187. {
  11188. Parameter_name = "载具穴号",
  11189. Parameter_value = "1",
  11190. Parameter_unit = ""
  11191. });
  11192. items1.Add(new TestItem()
  11193. {
  11194. Parameter_name = "产品结果",
  11195. Parameter_value = d5Result == 1 ? "OK" : "NG",
  11196. Parameter_unit = ""
  11197. });
  11198. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  11199. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  11200. results.Add(result1);
  11201. }
  11202. }
  11203. short result = 0;
  11204. if (results.All(a => a == 1))
  11205. result = 1;
  11206. else if (results.Contains(3))
  11207. result = 3;
  11208. else if (results.Contains(2))
  11209. result = 2;
  11210. else if (results.Contains(4))
  11211. result = 4;
  11212. else
  11213. result = 4;
  11214. stopwatch2.Stop();
  11215. #region 存储绑定数据到 边线MES系统中
  11216. if (result == 1)
  11217. {
  11218. // 删除绑定信息
  11219. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  11220. if (resultMesR != 0)
  11221. {
  11222. result = 4;
  11223. AddMessage_Station(stationNameStr, LogType.Error,
  11224. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  11225. }
  11226. }
  11227. #endregion 存储绑定数据到 边线MES系统中
  11228. // MES_Flag 为4MES报错
  11229. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11230. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11231. writeToPLC_Flag.Name = "d5MES_FLAG";
  11232. writeToPLC_Flag.Adress = 2591;
  11233. writeToPLC_Flag.Value = result;
  11234. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  11235. OnMessage(LogType.Debug,
  11236. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  11237. }
  11238. catch (Exception ex)
  11239. {
  11240. stopwatch2.Restart();
  11241. // MES_Flag 为4上位机报错
  11242. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  11243. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11244. writeToPLC_Flag.Name = "d5MES_FLAG";
  11245. writeToPLC_Flag.Adress = 2591;
  11246. writeToPLC_Flag.Value = (short)4;
  11247. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  11248. stopwatch2.Stop();
  11249. string str = ex.StackTrace;
  11250. AddMessage_Station(stationNameStr, LogType.Error,
  11251. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11252. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11253. }
  11254. stopwatch1.Stop();
  11255. AddMessage(LogType.Info,
  11256. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11257. stopwatch2.ElapsedMilliseconds + "ms");
  11258. }
  11259. /// <summary>
  11260. /// [S4] 取放桁架 - S4_5节拍接口
  11261. /// </summary>
  11262. /// <param name="plcNo">PLC编号</param>
  11263. /// <param name="stationNameStr">工站全称</param>
  11264. private void S4_5节拍接口(int plcNo, string stationNameStr)
  11265. {
  11266. Stopwatch stopwatch1 = new Stopwatch();
  11267. Stopwatch stopwatch2 = new Stopwatch();
  11268. string resultStr = string.Empty;
  11269. try
  11270. {
  11271. stopwatch1.Start();
  11272. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  11273. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  11274. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  11275. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  11276. if (!actionBool)
  11277. {
  11278. stopwatch2.Start();
  11279. // MES_Flag
  11280. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  11281. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11282. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  11283. writeToPLC_Flag1.Adress = 2924;
  11284. writeToPLC_Flag1.Value = (short)4;
  11285. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  11286. stopwatch2.Stop();
  11287. AddMessage(LogType.Info,
  11288. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  11289. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  11290. return;
  11291. }
  11292. string d5OEEPartNo = string.Empty; // 物料码
  11293. if (string.IsNullOrEmpty(d5OEEProductSN))
  11294. {
  11295. stopwatch2.Start();
  11296. // MES_Flag
  11297. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11298. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11299. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  11300. writeToPLC_Flag1.Adress = 2924;
  11301. writeToPLC_Flag1.Value = (short)1;
  11302. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  11303. stopwatch2.Stop();
  11304. AddMessage(LogType.Info,
  11305. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11306. stopwatch2.ElapsedMilliseconds + "ms");
  11307. return;
  11308. }
  11309. else
  11310. {
  11311. // 查产品SN
  11312. d5OEEPartNo = "Test"; // ZS
  11313. }
  11314. short d5OEEMES_FLAG = 0;
  11315. // 上传OEE
  11316. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  11317. d5OEEMES_FLAG = result.Item1;
  11318. resultStr = result.Item2;
  11319. stopwatch2.Start();
  11320. // MES_Flag
  11321. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11322. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11323. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  11324. writeToPLC_Flag.Adress = 2924;
  11325. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  11326. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  11327. stopwatch2.Stop();
  11328. }
  11329. catch (Exception ex)
  11330. {
  11331. string str = ex.StackTrace;
  11332. AddMessage_Station(stationNameStr, LogType.Error,
  11333. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  11334. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11335. // MES_Flag
  11336. stopwatch2.Start();
  11337. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  11338. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11339. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  11340. writeToPLC_Flag.Adress = 2924;
  11341. writeToPLC_Flag.Value = (short)4;
  11342. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  11343. stopwatch2.Stop();
  11344. }
  11345. stopwatch1.Stop();
  11346. AddMessage(LogType.Info,
  11347. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11348. stopwatch2.ElapsedMilliseconds + "ms");
  11349. }
  11350. #endregion [S4] 取放桁架
  11351. #endregion PLC4 刘果段
  11352. #region PLC5 张超凡
  11353. #region [S5] Tray盘下料装备
  11354. /// <summary>
  11355. /// S5工位的数据- 触发信号上次的值
  11356. /// </summary>
  11357. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  11358. /// <summary>
  11359. /// S5工位的数据(含触发信号)
  11360. /// </summary>
  11361. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  11362. /// <summary>
  11363. /// S5工位的数据- 回写点位
  11364. /// </summary>
  11365. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  11366. /// <summary>
  11367. /// [S5] Tray盘下料装备
  11368. /// </summary>
  11369. /// <param name="plcNo">PLC编号</param>
  11370. //private void ReadStation_S5(int plcNo)
  11371. //{
  11372. // // [S1] Tray盘上料装备
  11373. // // [S2] FCT
  11374. // // [S3] 值板机
  11375. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  11376. // // [S5] Tray盘下料装备
  11377. // /// 上位机心跳
  11378. // /// 获取设备报警数据与状态信息
  11379. // string stationCode = "[S5]";
  11380. // string stationName = "Tray盘下料装备";
  11381. // string stationNameStr = stationCode + stationName;
  11382. // #region 创建字典
  11383. // // 触发信号字典 赋值
  11384. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  11385. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  11386. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  11387. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  11388. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  11389. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  11390. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  11391. // // PLC数据字典 赋值
  11392. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  11393. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  11394. // s5PLCData.Add("e1ProductSN_Check", ""); //
  11395. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  11396. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  11397. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  11398. // s5PLCData.Add("e1PartNo", ""); // 物料码
  11399. // s5PLCData.Add("e1Result", 0); // 产品结果
  11400. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  11401. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  11402. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  11403. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  11404. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  11405. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  11406. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  11407. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  11408. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  11409. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  11410. // #endregion 创建字典
  11411. // while (IsRun)
  11412. // {
  11413. // try
  11414. // {
  11415. // if (!GlobalContext._IsCon_Funs5)
  11416. // {
  11417. // UpdatePLCMonitor(1, plcNo, 0);
  11418. // continue;
  11419. // }
  11420. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  11421. // {
  11422. // Stopwatch stopwatch1 = new Stopwatch();
  11423. // Stopwatch stopwatch2 = new Stopwatch();
  11424. // stopwatch1.Start();
  11425. // stopwatch2.Start();
  11426. // #region 一次性读取所有数据
  11427. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  11428. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  11429. // int[] datas = data1.Concat(data2).ToArray();
  11430. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  11431. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  11432. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  11433. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  11434. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  11435. // s5PLCData["e1MES_FLAG"] = datas[35];
  11436. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  11437. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  11438. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  11439. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  11440. // s5PLCData["e1Result"] = datas[76];
  11441. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  11442. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  11443. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  11444. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  11445. // s5PLCData["e1OEEType"] = datas[109];
  11446. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  11447. // s5PLCData["e1AGVUpStart"] = datas[121];
  11448. // s5PLCData["e1AGVUpEnd"] = datas[122];
  11449. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  11450. // s5PLCData["e1AGVDownStart"] = datas[134];
  11451. // s5PLCData["e1AGVDownEnd"] = datas[135];
  11452. // #endregion 一次性读取所有数据
  11453. // stopwatch2.Stop();
  11454. // #region 回写操作,写后清空flag
  11455. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  11456. // #endregion 回写操作,写后清空flag
  11457. // #region 进站校验
  11458. // try
  11459. // {
  11460. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  11461. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  11462. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  11463. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  11464. // {
  11465. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  11466. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  11467. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  11468. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  11469. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  11470. // }
  11471. // }
  11472. // catch (Exception ex)
  11473. // {
  11474. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  11475. // string str = ex.StackTrace;
  11476. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11477. // }
  11478. // #endregion 进站校验
  11479. // #region 出站接口
  11480. // try
  11481. // {
  11482. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  11483. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  11484. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  11485. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  11486. // {
  11487. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  11488. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  11489. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  11490. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  11491. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  11492. // }
  11493. // }
  11494. // catch (Exception ex)
  11495. // {
  11496. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  11497. // string str = ex.StackTrace;
  11498. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11499. // }
  11500. // #endregion 出站接口
  11501. // #region 节拍接口
  11502. // try
  11503. // {
  11504. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  11505. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  11506. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  11507. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  11508. // {
  11509. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  11510. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  11511. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  11512. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  11513. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  11514. // }
  11515. // }
  11516. // catch (Exception ex)
  11517. // {
  11518. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  11519. // string str = ex.StackTrace;
  11520. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11521. // }
  11522. // #endregion 节拍接口
  11523. // #region AGV上料
  11524. // // AGV上料叫AGV信号
  11525. // try
  11526. // {
  11527. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  11528. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  11529. // if (e1AGVUpCall != e1AGVUpCallOld)
  11530. // {
  11531. // if (e1AGVUpCall == 1) // 0->1
  11532. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  11533. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  11534. // }
  11535. // }
  11536. // catch (Exception ex)
  11537. // {
  11538. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  11539. // string str = ex.StackTrace;
  11540. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11541. // }
  11542. // // AGV上料完成信号
  11543. // try
  11544. // {
  11545. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  11546. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  11547. // if (e1AGVUpEnd != e1AGVUpEndOld)
  11548. // {
  11549. // if (e1AGVUpEnd == 1) // 0->1
  11550. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  11551. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  11552. // }
  11553. // }
  11554. // catch (Exception ex)
  11555. // {
  11556. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  11557. // string str = ex.StackTrace;
  11558. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11559. // }
  11560. // #endregion AGV上料
  11561. // #region AGV下料
  11562. // // AGV下料叫agv信号
  11563. // try
  11564. // {
  11565. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  11566. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  11567. // if (e1AGVDownCall != e1AGVDownCallOld)
  11568. // {
  11569. // if (e1AGVDownCall == 1) // 0->1
  11570. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  11571. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  11572. // }
  11573. // }
  11574. // catch (Exception ex)
  11575. // {
  11576. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  11577. // string str = ex.StackTrace;
  11578. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11579. // }
  11580. // // AGV下料完成信号
  11581. // try
  11582. // {
  11583. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  11584. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  11585. // if (e1AGVDownEnd != e1AGVDownEndOld)
  11586. // {
  11587. // if (e1AGVDownEnd == 1) // 0->1
  11588. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  11589. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  11590. // }
  11591. // }
  11592. // catch (Exception ex)
  11593. // {
  11594. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  11595. // string str = ex.StackTrace;
  11596. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11597. // }
  11598. // #endregion AGV下料
  11599. // #region 心跳
  11600. // try
  11601. // {
  11602. // short states = 0;
  11603. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  11604. // }
  11605. // catch (Exception ex)
  11606. // {
  11607. // string str = ex.StackTrace;
  11608. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11609. // }
  11610. // #endregion 心跳
  11611. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  11612. // stopwatch1.Stop();
  11613. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  11614. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  11615. // }
  11616. // else
  11617. // {
  11618. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  11619. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  11620. // Funs[plcNo].Connect();
  11621. // }
  11622. // }
  11623. // catch (Exception ex)
  11624. // {
  11625. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  11626. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  11627. // Funs[plcNo].ReConnect();
  11628. // }
  11629. // Thread.Sleep(IntervalReadPLC);
  11630. // }
  11631. //}
  11632. /// <summary>
  11633. /// [S5] Tray盘下料装备 - 进站校验
  11634. /// </summary>
  11635. /// <param name="plcNo">PLC编号</param>
  11636. /// <param name="stationNameStr">工站全称</param>
  11637. private void S5进站校验(int plcNo, string stationNameStr)
  11638. {
  11639. Stopwatch stopwatch1 = new Stopwatch();
  11640. Stopwatch stopwatch2 = new Stopwatch();
  11641. try
  11642. {
  11643. stopwatch1.Start();
  11644. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  11645. sn = sn.Replace("\0", "");
  11646. // 获取产品SN By 载具码
  11647. #region 查询载具上的产品信息
  11648. string cavityData = string.Empty;
  11649. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  11650. if (string.IsNullOrEmpty(cavityData))
  11651. cavityData = "";
  11652. if (snResult != 0)
  11653. {
  11654. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11655. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  11656. writeToPLC_Flag1.Adress = 2003;
  11657. writeToPLC_Flag1.Value = (short)6;
  11658. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  11659. stopwatch1.Stop();
  11660. AddMessage(LogType.Info,
  11661. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11662. return;
  11663. }
  11664. string[] cavitySNs = cavityData.Split('.');
  11665. string partNo = string.Empty;
  11666. if (cavitySNs != null && cavitySNs.Length >= 1)
  11667. partNo = cavitySNs[0];
  11668. #endregion 查询载具上的产品信息
  11669. // 产品SN(物料码)校验
  11670. List<TestItem> item = new List<TestItem>();
  11671. item.Add(new TestItem()
  11672. {
  11673. Parameter_name = "载具码",
  11674. Parameter_value = sn,
  11675. });
  11676. item.Add(new TestItem()
  11677. {
  11678. Parameter_name = "载具穴号",
  11679. Parameter_value = "1",
  11680. });
  11681. stopwatch2.Start();
  11682. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  11683. partNo, item, out string errorMsg);
  11684. stopwatch2.Stop();
  11685. short e1MES_FLAG_Check = (short)result;
  11686. // MES_Flag
  11687. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  11688. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11689. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  11690. writeToPLC_Flag.Adress = 2003;
  11691. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  11692. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  11693. }
  11694. catch (Exception ex)
  11695. {
  11696. string str = ex.StackTrace;
  11697. AddMessage_Station(stationNameStr, LogType.Error,
  11698. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  11699. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11700. // MES_Flag
  11701. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  11702. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11703. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  11704. writeToPLC_Flag.Adress = 2003;
  11705. writeToPLC_Flag.Value = (short)6;
  11706. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  11707. }
  11708. stopwatch1.Stop();
  11709. AddMessage(LogType.Info,
  11710. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  11711. stopwatch2.ElapsedMilliseconds + "ms");
  11712. }
  11713. /// <summary>
  11714. /// [S5] Tray盘下料装备 - 出站接口
  11715. /// </summary>
  11716. /// <param name="plcNo"></param>
  11717. /// <param name="stationCode"></param>
  11718. /// <param name="stationName"></param>
  11719. private void S5出站接口(int plcNo, string stationCode, string stationName)
  11720. {
  11721. Stopwatch stopwatch1 = new Stopwatch();
  11722. Stopwatch stopwatch2 = new Stopwatch();
  11723. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  11724. string stationNameStr = stationCode + stationName;
  11725. string processItem = stationName; // 测试项目
  11726. try
  11727. {
  11728. stopwatch1.Start();
  11729. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  11730. //string batch_num = GlobalContext.BatchNumber; // 批次号
  11731. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  11732. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  11733. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  11734. sn = sn.Replace("\0", "");
  11735. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  11736. //partNo = partNo.Replace("\0", "");
  11737. #region 查询载具上的产品信息
  11738. string cavityData = string.Empty;
  11739. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  11740. if (string.IsNullOrEmpty(cavityData))
  11741. cavityData = "";
  11742. if (snResult != 0)
  11743. {
  11744. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11745. writeToPLC_Flag1.Name = "e1MES_FLAG";
  11746. writeToPLC_Flag1.Adress = 2035;
  11747. writeToPLC_Flag1.Value = (short)4;
  11748. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  11749. stopwatch1.Stop();
  11750. AddMessage(LogType.Info,
  11751. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11752. return;
  11753. }
  11754. string[] cavitySNs = cavityData.Split('.');
  11755. string partNo = string.Empty;
  11756. if (cavitySNs != null && cavitySNs.Length >= 1)
  11757. partNo = cavitySNs[0];
  11758. #endregion 查询载具上的产品信息
  11759. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  11760. bool pass = e1Result == 1;
  11761. stopwatch2.Start();
  11762. // 上传MES
  11763. List<TestItem> items = new List<TestItem>();
  11764. items.Add(new TestItem()
  11765. {
  11766. Parameter_name = "载具码",
  11767. Parameter_value = sn,
  11768. Parameter_unit = ""
  11769. });
  11770. items.Add(new TestItem()
  11771. {
  11772. Parameter_name = "载具穴号",
  11773. Parameter_value = "1",
  11774. Parameter_unit = ""
  11775. });
  11776. items.Add(new TestItem()
  11777. {
  11778. Parameter_name = "产品结果",
  11779. Parameter_value = e1Result == 1 ? "OK" : "NG",
  11780. Parameter_unit = ""
  11781. });
  11782. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  11783. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  11784. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  11785. short result = result1 == 1 ? (short)1 : (short)3;
  11786. stopwatch2.Stop();
  11787. #region 存储绑定数据到 边线MES系统中
  11788. if (result == 1)
  11789. {
  11790. // 删除绑定信息
  11791. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  11792. if (resultMesR != 0)
  11793. {
  11794. result = 4;
  11795. AddMessage_Station(stationNameStr, LogType.Error,
  11796. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  11797. }
  11798. }
  11799. #endregion 存储绑定数据到 边线MES系统中
  11800. // MES_Flag 为MES报错
  11801. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11802. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  11803. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11804. writeToPLC_Flag.Name = "e1MES_FLAG";
  11805. writeToPLC_Flag.Adress = 2035;
  11806. writeToPLC_Flag.Value = result;
  11807. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  11808. OnMessage(LogType.Debug,
  11809. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  11810. }
  11811. catch (Exception ex)
  11812. {
  11813. stopwatch2.Restart();
  11814. // MES_Flag 为4上位机报错
  11815. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  11816. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11817. writeToPLC_Flag.Name = "e1MES_FLAG";
  11818. writeToPLC_Flag.Adress = 2035;
  11819. writeToPLC_Flag.Value = (short)4;
  11820. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  11821. stopwatch2.Stop();
  11822. string str = ex.StackTrace;
  11823. AddMessage_Station(stationNameStr, LogType.Error,
  11824. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11825. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11826. }
  11827. stopwatch1.Stop();
  11828. AddMessage(LogType.Info,
  11829. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11830. stopwatch2.ElapsedMilliseconds + "ms");
  11831. }
  11832. /// <summary>
  11833. /// [S5] Tray盘下料装备 - 节拍接口
  11834. /// </summary>
  11835. /// <param name="plcNo">PLC编号</param>
  11836. /// <param name="stationNameStr">工站全称</param>
  11837. //private void S5节拍接口(int plcNo, string stationNameStr)
  11838. //{
  11839. // Stopwatch stopwatch1 = new Stopwatch();
  11840. // Stopwatch stopwatch2 = new Stopwatch();
  11841. // string resultStr = string.Empty;
  11842. // try
  11843. // {
  11844. // stopwatch1.Start();
  11845. // string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  11846. // string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  11847. // e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  11848. // bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  11849. // if (!actionBool)
  11850. // {
  11851. // stopwatch2.Start();
  11852. // // MES_Flag
  11853. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11854. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11855. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  11856. // writeToPLC_Flag1.Adress = 2088;
  11857. // writeToPLC_Flag1.Value = (short)4;
  11858. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  11859. // stopwatch2.Stop();
  11860. // AddMessage(LogType.Info,
  11861. // stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  11862. // "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  11863. // return;
  11864. // }
  11865. // string e1OEEPartNo = string.Empty; // 物料码
  11866. // if (string.IsNullOrEmpty(e1OEEProductSN))
  11867. // {
  11868. // stopwatch2.Start();
  11869. // // MES_Flag
  11870. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11871. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11872. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  11873. // writeToPLC_Flag1.Adress = 2088;
  11874. // writeToPLC_Flag1.Value = (short)1;
  11875. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  11876. // stopwatch2.Stop();
  11877. // AddMessage(LogType.Info,
  11878. // stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11879. // stopwatch2.ElapsedMilliseconds + "ms");
  11880. // return;
  11881. // }
  11882. // else
  11883. // {
  11884. // // 查产品SN
  11885. // e1OEEPartNo = "Test"; // ZS
  11886. // }
  11887. // short e1OEEMES_FLAG = 0;
  11888. // // 上传OEE
  11889. // (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  11890. // e1OEEMES_FLAG = result.Item1;
  11891. // resultStr = result.Item2;
  11892. // stopwatch2.Start();
  11893. // // MES_Flag
  11894. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11895. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11896. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  11897. // writeToPLC_Flag.Adress = 2088;
  11898. // writeToPLC_Flag.Value = e1OEEMES_FLAG;
  11899. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  11900. // stopwatch2.Stop();
  11901. // }
  11902. // catch (Exception ex)
  11903. // {
  11904. // string str = ex.StackTrace;
  11905. // AddMessage_Station(stationNameStr, LogType.Error,
  11906. // $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  11907. // str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11908. // // MES_Flag
  11909. // stopwatch2.Start();
  11910. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  11911. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11912. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  11913. // writeToPLC_Flag.Adress = 2088;
  11914. // writeToPLC_Flag.Value = (short)4;
  11915. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  11916. // stopwatch2.Stop();
  11917. // }
  11918. // stopwatch1.Stop();
  11919. // AddMessage(LogType.Info,
  11920. // stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11921. // stopwatch2.ElapsedMilliseconds + "ms");
  11922. //}
  11923. /// <summary>
  11924. /// [S5] Tray盘下料装备 - AGV上料叫agv
  11925. /// </summary>
  11926. /// <param name="plcNo">PLC编号</param>
  11927. /// <param name="stationNameStr">工站全称</param>
  11928. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  11929. {
  11930. Stopwatch stopwatch1 = new Stopwatch();
  11931. Stopwatch stopwatch2 = new Stopwatch();
  11932. try
  11933. {
  11934. stopwatch1.Start();
  11935. // ZS 呼叫AGV
  11936. short e1AGVUpCall = 2;
  11937. stopwatch2.Start();
  11938. // e1AGVUpCall
  11939. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11940. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11941. writeToPLC_Flag.Name = "e1AGVUpCall";
  11942. writeToPLC_Flag.Adress = 2120;
  11943. writeToPLC_Flag.Value = e1AGVUpCall;
  11944. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  11945. stopwatch2.Stop();
  11946. }
  11947. catch (Exception ex)
  11948. {
  11949. string str = ex.StackTrace;
  11950. AddMessage_Station(stationNameStr, LogType.Error,
  11951. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  11952. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11953. // e1AGVUpCall
  11954. stopwatch2.Start();
  11955. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  11956. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11957. writeToPLC_Flag.Name = "e1AGVUpCall";
  11958. writeToPLC_Flag.Adress = 2120;
  11959. writeToPLC_Flag.Value = (short)4;
  11960. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  11961. stopwatch2.Stop();
  11962. }
  11963. stopwatch1.Stop();
  11964. AddMessage(LogType.Info,
  11965. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11966. stopwatch2.ElapsedMilliseconds + "ms");
  11967. }
  11968. /// <summary>
  11969. /// [S5] Tray盘下料装备 - AGV上料完成
  11970. /// </summary>
  11971. /// <param name="plcNo">PLC编号</param>
  11972. /// <param name="stationNameStr">工站全称</param>
  11973. private void S5AGV上料完成(int plcNo, string stationNameStr)
  11974. {
  11975. Stopwatch stopwatch1 = new Stopwatch();
  11976. Stopwatch stopwatch2 = new Stopwatch();
  11977. try
  11978. {
  11979. stopwatch1.Start();
  11980. // ZS AGV上料完成,让小车离开
  11981. short e1AGVUpEnd = 2;
  11982. stopwatch2.Start();
  11983. // e1AGVUpEnd
  11984. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11985. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11986. writeToPLC_Flag.Name = "e1AGVUpEnd";
  11987. writeToPLC_Flag.Adress = 2122;
  11988. writeToPLC_Flag.Value = e1AGVUpEnd;
  11989. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  11990. stopwatch2.Stop();
  11991. }
  11992. catch (Exception ex)
  11993. {
  11994. string str = ex.StackTrace;
  11995. AddMessage_Station(stationNameStr, LogType.Error,
  11996. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  11997. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11998. // e1AGVUpEnd
  11999. stopwatch2.Start();
  12000. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  12001. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12002. writeToPLC_Flag.Name = "e1AGVUpEnd";
  12003. writeToPLC_Flag.Adress = 2122;
  12004. writeToPLC_Flag.Value = (short)4;
  12005. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  12006. stopwatch2.Stop();
  12007. }
  12008. stopwatch1.Stop();
  12009. AddMessage(LogType.Info,
  12010. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12011. stopwatch2.ElapsedMilliseconds + "ms");
  12012. }
  12013. /// <summary>
  12014. /// [S5] Tray盘下料装备 - AGV下料叫agv
  12015. /// </summary>
  12016. /// <param name="plcNo">PLC编号</param>
  12017. /// <param name="stationNameStr">工站全称</param>
  12018. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  12019. {
  12020. Stopwatch stopwatch1 = new Stopwatch();
  12021. Stopwatch stopwatch2 = new Stopwatch();
  12022. try
  12023. {
  12024. stopwatch1.Start();
  12025. // ZS 呼叫AGV
  12026. short e1AGVDownCall = 2;
  12027. stopwatch2.Start();
  12028. // e1AGVDownCall
  12029. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  12030. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12031. writeToPLC_Flag.Name = "e1AGVDownCall";
  12032. writeToPLC_Flag.Adress = 2133;
  12033. writeToPLC_Flag.Value = e1AGVDownCall;
  12034. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  12035. stopwatch2.Stop();
  12036. }
  12037. catch (Exception ex)
  12038. {
  12039. string str = ex.StackTrace;
  12040. AddMessage_Station(stationNameStr, LogType.Error,
  12041. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  12042. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12043. // e1AGVDownCall
  12044. stopwatch2.Start();
  12045. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  12046. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12047. writeToPLC_Flag.Name = "e1AGVDownCall";
  12048. writeToPLC_Flag.Adress = 2133;
  12049. writeToPLC_Flag.Value = (short)4;
  12050. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  12051. stopwatch2.Stop();
  12052. }
  12053. stopwatch1.Stop();
  12054. AddMessage(LogType.Info,
  12055. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12056. stopwatch2.ElapsedMilliseconds + "ms");
  12057. }
  12058. /// <summary>
  12059. /// [S5] Tray盘下料装备 - AGV下料完成
  12060. /// </summary>
  12061. /// <param name="plcNo">PLC编号</param>
  12062. /// <param name="stationNameStr">工站全称</param>
  12063. private void S5AGV下料完成(int plcNo, string stationNameStr)
  12064. {
  12065. Stopwatch stopwatch1 = new Stopwatch();
  12066. Stopwatch stopwatch2 = new Stopwatch();
  12067. try
  12068. {
  12069. stopwatch1.Start();
  12070. // ZS AGV上料完成,让小车离开
  12071. short e1AGVDownEnd = 2;
  12072. stopwatch2.Start();
  12073. // e1AGVDownEnd
  12074. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  12075. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12076. writeToPLC_Flag.Name = "e1AGVDownEnd";
  12077. writeToPLC_Flag.Adress = 2135;
  12078. writeToPLC_Flag.Value = e1AGVDownEnd;
  12079. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  12080. stopwatch2.Stop();
  12081. }
  12082. catch (Exception ex)
  12083. {
  12084. string str = ex.StackTrace;
  12085. AddMessage_Station(stationNameStr, LogType.Error,
  12086. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  12087. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12088. // e1AGVDownEnd
  12089. stopwatch2.Start();
  12090. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  12091. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12092. writeToPLC_Flag.Name = "e1AGVDownEnd";
  12093. writeToPLC_Flag.Adress = 2135;
  12094. writeToPLC_Flag.Value = (short)4;
  12095. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  12096. stopwatch2.Stop();
  12097. }
  12098. stopwatch1.Stop();
  12099. AddMessage(LogType.Info,
  12100. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12101. stopwatch2.ElapsedMilliseconds + "ms");
  12102. }
  12103. #endregion [S5] Tray盘下料装备
  12104. #endregion PLC5 张超凡
  12105. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  12106. /// <summary>
  12107. /// PLC读取到的数据 -添加数据
  12108. /// </summary>
  12109. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  12110. {
  12111. if (sxPlcData.ContainsKey(newKey))
  12112. sxPlcData[newKey] = newValue;
  12113. else
  12114. sxPlcData.Add(newKey, newValue);
  12115. }
  12116. /// <summary>
  12117. /// PLC需要写入的数据 -添加数据
  12118. /// </summary>
  12119. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey,
  12120. WriteToPLC_Flag newValue)
  12121. {
  12122. if (sxPLCWriteData.ContainsKey(newKey))
  12123. sxPLCWriteData[newKey] = newValue;
  12124. else
  12125. sxPLCWriteData.Add(newKey, newValue);
  12126. }
  12127. /// <summary>
  12128. /// PLC回写操作,写后清空flag
  12129. /// </summary>
  12130. /// <param name="modbusClient">modbus对象</param>
  12131. /// <param name="pLCReadDatas">读取到的数据字典</param>
  12132. /// <param name="pLCWriteDatas">需要写入的数据</param>
  12133. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas,
  12134. ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  12135. {
  12136. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  12137. {
  12138. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  12139. for (int i = 0; i < pLCWriteDatas.Count; i++)
  12140. {
  12141. string mesFlagName = pLCWriteDatas[i].Name;
  12142. int mesFlagAdress = pLCWriteDatas[i].Adress;
  12143. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  12144. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  12145. {
  12146. // 先回写数据
  12147. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  12148. for (int j = 0; j < writeToPLCDatas.Count; j++)
  12149. {
  12150. int mesDataAdress = writeToPLCDatas[j].Adress;
  12151. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  12152. switch (mesDataType)
  12153. {
  12154. case PLCValueType.Short:
  12155. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  12156. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  12157. break;
  12158. case PLCValueType.String:
  12159. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  12160. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  12161. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr,
  12162. mesDataValueStrLength);
  12163. break;
  12164. }
  12165. }
  12166. // 再回写信号
  12167. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  12168. // 存储读取数据的字典
  12169. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  12170. // 存储写入数据的字典 - 清空写入值
  12171. pLCWriteDatas[i].Value = (short)0;
  12172. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  12173. }
  12174. }
  12175. }
  12176. }
  12177. /// <summary>
  12178. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  12179. /// </summary>
  12180. /// <param name="no">3</param>
  12181. /// <param name="stationCode">设备编号</param>
  12182. /// <param name="stationNameStr">设备名称</param>
  12183. /// <param name="plcOrder">车间订单号</param>
  12184. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  12185. {
  12186. try
  12187. {
  12188. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  12189. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  12190. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  12191. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  12192. int result1 = 0;
  12193. switch (stationCode)
  12194. {
  12195. case 2:
  12196. case 3:
  12197. case 4:
  12198. case 6:
  12199. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  12200. break;
  12201. case 102:
  12202. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  12203. break;
  12204. case 103:
  12205. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  12206. break;
  12207. case 104:
  12208. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  12209. break;
  12210. case 106:
  12211. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  12212. break;
  12213. default:
  12214. // MES_Flag 为“6未找到正确设备编号”
  12215. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  12216. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  12217. return;
  12218. }
  12219. short result = result1 == 1 ? (short)1 : (short)2;
  12220. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  12221. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  12222. }
  12223. catch (Exception ex)
  12224. {
  12225. // MES_Flag 为2上位机报错
  12226. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  12227. string str = ex.StackTrace;
  12228. AddMessage_Station(stationNameStr, LogType.Error,
  12229. $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  12230. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12231. }
  12232. }
  12233. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  12234. #region UI刷新
  12235. /// <summary>
  12236. /// 更新商品信息的UI + 下发产品信息(SN)
  12237. /// </summary>
  12238. private void UpdateProductInfo()
  12239. {
  12240. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  12241. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  12242. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  12243. //txt_CurSupplierCode.Text = ""; // 供应商代号
  12244. }
  12245. /// <summary>
  12246. /// 更新PLC连接状态的UI
  12247. /// </summary>
  12248. /// <param name="no">PLC编号</param>
  12249. /// <param name="status">状态</param>
  12250. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  12251. {
  12252. if (this != null && !this.IsDisposed)
  12253. {
  12254. switch (imgNo)
  12255. {
  12256. case 1:
  12257. this.BeginInvoke(new Action(() => { picPLC.Image = imageListState.Images[status]; }));
  12258. break;
  12259. case 2:
  12260. this.BeginInvoke(new Action(() => { pictureBox2.Image = imageListState.Images[status]; }));
  12261. break;
  12262. case 3:
  12263. this.BeginInvoke(new Action(() => { pictureBox3.Image = imageListState.Images[status]; }));
  12264. break;
  12265. case 4:
  12266. this.BeginInvoke(new Action(() => { pictureBox4.Image = imageListState.Images[status]; }));
  12267. break;
  12268. case 5:
  12269. this.BeginInvoke(new Action(() => { pictureBox5.Image = imageListState.Images[status]; }));
  12270. break;
  12271. case 6:
  12272. this.BeginInvoke(new Action(() => { pictureBox6.Image = imageListState.Images[status]; }));
  12273. break;
  12274. case 7:
  12275. this.BeginInvoke(new Action(() => { pictureBox7.Image = imageListState.Images[status]; }));
  12276. break;
  12277. case 8:
  12278. this.BeginInvoke(new Action(() => { pictureBox8.Image = imageListState.Images[status]; }));
  12279. break;
  12280. default:
  12281. break;
  12282. }
  12283. }
  12284. Task.Run(() => // 更新PLC交互页的指示灯
  12285. {
  12286. try
  12287. {
  12288. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  12289. {
  12290. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  12291. }
  12292. }
  12293. catch
  12294. {
  12295. }
  12296. });
  12297. }
  12298. #endregion UI刷新
  12299. #region 日志
  12300. /// <summary>
  12301. /// 添加各工位运行日志(同步至PLC交互页面)
  12302. /// </summary>
  12303. /// <param name="stationNameStr">工站名称</param>
  12304. /// <param name="logType">日志类型</param>
  12305. /// <param name="message">日志内容</param>
  12306. /// <param name="snNumber">产品数字SN</param>
  12307. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  12308. {
  12309. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")))
  12310. {
  12311. AddMessage(logType, message); // 首页展示+日志记录
  12312. }
  12313. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  12314. {
  12315. StationName = stationNameStr,
  12316. SnNumber = snNumber,
  12317. Message = message,
  12318. CreateTime = DateTime.Now
  12319. };
  12320. // PLC交互页展示
  12321. Task.Run(() =>
  12322. {
  12323. try
  12324. {
  12325. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  12326. {
  12327. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  12328. }
  12329. }
  12330. catch
  12331. {
  12332. }
  12333. });
  12334. }
  12335. /// <summary>
  12336. /// 添加运行日志
  12337. /// </summary>
  12338. /// <param name="logType">日志类型</param>
  12339. /// <param name="message">日志内容</param>
  12340. public void AddMessage(LogType logType, string message)
  12341. {
  12342. OnMessage(logType, message);
  12343. string date = DateTime.Now.ToString("yyyy/MM/dd");
  12344. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  12345. string msgShow = time + "--> " + message + "\r\n";
  12346. try
  12347. {
  12348. this.BeginInvoke(new Action(() =>
  12349. {
  12350. systemLog.Rows.Insert(0, date, time, message);
  12351. if (systemLog.Rows.Count >= 100)
  12352. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  12353. }));
  12354. }
  12355. catch (Exception ex) { }
  12356. }
  12357. /// <summary>
  12358. /// 添加运行日志-保存
  12359. /// </summary>
  12360. /// <param name="logType">日志类型</param>
  12361. /// <param name="message">日志内容</param>
  12362. private void OnMessage(LogType logType, string msg)
  12363. {
  12364. MessageEvent?.Invoke(logType, msg);
  12365. }
  12366. /// <summary>
  12367. /// 保存PLC写入日志
  12368. /// </summary>
  12369. /// <param name="logType"></param>
  12370. /// <param name="logValue"></param>
  12371. private void WritePLCLog(LogType logType, string logValue)
  12372. {
  12373. switch ((int)logType)
  12374. {
  12375. case 0:
  12376. _PLCLogNet.WriteDebug(logValue);
  12377. break;
  12378. case 1:
  12379. _PLCLogNet.WriteInfo(logValue);
  12380. break;
  12381. case 2:
  12382. _PLCLogNet.WriteWarn(logValue);
  12383. break;
  12384. case 3:
  12385. _PLCLogNet.WriteError(logValue);
  12386. break;
  12387. default:
  12388. _PLCLogNet.WriteFatal(logValue);
  12389. break;
  12390. }
  12391. }
  12392. /// <summary>
  12393. /// IOT Mqtt回调方法- With DataId
  12394. /// </summary>
  12395. /// <param name="id"></param>
  12396. /// <param name="v"></param>
  12397. /// <param name="dataId"></param>
  12398. public void CallbackWithDataId(string id, string msg, string dataId)
  12399. {
  12400. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  12401. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  12402. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  12403. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  12404. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  12405. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  12406. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  12407. }
  12408. /// <summary>
  12409. /// AGV Mqtt回调方法- 记录Log并处理数据
  12410. /// </summary>
  12411. /// <param name="obj"></param>
  12412. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  12413. {
  12414. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  12415. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  12416. // 接收到的信息
  12417. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  12418. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  12419. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  12420. {
  12421. }
  12422. }
  12423. #endregion 日志
  12424. //private void button1_Click(object sender, EventArgs e)
  12425. //{
  12426. // OpenDailogFalg=true;
  12427. // if (OpenDailogFalg)
  12428. // {
  12429. // using (var dialog = new BandBarodeDialog())
  12430. // {
  12431. // string strCarrierBarcode = "N801A-003";
  12432. // dialog._CarrierBarcode = strCarrierBarcode;
  12433. // string sn = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  12434. // dialog._ProductBarcode = sn;
  12435. // var rs = dialog.ShowDialog();
  12436. // if (rs == DialogResult.OK)
  12437. // {
  12438. // AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  12439. // OpenDailogFalg = false;//关闭扫码
  12440. // }
  12441. // }
  12442. // }
  12443. //}
  12444. }
  12445. }