Form_Home.cs 700 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. //using System.Text;
  8. using Microsoft.Win32;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using HslCommunication.LogNet;
  13. using MainForm.FaForm;
  14. using Sunny.UI;
  15. using MainForm.ClassFile.XiaomiAPI;
  16. using System.Diagnostics;
  17. using MainForm.Models;
  18. using SqlSugar;
  19. using EasyModbus;
  20. using ModBusClientSimple.Util;
  21. using csharp_networkprotocol_hpsocket;
  22. using MqttnetServerWin;
  23. using Sunny.UI.Win32;
  24. using MainForm.ClassFile.XiaomiAPI_AGV;
  25. using MainForm.ClassFile.XiaomiAPI_RouteCom;
  26. using HslCommunication.Controls;
  27. using EIP_Protocol;
  28. using MainForm.ClassFile.XiaomiAPI_MES;
  29. using NPOI.Util;
  30. using static MainForm.SQLHelper;
  31. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
  32. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
  33. using MainForm.ClassFile.ProjectClass;
  34. using CommonLib;
  35. using Org.BouncyCastle.Asn1.IsisMtt;
  36. using System.Web.Services.Description;
  37. using System.Numerics;
  38. using MathNet.Numerics.RootFinding;
  39. using HslCommunication.Enthernet;
  40. using BZFAStandardLib;
  41. using MainForm.ClassFile;
  42. using NPOI.SS.Formula.Functions;
  43. using static MainForm.ClassFile.XiaomiAPI.XiaomiMqttClient_Extend;
  44. using System.Net.Http;
  45. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_UpLoadFile;
  46. using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
  47. using System.Reflection;
  48. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
  49. using FaFrameUI;
  50. using System.Security.Policy;
  51. using static MainForm.ClassFile.XiaomiClass.MesHelper;
  52. using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
  53. using System.Drawing.Imaging;
  54. using System.Drawing;
  55. using ICSharpCode.SharpZipLib.Zip;
  56. using System.Text.RegularExpressions;
  57. /*
  58. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  59. */
  60. namespace MainForm
  61. {
  62. /// <summary>
  63. /// 记录日志的委托
  64. /// </summary>
  65. /// <param name="logType">日志类型</param>
  66. /// <param name="message">日志信息</param>
  67. public delegate void HomeMessageHandler(LogType logType, string message);
  68. /// <summary>
  69. /// 主页窗体
  70. /// </summary>
  71. public partial class Form_Home : Form
  72. {
  73. #region 常量
  74. //文本常量
  75. private const string Head = "开始采集";
  76. private const string Tail = "采集完成";
  77. private const string Body = "工位出站数据";
  78. private const string BodyCheck = "工位点检数据";
  79. private const string BodyRun = "整线运行数据";
  80. private const string BodyAlarm = "整线报警数据";
  81. #endregion 常量
  82. #region 变量
  83. /// <summary>
  84. /// 委托-记录日志的方法
  85. /// </summary>
  86. public event HomeMessageHandler MessageEvent;
  87. /// <summary>
  88. /// 日志接口
  89. /// </summary>
  90. ILogNet _PLCLogNet;
  91. /// <summary>
  92. /// 用于记录IOT MQTT日志
  93. /// </summary>
  94. ILogNet _IOTMqttLogNet;
  95. /// <summary>
  96. /// 用于记录AGV MQTT日志
  97. /// </summary>
  98. ILogNet _AGVMqttLogNet;
  99. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  100. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  101. // 间隔时间
  102. private int IntervalReadPLC = 300; //ms 读PLC
  103. private int IntervalMonitorMES = 1000; //ms MES心跳
  104. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  105. /// <summary>
  106. /// 设备报警数据
  107. /// </summary>
  108. uint[] _FaultDatas = { };
  109. uint[] _FaultDatas_Old = { };
  110. uint[] _FaultDatas2 = { };
  111. uint[] _FaultDatas_Old2 = { };
  112. // 软件状态
  113. private bool IsRun = true;
  114. #region PLC 与 TCP对象
  115. // 定义一个字典,存plc对象(通讯)
  116. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  117. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  118. // 定义TCPClient对象列表
  119. Dictionary<int, HPSocket_TcpClientHelper>
  120. _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  121. // 定义MQTTHelper对象
  122. MQTTHelper _MQTTHelper = new MQTTHelper();
  123. #endregion PLC 与 TCP对象
  124. /// <summary>
  125. /// 上次的设备运行信息
  126. /// </summary>
  127. private string lineWorkingData1_OldStr = string.Empty;
  128. /// <summary>
  129. /// 设备报警字典-当前结果
  130. /// Dictionary<工位代码,List<报警信息>>
  131. /// </summary>
  132. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  133. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  134. /// <summary>
  135. /// 单机用-设备状态
  136. /// </summary>
  137. //XiaomiDeviceState xmDeviceState = XiaomiDeviceState.Uninitialized;
  138. XiaomiDeviceStateData xmDeviceStateData = new XiaomiDeviceStateData();
  139. private int test_item_num = 0; //iot 过站数据序号
  140. public static string uuid = "";
  141. private bool inpass = false; //保存进站测试状态
  142. public static XiaoMiParm xiaomiParm = new XiaoMiParm();
  143. //记录上传附件的信息
  144. public static FileUpload_FileData fileUploadData = new FileUpload_FileData();
  145. #endregion 变量
  146. #region 窗体基础事件
  147. /// <summary>
  148. /// 初始化
  149. /// </summary>
  150. public Form_Home()
  151. {
  152. InitializeComponent();
  153. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  154. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  155. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  156. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  157. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  158. }
  159. /// <summary>
  160. /// 窗体加载事件
  161. /// </summary>
  162. public void Form_Home_Load(object sender, EventArgs e)
  163. {
  164. try
  165. {
  166. AddMessage(LogType.Info, "开始初始化程序");
  167. //组建plc对象字典
  168. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  169. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  170. if (GlobalContext.IsUsePLC1)
  171. {
  172. GlobalContext.IsUsePLCNow = 1;
  173. GlobalContext.IsUseStationName = "[OP10]壳体清洁上料";
  174. FunsEip.Add(GlobalContext.IsUsePLCNow,
  175. new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  176. }
  177. if (GlobalContext.IsUsePLC2)
  178. {
  179. GlobalContext.IsUsePLCNow = 2;
  180. GlobalContext.IsUseStationName = "[OP20]上盖板上料装备";
  181. FunsEip.Add(GlobalContext.IsUsePLCNow,
  182. new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  183. }
  184. if (GlobalContext.IsUsePLC3)
  185. {
  186. GlobalContext.IsUsePLCNow = 3;
  187. GlobalContext.IsUseStationName = "[OP30]点散热胶装备";
  188. FunsEip.Add(GlobalContext.IsUsePLCNow,
  189. new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  190. }
  191. if (GlobalContext.IsUsePLC4)
  192. {
  193. GlobalContext.IsUsePLCNow = 4;
  194. GlobalContext.IsUseStationName = "[OP40]胶线检测";
  195. FunsEip.Add(GlobalContext.IsUsePLCNow,
  196. new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  197. }
  198. if (GlobalContext.IsUsePLC5)
  199. {
  200. GlobalContext.IsUsePLCNow = 5;
  201. GlobalContext.IsUseStationName = "[OP50]ADD板上料组装装备";
  202. FunsEip.Add(GlobalContext.IsUsePLCNow,
  203. new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  204. }
  205. if (GlobalContext.IsUsePLC6)
  206. {
  207. GlobalContext.IsUsePLCNow = 6;
  208. GlobalContext.IsUseStationName = "[OP70]组上盖板";
  209. FunsEip.Add(GlobalContext.IsUsePLCNow,
  210. new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  211. }
  212. if (GlobalContext.IsUsePLC7)
  213. {
  214. GlobalContext.IsUsePLCNow = 7;
  215. GlobalContext.IsUseStationName = "[OP80]上盖板锁螺丝";
  216. FunsEip.Add(GlobalContext.IsUsePLCNow,
  217. new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  218. }
  219. if (GlobalContext.IsUsePLC8)
  220. {
  221. GlobalContext.IsUsePLCNow = 8;
  222. GlobalContext.IsUseStationName = "[OP90]NG下料";
  223. FunsEip.Add(GlobalContext.IsUsePLCNow,
  224. new Inovance_EIP(GlobalContext.PC8Address,
  225. GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  226. }
  227. if (GlobalContext.IsUsePLC9)
  228. {
  229. GlobalContext.IsUsePLCNow = 9;
  230. GlobalContext.IsUseStationName = "[OP100]半成品下料";
  231. FunsEip.Add(GlobalContext.IsUsePLCNow,
  232. new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  233. }
  234. (bool, string) DicResult = InitalDicAlarm(); // 实例化报警字典
  235. AddMessage(LogType.Info, DicResult.Item2);
  236. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  237. {
  238. if (plcEIP != null)
  239. {
  240. try
  241. {
  242. (int, string) result = plcEIP.Connect();
  243. }
  244. catch (Exception ex)
  245. {
  246. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  247. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
  248. MessageBoxOptions.ServiceNotification);
  249. }
  250. }
  251. }
  252. // 采集任务
  253. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  254. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  255. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  256. if (GlobalContext.IsUsePLC1)
  257. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  258. if (GlobalContext.IsUsePLC2)
  259. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  260. if (GlobalContext.IsUsePLC3)
  261. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  262. if (GlobalContext.IsUsePLC4)
  263. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  264. if (GlobalContext.IsUsePLC5)
  265. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  266. if (GlobalContext.IsUsePLC6)
  267. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  268. if (GlobalContext.IsUsePLC7)
  269. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  270. if (GlobalContext.IsUsePLC8)
  271. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  272. if (GlobalContext.IsUsePLC9)
  273. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  274. #region 初始化
  275. try
  276. {
  277. // 开启MES(Http)
  278. if (GlobalContext.IsUseMES)
  279. {
  280. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  281. if (mesret)
  282. {
  283. picMESStatus.Image = imageListState.Images[1];
  284. GlobalContext.MESIsConnect = true;
  285. AddMessage(LogType.Info, "小米MES初始连接成功!");
  286. }
  287. else
  288. {
  289. picMESStatus.Image = imageListState.Images[0];
  290. GlobalContext.MESIsConnect = false;
  291. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  292. }
  293. }
  294. // 开启IOT(MQTT)
  295. if (GlobalContext.IsUseIot)
  296. {
  297. string addr = GlobalContext.MQTTServerHost;
  298. int port = GlobalContext.MQTTServerPort;
  299. //生产环境需要修改
  300. (int, string) qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666,
  301. GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  302. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult.Item1;
  303. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  304. {
  305. picIot.Image = imageListState.Images[1];
  306. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  307. // 设置回调函数
  308. //XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  309. // 配置参数
  310. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  311. // fds
  312. param.parameter.fds.address = GlobalContext.address;
  313. param.parameter.fds.appId = GlobalContext.appId;
  314. param.parameter.fds.appKey = GlobalContext.appKey;
  315. // mes
  316. param.parameter.mes.address = GlobalContext.ServerIp;
  317. param.parameter.mes.appId = GlobalContext.MESAppId;
  318. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  319. // mqtt
  320. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  321. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  322. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  323. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  324. // 设备配置
  325. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  326. if (GlobalContext.IsUsePLC1)
  327. {
  328. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  329. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  330. xiaomiParm.workstation = GlobalContext.S1_work_station; //工站
  331. }
  332. if (GlobalContext.IsUsePLC2)
  333. {
  334. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  335. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  336. xiaomiParm.workstation = GlobalContext.S2_work_station; //工站
  337. }
  338. if (GlobalContext.IsUsePLC3)
  339. {
  340. param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
  341. //param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
  342. }
  343. if (GlobalContext.IsUsePLC4)
  344. {
  345. param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
  346. param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
  347. xiaomiParm.workstation = GlobalContext.s4_work_station; //工站
  348. }
  349. if (GlobalContext.IsUsePLC5)
  350. {
  351. param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
  352. param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
  353. xiaomiParm.workstation = GlobalContext.s5_work_station; //工站
  354. }
  355. if (GlobalContext.IsUsePLC6)
  356. {
  357. param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
  358. param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
  359. xiaomiParm.workstation = GlobalContext.s6_work_station; //工站
  360. }
  361. if (GlobalContext.IsUsePLC7)
  362. {
  363. param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  364. //param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  365. xiaomiParm.stationCode = GlobalContext.s7_1_station;
  366. }
  367. if (GlobalContext.IsUsePLC8)
  368. {
  369. param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
  370. param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
  371. xiaomiParm.workstation = GlobalContext.s8_work_station; //工站
  372. }
  373. if (GlobalContext.IsUsePLC9)
  374. {
  375. param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
  376. param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
  377. xiaomiParm.workstation = GlobalContext.s9_work_station; //工站
  378. }
  379. param.parameter.equipment.project = GlobalContext.Project_Code;
  380. param.parameter.equipment.productMode = "debug";
  381. param.parameter.other.logLevel = 0;
  382. param.parameter.other.LogPath = GlobalContext.MqttLogDir;
  383. XiaomiMqttClient_Extend.ParameterConfig(param);
  384. //保存全局变量
  385. xiaomiParm.stationCode = param.parameter.equipment.stationCode;
  386. xiaomiParm.deviceCode = param.parameter.equipment.deviceCode;
  387. }
  388. else
  389. {
  390. picIot.Image = imageListState.Images[0];
  391. AddMessage(LogType.Info,
  392. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  393. }
  394. }
  395. // 开启AGV(Http与MQTT)
  396. if (GlobalContext.IsUseAGV)
  397. {
  398. // AGV HTTP
  399. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  400. if (mesret1)
  401. {
  402. picAgvHttp.Image = imageListState.Images[1];
  403. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  404. }
  405. else
  406. {
  407. picAgvHttp.Image = imageListState.Images[0];
  408. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  409. }
  410. string agvMqttIp = GlobalContext.MQTTServerHost;
  411. int agvMqttPort = GlobalContext.MQTTServerPort;
  412. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  413. ResultData_MQTT result_MQTT = _MQTTHelper
  414. .CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  415. // AGV MQTT
  416. if (result_MQTT.ResultCode == 1)
  417. {
  418. picAgvMqtt.Image = imageListState.Images[1];
  419. GlobalContext.AGVMQTTIsConnect = true;
  420. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  421. ResultData_MQTT result =
  422. XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  423. AddMessage(LogType.Info,
  424. $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  425. }
  426. else
  427. {
  428. picAgvMqtt.Image = imageListState.Images[0];
  429. GlobalContext.AGVMQTTIsConnect = false;
  430. AddMessage(LogType.Info,
  431. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  432. }
  433. }
  434. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  435. Task.Run(MonitorMESConnect);
  436. // 查询PLC连接状态
  437. foreach (int plcNo in FunsEip.Keys)
  438. {
  439. bool connected = FunsEip[plcNo].IsConnected;
  440. if (connected)
  441. {
  442. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  443. AddMessage(LogType.Info, msg);
  444. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  445. }
  446. else
  447. {
  448. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  449. AddMessage(LogType.Info, msg);
  450. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  451. }
  452. }
  453. // PLC4时 初始化扫码器TCP
  454. //if (GlobalContext.IsUsePLC4)
  455. // HpTCPClientInit();
  456. // 开启PLC的业务处理线程-监听PLC点位+状态
  457. foreach (Task task in TaskReadProcess)
  458. {
  459. if (task != null)
  460. task.Start();
  461. }
  462. //// 开启iot的线程
  463. TaskReadAlarm.Start();
  464. ////下传MES信息给1工位(先判断下plc对象数量)
  465. //if (Funs.Count > 1)
  466. // DownLoadProductInfo(1);
  467. if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  468. {
  469. state_l.Text = "设备状态(左):";
  470. state_r.Text = "设备状态(右):";
  471. state_r.Visible = true;
  472. lblDeviceStates2.Visible = true;
  473. }
  474. //上传操作记录
  475. operateToIot("startup", "开启");
  476. AddMessage(LogType.Info, "程序初始化完成");
  477. }
  478. catch (Exception ex)
  479. {
  480. string str = ex.StackTrace;
  481. this.BeginInvoke(new Action(() =>
  482. {
  483. AddMessage(LogType.Error,
  484. "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  485. str.Length - str.LastIndexOf("\\") - 1));
  486. }));
  487. }
  488. #endregion
  489. }
  490. catch (Exception ex)
  491. {
  492. string str = ex.StackTrace;
  493. OnMessage(LogType.Info,
  494. "主窗体的首页初始化出错!异常位置:" +
  495. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" +
  496. ex.Message.ToString());
  497. if (ex.Message != null && ex.Message.Contains("timed out"))
  498. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  499. else
  500. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  501. }
  502. }
  503. /// <summary>
  504. /// 窗体关闭事件
  505. /// </summary>
  506. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  507. {
  508. Closed2();
  509. }
  510. public void Closed2()
  511. {
  512. try
  513. {
  514. IsRun = false;
  515. Thread.Sleep(IntervalReadPLC);
  516. // 断开TCP
  517. int count = _HPSocket_TcpClients.Count();
  518. for (int i = 0; i < count; i++)
  519. {
  520. try
  521. {
  522. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  523. {
  524. _HPSocket_TcpClients[i].Stop();
  525. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  526. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  527. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  528. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  529. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  530. }
  531. }
  532. catch
  533. {
  534. }
  535. }
  536. // 关闭Iot
  537. try
  538. {
  539. XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath,
  540. GlobalContext.MqttServerName);
  541. }
  542. catch
  543. {
  544. }
  545. // 关闭AGV Mqtt
  546. try
  547. {
  548. _MQTTHelper.DisconnectAsync_Client().Wait();
  549. }
  550. catch
  551. {
  552. }
  553. }
  554. catch
  555. {
  556. }
  557. }
  558. #endregion 窗体基础事件
  559. #region 监控MES状态
  560. /// <summary>
  561. /// 监控MES连接状态
  562. /// </summary>
  563. private void MonitorMESConnect()
  564. {
  565. while (IsRun) // 运行被控线程
  566. {
  567. try
  568. {
  569. // 开启MES(Http)
  570. if (GlobalContext.IsUseMES)
  571. {
  572. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  573. if (mesret)
  574. {
  575. picMESStatus.Image = imageListState.Images[1];
  576. GlobalContext.MESIsConnect = true;
  577. }
  578. else
  579. {
  580. picMESStatus.Image = imageListState.Images[0];
  581. GlobalContext.MESIsConnect = false;
  582. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  583. }
  584. }
  585. // 开启IOT(MQTT)
  586. if (GlobalContext.IsUseIot)
  587. {
  588. bool iIot = XiaomiMqttClient.IsOpen;
  589. if (iIot)
  590. picIot.Image = imageListState.Images[1];
  591. else
  592. {
  593. picIot.Image = imageListState.Images[0];
  594. OnMessage(LogType.Info,
  595. $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  596. }
  597. }
  598. // 开启AGV(Http与MQTT)
  599. if (GlobalContext.IsUseAGV)
  600. {
  601. // AGV Http
  602. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  603. if (mesret1)
  604. picAgvHttp.Image = imageListState.Images[1];
  605. else
  606. {
  607. picAgvHttp.Image = imageListState.Images[0];
  608. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  609. }
  610. // AGV MQTT
  611. if (GlobalContext.AGVMQTTIsConnect)
  612. picAgvMqtt.Image = imageListState.Images[1];
  613. else
  614. {
  615. picAgvMqtt.Image = imageListState.Images[0];
  616. OnMessage(LogType.Info,
  617. $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  618. }
  619. }
  620. }
  621. catch (Exception ex)
  622. {
  623. string str = ex.StackTrace;
  624. AddMessage(LogType.Error,
  625. "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  626. str.Length - str.LastIndexOf("\\") - 1));
  627. }
  628. Thread.Sleep(IntervalMonitorMES);
  629. }
  630. }
  631. #endregion 监控MES连接状态
  632. #region 采集设备状态、运行数据、报警数据
  633. /// <summary>
  634. /// 请求设备状态 5000
  635. /// </summary>
  636. /// <param name="no">1</param>
  637. /// <param name="stationNameStr"></param>
  638. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  639. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  640. {
  641. try
  642. {
  643. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  644. {
  645. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  646. return result;
  647. }
  648. else
  649. {
  650. return 0;
  651. }
  652. }
  653. catch (Exception ex)
  654. {
  655. string str = ex.StackTrace;
  656. AddMessage_Station(stationNameStr, LogType.Error,
  657. "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  658. str.Length - str.LastIndexOf("\\") - 1));
  659. return 0;
  660. }
  661. }
  662. /// <summary>
  663. /// 检查是否可采集点检数据 - 不取新值
  664. /// 5000不为1时可点检
  665. /// </summary>
  666. /// <returns></returns>
  667. public bool CheckCanSpotcheck1(int deviceState)
  668. {
  669. //return true;
  670. //D5000 = 1,代表设备控制状态处于运行状态
  671. //D5000 = 2, 代表设备控制状态处于故障状态
  672. //D5000 = 3,代表设备控制状态处于缺料状态
  673. //D5000 = 4, 代表设备控制状态处于待机状态
  674. //D5000 = 5,代表设备控制状态处于维修状态
  675. return deviceState != 1;
  676. }
  677. /// <summary>
  678. /// 检查是否可采集产品数据 - 不取新值
  679. /// </summary>
  680. /// <returns></returns>
  681. public bool CheckCanCollData(int deviceState)
  682. {
  683. return deviceState == 0; // 点检时该值不为0
  684. }
  685. /// <summary>
  686. /// 采集到的设备状态
  687. /// </summary>
  688. private string _DeviceStates = "未知状态";
  689. private string _DeviceStates_Old = "未知状态";
  690. private string _DeviceStates2 = "未知状态";
  691. private string _DeviceStates_Old2 = "未知状态";
  692. /// <summary>
  693. /// 获取设备报警数据与获取设备运行信息
  694. /// </summary>
  695. private async void ReadAlarmAllPLC()
  696. {
  697. /// 获取设备报警数据与状态信息
  698. string stationNameStr = "获取设备报警数据与状态信息";
  699. // 已连接到PLC
  700. while (IsRun)
  701. {
  702. try
  703. {
  704. #region 报警数据
  705. try
  706. {
  707. //_FaultDatas = new uint[] { 4, 0, 30, 10 };
  708. if (_FaultDatas.Length > 0)
  709. {
  710. ReadPLCAlarmToIot(_FaultDatas, _FaultDatas_Old, stationNameStr,"left");
  711. }
  712. else
  713. {
  714. AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!");
  715. }
  716. if (_FaultDatas2.Length > 0)
  717. {
  718. ReadPLCAlarmToIot(_FaultDatas2, _FaultDatas_Old2, stationNameStr,"right");
  719. }
  720. else
  721. {
  722. AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!");
  723. }
  724. }
  725. catch (Exception ex)
  726. {
  727. string str = ex.StackTrace;
  728. AddMessage_Station(stationNameStr, LogType.Error,
  729. $"【报警日志】{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" +
  730. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  731. }
  732. #endregion 报警数据
  733. #region 设备状态
  734. //if (!GlobalContext._IsCon_plc1Alarm)
  735. //{
  736. // UpdatePLCMonitor(1, -2, 0);
  737. // continue;
  738. //}
  739. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  740. {
  741. if (plcEIP != null)
  742. {
  743. if (plcEIP.IsConnected)
  744. {
  745. #region 主页展示设备运行状态并上传到IOT中,有双工位left就是左工位,没有双工位left就是单工位
  746. switch (xmDeviceStateData.left)
  747. {
  748. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  749. _DeviceStates = "未初始化状态";
  750. lblDeviceStates.Text = _DeviceStates;
  751. break;
  752. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  753. _DeviceStates = "初始化状态";
  754. lblDeviceStates.Text = _DeviceStates;
  755. break;
  756. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  757. _DeviceStates = "初始化完成状态";
  758. lblDeviceStates.Text = _DeviceStates;
  759. break;
  760. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  761. _DeviceStates = "运行状态";
  762. lblDeviceStates.Text = _DeviceStates;
  763. break;
  764. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  765. _DeviceStates = "暂停状态";
  766. lblDeviceStates.Text = _DeviceStates;
  767. break;
  768. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  769. _DeviceStates = "故障状态";
  770. lblDeviceStates.Text = _DeviceStates;
  771. break;
  772. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  773. _DeviceStates = "警报状态";
  774. lblDeviceStates.Text = _DeviceStates;
  775. break;
  776. }
  777. if (!_DeviceStates.Equals(_DeviceStates_Old))
  778. {
  779. var iotResult =
  780. SaveDeviceStateData(stationNameStr, xmDeviceStateData.left, "left"); // 上传+保存
  781. if (iotResult.Item1 == 1)
  782. {
  783. _DeviceStates_Old = _DeviceStates;
  784. AddMessage_Station(stationNameStr, LogType.Info,
  785. "【设备状态】" + stationNameStr + $"_上传设备状态到Iot成功!");
  786. }
  787. else
  788. AddMessage_Station(stationNameStr, LogType.Info,
  789. "【设备状态】" + stationNameStr +
  790. $"_上传设备状态到Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  791. }
  792. #endregion 主页展示设备运行状态并上传到IOT中
  793. #region 右工位
  794. if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
  795. {
  796. switch (xmDeviceStateData.right)
  797. {
  798. case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
  799. _DeviceStates2 = "未初始化状态";
  800. lblDeviceStates2.Text = _DeviceStates2;
  801. break;
  802. case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
  803. _DeviceStates2 = "初始化状态";
  804. lblDeviceStates2.Text = _DeviceStates2;
  805. break;
  806. case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
  807. _DeviceStates2 = "初始化完成状态";
  808. lblDeviceStates2.Text = _DeviceStates2;
  809. break;
  810. case XiaomiDeviceState.Running: // 运行状态(正常运行中)
  811. _DeviceStates2 = "运行状态";
  812. lblDeviceStates2.Text = _DeviceStates2;
  813. break;
  814. case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
  815. _DeviceStates2 = "暂停状态";
  816. lblDeviceStates2.Text = _DeviceStates2;
  817. break;
  818. case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
  819. _DeviceStates2 = "故障状态";
  820. lblDeviceStates2.Text = _DeviceStates2;
  821. break;
  822. case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
  823. _DeviceStates2 = "警报状态";
  824. lblDeviceStates2.Text = _DeviceStates2;
  825. break;
  826. }
  827. if (!_DeviceStates2.Equals(_DeviceStates_Old2))
  828. {
  829. var iotResult = SaveDeviceStateData(stationNameStr, xmDeviceStateData.left,
  830. "right"); // 上传+保存
  831. if (iotResult.Item1 == 1)
  832. {
  833. _DeviceStates_Old2 = _DeviceStates2;
  834. AddMessage_Station(stationNameStr, LogType.Info,
  835. "【设备状态】" + stationNameStr + $"_上传Iot成功!");
  836. }
  837. else
  838. AddMessage_Station(stationNameStr, LogType.Info,
  839. "【设备状态】" + stationNameStr +
  840. $"_上传Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
  841. }
  842. }
  843. #endregion 右工位
  844. }
  845. }
  846. }
  847. #endregion
  848. //if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  849. //{
  850. // DateTime dtNow = DateTime.Now;
  851. // //#region 获取设备运行信息
  852. // //try
  853. // //{
  854. // // LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  855. // // lineWorkingData1.GUID = Guid.NewGuid().ToString();
  856. // // lineWorkingData1.LineName = GlobalContext.LineCode;
  857. // // //
  858. // // lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  859. // // lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  860. // // lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  861. // // lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  862. // // lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  863. // // lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  864. // // lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  865. // // lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  866. // // lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  867. // // lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  868. // // lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  869. // // lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  870. // // lineWorkingData1.CreateTime = DateTime.Now;
  871. // // string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  872. // // // UI展示-展示到设备状态页
  873. // // if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  874. // // {
  875. // // // 查询数据库最新一条数据,确定是不是更新
  876. // // string qSql = @"SELECT top(1) [GUID]
  877. // // ,[LineName]
  878. // // ,[BootTimeLong]
  879. // // ,[NormalTimeLong]
  880. // // ,[StandbyTimeLong]
  881. // // ,[FaultTimeLong]
  882. // // ,[MaterialShortageTimeLong]
  883. // // ,[MaintenanceTimeLong]
  884. // // ,[FaultNumber]
  885. // // ,[OutputNumber]
  886. // // ,[QualifiedNumber]
  887. // // ,[QualifiedRate]
  888. // // ,[DesignRhythm]
  889. // // ,[RealityRhythm]
  890. // // ,[CreateTime]
  891. // // FROM [LineWorkingData]
  892. // // where [CreateTime] > '{0}'
  893. // // and [LineName]='{1}'
  894. // // order by [CreateTime] desc
  895. // // ";
  896. // // qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  897. // // var ds = SQLHelper_New.Query(qSql, null);
  898. // // if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  899. // // {
  900. // // var dataDBlast = new LineWorkingData_ThisTime();
  901. // // dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  902. // // dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  903. // // dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  904. // // dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  905. // // if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  906. // // {
  907. // // dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  908. // // dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  909. // // dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  910. // // dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  911. // // dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  912. // // dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  913. // // dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  914. // // dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  915. // // dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  916. // // dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  917. // // dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  918. // // dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  919. // // string usql = dataDBlast.ToStringUpdate();
  920. // // SQLHelper_New.ExecuteSQL(usql, null);
  921. // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  922. // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  923. // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  924. // // }
  925. // // }
  926. // // else
  927. // // {
  928. // // // 插入
  929. // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  930. // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  931. // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  932. // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  933. // // }
  934. // // }
  935. // // else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  936. // // {
  937. // // LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  938. // // //// 本次开机设备运行情况
  939. // // //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  940. // // //Task.Run(() =>
  941. // // //{
  942. // // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  943. // // // {
  944. // // // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  945. // // // }
  946. // // //});
  947. // // // 本日设备运行情况
  948. // // // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  949. // // if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  950. // // {
  951. // // // 更新
  952. // // lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  953. // // lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  954. // // lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  955. // // lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  956. // // lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  957. // // lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  958. // // lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  959. // // lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  960. // // lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  961. // // lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  962. // // lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  963. // // lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  964. // // SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  965. // // lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  966. // // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  967. // // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  968. // // }
  969. // // else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  970. // // {
  971. // // // 插入
  972. // // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  973. // // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  974. // // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  975. // // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  976. // // }
  977. // // await Task.Run(() =>
  978. // // {
  979. // // try
  980. // // {
  981. // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  982. // // {
  983. // // Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  984. // // }
  985. // // }
  986. // // catch { }
  987. // // });
  988. // // }
  989. // //}
  990. // //catch (Exception ex)
  991. // //{
  992. // // string str = ex.StackTrace;
  993. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  994. // //}
  995. // //#endregion 获取设备运行信息
  996. // #region 报警数据
  997. // try
  998. // {
  999. // List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  1000. // bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  1001. // // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  1002. // var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  1003. // for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  1004. // {
  1005. // short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  1006. // dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  1007. // if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  1008. // {
  1009. // isNeedUpdUI = true; // 需要更新历史报警UI信息
  1010. // // 记录
  1011. // dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  1012. // switch (dicAlarms_Cur_PLC1[i].是否报警)
  1013. // {
  1014. // case true: // 报警
  1015. // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  1016. // {
  1017. // GUID = Guid.NewGuid().ToString(),
  1018. // LineName = GlobalContext.LineCode, // 线体
  1019. // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  1020. // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  1021. // StartTime = dtNow // 开始时间
  1022. // };
  1023. // // 传输到页面
  1024. // deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  1025. // {
  1026. // 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  1027. // 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  1028. // 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  1029. // 开始时间 = dtNow
  1030. // });
  1031. // // 新增到数据库
  1032. // var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  1033. // SaveAlarmDataByDB(stationNameStr, data1, false);
  1034. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  1035. // break;
  1036. // case false: // 消除报警
  1037. // if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  1038. // {
  1039. // dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  1040. // {
  1041. // GUID = Guid.NewGuid().ToString(),
  1042. // LineName = GlobalContext.LineCode, // 线体
  1043. // AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  1044. // AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  1045. // StartTime = dtNow, // 开始时间
  1046. // EndTime = dtNow, // 开始时间
  1047. // PersistTime = 1, // 耗时1s
  1048. // };
  1049. // // 新增
  1050. // var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  1051. // SaveAlarmDataByDB(stationNameStr, data2, false);
  1052. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  1053. // }
  1054. // else
  1055. // {
  1056. // dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  1057. // dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  1058. // - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  1059. // // 修改
  1060. // var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  1061. // SaveAlarmDataByDB(stationNameStr, data3, true);
  1062. // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  1063. // }
  1064. // break;
  1065. // default:
  1066. // break;
  1067. // }
  1068. // }
  1069. // }
  1070. // DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  1071. // // 有新报警则更新
  1072. // if (isNeedUpdUI)
  1073. // {
  1074. // // UI展示 - 展示到设备状态页
  1075. // await Task.Run(() =>
  1076. // {
  1077. // try
  1078. // {
  1079. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  1080. // {
  1081. // Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  1082. // if (Form_Main.formDevAlarm.Visible)
  1083. // {
  1084. // Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  1085. // }
  1086. // }
  1087. // }
  1088. // catch { }
  1089. // });
  1090. // }
  1091. // }
  1092. // catch (Exception ex)
  1093. // {
  1094. // string str = ex.StackTrace;
  1095. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1096. // }
  1097. // #endregion 报警数据
  1098. // UpdatePLCMonitor(1, -2, 1);
  1099. //}
  1100. //else
  1101. //{
  1102. // UpdatePLCMonitor(1, -2, 0);
  1103. //}
  1104. }
  1105. catch (Exception ex)
  1106. {
  1107. //AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1108. AddMessage_Station(stationNameStr, LogType.Error,
  1109. $"PLC1_{stationNameStr}_采集运行数据与报警数据出错!错误信息:" + ex.Message.ToString());
  1110. }
  1111. Thread.Sleep(IntervalAlarm);
  1112. }
  1113. }
  1114. #endregion 轮询PLC
  1115. #region 下发订单信息
  1116. ///// <summary>
  1117. ///// 壳体上料(下发工单)的交互逻辑
  1118. ///// </summary>
  1119. ///// <param name="no"></param>
  1120. ///// <exception cref="NotImplementedException"></exception>
  1121. //private void ReadStation_DownOrderInfo(int plcNo)
  1122. //{
  1123. // // [S1] Tray盘上料装备(板测)
  1124. // // [S2] FCT(板测)
  1125. // // [S3] 值板机
  1126. // // [S4] 取放桁架
  1127. // // [S5] Tray盘下料装备
  1128. // /// 上位机心跳
  1129. // /// 获取设备报警数据与状态信息
  1130. // string stationNameStr = "[S0]壳体上料";
  1131. // while (IsRun)
  1132. // {
  1133. // try
  1134. // {
  1135. // if (!GlobalContext._IsCon_Funs1)
  1136. // {
  1137. // UpdatePLCMonitor(plcNo, 0);
  1138. // continue;
  1139. // }
  1140. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  1141. // {
  1142. // #region 壳体上料(下发工单)
  1143. // try
  1144. // {
  1145. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  1146. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  1147. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  1148. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  1149. // // 重置数据和信号
  1150. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  1151. // {
  1152. // // 清空写给PLC的数据
  1153. // int[] i497 = new int[1] { 0 };
  1154. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  1155. // // MES_Flag重置为0
  1156. // int[] i500 = new int[1] { 0 };
  1157. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  1158. // }
  1159. // }
  1160. // catch (Exception ex)
  1161. // {
  1162. // string str = ex.StackTrace;
  1163. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1164. // }
  1165. // #endregion 壳体上料(下发工单)
  1166. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1167. // }
  1168. // else
  1169. // {
  1170. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  1171. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1172. //
  1173. // Funs[plcNo].Connect();
  1174. // }
  1175. // }
  1176. // catch (Exception ex)
  1177. // {
  1178. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  1179. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1180. //
  1181. // Funs[plcNo].ReConnect();
  1182. // }
  1183. // Thread.Sleep(IntervalReadPLC);
  1184. // }
  1185. //}
  1186. ///// <summary>
  1187. ///// 下发订单信息到PLC
  1188. ///// </summary>
  1189. ///// <param name="no">PLC编号</param>
  1190. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  1191. //{
  1192. // try
  1193. // {
  1194. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  1195. // {
  1196. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  1197. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  1198. // }
  1199. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  1200. // }
  1201. // catch (Exception ex)
  1202. // {
  1203. // string str = ex.StackTrace;
  1204. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1205. // }
  1206. //}
  1207. /// <summary>
  1208. /// 下发清料信号
  1209. /// </summary>
  1210. /// <param name="no">PLC编号</param>
  1211. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  1212. {
  1213. try
  1214. {
  1215. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  1216. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  1217. return true;
  1218. }
  1219. catch (Exception ex)
  1220. {
  1221. string str = ex.StackTrace;
  1222. AddMessage_Station(stationNameStr, LogType.Error,
  1223. "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  1224. str.Length - str.LastIndexOf("\\") - 1));
  1225. return false;
  1226. }
  1227. }
  1228. #endregion 下发订单信息
  1229. #region Xiaomi 贲流
  1230. #region 公共方法
  1231. private static bool ProgressState = false;
  1232. private static readonly object lockObj = new object(); // 锁对象
  1233. private static bool isCollectingFlagLeft;
  1234. private static bool isCollectingFlagRight;
  1235. private bool OpenDailogFalg = true; //是否开启扫码弹窗标识
  1236. private static int res = 0;
  1237. public static bool StopWhile =false;
  1238. public void ConnectToIOT()
  1239. {
  1240. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  1241. // fds
  1242. param.parameter.fds.address = GlobalContext.address;
  1243. param.parameter.fds.appId = GlobalContext.appId;
  1244. param.parameter.fds.appKey = GlobalContext.appKey;
  1245. // mes
  1246. param.parameter.mes.address = GlobalContext.ServerIp;
  1247. param.parameter.mes.appId = GlobalContext.MESAppId;
  1248. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  1249. // mqtt
  1250. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  1251. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  1252. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  1253. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  1254. // 设备配置
  1255. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  1256. if (GlobalContext.IsUsePLC1)
  1257. {
  1258. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  1259. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  1260. xiaomiParm.workstation = GlobalContext.S1_work_station; //工站
  1261. }
  1262. if (GlobalContext.IsUsePLC2)
  1263. {
  1264. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  1265. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  1266. xiaomiParm.workstation = GlobalContext.S2_work_station; //工站
  1267. }
  1268. if (GlobalContext.IsUsePLC3)
  1269. {
  1270. param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
  1271. //param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
  1272. }
  1273. if (GlobalContext.IsUsePLC4)
  1274. {
  1275. param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
  1276. param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
  1277. xiaomiParm.workstation = GlobalContext.s4_work_station; //工站
  1278. }
  1279. if (GlobalContext.IsUsePLC5)
  1280. {
  1281. param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
  1282. param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
  1283. xiaomiParm.workstation = GlobalContext.s5_work_station; //工站
  1284. }
  1285. if (GlobalContext.IsUsePLC6)
  1286. {
  1287. param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
  1288. param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
  1289. xiaomiParm.workstation = GlobalContext.s6_work_station; //工站
  1290. }
  1291. if (GlobalContext.IsUsePLC7)
  1292. {
  1293. param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
  1294. //param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
  1295. xiaomiParm.stationCode = GlobalContext.s7_1_station;
  1296. }
  1297. if (GlobalContext.IsUsePLC8)
  1298. {
  1299. param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
  1300. param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
  1301. xiaomiParm.workstation = GlobalContext.s8_work_station; //工站
  1302. }
  1303. if (GlobalContext.IsUsePLC9)
  1304. {
  1305. param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
  1306. param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
  1307. xiaomiParm.workstation = GlobalContext.s9_work_station; //工站
  1308. }
  1309. param.parameter.equipment.project = GlobalContext.Project_Code;
  1310. param.parameter.equipment.productMode = "debug";
  1311. param.parameter.other.logLevel = 0;
  1312. param.parameter.other.LogPath = GlobalContext.MqttLogDir;
  1313. XiaomiMqttClient_Extend.ParameterConfig(param);
  1314. }
  1315. /// <summary>
  1316. /// float[]转为string
  1317. /// </summary>
  1318. public string FloatArrayToString(float[] nScrewResults)
  1319. {
  1320. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  1321. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  1322. }
  1323. /// <summary>
  1324. /// short[]转为string
  1325. /// </summary>
  1326. public string ShortArrayToString(short[] nScrewResults)
  1327. {
  1328. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  1329. return string.Join(",", nScrewResults);
  1330. }
  1331. /// <summary>
  1332. /// 写入PLC重复三次
  1333. /// </summary>
  1334. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount,
  1335. T inObj)
  1336. {
  1337. int i = 0;
  1338. int nRet = 0;
  1339. string strRet = "";
  1340. try
  1341. {
  1342. while (i < 3) // 最多上传三次
  1343. {
  1344. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  1345. if (nRet == 0) //成功
  1346. {
  1347. break;
  1348. }
  1349. else
  1350. {
  1351. AddMessage_Station(stationNameStr, LogType.Error,
  1352. $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1353. i++;
  1354. }
  1355. }
  1356. return (nRet, strRet);
  1357. }
  1358. catch (Exception ex)
  1359. {
  1360. return (1, ex.Message);
  1361. }
  1362. }
  1363. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes,
  1364. short[] nScrewOrders, short[] nScrewResults)
  1365. {
  1366. try
  1367. {
  1368. // 获取当前日期
  1369. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1370. // 构建保存路径
  1371. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  1372. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction, "螺丝Mes数据");
  1373. // 确保目录存在
  1374. Directory.CreateDirectory(savePath);
  1375. // 文件名
  1376. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  1377. string filePath = Path.Combine(savePath, fileName);
  1378. // 确保不会超出数组长度,只取前14个或数组的实际长度
  1379. int count = Math.Min(14, fScrewTimes.Length);
  1380. using (StreamWriter sw = new StreamWriter(filePath))
  1381. {
  1382. for (int i = 0; i < count; i++)
  1383. {
  1384. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  1385. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  1386. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  1387. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  1388. sw.WriteLine(); // 空行分隔不同螺丝的信息
  1389. }
  1390. }
  1391. return (0, "");
  1392. }
  1393. catch (Exception ex)
  1394. {
  1395. return (1, ex.Message);
  1396. }
  1397. }
  1398. public Dictionary<string, string> GetLastLineCompensation(string path, string direction, string sn)
  1399. {
  1400. // 创建字典存储补偿点及其对应的值
  1401. Dictionary<string, string> compensationDict = new Dictionary<string, string>();
  1402. try
  1403. {
  1404. //string path = GlobalContext.MESLaserRPath;
  1405. // 获取当前日期并格式化为 "yyyy-MM-dd" 格式
  1406. string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
  1407. string filename = $"Laser-{currentDate}-W0.txt";
  1408. // 拼接完整路径
  1409. string fullPath = Path.Combine(path, filename);
  1410. string lastNonEmptyLine = "";
  1411. // 判断文件是否存在
  1412. if (File.Exists(fullPath))
  1413. {
  1414. //读取文件内容
  1415. string[] lines = File.ReadAllLines(fullPath);
  1416. // 获取最后一行数据(忽略标题行)
  1417. if (lines.Length > 1)
  1418. {
  1419. string lastLine = "";
  1420. for (int i = lines.Length - 1; i > 0; i--)
  1421. {
  1422. if (!string.IsNullOrEmpty(lines[i]))
  1423. {
  1424. lastLine = lines[i];
  1425. break;
  1426. }
  1427. }
  1428. // 将最后一行按逗号分隔
  1429. string[] values = lastLine.Split(',');
  1430. values[1] = sn;
  1431. string key = "三点激光_" + direction; // 构造键名
  1432. string value = string.Join(",", values); // 获取值并去除多余空格
  1433. compensationDict[key] = value;
  1434. //// 提取“1点补偿”到“6点补偿”的值
  1435. //for (int i = 2; i <= 7 && i < values.Length; i++) // 从索引2开始,最多提取6个值
  1436. //{
  1437. // string key = $"{i - 1}点补偿"; // 构造键名
  1438. // string value = values[i].Trim(); // 获取值并去除多余空格
  1439. // compensationDict[key] = value;
  1440. //}
  1441. }
  1442. }
  1443. else
  1444. {
  1445. Console.WriteLine($"文件不存在: {fullPath}");
  1446. }
  1447. }
  1448. catch (Exception ex)
  1449. {
  1450. // 捕获异常并输出错误信息
  1451. Console.WriteLine($"发生错误: {ex.Message}");
  1452. }
  1453. return compensationDict;
  1454. }
  1455. public int PCBStationOutData(BarcodeSet_t Barcode, IoT_DataSet_t iotData)
  1456. {
  1457. int res = 0;
  1458. string jsonstr1 = "";
  1459. try
  1460. {
  1461. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1462. outRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备id(可配置)
  1463. outRequest_Body.stationId = GlobalContext.s5_station; // ⼯位ID(可配置)
  1464. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1465. outRequest_Body.clientTime =
  1466. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1467. outRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
  1468. int a1Result = (int)iotData.testStatus;
  1469. //bool pass = a1Result == 1;
  1470. //outRequest_Body.state = pass ? "PASS" : "FAIL"; ; // 出站条件 PASS或FAIL
  1471. outRequest_Body.state = "PASS";
  1472. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1473. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1474. XmStationOut_KeyMaterial keyMaterial = new XmStationOut_KeyMaterial();
  1475. keyMaterial.bindSort = 1;
  1476. keyMaterial.materialSn = Barcode.strProductBarcode;
  1477. outRequest_Body.unitData.keyMaterial.Add(keyMaterial); // 产品码
  1478. jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1479. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1480. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1481. if (response != null && response.header.code == "200")
  1482. {
  1483. res = 1;
  1484. AddMessage(LogType.Info,
  1485. "上传PCB出站数据到MES服务器---成功!请求信息:" + jsonstr1 + ",返回信息:" +
  1486. JsonConvert.SerializeObject(response.body));
  1487. }
  1488. else
  1489. {
  1490. res = 0;
  1491. AddMessage(LogType.Error,
  1492. "上传PCB出站数据到MES服务器---失败!错误信息:" + response.header.desc + ",请求信息:" + jsonstr1 + ",返回信息:" +
  1493. JsonConvert.SerializeObject(response.body));
  1494. }
  1495. }
  1496. catch (Exception e)
  1497. {
  1498. res = 0;
  1499. AddMessage(LogType.Info, "上传PCB出站数据到MES服务器---失败!请求信息:" + jsonstr1 + ",返回信息:" + e.Message);
  1500. }
  1501. return res;
  1502. }
  1503. public int PCBStationInData(BarcodeSet_t Barcode, IoT_DataSet_t iotData)
  1504. {
  1505. int res = 0;
  1506. string json_Body = "";
  1507. try
  1508. {
  1509. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1510. inRequest_Body.machineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  1511. inRequest_Body.stationId = GlobalContext.s5_station; // ⼯位ID(可配置)
  1512. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1513. inRequest_Body.clientTime =
  1514. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1515. inRequest_Body.unitSn = Barcode.strPCBBarcode; // 产品SN
  1516. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1517. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1518. json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1519. var response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1520. string resultJson = JsonConvert.SerializeObject(response);
  1521. if (response != null && response.header.code == "200")
  1522. {
  1523. res = 1;
  1524. AddMessage(LogType.Info,
  1525. "上传PCB进站数据到MES服务器---成功!请求信息:" + json_Body + ",返回信息:" +
  1526. JsonConvert.SerializeObject(response.body));
  1527. }
  1528. else
  1529. {
  1530. res = 0;
  1531. AddMessage(LogType.Error,
  1532. "上传PCB进站数据到MES服务器---失败!错误信息:" + response.header.desc + ",请求信息:" + json_Body + ",返回信息:" +
  1533. JsonConvert.SerializeObject(response.body));
  1534. }
  1535. }
  1536. catch (Exception e)
  1537. {
  1538. res = 0;
  1539. AddMessage(LogType.Info, "上传PCB进站数据到MES服务器---失败!请求信息:" + json_Body + ",返回信息:" + e.Message);
  1540. }
  1541. return res;
  1542. }
  1543. /// <summary>
  1544. /// 调用进站接口并保存进站数据
  1545. /// </summary>
  1546. /// <param name="stationNameStr">工站信息</param>
  1547. /// <param name="workorder_code">工单号</param>
  1548. /// <param name="mtltmrk">型号(物料号)</param>
  1549. /// <param name="sn">产品SN</param>
  1550. /// <param name="items">进站数据</param>
  1551. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1552. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn,
  1553. List<TestItem> items, string MachineId, string StationId, bool pass, string slot)
  1554. {
  1555. int result = 0;
  1556. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1557. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1558. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1559. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1560. inRequest_Body.clientTime =
  1561. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1562. inRequest_Body.unitSn = sn; // 产品SN
  1563. inRequest_Body.uuidInspection = uuid;
  1564. inRequest_Body.state = pass ? "PASS" : "FAIL";
  1565. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1566. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1567. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1568. StationIn stationIn = new StationIn()
  1569. {
  1570. Workorder_code = workorder_code, // 车间订单号
  1571. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1572. Sn = sn, // SN
  1573. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1574. Parameter_values = items, // 进站数据
  1575. Write_user = inRequest_Body.userId, // 员工Id
  1576. Test_time = inRequest_Body.clientTime // 进站时间
  1577. };
  1578. // 本地数据
  1579. string sql = stationIn.ToStringInsert(0);
  1580. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1581. result = ret == "成功" ? 1 : 6;
  1582. #region MES
  1583. if (GlobalContext.IsSendStationIn)
  1584. {
  1585. try
  1586. {
  1587. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1588. string resultJson = "";
  1589. string mesRet = string.Empty;
  1590. int i = 0;
  1591. while (i < 2) // 1009会多次尝试上传
  1592. {
  1593. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1594. resultJson = JsonConvert.SerializeObject(response);
  1595. if (response != null && response.header.code == "200")
  1596. break;
  1597. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1598. i++;
  1599. i++;
  1600. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1601. // 记录失败原因
  1602. OnMessage(LogType.Error, $"上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:{mesRet},请求参数:{json_Body}");
  1603. }
  1604. if (response?.header?.code == "200")
  1605. {
  1606. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1607. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1608. result = ret_Upd == "成功" ? 1 : 6;
  1609. AddMessage(LogType.Info,
  1610. $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功,返回参数:{resultJson},请求参数:{json_Body}");
  1611. }
  1612. else
  1613. {
  1614. result = 5;
  1615. AddMessage(LogType.Info,
  1616. $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息: {mesRet},请求参数:{json_Body}");
  1617. }
  1618. string sql_response =
  1619. stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1620. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1621. }
  1622. catch (Exception ex)
  1623. {
  1624. result = 6;
  1625. string str = ex.StackTrace;
  1626. AddMessage_Station(stationNameStr, LogType.Error,
  1627. $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1628. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1629. }
  1630. }
  1631. #endregion
  1632. #region IOT
  1633. //过站结果
  1634. if (GlobalContext.IsMqttSendProcessData)
  1635. {
  1636. PassStationResultRequest request = new PassStationResultRequest();
  1637. request.project_code = GlobalContext.Project_Code; // 项⽬编码
  1638. request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
  1639. request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
  1640. request.line_code = GlobalContext.LineCode; // 线体编码
  1641. request.work_station = xiaomiParm.workstation; // ⼯站ID
  1642. request.device_code = xiaomiParm.deviceCode; // 装备编码
  1643. request.station = xiaomiParm.stationCode;
  1644. request.process_time =
  1645. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
  1646. request.slot = slot; // 槽位编码
  1647. request.sn = sn; // 产品SN
  1648. // request.enter_status = inpass ? "PASS" : "FAIL"; // 进站状态
  1649. request.enter_status = pass ? "PASS" : "FAIL"; // 进站状态
  1650. request.result = ""; // 出站条件 PASS或FAIL; // 过站结果
  1651. request.work_type = "OUT_STATION"; // 作业类型
  1652. // 上传过站结果
  1653. (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
  1654. if (iotResult.Item1 != 0)
  1655. {
  1656. OnMessage(LogType.Info,
  1657. $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}] 进站结果[{request.enter_status}] 出站结果[{request.result}]");
  1658. }
  1659. }
  1660. #endregion
  1661. return result;
  1662. }
  1663. /// <summary>
  1664. /// 选择如何记录出站数据
  1665. /// </summary>
  1666. /// <param name="items">出站数据</param>
  1667. /// <param name="equipmentCode">设备编号</param>
  1668. /// <param name="processItem">测试项目</param>
  1669. /// <param name="workorder_code">车间订单号</param>
  1670. /// <param name="batch_num">批次号</param>
  1671. /// <param name="mtltmrk">型号</param>
  1672. /// <param name="proDate">日期</param>
  1673. /// <param name="supplierCode">供应商代码</param>
  1674. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1675. /// <returns>上传成功时返回1;失败返回0</returns>
  1676. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode,
  1677. string processItem,
  1678. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1679. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId,
  1680. string StationId, string PartBarcode, string jsonParm, string direction = "")
  1681. {
  1682. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num,
  1683. mtltmrk,
  1684. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode, jsonParm,
  1685. direction);
  1686. }
  1687. /// <summary>
  1688. /// 添加出站数据(提交到MES+本地保存到数据库)
  1689. /// </summary>
  1690. /// <param name="items">出站数据</param>
  1691. /// <param name="equipmentCode">设备编号</param>
  1692. /// <param name="processItem">测试项目</param>
  1693. /// <param name="workorder_code">车间订单号</param>
  1694. /// <param name="batch_num">批次号</param>
  1695. /// <param name="mtltmrk">型号</param>
  1696. /// <param name="proDate">日期</param>
  1697. /// <param name="supplierCode">供应商代码</param>
  1698. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1699. /// <returns>上传成功时返回1;失败返回0</returns>
  1700. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1701. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1702. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot,
  1703. string machineId, string stationId, string partBarcode, string jsonParm, string direction = "")
  1704. {
  1705. int upload = 0;
  1706. int result = 0;
  1707. ProcessData processData = new ProcessData()
  1708. {
  1709. Equipment_code = equipmentCode,
  1710. Workorder_code = workorder_code,
  1711. Batch_number = batch_num,
  1712. Sn = sn, // SN
  1713. Testitem = processItem,
  1714. Parameter_values = items,
  1715. Write_user = GlobalContext.CurrentUser,
  1716. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1717. };
  1718. // 本地数据
  1719. string sql = processData.ToStringInsert(upload);
  1720. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1721. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1722. #region MES
  1723. if (GlobalContext.IsSendProcessData)
  1724. {
  1725. try
  1726. {
  1727. string id = processData.ID.Copy();
  1728. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1729. outRequest_Body.uuidInspection = uuid;
  1730. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1731. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1732. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1733. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1734. outRequest_Body.unitSn = sn; // 产品SN
  1735. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1736. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1737. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1738. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1739. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1740. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1741. if (!string.IsNullOrEmpty(partBarcode))
  1742. {
  1743. outRequest_Body.unitData.keyMaterial.Add(
  1744. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1745. {
  1746. bindSort = 1,
  1747. materialSn = partBarcode
  1748. }); // 设备数据 - 部件码
  1749. }
  1750. //OP30站读txt数据
  1751. if (stationNameStr.Contains("OP30"))
  1752. {
  1753. string path = "";
  1754. if (direction == "Left")
  1755. path = GlobalContext.MESLaserLPath;
  1756. else
  1757. path = GlobalContext.MESLaserRPath;
  1758. //字典存储数据
  1759. Dictionary<string, string> compensationDict = GetLastLineCompensation(path, direction, sn);
  1760. foreach (var kvp in compensationDict)
  1761. {
  1762. outRequest_Body.unitData.processData.Add(
  1763. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1764. {
  1765. dataName = kvp.Key.ToString(),
  1766. dataValue = kvp.Value.ToString()
  1767. });
  1768. }
  1769. }
  1770. //过站明细
  1771. if (GlobalContext.IsSendProcessDetail)
  1772. {
  1773. if (jsonParm.Length > 0)
  1774. {
  1775. //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]}";
  1776. // 解析JSON字符串为字典
  1777. jsonParm = jsonParm.Replace("[", "\"[");
  1778. jsonParm = jsonParm.Replace("]", "]\"");
  1779. var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonParm);
  1780. foreach (var kvp in dictionary)
  1781. {
  1782. outRequest_Body.unitData.processData.Add(
  1783. new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
  1784. {
  1785. dataName = kvp.Key.ToString(),
  1786. dataValue = string.IsNullOrEmpty(kvp.Value) ? "" : kvp.Value.ToString()
  1787. });
  1788. }
  1789. }
  1790. }
  1791. if (GlobalContext.MESIsSendUpFile)
  1792. {
  1793. foreach (var item in fileUploadData.fileData)
  1794. {
  1795. if (!string.IsNullOrEmpty(item.FileName))
  1796. {
  1797. outRequest_Body.unitData.fileData.Add(
  1798. new XmStationOut_FileData()
  1799. {
  1800. fileName = item.FileName,
  1801. fileId = item.FileId,
  1802. bucket = item.Bucket
  1803. });
  1804. }
  1805. }
  1806. }
  1807. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1808. if (GlobalContext.IsSendProcessData)
  1809. {
  1810. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1811. string mesRet = string.Empty;
  1812. int i = 0;
  1813. while (i < 2) // 1009会多次尝试上传
  1814. {
  1815. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1816. if (response != null && response.header.code == "200")
  1817. {
  1818. OnMessage(LogType.Info,
  1819. $"【出站数据 SN {sn}】上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" +
  1820. JsonConvert.SerializeObject(response.body));
  1821. break;
  1822. }
  1823. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1824. i++;
  1825. i++;
  1826. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1827. // 记录失败原因
  1828. OnMessage(LogType.Error,
  1829. $"【出站数据 SN {sn}】上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1830. }
  1831. if (response?.header?.code == "200")
  1832. {
  1833. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1834. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1835. result = 1;
  1836. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1837. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1838. }
  1839. else
  1840. {
  1841. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1842. }
  1843. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(
  1844. JsonConvert.SerializeObject(outRequest_Body),
  1845. JsonConvert.SerializeObject(response), id);
  1846. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1847. }
  1848. }
  1849. catch (Exception ex)
  1850. {
  1851. string str = ex.StackTrace;
  1852. AddMessage_Station(stationNameStr, LogType.Error,
  1853. $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  1854. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1855. }
  1856. }
  1857. #endregion
  1858. #region IOT
  1859. //过站明细
  1860. if (GlobalContext.IsMqttSendProcessData)
  1861. {
  1862. test_item_num += 1;
  1863. PassStationDetailRequest request = new PassStationDetailRequest();
  1864. request.pass_station_id = uuid;
  1865. request.sn = sn; // 产品SN
  1866. request.slot = vehicleSlot; // 槽位编码
  1867. request.test_item_num = test_item_num.ToString();
  1868. request.function_name = "Machine_加⼯模块";
  1869. request.status = "PASS";
  1870. (int, string) iotResult = (0, "");
  1871. if (jsonParm.Length > 0)
  1872. {
  1873. // 解析JSON字符串为字典
  1874. var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonParm);
  1875. foreach (var kvp in dictionary)
  1876. {
  1877. request.test_item = kvp.Key.ToString();
  1878. request.result_val = string.IsNullOrEmpty(kvp.Value) ? "" : kvp.Value.ToString();
  1879. request.description = request.test_item;
  1880. // 上传过站明细
  1881. iotResult = XiaomiMqttClient_Extend.Write_PassStationDetail(request);
  1882. if (iotResult.Item1 != 0)
  1883. {
  1884. OnMessage(LogType.Info,
  1885. $"【IOT过站明细】上传失败!错误原因:{iotResult.Item2},过站明细;产品码[{sn}] 测试项目[{request.test_item}] 测试值[{request.result_val}]");
  1886. }
  1887. }
  1888. }
  1889. }
  1890. //过站结果
  1891. if (GlobalContext.IsMqttSendProcessData)
  1892. {
  1893. PassStationResultRequest request = new PassStationResultRequest();
  1894. request.project_code = GlobalContext.Project_Code; // 项⽬编码
  1895. request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
  1896. request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
  1897. request.line_code = GlobalContext.LineCode; // 线体编码
  1898. request.work_station = xiaomiParm.workstation; // ⼯站ID
  1899. request.device_code = xiaomiParm.deviceCode; // 装备编码
  1900. request.station = xiaomiParm.stationCode;
  1901. request.process_time =
  1902. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
  1903. request.slot = vehicleSlot; // 槽位编码
  1904. request.sn = sn; // 产品SN
  1905. // request.enter_status = inpass ? "PASS" : "FAIL"; // 进站状态
  1906. request.enter_status = ""; // 进站状态
  1907. request.result = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL; // 过站结果
  1908. request.work_type = "OUT_STATION"; // 作业类型
  1909. // 上传过站结果
  1910. (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
  1911. if (iotResult.Item1 != 0)
  1912. {
  1913. OnMessage(LogType.Info,
  1914. $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}] 进站结果[{request.enter_status}] 出站结果[{request.result}]");
  1915. }
  1916. }
  1917. #endregion
  1918. return result;
  1919. }
  1920. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1921. //{
  1922. // Stopwatch stopwatch = new Stopwatch();
  1923. // stopwatch.Start();
  1924. // try
  1925. // {
  1926. // // 初始化 AtlasScrew 实例
  1927. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1928. // atlasScrew1.Initial();
  1929. // // 存储结果的列表
  1930. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1931. // // 存储角度和扭力的字符串列表
  1932. // List<string> angleStrs = new List<string>();
  1933. // List<string> torqueStrs = new List<string>();
  1934. // // 上一次获取的数据
  1935. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1936. // while (isExitAtlasLeft) // 检查是否收集数据
  1937. // {
  1938. // // 获取当前数据
  1939. // var currentResult = atlasScrew1.GetResults();
  1940. // // 判断是否为新数据
  1941. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1942. // {
  1943. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1944. // // 更新角度和扭力的字符串列表
  1945. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1946. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1947. // // 计算角度、扭力、起始扭力和最大扭力
  1948. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1949. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1950. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1951. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1952. // // 将新数据添加到结果列表
  1953. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1954. // // 更新上一次获取的数据
  1955. // lastResult = currentResult;
  1956. // }
  1957. // // 等待一段时间后再次检查
  1958. // Thread.Sleep(20); // 轮询间隔时间
  1959. // // 如果触发了出站,则退出循环
  1960. // if (!isExitAtlasLeft)
  1961. // {
  1962. // break;
  1963. // }
  1964. // }
  1965. // // 生成文件名
  1966. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1967. // // 写入数据到文件
  1968. // using (StreamWriter writer = new StreamWriter(fileName))
  1969. // {
  1970. // // 写入标题行
  1971. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1972. // // 写入每一行数据
  1973. // foreach (var result in results)
  1974. // {
  1975. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1976. // }
  1977. // }
  1978. // stopwatch.Stop();
  1979. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1980. // }
  1981. // catch (Exception ex)
  1982. // {
  1983. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1984. // }
  1985. // finally
  1986. // {
  1987. // // 重置标志变量
  1988. // isExitAtlasLeft = false;
  1989. // }
  1990. //}
  1991. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1992. //{
  1993. // Stopwatch stopwatch = new Stopwatch();
  1994. // stopwatch.Start();
  1995. // try
  1996. // {
  1997. // // 初始化 AtlasScrew 实例
  1998. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1999. // atlasScrew2.Initial();
  2000. // // 存储结果的列表
  2001. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  2002. // // 上一次获取的数据
  2003. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  2004. // while (isExitAtlasRight) // 检查是否收集数据
  2005. // {
  2006. // // 获取当前数据
  2007. // var currentResult = atlasScrew2.GetResults();
  2008. // // 判断是否为新数据
  2009. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  2010. // {
  2011. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  2012. // // 将新数据写入PLC
  2013. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  2014. // // 将新数据添加到结果列表
  2015. // results.Add(currentResult);
  2016. // // 更新上一次获取的数据
  2017. // lastResult = currentResult;
  2018. // }
  2019. // // 等待一段时间后再次检查
  2020. // Thread.Sleep(20); // 轮询间隔时间
  2021. // // 如果触发了出站,则退出循环
  2022. // if (!isExitAtlasRight)
  2023. // {
  2024. // break;
  2025. // }
  2026. // }
  2027. // // 将所有数据写入文件
  2028. // //WriteDataToFile(sn, direction, results);
  2029. // stopwatch.Stop();
  2030. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  2031. // }
  2032. // catch (Exception ex)
  2033. // {
  2034. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  2035. // }
  2036. // finally
  2037. // {
  2038. // // 重置标志变量
  2039. // isExitAtlasRight = false;
  2040. // }
  2041. //}
  2042. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  2043. {
  2044. Stopwatch stopwatch = new Stopwatch();
  2045. stopwatch.Start();
  2046. int nRet = 0;
  2047. string strRet = "";
  2048. try
  2049. {
  2050. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  2051. while (isCollectingFlagLeft)
  2052. {
  2053. // 从缓存中获取所有未处理的数据
  2054. var cachedData = atlasScrew.GetCachedDataLeft();
  2055. foreach (var currentResult in cachedData)
  2056. {
  2057. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  2058. {
  2059. continue; // 跳过无效数据
  2060. }
  2061. OnMessage(LogType.Info,
  2062. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  2063. // 写入PLC
  2064. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  2065. {
  2066. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  2067. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  2068. };
  2069. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  2070. if (nRet != 0)
  2071. {
  2072. OnMessage(LogType.Info,
  2073. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  2074. }
  2075. else
  2076. {
  2077. OnMessage(LogType.Info,
  2078. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  2079. }
  2080. // 构建保存路径
  2081. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  2082. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  2083. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  2084. Directory.CreateDirectory(savePath); // 确保目录存在
  2085. // 构建文件名(以 SN + 序号命名)
  2086. string fileName = $"{sn}_{fileCounter}.txt";
  2087. string filePath = Path.Combine(savePath, fileName);
  2088. // 写入文件
  2089. using (StreamWriter writer = new StreamWriter(filePath))
  2090. {
  2091. writer.WriteLine("精度, 扭力");
  2092. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  2093. for (int i = 0;
  2094. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  2095. i++)
  2096. {
  2097. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  2098. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  2099. writer.WriteLine($"{precision}, {torque}");
  2100. }
  2101. }
  2102. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  2103. // 增加文件计数器
  2104. fileCounter++;
  2105. }
  2106. // 如果没有更多数据,则短暂休眠以节省资源
  2107. if (!cachedData.Any())
  2108. {
  2109. Thread.Sleep(10); // 根据需要调整休眠时间
  2110. }
  2111. // 如果触发了出站,则退出循环
  2112. if (!isCollectingFlagLeft)
  2113. {
  2114. break;
  2115. }
  2116. }
  2117. stopwatch.Stop();
  2118. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  2119. }
  2120. catch (Exception ex)
  2121. {
  2122. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  2123. }
  2124. finally
  2125. {
  2126. isCollectingFlagLeft = false;
  2127. }
  2128. }
  2129. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  2130. {
  2131. Stopwatch stopwatch = new Stopwatch();
  2132. stopwatch.Start();
  2133. int nRet = 0;
  2134. string strRet = "";
  2135. try
  2136. {
  2137. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  2138. while (isCollectingFlagRight)
  2139. {
  2140. // 从缓存中获取所有未处理的数据
  2141. var cachedData = atlasScrew.GetCachedDataLeft();
  2142. foreach (var currentResult in cachedData)
  2143. {
  2144. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  2145. {
  2146. continue; // 跳过无效数据
  2147. }
  2148. OnMessage(LogType.Info,
  2149. $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  2150. // 写入PLC
  2151. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  2152. {
  2153. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  2154. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  2155. };
  2156. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  2157. if (nRet != 0)
  2158. {
  2159. OnMessage(LogType.Info,
  2160. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  2161. }
  2162. else
  2163. {
  2164. OnMessage(LogType.Info,
  2165. $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  2166. }
  2167. // 构建保存路径
  2168. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  2169. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  2170. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  2171. Directory.CreateDirectory(savePath); // 确保目录存在
  2172. // 构建文件名(以 SN + 序号命名)
  2173. string fileName = $"{sn}_{fileCounter}.txt";
  2174. string filePath = Path.Combine(savePath, fileName);
  2175. // 写入文件
  2176. using (StreamWriter writer = new StreamWriter(filePath))
  2177. {
  2178. writer.WriteLine("精度, 扭力");
  2179. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  2180. for (int i = 0;
  2181. i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
  2182. i++)
  2183. {
  2184. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  2185. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  2186. writer.WriteLine($"{precision}, {torque}");
  2187. }
  2188. }
  2189. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  2190. // 增加文件计数器
  2191. fileCounter++;
  2192. }
  2193. // 如果没有更多数据,则短暂休眠以节省资源
  2194. if (!cachedData.Any())
  2195. {
  2196. Thread.Sleep(10); // 根据需要调整休眠时间
  2197. }
  2198. // 如果触发了出站,则退出循环
  2199. if (!isCollectingFlagRight)
  2200. {
  2201. break;
  2202. }
  2203. }
  2204. stopwatch.Stop();
  2205. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  2206. }
  2207. catch (Exception ex)
  2208. {
  2209. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  2210. }
  2211. finally
  2212. {
  2213. isCollectingFlagRight = false;
  2214. }
  2215. }
  2216. public static (int, string) CompressFolder(string folderPath, string zipFilePath)
  2217. {
  2218. try
  2219. {
  2220. // 创建zip文件,将指定文件夹内的所有内容压缩到这个zip文件中
  2221. System.IO.Compression.ZipFile.CreateFromDirectory(folderPath, zipFilePath);
  2222. return (1, "文件夹已成功压缩!");
  2223. }
  2224. catch (Exception ex)
  2225. {
  2226. return (0, "文件压缩出错!" + ex.Message);
  2227. }
  2228. }
  2229. /// <summary>
  2230. /// 上传文件
  2231. /// </summary>
  2232. /// <param name="BarcodeSet_t">条码集合</param>
  2233. /// <param name="stationCode">工站编号</param>
  2234. /// <param name="stationName">工站名称</param>
  2235. /// <param name="path">文件路径</param>
  2236. public async Task<(int, string)> SaveDBbyFileInfo(BarcodeSet_t BarcodeSet, string stationCode,
  2237. string stationName, int pass, string path, string guid = "")
  2238. {
  2239. string sql, filename = "";
  2240. int result = 0;
  2241. var formData = new MultipartFormDataContent();
  2242. string msg = "";
  2243. string file_category = "IMAGE"; //IMAGE 、TEXT 、UNKNOWN
  2244. string file_type = "IMAGE";
  2245. string project = GlobalContext.ProgramName;
  2246. string run_mode = GlobalContext.run_mode;
  2247. string product_mode = GlobalContext.product_mode;
  2248. string pass_result = (pass == 1 ? "PASS" : "Fail");
  2249. string device_code = xiaomiParm.deviceCode;
  2250. string sn = BarcodeSet.strProductBarcode;
  2251. string staion_id = xiaomiParm.stationCode;
  2252. string bucket =
  2253. $"{file_category}/{file_type}/{project}/{product_mode}/{run_mode}/{pass_result}/{device_code}/{sn}/{staion_id}";
  2254. // 获取所有图片文件
  2255. if (guid == "")
  2256. {
  2257. guid = Guid.NewGuid().ToString();
  2258. }
  2259. try
  2260. {
  2261. if (GlobalContext.MESIsSendUpFile)
  2262. {
  2263. List<string> imageFiles = GetAllImageFiles(path);
  2264. string toPath = GlobalContext.MqttFileBackupLogDir;
  2265. filename =
  2266. $"{xiaomiParm.workstation}_{file_type}_{sn}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";
  2267. //string directoryPath = Path.GetDirectoryName(path);
  2268. string strFilePath = toPath + "\\" + filename;
  2269. if (imageFiles.Count > 0)
  2270. {
  2271. var r = CompressFolder(path, strFilePath);
  2272. if (r.Item1 == 0)
  2273. {
  2274. return (0, r.Item2);
  2275. }
  2276. else
  2277. {
  2278. msg = r.Item2 + "\r\n";
  2279. }
  2280. }
  2281. else
  2282. {
  2283. return (0, "文件不存在!");
  2284. }
  2285. FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
  2286. fileUpload_X5.bucket = bucket;
  2287. fileUpload_X5.name = filename;
  2288. fileUpload_X5.uuid = guid.ToString();
  2289. ///需要上传文件
  2290. FileInfo file = new FileInfo(strFilePath);
  2291. string fileMd5Hex = GetMD5Hex(file);
  2292. fileUpload_X5.md5 = fileMd5Hex;
  2293. fileUpload_X5.uploadCloud = true;
  2294. fileUpload_X5.informMqtt = true;
  2295. FileMqttPayload fileMqttPayload = new FileMqttPayload();
  2296. fileMqttPayload.factory = GlobalContext.Factory_Code;
  2297. fileMqttPayload.project_name = GlobalContext.Project_Code;
  2298. fileMqttPayload.product_mode = GlobalContext.product_mode;
  2299. fileMqttPayload.line_no = GlobalContext.LineCode;
  2300. fileMqttPayload.work_station_no = xiaomiParm.workstation;
  2301. fileMqttPayload.equipment_no = xiaomiParm.deviceCode;
  2302. fileMqttPayload.station_no = xiaomiParm.stationCode;
  2303. fileMqttPayload.file_id = guid;
  2304. fileMqttPayload.file_name = filename;
  2305. fileMqttPayload.sn = BarcodeSet.strProductBarcode;
  2306. //fileMqttPayload.opt_time = "";
  2307. //fileMqttPayload.file_type = "";
  2308. //fileMqttPayload.file_category = "";
  2309. //fileMqttPayload.tag = "";
  2310. fileMqttPayload.reference_info.pass_station_id = uuid;
  2311. var fileresult = await
  2312. XiaomiMESHttp_UpLoadFile.FileUoladToMes(strFilePath, fileUpload_X5, fileMqttPayload);
  2313. if (fileresult.Item1 != 1)
  2314. {
  2315. return (0, msg + fileresult.Item2 + "\r\n");
  2316. }
  2317. else
  2318. {
  2319. msg = msg + fileresult.Item2 + "\r\n";
  2320. }
  2321. foreach (var imageFile in imageFiles)
  2322. {
  2323. if (File.Exists(imageFile))
  2324. {
  2325. //删除文件
  2326. (bool, string) newResult = DeleteFile(imageFile);
  2327. if (!newResult.Item1)
  2328. {
  2329. return (0, Path.GetFileName(imageFile) + newResult.Item2);
  2330. }
  2331. }
  2332. }
  2333. }
  2334. return (1, msg);
  2335. }
  2336. catch (Exception e)
  2337. {
  2338. return (0,
  2339. filename + $"文件上传错误!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode},错误原因:" +
  2340. e.Message);
  2341. }
  2342. }
  2343. /// <summary>
  2344. /// 获取路径下的所有图片
  2345. /// </summary>
  2346. /// <param name="directoryPath"></param>
  2347. /// <returns></returns>
  2348. public List<string> GetAllImageFiles(string directoryPath)
  2349. {
  2350. var imageExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
  2351. { ".jpg", ".jpeg", ".png", ".bmp", ".gif", ".tiff" };
  2352. var imageFiles = new List<string>();
  2353. try
  2354. {
  2355. // 遍历目录及子目录中的所有文件
  2356. foreach (string file in Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories))
  2357. {
  2358. // 获取文件扩展名并检查是否为图片格式
  2359. string extension = Path.GetExtension(file);
  2360. if (imageExtensions.Contains(extension))
  2361. {
  2362. imageFiles.Add(file);
  2363. }
  2364. }
  2365. }
  2366. catch (Exception ex)
  2367. {
  2368. OnMessage(LogType.Error, $"图片查询发生错误: {ex.Message}");
  2369. }
  2370. return imageFiles;
  2371. }
  2372. /// <summary>
  2373. /// 实例化报警字典
  2374. /// </summary>
  2375. private (bool, string) InitalDicAlarm()
  2376. {
  2377. #region 加载报警表
  2378. string excelPath = "";
  2379. switch (GlobalContext.IsUsePLCNow)
  2380. {
  2381. case 1:
  2382. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_10_壳体清洁上料.xlsx";
  2383. break;
  2384. case 2:
  2385. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_20_上盖板上料装备.xlsx";
  2386. break;
  2387. case 3:
  2388. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_30_点散热胶装备.xlsx";
  2389. break;
  2390. case 4:
  2391. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_40_胶线检测.xlsx";
  2392. break;
  2393. case 5:
  2394. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_50_ADD板上料组装装备.xlsx";
  2395. break;
  2396. case 6:
  2397. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_60_组上盖板.xlsx";
  2398. break;
  2399. case 7:
  2400. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_70_上盖板锁螺丝.xlsx";
  2401. break;
  2402. case 8:
  2403. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_80_NG下料.xlsx";
  2404. break;
  2405. case 9:
  2406. excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_90_半成品下料.xlsx";
  2407. break;
  2408. default:
  2409. return (false, $"不支持当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请在设置页切换到正确的plc后重启该软件!");
  2410. }
  2411. if (!File.Exists(excelPath))
  2412. return (false, $"未找到当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请检查文件路径:'{excelPath}'。");
  2413. DataTable DtModel = NPOIHelper.ReadExcel(excelPath);
  2414. if (DtModel == null || DtModel.Rows.Count < 1)
  2415. return (false, $"报警点位表未包含任何报警数据!请检查‘{excelPath}’文件!");
  2416. // 检查列名
  2417. List<string> isNeedParms = new List<string>()
  2418. {
  2419. "设备分类名称", "设备分类编码", "分类层级1", "分类层级2", "分类层级3", "分类层级4", "事件名称", "事件ID", "描述", "标签", "PLC地址", "工位"
  2420. }; // 必须要有的列
  2421. // 指定列名 + 检查列是否完整
  2422. DataRow dtRowName = DtModel.Rows[0];
  2423. int count = DtModel.Columns.Count;
  2424. for (int i = 0; i < count; i++)
  2425. {
  2426. string columeName = dtRowName[i]?.ToString();
  2427. if (!string.IsNullOrEmpty(columeName))
  2428. DtModel.Columns[i].ColumnName = columeName;
  2429. if ((!string.IsNullOrEmpty(columeName)) && isNeedParms.Count > 0 && isNeedParms.Contains(columeName))
  2430. isNeedParms.Remove(columeName);
  2431. }
  2432. DtModel.Rows.RemoveAt(0);
  2433. if (isNeedParms.Count > 0)
  2434. {
  2435. string msg1 = string.Join(",", isNeedParms);
  2436. return (false, $"报警点位表未包含列:{msg1}!请检查‘{excelPath}’文件!");
  2437. }
  2438. #endregion 加载报警表
  2439. List<Alarm> keyValues1 = new List<Alarm>();
  2440. for (int i = 0; i < DtModel.Rows.Count; i++)
  2441. {
  2442. Alarm alarm = new Alarm();
  2443. alarm.plcName = DtModel.Rows[i]["设备分类名称"]?.ToString(); // 设备名;
  2444. string type1Str = DtModel.Rows[i]["分类层级1"]?.ToString(); // 分类层级1;
  2445. alarm.type1CH = type1Str; // 分类层级1 中文
  2446. alarm.type1 = type1Str; // 分类层级1
  2447. if (!string.IsNullOrEmpty(type1Str) && type1Str.Contains("\n"))
  2448. {
  2449. string[] type1Strs = type1Str.Split('\n');
  2450. if (type1Strs.Length >= 2)
  2451. {
  2452. alarm.type1CH = type1Strs[0].Trim(); // 分类层级1 中文
  2453. alarm.type1 = type1Strs[1].Trim(); // 分类层级1
  2454. if (string.IsNullOrEmpty(alarm.type1))
  2455. alarm.type1 = alarm.type1CH;
  2456. }
  2457. }
  2458. string type2Str = DtModel.Rows[i]["分类层级2"]?.ToString(); // 分类层级2;电气控制 electric_control
  2459. alarm.type2CH = type2Str; // 分类层级2 中文
  2460. alarm.type2 = type2Str; // 分类层级2
  2461. if (!string.IsNullOrEmpty(type2Str) && type2Str.Contains("\n"))
  2462. {
  2463. string[] type2Strs = type2Str.Split('\n');
  2464. if (type2Strs.Length >= 2)
  2465. {
  2466. alarm.type2CH = type2Strs[0].Trim(); // 分类层级2 中文
  2467. alarm.type2 = type2Strs[1].Trim(); // 分类层级2
  2468. if (string.IsNullOrEmpty(alarm.type2))
  2469. alarm.type2 = alarm.type2CH;
  2470. }
  2471. }
  2472. string type3Str = DtModel.Rows[i]["分类层级3"]?.ToString(); // 分类层级3;故障 Fault
  2473. alarm.type3CH = type3Str; // 分类层级3 中文
  2474. alarm.type3 = type3Str; // 分类层级3
  2475. if (!string.IsNullOrEmpty(type3Str) && type3Str.Contains("\n"))
  2476. {
  2477. string[] type3Strs = type3Str.Split('\n');
  2478. if (type3Strs.Length >= 2)
  2479. {
  2480. alarm.type3CH = type3Strs[0].Trim(); // 分类层级3 中文
  2481. alarm.type3 = type3Strs[1].Trim(); // 分类层级3
  2482. if (string.IsNullOrEmpty(alarm.type3))
  2483. alarm.type3 = alarm.type3CH;
  2484. }
  2485. }
  2486. string faultStr = DtModel.Rows[i]["分类层级4"]?.ToString(); // 故障部件;overall_module
  2487. alarm.type4 = faultStr; // 分类层级4 中文
  2488. alarm.type4CH = faultStr; // 分类层级4
  2489. if (!string.IsNullOrEmpty(faultStr) && faultStr.Contains("\n"))
  2490. {
  2491. string[] faultStrs = faultStr.Split('\n');
  2492. if (faultStrs.Length >= 2)
  2493. {
  2494. alarm.type4CH = faultStrs[0].Trim(); // 故障部件;overall_module
  2495. alarm.type4 = faultStrs[1].Trim(); // 故障部件
  2496. if (string.IsNullOrEmpty(alarm.type4))
  2497. alarm.type4 = alarm.type4CH;
  2498. }
  2499. }
  2500. alarm.fault_code = DtModel.Rows[i]["事件ID"]?.ToString(); // 故障编码;A40001
  2501. alarm.fault_name = DtModel.Rows[i]["事件名称"]?.ToString(); // 故障名称;AL[1000]_系统_HMI急停故障
  2502. alarm.fault_desc = alarm.fault_name; // 故障描述;AL[1000]_系统_HMI急停故障
  2503. string plcAdress = DtModel.Rows[i]["PLC地址"]?.ToString();
  2504. alarm.PLC地址 = plcAdress;
  2505. plcAdress = plcAdress.Replace("fault_codes[", "");
  2506. plcAdress = plcAdress.Replace("]", "");
  2507. alarm.group_index = Convert.ToInt32(plcAdress.Split(".")[0]);
  2508. keyValues1.Add(alarm);
  2509. }
  2510. DicAlarms_Cur.Add(GlobalContext.IsUseStationName, keyValues1); // 这里使用线体代替工位
  2511. return (true, "报警字典表初始化成功!");
  2512. }
  2513. private async void ReadPLCAlarmToIot(uint[] FaultData, uint[] FaultDataOld, string stationNameStr,string flag)
  2514. {
  2515. DateTime dtNow = DateTime.Now;
  2516. try
  2517. {
  2518. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  2519. List<(int, int)> AlarmIndexList = new List<(int, int)>(); //收集所有报警信息的位置
  2520. AlarmData alarmData = new AlarmData();
  2521. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  2522. bool isNoAlarm = false; //是否有报警
  2523. string binaryString = "";
  2524. bool isNoNewAlarm = false; //是否有新的报警
  2525. if (FaultData.Length > 0)
  2526. {
  2527. foreach (var item in FaultData)
  2528. {
  2529. if (item > 0)
  2530. {
  2531. isNoAlarm = true;
  2532. break;
  2533. }
  2534. else {
  2535. isNoAlarm = false;
  2536. }
  2537. }
  2538. if (!FaultData.SequenceEqual(FaultDataOld))
  2539. {
  2540. isNoNewAlarm = true;
  2541. isNeedUpdUI = true;
  2542. }
  2543. if (FaultData.Length > 0 && isNoAlarm && isNoNewAlarm)
  2544. {
  2545. //解析报警信息,分析当前报警在字典中的定位
  2546. for (int i = 0; i <= FaultData.Length - 1; i++)
  2547. {
  2548. var num = 0;
  2549. if (FaultData[i] > 0)
  2550. {
  2551. //转换二进制
  2552. binaryString = Convert.ToString(FaultData[i], 2);
  2553. for (int j = binaryString.Length - 1; j >= 0; j--)
  2554. {
  2555. num++;
  2556. char s = binaryString[j];
  2557. if (binaryString[j] == '1')
  2558. {
  2559. //记录1的位置
  2560. AlarmIndexList.Add((i, num - 1));
  2561. }
  2562. }
  2563. }
  2564. }
  2565. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  2566. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.IsUseStationName];
  2567. foreach ((int index, int row) in AlarmIndexList)
  2568. {
  2569. var tempDic = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList();
  2570. for (int i = 0; i < tempDic.Count - 1; i++) // 读取
  2571. {
  2572. //若报警字典第[group_index]个数据,第[i]行与AlarmIndexList中的定位匹配,则添加进对应行的报警数据
  2573. if (tempDic[i].group_index == index && i == row)
  2574. {
  2575. dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据 =
  2576. new AlarmData()
  2577. {
  2578. GUID = Guid.NewGuid().ToString(),
  2579. LineName = GlobalContext.IsUseStationName, // 工站
  2580. PlcStation = tempDic[i].plcName, // 工站全称;[S1]
  2581. Type1 = tempDic[i].type1, // 故障层级1
  2582. Type2 = tempDic[i].type2, // 故障层级2
  2583. Type3 = tempDic[i].type3, // 故障层级3
  2584. Type4 = tempDic[i].type4, // 故障层级4
  2585. AlarmType = tempDic[i].fault_code, // 报警类型
  2586. AlarmDesc = tempDic[i].fault_name, // 报警内容
  2587. StartTime = dtNow // 开始时间
  2588. };
  2589. // 传输到页面
  2590. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  2591. {
  2592. 线体名称 = tempDic[i].plcName,
  2593. 报警类型 = tempDic[i].fault_code,
  2594. 报警内容 = tempDic[i].fault_name,
  2595. 开始时间 = dtNow
  2596. });
  2597. // 新增到数据库
  2598. //var data1 = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据;
  2599. //SaveAlarmDataByDB(stationNameStr, data1, false);
  2600. //OnMessage(LogType.Info, $"更新{BodyAlarm}完毕!");
  2601. }
  2602. }
  2603. }
  2604. //筛选含报警数据的字典
  2605. var dicAlarms_Cur = dicAlarms_Cur_PLC1.Where(x => x.报警数据 != null).ToList();
  2606. if (dicAlarms_Cur.Count > 0)
  2607. {
  2608. string stationId = "";
  2609. foreach (var item in dicAlarms_Cur)
  2610. {
  2611. if (!string.IsNullOrEmpty(xiaomiParm.stationCode))
  2612. {
  2613. stationId = xiaomiParm.stationCode;
  2614. //上传
  2615. SaveAlarmDataByDB(GlobalContext.IsUseStationName, stationId, item.报警数据, false);
  2616. }
  2617. else {
  2618. if (flag == "left")
  2619. {
  2620. if (GlobalContext.IsUsePLC3)
  2621. stationId = GlobalContext.s3_1_station;
  2622. if (GlobalContext.IsUsePLC7)
  2623. stationId = GlobalContext.s7_1_station;
  2624. //上传
  2625. SaveAlarmDataByDB(GlobalContext.IsUseStationName, stationId, item.报警数据, false);
  2626. }
  2627. else {
  2628. if (GlobalContext.IsUsePLC3)
  2629. stationId = GlobalContext.s3_2_station;
  2630. if (GlobalContext.IsUsePLC7)
  2631. stationId = GlobalContext.s7_2_station;
  2632. //上传
  2633. SaveAlarmDataByDB(GlobalContext.IsUseStationName, stationId, item.报警数据, false);
  2634. }
  2635. }
  2636. }
  2637. }
  2638. // 有新报警则更新
  2639. if (isNeedUpdUI)
  2640. // UI展示 - 展示到设备状态页
  2641. await Task.Run(() =>
  2642. {
  2643. try
  2644. {
  2645. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  2646. {
  2647. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  2648. if (Form_Main.formDevAlarm.Visible)
  2649. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  2650. }
  2651. }
  2652. catch
  2653. {
  2654. }
  2655. });
  2656. if (flag == "left")
  2657. {
  2658. _FaultDatas_Old = FaultData.ToArray();
  2659. }
  2660. else {
  2661. _FaultDatas_Old2 = FaultData.ToArray();
  2662. }
  2663. }
  2664. }
  2665. //FaultLogRequest request = new FaultLogRequest();
  2666. //request.station = mesStation; // 工位
  2667. //request.fault_name = xmFaultName; // 故障名称(同数据字典中的事件名称)
  2668. //request.fault_code = xmFaultCode2; // 故障编码(A,B,C,D,E)
  2669. //request.fault_cmpnt = xmFaultCmpnt; // 故障部件
  2670. //request.fault_desc = xmFaultDesc; // 故障描述
  2671. //request.fault_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 故障发生时间 2022-06-01 14:27:57.283
  2672. // // 上传
  2673. //(int, string) iotResult = XiaomiMqttClient_Extend.Write_FaultLog(request, type1, type2, type3, request.fault_cmpnt, deciveCode);
  2674. }
  2675. catch (Exception ex)
  2676. {
  2677. string str = ex.StackTrace;
  2678. AddMessage_Station(stationNameStr, LogType.Error,
  2679. $"{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" +
  2680. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2681. }
  2682. }
  2683. public void operateToIot(string action, string stationNameStr)
  2684. {
  2685. OperateLogRequest request = new OperateLogRequest();
  2686. request.software_version = "V" + Application.ProductVersion; // 软件版本号;如:V1.2.4
  2687. request.operate_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 操作时间(2022-06-01 14:27:57.283)
  2688. request.operate_action = action; // 操作动作(对应软件开启/关闭/重新加载项⽬;startup、shutdown、reload)
  2689. //request.current_process = Process.GetCurrentProcess()?.Id.ToString(); // 当前进程;进程ID
  2690. request.current_process = Application.ProductName;
  2691. request.operate_desc = stationNameStr; // 操作描述;如:供应商软件开启/关闭/重新加载项⽬
  2692. request.operate_result = "success"; // 操作结果
  2693. request.operator_name = "default"; // 操作账号名;填当前操作⽤⼾,如⽆则填default
  2694. // 上传
  2695. (int, string) iotResult = XiaomiMqttClient_Extend.Write_OperateLog(request);
  2696. if (iotResult.Item1 != 0)
  2697. {
  2698. AddMessage(LogType.Info, "【操作记录】上传失败!错误原因:" + iotResult.Item2 + "操作状态:" + stationNameStr);
  2699. }
  2700. }
  2701. private void 通用节拍接口(int plcNo, string stationNameStr, string tagMesCommName, string CarrierBarcode,
  2702. IoT_DataSet_t iot_data, out int res)
  2703. {
  2704. Stopwatch stopwatch1 = new Stopwatch();
  2705. Stopwatch stopwatch2 = new Stopwatch();
  2706. string resultStr = string.Empty;
  2707. try
  2708. {
  2709. string oEEType = iot_data.beatAction.ToString(); // 节拍类型(plc写入)
  2710. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode); //产品SN
  2711. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  2712. (short, string) result = (0, "");
  2713. // 上传开始节拍
  2714. result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2715. //上传结束节拍
  2716. switch (oEEType)
  2717. {
  2718. case "1":
  2719. Enum.TryParse("2", out deviceOEE);
  2720. result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2721. break;
  2722. case "5":
  2723. Enum.TryParse("6", out deviceOEE);
  2724. result = SaveOEEData(plcNo, stationNameStr, deviceOEE, strProductBarcode, CarrierBarcode);
  2725. break;
  2726. }
  2727. if (result.Item1 == 1)
  2728. {
  2729. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]上传成功!");
  2730. //写入PLC
  2731. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2732. iotData.machineState = iot_data.machineState;
  2733. iotData.work_type = iot_data.work_type;
  2734. iotData.testStatus = iot_data.testStatus;
  2735. iotData.beatAction = iot_data.beatAction;
  2736. iotData.beatReturn = 1; //OK
  2737. iotData.fault_codes = iot_data.fault_codes;
  2738. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2739. if (PLCresult.Item1 == 0)
  2740. {
  2741. res = 1;
  2742. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]写入成功!");
  2743. }
  2744. else
  2745. {
  2746. res = 0;
  2747. }
  2748. }
  2749. else
  2750. {
  2751. res = 0;
  2752. OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍[{deviceOEE}]接口出错!错误信息:" + result.Item2);
  2753. //写入PLC
  2754. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2755. iotData.machineState = iot_data.machineState;
  2756. iotData.work_type = iot_data.work_type;
  2757. iotData.testStatus = iot_data.testStatus;
  2758. iotData.beatAction = iot_data.beatAction;
  2759. iotData.beatReturn = 2; //NG
  2760. iotData.fault_codes = iot_data.fault_codes;
  2761. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2762. }
  2763. }
  2764. catch (Exception ex)
  2765. {
  2766. res = 0;
  2767. string str = ex.StackTrace;
  2768. AddMessage_Station(stationNameStr, LogType.Error,
  2769. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  2770. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2771. //写入PLC
  2772. IoT_DataSet_t iotData = new IoT_DataSet_t();
  2773. iotData.machineState = iot_data.machineState;
  2774. iotData.work_type = iot_data.work_type;
  2775. iotData.testStatus = iot_data.testStatus;
  2776. iotData.beatAction = iot_data.beatAction;
  2777. iotData.beatReturn = 2; //NG
  2778. iotData.fault_codes = iot_data.fault_codes;
  2779. (int, string) PLCresult = WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iotData);
  2780. }
  2781. }
  2782. /// <summary>
  2783. /// 去除常见特殊字符,如 \r, \n, \t 等
  2784. /// </summary>
  2785. /// <param name="format"></param>
  2786. /// <returns></returns>
  2787. private static string FormatStrbyPLC(string format)
  2788. {
  2789. string cleanedString = "";
  2790. if (!string.IsNullOrEmpty(format))
  2791. {
  2792. cleanedString = Regex.Replace(format, @"[\r\n\t]", "");
  2793. }
  2794. return cleanedString;
  2795. }
  2796. #endregion
  2797. #region S1
  2798. /// <summary>
  2799. /// [S1] 壳体清洁上料装备
  2800. /// </summary>
  2801. /// <param name="plcNo">PLC编号</param>
  2802. private void ReadStation_S1(int plcNo)
  2803. {
  2804. string stationCode = "[OP10]";
  2805. string stationName = "壳体清洁上料";
  2806. string stationNameStr = stationCode + stationName;
  2807. string tagBaseName = "g_OP10_MES"; //标签变量名称
  2808. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2809. string tagAgvCommName = "agvCommFrmPC";
  2810. string tagiotComnName = "iotData";
  2811. string tagBarsetName = "BarcodeSet";
  2812. string CarrierBarcode = "";
  2813. string ProductBarcode = "";
  2814. // 触发信号字典
  2815. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2816. s1PLCSignal_Old.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2817. // PLC数据字典 赋值
  2818. s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  2819. s1PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  2820. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  2821. (int, string) result;
  2822. while (true)
  2823. {
  2824. try
  2825. {
  2826. if (!GlobalContext._IsCon_Funs1)
  2827. {
  2828. UpdatePLCMonitor(1, plcNo, 0);
  2829. continue;
  2830. }
  2831. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2832. {
  2833. Stopwatch stopwatch1 = new Stopwatch();
  2834. Stopwatch stopwatch2 = new Stopwatch();
  2835. stopwatch1.Start();
  2836. stopwatch2.Start();
  2837. #region 一次性读取所有数据
  2838. // 一次性读取所有数据
  2839. result = FunsEip[plcNo]
  2840. .Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2841. if (result.Item1 != 0)
  2842. {
  2843. //richTextBox1.AppendText("\n" + strRet);
  2844. }
  2845. else
  2846. {
  2847. //richTextBox1.AppendText("\n" + "读取成功");
  2848. stPLC_MesData.BarcodeSet.strProductBarcode =
  2849. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  2850. stPLC_MesData.BarcodeSet.strPartBarcode =
  2851. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  2852. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  2853. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  2854. stPLC_MesData.BarcodeSet.strPCBBarcode =
  2855. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  2856. //设备状态
  2857. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  2858. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  2859. ? XiaomiDeviceState.Unknown
  2860. : (XiaomiDeviceState)xmDeviceStateInt;
  2861. // 载具SN
  2862. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode.ToString();
  2863. // 物料码(物料码还未绑定载具SN时必填)
  2864. ProductBarcode = stPLC_MesData.BarcodeSet.strProductBarcode;
  2865. // 节拍
  2866. s1PLCData["a1OEEType"] = stPLC_MesData.iotData.beatAction;
  2867. //报警信息
  2868. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  2869. }
  2870. #endregion 一次性读取所有数据
  2871. stopwatch2.Stop();
  2872. #region 进站
  2873. try
  2874. {
  2875. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2876. {
  2877. lock (lockObj)
  2878. {
  2879. if (!ProgressState)
  2880. {
  2881. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  2882. ProgressState = true;
  2883. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData,
  2884. tagBaseName + "." + tagMesCommName, out ProgressState));
  2885. }
  2886. }
  2887. }
  2888. }
  2889. catch (Exception ex)
  2890. {
  2891. ProgressState = false;
  2892. string str = ex.StackTrace;
  2893. AddMessage_Station(stationNameStr, LogType.Error,
  2894. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2895. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2896. }
  2897. #endregion 进站
  2898. #region 出站
  2899. try
  2900. {
  2901. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2902. {
  2903. lock (lockObj)
  2904. {
  2905. if (!ProgressState)
  2906. {
  2907. ProgressState = true;
  2908. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData,
  2909. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  2910. out ProgressState));
  2911. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  2912. }
  2913. }
  2914. }
  2915. }
  2916. catch (Exception ex)
  2917. {
  2918. ProgressState = false;
  2919. string str = ex.StackTrace;
  2920. AddMessage_Station(stationNameStr, LogType.Error,
  2921. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  2922. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2923. }
  2924. #endregion 出站
  2925. #region 节拍接口
  2926. try
  2927. {
  2928. if (stPLC_MesData.iotData.beatAction > 0)
  2929. {
  2930. int a1OEEType = Convert.ToInt32(s1PLCData["a1OEEType"]);
  2931. int a1OEETypeGOld = Convert.ToInt32(s1PLCSignal_Old["a1OEEType"]);
  2932. if (a1OEEType != a1OEETypeGOld)
  2933. {
  2934. s1PLCData["OEETypeFlag"] = "1";
  2935. }
  2936. else
  2937. {
  2938. s1PLCData["OEETypeFlag"] = "0";
  2939. }
  2940. if (s1PLCData["OEETypeFlag"].ToString() == "1" && (a1OEEType == 1 || a1OEEType == 3 || a1OEEType == 4 || a1OEEType == 5))
  2941. {
  2942. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  2943. if (res == 1)
  2944. {
  2945. s1PLCSignal_Old["a1OEEType"] = s1PLCData["a1OEEType"];
  2946. }
  2947. else {
  2948. s1PLCSignal_Old["a1OEEType"] = 0;
  2949. }
  2950. }
  2951. }
  2952. else {
  2953. s1PLCSignal_Old["a1OEEType"] = 0;
  2954. }
  2955. }
  2956. catch (Exception ex)
  2957. {
  2958. string str = ex.StackTrace;
  2959. AddMessage_Station(stationNameStr, LogType.Error,
  2960. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  2961. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2962. }
  2963. #endregion
  2964. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2965. stopwatch1.Stop();
  2966. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2967. }
  2968. else
  2969. {
  2970. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2971. AddMessage_Station(stationNameStr, LogType.Info,
  2972. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2973. FunsEip[plcNo].Connect(); // 重连
  2974. }
  2975. }
  2976. catch (Exception ex)
  2977. {
  2978. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2979. AddMessage_Station(stationNameStr, LogType.Error,
  2980. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2981. }
  2982. Thread.Sleep(IntervalReadPLC);
  2983. }
  2984. }
  2985. /// <summary>
  2986. /// [S1] 壳体清洁上料 - 进站
  2987. /// </summary>
  2988. /// <param name="plcNo">PLC编号</param>
  2989. /// <param name="stationNameStr">工站全称</param>
  2990. /// <param name="stPLC_MesData"></param>
  2991. /// <param name="tagMesCommName"></param>
  2992. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  2993. out bool ProgressState)
  2994. {
  2995. Stopwatch stopwatch1 = new Stopwatch();
  2996. Stopwatch stopwatch2 = new Stopwatch();
  2997. try
  2998. {
  2999. stopwatch1.Start();
  3000. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3001. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  3002. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3003. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  3004. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  3005. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3006. bool pass = a1Result == 1;
  3007. if (string.IsNullOrEmpty(sn))
  3008. {
  3009. ProgressState = false;
  3010. AddMessage(LogType.Error, $"{stationNameStr}_未能查到产品码");
  3011. Thread.Sleep(10000);
  3012. return;
  3013. }
  3014. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  3015. // sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  3016. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3017. //绑定载具和产品
  3018. ResponseMessage message = new ResponseMessage();
  3019. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  3020. if (message.result == false)
  3021. {
  3022. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  3023. ProgressState = false;
  3024. Thread.Sleep(10000);
  3025. return;
  3026. }
  3027. // 产品SN进站
  3028. List<TestItem> item = new List<TestItem>();
  3029. stopwatch2.Start();
  3030. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3031. item, MachineId, StationId, pass, "01-SLOT-01");
  3032. stopwatch2.Stop();
  3033. //指令执行结果 1:OK 110:失败
  3034. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3035. if (mesResultFrmWeb == 1)
  3036. {
  3037. if (a1Result == 1)
  3038. {
  3039. mesResultFrmWeb = 1;
  3040. }
  3041. else
  3042. {
  3043. mesResultFrmWeb = 110;
  3044. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3045. }
  3046. }
  3047. //进站结果写入PLC
  3048. CommandFromPLC resultToPlC = new CommandFromPLC();
  3049. resultToPlC.cmd = 0;
  3050. resultToPlC.cmdParam = 0;
  3051. resultToPlC.cmdResult = mesResultFrmWeb;
  3052. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3053. }
  3054. catch (Exception ex)
  3055. {
  3056. string str = ex.StackTrace;
  3057. AddMessage(LogType.Error,
  3058. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3059. str.Length - str.LastIndexOf("\\") - 1));
  3060. CommandFromPLC resultToPlC = new CommandFromPLC();
  3061. resultToPlC.cmd = 0;
  3062. resultToPlC.cmdParam = 0; //指令参数
  3063. resultToPlC.cmdResult = 110;
  3064. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3065. }
  3066. stopwatch1.Stop();
  3067. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3068. AddMessage(LogType.Info,
  3069. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3070. stopwatch2.ElapsedMilliseconds + "ms");
  3071. ProgressState = false;
  3072. }
  3073. /// <summary>
  3074. /// [S1] 壳体清洁上料 - 出站接口
  3075. /// </summary>
  3076. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
  3077. string stationCode, string stationName, out bool ProgressState)
  3078. {
  3079. Stopwatch stopwatch1 = new Stopwatch();
  3080. Stopwatch stopwatch2 = new Stopwatch();
  3081. test_item_num = 0; //iot 过站明细序号
  3082. try
  3083. {
  3084. stopwatch1.Start();
  3085. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3086. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3087. string processItem = stationName; // 项目
  3088. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3089. string supplierCode = ""; // 供应商代码
  3090. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  3091. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  3092. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  3093. string sn = string.Empty;
  3094. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3095. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  3096. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  3097. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3098. //a1Result = 1;
  3099. bool pass = a1Result == 1;
  3100. //根据载具码获取产品码
  3101. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3102. if (string.IsNullOrEmpty(strProductBarcode))
  3103. {
  3104. ProgressState = false;
  3105. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3106. Thread.Sleep(10000);
  3107. return;
  3108. }
  3109. sn = strProductBarcode;
  3110. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3111. List<TestItem> items = new List<TestItem>();
  3112. items.Add(new TestItem()
  3113. {
  3114. Parameter_name = "载具码",
  3115. Parameter_value = CarrierBarcode,
  3116. Parameter_unit = ""
  3117. });
  3118. items.Add(new TestItem()
  3119. {
  3120. Parameter_name = "产品码",
  3121. Parameter_value = sn,
  3122. Parameter_unit = ""
  3123. });
  3124. #region 转换过站明细字符串
  3125. //创建字典
  3126. var dic = new Dictionary<string, string>();
  3127. // 获取结构体类型
  3128. FieldInfo[] fields = typeof(OP10_DataSet_t).GetFields();
  3129. // 遍历变量名转换成字典描述
  3130. foreach (FieldInfo field in fields)
  3131. {
  3132. //获取枚举描述
  3133. string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name,
  3134. typeof(XiaomiMESEnum_ProcessData.Enum_10_ProcessData));
  3135. //获取过站明细的值
  3136. object valueObj = field.GetValue(stPLC_MesData.mesData);
  3137. dic.Add(name, valueObj.ToString());
  3138. }
  3139. string paramJson = JsonConvert.SerializeObject(dic);
  3140. #endregion
  3141. //出站接口
  3142. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3143. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  3144. MachineId, StationId, "", paramJson);
  3145. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3146. if (mesResultFrmWeb == 1)
  3147. {
  3148. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3149. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  3150. }
  3151. stopwatch2.Start();
  3152. //进站结果写入PLC
  3153. CommandFromPLC resultToPlC = new CommandFromPLC();
  3154. resultToPlC.cmd = 0;
  3155. resultToPlC.cmdParam = 0; //指令参数
  3156. resultToPlC.cmdResult = mesResultFrmWeb;
  3157. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3158. stopwatch2.Stop();
  3159. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3160. //保存PLC返回MES数据到本地
  3161. ResponseMessage message = new ResponseMessage();
  3162. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  3163. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress,
  3164. stPLC_MesData.mesData.fCleanSpeed,
  3165. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime,
  3166. stPLC_MesData.mesData.nCleanCount,
  3167. stPLC_MesData.mesData.nRemainCount);
  3168. if (message.result == false)
  3169. {
  3170. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3171. }
  3172. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  3173. }
  3174. catch (Exception ex)
  3175. {
  3176. stopwatch2.Start();
  3177. CommandFromPLC resultToPlC = new CommandFromPLC();
  3178. resultToPlC.cmd = 0;
  3179. resultToPlC.cmdParam = 0; //指令参数
  3180. resultToPlC.cmdResult = 110;
  3181. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3182. stopwatch2.Stop();
  3183. string str = ex.StackTrace;
  3184. AddMessage(LogType.Error,
  3185. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3186. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3187. }
  3188. stopwatch1.Stop();
  3189. AddMessage(LogType.Info,
  3190. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3191. stopwatch2.ElapsedMilliseconds + "ms");
  3192. ProgressState = false;
  3193. uuid = "";
  3194. }
  3195. #endregion
  3196. #region S2
  3197. /// <summary>
  3198. /// [S2] 上盖板上料装备
  3199. /// </summary>
  3200. /// <param name="plcNo">PLC编号</param>
  3201. private void ReadStation_S2(int plcNo)
  3202. {
  3203. string stationCode = "[OP20]";
  3204. string stationName = "上盖板上料装备";
  3205. string stationNameStr = stationCode + stationName;
  3206. string tagBaseName = "g_OP20_MES"; //标签变量名称
  3207. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3208. string tagAgvCommName = "agvCommFrmPC";
  3209. string tagiotComnName = "iotData";
  3210. string tagBarsetName = "BarcodeSet";
  3211. string CarrierBarcode = "";
  3212. // 触发信号字典
  3213. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  3214. s2PLCSignal_Old.Add("a2OEEType", 0); // 节拍类型(plc写入)
  3215. // PLC数据字典 赋值
  3216. s2PLCData.Add("a2OEEType", 0); // 节拍类型(plc写入)
  3217. s2PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  3218. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  3219. (int, string) result;
  3220. while (true)
  3221. {
  3222. try
  3223. {
  3224. if (!GlobalContext._IsCon_Funs2)
  3225. {
  3226. UpdatePLCMonitor(1, plcNo, 0);
  3227. continue;
  3228. }
  3229. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3230. {
  3231. Stopwatch stopwatch1 = new Stopwatch();
  3232. Stopwatch stopwatch2 = new Stopwatch();
  3233. stopwatch1.Start();
  3234. stopwatch2.Start();
  3235. #region 一次性读取所有数据
  3236. // 一次性读取所有数据
  3237. result = FunsEip[plcNo]
  3238. .Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3239. if (result.Item1 != 0)
  3240. {
  3241. //richTextBox1.AppendText("\n" + strRet);
  3242. }
  3243. else
  3244. {
  3245. //richTextBox1.AppendText("\n" + "读取成功");
  3246. stPLC_MesData.BarcodeSet.strProductBarcode =
  3247. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  3248. stPLC_MesData.BarcodeSet.strPartBarcode =
  3249. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  3250. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  3251. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  3252. stPLC_MesData.BarcodeSet.strPCBBarcode =
  3253. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  3254. //设备状态
  3255. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  3256. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  3257. ? XiaomiDeviceState.Unknown
  3258. : (XiaomiDeviceState)xmDeviceStateInt;
  3259. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  3260. s2PLCData["a2OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  3261. //报警信息
  3262. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  3263. }
  3264. #endregion 一次性读取所有数据
  3265. stopwatch2.Stop();
  3266. #region 进站
  3267. try
  3268. {
  3269. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3270. {
  3271. lock (lockObj)
  3272. {
  3273. if (!ProgressState)
  3274. {
  3275. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3276. ProgressState = true;
  3277. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData,
  3278. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  3279. out ProgressState));
  3280. }
  3281. }
  3282. }
  3283. }
  3284. catch (Exception ex)
  3285. {
  3286. ProgressState = false;
  3287. string str = ex.StackTrace;
  3288. AddMessage_Station(stationNameStr, LogType.Error,
  3289. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3290. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3291. }
  3292. #endregion 进站
  3293. #region 出站
  3294. try
  3295. {
  3296. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3297. {
  3298. lock (lockObj)
  3299. {
  3300. if (!ProgressState)
  3301. {
  3302. ProgressState = true;
  3303. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData,
  3304. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  3305. out ProgressState));
  3306. stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
  3307. }
  3308. }
  3309. }
  3310. }
  3311. catch (Exception ex)
  3312. {
  3313. ProgressState = false;
  3314. string str = ex.StackTrace;
  3315. AddMessage_Station(stationNameStr, LogType.Error,
  3316. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3317. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3318. }
  3319. #endregion 出站
  3320. #region 节拍接口
  3321. try
  3322. {
  3323. if (stPLC_MesData.iotData.beatAction > 0)
  3324. {
  3325. int a2OEEType = Convert.ToInt32(s2PLCData["a2OEEType"]);
  3326. int a2OEETypeGOld = Convert.ToInt32(s2PLCSignal_Old["a2OEEType"]);
  3327. if (a2OEEType != a2OEETypeGOld)
  3328. {
  3329. s2PLCData["OEETypeFlag"] = "1";
  3330. }
  3331. else
  3332. {
  3333. s2PLCData["OEETypeFlag"] = "0";
  3334. }
  3335. if (s2PLCData["OEETypeFlag"].ToString() == "1" && (a2OEEType == 1 || a2OEEType == 3 || a2OEEType == 4 || a2OEEType == 5))
  3336. {
  3337. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  3338. if (res == 1)
  3339. {
  3340. s2PLCSignal_Old["a2OEEType"] = s2PLCData["a2OEEType"];
  3341. }
  3342. else
  3343. {
  3344. s2PLCSignal_Old["a2OEEType"] = 0;
  3345. }
  3346. }
  3347. }
  3348. else {
  3349. s2PLCSignal_Old["a2OEEType"] = 0;
  3350. }
  3351. }
  3352. catch (Exception ex)
  3353. {
  3354. string str = ex.StackTrace;
  3355. AddMessage_Station(stationNameStr, LogType.Error,
  3356. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3357. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3358. }
  3359. #endregion
  3360. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3361. stopwatch1.Stop();
  3362. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  3363. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3364. }
  3365. else
  3366. {
  3367. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3368. AddMessage_Station(stationNameStr, LogType.Info,
  3369. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3370. FunsEip[plcNo].Connect();
  3371. }
  3372. }
  3373. catch (Exception ex)
  3374. {
  3375. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3376. AddMessage_Station(stationNameStr, LogType.Error,
  3377. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3378. //Funs[plcNo].ReConnect();
  3379. }
  3380. Thread.Sleep(IntervalReadPLC);
  3381. }
  3382. }
  3383. /// <summary>
  3384. /// [S2] 上盖板上料装备
  3385. /// </summary>
  3386. /// <param name="plcNo">PLC编号</param>
  3387. /// <param name="stationNameStr">工站全称</param>
  3388. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  3389. string tagBarsetName, out bool ProgressState)
  3390. {
  3391. Stopwatch stopwatch1 = new Stopwatch();
  3392. Stopwatch stopwatch2 = new Stopwatch();
  3393. try
  3394. {
  3395. stopwatch1.Start();
  3396. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3397. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  3398. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  3399. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3400. bool pass = a1Result == 1;
  3401. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  3402. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  3403. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3404. //根据载具码获取产品码
  3405. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3406. if (string.IsNullOrEmpty(strProductBarcode))
  3407. {
  3408. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3409. ProgressState = false;
  3410. Thread.Sleep(10000);
  3411. return;
  3412. }
  3413. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  3414. //if (sn != strProductBarcode)
  3415. //{
  3416. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  3417. //}
  3418. sn = strProductBarcode;
  3419. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3420. // 产品SN(物料码)校验
  3421. List<TestItem> item = new List<TestItem>();
  3422. stopwatch2.Start();
  3423. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3424. item, MachineId, StationId, pass, "01-SLOT-01");
  3425. stopwatch2.Stop();
  3426. //指令执行结果 1:OK 110:失败
  3427. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3428. if (mesResultFrmWeb == 1)
  3429. {
  3430. if (a1Result == 1)
  3431. {
  3432. mesResultFrmWeb = 1;
  3433. }
  3434. else
  3435. {
  3436. mesResultFrmWeb = 110;
  3437. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3438. }
  3439. }
  3440. //进站结果写入PLC
  3441. CommandFromPLC resultToPlC = new CommandFromPLC();
  3442. resultToPlC.cmd = 0;
  3443. resultToPlC.cmdParam = 0; //指令参数
  3444. resultToPlC.cmdResult = mesResultFrmWeb;
  3445. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3446. }
  3447. catch (Exception ex)
  3448. {
  3449. string str = ex.StackTrace;
  3450. AddMessage(LogType.Error,
  3451. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3452. str.Length - str.LastIndexOf("\\") - 1));
  3453. CommandFromPLC resultToPlC = new CommandFromPLC();
  3454. resultToPlC.cmd = 0;
  3455. resultToPlC.cmdParam = 0; //指令参数
  3456. resultToPlC.cmdResult = 110;
  3457. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3458. }
  3459. stopwatch1.Stop();
  3460. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3461. AddMessage(LogType.Info,
  3462. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3463. stopwatch2.ElapsedMilliseconds + "ms");
  3464. ProgressState = false;
  3465. }
  3466. /// <summary>
  3467. /// [S2] 上盖板上料装备 - 出站接口
  3468. /// </summary>
  3469. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
  3470. string stationCode, string stationName, out bool ProgressState)
  3471. {
  3472. Stopwatch stopwatch1 = new Stopwatch();
  3473. Stopwatch stopwatch2 = new Stopwatch();
  3474. test_item_num = 0; //iot 过站明细序号
  3475. try
  3476. {
  3477. stopwatch1.Start();
  3478. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3479. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3480. string processItem = stationName; // 测试项目
  3481. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3482. string supplierCode = ""; // 供应商代码
  3483. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3484. string batch_num = GlobalContext.BatchNumber; // 批次号
  3485. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3486. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3487. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3488. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  3489. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  3490. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  3491. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3492. bool pass = a1Result == 1;
  3493. //根据载具码获取产品码
  3494. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3495. if (string.IsNullOrEmpty(strProductBarcode))
  3496. {
  3497. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3498. ProgressState = false;
  3499. Thread.Sleep(10000);
  3500. return;
  3501. }
  3502. sn = strProductBarcode;
  3503. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3504. List<TestItem> items = new List<TestItem>();
  3505. items.Add(new TestItem()
  3506. {
  3507. Parameter_name = "载具码",
  3508. Parameter_value = CarrierBarcode,
  3509. Parameter_unit = ""
  3510. });
  3511. items.Add(new TestItem()
  3512. {
  3513. Parameter_name = "产品码",
  3514. Parameter_value = sn,
  3515. Parameter_unit = ""
  3516. });
  3517. items.Add(new TestItem()
  3518. {
  3519. Parameter_name = "部件码",
  3520. Parameter_value = PartBarcode,
  3521. Parameter_unit = ""
  3522. });
  3523. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  3524. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3525. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  3526. MachineId, StationId, PartBarcode, paramJson);
  3527. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3528. if (mesResultFrmWeb == 1)
  3529. {
  3530. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  3531. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  3532. }
  3533. stopwatch2.Start();
  3534. //进站结果写入PLC
  3535. CommandFromPLC resultToPlC = new CommandFromPLC();
  3536. resultToPlC.cmd = 0;
  3537. resultToPlC.cmdParam = 0; //指令参数
  3538. resultToPlC.cmdResult = mesResultFrmWeb;
  3539. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3540. stopwatch2.Stop();
  3541. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3542. //保存PLC返回MES数据到本地
  3543. ResponseMessage message = new ResponseMessage();
  3544. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  3545. stPLC_MesData.mesData.nRemainCount);
  3546. if (message.result == false)
  3547. {
  3548. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3549. }
  3550. if (!string.IsNullOrEmpty(PartBarcode))
  3551. {
  3552. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  3553. if (message.result == false)
  3554. {
  3555. AddMessage(LogType.Error, message.text);
  3556. }
  3557. }
  3558. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3559. }
  3560. catch (Exception ex)
  3561. {
  3562. stopwatch2.Start();
  3563. CommandFromPLC resultToPlC = new CommandFromPLC();
  3564. resultToPlC.cmd = 0;
  3565. resultToPlC.cmdParam = 0; //指令参数
  3566. resultToPlC.cmdResult = 110;
  3567. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3568. stopwatch2.Stop();
  3569. string str = ex.StackTrace;
  3570. AddMessage(LogType.Error,
  3571. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  3572. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3573. }
  3574. stopwatch1.Stop();
  3575. AddMessage(LogType.Info,
  3576. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  3577. stopwatch2.ElapsedMilliseconds + "ms");
  3578. ProgressState = false;
  3579. uuid = "";
  3580. }
  3581. #endregion
  3582. #region S3
  3583. /// <summary>
  3584. /// [S3] 点散热胶装备
  3585. /// </summary>
  3586. /// <param name="plcNo">PLC编号</param>
  3587. private void ReadStation_S3(int plcNo)
  3588. {
  3589. string stationCode = "[OP30]";
  3590. string stationName = "点散热胶装备";
  3591. string stationNameStr = stationCode + stationName;
  3592. string tagBaseName = "g_OP30_MES"; //标签变量名称
  3593. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3594. string tagAgvCommName = "agvCommFrmPC";
  3595. string tagiotComnName = "iotData";
  3596. string tagBarsetName = "BarcodeSet";
  3597. string CarrierBarcode_Left = "";
  3598. string CarrierBarcode_Right = "";
  3599. s3PLCSignal_Old.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
  3600. s3PLCSignal_Old.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
  3601. // PLC数据字典 赋值
  3602. s3PLCData.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
  3603. s3PLCData.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
  3604. s5PLCData.Add("OEETypeFlag_left", 0); // 节拍标识 0 不上传 ,1 上传
  3605. s5PLCData.Add("OEETypeFlag_right", 0); // 节拍标识 0 不上传 ,1 上传
  3606. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  3607. (int, string) result;
  3608. while (true)
  3609. {
  3610. try
  3611. {
  3612. if (!GlobalContext._IsCon_Funs2)
  3613. {
  3614. UpdatePLCMonitor(1, plcNo, 0);
  3615. continue;
  3616. }
  3617. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3618. {
  3619. Stopwatch stopwatch1 = new Stopwatch();
  3620. Stopwatch stopwatch2 = new Stopwatch();
  3621. stopwatch1.Start();
  3622. stopwatch2.Start();
  3623. #region 一次性读取所有数据
  3624. // 一次性读取所有数据
  3625. result = FunsEip[plcNo]
  3626. .Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3627. if (result.Item1 != 0)
  3628. {
  3629. //richTextBox1.AppendText("\n" + strRet);
  3630. }
  3631. else
  3632. {
  3633. //测试数据
  3634. //stPLC_MesData.Left.mesCommFrmPLC.cmd = 2;
  3635. //stPLC_MesData.Left.BarcodeSet.strCarrierBarcode = "A123456";
  3636. //stPLC_MesData.Left.BarcodeSet.strPCBBarcode = "A1507V000239";
  3637. //stPLC_MesData.Left.iotData.beatAction = 1;
  3638. //stPLC_MesData.Left.iotData.beatAction = 2;
  3639. //stPLC_MesData.Left.BarcodeSet.strCarrierBarcode = "A123456";
  3640. #region 去除扫码产生的特殊字符
  3641. stPLC_MesData.Left.BarcodeSet.strProductBarcode =
  3642. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strProductBarcode);
  3643. stPLC_MesData.Left.BarcodeSet.strPartBarcode =
  3644. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPartBarcode);
  3645. stPLC_MesData.Left.BarcodeSet.strCarrierBarcode =
  3646. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strCarrierBarcode);
  3647. stPLC_MesData.Left.BarcodeSet.strPCBBarcode =
  3648. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPCBBarcode);
  3649. stPLC_MesData.Right.BarcodeSet.strProductBarcode =
  3650. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strProductBarcode);
  3651. stPLC_MesData.Right.BarcodeSet.strPartBarcode =
  3652. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPartBarcode);
  3653. stPLC_MesData.Right.BarcodeSet.strCarrierBarcode =
  3654. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strCarrierBarcode);
  3655. stPLC_MesData.Right.BarcodeSet.strPCBBarcode =
  3656. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPCBBarcode);
  3657. #endregion
  3658. //richTextBox1.AppendText("\n" + "读取成功");
  3659. //设备状态
  3660. int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  3661. int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  3662. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  3663. ? XiaomiDeviceState.Unknown
  3664. : (XiaomiDeviceState)xmDeviceStateInt_L;
  3665. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  3666. ? XiaomiDeviceState.Unknown
  3667. : (XiaomiDeviceState)xmDeviceStateInt_R;
  3668. //载具SN
  3669. CarrierBarcode_Left = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode;
  3670. CarrierBarcode_Right = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode;
  3671. // 节拍
  3672. s3PLCData["a3OEEType_left"] = stPLC_MesData.Left.iotData.beatAction;
  3673. s3PLCData["a3OEEType_right"] = stPLC_MesData.Right.iotData.beatAction;
  3674. //报警信息
  3675. _FaultDatas = stPLC_MesData.Left.iotData.fault_codes;
  3676. _FaultDatas2 = stPLC_MesData.Right.iotData.fault_codes;
  3677. //_FaultDatas = new uint[] { 2, 0, 16, 0, 0, 0, 0, 0, 0, 0 };
  3678. //_FaultDatas2 = new uint[] { 2, 0, 16, 0, 0, 0, 0, 0, 0, 0 };
  3679. }
  3680. #endregion 一次性读取所有数据
  3681. stopwatch2.Stop();
  3682. #region 左边进站
  3683. try
  3684. {
  3685. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3686. {
  3687. lock (lockObj)
  3688. {
  3689. if (!ProgressState)
  3690. {
  3691. stationCode = "[OP31]";
  3692. stationName = "点散热胶装备1";
  3693. stationNameStr = stationCode + stationName;
  3694. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3695. ProgressState = true;
  3696. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left,
  3697. tagBaseName + ".Left." + tagMesCommName,
  3698. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  3699. }
  3700. }
  3701. }
  3702. }
  3703. catch (Exception ex)
  3704. {
  3705. ProgressState = false;
  3706. string str = ex.StackTrace;
  3707. AddMessage_Station(stationNameStr, LogType.Error,
  3708. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3709. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3710. }
  3711. #endregion 左边进站
  3712. #region 左边出站
  3713. try
  3714. {
  3715. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3716. {
  3717. lock (lockObj)
  3718. {
  3719. if (!ProgressState)
  3720. {
  3721. stationCode = "[OP31]";
  3722. stationName = "点散热胶装备1";
  3723. stationNameStr = stationCode + stationName;
  3724. ProgressState = true;
  3725. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left,
  3726. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  3727. out ProgressState));
  3728. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  3729. }
  3730. }
  3731. }
  3732. }
  3733. catch (Exception ex)
  3734. {
  3735. ProgressState = false;
  3736. string str = ex.StackTrace;
  3737. AddMessage_Station(stationNameStr, LogType.Error,
  3738. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3739. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3740. }
  3741. #endregion 左边出站
  3742. #region 右边进站
  3743. try
  3744. {
  3745. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3746. {
  3747. lock (lockObj)
  3748. {
  3749. if (!ProgressState)
  3750. {
  3751. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  3752. stationCode = "[OP32]";
  3753. stationName = "点散热胶装备2";
  3754. stationNameStr = stationCode + stationName;
  3755. ProgressState = true;
  3756. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right,
  3757. tagBaseName + ".Right." + tagMesCommName,
  3758. tagBaseName + ".Right." + tagBarsetName, "Right", out ProgressState));
  3759. }
  3760. }
  3761. }
  3762. }
  3763. catch (Exception ex)
  3764. {
  3765. ProgressState = false;
  3766. string str = ex.StackTrace;
  3767. AddMessage_Station(stationNameStr, LogType.Error,
  3768. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3769. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3770. }
  3771. #endregion 右边进站
  3772. #region 右边出站
  3773. try
  3774. {
  3775. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3776. {
  3777. lock (lockObj)
  3778. {
  3779. if (!ProgressState)
  3780. {
  3781. stationCode = "[OP32]";
  3782. stationName = "点散热胶装备2";
  3783. stationNameStr = stationCode + stationName;
  3784. ProgressState = true;
  3785. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right,
  3786. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  3787. out ProgressState));
  3788. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  3789. }
  3790. }
  3791. }
  3792. }
  3793. catch (Exception ex)
  3794. {
  3795. string str = ex.StackTrace;
  3796. AddMessage_Station(stationNameStr, LogType.Error,
  3797. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  3798. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3799. }
  3800. #endregion 右边出站
  3801. #region 节拍接口
  3802. try
  3803. {
  3804. #region 左工位 节拍
  3805. if (stPLC_MesData.Left.iotData.beatAction > 0)
  3806. {
  3807. stationCode = "[OP31]";
  3808. stationName = "点散热胶装备1";
  3809. stationNameStr = stationCode + stationName;
  3810. int a3OEEType_left = Convert.ToInt32(s3PLCData["a3OEEType_left"]);
  3811. int a3OEETypeGOld_left = Convert.ToInt32(s3PLCSignal_Old["a3OEEType_left"]);
  3812. if (a3OEEType_left != a3OEETypeGOld_left)
  3813. {
  3814. s3PLCData["OEETypeFlag_left"] = "1";
  3815. }
  3816. else
  3817. {
  3818. s3PLCData["OEETypeFlag_left"] = "0";
  3819. }
  3820. if (s3PLCData["OEETypeFlag_left"].ToString() == "1" && (a3OEEType_left == 1 || a3OEEType_left == 3 || a3OEEType_left == 4 || a3OEEType_left == 5))
  3821. {
  3822. 通用节拍接口(plcNo, stationNameStr,
  3823. tagBaseName + ".Left." + tagiotComnName, CarrierBarcode_Left,
  3824. stPLC_MesData.Left.iotData, out res);
  3825. if (res == 1)
  3826. {
  3827. s3PLCSignal_Old["a3OEEType_left"] = a3OEEType_left;
  3828. }
  3829. else {
  3830. s3PLCSignal_Old["a3OEEType_left"] = 0;
  3831. }
  3832. }
  3833. }
  3834. else
  3835. {
  3836. s3PLCSignal_Old["a3OEEType_left"] = 0;
  3837. }
  3838. #endregion 左工位 节拍
  3839. #region 右工位 节拍
  3840. if (stPLC_MesData.Right.iotData.beatAction > 0)
  3841. {
  3842. stationCode = "[OP32]";
  3843. stationName = "点散热胶装备2";
  3844. stationNameStr = stationCode + stationName;
  3845. int a3OEEType_right = Convert.ToInt32(s3PLCData["a3OEEType_right"]);
  3846. int a3OEETypeGOld_right = Convert.ToInt32(s3PLCSignal_Old["a3OEEType_right"]);
  3847. if (a3OEEType_right != a3OEETypeGOld_right)
  3848. {
  3849. s3PLCData["OEETypeFlag_right"] = "1";
  3850. }
  3851. else
  3852. {
  3853. s3PLCData["OEETypeFlag_right"] = "0";
  3854. }
  3855. if (s3PLCData["OEETypeFlag_right"].ToString() == "1" && (a3OEEType_right == 1 || a3OEEType_right == 3 || a3OEEType_right == 4 || a3OEEType_right == 5))
  3856. {
  3857. 通用节拍接口(plcNo, stationNameStr,
  3858. tagBaseName + ".Right." + tagiotComnName, CarrierBarcode_Right,
  3859. stPLC_MesData.Right.iotData, out res);
  3860. if (res == 1)
  3861. {
  3862. s3PLCSignal_Old["a3OEEType_right"] = a3OEEType_right;
  3863. }
  3864. else {
  3865. s3PLCSignal_Old["a3OEEType_right"] = 0;
  3866. }
  3867. }
  3868. }
  3869. else
  3870. {
  3871. s3PLCSignal_Old["a3OEEType_right"] = 0;
  3872. }
  3873. #endregion 右工位 节拍
  3874. }
  3875. catch (Exception ex)
  3876. {
  3877. string str = ex.StackTrace;
  3878. AddMessage_Station(stationNameStr, LogType.Error,
  3879. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  3880. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3881. }
  3882. #endregion
  3883. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3884. stopwatch1.Stop();
  3885. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  3886. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3887. }
  3888. else
  3889. {
  3890. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3891. AddMessage_Station(stationNameStr, LogType.Info,
  3892. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3893. FunsEip[plcNo].Connect();
  3894. }
  3895. }
  3896. catch (Exception ex)
  3897. {
  3898. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3899. AddMessage_Station(stationNameStr, LogType.Error,
  3900. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3901. //Funs[plcNo].ReConnect();
  3902. }
  3903. Thread.Sleep(IntervalReadPLC);
  3904. }
  3905. }
  3906. /// <summary>
  3907. /// [S3] 点散热胶装备 - 进站
  3908. /// </summary>
  3909. /// <param name="plcNo">PLC编号</param>
  3910. /// <param name="stationNameStr">工站全称</param>
  3911. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  3912. string tagBarsetName, string direction, out bool ProgressState)
  3913. {
  3914. Stopwatch stopwatch1 = new Stopwatch();
  3915. Stopwatch stopwatch2 = new Stopwatch();
  3916. try
  3917. {
  3918. stopwatch1.Start();
  3919. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  3920. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3921. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  3922. string StationId = string.Empty;
  3923. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3924. bool pass = a1Result == 1;
  3925. string slot = "";
  3926. if (direction == "Left")
  3927. {
  3928. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  3929. slot = "01-SLOT-01";
  3930. }
  3931. if (direction == "Right")
  3932. {
  3933. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  3934. slot = "01-SLOT-02";
  3935. }
  3936. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3937. //载具码验证产品码
  3938. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3939. if (string.IsNullOrEmpty(strProductBarcode))
  3940. {
  3941. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  3942. ProgressState = false;
  3943. Thread.Sleep(10000);
  3944. return;
  3945. }
  3946. sn = strProductBarcode;
  3947. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  3948. // 产品SN(物料码)校验
  3949. List<TestItem> item = new List<TestItem>();
  3950. stopwatch2.Start();
  3951. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  3952. item, MachineId, StationId, pass, slot);
  3953. stopwatch2.Stop();
  3954. //指令执行结果 1:OK 110:失败
  3955. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3956. if (mesResultFrmWeb == 1)
  3957. {
  3958. if (a1Result == 1)
  3959. {
  3960. mesResultFrmWeb = 1;
  3961. }
  3962. else
  3963. {
  3964. mesResultFrmWeb = 110;
  3965. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  3966. }
  3967. }
  3968. //进站结果写入PLC
  3969. CommandFromPLC resultToPlC = new CommandFromPLC();
  3970. resultToPlC.cmd = 0;
  3971. resultToPlC.cmdParam = 0; //指令参数
  3972. resultToPlC.cmdResult = mesResultFrmWeb;
  3973. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3974. }
  3975. catch (Exception ex)
  3976. {
  3977. string str = ex.StackTrace;
  3978. AddMessage(LogType.Error,
  3979. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  3980. str.Length - str.LastIndexOf("\\") - 1));
  3981. CommandFromPLC resultToPlC = new CommandFromPLC();
  3982. resultToPlC.cmd = 0;
  3983. resultToPlC.cmdParam = 0; //指令参数
  3984. resultToPlC.cmdResult = 110;
  3985. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3986. }
  3987. stopwatch1.Stop();
  3988. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3989. AddMessage(LogType.Info,
  3990. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  3991. stopwatch2.ElapsedMilliseconds + "ms");
  3992. ProgressState = false;
  3993. }
  3994. /// <summary>
  3995. /// [S3] 点散热胶装备 - 出站
  3996. /// </summary>
  3997. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
  3998. string stationCode, string stationName, string direction, out bool ProgressState)
  3999. {
  4000. Stopwatch stopwatch1 = new Stopwatch();
  4001. Stopwatch stopwatch2 = new Stopwatch();
  4002. test_item_num = 0; //iot 过站明细序号
  4003. try
  4004. {
  4005. stopwatch1.Start();
  4006. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  4007. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4008. string processItem = stationName; // 测试项目
  4009. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4010. string supplierCode = ""; // 供应商代码
  4011. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4012. string batch_num = GlobalContext.BatchNumber; // 批次号
  4013. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4014. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4015. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4016. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  4017. string StationId = string.Empty;
  4018. if (direction == "Left")
  4019. {
  4020. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  4021. }
  4022. if (direction == "Right")
  4023. {
  4024. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  4025. }
  4026. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4027. bool pass = a1Result == 1;
  4028. //根据载具码获取产品码
  4029. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4030. if (string.IsNullOrEmpty(strProductBarcode))
  4031. {
  4032. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4033. ProgressState = false;
  4034. Thread.Sleep(10000);
  4035. return;
  4036. }
  4037. Console.WriteLine($"异常1:{strProductBarcode}");
  4038. sn = strProductBarcode;
  4039. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4040. List<TestItem> items = new List<TestItem>();
  4041. items.Add(new TestItem()
  4042. {
  4043. Parameter_name = "载具码",
  4044. Parameter_value = CarrierBarcode,
  4045. Parameter_unit = ""
  4046. });
  4047. items.Add(new TestItem()
  4048. {
  4049. Parameter_name = "产品码",
  4050. Parameter_value = sn,
  4051. Parameter_unit = ""
  4052. });
  4053. //if (direction == "Right")
  4054. //{
  4055. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData).Replace("null","0");
  4056. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4057. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  4058. MachineId, StationId, "", paramJson, direction);
  4059. //}
  4060. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4061. if (mesResultFrmWeb == 1)
  4062. {
  4063. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  4064. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  4065. }
  4066. stopwatch2.Start();
  4067. //进站结果写入PLC
  4068. CommandFromPLC resultToPlC = new CommandFromPLC();
  4069. resultToPlC.cmd = 0;
  4070. resultToPlC.cmdParam = 0; //指令参数
  4071. resultToPlC.cmdResult = mesResultFrmWeb;
  4072. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4073. stopwatch2.Stop();
  4074. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  4075. //保存PLC返回MES数据到本地
  4076. ResponseMessage message = new ResponseMessage();
  4077. if (direction == "Left")
  4078. {
  4079. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  4080. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  4081. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  4082. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  4083. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  4084. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  4085. if (message.result == false)
  4086. {
  4087. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4088. }
  4089. }
  4090. if (direction == "Right")
  4091. {
  4092. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  4093. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  4094. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  4095. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  4096. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  4097. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  4098. if (message.result == false)
  4099. {
  4100. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4101. }
  4102. }
  4103. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4104. }
  4105. catch (Exception ex)
  4106. {
  4107. stopwatch2.Start();
  4108. CommandFromPLC resultToPlC = new CommandFromPLC();
  4109. resultToPlC.cmd = 0;
  4110. resultToPlC.cmdParam = 0; //指令参数
  4111. resultToPlC.cmdResult = 110;
  4112. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4113. stopwatch2.Stop();
  4114. string str = ex.StackTrace;
  4115. AddMessage(LogType.Error,
  4116. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4117. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4118. }
  4119. stopwatch1.Stop();
  4120. AddMessage(LogType.Info,
  4121. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4122. stopwatch2.ElapsedMilliseconds + "ms");
  4123. ProgressState = false;
  4124. uuid = "";
  4125. }
  4126. #endregion S3
  4127. #region S4
  4128. /// <summary>
  4129. /// [S4] 点胶检测设备
  4130. /// </summary>
  4131. /// <param name="plcNo">PLC编号</param>
  4132. private void ReadStation_S4(int plcNo)
  4133. {
  4134. string stationCode = "[OP40]";
  4135. string stationName = "胶线检测";
  4136. string stationNameStr = stationCode + stationName;
  4137. string tagBaseName = "g_OP40_MES"; //标签变量名称
  4138. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4139. string tagAgvCommName = "agvCommFrmPC";
  4140. string tagiotComnName = "iotData";
  4141. string tagBarsetName = "BarcodeSet";
  4142. string CarrierBarcode = "";
  4143. // 触发信号字典
  4144. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4145. s4PLCSignal_Old.Add("a4OEEType", 0); // 节拍类型(plc写入)
  4146. // PLC数据字典 赋值
  4147. s4PLCData.Add("a4OEEType", 0); // 节拍类型(plc写入)
  4148. s4PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  4149. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  4150. (int, string) result;
  4151. while (true)
  4152. {
  4153. try
  4154. {
  4155. if (!GlobalContext._IsCon_Funs1)
  4156. {
  4157. UpdatePLCMonitor(1, plcNo, 0);
  4158. continue;
  4159. }
  4160. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4161. {
  4162. Stopwatch stopwatch1 = new Stopwatch();
  4163. Stopwatch stopwatch2 = new Stopwatch();
  4164. stopwatch1.Start();
  4165. stopwatch2.Start();
  4166. #region 一次性读取所有数据
  4167. // 一次性读取所有数据
  4168. result = FunsEip[plcNo]
  4169. .Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4170. if (result.Item1 != 0)
  4171. {
  4172. //richTextBox1.AppendText("\n" + strRet);
  4173. }
  4174. else
  4175. {
  4176. //去除扫码产生的特殊字符
  4177. stPLC_MesData.BarcodeSet.strProductBarcode =
  4178. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  4179. stPLC_MesData.BarcodeSet.strPartBarcode =
  4180. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  4181. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  4182. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  4183. stPLC_MesData.BarcodeSet.strPCBBarcode =
  4184. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  4185. //richTextBox1.AppendText("\n" + "读取成功");
  4186. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  4187. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  4188. ? XiaomiDeviceState.Unknown
  4189. : (XiaomiDeviceState)xmDeviceStateInt;
  4190. // 载具SN
  4191. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode;
  4192. // 节拍
  4193. s4PLCData["a4OEEType"] = stPLC_MesData.iotData.beatAction;
  4194. //报警信息
  4195. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  4196. }
  4197. #endregion 一次性读取所有数据
  4198. stopwatch2.Stop();
  4199. #region 进站
  4200. try
  4201. {
  4202. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4203. {
  4204. lock (lockObj)
  4205. {
  4206. if (!ProgressState)
  4207. {
  4208. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  4209. ProgressState = true;
  4210. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData,
  4211. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  4212. out ProgressState));
  4213. }
  4214. }
  4215. }
  4216. }
  4217. catch (Exception ex)
  4218. {
  4219. ProgressState = false;
  4220. string str = ex.StackTrace;
  4221. AddMessage_Station(stationNameStr, LogType.Error,
  4222. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4223. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4224. }
  4225. #endregion 进站
  4226. #region 出站
  4227. try
  4228. {
  4229. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4230. {
  4231. lock (lockObj)
  4232. {
  4233. if (!ProgressState)
  4234. {
  4235. ProgressState = true;
  4236. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData,
  4237. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4238. out ProgressState));
  4239. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4240. }
  4241. }
  4242. }
  4243. }
  4244. catch (Exception ex)
  4245. {
  4246. string str = ex.StackTrace;
  4247. AddMessage_Station(stationNameStr, LogType.Error,
  4248. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4249. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4250. }
  4251. #endregion 出站
  4252. #region 节拍接口
  4253. try
  4254. {
  4255. if (stPLC_MesData.iotData.beatAction > 0)
  4256. {
  4257. int a4OEEType = Convert.ToInt32(s4PLCData["a4OEEType"]);
  4258. int a4OEETypeGOld = Convert.ToInt32(s4PLCSignal_Old["a4OEEType"]);
  4259. //若设备紧急复原后节拍重置
  4260. if (a4OEEType == 1)
  4261. {
  4262. a4OEETypeGOld = 0;
  4263. }
  4264. if (a4OEEType != a4OEETypeGOld)
  4265. {
  4266. s4PLCData["OEETypeFlag"] = "1";
  4267. }
  4268. else
  4269. {
  4270. s4PLCData["OEETypeFlag"] = "0";
  4271. }
  4272. if (s4PLCData["OEETypeFlag"].ToString() == "1" && (a4OEEType == 1 || a4OEEType == 3 || a4OEEType == 4 || a4OEEType == 5))
  4273. {
  4274. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  4275. if (res == 1)
  4276. {
  4277. s4PLCSignal_Old["a4OEEType"] = s4PLCData["a4OEEType"];
  4278. }
  4279. else
  4280. {
  4281. s4PLCSignal_Old["a4OEEType"] = 0;
  4282. }
  4283. }
  4284. }
  4285. else {
  4286. s4PLCSignal_Old["a4OEEType"] = 0;
  4287. }
  4288. }
  4289. catch (Exception ex)
  4290. {
  4291. string str = ex.StackTrace;
  4292. AddMessage_Station(stationNameStr, LogType.Error,
  4293. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4294. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4295. }
  4296. #endregion
  4297. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4298. stopwatch1.Stop();
  4299. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4300. }
  4301. else
  4302. {
  4303. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4304. AddMessage_Station(stationNameStr, LogType.Info,
  4305. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4306. FunsEip[plcNo].Connect(); // 重连
  4307. }
  4308. }
  4309. catch (Exception ex)
  4310. {
  4311. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4312. AddMessage_Station(stationNameStr, LogType.Error,
  4313. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4314. }
  4315. Thread.Sleep(IntervalReadPLC);
  4316. }
  4317. }
  4318. /// <summary>
  4319. /// [S4] 点胶检测设备 - 进站
  4320. /// </summary>
  4321. /// <param name="plcNo">PLC编号</param>
  4322. /// <param name="stationNameStr">工站全称</param>
  4323. /// <param name="stPLC_MesData"></param>
  4324. /// <param name="tagMesCommName"></param>
  4325. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  4326. string tagBarsetName, out bool ProgressState)
  4327. {
  4328. Stopwatch stopwatch1 = new Stopwatch();
  4329. Stopwatch stopwatch2 = new Stopwatch();
  4330. test_item_num = 0; //iot 过站明细序号
  4331. try
  4332. {
  4333. stopwatch1.Start();
  4334. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4335. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4336. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  4337. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  4338. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4339. bool pass = a1Result == 1;
  4340. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  4341. //载具码验证产品码
  4342. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4343. if (string.IsNullOrEmpty(strProductBarcode))
  4344. {
  4345. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4346. ProgressState = false;
  4347. Thread.Sleep(10000);
  4348. return;
  4349. }
  4350. sn = strProductBarcode;
  4351. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4352. // 产品SN(物料码)校验
  4353. List<TestItem> item = new List<TestItem>();
  4354. stopwatch2.Start();
  4355. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  4356. item, MachineId, StationId, pass, "01-SLOT-01");
  4357. stopwatch2.Stop();
  4358. //指令执行结果 1:OK 110:失败
  4359. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4360. if (mesResultFrmWeb == 1)
  4361. {
  4362. if (a1Result == 1)
  4363. {
  4364. mesResultFrmWeb = 1;
  4365. }
  4366. else
  4367. {
  4368. mesResultFrmWeb = 110;
  4369. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  4370. }
  4371. }
  4372. //进站结果写入PLC
  4373. CommandFromPLC resultToPlC = new CommandFromPLC();
  4374. resultToPlC.cmd = 0;
  4375. resultToPlC.cmdParam = 0; //指令参数
  4376. resultToPlC.cmdResult = mesResultFrmWeb;
  4377. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4378. }
  4379. catch (Exception ex)
  4380. {
  4381. string str = ex.StackTrace;
  4382. AddMessage(LogType.Error,
  4383. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4384. str.Length - str.LastIndexOf("\\") - 1));
  4385. CommandFromPLC resultToPlC = new CommandFromPLC();
  4386. resultToPlC.cmd = 0;
  4387. resultToPlC.cmdParam = 0; //指令参数
  4388. resultToPlC.cmdResult = 110;
  4389. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4390. }
  4391. stopwatch1.Stop();
  4392. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4393. AddMessage(LogType.Info,
  4394. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4395. stopwatch2.ElapsedMilliseconds + "ms");
  4396. ProgressState = false;
  4397. }
  4398. /// <summary>
  4399. /// [S4] 点胶检测设备 - 出站接口
  4400. /// </summary>
  4401. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
  4402. string stationCode, string stationName, out bool ProgressState)
  4403. {
  4404. Stopwatch stopwatch1 = new Stopwatch();
  4405. Stopwatch stopwatch2 = new Stopwatch();
  4406. test_item_num = 0; //iot 过站明细序号
  4407. try
  4408. {
  4409. stopwatch1.Start();
  4410. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4411. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4412. string processItem = stationName; // 测试项目
  4413. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4414. string supplierCode = ""; // 供应商代码
  4415. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4416. string batch_num = GlobalContext.BatchNumber; // 批次号
  4417. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4418. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4419. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4420. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  4421. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  4422. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4423. bool pass = a1Result == 1;
  4424. //根据载具码获取产品码
  4425. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4426. if (string.IsNullOrEmpty(strProductBarcode))
  4427. {
  4428. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4429. ProgressState = false;
  4430. Thread.Sleep(10000);
  4431. return;
  4432. }
  4433. sn = strProductBarcode;
  4434. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4435. List<TestItem> items = new List<TestItem>();
  4436. items.Add(new TestItem()
  4437. {
  4438. Parameter_name = "载具码",
  4439. Parameter_value = CarrierBarcode,
  4440. Parameter_unit = ""
  4441. });
  4442. items.Add(new TestItem()
  4443. {
  4444. Parameter_name = "产品码",
  4445. Parameter_value = sn,
  4446. Parameter_unit = ""
  4447. });
  4448. #region 上传图片
  4449. if (GlobalContext.MQTTIsSendUpFile)
  4450. {
  4451. string[] urlarry = GlobalContext.UpFilePath.Split(",");
  4452. fileUploadData.fileData.Clear();
  4453. foreach (var item in urlarry)
  4454. {
  4455. if (!string.IsNullOrEmpty(item))
  4456. {
  4457. //上传图片
  4458. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName, a1Result,
  4459. item, uuid).Result;
  4460. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  4461. }
  4462. }
  4463. }
  4464. #endregion
  4465. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4466. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4467. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode,
  4468. "01-SLOT-01", MachineId, StationId, "", paramJson);
  4469. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4470. if (mesResultFrmWeb == 1)
  4471. {
  4472. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  4473. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  4474. }
  4475. stopwatch2.Start();
  4476. //进站结果写入PLC
  4477. CommandFromPLC resultToPlC = new CommandFromPLC();
  4478. resultToPlC.cmd = 0;
  4479. resultToPlC.cmdParam = 0; //指令参数
  4480. resultToPlC.cmdResult = mesResultFrmWeb;
  4481. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4482. stopwatch2.Stop();
  4483. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4484. //保存PLC返回MES数据到本地
  4485. ResponseMessage message = new ResponseMessage();
  4486. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  4487. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  4488. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  4489. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  4490. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  4491. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  4492. if (message.result == false)
  4493. {
  4494. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4495. }
  4496. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4497. }
  4498. catch (Exception ex)
  4499. {
  4500. stopwatch2.Start();
  4501. CommandFromPLC resultToPlC = new CommandFromPLC();
  4502. resultToPlC.cmd = 0;
  4503. resultToPlC.cmdParam = 0; //指令参数
  4504. resultToPlC.cmdResult = 110;
  4505. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4506. stopwatch2.Stop();
  4507. string str = ex.StackTrace;
  4508. AddMessage(LogType.Error,
  4509. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4510. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4511. }
  4512. stopwatch1.Stop();
  4513. AddMessage(LogType.Info,
  4514. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4515. stopwatch2.ElapsedMilliseconds + "ms");
  4516. ProgressState = false;
  4517. uuid = "";
  4518. }
  4519. #endregion
  4520. #region S5
  4521. private static bool isPCBStation = false; //控制PCB是否进出站的标识
  4522. /// <summary>
  4523. /// [S5] 点胶检测设备
  4524. /// </summary>
  4525. /// <param name="plcNo">PLC编号</param>
  4526. private void ReadStation_S5(int plcNo)
  4527. {
  4528. string stationCode = "[OP50]";
  4529. string stationName = "ADD板上料组装装备";
  4530. string stationNameStr = stationCode + stationName;
  4531. string tagBaseName = "g_OP50_MES"; //标签变量名称
  4532. string tagMesCommName = "mesCommToPC"; //标签变量名称
  4533. string tagAgvCommName = "agvCommFrmPC";
  4534. string tagiotComnName = "iotData";
  4535. string tagBarsetName = "BarcodeSet";
  4536. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  4537. string CarrierBarcode = "";
  4538. // 触发信号字典
  4539. s5PLCSignal_Old.Add("a5OEEType", 0); // 节拍类型(plc写入)
  4540. // PLC数据字典 赋值
  4541. s5PLCData.Add("a5OEEType", 0); // 节拍类型(plc写入)
  4542. s5PLCData.Add("OEETypeFlag", 0); // 节拍标识 0 不上传 ,1 上传
  4543. (int, string) result;
  4544. while (true)
  4545. {
  4546. try
  4547. {
  4548. if (!GlobalContext._IsCon_Funs1)
  4549. {
  4550. UpdatePLCMonitor(1, plcNo, 0);
  4551. continue;
  4552. }
  4553. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  4554. {
  4555. Stopwatch stopwatch1 = new Stopwatch();
  4556. Stopwatch stopwatch2 = new Stopwatch();
  4557. stopwatch1.Start();
  4558. stopwatch2.Start();
  4559. #region 一次性读取所有数据
  4560. // 一次性读取所有数据
  4561. result = FunsEip[plcNo]
  4562. .Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  4563. if (result.Item1 != 0)
  4564. {
  4565. }
  4566. else
  4567. {
  4568. //测试数据
  4569. //stPLC_MesData.mesCommFrmPLC.cmd = 2;
  4570. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
  4571. //stPLC_MesData.BarcodeSet.strPCBBarcode = "A1507V000239";
  4572. //stPLC_MesData.iotData.beatAction = 1;
  4573. //stPLC_MesData.iotData.beatAction = 2;
  4574. //stPLC_MesData.iotData.beatAction = 3;
  4575. //stPLC_MesData.iotData.beatAction = 4;
  4576. //stPLC_MesData.iotData.beatAction = 5;
  4577. //stPLC_MesData.iotData.beatAction = 6;
  4578. //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
  4579. #region 去除扫码产生的特殊字符
  4580. stPLC_MesData.BarcodeSet.strProductBarcode =
  4581. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  4582. stPLC_MesData.BarcodeSet.strPartBarcode =
  4583. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  4584. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  4585. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  4586. stPLC_MesData.BarcodeSet.strPCBBarcode =
  4587. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  4588. #endregion
  4589. //richTextBox1.AppendText("\n" + "读取成功");
  4590. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  4591. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  4592. ? XiaomiDeviceState.Unknown
  4593. : (XiaomiDeviceState)xmDeviceStateInt;
  4594. // 节拍
  4595. s5PLCData["a5OEEType"] = stPLC_MesData.iotData.beatAction;
  4596. //载具码
  4597. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode.ToString();
  4598. //报警信息
  4599. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  4600. }
  4601. #endregion 一次性读取所有数据
  4602. stopwatch2.Stop();
  4603. #region 进站
  4604. try
  4605. {
  4606. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  4607. {
  4608. lock (lockObj)
  4609. {
  4610. if (!ProgressState)
  4611. {
  4612. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  4613. ProgressState = true;
  4614. string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
  4615. if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
  4616. {
  4617. ProgressState = true;
  4618. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData,
  4619. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  4620. out ProgressState));
  4621. }
  4622. }
  4623. }
  4624. }
  4625. }
  4626. catch (Exception ex)
  4627. {
  4628. ProgressState = false;
  4629. string str = ex.StackTrace;
  4630. AddMessage_Station(stationNameStr, LogType.Error,
  4631. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4632. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4633. }
  4634. #endregion 进站
  4635. #region 出站
  4636. try
  4637. {
  4638. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  4639. {
  4640. lock (lockObj)
  4641. {
  4642. if (!ProgressState)
  4643. {
  4644. ProgressState = true;
  4645. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData,
  4646. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  4647. out ProgressState));
  4648. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  4649. }
  4650. }
  4651. }
  4652. }
  4653. catch (Exception ex)
  4654. {
  4655. ProgressState = false;
  4656. string str = ex.StackTrace;
  4657. AddMessage_Station(stationNameStr, LogType.Error,
  4658. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  4659. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4660. }
  4661. #endregion 出站
  4662. #region 节拍接口
  4663. try
  4664. {
  4665. if (stPLC_MesData.iotData.beatAction > 0)
  4666. {
  4667. int a5OEEType = Convert.ToInt32(s5PLCData["a5OEEType"]);
  4668. int a5OEETypeGOld = Convert.ToInt32(s5PLCSignal_Old["a5OEEType"]);
  4669. if (a5OEEType != a5OEETypeGOld)
  4670. {
  4671. s5PLCData["OEETypeFlag"] = "1";
  4672. }
  4673. else
  4674. {
  4675. s5PLCData["OEETypeFlag"] = "0";
  4676. }
  4677. if (s5PLCData["OEETypeFlag"].ToString() == "1" && (a5OEEType == 1 || a5OEEType == 3 || a5OEEType == 4 || a5OEEType == 5))
  4678. {
  4679. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  4680. if (res == 1)
  4681. {
  4682. s5PLCSignal_Old["a5OEEType"] = s5PLCData["a5OEEType"];
  4683. }
  4684. else {
  4685. s5PLCSignal_Old["a5OEEType"] = 0;
  4686. }
  4687. }
  4688. }
  4689. else {
  4690. s5PLCSignal_Old["a5OEEType"] = 0;
  4691. }
  4692. }
  4693. catch (Exception ex)
  4694. {
  4695. string str = ex.StackTrace;
  4696. AddMessage_Station(stationNameStr, LogType.Error,
  4697. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  4698. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4699. }
  4700. #endregion
  4701. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4702. stopwatch1.Stop();
  4703. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4704. }
  4705. else
  4706. {
  4707. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4708. AddMessage_Station(stationNameStr, LogType.Info,
  4709. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4710. FunsEip[plcNo].Connect(); // 重连
  4711. }
  4712. }
  4713. catch (Exception ex)
  4714. {
  4715. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4716. AddMessage_Station(stationNameStr, LogType.Error,
  4717. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4718. }
  4719. Thread.Sleep(IntervalReadPLC);
  4720. }
  4721. }
  4722. /// <summary>
  4723. /// [S5] 点胶检测设备 - 进站
  4724. /// </summary>
  4725. /// <param name="plcNo">PLC编号</param>
  4726. /// <param name="stationNameStr">工站全称</param>
  4727. /// <param name="stPLC_MesData"></param>
  4728. /// <param name="tagMesCommName"></param>
  4729. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  4730. string tagBarsetName, out bool ProgressState)
  4731. {
  4732. Stopwatch stopwatch1 = new Stopwatch();
  4733. Stopwatch stopwatch2 = new Stopwatch();
  4734. try
  4735. {
  4736. stopwatch1.Start();
  4737. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  4738. //string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  4739. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  4740. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  4741. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  4742. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码
  4743. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  4744. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4745. bool pass = a1Result == 1;
  4746. AddMessage(LogType.Info, $"ADD板编码(PCB码):{pcbBarcode}");
  4747. //绑定载具和产品
  4748. ResponseMessage message = new ResponseMessage();
  4749. message = SQLHelper.PCBCarrierBind(strCarrierBarcode, pcbBarcode);
  4750. if (message.result == false)
  4751. {
  4752. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  4753. ProgressState = false;
  4754. Thread.Sleep(10000);
  4755. return;
  4756. }
  4757. //载具码验证产品码 //载具码验证产品码
  4758. //string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  4759. //if (string.IsNullOrEmpty(strProductBarcode))
  4760. //{
  4761. // AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4762. //}
  4763. //sn = strProductBarcode;
  4764. //AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  4765. // 产品SN(物料码)校验
  4766. List<TestItem> item = new List<TestItem>();
  4767. stopwatch2.Start();
  4768. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  4769. pcbBarcode,
  4770. item, MachineId, StationId, pass, "01-SLOT-01");
  4771. stopwatch2.Stop();
  4772. //指令执行结果 1:OK 110:失败
  4773. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  4774. if (mesResultFrmWeb == 1)
  4775. {
  4776. if (a1Result == 1)
  4777. {
  4778. mesResultFrmWeb = 1;
  4779. }
  4780. else
  4781. {
  4782. mesResultFrmWeb = 110;
  4783. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  4784. }
  4785. }
  4786. //进站结果写入PLC
  4787. CommandFromPLC resultToPlC = new CommandFromPLC();
  4788. resultToPlC.cmd = 0;
  4789. resultToPlC.cmdParam = 0; //指令参数
  4790. resultToPlC.cmdResult = mesResultFrmWeb;
  4791. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4792. }
  4793. catch (Exception ex)
  4794. {
  4795. string str = ex.StackTrace;
  4796. AddMessage(LogType.Error,
  4797. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  4798. str.Length - str.LastIndexOf("\\") - 1));
  4799. CommandFromPLC resultToPlC = new CommandFromPLC();
  4800. resultToPlC.cmd = 0;
  4801. resultToPlC.cmdParam = 0; //指令参数
  4802. resultToPlC.cmdResult = 110;
  4803. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4804. }
  4805. stopwatch1.Stop();
  4806. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  4807. AddMessage(LogType.Info,
  4808. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  4809. stopwatch2.ElapsedMilliseconds + "ms");
  4810. ProgressState = false;
  4811. }
  4812. /// <summary>
  4813. /// [S5] 点胶检测设备 - 出站接口
  4814. /// </summary>
  4815. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
  4816. string stationCode, string stationName, out bool ProgressState)
  4817. {
  4818. Stopwatch stopwatch1 = new Stopwatch();
  4819. Stopwatch stopwatch2 = new Stopwatch();
  4820. test_item_num = 0; //iot 过站明细序号
  4821. try
  4822. {
  4823. stopwatch1.Start();
  4824. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4825. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4826. string processItem = stationName; // 测试项目
  4827. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4828. string supplierCode = ""; // 供应商代码
  4829. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4830. string batch_num = GlobalContext.BatchNumber; // 批次号
  4831. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4832. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4833. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 部件条码;
  4834. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4835. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  4836. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  4837. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  4838. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4839. bool pass = a1Result == 1;
  4840. CommandFromPLC resultToPlC = new CommandFromPLC();
  4841. //根据载具码获取产品码
  4842. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4843. if (string.IsNullOrEmpty(strProductBarcode))
  4844. {
  4845. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  4846. ProgressState = false;
  4847. Thread.Sleep(10000);
  4848. return;
  4849. }
  4850. stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
  4851. sn = strProductBarcode;
  4852. //数据库绑定载具和PCB
  4853. ResponseMessage message = new ResponseMessage();
  4854. message = SQLHelper.PCBCarrierBind(CarrierBarcode, pcbBarcode);
  4855. if (message.result == false)
  4856. {
  4857. AddMessage(LogType.Error, stationNameStr + "_PCB码数据库绑定失败,错误:" + message.text);
  4858. ProgressState = true; //防止循环报错
  4859. return;
  4860. }
  4861. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn};PCB码:{pcbBarcode}");
  4862. List<TestItem> items = new List<TestItem>();
  4863. items.Add(new TestItem()
  4864. {
  4865. Parameter_name = "载具码",
  4866. Parameter_value = CarrierBarcode,
  4867. Parameter_unit = ""
  4868. });
  4869. items.Add(new TestItem()
  4870. {
  4871. Parameter_name = "产品码",
  4872. Parameter_value = sn,
  4873. Parameter_unit = ""
  4874. });
  4875. items.Add(new TestItem()
  4876. {
  4877. Parameter_name = "PCB码",
  4878. Parameter_value = pcbBarcode,
  4879. Parameter_unit = ""
  4880. });
  4881. #region 上传图片
  4882. if (GlobalContext.MQTTIsSendUpFile)
  4883. {
  4884. string[] urlarry = GlobalContext.UpFilePath.Split(",");
  4885. fileUploadData.fileData.Clear();
  4886. foreach (var item in urlarry)
  4887. {
  4888. if (!string.IsNullOrEmpty(item))
  4889. {
  4890. //上传图片
  4891. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName, a1Result,
  4892. item, uuid).Result;
  4893. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  4894. }
  4895. }
  4896. }
  4897. #endregion
  4898. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  4899. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4900. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  4901. MachineId, StationId, PartBarcode, paramJson);
  4902. byte mesResultFrmWeb = 0;
  4903. if (stPLC_MesData.mesCommFrmPLC.cmdParam == 2)
  4904. {
  4905. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem, workorder_code,
  4906. batch_num
  4907. , mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId,
  4908. PartBarcode, paramJson);
  4909. }
  4910. else if (stPLC_MesData.mesCommFrmPLC.cmdParam == 1)
  4911. {
  4912. result1 = PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  4913. }
  4914. mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4915. //进站结果写入PLC
  4916. resultToPlC.cmd = 0;
  4917. resultToPlC.cmdParam = 0; //指令参数
  4918. resultToPlC.cmdResult = mesResultFrmWeb;
  4919. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4920. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4921. //保存PLC返回MES数据到本地
  4922. //ResponseMessage message = new ResponseMessage();
  4923. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  4924. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB,
  4925. stPLC_MesData.mesData.nRemainCount, "");
  4926. if (message.result == false)
  4927. {
  4928. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4929. }
  4930. //保存部件码信息
  4931. if (!string.IsNullOrEmpty(PartBarcode))
  4932. {
  4933. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  4934. if (message.result == false)
  4935. {
  4936. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  4937. }
  4938. }
  4939. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4940. }
  4941. catch (Exception ex)
  4942. {
  4943. stopwatch2.Start();
  4944. CommandFromPLC resultToPlC = new CommandFromPLC();
  4945. resultToPlC.cmd = 0;
  4946. resultToPlC.cmdParam = 0; //指令参数
  4947. resultToPlC.cmdResult = 110;
  4948. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4949. stopwatch2.Stop();
  4950. string str = ex.StackTrace;
  4951. AddMessage(LogType.Error,
  4952. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  4953. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4954. }
  4955. stopwatch1.Stop();
  4956. AddMessage(LogType.Info,
  4957. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  4958. stopwatch2.ElapsedMilliseconds + "ms");
  4959. ProgressState = false;
  4960. uuid = "";
  4961. }
  4962. private int S5_PCB进出站(OP50_MesData_t stPLC_MesData, int plcNo, string stationNameStr, string tagBaseName,
  4963. string tagMesCommName)
  4964. {
  4965. string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
  4966. if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
  4967. {
  4968. string strProductBarcode =
  4969. SQLHelper.GetProductBarcodeByCarrierCode(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  4970. stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
  4971. CommandFromPLC resultToPlC = new CommandFromPLC();
  4972. resultToPlC.cmd = 0;
  4973. resultToPlC.cmdParam = 0; //指令参数
  4974. if (GlobalContext.IsSendStationIn)
  4975. {
  4976. #region 进站
  4977. //int res1 = PCBStationInData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  4978. //if (res1 == 1)
  4979. //{
  4980. // resultToPlC.cmdResult = 2;//OK
  4981. // WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  4982. //}
  4983. //else
  4984. //{
  4985. // resultToPlC.cmdResult = 120;
  4986. // WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  4987. // return 2;
  4988. //}
  4989. #endregion
  4990. #region 出站
  4991. int res2 = PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
  4992. if (res2 == 1)
  4993. {
  4994. resultToPlC.cmdResult = 2; //OK
  4995. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  4996. return 1;
  4997. }
  4998. else
  4999. {
  5000. resultToPlC.cmdResult = 120;
  5001. WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
  5002. return 2;
  5003. }
  5004. #endregion
  5005. }
  5006. else
  5007. {
  5008. return 2;
  5009. }
  5010. }
  5011. else
  5012. {
  5013. return 2;
  5014. }
  5015. }
  5016. #endregion
  5017. #region S6
  5018. private Dictionary<string, object> s6PLCData = new Dictionary<string, object>();
  5019. private Dictionary<string, object> s6PLCSignal_Old = new Dictionary<string, object>();
  5020. /// <summary>
  5021. /// [S6] 顶盖装配设备
  5022. /// </summary>
  5023. /// <param name="plcNo">PLC编号</param>
  5024. public void ReadStation_S6(int plcNo)
  5025. {
  5026. string stationCode = "[OP70]";
  5027. string stationName = "组上盖板";
  5028. string stationNameStr = stationCode + stationName;
  5029. string tagBaseName = "g_OP60_MES"; //标签变量名称
  5030. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5031. string tagAgvCommName = "agvCommFrmPC";
  5032. string tagiotComnName = "iotData";
  5033. string tagBarsetName = "BarcodeSet";
  5034. string CarrierBarcode = "";
  5035. // 触发信号字典
  5036. s6PLCSignal_Old.Add("a6OEEType", 0); // 节拍类型(plc写入)
  5037. // PLC数据字典 赋值
  5038. s6PLCData.Add("a6OEEType", 0); // 节拍类型(plc写入)
  5039. s6PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  5040. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  5041. (int, string) result;
  5042. while (true)
  5043. {
  5044. try
  5045. {
  5046. if (!GlobalContext._IsCon_Funs1)
  5047. {
  5048. UpdatePLCMonitor(1, plcNo, 0);
  5049. continue;
  5050. }
  5051. if (StopWhile)
  5052. {
  5053. continue;
  5054. }
  5055. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5056. {
  5057. Stopwatch stopwatch1 = new Stopwatch();
  5058. Stopwatch stopwatch2 = new Stopwatch();
  5059. stopwatch1.Start();
  5060. stopwatch2.Start();
  5061. #region 一次性读取所有数据
  5062. // 一次性读取所有数据
  5063. result = FunsEip[plcNo]
  5064. .Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  5065. if (result.Item1 != 0)
  5066. {
  5067. //richTextBox1.AppendText("\n" + strRet);
  5068. }
  5069. else
  5070. {
  5071. //测试
  5072. stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
  5073. stPLC_MesData.mesCommFrmPLC.cmd = 1;
  5074. //去除扫码产生的特殊字符
  5075. stPLC_MesData.BarcodeSet.strProductBarcode =
  5076. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  5077. stPLC_MesData.BarcodeSet.strPartBarcode =
  5078. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  5079. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  5080. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  5081. stPLC_MesData.BarcodeSet.strPCBBarcode =
  5082. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  5083. //richTextBox1.AppendText("\n" + "读取成功");
  5084. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  5085. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  5086. ? XiaomiDeviceState.Unknown
  5087. : (XiaomiDeviceState)xmDeviceStateInt;
  5088. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  5089. s6PLCData["a6OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  5090. //报警信息
  5091. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  5092. }
  5093. #endregion 一次性读取所有数据
  5094. stopwatch2.Stop();
  5095. #region 进站
  5096. try
  5097. {
  5098. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5099. {
  5100. lock (lockObj)
  5101. {
  5102. if (!ProgressState)
  5103. {
  5104. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  5105. ProgressState = true;
  5106. //载具码验证产品码
  5107. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData,
  5108. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  5109. out ProgressState));
  5110. }
  5111. }
  5112. }
  5113. }
  5114. catch (Exception ex)
  5115. {
  5116. ProgressState = false;
  5117. string str = ex.StackTrace;
  5118. AddMessage_Station(stationNameStr, LogType.Error,
  5119. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5120. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5121. }
  5122. #endregion 进站
  5123. #region 出站
  5124. try
  5125. {
  5126. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5127. {
  5128. lock (lockObj)
  5129. {
  5130. if (!ProgressState)
  5131. {
  5132. ProgressState = true;
  5133. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData,
  5134. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  5135. out ProgressState));
  5136. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  5137. }
  5138. }
  5139. }
  5140. }
  5141. catch (Exception ex)
  5142. {
  5143. ProgressState = false;
  5144. string str = ex.StackTrace;
  5145. AddMessage_Station(stationNameStr, LogType.Error,
  5146. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5147. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5148. }
  5149. #endregion 出站
  5150. #region 节拍接口
  5151. try
  5152. {
  5153. if (stPLC_MesData.iotData.beatAction > 0)
  5154. {
  5155. int a6OEEType = Convert.ToInt32(s6PLCData["a6OEEType"]);
  5156. int a6OEETypeGOld = Convert.ToInt32(s6PLCSignal_Old["a6OEEType"]);
  5157. if (a6OEEType != a6OEETypeGOld)
  5158. {
  5159. s6PLCData["OEETypeFlag"] = "1";
  5160. }
  5161. else
  5162. {
  5163. s6PLCData["OEETypeFlag"] = "0";
  5164. }
  5165. if (s6PLCData["OEETypeFlag"].ToString() == "1" && (a6OEEType == 1 || a6OEEType == 3 || a6OEEType == 4 || a6OEEType == 5))
  5166. {
  5167. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName, CarrierBarcode, stPLC_MesData.iotData, out res);
  5168. if (res == 1)
  5169. {
  5170. s6PLCSignal_Old["a6OEEType"] = s6PLCData["a6OEEType"];
  5171. }
  5172. else
  5173. {
  5174. s6PLCSignal_Old["a6OEEType"] = 0;
  5175. }
  5176. }
  5177. }
  5178. else {
  5179. s6PLCSignal_Old["a6OEEType"] = 0;
  5180. }
  5181. }
  5182. catch (Exception ex)
  5183. {
  5184. string str = ex.StackTrace;
  5185. AddMessage_Station(stationNameStr, LogType.Error,
  5186. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  5187. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5188. }
  5189. #endregion
  5190. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5191. stopwatch1.Stop();
  5192. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5193. }
  5194. else
  5195. {
  5196. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5197. AddMessage_Station(stationNameStr, LogType.Info,
  5198. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5199. FunsEip[plcNo].Connect(); // 重连
  5200. }
  5201. }
  5202. catch (Exception ex)
  5203. {
  5204. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5205. AddMessage_Station(stationNameStr, LogType.Error,
  5206. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5207. }
  5208. Thread.Sleep(IntervalReadPLC);
  5209. }
  5210. }
  5211. /// <summary>
  5212. /// [S6] 顶盖装配设备 - 进站
  5213. /// </summary>
  5214. /// <param name="plcNo">PLC编号</param>
  5215. /// <param name="stationNameStr">工站全称</param>
  5216. /// <param name="stPLC_MesData"></param>
  5217. /// <param name="tagMesCommName"></param>
  5218. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  5219. string tagBarsetName, out bool ProgressState)
  5220. {
  5221. Stopwatch stopwatch1 = new Stopwatch();
  5222. Stopwatch stopwatch2 = new Stopwatch();
  5223. try
  5224. {
  5225. stopwatch1.Start();
  5226. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  5227. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5228. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  5229. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  5230. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5231. bool pass = a1Result == 1;
  5232. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  5233. string ProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  5234. string PCBBarcode = SQLHelper.GetPCBBarcodeByCarrierCode(strCarrierBarcode);
  5235. //strCarrierBarcode = "N801A-003";
  5236. //载具码验证产品码
  5237. if (string.IsNullOrEmpty(ProductBarcode))
  5238. {
  5239. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5240. ProgressState = false;
  5241. Thread.Sleep(10000);
  5242. return;
  5243. }
  5244. sn = ProductBarcode;
  5245. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5246. // 产品SN(物料码)校验
  5247. List<TestItem> item = new List<TestItem>();
  5248. stopwatch2.Start();
  5249. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  5250. item, MachineId, StationId, pass, "01-SLOT-01");
  5251. stopwatch2.Stop();
  5252. //指令执行结果 1:OK 110:失败
  5253. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5254. if (mesResultFrmWeb == 1)
  5255. {
  5256. if (a1Result == 1)
  5257. {
  5258. mesResultFrmWeb = 1;
  5259. }
  5260. else
  5261. {
  5262. mesResultFrmWeb = 110;
  5263. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  5264. }
  5265. }
  5266. //进站结果写入PLC
  5267. CommandFromPLC resultToPlC = new CommandFromPLC();
  5268. resultToPlC.cmd = 0;
  5269. resultToPlC.cmdParam = 0; //指令参数
  5270. resultToPlC.cmdResult = mesResultFrmWeb;
  5271. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5272. if (mesResultFrmWeb == 1)
  5273. {
  5274. if (OpenDailogFalg)
  5275. {
  5276. using (var dialog = new BandBarodeDialog(strCarrierBarcode, ProductBarcode, PCBBarcode))
  5277. {
  5278. var rs = dialog.ShowDialog();
  5279. if (rs == DialogResult.OK)
  5280. {
  5281. AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode}");
  5282. OpenDailogFalg = false; //关闭扫码
  5283. StopWhile = false;//开启while循环
  5284. }
  5285. else
  5286. {
  5287. ProgressState = false;
  5288. return;
  5289. }
  5290. }
  5291. }
  5292. }
  5293. }
  5294. catch (Exception ex)
  5295. {
  5296. string str = ex.StackTrace;
  5297. AddMessage(LogType.Error,
  5298. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  5299. str.Length - str.LastIndexOf("\\") - 1));
  5300. CommandFromPLC resultToPlC = new CommandFromPLC();
  5301. resultToPlC.cmd = 0;
  5302. resultToPlC.cmdParam = 0; //指令参数
  5303. resultToPlC.cmdResult = 110;
  5304. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5305. }
  5306. stopwatch1.Stop();
  5307. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  5308. AddMessage(LogType.Info,
  5309. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5310. stopwatch2.ElapsedMilliseconds + "ms");
  5311. ProgressState = false;
  5312. }
  5313. /// <summary>
  5314. /// [S6] 顶盖装配设备 - 出站接口
  5315. /// </summary>
  5316. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
  5317. string stationCode, string stationName, out bool ProgressState)
  5318. {
  5319. Stopwatch stopwatch1 = new Stopwatch();
  5320. Stopwatch stopwatch2 = new Stopwatch();
  5321. test_item_num = 0; //iot 过站明细序号
  5322. try
  5323. {
  5324. stopwatch1.Start();
  5325. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  5326. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5327. string processItem = stationName; // 测试项目
  5328. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5329. string supplierCode = ""; // 供应商代码
  5330. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5331. string batch_num = GlobalContext.BatchNumber; // 批次号
  5332. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5333. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5334. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5335. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  5336. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  5337. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5338. bool pass = a1Result == 1;
  5339. //根据载具码获取产品码
  5340. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5341. if (string.IsNullOrEmpty(strProductBarcode))
  5342. {
  5343. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5344. ProgressState = false;
  5345. Thread.Sleep(10000);
  5346. return;
  5347. }
  5348. sn = strProductBarcode;
  5349. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  5350. List<TestItem> items = new List<TestItem>();
  5351. items.Add(new TestItem()
  5352. {
  5353. Parameter_name = "载具码",
  5354. Parameter_value = CarrierBarcode,
  5355. Parameter_unit = ""
  5356. });
  5357. items.Add(new TestItem()
  5358. {
  5359. Parameter_name = "产品码",
  5360. Parameter_value = sn,
  5361. Parameter_unit = ""
  5362. });
  5363. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  5364. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  5365. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  5366. MachineId, StationId, "", paramJson);
  5367. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5368. if (mesResultFrmWeb == 1)
  5369. {
  5370. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  5371. if (mesResultFrmWeb==110)
  5372. {
  5373. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  5374. }
  5375. }
  5376. stopwatch2.Start();
  5377. //进站结果写入PLC
  5378. CommandFromPLC resultToPlC = new CommandFromPLC();
  5379. resultToPlC.cmd = 0;
  5380. resultToPlC.cmdParam = 0; //指令参数
  5381. resultToPlC.cmdResult = mesResultFrmWeb;
  5382. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5383. stopwatch2.Stop();
  5384. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  5385. //保存PLC返回MES数据到本地
  5386. ResponseMessage message = new ResponseMessage();
  5387. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  5388. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  5389. }
  5390. catch (Exception ex)
  5391. {
  5392. stopwatch2.Start();
  5393. CommandFromPLC resultToPlC = new CommandFromPLC();
  5394. resultToPlC.cmd = 0;
  5395. resultToPlC.cmdParam = 0; //指令参数
  5396. resultToPlC.cmdResult = 110;
  5397. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5398. stopwatch2.Stop();
  5399. string str = ex.StackTrace;
  5400. AddMessage(LogType.Error,
  5401. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5402. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5403. }
  5404. stopwatch1.Stop();
  5405. AddMessage(LogType.Info,
  5406. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5407. stopwatch2.ElapsedMilliseconds + "ms");
  5408. ProgressState = false;
  5409. uuid = "";
  5410. OpenDailogFalg = true; //开启下一个物料的扫码
  5411. }
  5412. #endregion
  5413. #region S7
  5414. private Dictionary<string, object> s7PLCSignal_Old = new Dictionary<string, object>();
  5415. private Dictionary<string, object> s7PLCData = new Dictionary<string, object>();
  5416. /// <summary>
  5417. /// [S7] 锁螺丝设备
  5418. /// </summary>
  5419. /// <param name="plcNo">PLC编号</param>
  5420. private void ReadStation_S7(int plcNo)
  5421. {
  5422. string stationCode = "[OP80]";
  5423. string stationName = "上盖板锁螺丝";
  5424. string stationNameStr = stationCode + stationName;
  5425. string tagBaseName = "g_OP70_MES"; //标签变量名称
  5426. string tagMesCommName = "mesCommToPC"; //标签变量名称
  5427. string tagAgvCommName = "agvCommFrmPC";
  5428. string tagBarsetName = "BarcodeSet";
  5429. string tagiotComnName = "iotData";
  5430. string tagScrewDataset = "screwDataset";
  5431. string CarrierBarcode_Left = "";
  5432. string CarrierBarcode_Right = "";
  5433. s7PLCSignal_Old.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
  5434. s7PLCSignal_Old.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
  5435. // PLC数据字典 赋值
  5436. s7PLCData.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
  5437. s7PLCData.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
  5438. s5PLCData.Add("OEETypeFlag_left", 0); // 节拍标识 0 不上传 ,1 上传
  5439. s5PLCData.Add("OEETypeFlag_right", 0); // 节拍标识 0 不上传 ,1 上传
  5440. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  5441. (int, string) result;
  5442. AtlasScrew atlasScrewLeft = new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort,
  5443. 3000, 3000, "Left");
  5444. atlasScrewLeft.Initial();
  5445. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort,
  5446. 3000, 3000, "Right");
  5447. atlasScrewRight.Initial();
  5448. while (true)
  5449. {
  5450. try
  5451. {
  5452. if (!GlobalContext._IsCon_Funs1)
  5453. {
  5454. UpdatePLCMonitor(1, plcNo, 0);
  5455. continue;
  5456. }
  5457. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  5458. {
  5459. Stopwatch stopwatch1 = new Stopwatch();
  5460. Stopwatch stopwatch2 = new Stopwatch();
  5461. stopwatch1.Start();
  5462. stopwatch2.Start();
  5463. #region 一次性读取所有数据
  5464. // 一次性读取所有数据
  5465. result = FunsEip[plcNo]
  5466. .Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  5467. if (result.Item1 != 0)
  5468. {
  5469. //richTextBox1.AppendText("\n" + strRet);
  5470. }
  5471. else
  5472. {
  5473. #region 去除扫码产生的特殊字符
  5474. stPLC_MesData.Left.BarcodeSet.strProductBarcode =
  5475. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strProductBarcode);
  5476. stPLC_MesData.Left.BarcodeSet.strPartBarcode =
  5477. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPartBarcode);
  5478. stPLC_MesData.Left.BarcodeSet.strCarrierBarcode =
  5479. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strCarrierBarcode);
  5480. stPLC_MesData.Left.BarcodeSet.strPCBBarcode =
  5481. FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPCBBarcode);
  5482. stPLC_MesData.Right.BarcodeSet.strProductBarcode =
  5483. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strProductBarcode);
  5484. stPLC_MesData.Right.BarcodeSet.strPartBarcode =
  5485. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPartBarcode);
  5486. stPLC_MesData.Right.BarcodeSet.strCarrierBarcode =
  5487. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strCarrierBarcode);
  5488. stPLC_MesData.Right.BarcodeSet.strPCBBarcode =
  5489. FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPCBBarcode);
  5490. #endregion
  5491. int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
  5492. int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
  5493. xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  5494. ? XiaomiDeviceState.Unknown
  5495. : (XiaomiDeviceState)xmDeviceStateInt_L;
  5496. xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
  5497. ? XiaomiDeviceState.Unknown
  5498. : (XiaomiDeviceState)xmDeviceStateInt_R;
  5499. s7PLCData["a7OEEPartNo"] =
  5500. stPLC_MesData.Left.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
  5501. // 载具SN
  5502. CarrierBarcode_Left = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode;
  5503. CarrierBarcode_Right = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode;
  5504. // 节拍
  5505. s7PLCData["a7OEEType"] = stPLC_MesData.Left.iotData.beatAction;
  5506. s7PLCData["a7OEEType_right"] = stPLC_MesData.Right.iotData.beatAction;
  5507. //报警信息
  5508. _FaultDatas = stPLC_MesData.Left.iotData.fault_codes;
  5509. _FaultDatas2 = stPLC_MesData.Right.iotData.fault_codes;
  5510. }
  5511. #endregion 一次性读取所有数据
  5512. stopwatch2.Stop();
  5513. #region 左边进站
  5514. try
  5515. {
  5516. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5517. {
  5518. lock (lockObj)
  5519. {
  5520. if (!ProgressState)
  5521. {
  5522. stationCode = "[OP81]";
  5523. stationName = "上盖板锁螺丝1";
  5524. stationNameStr = stationCode + stationName;
  5525. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  5526. ProgressState = true;
  5527. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left,
  5528. tagBaseName + ".Left." + tagMesCommName,
  5529. tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState,
  5530. atlasScrewLeft));
  5531. }
  5532. }
  5533. }
  5534. }
  5535. catch (Exception ex)
  5536. {
  5537. ProgressState = false;
  5538. string str = ex.StackTrace;
  5539. AddMessage_Station(stationNameStr, LogType.Error,
  5540. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5541. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5542. }
  5543. #endregion 左边进站
  5544. #region 左边出站
  5545. try
  5546. {
  5547. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5548. {
  5549. lock (lockObj)
  5550. {
  5551. if (!ProgressState)
  5552. {
  5553. stationCode = "[OP81]";
  5554. stationName = "上盖板锁螺丝1";
  5555. stationNameStr = stationCode + stationName;
  5556. ProgressState = true;
  5557. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left,
  5558. tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
  5559. out ProgressState));
  5560. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  5561. }
  5562. }
  5563. }
  5564. }
  5565. catch (Exception ex)
  5566. {
  5567. ProgressState = false;
  5568. string str = ex.StackTrace;
  5569. AddMessage_Station(stationNameStr, LogType.Error,
  5570. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5571. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5572. }
  5573. #endregion 左边出站
  5574. #region 右边进站
  5575. try
  5576. {
  5577. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  5578. {
  5579. lock (lockObj)
  5580. {
  5581. if (!ProgressState)
  5582. {
  5583. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  5584. stationCode = "[OP82]";
  5585. stationName = "上盖板锁螺丝2";
  5586. stationNameStr = stationCode + stationName;
  5587. ProgressState = true;
  5588. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right,
  5589. tagBaseName + ".Right." + tagMesCommName,
  5590. tagBaseName + ".Right" + tagBarsetName, "Right", out ProgressState,
  5591. atlasScrewRight));
  5592. }
  5593. }
  5594. }
  5595. }
  5596. catch (Exception ex)
  5597. {
  5598. ProgressState = false;
  5599. string str = ex.StackTrace;
  5600. AddMessage_Station(stationNameStr, LogType.Error,
  5601. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5602. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5603. }
  5604. #endregion 右边进站
  5605. #region 右边出站
  5606. try
  5607. {
  5608. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  5609. {
  5610. lock (lockObj)
  5611. {
  5612. if (!ProgressState)
  5613. {
  5614. stationCode = "[OP82]";
  5615. stationName = "上盖板锁螺丝2";
  5616. stationNameStr = stationCode + stationName;
  5617. ProgressState = true;
  5618. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right,
  5619. tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
  5620. out ProgressState));
  5621. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  5622. }
  5623. }
  5624. }
  5625. }
  5626. catch (Exception ex)
  5627. {
  5628. ProgressState = false;
  5629. string str = ex.StackTrace;
  5630. AddMessage_Station(stationNameStr, LogType.Error,
  5631. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  5632. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5633. }
  5634. #endregion 右边出站
  5635. #region 节拍接口
  5636. try
  5637. {
  5638. #region 左工位 节拍
  5639. if (stPLC_MesData.Left.iotData.beatAction > 0)
  5640. {
  5641. stationCode = "[OP81]";
  5642. stationName = "上盖板锁螺丝1";
  5643. stationNameStr = stationCode + stationName;
  5644. int a7OEEType_left = Convert.ToInt32(s7PLCData["a7OEEType_left"]);
  5645. int a7OEETypeGOld_left = Convert.ToInt32(s7PLCSignal_Old["a7OEEType_left"]);
  5646. if (a7OEEType_left != a7OEETypeGOld_left)
  5647. {
  5648. if (a7OEEType_left != a7OEETypeGOld_left)
  5649. s7PLCData["OEETypeFlag_left"] = "1";
  5650. else
  5651. s7PLCData["OEETypeFlag_left"] = "0";
  5652. if (s7PLCData["OEETypeFlag_left"].ToString() == "1" && (a7OEEType_left == 1 || a7OEEType_left == 3 || a7OEEType_left == 4 || a7OEEType_left == 5))
  5653. {
  5654. int res = 0;
  5655. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagiotComnName, CarrierBarcode_Left,
  5656. stPLC_MesData.Left.iotData, out res);
  5657. if (res == 1)
  5658. {
  5659. s7PLCSignal_Old["a7OEEType_left"] = s7PLCData["a7OEEType_left"];
  5660. }
  5661. else {
  5662. s7PLCSignal_Old["a7OEEType_left"] = 0;
  5663. }
  5664. }
  5665. }
  5666. }
  5667. else
  5668. {
  5669. s7PLCSignal_Old["a7OEEType_left"] = 0;
  5670. }
  5671. #endregion 左工位 节拍
  5672. #region 右工位 节拍
  5673. if (stPLC_MesData.Right.iotData.beatAction > 0)
  5674. {
  5675. stationCode = "[OP82]";
  5676. stationName = "上盖板锁螺丝2";
  5677. stationNameStr = stationCode + stationName;
  5678. int a7OEEType_right = Convert.ToInt32(s7PLCData["a7OEEType_right"]);
  5679. int a7OEETypeGOld_right = Convert.ToInt32(s7PLCSignal_Old["a7OEEType_right"]);
  5680. if (a7OEEType_right != a7OEETypeGOld_right)
  5681. {
  5682. if (a7OEEType_right != a7OEETypeGOld_right)
  5683. s7PLCData["a7OEEType_right"] = "1";
  5684. else
  5685. s7PLCData["a7OEEType_right"] = "0";
  5686. if (s7PLCData["a7OEEType_right"].ToString() == "1" && (a7OEEType_right == 1 || a7OEEType_right == 3 || a7OEEType_right == 4 || a7OEEType_right == 5))
  5687. {
  5688. 通用节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagiotComnName, CarrierBarcode_Left,
  5689. stPLC_MesData.Right.iotData, out res);
  5690. if (res == 1)
  5691. {
  5692. s7PLCSignal_Old["a7OEEType_right"] = s7PLCData["a7OEEType_right"];
  5693. }
  5694. else {
  5695. s7PLCSignal_Old["a7OEEType_right"] = 0;
  5696. }
  5697. }
  5698. }
  5699. }
  5700. else
  5701. {
  5702. s7PLCSignal_Old["a7OEEType_right"] = 0;
  5703. }
  5704. #endregion 右工位 节拍
  5705. }
  5706. catch (Exception ex)
  5707. {
  5708. string str = ex.StackTrace;
  5709. AddMessage_Station(stationNameStr, LogType.Error,
  5710. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  5711. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5712. }
  5713. #endregion
  5714. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5715. stopwatch1.Stop();
  5716. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5717. }
  5718. else
  5719. {
  5720. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5721. AddMessage_Station(stationNameStr, LogType.Info,
  5722. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5723. FunsEip[plcNo].Connect(); // 重连
  5724. }
  5725. }
  5726. catch (Exception ex)
  5727. {
  5728. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5729. AddMessage_Station(stationNameStr, LogType.Error,
  5730. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5731. }
  5732. Thread.Sleep(IntervalReadPLC);
  5733. }
  5734. }
  5735. /// <summary>
  5736. /// [S7] 锁螺丝设备 - 进站
  5737. /// </summary>
  5738. /// <param name="plcNo">PLC编号</param>
  5739. /// <param name="stationNameStr">工站全称</param>
  5740. /// <param name="stPLC_MesData"></param>
  5741. /// <param name="tagMesCommName"></param>
  5742. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  5743. string tagBarsetName, string direction, out bool ProgressState, AtlasScrew atlasScrew)
  5744. {
  5745. Stopwatch stopwatch1 = new Stopwatch();
  5746. Stopwatch stopwatch2 = new Stopwatch();
  5747. string atlasSn = string.Empty;
  5748. try
  5749. {
  5750. stopwatch1.Start();
  5751. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
  5752. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  5753. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  5754. string StationId = string.Empty; // 工位ID(可配置)
  5755. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5756. bool pass = a1Result == 1;
  5757. if (direction == "Left")
  5758. {
  5759. StationId = GlobalContext.S7_StationId_1;
  5760. }
  5761. if (direction == "Right")
  5762. {
  5763. StationId = GlobalContext.S7_StationId_2;
  5764. }
  5765. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  5766. //载具码验证产品码
  5767. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  5768. if (string.IsNullOrEmpty(strProductBarcode))
  5769. {
  5770. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5771. ProgressState = false;
  5772. Thread.Sleep(10000);
  5773. return;
  5774. }
  5775. sn = strProductBarcode;
  5776. atlasSn = strProductBarcode;
  5777. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  5778. string slot = "";
  5779. if (direction == "Left")
  5780. {
  5781. isCollectingFlagLeft = false; //采集螺丝数据结束
  5782. slot = "01-SLOT-01";
  5783. }
  5784. if (direction == "Right")
  5785. {
  5786. isCollectingFlagRight = false; //采集螺丝数据结束
  5787. slot = "01-SLOT-02";
  5788. }
  5789. // 产品SN(物料码)校验
  5790. List<TestItem> item = new List<TestItem>();
  5791. stopwatch2.Start();
  5792. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  5793. item, MachineId, StationId, pass, slot);
  5794. stopwatch2.Stop();
  5795. //指令执行结果 1:OK 110:失败
  5796. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  5797. if (mesResultFrmWeb == 1)
  5798. {
  5799. if (a1Result == 1)
  5800. {
  5801. mesResultFrmWeb = 1;
  5802. }
  5803. else
  5804. {
  5805. mesResultFrmWeb = 110;
  5806. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  5807. }
  5808. }
  5809. //进站结果写入PLC
  5810. CommandFromPLC resultToPlC = new CommandFromPLC();
  5811. resultToPlC.cmd = 0;
  5812. resultToPlC.cmdParam = 0; //指令参数
  5813. resultToPlC.cmdResult = mesResultFrmWeb;
  5814. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5815. }
  5816. catch (Exception ex)
  5817. {
  5818. string str = ex.StackTrace;
  5819. AddMessage(LogType.Error,
  5820. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  5821. str.Length - str.LastIndexOf("\\") - 1));
  5822. CommandFromPLC resultToPlC = new CommandFromPLC();
  5823. resultToPlC.cmd = 0;
  5824. resultToPlC.cmdParam = 0; //指令参数
  5825. resultToPlC.cmdResult = 110;
  5826. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5827. }
  5828. stopwatch1.Stop();
  5829. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  5830. AddMessage(LogType.Info,
  5831. stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  5832. stopwatch2.ElapsedMilliseconds + "ms");
  5833. ProgressState = false;
  5834. //开始采集螺丝数据
  5835. if (direction == "Left")
  5836. {
  5837. isCollectingFlagLeft = true;
  5838. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  5839. }
  5840. if (direction == "Right")
  5841. {
  5842. isCollectingFlagRight = true;
  5843. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  5844. }
  5845. }
  5846. /// <summary>
  5847. /// [S7] 锁螺丝设备 - 出站
  5848. /// </summary>
  5849. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
  5850. string stationCode, string stationName, string direction, out bool ProgressState)
  5851. {
  5852. Stopwatch stopwatch1 = new Stopwatch();
  5853. Stopwatch stopwatch2 = new Stopwatch();
  5854. test_item_num = 0; //iot 过站明细序号
  5855. try
  5856. {
  5857. stopwatch1.Start();
  5858. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  5859. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5860. string processItem = stationName; // 测试项目
  5861. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5862. string supplierCode = ""; // 供应商代码
  5863. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5864. string batch_num = GlobalContext.BatchNumber; // 批次号
  5865. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5866. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  5867. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  5868. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  5869. string StationId = string.Empty; // 工位ID(可配置)
  5870. if (direction == "Left")
  5871. {
  5872. StationId = GlobalContext.S7_StationId_1;
  5873. }
  5874. if (direction == "Right")
  5875. {
  5876. StationId = GlobalContext.S7_StationId_2;
  5877. }
  5878. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  5879. //a1Result = 1;
  5880. bool pass = a1Result == 1;
  5881. //根据载具码获取产品码
  5882. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  5883. if (string.IsNullOrEmpty(strProductBarcode))
  5884. {
  5885. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  5886. ProgressState = false;
  5887. Thread.Sleep(10000);
  5888. return;
  5889. }
  5890. sn = strProductBarcode;
  5891. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  5892. List<TestItem> items = new List<TestItem>();
  5893. items.Add(new TestItem()
  5894. {
  5895. Parameter_name = "载具码",
  5896. Parameter_value = CarrierBarcode,
  5897. Parameter_unit = ""
  5898. });
  5899. items.Add(new TestItem()
  5900. {
  5901. Parameter_name = "产品码",
  5902. Parameter_value = sn,
  5903. Parameter_unit = ""
  5904. });
  5905. //if (direction == "Right")
  5906. //{
  5907. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  5908. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem, workorder_code,
  5909. batch_num, mtltmrk, plcDate_YMD, supplierCode
  5910. , sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
  5911. //}
  5912. //if (direction == "Left")
  5913. //{
  5914. // isCollectingFlagLeft = false;//采集螺丝数据结束
  5915. //}
  5916. //if (direction == "Right")
  5917. //{
  5918. // isCollectingFlagRight = false;//采集螺丝数据结束
  5919. //}
  5920. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  5921. if (mesResultFrmWeb == 1)
  5922. {
  5923. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  5924. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  5925. }
  5926. stopwatch2.Start();
  5927. //进站结果写入PLC
  5928. CommandFromPLC resultToPlC = new CommandFromPLC();
  5929. resultToPlC.cmd = 0;
  5930. resultToPlC.cmdParam = 0; //指令参数
  5931. resultToPlC.cmdResult = mesResultFrmWeb;
  5932. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5933. stopwatch2.Stop();
  5934. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  5935. //保存PLC返回MES数据到本地
  5936. ResponseMessage message = new ResponseMessage();
  5937. if (direction == "Left")
  5938. {
  5939. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  5940. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  5941. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  5942. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  5943. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  5944. if (message.result == false)
  5945. {
  5946. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  5947. }
  5948. }
  5949. if (direction == "Right")
  5950. {
  5951. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  5952. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  5953. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  5954. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  5955. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  5956. if (message.result == false)
  5957. {
  5958. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  5959. }
  5960. }
  5961. //保存螺丝数据到txt
  5962. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes,
  5963. stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  5964. if (result.Item1 != 0)
  5965. {
  5966. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  5967. }
  5968. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_保存加工数据到本地成功");
  5969. }
  5970. catch (Exception ex)
  5971. {
  5972. stopwatch2.Start();
  5973. CommandFromPLC resultToPlC = new CommandFromPLC();
  5974. resultToPlC.cmd = 0;
  5975. resultToPlC.cmdParam = 0; //指令参数
  5976. resultToPlC.cmdResult = 110;
  5977. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  5978. stopwatch2.Stop();
  5979. string str = ex.StackTrace;
  5980. AddMessage(LogType.Error,
  5981. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  5982. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5983. }
  5984. stopwatch1.Stop();
  5985. AddMessage(LogType.Info,
  5986. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  5987. stopwatch2.ElapsedMilliseconds + "ms");
  5988. ProgressState = false;
  5989. uuid = "";
  5990. }
  5991. #endregion
  5992. #region S8
  5993. private Dictionary<string, object> s8PLCData = new Dictionary<string, object>();
  5994. private Dictionary<string, object> s8PLCSignal_Old = new Dictionary<string, object>();
  5995. /// <summary>
  5996. /// [S8] 3D螺丝高度检测设备
  5997. /// </summary>
  5998. /// <param name="plcNo">PLC编号</param>
  5999. private void ReadStation_S8(int plcNo)
  6000. {
  6001. string stationCode = "[OP90]";
  6002. string stationName = "NG下料";
  6003. string stationNameStr = stationCode + stationName;
  6004. string tagBaseName = "g_OP80_MES"; //标签变量名称
  6005. string tagMesCommName = "mesCommToPC"; //标签变量名称
  6006. string tagAgvCommName = "agvCommFrmPC";
  6007. string tagiotComnName = "iotData";
  6008. string tagBarsetName = "BarcodeSet";
  6009. string CarrierBarcode = "";
  6010. // 触发信号字典
  6011. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6012. s8PLCSignal_Old.Add("a8OEEType", 0); // 节拍类型(plc写入)
  6013. // PLC数据字典 赋值
  6014. s8PLCData.Add("a8OEEType", 0); // 节拍类型(plc写入)
  6015. s8PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  6016. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  6017. (int, string) result;
  6018. while (true)
  6019. {
  6020. try
  6021. {
  6022. if (!GlobalContext._IsCon_Funs1)
  6023. {
  6024. UpdatePLCMonitor(1, plcNo, 0);
  6025. continue;
  6026. }
  6027. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  6028. {
  6029. Stopwatch stopwatch1 = new Stopwatch();
  6030. Stopwatch stopwatch2 = new Stopwatch();
  6031. stopwatch1.Start();
  6032. stopwatch2.Start();
  6033. #region 一次性读取所有数据
  6034. // 一次性读取所有数据
  6035. result = FunsEip[plcNo]
  6036. .Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  6037. if (result.Item1 != 0)
  6038. {
  6039. //richTextBox1.AppendText("\n" + strRet);
  6040. }
  6041. else
  6042. {
  6043. //去除扫码产生的特殊字符
  6044. stPLC_MesData.BarcodeSet.strProductBarcode =
  6045. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  6046. stPLC_MesData.BarcodeSet.strPartBarcode =
  6047. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  6048. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  6049. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  6050. stPLC_MesData.BarcodeSet.strPCBBarcode =
  6051. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  6052. }
  6053. #endregion 一次性读取所有数据
  6054. stopwatch2.Stop();
  6055. //richTextBox1.AppendText("\n" + "读取成功");
  6056. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  6057. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  6058. ? XiaomiDeviceState.Unknown
  6059. : (XiaomiDeviceState)xmDeviceStateInt;
  6060. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  6061. s8PLCData["a8OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  6062. //报警信息
  6063. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  6064. stopwatch2.Stop();
  6065. #region 进站
  6066. try
  6067. {
  6068. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  6069. {
  6070. lock (lockObj)
  6071. {
  6072. if (!ProgressState)
  6073. {
  6074. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  6075. ProgressState = true;
  6076. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData,
  6077. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  6078. out ProgressState));
  6079. }
  6080. }
  6081. }
  6082. }
  6083. catch (Exception ex)
  6084. {
  6085. ProgressState = false;
  6086. string str = ex.StackTrace;
  6087. AddMessage_Station(stationNameStr, LogType.Error,
  6088. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6089. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6090. }
  6091. #endregion 进站
  6092. #region 出站
  6093. try
  6094. {
  6095. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  6096. {
  6097. lock (lockObj)
  6098. {
  6099. if (!ProgressState)
  6100. {
  6101. ProgressState = true;
  6102. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData,
  6103. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  6104. out ProgressState));
  6105. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  6106. uuid = "";
  6107. }
  6108. }
  6109. }
  6110. }
  6111. catch (Exception ex)
  6112. {
  6113. ProgressState = false;
  6114. string str = ex.StackTrace;
  6115. AddMessage_Station(stationNameStr, LogType.Error,
  6116. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6117. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6118. }
  6119. #endregion 出站
  6120. #region 节拍接口
  6121. try
  6122. {
  6123. int a8OEEType = Convert.ToInt32(s8PLCData["a8OEEType"]);
  6124. int a8OEETypeGOld = Convert.ToInt32(s8PLCSignal_Old["a8OEEType"]);
  6125. if (stPLC_MesData.iotData.beatAction > 0)
  6126. {
  6127. if (a8OEEType != a8OEETypeGOld)
  6128. {
  6129. s8PLCData["OEETypeFlag"] = "1";
  6130. }
  6131. else
  6132. {
  6133. s8PLCData["OEETypeFlag"] = "0";
  6134. }
  6135. if (s8PLCData["OEETypeFlag"].ToString() == "1" && (a8OEEType == 1 || a8OEEType == 3 || a8OEEType == 4 || a8OEEType == 5))
  6136. {
  6137. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  6138. CarrierBarcode, stPLC_MesData.iotData, out res);
  6139. if (res == 1)
  6140. {
  6141. s8PLCSignal_Old["a8OEEType"] = s8PLCData["a8OEEType"];
  6142. }
  6143. else
  6144. {
  6145. s8PLCSignal_Old["a8OEEType"] = 0;
  6146. }
  6147. }
  6148. }
  6149. else {
  6150. s8PLCSignal_Old["a8OEEType"] = 0;
  6151. }
  6152. }
  6153. catch (Exception ex)
  6154. {
  6155. string str = ex.StackTrace;
  6156. AddMessage_Station(stationNameStr, LogType.Error,
  6157. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  6158. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6159. }
  6160. #endregion
  6161. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6162. stopwatch1.Stop();
  6163. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6164. }
  6165. else
  6166. {
  6167. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6168. AddMessage_Station(stationNameStr, LogType.Info,
  6169. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6170. FunsEip[plcNo].Connect(); // 重连
  6171. }
  6172. }
  6173. catch (Exception ex)
  6174. {
  6175. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6176. AddMessage_Station(stationNameStr, LogType.Error,
  6177. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6178. }
  6179. Thread.Sleep(IntervalReadPLC);
  6180. }
  6181. }
  6182. /// <summary>
  6183. /// [S8] 3D螺丝高度检测设备 - 进站
  6184. /// </summary>
  6185. /// <param name="plcNo">PLC编号</param>
  6186. /// <param name="stationNameStr">工站全称</param>
  6187. /// <param name="stPLC_MesData"></param>
  6188. /// <param name="tagMesCommName"></param>
  6189. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  6190. string tagBarsetName, out bool ProgressState)
  6191. {
  6192. Stopwatch stopwatch1 = new Stopwatch();
  6193. Stopwatch stopwatch2 = new Stopwatch();
  6194. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6195. bool pass = a1Result == 1;
  6196. try
  6197. {
  6198. stopwatch1.Start();
  6199. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  6200. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  6201. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  6202. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  6203. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  6204. //载具码验证产品码
  6205. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  6206. if (string.IsNullOrEmpty(strProductBarcode))
  6207. {
  6208. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6209. ProgressState = false;
  6210. Thread.Sleep(10000);
  6211. return;
  6212. }
  6213. sn = strProductBarcode;
  6214. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  6215. // 产品SN(物料码)校验
  6216. List<TestItem> item = new List<TestItem>();
  6217. stopwatch2.Start();
  6218. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  6219. sn,
  6220. item, MachineId, StationId, pass, "01-SLOT-01");
  6221. stopwatch2.Stop();
  6222. //指令执行结果 1:OK 110:失败
  6223. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  6224. if (mesResultFrmWeb == 1)
  6225. {
  6226. if (a1Result == 1)
  6227. {
  6228. mesResultFrmWeb = 1;
  6229. }
  6230. else
  6231. {
  6232. mesResultFrmWeb = 110;
  6233. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  6234. }
  6235. }
  6236. //进站结果写入PLC
  6237. CommandFromPLC resultToPlC = new CommandFromPLC();
  6238. resultToPlC.cmd = 0;
  6239. resultToPlC.cmdParam = 0; //指令参数
  6240. resultToPlC.cmdResult = mesResultFrmWeb;
  6241. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6242. }
  6243. catch (Exception ex)
  6244. {
  6245. string str = ex.StackTrace;
  6246. AddMessage(LogType.Error,
  6247. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(
  6248. str.LastIndexOf("\\") + 1,
  6249. str.Length - str.LastIndexOf("\\") - 1));
  6250. CommandFromPLC resultToPlC = new CommandFromPLC();
  6251. resultToPlC.cmd = 0;
  6252. resultToPlC.cmdParam = 0; //指令参数
  6253. resultToPlC.cmdResult = 110;
  6254. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6255. }
  6256. stopwatch1.Stop();
  6257. AddMessage(LogType.Info,
  6258. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  6259. stopwatch2.ElapsedMilliseconds + "ms");
  6260. ProgressState = false;
  6261. }
  6262. /// <summary>
  6263. /// [S8] 3D螺丝高度检测设备 - 出站接口
  6264. /// </summary>
  6265. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
  6266. string stationCode, string stationName, out bool ProgressState)
  6267. {
  6268. Stopwatch stopwatch1 = new Stopwatch();
  6269. Stopwatch stopwatch2 = new Stopwatch();
  6270. test_item_num = 0; //iot 过站明细序号
  6271. try
  6272. {
  6273. stopwatch1.Start();
  6274. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  6275. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6276. string processItem = stationName; // 测试项目
  6277. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6278. string supplierCode = ""; // 供应商代码
  6279. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6280. string batch_num = GlobalContext.BatchNumber; // 批次号
  6281. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6282. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  6283. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  6284. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  6285. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  6286. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6287. bool pass = a1Result == 1;
  6288. //根据载具码获取产品码
  6289. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  6290. if (string.IsNullOrEmpty(strProductBarcode))
  6291. {
  6292. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6293. ProgressState = false;
  6294. Thread.Sleep(10000);
  6295. return;
  6296. }
  6297. sn = strProductBarcode;
  6298. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  6299. List<TestItem> items = new List<TestItem>();
  6300. items.Add(new TestItem()
  6301. {
  6302. Parameter_name = "载具码",
  6303. Parameter_value = CarrierBarcode,
  6304. Parameter_unit = ""
  6305. });
  6306. items.Add(new TestItem()
  6307. {
  6308. Parameter_name = "产品码",
  6309. Parameter_value = sn,
  6310. Parameter_unit = ""
  6311. });
  6312. #region 上传图片
  6313. if (GlobalContext.MQTTIsSendUpFile)
  6314. {
  6315. string[] urlarry = GlobalContext.UpFilePath.Split(",");
  6316. fileUploadData.fileData.Clear();
  6317. foreach (var item in urlarry)
  6318. {
  6319. if (!string.IsNullOrEmpty(item))
  6320. {
  6321. //上传图片
  6322. var result = SaveDBbyFileInfo(stPLC_MesData.BarcodeSet, stationCode, stationName,
  6323. a1Result, item, uuid).Result;
  6324. OnMessage(LogType.Error, $"【文件上传】 产品码 [{sn}] " + result.Item2);
  6325. }
  6326. }
  6327. }
  6328. #endregion
  6329. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  6330. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6331. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  6332. MachineId, StationId, "", paramJson);
  6333. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  6334. if (mesResultFrmWeb == 1)
  6335. {
  6336. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  6337. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  6338. }
  6339. stopwatch2.Start();
  6340. //进站结果写入PLC
  6341. CommandFromPLC resultToPlC = new CommandFromPLC();
  6342. resultToPlC.cmd = 0;
  6343. resultToPlC.cmdParam = 0; //指令参数
  6344. resultToPlC.cmdResult = mesResultFrmWeb;
  6345. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6346. stopwatch2.Stop();
  6347. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  6348. //保存PLC返回MES数据到本地
  6349. ResponseMessage message = new ResponseMessage();
  6350. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  6351. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  6352. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  6353. if (message.result == false)
  6354. {
  6355. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  6356. }
  6357. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  6358. }
  6359. catch (Exception ex)
  6360. {
  6361. stopwatch2.Start();
  6362. CommandFromPLC resultToPlC = new CommandFromPLC();
  6363. resultToPlC.cmd = 0;
  6364. resultToPlC.cmdParam = 0; //指令参数
  6365. resultToPlC.cmdResult = 110;
  6366. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6367. stopwatch2.Stop();
  6368. string str = ex.StackTrace;
  6369. AddMessage(LogType.Error,
  6370. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  6371. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6372. }
  6373. stopwatch1.Stop();
  6374. AddMessage(LogType.Info,
  6375. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6376. stopwatch2.ElapsedMilliseconds + "ms");
  6377. ProgressState = false;
  6378. }
  6379. #endregion
  6380. #region S9
  6381. private Dictionary<string, object> s9PLCData = new Dictionary<string, object>();
  6382. private Dictionary<string, object> s9PLCSignal_Old = new Dictionary<string, object>();
  6383. /// <summary>
  6384. /// [S9] 下料设备
  6385. /// </summary>
  6386. /// <param name="plcNo">PLC编号</param>
  6387. private void ReadStation_S9(int plcNo)
  6388. {
  6389. string stationCode = "[OP100]";
  6390. string stationName = "半成品下料";
  6391. string stationNameStr = stationCode + stationName;
  6392. string tagBaseName = "g_OP90_MES"; //标签变量名称
  6393. string tagMesCommName = "mesCommToPC"; //标签变量名称
  6394. string tagAgvCommName = "agvCommFrmPC";
  6395. string tagiotComnName = "iotData";
  6396. string tagBarsetName = "BarcodeSet";
  6397. string CarrierBarcode = "";
  6398. // 触发信号字典
  6399. //s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6400. s9PLCSignal_Old.Add("a9OEEType", 0); // 节拍类型(plc写入)
  6401. // PLC数据字典 赋值
  6402. s9PLCData.Add("a9OEEType", 0); // 节拍类型(plc写入)
  6403. s9PLCData.Add("OEETypeFlag", 0); // 节拍类型(plc写入)
  6404. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  6405. (int, string) result;
  6406. while (true)
  6407. {
  6408. try
  6409. {
  6410. if (!GlobalContext._IsCon_Funs1)
  6411. {
  6412. UpdatePLCMonitor(1, plcNo, 0);
  6413. continue;
  6414. }
  6415. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  6416. {
  6417. Stopwatch stopwatch1 = new Stopwatch();
  6418. Stopwatch stopwatch2 = new Stopwatch();
  6419. stopwatch1.Start();
  6420. stopwatch2.Start();
  6421. #region 一次性读取所有数据
  6422. // 一次性读取所有数据
  6423. result = FunsEip[plcNo]
  6424. .Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  6425. if (result.Item1 != 0)
  6426. {
  6427. //richTextBox1.AppendText("\n" + strRet);
  6428. }
  6429. else
  6430. {
  6431. //去除扫码产生的特殊字符
  6432. stPLC_MesData.BarcodeSet.strProductBarcode =
  6433. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
  6434. stPLC_MesData.BarcodeSet.strPartBarcode =
  6435. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
  6436. stPLC_MesData.BarcodeSet.strCarrierBarcode =
  6437. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
  6438. stPLC_MesData.BarcodeSet.strPCBBarcode =
  6439. FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
  6440. //richTextBox1.AppendText("\n" + "读取成功");
  6441. int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
  6442. xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
  6443. ? XiaomiDeviceState.Unknown
  6444. : (XiaomiDeviceState)xmDeviceStateInt;
  6445. CarrierBarcode = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
  6446. s9PLCData["a9OEEType"] = stPLC_MesData.iotData.beatAction; // 节拍
  6447. //报警信息
  6448. _FaultDatas = stPLC_MesData.iotData.fault_codes;
  6449. }
  6450. #endregion 一次性读取所有数据
  6451. stopwatch2.Stop();
  6452. #region 进站
  6453. try
  6454. {
  6455. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  6456. {
  6457. lock (lockObj)
  6458. {
  6459. if (!ProgressState)
  6460. {
  6461. uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
  6462. ProgressState = true;
  6463. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData,
  6464. tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
  6465. out ProgressState));
  6466. }
  6467. }
  6468. }
  6469. }
  6470. catch (Exception ex)
  6471. {
  6472. ProgressState = false;
  6473. string str = ex.StackTrace;
  6474. AddMessage_Station(stationNameStr, LogType.Error,
  6475. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6476. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6477. }
  6478. #endregion 进站
  6479. #region 出站
  6480. try
  6481. {
  6482. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  6483. {
  6484. lock (lockObj)
  6485. {
  6486. if (!ProgressState)
  6487. {
  6488. ProgressState = true;
  6489. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData,
  6490. tagBaseName + "." + tagMesCommName, stationCode, stationName,
  6491. out ProgressState));
  6492. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  6493. uuid = "";
  6494. }
  6495. }
  6496. }
  6497. }
  6498. catch (Exception ex)
  6499. {
  6500. ProgressState = false;
  6501. string str = ex.StackTrace;
  6502. AddMessage_Station(stationNameStr, LogType.Error,
  6503. $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
  6504. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6505. }
  6506. #endregion 出站
  6507. #region 节拍接口
  6508. try
  6509. {
  6510. if (stPLC_MesData.iotData.beatAction > 0)
  6511. {
  6512. int a9OEEType = Convert.ToInt32(s9PLCData["a9OEEType"]);
  6513. int a9OEETypeGOld = Convert.ToInt32(s9PLCSignal_Old["a9OEEType"]);
  6514. if (a9OEEType != a9OEETypeGOld)
  6515. {
  6516. s9PLCData["OEETypeFlag"] = "1";
  6517. }
  6518. else
  6519. {
  6520. s9PLCData["OEETypeFlag"] = "0";
  6521. }
  6522. if (s9PLCData["OEETypeFlag"].ToString() == "1" && (a9OEEType == 1 || a9OEEType == 3 || a9OEEType == 4 || a9OEEType == 5))
  6523. {
  6524. 通用节拍接口(plcNo, stationNameStr, tagBaseName + "." + tagiotComnName,
  6525. CarrierBarcode, stPLC_MesData.iotData, out res);
  6526. if (res == 1)
  6527. {
  6528. s9PLCSignal_Old["a9OEEType"] = s9PLCData["a9OEEType"];
  6529. }
  6530. else
  6531. {
  6532. s9PLCSignal_Old["a9OEEType"] = 0;
  6533. }
  6534. }
  6535. }
  6536. else {
  6537. s9PLCSignal_Old["a9OEEType"] = 0;
  6538. }
  6539. }
  6540. catch (Exception ex)
  6541. {
  6542. string str = ex.StackTrace;
  6543. AddMessage_Station(stationNameStr, LogType.Error,
  6544. $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
  6545. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6546. }
  6547. #endregion
  6548. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6549. stopwatch1.Stop();
  6550. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6551. }
  6552. else
  6553. {
  6554. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6555. AddMessage_Station(stationNameStr, LogType.Info,
  6556. "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6557. FunsEip[plcNo].Connect(); // 重连
  6558. }
  6559. }
  6560. catch (Exception ex)
  6561. {
  6562. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6563. AddMessage_Station(stationNameStr, LogType.Error,
  6564. $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6565. }
  6566. Thread.Sleep(IntervalReadPLC);
  6567. }
  6568. }
  6569. /// <summary>
  6570. /// [S9] 下料设备 - 进站
  6571. /// </summary>
  6572. /// <param name="plcNo">PLC编号</param>
  6573. /// <param name="stationNameStr">工站全称</param>
  6574. /// <param name="stPLC_MesData"></param>
  6575. /// <param name="tagMesCommName"></param>
  6576. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  6577. string tagBarsetName, out bool ProgressState)
  6578. {
  6579. Stopwatch stopwatch1 = new Stopwatch();
  6580. Stopwatch stopwatch2 = new Stopwatch();
  6581. try
  6582. {
  6583. stopwatch1.Start();
  6584. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  6585. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  6586. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  6587. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  6588. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6589. bool pass = a1Result == 1;
  6590. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  6591. //载具码验证产品码
  6592. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  6593. if (string.IsNullOrEmpty(strProductBarcode))
  6594. {
  6595. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6596. ProgressState = false;
  6597. Thread.Sleep(10000);
  6598. return;
  6599. }
  6600. sn = strProductBarcode;
  6601. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  6602. // 产品SN(物料码)校验
  6603. List<TestItem> item = new List<TestItem>();
  6604. stopwatch2.Start();
  6605. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  6606. item, MachineId, StationId, pass, "01-SLOT-01");
  6607. stopwatch2.Stop();
  6608. //指令执行结果 1:OK 110:失败
  6609. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  6610. if (mesResultFrmWeb == 1)
  6611. {
  6612. if (a1Result == 1)
  6613. {
  6614. mesResultFrmWeb = 1;
  6615. }
  6616. else
  6617. {
  6618. mesResultFrmWeb = 110;
  6619. AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
  6620. }
  6621. }
  6622. //进站结果写入PLC
  6623. CommandFromPLC resultToPlC = new CommandFromPLC();
  6624. resultToPlC.cmd = 0;
  6625. resultToPlC.cmdParam = 0; //指令参数
  6626. resultToPlC.cmdResult = mesResultFrmWeb;
  6627. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6628. }
  6629. catch (Exception ex)
  6630. {
  6631. string str = ex.StackTrace;
  6632. AddMessage(LogType.Error,
  6633. $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
  6634. str.Length - str.LastIndexOf("\\") - 1));
  6635. CommandFromPLC resultToPlC = new CommandFromPLC();
  6636. resultToPlC.cmd = 0;
  6637. resultToPlC.cmdParam = 0; //指令参数
  6638. resultToPlC.cmdResult = 110;
  6639. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6640. }
  6641. stopwatch1.Stop();
  6642. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  6643. AddMessage(LogType.Info,
  6644. stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  6645. stopwatch2.ElapsedMilliseconds + "ms");
  6646. ProgressState = false;
  6647. }
  6648. /// <summary>
  6649. /// [S9] 下料设备 - 出站接口
  6650. /// </summary>
  6651. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
  6652. string stationCode, string stationName, out bool ProgressState)
  6653. {
  6654. Stopwatch stopwatch1 = new Stopwatch();
  6655. Stopwatch stopwatch2 = new Stopwatch();
  6656. test_item_num = 0; //iot 过站明细序号
  6657. try
  6658. {
  6659. stopwatch1.Start();
  6660. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  6661. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6662. string processItem = stationName; // 测试项目
  6663. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6664. string supplierCode = ""; // 供应商代码
  6665. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6666. string batch_num = GlobalContext.BatchNumber; // 批次号
  6667. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6668. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  6669. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  6670. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  6671. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  6672. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  6673. bool pass = a1Result == 1;
  6674. //根据载具码获取产品码
  6675. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  6676. if (string.IsNullOrEmpty(strProductBarcode))
  6677. {
  6678. AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
  6679. ProgressState = false;
  6680. Thread.Sleep(10000);
  6681. return;
  6682. }
  6683. sn = strProductBarcode;
  6684. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  6685. List<TestItem> items = new List<TestItem>();
  6686. items.Add(new TestItem()
  6687. {
  6688. Parameter_name = "载具码",
  6689. Parameter_value = CarrierBarcode,
  6690. Parameter_unit = ""
  6691. });
  6692. items.Add(new TestItem()
  6693. {
  6694. Parameter_name = "产品码",
  6695. Parameter_value = sn,
  6696. Parameter_unit = ""
  6697. });
  6698. string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
  6699. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6700. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
  6701. MachineId, StationId, "", paramJson);
  6702. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  6703. if (mesResultFrmWeb == 1)
  6704. {
  6705. mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
  6706. AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
  6707. }
  6708. stopwatch2.Start();
  6709. //进站结果写入PLC
  6710. CommandFromPLC resultToPlC = new CommandFromPLC();
  6711. resultToPlC.cmd = 0;
  6712. resultToPlC.cmdParam = 0; //指令参数
  6713. resultToPlC.cmdResult = mesResultFrmWeb;
  6714. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6715. stopwatch2.Stop();
  6716. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  6717. //保存PLC返回MES数据到本地
  6718. ResponseMessage message = new ResponseMessage();
  6719. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
  6720. stPLC_MesData.mesData.nRemainCount);
  6721. if (message.result == false)
  6722. {
  6723. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  6724. }
  6725. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  6726. if (result1 == 1)
  6727. {
  6728. //载具码解除绑定
  6729. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  6730. if (message.result == false)
  6731. {
  6732. AddMessage(LogType.Error, message.text);
  6733. }
  6734. }
  6735. }
  6736. catch (Exception ex)
  6737. {
  6738. stopwatch2.Start();
  6739. CommandFromPLC resultToPlC = new CommandFromPLC();
  6740. resultToPlC.cmd = 0;
  6741. resultToPlC.cmdParam = 0; //指令参数
  6742. resultToPlC.cmdResult = 110;
  6743. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  6744. stopwatch2.Stop();
  6745. string str = ex.StackTrace;
  6746. AddMessage(LogType.Error,
  6747. $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  6748. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6749. }
  6750. stopwatch1.Stop();
  6751. AddMessage(LogType.Info,
  6752. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  6753. stopwatch2.ElapsedMilliseconds + "ms");
  6754. ProgressState = false;
  6755. }
  6756. #endregion
  6757. #endregion Xiaomi
  6758. #region PLC1 张超凡
  6759. #region [S1] Tray盘上料装备(板测)
  6760. /// <summary>
  6761. /// S1工位的数据- 触发信号上次的值
  6762. /// </summary>
  6763. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  6764. /// <summary>
  6765. /// S1工位的数据(含触发信号)
  6766. /// </summary>
  6767. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  6768. /// <summary>
  6769. /// S1工位的数据- 回写点位
  6770. /// </summary>
  6771. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6772. ///// <summary>
  6773. ///// 触发信号
  6774. ///// </summary>
  6775. //private ManualResetEvent[] MreTasks;
  6776. /// <summary>
  6777. /// [S1] Tray盘上料装备(板测)
  6778. /// </summary>
  6779. /// <param name="plcNo">PLC编号</param>
  6780. //private void ReadStation_S1(int plcNo)
  6781. //{
  6782. // // [S1] Tray盘上料装备
  6783. // // [S2] FCT
  6784. // // [S3] 值板机
  6785. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6786. // // [S5] Tray盘下料装备
  6787. // string stationCode = "[S1]";
  6788. // string stationName = "Tray盘上料装备";
  6789. // string stationNameStr = stationCode + stationName;
  6790. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6791. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6792. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  6793. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  6794. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6795. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  6796. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6797. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  6798. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  6799. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  6800. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  6801. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6802. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  6803. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  6804. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  6805. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  6806. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  6807. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  6808. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6809. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  6810. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  6811. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  6812. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  6813. // s1PLCData.Add("a1Result", 0); // 产品结果
  6814. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  6815. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  6816. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  6817. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  6818. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  6819. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6820. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  6821. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  6822. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  6823. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  6824. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  6825. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  6826. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  6827. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  6828. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  6829. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  6830. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  6831. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  6832. // while (IsRun)
  6833. // {
  6834. // try
  6835. // {
  6836. // if (!GlobalContext._IsCon_Funs1)
  6837. // {
  6838. // UpdatePLCMonitor(1, plcNo, 0);
  6839. // continue;
  6840. // }
  6841. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6842. // {
  6843. // Stopwatch stopwatch1 = new Stopwatch();
  6844. // Stopwatch stopwatch2 = new Stopwatch();
  6845. // stopwatch1.Start();
  6846. // stopwatch2.Start();
  6847. // #region 一次性读取所有数据
  6848. // // 一次性读取所有数据
  6849. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6850. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6851. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6852. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  6853. // int[] datas = data1.Concat(data2).ToArray();
  6854. // datas = datas.Concat(data3).ToArray();
  6855. // datas = datas.Concat(data4).ToArray();
  6856. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  6857. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  6858. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  6859. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  6860. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  6861. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  6862. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  6863. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  6864. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  6865. // s1PLCData["a1MES_FLAG"] = datas[109];
  6866. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  6867. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  6868. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  6869. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  6870. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  6871. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  6872. // s1PLCData["a1Result"] = datas[170];
  6873. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  6874. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  6875. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  6876. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  6877. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  6878. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  6879. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  6880. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  6881. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  6882. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  6883. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  6884. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  6885. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  6886. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  6887. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  6888. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  6889. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  6890. // s1PLCData["a1AGVUpStart"] = datas[308];
  6891. // s1PLCData["a1AGVUpEnd"] = datas[309];
  6892. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  6893. // s1PLCData["a1AGVDownStart"] = datas[321];
  6894. // s1PLCData["a1AGVDownEnd"] = datas[322];
  6895. // #endregion 一次性读取所有数据
  6896. // stopwatch2.Stop();
  6897. // #region 回写操作,写后清空flag
  6898. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  6899. // #endregion 回写操作,写后清空flag
  6900. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  6901. // try
  6902. // {
  6903. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  6904. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  6905. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  6906. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  6907. // {
  6908. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  6909. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  6910. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  6911. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  6912. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  6913. // }
  6914. // }
  6915. // catch (Exception ex)
  6916. // {
  6917. // // 6代表上位机报警
  6918. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  6919. // string str = ex.StackTrace;
  6920. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6921. // }
  6922. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  6923. // #region 上料进站校验
  6924. // try
  6925. // {
  6926. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  6927. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  6928. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  6929. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  6930. // {
  6931. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  6932. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  6933. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  6934. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  6935. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  6936. // }
  6937. // }
  6938. // catch (Exception ex)
  6939. // {
  6940. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  6941. // string str = ex.StackTrace;
  6942. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6943. // }
  6944. // #endregion 上料进站校验
  6945. // #region Tray盘上料装备-出站接口
  6946. // try
  6947. // {
  6948. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  6949. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  6950. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  6951. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  6952. // {
  6953. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  6954. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6955. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  6956. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  6957. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  6958. // }
  6959. // }
  6960. // catch (Exception ex)
  6961. // {
  6962. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  6963. // string str = ex.StackTrace;
  6964. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6965. // }
  6966. // #endregion Tray盘上料装备-出站接口
  6967. // #region Tray盘上料装备-将SN发给ICT标机
  6968. // try
  6969. // {
  6970. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  6971. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  6972. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  6973. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  6974. // {
  6975. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  6976. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  6977. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  6978. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  6979. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  6980. // }
  6981. // }
  6982. // catch (Exception ex)
  6983. // {
  6984. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  6985. // string str = ex.StackTrace;
  6986. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6987. // }
  6988. // #endregion Tray盘上料装备-将SN发给ICT标机
  6989. // #region Tray盘上料装备-点检数据
  6990. // //try
  6991. // //{
  6992. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  6993. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  6994. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  6995. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  6996. // // if (pLC_Flag && !mES_Flag) // 1 0
  6997. // // {
  6998. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  6999. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  7000. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  7001. // // }
  7002. // // else if (!pLC_Flag && mES_Flag) // 0 1
  7003. // // {
  7004. // // // 清空写给PLC的数据
  7005. // // // MES_Flag重置为0
  7006. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  7007. // // }
  7008. // //}
  7009. // //catch (Exception ex)
  7010. // //{
  7011. // // // MES_Flag 为2上位机报错
  7012. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  7013. // // string str = ex.StackTrace;
  7014. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7015. // //}
  7016. // #endregion Tray盘上料装备-点检数据
  7017. // #region 节拍接口
  7018. // try
  7019. // {
  7020. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  7021. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  7022. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  7023. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  7024. // {
  7025. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  7026. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7027. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  7028. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  7029. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  7030. // }
  7031. // }
  7032. // catch (Exception ex)
  7033. // {
  7034. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  7035. // string str = ex.StackTrace;
  7036. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7037. // }
  7038. // #endregion 节拍接口
  7039. // #region AGV上料
  7040. // // AGV上料叫AGV信号
  7041. // try
  7042. // {
  7043. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  7044. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  7045. // if (a1AGVUpCall != a1AGVUpCallOld)
  7046. // {
  7047. // if (a1AGVUpCall == 1) // 0->1
  7048. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  7049. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  7050. // }
  7051. // }
  7052. // catch (Exception ex)
  7053. // {
  7054. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  7055. // string str = ex.StackTrace;
  7056. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7057. // }
  7058. // // AGV上料完成信号
  7059. // try
  7060. // {
  7061. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  7062. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  7063. // if (a1AGVUpEnd != a1AGVUpEndOld)
  7064. // {
  7065. // if (a1AGVUpEnd == 1) // 0->1
  7066. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  7067. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  7068. // }
  7069. // }
  7070. // catch (Exception ex)
  7071. // {
  7072. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  7073. // string str = ex.StackTrace;
  7074. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7075. // }
  7076. // #endregion AGV上料
  7077. // #region AGV下料
  7078. // // AGV下料叫agv信号
  7079. // try
  7080. // {
  7081. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  7082. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  7083. // if (a1AGVDownCall != a1AGVDownCallOld)
  7084. // {
  7085. // if (a1AGVDownCall == 1) // 0->1
  7086. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  7087. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  7088. // }
  7089. // }
  7090. // catch (Exception ex)
  7091. // {
  7092. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  7093. // string str = ex.StackTrace;
  7094. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7095. // }
  7096. // // AGV下料完成信号
  7097. // try
  7098. // {
  7099. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  7100. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  7101. // if (a1AGVDownEnd != a1AGVDownEndOld)
  7102. // {
  7103. // if (a1AGVDownEnd == 1) // 0->1
  7104. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  7105. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  7106. // }
  7107. // }
  7108. // catch (Exception ex)
  7109. // {
  7110. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  7111. // string str = ex.StackTrace;
  7112. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7113. // }
  7114. // #endregion AGV下料
  7115. // #region 心跳
  7116. // try
  7117. // {
  7118. // short states = 0;
  7119. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7120. // }
  7121. // catch (Exception ex)
  7122. // {
  7123. // string str = ex.StackTrace;
  7124. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7125. // }
  7126. // #endregion 心跳
  7127. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7128. // stopwatch1.Stop();
  7129. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7130. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7131. // }
  7132. // else
  7133. // {
  7134. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7135. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  7136. // Funs[plcNo].Connect(); // 重连
  7137. // }
  7138. // }
  7139. // catch (Exception ex)
  7140. // {
  7141. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7142. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  7143. // Funs[plcNo].ReConnect();
  7144. // }
  7145. // Thread.Sleep(IntervalReadPLC);
  7146. // }
  7147. //}
  7148. /// <summary>
  7149. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  7150. /// </summary>
  7151. /// <param name="plcNo">PLC编号</param>
  7152. /// <param name="stationNameStr">工站全称</param>
  7153. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  7154. {
  7155. Stopwatch stopwatch1 = new Stopwatch();
  7156. Stopwatch stopwatch2 = new Stopwatch();
  7157. try
  7158. {
  7159. stopwatch1.Start();
  7160. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  7161. sn = sn.Replace("\0", "");
  7162. #region 查询载具上的产品信息
  7163. string cavityData = string.Empty;
  7164. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  7165. if (string.IsNullOrEmpty(cavityData))
  7166. cavityData = "";
  7167. if (snResult != 0)
  7168. {
  7169. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7170. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  7171. writeToPLC_Flag1.Adress = 2003;
  7172. writeToPLC_Flag1.Value = (short)6;
  7173. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  7174. stopwatch1.Stop();
  7175. AddMessage(LogType.Info,
  7176. stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  7177. "ms");
  7178. return;
  7179. }
  7180. #endregion 查询载具上的产品信息
  7181. string[] cavitySNs = cavityData.Split('.');
  7182. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  7183. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  7184. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  7185. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  7186. if (cavitySNs != null && cavitySNs.Length >= 2)
  7187. {
  7188. a1CavitySN1_VehicleStates = cavitySNs[0];
  7189. a1CavitySN2_VehicleStates = cavitySNs[1];
  7190. a1CavityResult1_VehicleStates = 2;
  7191. a1CavityResult2_VehicleStates = 2;
  7192. }
  7193. if (a1CavitySN1_VehicleStates == "假产品")
  7194. a1CavityResult1_VehicleStates = 3;
  7195. if (a1CavitySN2_VehicleStates == "假产品")
  7196. a1CavityResult2_VehicleStates = 3;
  7197. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7198. // 回写
  7199. stopwatch2.Start();
  7200. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  7201. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  7202. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  7203. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  7204. //// MES_Flag
  7205. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  7206. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7207. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  7208. writeToPLC_Flag.Adress = 2003;
  7209. writeToPLC_Flag.Value = mES_Flag;
  7210. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7211. {
  7212. Name = "a1CavitySN1_VehicleStates",
  7213. Adress = 2024,
  7214. ValueType = PLCValueType.String,
  7215. ValueTypeStrLength = 20,
  7216. Value = a1CavitySN1_VehicleStates
  7217. });
  7218. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  7219. {
  7220. Name = "a1CavitySN2_VehicleStates",
  7221. Adress = 2044,
  7222. ValueType = PLCValueType.String,
  7223. ValueTypeStrLength = 20,
  7224. Value = a1CavitySN2_VehicleStates
  7225. });
  7226. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  7227. {
  7228. Name = "a1CavityResult1_VehicleStates",
  7229. Adress = 2064,
  7230. ValueType = PLCValueType.Short,
  7231. Value = a1CavityResult1_VehicleStates
  7232. });
  7233. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  7234. {
  7235. Name = "a1CavityResult2_VehicleStates",
  7236. Adress = 2065,
  7237. ValueType = PLCValueType.Short,
  7238. Value = a1CavityResult2_VehicleStates
  7239. });
  7240. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  7241. stopwatch2.Stop();
  7242. }
  7243. catch (Exception ex)
  7244. {
  7245. string str = ex.StackTrace;
  7246. AddMessage_Station(stationNameStr, LogType.Error,
  7247. $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" +
  7248. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7249. // MES_Flag
  7250. stopwatch2.Start();
  7251. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7252. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7253. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  7254. writeToPLC_Flag.Adress = 2003;
  7255. writeToPLC_Flag.Value = (short)6;
  7256. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  7257. stopwatch2.Stop();
  7258. }
  7259. stopwatch1.Stop();
  7260. AddMessage(LogType.Info,
  7261. stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7262. stopwatch2.ElapsedMilliseconds + "ms");
  7263. }
  7264. /// <summary>
  7265. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  7266. /// </summary>
  7267. /// <param name="plcNo">PLC编号</param>
  7268. /// <param name="stationNameStr">工站全称</param>
  7269. private void S1上料进站校验(int plcNo, string stationNameStr)
  7270. {
  7271. Stopwatch stopwatch1 = new Stopwatch();
  7272. Stopwatch stopwatch2 = new Stopwatch();
  7273. try
  7274. {
  7275. stopwatch1.Start();
  7276. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  7277. sn = sn.Replace("\0", "");
  7278. // 保存进站数据+调用进站MES接口
  7279. List<TestItem> item = new List<TestItem>();
  7280. stopwatch2.Start();
  7281. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
  7282. item, out string errorMsg);
  7283. stopwatch2.Stop();
  7284. short a1MES_FLAG_Check = (short)result;
  7285. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  7286. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7287. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  7288. writeToPLC_Flag.Adress = 2077;
  7289. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  7290. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  7291. }
  7292. catch (Exception ex)
  7293. {
  7294. string str = ex.StackTrace;
  7295. AddMessage_Station(stationNameStr, LogType.Error,
  7296. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  7297. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7298. // MES_Flag
  7299. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7300. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7301. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  7302. writeToPLC_Flag.Adress = 2077;
  7303. writeToPLC_Flag.Value = (short)6;
  7304. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  7305. }
  7306. stopwatch1.Stop();
  7307. AddMessage(LogType.Info,
  7308. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  7309. stopwatch2.ElapsedMilliseconds + "ms");
  7310. }
  7311. /// <summary>
  7312. /// [S1] Tray盘上料装备(板测)- 出站接口
  7313. /// </summary>
  7314. /// <param name="plcNo"></param>
  7315. /// <param name="stationCode"></param>
  7316. /// <param name="stationName"></param>
  7317. private void S1出站接口(int plcNo, string stationCode, string stationName)
  7318. {
  7319. Stopwatch stopwatch1 = new Stopwatch();
  7320. Stopwatch stopwatch2 = new Stopwatch();
  7321. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7322. string stationNameStr = stationCode + stationName;
  7323. string processItem = stationName; // 测试项目
  7324. try
  7325. {
  7326. stopwatch1.Start();
  7327. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7328. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7329. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7330. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7331. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  7332. sn = sn.Replace("\0", "");
  7333. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  7334. partNo1 = partNo1.Replace("\0", "");
  7335. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  7336. partNo2 = partNo2.Replace("\0", "");
  7337. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  7338. bool pass = a1Result == 1;
  7339. stopwatch2.Start();
  7340. // 产品1
  7341. List<TestItem> items = new List<TestItem>();
  7342. items.Add(new TestItem()
  7343. {
  7344. Parameter_name = "载具码",
  7345. Parameter_value = sn,
  7346. Parameter_unit = ""
  7347. });
  7348. items.Add(new TestItem()
  7349. {
  7350. Parameter_name = "载具穴号",
  7351. Parameter_value = "1",
  7352. Parameter_unit = ""
  7353. });
  7354. items.Add(new TestItem()
  7355. {
  7356. Parameter_name = "产品结果",
  7357. Parameter_value = a1Result == 1 ? "OK" : "NG",
  7358. Parameter_unit = ""
  7359. });
  7360. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  7361. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  7362. // 产品2
  7363. items = new List<TestItem>();
  7364. items.Add(new TestItem()
  7365. {
  7366. Parameter_name = "载具码",
  7367. Parameter_value = sn,
  7368. Parameter_unit = ""
  7369. });
  7370. items.Add(new TestItem()
  7371. {
  7372. Parameter_name = "载具穴号",
  7373. Parameter_value = "2",
  7374. Parameter_unit = ""
  7375. });
  7376. items.Add(new TestItem()
  7377. {
  7378. Parameter_name = "产品结果",
  7379. Parameter_value = a1Result == 1 ? "OK" : "NG",
  7380. Parameter_unit = ""
  7381. });
  7382. int result2 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  7383. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  7384. short result = 0;
  7385. List<int> results = new List<int>() { result1, result2 };
  7386. if (result1 == 1 && result2 == 1)
  7387. result = 1;
  7388. else if (results.Contains(3))
  7389. result = 3;
  7390. else if (results.Contains(2))
  7391. result = 2;
  7392. else if (results.Contains(4))
  7393. result = 4;
  7394. else
  7395. result = 4;
  7396. stopwatch2.Stop();
  7397. #region 存储绑定数据到 边线MES系统中
  7398. if (result == 1)
  7399. {
  7400. string data = string.Concat(partNo1, ".", partNo2);
  7401. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7402. if (resultMesR != 0)
  7403. {
  7404. result = 4;
  7405. AddMessage_Station(stationNameStr, LogType.Error,
  7406. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  7407. }
  7408. }
  7409. #endregion 存储绑定数据到 边线MES系统中
  7410. // MES_Flag 为MES报错
  7411. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7412. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  7413. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7414. writeToPLC_Flag.Name = "a1MES_FLAG";
  7415. writeToPLC_Flag.Adress = 2109;
  7416. writeToPLC_Flag.Value = result;
  7417. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  7418. OnMessage(LogType.Debug,
  7419. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7420. }
  7421. catch (Exception ex)
  7422. {
  7423. stopwatch2.Restart();
  7424. // MES_Flag 为4上位机报错
  7425. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  7426. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7427. writeToPLC_Flag.Name = "a1MES_FLAG";
  7428. writeToPLC_Flag.Adress = 2109;
  7429. writeToPLC_Flag.Value = (short)4;
  7430. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  7431. stopwatch2.Stop();
  7432. string str = ex.StackTrace;
  7433. AddMessage_Station(stationNameStr, LogType.Error,
  7434. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  7435. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7436. }
  7437. stopwatch1.Stop();
  7438. AddMessage(LogType.Info,
  7439. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  7440. stopwatch2.ElapsedMilliseconds + "ms");
  7441. }
  7442. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  7443. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  7444. //{
  7445. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7446. // string stationNameStr = stationCode + stationName;
  7447. // string processItem = stationName; // 测试项目
  7448. // try
  7449. // {
  7450. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7451. // string accno = "1"; // 工序编号
  7452. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  7453. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  7454. // List<OneCheckItem> items = new List<OneCheckItem>()
  7455. // {
  7456. // new OneCheckItem()
  7457. // {
  7458. // Onecheck_name="胶圈装配行程设定上限",
  7459. // Onecheck_content="上限值",
  7460. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  7461. // },
  7462. // };
  7463. // OneCheckData oneCheckData = new OneCheckData()
  7464. // {
  7465. // Line_code = GlobalContext.LineCode,
  7466. // Line_name = GlobalContext.LineName,
  7467. // Equipment_code = equipmentCode,
  7468. // Equipment_name = equipmentCode,
  7469. // Workorder_code = workorder_code,
  7470. // Procedure_code = accno,
  7471. // Procedure_name = processItem,
  7472. // Oneckeck_values = items,
  7473. // Onecheck_empcode = "",
  7474. // Onecheck_empname = "",
  7475. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  7476. // };
  7477. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  7478. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  7479. // short result = result1 == 1 ? (short)1 : (short)2;
  7480. // // MES_Flag 为4MES报错
  7481. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  7482. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7483. // }
  7484. // catch (Exception ex)
  7485. // {
  7486. // // MES_Flag 为2上位机报错
  7487. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  7488. // string str = ex.StackTrace;
  7489. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7490. // }
  7491. //}
  7492. // ReadStation_S1_2 节拍接口+AGV
  7493. /// <summary>
  7494. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  7495. /// </summary>
  7496. /// <param name="plcNo">PLC编号</param>
  7497. /// <param name="stationNameStr">工站全称</param>
  7498. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  7499. {
  7500. Stopwatch stopwatch1 = new Stopwatch();
  7501. Stopwatch stopwatch2 = new Stopwatch();
  7502. try
  7503. {
  7504. stopwatch1.Start();
  7505. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  7506. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  7507. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  7508. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  7509. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  7510. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  7511. // ZS 将SN发给ICT标机(串口)
  7512. short a1MES_FLAG_ICT = 1;
  7513. stopwatch2.Start();
  7514. // MES_Flag
  7515. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  7516. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7517. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  7518. writeToPLC_Flag.Adress = 2182;
  7519. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  7520. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  7521. stopwatch2.Stop();
  7522. }
  7523. catch (Exception ex)
  7524. {
  7525. string str = ex.StackTrace;
  7526. AddMessage_Station(stationNameStr, LogType.Error,
  7527. $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" +
  7528. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7529. stopwatch2.Start();
  7530. // MES_Flag
  7531. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  7532. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7533. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  7534. writeToPLC_Flag.Adress = 2182;
  7535. writeToPLC_Flag.Value = (short)4;
  7536. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  7537. stopwatch2.Stop();
  7538. }
  7539. stopwatch1.Stop();
  7540. AddMessage(LogType.Info,
  7541. stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7542. stopwatch2.ElapsedMilliseconds + "ms");
  7543. }
  7544. /// <summary>
  7545. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  7546. /// </summary>
  7547. /// <param name="plcNo">PLC编号</param>
  7548. /// <param name="stationNameStr">工站全称</param>
  7549. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  7550. {
  7551. Stopwatch stopwatch1 = new Stopwatch();
  7552. Stopwatch stopwatch2 = new Stopwatch();
  7553. try
  7554. {
  7555. stopwatch1.Start();
  7556. // ZS 呼叫AGV
  7557. short a1AGVUpCall = 2;
  7558. stopwatch2.Start();
  7559. // a1AGVUpCall
  7560. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7561. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7562. writeToPLC_Flag.Name = "a1AGVUpCall";
  7563. writeToPLC_Flag.Adress = 2307;
  7564. writeToPLC_Flag.Value = a1AGVUpCall;
  7565. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  7566. stopwatch2.Stop();
  7567. }
  7568. catch (Exception ex)
  7569. {
  7570. string str = ex.StackTrace;
  7571. AddMessage_Station(stationNameStr, LogType.Error,
  7572. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  7573. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7574. // a1AGVUpCall
  7575. stopwatch2.Start();
  7576. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  7577. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7578. writeToPLC_Flag.Name = "a1AGVUpCall";
  7579. writeToPLC_Flag.Adress = 2307;
  7580. writeToPLC_Flag.Value = (short)4;
  7581. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  7582. stopwatch2.Stop();
  7583. }
  7584. stopwatch1.Stop();
  7585. AddMessage(LogType.Info,
  7586. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7587. stopwatch2.ElapsedMilliseconds + "ms");
  7588. }
  7589. /// <summary>
  7590. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  7591. /// </summary>
  7592. /// <param name="plcNo">PLC编号</param>
  7593. /// <param name="stationNameStr">工站全称</param>
  7594. private void S1AGV上料完成(int plcNo, string stationNameStr)
  7595. {
  7596. Stopwatch stopwatch1 = new Stopwatch();
  7597. Stopwatch stopwatch2 = new Stopwatch();
  7598. try
  7599. {
  7600. stopwatch1.Start();
  7601. // ZS AGV上料完成,让小车离开
  7602. short a1AGVUpEnd = 2;
  7603. stopwatch2.Start();
  7604. // a1AGVUpEnd
  7605. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7606. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7607. writeToPLC_Flag.Name = "a1AGVUpEnd";
  7608. writeToPLC_Flag.Adress = 2309;
  7609. writeToPLC_Flag.Value = a1AGVUpEnd;
  7610. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  7611. stopwatch2.Stop();
  7612. }
  7613. catch (Exception ex)
  7614. {
  7615. string str = ex.StackTrace;
  7616. AddMessage_Station(stationNameStr, LogType.Error,
  7617. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  7618. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7619. // a1AGVUpEnd
  7620. stopwatch2.Start();
  7621. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  7622. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7623. writeToPLC_Flag.Name = "a1AGVUpEnd";
  7624. writeToPLC_Flag.Adress = 2309;
  7625. writeToPLC_Flag.Value = (short)4;
  7626. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  7627. stopwatch2.Stop();
  7628. }
  7629. stopwatch1.Stop();
  7630. AddMessage(LogType.Info,
  7631. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7632. stopwatch2.ElapsedMilliseconds + "ms");
  7633. }
  7634. /// <summary>
  7635. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  7636. /// </summary>
  7637. /// <param name="plcNo">PLC编号</param>
  7638. /// <param name="stationNameStr">工站全称</param>
  7639. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  7640. {
  7641. Stopwatch stopwatch1 = new Stopwatch();
  7642. Stopwatch stopwatch2 = new Stopwatch();
  7643. try
  7644. {
  7645. stopwatch1.Start();
  7646. // ZS 呼叫AGV
  7647. short a1AGVDownCall = 2;
  7648. stopwatch2.Start();
  7649. // a1AGVDownCall
  7650. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7651. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7652. writeToPLC_Flag.Name = "a1AGVDownCall";
  7653. writeToPLC_Flag.Adress = 2320;
  7654. writeToPLC_Flag.Value = a1AGVDownCall;
  7655. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  7656. stopwatch2.Stop();
  7657. }
  7658. catch (Exception ex)
  7659. {
  7660. string str = ex.StackTrace;
  7661. AddMessage_Station(stationNameStr, LogType.Error,
  7662. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  7663. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7664. // a1AGVDownCall
  7665. stopwatch2.Start();
  7666. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  7667. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7668. writeToPLC_Flag.Name = "a1AGVDownCall";
  7669. writeToPLC_Flag.Adress = 2320;
  7670. writeToPLC_Flag.Value = (short)4;
  7671. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  7672. stopwatch2.Stop();
  7673. }
  7674. stopwatch1.Stop();
  7675. AddMessage(LogType.Info,
  7676. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7677. stopwatch2.ElapsedMilliseconds + "ms");
  7678. }
  7679. /// <summary>
  7680. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  7681. /// </summary>
  7682. /// <param name="plcNo">PLC编号</param>
  7683. /// <param name="stationNameStr">工站全称</param>
  7684. private void S1AGV下料完成(int plcNo, string stationNameStr)
  7685. {
  7686. Stopwatch stopwatch1 = new Stopwatch();
  7687. Stopwatch stopwatch2 = new Stopwatch();
  7688. try
  7689. {
  7690. stopwatch1.Start();
  7691. // ZS AGV上料完成,让小车离开
  7692. short a1AGVDownEnd = 2;
  7693. stopwatch2.Start();
  7694. // a1AGVDownEnd
  7695. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  7696. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7697. writeToPLC_Flag.Name = "a1AGVDownEnd";
  7698. writeToPLC_Flag.Adress = 2322;
  7699. writeToPLC_Flag.Value = a1AGVDownEnd;
  7700. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  7701. stopwatch2.Stop();
  7702. }
  7703. catch (Exception ex)
  7704. {
  7705. string str = ex.StackTrace;
  7706. AddMessage_Station(stationNameStr, LogType.Error,
  7707. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  7708. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7709. // a1AGVDownEnd
  7710. stopwatch2.Start();
  7711. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  7712. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7713. writeToPLC_Flag.Name = "a1AGVDownEnd";
  7714. writeToPLC_Flag.Adress = 2322;
  7715. writeToPLC_Flag.Value = (short)4;
  7716. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  7717. stopwatch2.Stop();
  7718. }
  7719. stopwatch1.Stop();
  7720. AddMessage(LogType.Info,
  7721. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  7722. stopwatch2.ElapsedMilliseconds + "ms");
  7723. }
  7724. #endregion [S1] Tray盘上料装备(板测)
  7725. #endregion PLC1 张超凡
  7726. #region PLC2 李晓奇
  7727. #region [S2] FCT(板测)
  7728. /// <summary>
  7729. /// S2工位的数据- 触发信号上次的值
  7730. /// </summary>
  7731. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  7732. /// <summary>
  7733. /// S2工位的数据(含触发信号)
  7734. /// </summary>
  7735. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  7736. /// <summary>
  7737. /// S2工位的数据- 回写点位
  7738. /// </summary>
  7739. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  7740. /// <summary>
  7741. /// [S2] FCT(板测)
  7742. /// </summary>
  7743. /// <param name="plcNo">PLC编号</param>
  7744. //private void ReadStation_S2(int plcNo)
  7745. //{
  7746. // // [S1] Tray盘上料装备
  7747. // // [S2] FCT
  7748. // // [S3] 值板机
  7749. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  7750. // // [S5] Tray盘下料装备
  7751. // /// 上位机心跳
  7752. // /// 获取设备报警数据与状态信息
  7753. // string stationCode = "[S2]";
  7754. // string stationName = "FCT";
  7755. // string stationNameStr = stationCode + stationName;
  7756. // #region 创建字典
  7757. // // 触发信号字典 赋值
  7758. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  7759. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  7760. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  7761. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  7762. // // PLC数据字典 赋值
  7763. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  7764. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  7765. // s2PLCData.Add("b1ProductSN_Check", 0);
  7766. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  7767. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  7768. // s2PLCData.Add("b1ProductSN_Unbind", "");
  7769. // s2PLCData.Add("b1ProductSN_Bind", "");
  7770. // s2PLCData.Add("b1Part1SN_Bind", "");
  7771. // s2PLCData.Add("b1Part2SN_Bind", "");
  7772. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  7773. // s2PLCData.Add("b1MES_FLAG", 0);
  7774. // s2PLCData.Add("b1ProductSN", 0);
  7775. // s2PLCData.Add("b1Part1Result", 0);
  7776. // s2PLCData.Add("b1Part2Result", 0);
  7777. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  7778. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  7779. // s2PLCData.Add("b1OEEProductSN", "");
  7780. // s2PLCData.Add("b1OEEType", 0);
  7781. // #endregion 创建字典
  7782. // while (IsRun)
  7783. // {
  7784. // try
  7785. // {
  7786. // if (!GlobalContext._IsCon_Funs2)
  7787. // {
  7788. // UpdatePLCMonitor(1, plcNo, 0);
  7789. // continue;
  7790. // }
  7791. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  7792. // {
  7793. // Stopwatch stopwatch1 = new Stopwatch();
  7794. // Stopwatch stopwatch2 = new Stopwatch();
  7795. // stopwatch1.Start();
  7796. // stopwatch2.Start();
  7797. // #region 一次性读取所有数据
  7798. // // 一次性读取所有数据
  7799. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  7800. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  7801. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  7802. // int[] datas = data1.Concat(data2).ToArray();
  7803. // datas = datas.Concat(data3).ToArray();
  7804. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  7805. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  7806. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  7807. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  7808. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  7809. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  7810. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  7811. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  7812. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  7813. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  7814. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  7815. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  7816. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  7817. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  7818. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  7819. // s2PLCData["b1MES_FLAG"] = datas[169];
  7820. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  7821. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  7822. // s2PLCData["b1Part1Result"] = datas[190];
  7823. // s2PLCData["b1Part2Result"] = datas[191];
  7824. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  7825. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  7826. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  7827. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  7828. // s2PLCData["b1OEEType"] = datas[224];
  7829. // #endregion 一次性读取所有数据
  7830. // stopwatch2.Stop();
  7831. // #region 回写操作,写后清空flag
  7832. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  7833. // #endregion 回写操作,写后清空flag
  7834. // #region 进站校验
  7835. // try
  7836. // {
  7837. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  7838. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  7839. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  7840. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  7841. // {
  7842. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  7843. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  7844. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  7845. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  7846. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  7847. // }
  7848. // }
  7849. // catch (Exception ex)
  7850. // {
  7851. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  7852. // string str = ex.StackTrace;
  7853. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7854. // }
  7855. // #endregion 进站校验
  7856. // #region 二穴载具解绑/绑定(产品换载具)
  7857. // try
  7858. // {
  7859. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  7860. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  7861. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  7862. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  7863. // {
  7864. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  7865. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  7866. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  7867. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  7868. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  7869. // }
  7870. // }
  7871. // catch (Exception ex)
  7872. // {
  7873. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  7874. // string str = ex.StackTrace;
  7875. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7876. // }
  7877. // #endregion 二穴载具解绑/绑定(产品换载具)
  7878. // #region FCT-出站接口
  7879. // try
  7880. // {
  7881. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  7882. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  7883. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  7884. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  7885. // {
  7886. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  7887. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  7888. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  7889. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  7890. // }
  7891. // }
  7892. // catch (Exception ex)
  7893. // {
  7894. // // MES_Flag 为6上位机报错
  7895. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  7896. // string str = ex.StackTrace;
  7897. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7898. // }
  7899. // #endregion FCT-出站接口
  7900. // #region 节拍接口
  7901. // try
  7902. // {
  7903. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  7904. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  7905. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  7906. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  7907. // {
  7908. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  7909. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  7910. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  7911. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  7912. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  7913. // }
  7914. // }
  7915. // catch (Exception ex)
  7916. // {
  7917. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  7918. // string str = ex.StackTrace;
  7919. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7920. // }
  7921. // #endregion 节拍接口
  7922. // #region 心跳
  7923. // try
  7924. // {
  7925. // short states = 0;
  7926. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7927. // }
  7928. // catch (Exception ex)
  7929. // {
  7930. // string str = ex.StackTrace;
  7931. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7932. // }
  7933. // #endregion 心跳
  7934. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7935. // stopwatch1.Stop();
  7936. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7937. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7938. // }
  7939. // else
  7940. // {
  7941. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7942. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  7943. // Funs[plcNo].Connect();
  7944. // }
  7945. // }
  7946. // catch (Exception ex)
  7947. // {
  7948. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7949. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  7950. // Funs[plcNo].ReConnect();
  7951. // }
  7952. // Thread.Sleep(IntervalReadPLC);
  7953. // }
  7954. //}
  7955. /// <summary>
  7956. /// [S2] FCT(板测)- 进站校验
  7957. /// </summary>
  7958. /// <param name="plcNo">PLC编号</param>
  7959. /// <param name="stationNameStr">工站全称</param>
  7960. private void S2进站校验(int plcNo, string stationNameStr)
  7961. {
  7962. Stopwatch stopwatch1 = new Stopwatch();
  7963. Stopwatch stopwatch2 = new Stopwatch();
  7964. try
  7965. {
  7966. stopwatch1.Start();
  7967. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  7968. sn = sn.Replace("\0", "");
  7969. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  7970. // 查询物料码By载具码 并判断是不是假产品
  7971. string cavityData = string.Empty;
  7972. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  7973. if (string.IsNullOrEmpty(cavityData))
  7974. cavityData = "";
  7975. if (snResult != 0)
  7976. {
  7977. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7978. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  7979. writeToPLC_Flag1.Adress = 2003;
  7980. writeToPLC_Flag1.Value = (short)6;
  7981. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  7982. stopwatch1.Stop();
  7983. AddMessage(LogType.Info,
  7984. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7985. return;
  7986. }
  7987. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  7988. string[] cavitySNs = cavityData.Split('.');
  7989. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  7990. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  7991. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  7992. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  7993. if (cavitySNs != null && cavitySNs.Length >= 2)
  7994. {
  7995. b1Part1SN_Check = cavitySNs[0];
  7996. b1Part2SN_Check = cavitySNs[1];
  7997. b1Part1Result_Check = 2;
  7998. b1Part2Result_Check = 2;
  7999. }
  8000. if (b1Part1SN_Check == "假产品")
  8001. b1Part1Result_Check = 3;
  8002. if (b1Part2SN_Check == "假产品")
  8003. b1Part2Result_Check = 3;
  8004. // 调用MES进站
  8005. stopwatch2.Start();
  8006. // 调用MES进站 - 产品1
  8007. List<TestItem> item;
  8008. int result1 = b1Part1Result_Check;
  8009. if (result1 != 3)
  8010. {
  8011. item = new List<TestItem>();
  8012. item.Add(new TestItem()
  8013. {
  8014. Parameter_name = "载具码",
  8015. Parameter_value = sn,
  8016. });
  8017. item.Add(new TestItem()
  8018. {
  8019. Parameter_name = "载具穴号",
  8020. Parameter_value = "1",
  8021. });
  8022. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8023. b1Part1SN_Check, item, out string errorMsg);
  8024. }
  8025. // 调用MES进站 - 产品2
  8026. int result2 = b1Part2Result_Check;
  8027. if (result2 != 3)
  8028. {
  8029. item = new List<TestItem>();
  8030. item.Add(new TestItem()
  8031. {
  8032. Parameter_name = "载具码",
  8033. Parameter_value = sn,
  8034. });
  8035. item.Add(new TestItem()
  8036. {
  8037. Parameter_name = "载具穴号",
  8038. Parameter_value = "2",
  8039. });
  8040. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8041. b1Part2SN_Check, item, out string errorMsg);
  8042. }
  8043. stopwatch2.Stop();
  8044. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  8045. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  8046. int result = result1;
  8047. if (result == 1)
  8048. result = result2;
  8049. short b1MES_FLAG_Check = (short)result;
  8050. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  8051. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  8052. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  8053. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  8054. //// MES_Flag
  8055. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8056. WriteToPLC_Flag
  8057. writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8058. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  8059. writeToPLC_Flag.Adress = 2003;
  8060. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  8061. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8062. {
  8063. Name = "b1Part1SN_Check",
  8064. Adress = 2024,
  8065. ValueType = PLCValueType.String,
  8066. ValueTypeStrLength = 20,
  8067. Value = b1Part1SN_Check
  8068. });
  8069. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8070. {
  8071. Name = "b1Part2SN_Check",
  8072. Adress = 2044,
  8073. ValueType = PLCValueType.String,
  8074. ValueTypeStrLength = 20,
  8075. Value = b1Part2SN_Check
  8076. });
  8077. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8078. {
  8079. Name = "b1Part1Result_Check",
  8080. Adress = 2064,
  8081. ValueType = PLCValueType.Short,
  8082. Value = b1Part1Result_Check
  8083. });
  8084. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8085. {
  8086. Name = "b1Part2Result_Check",
  8087. Adress = 2065,
  8088. ValueType = PLCValueType.Short,
  8089. Value = b1Part2Result_Check
  8090. });
  8091. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  8092. }
  8093. catch (Exception ex)
  8094. {
  8095. string str = ex.StackTrace;
  8096. AddMessage_Station(stationNameStr, LogType.Error,
  8097. $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  8098. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8099. // MES_Flag
  8100. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8101. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8102. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  8103. writeToPLC_Flag.Adress = 2003;
  8104. writeToPLC_Flag.Value = (short)6;
  8105. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  8106. }
  8107. stopwatch1.Stop();
  8108. AddMessage(LogType.Info,
  8109. stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  8110. stopwatch2.ElapsedMilliseconds + "ms");
  8111. }
  8112. /// <summary>
  8113. /// [S2] FCT(板测)- 二穴载具解绑绑定
  8114. /// </summary>
  8115. /// <param name="plcNo">PLC编号</param>
  8116. /// <param name="stationNameStr">工站全称</param>
  8117. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  8118. {
  8119. Stopwatch stopwatch1 = new Stopwatch();
  8120. Stopwatch stopwatch2 = new Stopwatch();
  8121. try
  8122. {
  8123. stopwatch1.Start();
  8124. // 产品换载具
  8125. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  8126. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  8127. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  8128. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  8129. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  8130. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  8131. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  8132. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  8133. stopwatch2.Start();
  8134. #region 查询载具上的产品信息
  8135. //string cavityData = string.Empty;
  8136. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  8137. //if (string.IsNullOrEmpty(cavityData))
  8138. // cavityData = "";
  8139. //if (snResult != 0)
  8140. //{
  8141. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8142. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  8143. // writeToPLC_Flag.Adress = 2077;
  8144. // writeToPLC_Flag.Value = (short)6;
  8145. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  8146. // stopwatch1.Stop();
  8147. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8148. // return;
  8149. //}
  8150. #endregion 查询载具上的产品信息
  8151. #region 解绑(边线MES系统)
  8152. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  8153. if (snResult != 0)
  8154. {
  8155. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8156. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  8157. writeToPLC_Flag1.Adress = 2077;
  8158. writeToPLC_Flag1.Value = (short)6;
  8159. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  8160. stopwatch1.Stop();
  8161. AddMessage(LogType.Info,
  8162. stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" +
  8163. stopwatch1.ElapsedMilliseconds + "ms");
  8164. return;
  8165. }
  8166. #endregion 解绑(边线MES系统)
  8167. #region 存储绑定数据到 边线MES系统中
  8168. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  8169. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  8170. if (snResult != 0)
  8171. {
  8172. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8173. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  8174. writeToPLC_Flag1.Adress = 2077;
  8175. writeToPLC_Flag1.Value = (short)6;
  8176. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  8177. stopwatch1.Stop();
  8178. AddMessage(LogType.Info,
  8179. stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" +
  8180. stopwatch1.ElapsedMilliseconds + "ms");
  8181. return;
  8182. }
  8183. #endregion 存储绑定数据到 边线MES系统中
  8184. stopwatch2.Stop();
  8185. short b1MES_FLAG_Unbind = 1;
  8186. // MES_Flag
  8187. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8188. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8189. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  8190. writeToPLC_Flag.Adress = 2077;
  8191. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  8192. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  8193. }
  8194. catch (Exception ex)
  8195. {
  8196. string str = ex.StackTrace;
  8197. AddMessage_Station(stationNameStr, LogType.Error,
  8198. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" +
  8199. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8200. // MES_Flag
  8201. stopwatch2.Start();
  8202. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  8203. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8204. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  8205. writeToPLC_Flag.Adress = 2077;
  8206. writeToPLC_Flag.Value = (short)6;
  8207. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  8208. stopwatch2.Stop();
  8209. }
  8210. stopwatch1.Stop();
  8211. AddMessage(LogType.Info,
  8212. stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8213. stopwatch2.ElapsedMilliseconds + "ms");
  8214. }
  8215. //// 上次采集到的SN
  8216. //private string sn_FCT = string.Empty;
  8217. /// <summary>
  8218. /// [S2] FCT(板测)- 出站数据
  8219. /// </summary>
  8220. private void S2出站接口(int plcNo, string stationCode, string stationName)
  8221. {
  8222. Stopwatch stopwatch1 = new Stopwatch();
  8223. Stopwatch stopwatch2 = new Stopwatch();
  8224. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8225. string stationNameStr = stationCode + stationName;
  8226. string processItem = stationName; // 测试项目
  8227. try
  8228. {
  8229. stopwatch1.Start();
  8230. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8231. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8232. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8233. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8234. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  8235. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  8236. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  8237. bool pass1 = b1Part1Result == 1;
  8238. bool pass2 = b1Part2Result == 1;
  8239. #region 根据 载具SN 查 物料SN
  8240. string cavityData = string.Empty;
  8241. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  8242. if (string.IsNullOrEmpty(cavityData))
  8243. cavityData = "";
  8244. if (snResult != 0)
  8245. {
  8246. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8247. writeToPLC_Flag1.Name = "b1MES_FLAG";
  8248. writeToPLC_Flag1.Adress = 2169;
  8249. writeToPLC_Flag1.Value = (short)4;
  8250. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  8251. stopwatch1.Stop();
  8252. AddMessage(LogType.Info,
  8253. stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8254. "ms");
  8255. return;
  8256. }
  8257. #endregion 根据 载具SN 查 物料SN
  8258. string[] cavitySNs = cavityData.Split('.');
  8259. string b1ProductSN1 = string.Empty;
  8260. string b1ProductSN2 = string.Empty;
  8261. if (cavitySNs != null && cavitySNs.Length >= 2)
  8262. {
  8263. b1ProductSN1 = cavitySNs[0];
  8264. b1ProductSN2 = cavitySNs[1];
  8265. }
  8266. stopwatch2.Start();
  8267. // 产品1
  8268. int result1 = 0;
  8269. if (b1ProductSN1 == "假产品")
  8270. result1 = 1;
  8271. else
  8272. {
  8273. List<TestItem> items1 = new List<TestItem>();
  8274. items1.Add(new TestItem()
  8275. {
  8276. Parameter_name = "载具码",
  8277. Parameter_value = b1ProductSN.ToString(),
  8278. Parameter_unit = ""
  8279. });
  8280. items1.Add(new TestItem()
  8281. {
  8282. Parameter_name = "载具穴号",
  8283. Parameter_value = "1",
  8284. Parameter_unit = ""
  8285. });
  8286. items1.Add(new TestItem()
  8287. {
  8288. Parameter_name = "产品结果",
  8289. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  8290. Parameter_unit = ""
  8291. });
  8292. result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  8293. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  8294. }
  8295. // 产品2
  8296. int result2 = 0;
  8297. if (b1ProductSN1 == "假产品")
  8298. result2 = 1;
  8299. else
  8300. {
  8301. List<TestItem> items2 = new List<TestItem>();
  8302. items2.Add(new TestItem()
  8303. {
  8304. Parameter_name = "载具码",
  8305. Parameter_value = b1ProductSN.ToString(),
  8306. Parameter_unit = ""
  8307. });
  8308. items2.Add(new TestItem()
  8309. {
  8310. Parameter_name = "载具穴号",
  8311. Parameter_value = "2",
  8312. Parameter_unit = ""
  8313. });
  8314. items2.Add(new TestItem()
  8315. {
  8316. Parameter_name = "产品结果",
  8317. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  8318. Parameter_unit = ""
  8319. });
  8320. result2 = SwitctProcessData_old(stationNameStr, items2, equipmentCode, processItem
  8321. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  8322. }
  8323. short result = 0;
  8324. List<int> results = new List<int>() { result1, result2 };
  8325. if (result1 == 1 && result2 == 1)
  8326. result = 1;
  8327. else if (results.Contains(3))
  8328. result = 3;
  8329. else if (results.Contains(2))
  8330. result = 2;
  8331. else if (results.Contains(4))
  8332. result = 4;
  8333. else
  8334. result = 4;
  8335. stopwatch2.Stop();
  8336. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8337. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8338. writeToPLC_Flag.Name = "b1MES_FLAG";
  8339. writeToPLC_Flag.Adress = 2169;
  8340. writeToPLC_Flag.Value = result;
  8341. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  8342. OnMessage(LogType.Debug,
  8343. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8344. }
  8345. catch (Exception ex)
  8346. {
  8347. stopwatch2.Restart();
  8348. // MES_Flag 为4上位机报错
  8349. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  8350. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8351. writeToPLC_Flag.Name = "b1MES_FLAG";
  8352. writeToPLC_Flag.Adress = 2169;
  8353. writeToPLC_Flag.Value = (short)4;
  8354. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  8355. stopwatch2.Stop();
  8356. string str = ex.StackTrace;
  8357. AddMessage_Station(stationNameStr, LogType.Error,
  8358. $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  8359. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8360. }
  8361. stopwatch1.Stop();
  8362. AddMessage(LogType.Info,
  8363. stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  8364. stopwatch2.ElapsedMilliseconds + "ms");
  8365. }
  8366. #endregion [S2] FCT(板测)
  8367. #endregion PLC2 李晓奇
  8368. #region PLC3 刘永村
  8369. #region [S3] 值板机
  8370. /// <summary>
  8371. /// S3工位的数据- 触发信号上次的值
  8372. /// </summary>
  8373. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  8374. /// <summary>
  8375. /// S3工位的数据(含触发信号)
  8376. /// </summary>
  8377. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  8378. /// <summary>
  8379. /// S3工位的数据- 回写点位
  8380. /// </summary>
  8381. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8382. /// <summary>
  8383. /// [S3] 值板机
  8384. /// </summary>
  8385. /// <param name="plcNo">PLC编号</param>
  8386. //private void ReadStation_S3(int plcNo)
  8387. //{
  8388. // // [S1] Tray盘上料装备
  8389. // // [S2] FCT
  8390. // // [S3] 值板机
  8391. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8392. // // [S5] Tray盘下料装备
  8393. // /// 上位机心跳
  8394. // /// 获取设备报警数据与状态信息
  8395. // string stationCode = "[S3]";
  8396. // string stationName = "值板机";
  8397. // string stationNameStr = stationCode + stationName;
  8398. // #region 创建字典
  8399. // // 触发信号字典 赋值
  8400. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8401. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  8402. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  8403. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8404. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8405. // // PLC数据字典 赋值
  8406. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8407. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  8408. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8409. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  8410. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  8411. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8412. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8413. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  8414. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  8415. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  8416. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  8417. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  8418. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8419. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8420. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  8421. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  8422. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  8423. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8424. // s3PLCData.Add("c1Result", 0); // 产品结果
  8425. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8426. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  8427. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  8428. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  8429. // #endregion 创建字典
  8430. // while (IsRun)
  8431. // {
  8432. // try
  8433. // {
  8434. // if (!GlobalContext._IsCon_Funs3)
  8435. // {
  8436. // UpdatePLCMonitor(1, plcNo, 0);
  8437. // continue;
  8438. // }
  8439. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8440. // {
  8441. // Stopwatch stopwatch1 = new Stopwatch();
  8442. // Stopwatch stopwatch2 = new Stopwatch();
  8443. // stopwatch1.Start();
  8444. // stopwatch2.Start();
  8445. // #region 一次性读取所有数据
  8446. // // 一次性读取所有数据
  8447. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  8448. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8449. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  8450. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  8451. // int[] datas = data1.Concat(data2).ToArray();
  8452. // datas = datas.Concat(data3).ToArray();
  8453. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  8454. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  8455. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8456. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  8457. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  8458. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  8459. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8460. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  8461. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  8462. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  8463. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  8464. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8465. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  8466. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  8467. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  8468. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  8469. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8470. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  8471. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  8472. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  8473. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  8474. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  8475. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  8476. // #endregion 一次性读取所有数据
  8477. // stopwatch2.Stop();
  8478. // #region 回写操作,写后清空flag
  8479. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  8480. // #endregion 回写操作,写后清空flag
  8481. // #region S3进站校验
  8482. // try
  8483. // {
  8484. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  8485. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  8486. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  8487. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  8488. // {
  8489. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  8490. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8491. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  8492. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8493. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  8494. // }
  8495. // }
  8496. // catch (Exception ex)
  8497. // {
  8498. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8499. // string str = ex.StackTrace;
  8500. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8501. // }
  8502. // #endregion S3进站校验
  8503. // #region S3二穴载具解绑
  8504. // try
  8505. // {
  8506. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  8507. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  8508. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  8509. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  8510. // {
  8511. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  8512. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  8513. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  8514. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  8515. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  8516. // }
  8517. // }
  8518. // catch (Exception ex)
  8519. // {
  8520. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  8521. // string str = ex.StackTrace;
  8522. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8523. // }
  8524. // #endregion S3二穴载具解绑
  8525. // #region S3二穴载具绑定
  8526. // try
  8527. // {
  8528. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  8529. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  8530. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  8531. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  8532. // {
  8533. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  8534. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  8535. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  8536. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  8537. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  8538. // }
  8539. // }
  8540. // catch (Exception ex)
  8541. // {
  8542. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  8543. // string str = ex.StackTrace;
  8544. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8545. // }
  8546. // #endregion S3二穴载具绑定
  8547. // #region S3出站接口(+一穴载具绑定)
  8548. // try
  8549. // {
  8550. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  8551. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  8552. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  8553. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  8554. // {
  8555. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  8556. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8557. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  8558. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  8559. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  8560. // }
  8561. // }
  8562. // catch (Exception ex)
  8563. // {
  8564. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  8565. // string str = ex.StackTrace;
  8566. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8567. // }
  8568. // #endregion S3出站接口(+一穴载具绑定)
  8569. // #region S3节拍接口
  8570. // try
  8571. // {
  8572. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  8573. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  8574. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  8575. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  8576. // {
  8577. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  8578. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8579. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  8580. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  8581. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  8582. // }
  8583. // }
  8584. // catch (Exception ex)
  8585. // {
  8586. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  8587. // string str = ex.StackTrace;
  8588. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8589. // }
  8590. // #endregion S3节拍接口
  8591. // #region 心跳
  8592. // try
  8593. // {
  8594. // short states = 0;
  8595. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  8596. // }
  8597. // catch (Exception ex)
  8598. // {
  8599. // string str = ex.StackTrace;
  8600. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8601. // }
  8602. // #endregion 心跳
  8603. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  8604. // stopwatch1.Stop();
  8605. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  8606. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  8607. // }
  8608. // else
  8609. // {
  8610. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8611. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  8612. // Funs[plcNo].Connect();
  8613. // }
  8614. // }
  8615. // catch (Exception ex)
  8616. // {
  8617. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8618. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  8619. // Funs[plcNo].ReConnect();
  8620. // }
  8621. // Thread.Sleep(IntervalReadPLC);
  8622. // }
  8623. //}
  8624. /// <summary>
  8625. /// [S3] 值板机- 进站校验
  8626. /// </summary>
  8627. /// <param name="plcNo">PLC编号</param>
  8628. /// <param name="stationNameStr">工站全称</param>
  8629. private void S3进站校验(int plcNo, string stationNameStr)
  8630. {
  8631. Stopwatch stopwatch1 = new Stopwatch();
  8632. Stopwatch stopwatch2 = new Stopwatch();
  8633. try
  8634. {
  8635. stopwatch1.Start();
  8636. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  8637. sn = sn.Replace("\0", "");
  8638. #region 查询载具上的产品信息
  8639. string cavityData = string.Empty;
  8640. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  8641. if (string.IsNullOrEmpty(cavityData))
  8642. cavityData = "";
  8643. if (snResult != 0)
  8644. {
  8645. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8646. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  8647. writeToPLC_Flag1.Adress = 2003;
  8648. writeToPLC_Flag1.Value = (short)6;
  8649. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  8650. stopwatch1.Stop();
  8651. AddMessage(LogType.Info,
  8652. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8653. return;
  8654. }
  8655. #endregion 查询载具上的产品信息
  8656. string[] cavitySNs = cavityData.Split('.');
  8657. string part1Str = ""; // 产品1的SN码
  8658. string part2Str = ""; // 产品2的SN码
  8659. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  8660. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  8661. if (cavitySNs != null && cavitySNs.Length >= 2)
  8662. {
  8663. part1Str = cavitySNs[0];
  8664. part2Str = cavitySNs[1];
  8665. c1Part1Result_Check = 2;
  8666. c1Part2Result_Check = 2;
  8667. }
  8668. if (part1Str == "假产品")
  8669. c1Part1Result_Check = 3;
  8670. if (part2Str == "假产品")
  8671. c1Part2Result_Check = 3;
  8672. // 调用MES进站
  8673. stopwatch2.Start();
  8674. // 调用MES进站 - 产品1
  8675. List<TestItem> item;
  8676. int result1 = c1Part1Result_Check;
  8677. if (result1 != 3)
  8678. {
  8679. item = new List<TestItem>();
  8680. item.Add(new TestItem()
  8681. {
  8682. Parameter_name = "载具码",
  8683. Parameter_value = sn,
  8684. });
  8685. item.Add(new TestItem()
  8686. {
  8687. Parameter_name = "载具穴号",
  8688. Parameter_value = "1",
  8689. });
  8690. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8691. part1Str, item, out string errorMsg);
  8692. }
  8693. // 调用MES进站 - 产品2
  8694. int result2 = c1Part2Result_Check;
  8695. if (result2 != 3)
  8696. {
  8697. item = new List<TestItem>();
  8698. item.Add(new TestItem()
  8699. {
  8700. Parameter_name = "载具码",
  8701. Parameter_value = sn,
  8702. });
  8703. item.Add(new TestItem()
  8704. {
  8705. Parameter_name = "载具穴号",
  8706. Parameter_value = "2",
  8707. });
  8708. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  8709. part2Str, item, out string errorMsg);
  8710. }
  8711. stopwatch2.Stop();
  8712. if (result1 == 2)
  8713. c1Part1Result_Check = 2;
  8714. if (result2 == 2)
  8715. c1Part2Result_Check = 2;
  8716. int result = result1;
  8717. if (result == 1)
  8718. result = result2;
  8719. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  8720. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  8721. short c1MES_FLAG_Check = (short)result;
  8722. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  8723. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  8724. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  8725. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  8726. //// MES_Flag
  8727. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8728. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8729. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  8730. writeToPLC_Flag.Adress = 2003;
  8731. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  8732. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8733. {
  8734. Name = "c1Part1Result_Check",
  8735. Adress = 2024,
  8736. ValueType = PLCValueType.Short,
  8737. Value = c1Part1Result_Check
  8738. });
  8739. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8740. {
  8741. Name = "c1Part2Result_Check",
  8742. Adress = 2025,
  8743. ValueType = PLCValueType.Short,
  8744. Value = c1Part2Result_Check
  8745. });
  8746. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8747. {
  8748. Name = "c1Part1Num_Check",
  8749. Adress = 2026,
  8750. ValueType = PLCValueType.Short,
  8751. Value = c1Part1Num_Check
  8752. });
  8753. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  8754. {
  8755. Name = "c1Part2Num_Check",
  8756. Adress = 2027,
  8757. ValueType = PLCValueType.Short,
  8758. Value = c1Part2Num_Check
  8759. });
  8760. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  8761. }
  8762. catch (Exception ex)
  8763. {
  8764. string str = ex.StackTrace;
  8765. AddMessage_Station(stationNameStr, LogType.Error,
  8766. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  8767. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8768. // MES_Flag
  8769. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8770. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8771. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  8772. writeToPLC_Flag.Adress = 2003;
  8773. writeToPLC_Flag.Value = (short)6;
  8774. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  8775. }
  8776. stopwatch1.Stop();
  8777. AddMessage(LogType.Info,
  8778. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  8779. stopwatch2.ElapsedMilliseconds + "ms");
  8780. }
  8781. /// <summary>
  8782. /// [S3] 值板机 - 二穴载具解绑
  8783. /// </summary>
  8784. /// <param name="plcNo">PLC编号</param>
  8785. /// <param name="stationNameStr">工站全称</param>
  8786. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  8787. {
  8788. Stopwatch stopwatch1 = new Stopwatch();
  8789. Stopwatch stopwatch2 = new Stopwatch();
  8790. try
  8791. {
  8792. stopwatch1.Start();
  8793. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  8794. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8795. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8796. // 解绑
  8797. #region 查询载具上的产品信息
  8798. string cavityData = string.Empty;
  8799. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8800. if (string.IsNullOrEmpty(cavityData))
  8801. cavityData = "";
  8802. if (snResult != 0)
  8803. {
  8804. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8805. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  8806. writeToPLC_Flag1.Adress = 2082;
  8807. writeToPLC_Flag1.Value = (short)6;
  8808. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  8809. stopwatch1.Stop();
  8810. AddMessage(LogType.Info,
  8811. stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8812. "ms");
  8813. return;
  8814. }
  8815. #endregion 查询载具上的产品信息
  8816. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  8817. #region 解绑
  8818. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  8819. {
  8820. // 删除
  8821. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8822. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  8823. }
  8824. else
  8825. {
  8826. string data_new = string.Join(".", cavitySNs);
  8827. // 删除再插入
  8828. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8829. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  8830. OnMessage(LogType.Debug,
  8831. $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  8832. }
  8833. #endregion 解绑
  8834. short c1MES_FLAG_Unbind = 1;
  8835. stopwatch2.Start();
  8836. // MES_Flag
  8837. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8838. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8839. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  8840. writeToPLC_Flag.Adress = 2082;
  8841. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  8842. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  8843. stopwatch2.Stop();
  8844. }
  8845. catch (Exception ex)
  8846. {
  8847. string str = ex.StackTrace;
  8848. AddMessage_Station(stationNameStr, LogType.Error,
  8849. $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" +
  8850. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8851. // MES_Flag
  8852. stopwatch2.Start();
  8853. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  8854. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8855. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  8856. writeToPLC_Flag.Adress = 2082;
  8857. writeToPLC_Flag.Value = (short)6;
  8858. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  8859. stopwatch2.Stop();
  8860. }
  8861. stopwatch1.Stop();
  8862. AddMessage(LogType.Info,
  8863. stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8864. stopwatch2.ElapsedMilliseconds + "ms");
  8865. }
  8866. /// <summary>
  8867. /// [S3] 值板机 - 二穴载具绑定
  8868. /// </summary>
  8869. /// <param name="plcNo">PLC编号</param>
  8870. /// <param name="stationNameStr">工站全称</param>
  8871. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  8872. {
  8873. Stopwatch stopwatch1 = new Stopwatch();
  8874. Stopwatch stopwatch2 = new Stopwatch();
  8875. try
  8876. {
  8877. stopwatch1.Start();
  8878. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  8879. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8880. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  8881. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  8882. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  8883. stopwatch2.Start();
  8884. #region 查询载具上的产品信息
  8885. string cavityData = string.Empty;
  8886. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8887. if (string.IsNullOrEmpty(cavityData))
  8888. cavityData = "";
  8889. if (snResult != 0)
  8890. {
  8891. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8892. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  8893. writeToPLC_Flag1.Adress = 2115;
  8894. writeToPLC_Flag1.Value = (short)6;
  8895. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  8896. stopwatch1.Stop();
  8897. AddMessage(LogType.Info,
  8898. stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  8899. "ms");
  8900. return;
  8901. }
  8902. #endregion 查询载具上的产品信息
  8903. // 产品换载具
  8904. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  8905. string partSn1 = "";
  8906. string partSn2 = "";
  8907. if (cavitySNs != null && cavitySNs.Length >= 2)
  8908. {
  8909. partSn1 = cavitySNs[0];
  8910. partSn2 = cavitySNs[1];
  8911. }
  8912. string data_new = string.Empty;
  8913. // 是否是两个穴位交换
  8914. if (c1CavityReverse_Bind == 1)
  8915. {
  8916. // 交换
  8917. data_new = string.Concat(partSn2, ".", partSn1);
  8918. }
  8919. else
  8920. {
  8921. // 不交换
  8922. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  8923. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  8924. cavitySNs[c1VehicleCavityFr_Bind] = "";
  8925. data_new = string.Join(".", cavitySNs);
  8926. }
  8927. // 删除再插入
  8928. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  8929. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  8930. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  8931. stopwatch2.Stop();
  8932. short c1MES_FLAG_Bind = 1;
  8933. // MES_Flag
  8934. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  8935. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8936. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  8937. writeToPLC_Flag.Adress = 2115;
  8938. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  8939. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  8940. }
  8941. catch (Exception ex)
  8942. {
  8943. string str = ex.StackTrace;
  8944. AddMessage_Station(stationNameStr, LogType.Error,
  8945. $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" +
  8946. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8947. // MES_Flag
  8948. stopwatch2.Start();
  8949. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  8950. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8951. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  8952. writeToPLC_Flag.Adress = 2115;
  8953. writeToPLC_Flag.Value = (short)6;
  8954. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  8955. stopwatch2.Stop();
  8956. }
  8957. stopwatch1.Stop();
  8958. AddMessage(LogType.Info,
  8959. stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  8960. stopwatch2.ElapsedMilliseconds + "ms");
  8961. }
  8962. //// 上次采集到的SN
  8963. //private string sn_值板机 = string.Empty;
  8964. /// <summary>
  8965. /// [S3] 值板机 - 出站接口
  8966. /// </summary>
  8967. /// <param name="plcNo">PLC编号</param>
  8968. private void S3出站接口(int plcNo, string stationCode, string stationName)
  8969. {
  8970. Stopwatch stopwatch1 = new Stopwatch();
  8971. Stopwatch stopwatch2 = new Stopwatch();
  8972. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8973. string stationNameStr = stationCode + stationName;
  8974. string processItem = stationName; // 测试项目
  8975. try
  8976. {
  8977. stopwatch1.Start();
  8978. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8979. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8980. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8981. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8982. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  8983. sn = sn.Replace("\0", "");
  8984. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  8985. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  8986. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  8987. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  8988. bool pass = c1Result == 1;
  8989. // 查sn
  8990. #region 查询载具上的产品信息
  8991. string cavityData = string.Empty;
  8992. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  8993. if (string.IsNullOrEmpty(cavityData))
  8994. cavityData = "";
  8995. if (snResult != 0)
  8996. {
  8997. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8998. writeToPLC_Flag1.Name = "c1MES_FLAG";
  8999. writeToPLC_Flag1.Adress = 2150;
  9000. writeToPLC_Flag1.Value = (short)4;
  9001. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  9002. stopwatch1.Stop();
  9003. AddMessage(LogType.Info,
  9004. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9005. return;
  9006. }
  9007. #endregion 查询载具上的产品信息
  9008. string[] cavitySNs = cavityData.Split('.');
  9009. string productSN = "";
  9010. if (cavitySNs != null && cavitySNs.Length >= 2)
  9011. {
  9012. productSN = cavitySNs[c1VehicleCavity];
  9013. cavitySNs[c1VehicleCavity] = "";
  9014. }
  9015. stopwatch2.Start();
  9016. List<TestItem> items = new List<TestItem>();
  9017. items.Add(new TestItem()
  9018. {
  9019. Parameter_name = "二穴载具码",
  9020. Parameter_value = c1ProductSN_Check,
  9021. Parameter_unit = ""
  9022. });
  9023. items.Add(new TestItem()
  9024. {
  9025. Parameter_name = "二穴载具穴号",
  9026. Parameter_value = c1VehicleCavity.ToString(),
  9027. Parameter_unit = ""
  9028. });
  9029. items.Add(new TestItem()
  9030. {
  9031. Parameter_name = "一穴载具码",
  9032. Parameter_value = sn,
  9033. Parameter_unit = ""
  9034. });
  9035. items.Add(new TestItem()
  9036. {
  9037. Parameter_name = "一穴载具穴号",
  9038. Parameter_value = "1",
  9039. Parameter_unit = ""
  9040. });
  9041. items.Add(new TestItem()
  9042. {
  9043. Parameter_name = "产品结果",
  9044. Parameter_value = c1Result == 1 ? "OK" : "NG",
  9045. Parameter_unit = ""
  9046. });
  9047. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  9048. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  9049. short result = (short)result1;
  9050. stopwatch2.Stop();
  9051. #region 存储绑定数据到 边线MES系统中
  9052. if (result == 1)
  9053. {
  9054. string data = string.Concat(productSN);
  9055. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  9056. if (resultMesR != 0)
  9057. {
  9058. result = 4;
  9059. AddMessage_Station(stationNameStr, LogType.Error,
  9060. $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  9061. }
  9062. }
  9063. #endregion 存储绑定数据到 边线MES系统中
  9064. #region 产品从 来源载具(二穴载具)中删除
  9065. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  9066. {
  9067. // 删除
  9068. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  9069. OnMessage(LogType.Debug,
  9070. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  9071. }
  9072. else
  9073. {
  9074. string data_new = string.Join(".", cavitySNs);
  9075. // 删除再插入
  9076. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  9077. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  9078. OnMessage(LogType.Debug,
  9079. $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  9080. }
  9081. #endregion 产品从 来源载具(二穴载具)中删除
  9082. // MES_Flag 为MES报错
  9083. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9084. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  9085. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9086. writeToPLC_Flag.Name = "c1MES_FLAG";
  9087. writeToPLC_Flag.Adress = 2150;
  9088. writeToPLC_Flag.Value = result;
  9089. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  9090. OnMessage(LogType.Debug,
  9091. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9092. }
  9093. catch (Exception ex)
  9094. {
  9095. stopwatch2.Restart();
  9096. // MES_Flag 为4上位机报错
  9097. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  9098. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9099. writeToPLC_Flag.Name = "c1MES_FLAG";
  9100. writeToPLC_Flag.Adress = 2150;
  9101. writeToPLC_Flag.Value = (short)4;
  9102. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  9103. stopwatch2.Stop();
  9104. string str = ex.StackTrace;
  9105. AddMessage_Station(stationNameStr, LogType.Error,
  9106. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  9107. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9108. }
  9109. stopwatch1.Stop();
  9110. AddMessage(LogType.Info,
  9111. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  9112. stopwatch2.ElapsedMilliseconds + "ms");
  9113. }
  9114. #endregion [S3] 值板机
  9115. #endregion PLC3 刘永村
  9116. #region PLC4 刘果段
  9117. #region [S4] 取放桁架
  9118. /// <summary>
  9119. /// S4工位的数据- 触发信号上次的值
  9120. /// </summary>
  9121. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  9122. /// <summary>
  9123. /// S4工位的数据(含触发信号)
  9124. /// </summary>
  9125. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  9126. /// <summary>
  9127. /// S4工位的数据- 回写点位
  9128. /// </summary>
  9129. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  9130. /// <summary>
  9131. /// [S4] 取放桁架
  9132. /// </summary>
  9133. /// <param name="plcNo">PLC编号</param>
  9134. //private void ReadStation_S4(int plcNo)
  9135. //{
  9136. // // [S1] Tray盘上料装备
  9137. // // [S2] FCT
  9138. // // [S3] 值板机
  9139. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  9140. // // [S5] Tray盘下料装备
  9141. // /// 上位机心跳
  9142. // /// 获取设备报警数据与状态信息
  9143. // string stationCode = "[S4_1]";
  9144. // string stationName = "载具下线装备";
  9145. // string stationNameStr = stationCode + stationName;
  9146. // string stationCode2 = "[S4_2]";
  9147. // string stationName2 = "桁架";
  9148. // string stationNameStr2 = stationCode2 + stationName2;
  9149. // string stationCode3 = "[S4_3]";
  9150. // string stationName3 = "提升机1";
  9151. // string stationNameStr3 = stationCode3 + stationName3;
  9152. // string stationCode4 = "[S4_4]";
  9153. // string stationName4 = "提升机2";
  9154. // string stationNameStr4 = stationCode4 + stationName4;
  9155. // string stationCode5 = "[S4_5]";
  9156. // string stationName5 = "载具上线装备";
  9157. // string stationNameStr5 = stationCode5 + stationName5;
  9158. // #region 创建字典
  9159. // // 触发信号字典 赋值
  9160. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9161. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  9162. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  9163. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9164. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  9165. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  9166. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  9167. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9168. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  9169. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  9170. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9171. // // PLC数据字典 赋值
  9172. // // 载具下线装备(弹夹上线)
  9173. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9174. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  9175. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  9176. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  9177. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  9178. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  9179. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  9180. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  9181. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  9182. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  9183. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  9184. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  9185. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  9186. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  9187. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  9188. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  9189. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  9190. // s4PLCData.Add("d1Result", 0); // 产品结果
  9191. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9192. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  9193. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  9194. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  9195. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  9196. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  9197. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  9198. // // 真空标机(提升机)
  9199. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  9200. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  9201. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  9202. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  9203. // s4PLCData.Add("d3Result", 0); // 产品结果
  9204. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  9205. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  9206. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  9207. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  9208. // s4PLCData.Add("d4Result", 0); // 产品结果
  9209. // // 载具上线装备(弹夹下线)
  9210. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  9211. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  9212. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  9213. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  9214. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  9215. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  9216. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  9217. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  9218. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  9219. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  9220. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  9221. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  9222. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  9223. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  9224. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  9225. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  9226. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  9227. // s4PLCData.Add("d5Result", 0); // 产品结果
  9228. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  9229. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  9230. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  9231. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  9232. // #endregion 创建字典
  9233. // while (IsRun)
  9234. // {
  9235. // try
  9236. // {
  9237. // if (!GlobalContext._IsCon_Funs4)
  9238. // {
  9239. // UpdatePLCMonitor(1, plcNo, 0);
  9240. // continue;
  9241. // }
  9242. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  9243. // {
  9244. // Stopwatch stopwatch1 = new Stopwatch();
  9245. // Stopwatch stopwatch2 = new Stopwatch();
  9246. // stopwatch1.Start();
  9247. // stopwatch2.Start();
  9248. // #region 一次性读取所有数据
  9249. // // 载具下线装备(弹夹上线)
  9250. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  9251. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  9252. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  9253. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  9254. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  9255. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  9256. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  9257. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  9258. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  9259. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  9260. // int[] datas = data1.Concat(data2).ToArray();
  9261. // datas = datas.Concat(data3).ToArray();
  9262. // datas = datas.Concat(data4).ToArray();
  9263. // datas = datas.Concat(data5).ToArray();
  9264. // datas = datas.Concat(data6).ToArray();
  9265. // datas = datas.Concat(data7).ToArray();
  9266. // datas = datas.Concat(data8).ToArray();
  9267. // datas = datas.Concat(data9).ToArray();
  9268. // datas = datas.Concat(data10).ToArray();
  9269. // // 载具下线装备(弹夹上线)
  9270. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  9271. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  9272. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  9273. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  9274. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  9275. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  9276. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  9277. // s4PLCData["d1MES_FLAG"] = datas[65];
  9278. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  9279. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  9280. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  9281. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  9282. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  9283. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  9284. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  9285. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  9286. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  9287. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  9288. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  9289. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  9290. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  9291. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  9292. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  9293. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  9294. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  9295. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  9296. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  9297. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  9298. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  9299. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  9300. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  9301. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  9302. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  9303. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  9304. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  9305. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  9306. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  9307. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  9308. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  9309. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  9310. // s4PLCData["d1Result"] = datas[386];
  9311. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  9312. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  9313. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  9314. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  9315. // s4PLCData["d1OEEType"] = datas[419];
  9316. // // 桁架(查询标机中弹夹的状态)
  9317. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  9318. // s4PLCData["d2BulletclipStates"] = datas[431];
  9319. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  9320. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  9321. // // 真空标机
  9322. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  9323. // s4PLCData["d3MES_FLAG"] = datas[463];
  9324. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  9325. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  9326. // s4PLCData["d3Result"] = datas[484];
  9327. // s4PLCData["d3Type"] = datas[485];
  9328. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  9329. // s4PLCData["d4MES_FLAG"] = datas[496];
  9330. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  9331. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  9332. // s4PLCData["d4Result"] = datas[517];
  9333. // s4PLCData["d4Type"] = datas[518];
  9334. // // 载具上线装备(弹夹下线)
  9335. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  9336. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  9337. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  9338. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  9339. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  9340. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  9341. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  9342. // s4PLCData["d5MES_FLAG"] = datas[591];
  9343. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  9344. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  9345. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  9346. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  9347. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  9348. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  9349. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  9350. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  9351. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  9352. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  9353. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  9354. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  9355. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  9356. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  9357. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  9358. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  9359. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  9360. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  9361. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  9362. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  9363. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  9364. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  9365. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  9366. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  9367. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  9368. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  9369. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  9370. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  9371. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  9372. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  9373. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  9374. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  9375. // s4PLCData["d5Result"] = datas[912];
  9376. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  9377. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  9378. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  9379. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  9380. // s4PLCData["d5OEEType"] = datas[945];
  9381. // #endregion 一次性读取所有数据
  9382. // stopwatch2.Stop();
  9383. // #region 回写操作,写后清空flag
  9384. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  9385. // #endregion 回写操作,写后清空flag
  9386. // // N801A-S4_1 弹夹扫码
  9387. // #region N801A-S4_1 弹夹扫码
  9388. // try
  9389. // {
  9390. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  9391. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  9392. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  9393. // {
  9394. // if (d1BulletclipScanCode == 1) // 0->1
  9395. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  9396. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  9397. // }
  9398. // }
  9399. // catch (Exception ex)
  9400. // {
  9401. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  9402. // string str = ex.StackTrace;
  9403. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9404. // }
  9405. // #endregion N801A-S4_1 弹夹扫码
  9406. // // N801A-S4_1 载具扫码
  9407. // #region N801A-S4_1 载具扫码
  9408. // try
  9409. // {
  9410. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  9411. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  9412. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  9413. // {
  9414. // if (d1VehicleScanCode == 1) // 0->1
  9415. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  9416. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  9417. // }
  9418. // }
  9419. // catch (Exception ex)
  9420. // {
  9421. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  9422. // string str = ex.StackTrace;
  9423. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9424. // }
  9425. // #endregion N801A-S4_1 载具扫码
  9426. // // N801A-S4_1 出站接口
  9427. // #region N801A-S4_1 出站接口
  9428. // try
  9429. // {
  9430. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  9431. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  9432. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  9433. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  9434. // {
  9435. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  9436. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  9437. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  9438. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  9439. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  9440. // }
  9441. // }
  9442. // catch (Exception ex)
  9443. // {
  9444. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  9445. // string str = ex.StackTrace;
  9446. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9447. // }
  9448. // #endregion N801A-S4_1 出站接口
  9449. // // N801A-S4_1 节拍接口
  9450. // #region N801A-S4_1 节拍接口
  9451. // try
  9452. // {
  9453. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  9454. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  9455. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  9456. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  9457. // {
  9458. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  9459. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  9460. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  9461. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  9462. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  9463. // }
  9464. // }
  9465. // catch (Exception ex)
  9466. // {
  9467. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  9468. // string str = ex.StackTrace;
  9469. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9470. // }
  9471. // #endregion N801A-S4_1 节拍接口
  9472. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  9473. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  9474. // try
  9475. // {
  9476. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  9477. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  9478. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  9479. // {
  9480. // if (d2BulletclipScanCode == 1) // 0->1
  9481. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  9482. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  9483. // }
  9484. // }
  9485. // catch (Exception ex)
  9486. // {
  9487. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  9488. // string str = ex.StackTrace;
  9489. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9490. // }
  9491. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  9492. // // N801A-S4_3 真空标机1 数据
  9493. // #region N801A-S4_3 真空标机1
  9494. // try
  9495. // {
  9496. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  9497. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  9498. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  9499. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  9500. // {
  9501. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  9502. // {
  9503. // int stationType = (int)s4PLCData["d3Type"];
  9504. // if (stationType == 1)
  9505. // {
  9506. // // S4_3进站接口
  9507. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  9508. // }
  9509. // else if (stationType == 2)
  9510. // {
  9511. // // S4_3出站接口
  9512. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  9513. // }
  9514. // }
  9515. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  9516. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  9517. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  9518. // }
  9519. // }
  9520. // catch (Exception ex)
  9521. // {
  9522. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  9523. // string str = ex.StackTrace;
  9524. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9525. // }
  9526. // #endregion N801A-S4_3 真空标机1
  9527. // // N801A-S4_4 真空标机2 数据
  9528. // #region N801A-S4_4 真空标机2
  9529. // try
  9530. // {
  9531. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  9532. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  9533. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  9534. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  9535. // {
  9536. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  9537. // {
  9538. // int stationType = (int)s4PLCData["d4Type"];
  9539. // if (stationType == 1)
  9540. // {
  9541. // // S4_4进站接口
  9542. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  9543. // }
  9544. // else if (stationType == 2)
  9545. // {
  9546. // // S4_4出站接口
  9547. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  9548. // }
  9549. // }
  9550. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  9551. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  9552. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  9553. // }
  9554. // }
  9555. // catch (Exception ex)
  9556. // {
  9557. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  9558. // string str = ex.StackTrace;
  9559. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9560. // }
  9561. // #endregion N801A-S4_4 真空标机2
  9562. // // N801A-S4_5 弹夹扫码 数据
  9563. // #region N801A-S4_5 弹夹扫码
  9564. // try
  9565. // {
  9566. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  9567. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  9568. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  9569. // {
  9570. // if (d5BulletclipScanCode == 1) // 0->1
  9571. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  9572. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  9573. // }
  9574. // }
  9575. // catch (Exception ex)
  9576. // {
  9577. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  9578. // string str = ex.StackTrace;
  9579. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9580. // }
  9581. // #endregion N801A-S4_5 弹夹扫码
  9582. // // N801A-S4_5 载具扫码 数据
  9583. // #region N801A-S4_5 载具扫码
  9584. // try
  9585. // {
  9586. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  9587. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  9588. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  9589. // {
  9590. // if (d5VehicleScanCode == 1) // 0->1
  9591. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  9592. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  9593. // }
  9594. // }
  9595. // catch (Exception ex)
  9596. // {
  9597. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  9598. // string str = ex.StackTrace;
  9599. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9600. // }
  9601. // #endregion N801A-S4_5 载具扫码
  9602. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  9603. // #region N801A-S4_5 出站接口
  9604. // try
  9605. // {
  9606. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  9607. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  9608. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  9609. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  9610. // {
  9611. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  9612. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  9613. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  9614. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  9615. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  9616. // }
  9617. // }
  9618. // catch (Exception ex)
  9619. // {
  9620. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  9621. // string str = ex.StackTrace;
  9622. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9623. // }
  9624. // #endregion N801A-S4_5 出站接口
  9625. // // N801A-S4_5 节拍接口 数据
  9626. // #region N801A-S4_5 节拍接口
  9627. // try
  9628. // {
  9629. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  9630. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  9631. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  9632. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  9633. // {
  9634. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  9635. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  9636. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  9637. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  9638. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  9639. // }
  9640. // }
  9641. // catch (Exception ex)
  9642. // {
  9643. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  9644. // string str = ex.StackTrace;
  9645. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9646. // }
  9647. // #endregion N801A-S4_5 节拍接口
  9648. // #region 心跳
  9649. // try
  9650. // {
  9651. // short states = 0;
  9652. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  9653. // }
  9654. // catch (Exception ex)
  9655. // {
  9656. // string str = ex.StackTrace;
  9657. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9658. // }
  9659. // #endregion 心跳
  9660. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  9661. // stopwatch1.Stop();
  9662. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  9663. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  9664. // }
  9665. // else
  9666. // {
  9667. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9668. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  9669. // Funs[plcNo].Connect();
  9670. // }
  9671. // }
  9672. // catch (Exception ex)
  9673. // {
  9674. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9675. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  9676. // Funs[plcNo].ReConnect();
  9677. // }
  9678. // Thread.Sleep(IntervalReadPLC);
  9679. // }
  9680. //}
  9681. /// <summary>
  9682. /// [S4] 取放桁架 - S4_1弹夹扫码
  9683. /// </summary>
  9684. /// <param name="plcNo">PLC编号</param>
  9685. /// <param name="stationNameStr">工站全称</param>
  9686. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  9687. {
  9688. Stopwatch stopwatch1 = new Stopwatch();
  9689. Stopwatch stopwatch2 = new Stopwatch();
  9690. try
  9691. {
  9692. stopwatch1.Start();
  9693. // ZS 弹夹扫码
  9694. string d1BulletclipCode = " "; // 扫到的码
  9695. short d1BulletclipScanCode = 2;
  9696. stopwatch2.Start();
  9697. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  9698. //// MES_Flag
  9699. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  9700. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9701. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  9702. writeToPLC_Flag.Adress = 2002;
  9703. writeToPLC_Flag.Value = d1BulletclipScanCode;
  9704. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  9705. {
  9706. Name = "d1BulletclipCode",
  9707. Adress = 2003,
  9708. ValueType = PLCValueType.String,
  9709. ValueTypeStrLength = 20,
  9710. Value = d1BulletclipCode
  9711. });
  9712. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  9713. stopwatch2.Stop();
  9714. }
  9715. catch (Exception ex)
  9716. {
  9717. string str = ex.StackTrace;
  9718. AddMessage_Station(stationNameStr, LogType.Error,
  9719. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  9720. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9721. stopwatch2.Start();
  9722. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  9723. //// MES_Flag
  9724. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  9725. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9726. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  9727. writeToPLC_Flag.Adress = 2002;
  9728. writeToPLC_Flag.Value = (short)6;
  9729. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  9730. {
  9731. Name = "d1BulletclipCode",
  9732. Adress = 2003,
  9733. ValueType = PLCValueType.String,
  9734. ValueTypeStrLength = 20,
  9735. Value = " "
  9736. });
  9737. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  9738. stopwatch2.Stop();
  9739. }
  9740. stopwatch1.Stop();
  9741. AddMessage(LogType.Info,
  9742. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9743. stopwatch2.ElapsedMilliseconds + "ms");
  9744. }
  9745. /// <summary>
  9746. /// [S4] 取放桁架 - S4_1载具扫码
  9747. /// </summary>
  9748. /// <param name="plcNo">PLC编号</param>
  9749. /// <param name="stationNameStr">工站全称</param>
  9750. private void S4_1载具扫码(int plcNo, string stationNameStr)
  9751. {
  9752. Stopwatch stopwatch1 = new Stopwatch();
  9753. Stopwatch stopwatch2 = new Stopwatch();
  9754. try
  9755. {
  9756. stopwatch1.Start();
  9757. // ZS 载具扫码
  9758. string d1VehicleCode = ""; // 扫到的码
  9759. short d1VehicleScanCode = 2;
  9760. #region 进站
  9761. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  9762. {
  9763. #region 查询载具上的产品信息
  9764. string cavityData = string.Empty;
  9765. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  9766. if (string.IsNullOrEmpty(cavityData))
  9767. cavityData = "";
  9768. if (snResult != 0)
  9769. {
  9770. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9771. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  9772. writeToPLC_Flag1.Adress = 2033;
  9773. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  9774. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9775. {
  9776. Name = "d1VehicleCode",
  9777. Adress = 2034,
  9778. ValueType = PLCValueType.String,
  9779. ValueTypeStrLength = 20,
  9780. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  9781. });
  9782. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  9783. stopwatch1.Stop();
  9784. AddMessage(LogType.Info,
  9785. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9786. "ms");
  9787. return;
  9788. }
  9789. string[] cavitySNs = cavityData.Split('.');
  9790. string partNo = "";
  9791. if (cavitySNs != null && cavitySNs.Length >= 1)
  9792. {
  9793. partNo = cavitySNs[0];
  9794. }
  9795. #endregion 查询载具上的产品信息
  9796. List<TestItem> item = new List<TestItem>();
  9797. item.Add(new TestItem()
  9798. {
  9799. Parameter_name = "载具码",
  9800. Parameter_value = d1VehicleCode,
  9801. });
  9802. item.Add(new TestItem()
  9803. {
  9804. Parameter_name = "载具穴号",
  9805. Parameter_value = "1",
  9806. });
  9807. stopwatch2.Start();
  9808. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  9809. partNo, item, out string errorMsg);
  9810. stopwatch2.Stop();
  9811. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  9812. }
  9813. #endregion 进站
  9814. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  9815. //// MES_Flag
  9816. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  9817. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9818. writeToPLC_Flag.Name = "d1VehicleScanCode";
  9819. writeToPLC_Flag.Adress = 2033;
  9820. writeToPLC_Flag.Value = d1VehicleScanCode;
  9821. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9822. {
  9823. Name = "d1VehicleCode",
  9824. Adress = 2034,
  9825. ValueType = PLCValueType.String,
  9826. ValueTypeStrLength = 20,
  9827. Value = d1VehicleCode
  9828. });
  9829. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  9830. }
  9831. catch (Exception ex)
  9832. {
  9833. string str = ex.StackTrace;
  9834. AddMessage_Station(stationNameStr, LogType.Error,
  9835. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  9836. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9837. stopwatch2.Start();
  9838. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  9839. //// MES_Flag
  9840. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  9841. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9842. writeToPLC_Flag.Name = "d1VehicleScanCode";
  9843. writeToPLC_Flag.Adress = 2033;
  9844. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  9845. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  9846. {
  9847. Name = "d1VehicleCode",
  9848. Adress = 2034,
  9849. ValueType = PLCValueType.String,
  9850. ValueTypeStrLength = 20,
  9851. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  9852. });
  9853. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  9854. stopwatch2.Stop();
  9855. }
  9856. stopwatch1.Stop();
  9857. AddMessage(LogType.Info,
  9858. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  9859. stopwatch2.ElapsedMilliseconds + "ms");
  9860. }
  9861. // 上次采集到的SN
  9862. //private string sn_S4_1出站接口 = string.Empty;
  9863. /// <summary>
  9864. /// [S4] 取放桁架 - S4_1出站接口
  9865. /// </summary>
  9866. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  9867. {
  9868. Stopwatch stopwatch1 = new Stopwatch();
  9869. Stopwatch stopwatch2 = new Stopwatch();
  9870. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9871. string stationNameStr = stationCode + stationName;
  9872. string processItem = stationName; // 测试项目
  9873. try
  9874. {
  9875. stopwatch1.Start();
  9876. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9877. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9878. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9879. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9880. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  9881. sn = sn.Replace("\0", "");
  9882. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  9883. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  9884. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  9885. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  9886. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  9887. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  9888. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  9889. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  9890. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  9891. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  9892. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  9893. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  9894. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  9895. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  9896. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  9897. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  9898. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  9899. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  9900. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  9901. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  9902. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  9903. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  9904. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  9905. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  9906. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  9907. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  9908. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  9909. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  9910. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  9911. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  9912. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  9913. bool pass = d1Result == 1;
  9914. // 存 载具SN列表
  9915. List<string> vehicleCodes = new List<string>()
  9916. {
  9917. d1VehicleCode1, d1VehicleCode2, d1VehicleCode3, d1VehicleCode4, d1VehicleCode5,
  9918. d1VehicleCode6, d1VehicleCode7, d1VehicleCode8, d1VehicleCode9, d1VehicleCode10,
  9919. d1VehicleCode11, d1VehicleCode12, d1VehicleCode13, d1VehicleCode14, d1VehicleCode15
  9920. };
  9921. // 统一查 产品SN列表
  9922. List<string> partNos = new List<string>();
  9923. foreach (string vehicleCode in vehicleCodes)
  9924. {
  9925. if (string.IsNullOrEmpty(vehicleCode))
  9926. partNos.Add("");
  9927. else
  9928. {
  9929. string partNo = "";
  9930. #region 查询载具上的产品信息
  9931. string cavityData = string.Empty;
  9932. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  9933. if (string.IsNullOrEmpty(cavityData))
  9934. cavityData = "";
  9935. if (snResult != 0)
  9936. {
  9937. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9938. writeToPLC_Flag1.Name = "d1MES_FLAG";
  9939. writeToPLC_Flag1.Adress = 2065;
  9940. writeToPLC_Flag1.Value = (short)4;
  9941. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  9942. stopwatch1.Stop();
  9943. AddMessage(LogType.Info,
  9944. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  9945. "ms");
  9946. return;
  9947. }
  9948. string[] cavitySNs = cavityData.Split('.');
  9949. if (cavitySNs != null && cavitySNs.Length >= 1)
  9950. partNo = cavitySNs[0];
  9951. #endregion 查询载具上的产品信息
  9952. partNos.Add(partNo);
  9953. }
  9954. }
  9955. // 统一上传
  9956. stopwatch2.Start();
  9957. List<int> results = new List<int>();
  9958. for (int i = 0; i < partNos.Count; i++)
  9959. {
  9960. string index = (i + 1).ToString(); // 弹夹穴号
  9961. if (string.IsNullOrEmpty(partNos[i]))
  9962. results.Add(1);
  9963. else
  9964. {
  9965. List<TestItem> items1 = new List<TestItem>();
  9966. items1.Add(new TestItem()
  9967. {
  9968. Parameter_name = "弹夹码",
  9969. Parameter_value = sn,
  9970. Parameter_unit = ""
  9971. });
  9972. items1.Add(new TestItem()
  9973. {
  9974. Parameter_name = "弹夹穴号",
  9975. Parameter_value = index,
  9976. Parameter_unit = ""
  9977. });
  9978. items1.Add(new TestItem()
  9979. {
  9980. Parameter_name = "载具码",
  9981. Parameter_value = vehicleCodes[i],
  9982. Parameter_unit = ""
  9983. });
  9984. items1.Add(new TestItem()
  9985. {
  9986. Parameter_name = "载具穴号",
  9987. Parameter_value = "1",
  9988. Parameter_unit = ""
  9989. });
  9990. items1.Add(new TestItem()
  9991. {
  9992. Parameter_name = "产品结果",
  9993. Parameter_value = d1Result == 1 ? "OK" : "NG",
  9994. Parameter_unit = ""
  9995. });
  9996. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  9997. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  9998. results.Add(result1);
  9999. }
  10000. }
  10001. short result = 0;
  10002. if (results.All(a => a == 1))
  10003. result = 1;
  10004. else if (results.Contains(3))
  10005. result = 3;
  10006. else if (results.Contains(2))
  10007. result = 2;
  10008. else if (results.Contains(4))
  10009. result = 4;
  10010. else
  10011. result = 4;
  10012. stopwatch2.Stop();
  10013. #region 存储绑定数据到 边线MES系统中
  10014. if (result == 1)
  10015. {
  10016. string data = string.Join(".", vehicleCodes);
  10017. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  10018. if (resultMesR != 0)
  10019. {
  10020. result = 4;
  10021. AddMessage_Station(stationNameStr, LogType.Error,
  10022. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  10023. }
  10024. }
  10025. #endregion 存储绑定数据到 边线MES系统中
  10026. // MES_Flag 为4MES报错
  10027. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10028. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10029. writeToPLC_Flag.Name = "d1MES_FLAG";
  10030. writeToPLC_Flag.Adress = 2065;
  10031. writeToPLC_Flag.Value = result;
  10032. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  10033. OnMessage(LogType.Debug,
  10034. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  10035. }
  10036. catch (Exception ex)
  10037. {
  10038. stopwatch2.Restart();
  10039. // MES_Flag 为4上位机报错
  10040. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  10041. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10042. writeToPLC_Flag.Name = "d1MES_FLAG";
  10043. writeToPLC_Flag.Adress = 2065;
  10044. writeToPLC_Flag.Value = (short)4;
  10045. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  10046. stopwatch2.Stop();
  10047. string str = ex.StackTrace;
  10048. AddMessage_Station(stationNameStr, LogType.Error,
  10049. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10050. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10051. }
  10052. stopwatch1.Stop();
  10053. AddMessage(LogType.Info,
  10054. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10055. stopwatch2.ElapsedMilliseconds + "ms");
  10056. }
  10057. /// <summary>
  10058. /// [S4] 取放桁架 - S4_1节拍接口
  10059. /// </summary>
  10060. /// <param name="plcNo">PLC编号</param>
  10061. /// <param name="stationNameStr">工站全称</param>
  10062. private void S4_1节拍接口(int plcNo, string stationNameStr)
  10063. {
  10064. Stopwatch stopwatch1 = new Stopwatch();
  10065. Stopwatch stopwatch2 = new Stopwatch();
  10066. string resultStr = string.Empty;
  10067. try
  10068. {
  10069. stopwatch1.Start();
  10070. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  10071. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  10072. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  10073. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  10074. if (!actionBool)
  10075. {
  10076. stopwatch2.Start();
  10077. // MES_Flag
  10078. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10079. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10080. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  10081. writeToPLC_Flag1.Adress = 2398;
  10082. writeToPLC_Flag1.Value = (short)4;
  10083. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  10084. stopwatch2.Stop();
  10085. AddMessage(LogType.Info,
  10086. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  10087. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  10088. return;
  10089. }
  10090. string d1OEEPartNo = string.Empty; // 物料码
  10091. if (string.IsNullOrEmpty(d1OEEProductSN))
  10092. {
  10093. stopwatch2.Start();
  10094. // MES_Flag
  10095. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10096. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10097. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  10098. writeToPLC_Flag1.Adress = 2398;
  10099. writeToPLC_Flag1.Value = (short)1;
  10100. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  10101. stopwatch2.Stop();
  10102. AddMessage(LogType.Info,
  10103. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10104. stopwatch2.ElapsedMilliseconds + "ms");
  10105. return;
  10106. }
  10107. else
  10108. {
  10109. // 查产品SN ZS
  10110. d1OEEPartNo = "Test";
  10111. }
  10112. short d1OEEMES_FLAG = 0;
  10113. // 上传OEE
  10114. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  10115. d1OEEMES_FLAG = result.Item1;
  10116. resultStr = result.Item2;
  10117. stopwatch2.Start();
  10118. // MES_Flag
  10119. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10120. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10121. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  10122. writeToPLC_Flag.Adress = 2398;
  10123. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  10124. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  10125. stopwatch2.Stop();
  10126. }
  10127. catch (Exception ex)
  10128. {
  10129. string str = ex.StackTrace;
  10130. AddMessage_Station(stationNameStr, LogType.Error,
  10131. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  10132. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10133. // MES_Flag
  10134. stopwatch2.Start();
  10135. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  10136. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10137. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  10138. writeToPLC_Flag.Adress = 2398;
  10139. writeToPLC_Flag.Value = (short)4;
  10140. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  10141. stopwatch2.Stop();
  10142. }
  10143. stopwatch1.Stop();
  10144. AddMessage(LogType.Info,
  10145. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10146. stopwatch2.ElapsedMilliseconds + "ms");
  10147. }
  10148. /// <summary>
  10149. /// [S4] 取放桁架 - S4_2桁架
  10150. /// </summary>
  10151. /// <param name="plcNo">PLC编号</param>
  10152. /// <param name="stationNameStr">工站全称</param>
  10153. private void S4_2桁架(int plcNo, string stationNameStr)
  10154. {
  10155. Stopwatch stopwatch1 = new Stopwatch();
  10156. Stopwatch stopwatch2 = new Stopwatch();
  10157. try
  10158. {
  10159. stopwatch1.Start();
  10160. // ZS 弹夹扫码
  10161. string d2BulletclipCode = " "; // 扫到的码
  10162. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  10163. short d2BulletclipScanCode = 2;
  10164. stopwatch2.Start();
  10165. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  10166. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  10167. //// MES_Flag
  10168. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10169. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10170. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  10171. writeToPLC_Flag.Adress = 2430;
  10172. writeToPLC_Flag.Value = d2BulletclipScanCode;
  10173. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10174. {
  10175. Name = "d2BulletclipCode",
  10176. Adress = 2432,
  10177. ValueType = PLCValueType.String,
  10178. ValueTypeStrLength = 20,
  10179. Value = d2BulletclipCode
  10180. });
  10181. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10182. {
  10183. Name = "d2BulletclipStates",
  10184. Adress = 2431,
  10185. ValueType = PLCValueType.Short,
  10186. Value = d2BulletclipStates
  10187. });
  10188. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  10189. stopwatch2.Stop();
  10190. }
  10191. catch (Exception ex)
  10192. {
  10193. string str = ex.StackTrace;
  10194. AddMessage_Station(stationNameStr, LogType.Error,
  10195. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10196. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10197. stopwatch2.Start();
  10198. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  10199. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  10200. // MES_Flag
  10201. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  10202. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10203. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  10204. writeToPLC_Flag.Adress = 2430;
  10205. writeToPLC_Flag.Value = (short)6;
  10206. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10207. {
  10208. Name = "d2BulletclipCode",
  10209. Adress = 2432,
  10210. ValueType = PLCValueType.String,
  10211. ValueTypeStrLength = 20,
  10212. Value = " "
  10213. });
  10214. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  10215. {
  10216. Name = "d2BulletclipStates",
  10217. Adress = 2431,
  10218. ValueType = PLCValueType.Short,
  10219. Value = (short)0
  10220. });
  10221. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  10222. stopwatch2.Stop();
  10223. }
  10224. stopwatch1.Stop();
  10225. AddMessage(LogType.Info,
  10226. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10227. stopwatch2.ElapsedMilliseconds + "ms");
  10228. }
  10229. // 上次采集到的SN
  10230. //private string sn_S4_3进站接口 = string.Empty;
  10231. /// <summary>
  10232. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  10233. /// </summary>
  10234. private void S4_3进站接口(int plcNo, string stationNameStr)
  10235. {
  10236. Stopwatch stopwatch1 = new Stopwatch();
  10237. Stopwatch stopwatch2 = new Stopwatch();
  10238. try
  10239. {
  10240. stopwatch1.Start();
  10241. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  10242. sn = sn.Replace("\0", "");
  10243. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  10244. #region 查询15个载具码
  10245. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10246. string vehicleData = string.Empty;
  10247. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10248. if (string.IsNullOrEmpty(vehicleData))
  10249. vehicleData = "";
  10250. if (snResult != 0)
  10251. {
  10252. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10253. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10254. writeToPLC_Flag1.Adress = 2463;
  10255. writeToPLC_Flag1.Value = (short)4;
  10256. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10257. stopwatch1.Stop();
  10258. AddMessage(LogType.Info,
  10259. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10260. return;
  10261. }
  10262. string[] cavitySNs = vehicleData.Split('.');
  10263. if (cavitySNs != null && cavitySNs.Length > 0)
  10264. {
  10265. for (int i = 0; i < cavitySNs.Length; i++)
  10266. {
  10267. if (string.IsNullOrEmpty(cavitySNs[i]))
  10268. vehicleCodes.Add("");
  10269. else
  10270. vehicleCodes.Add(cavitySNs[i]);
  10271. }
  10272. }
  10273. #endregion 查询15个载具码
  10274. #region 查询15个产品SN
  10275. List<string> portNos = new List<string>(); // 15个产品SN
  10276. foreach (string vehicleCode in vehicleCodes)
  10277. {
  10278. if (string.IsNullOrEmpty(vehicleCode))
  10279. portNos.Add("");
  10280. else
  10281. {
  10282. // 查询
  10283. string cavityData = string.Empty;
  10284. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10285. if (string.IsNullOrEmpty(cavityData))
  10286. cavityData = "";
  10287. if (snResult1 != 0)
  10288. {
  10289. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10290. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10291. writeToPLC_Flag1.Adress = 2463;
  10292. writeToPLC_Flag1.Value = (short)4;
  10293. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10294. stopwatch1.Stop();
  10295. AddMessage(LogType.Info,
  10296. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  10297. stopwatch1.ElapsedMilliseconds + "ms");
  10298. return;
  10299. }
  10300. string[] partSNs = cavityData.Split('.');
  10301. if (partSNs != null && partSNs.Length >= 1)
  10302. portNos.Add(partSNs[0]);
  10303. else
  10304. portNos.Add("");
  10305. }
  10306. }
  10307. #endregion 查询15个产品SN
  10308. // 调用MES进站(最多15个)
  10309. stopwatch2.Start();
  10310. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  10311. for (int i = 0; i < vehicleCodes.Count; i++)
  10312. {
  10313. // 循环进站
  10314. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  10315. {
  10316. // 产品SN(物料码)校验
  10317. string portNo = portNos[i];
  10318. List<TestItem> item = new List<TestItem>();
  10319. item.Add(new TestItem()
  10320. {
  10321. Parameter_name = "弹夹码",
  10322. Parameter_value = sn,
  10323. });
  10324. item.Add(new TestItem()
  10325. {
  10326. Parameter_name = "弹夹穴位",
  10327. Parameter_value = (i + 1).ToString(),
  10328. });
  10329. item.Add(new TestItem()
  10330. {
  10331. Parameter_name = "载具码",
  10332. Parameter_value = vehicleCodes[i],
  10333. });
  10334. item.Add(new TestItem()
  10335. {
  10336. Parameter_name = "载具穴号",
  10337. Parameter_value = "1",
  10338. });
  10339. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  10340. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  10341. }
  10342. }
  10343. stopwatch2.Stop();
  10344. short result = 0;
  10345. bool haveMesWarn = results.Contains(5);
  10346. bool havePCWarn = results.Contains(6);
  10347. if (haveMesWarn)
  10348. result = 2; // 5->2
  10349. else if (havePCWarn)
  10350. result = 6; // 6->4
  10351. else
  10352. result = 1;
  10353. // MES_Flag 为4MES报错
  10354. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10355. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10356. writeToPLC_Flag.Name = "d3MES_FLAG";
  10357. writeToPLC_Flag.Adress = 2463;
  10358. writeToPLC_Flag.Value = result;
  10359. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10360. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10361. }
  10362. catch (Exception ex)
  10363. {
  10364. stopwatch2.Stop();
  10365. // MES_Flag 为4上位机报错
  10366. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  10367. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10368. writeToPLC_Flag.Name = "d3MES_FLAG";
  10369. writeToPLC_Flag.Adress = 2463;
  10370. writeToPLC_Flag.Value = (short)4;
  10371. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10372. string str = ex.StackTrace;
  10373. AddMessage_Station(stationNameStr, LogType.Error,
  10374. $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10375. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10376. }
  10377. stopwatch1.Stop();
  10378. AddMessage(LogType.Info,
  10379. stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  10380. stopwatch2.ElapsedMilliseconds + "ms");
  10381. }
  10382. // 上次采集到的SN
  10383. //private string sn_S4_3出站接口 = string.Empty;
  10384. /// <summary>
  10385. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  10386. /// </summary>
  10387. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  10388. {
  10389. Stopwatch stopwatch1 = new Stopwatch();
  10390. Stopwatch stopwatch2 = new Stopwatch();
  10391. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10392. string stationNameStr = stationCode + stationName;
  10393. string processItem = stationName; // 测试项目
  10394. try
  10395. {
  10396. stopwatch1.Start();
  10397. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10398. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10399. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10400. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10401. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  10402. sn = sn.Replace("\0", "");
  10403. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  10404. bool isPass = d3Result == 1; // 产品结果 bool
  10405. #region 查询15个载具码
  10406. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10407. string vehicleData = string.Empty;
  10408. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10409. if (string.IsNullOrEmpty(vehicleData))
  10410. vehicleData = "";
  10411. if (snResult1 != 0)
  10412. {
  10413. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10414. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10415. writeToPLC_Flag1.Adress = 2463;
  10416. writeToPLC_Flag1.Value = (short)4;
  10417. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10418. stopwatch1.Stop();
  10419. AddMessage(LogType.Info,
  10420. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10421. return;
  10422. }
  10423. string[] cavitySNs = vehicleData.Split('.');
  10424. if (cavitySNs != null && cavitySNs.Length > 0)
  10425. {
  10426. for (int i = 0; i < cavitySNs.Length; i++)
  10427. {
  10428. if (string.IsNullOrEmpty(cavitySNs[i]))
  10429. vehicleCodes.Add("");
  10430. else
  10431. vehicleCodes.Add(cavitySNs[i]);
  10432. }
  10433. }
  10434. #endregion 查询15个载具码
  10435. // 统一查 产品SN列表
  10436. List<string> partNos = new List<string>();
  10437. foreach (string vehicleCode in vehicleCodes)
  10438. {
  10439. if (string.IsNullOrEmpty(vehicleCode))
  10440. partNos.Add("");
  10441. else
  10442. {
  10443. string partNo = "";
  10444. #region 查询载具上的产品信息
  10445. string cavityData = string.Empty;
  10446. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10447. if (string.IsNullOrEmpty(cavityData))
  10448. cavityData = "";
  10449. if (snResult != 0)
  10450. {
  10451. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10452. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10453. writeToPLC_Flag1.Adress = 2463;
  10454. writeToPLC_Flag1.Value = (short)4;
  10455. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10456. stopwatch1.Stop();
  10457. AddMessage(LogType.Info,
  10458. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10459. "ms");
  10460. return;
  10461. }
  10462. string[] partSNs = cavityData.Split('.');
  10463. if (partSNs != null && partSNs.Length >= 1)
  10464. partNo = partSNs[0];
  10465. #endregion 查询载具上的产品信息
  10466. partNos.Add(partNo);
  10467. }
  10468. }
  10469. // 统一上传 - 调用MES出站
  10470. stopwatch2.Start();
  10471. List<int> results = new List<int>();
  10472. for (int i = 0; i < partNos.Count; i++)
  10473. {
  10474. string index = (i + 1).ToString(); // 弹夹穴号
  10475. if (string.IsNullOrEmpty(partNos[i]))
  10476. results.Add(1);
  10477. else
  10478. {
  10479. List<TestItem> items1 = new List<TestItem>();
  10480. items1.Add(new TestItem()
  10481. {
  10482. Parameter_name = "弹夹码",
  10483. Parameter_value = sn,
  10484. Parameter_unit = ""
  10485. });
  10486. items1.Add(new TestItem()
  10487. {
  10488. Parameter_name = "弹夹穴号",
  10489. Parameter_value = index,
  10490. Parameter_unit = ""
  10491. });
  10492. items1.Add(new TestItem()
  10493. {
  10494. Parameter_name = "载具码",
  10495. Parameter_value = vehicleCodes[i],
  10496. Parameter_unit = ""
  10497. });
  10498. items1.Add(new TestItem()
  10499. {
  10500. Parameter_name = "载具穴号",
  10501. Parameter_value = "1",
  10502. Parameter_unit = ""
  10503. });
  10504. items1.Add(new TestItem()
  10505. {
  10506. Parameter_name = "产品结果",
  10507. Parameter_value = d3Result == 1 ? "OK" : "NG",
  10508. Parameter_unit = ""
  10509. });
  10510. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  10511. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  10512. results.Add(result1);
  10513. }
  10514. }
  10515. short result = 0;
  10516. if (results.All(a => a == 1))
  10517. result = 1;
  10518. else if (results.Contains(3))
  10519. result = 3;
  10520. else if (results.Contains(2))
  10521. result = 2;
  10522. else if (results.Contains(4))
  10523. result = 4;
  10524. else
  10525. result = 4;
  10526. stopwatch2.Stop();
  10527. // MES_Flag 为4MES报错
  10528. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10529. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10530. writeToPLC_Flag.Name = "d3MES_FLAG";
  10531. writeToPLC_Flag.Adress = 2463;
  10532. writeToPLC_Flag.Value = result;
  10533. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10534. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10535. }
  10536. catch (Exception ex)
  10537. {
  10538. stopwatch2.Restart();
  10539. // MES_Flag 为4上位机报错
  10540. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  10541. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10542. writeToPLC_Flag.Name = "d3MES_FLAG";
  10543. writeToPLC_Flag.Adress = 2463;
  10544. writeToPLC_Flag.Value = (short)4;
  10545. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  10546. string str = ex.StackTrace;
  10547. AddMessage_Station(stationNameStr, LogType.Error,
  10548. $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10549. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10550. stopwatch2.Stop();
  10551. }
  10552. stopwatch1.Stop();
  10553. AddMessage(LogType.Info,
  10554. stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10555. stopwatch2.ElapsedMilliseconds + "ms");
  10556. }
  10557. // 上次采集到的SN
  10558. //private string sn_S4_4进站接口 = string.Empty;
  10559. /// <summary>
  10560. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  10561. /// </summary>
  10562. private void S4_4进站接口(int plcNo, string stationNameStr)
  10563. {
  10564. Stopwatch stopwatch1 = new Stopwatch();
  10565. Stopwatch stopwatch2 = new Stopwatch();
  10566. try
  10567. {
  10568. stopwatch1.Start();
  10569. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  10570. sn = sn.Replace("\0", "");
  10571. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  10572. #region 查询15个载具码
  10573. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10574. string vehicleData = string.Empty;
  10575. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10576. if (string.IsNullOrEmpty(vehicleData))
  10577. vehicleData = "";
  10578. if (snResult != 0)
  10579. {
  10580. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10581. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10582. writeToPLC_Flag1.Adress = 2463;
  10583. writeToPLC_Flag1.Value = (short)4;
  10584. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10585. stopwatch1.Stop();
  10586. AddMessage(LogType.Info,
  10587. stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10588. return;
  10589. }
  10590. string[] cavitySNs = vehicleData.Split('.');
  10591. if (cavitySNs != null && cavitySNs.Length > 0)
  10592. {
  10593. for (int i = 0; i < cavitySNs.Length; i++)
  10594. {
  10595. if (string.IsNullOrEmpty(cavitySNs[i]))
  10596. vehicleCodes.Add("");
  10597. else
  10598. vehicleCodes.Add(cavitySNs[i]);
  10599. }
  10600. }
  10601. #endregion 查询15个载具码
  10602. #region 查询15个产品SN
  10603. List<string> portNos = new List<string>(); // 15个产品SN
  10604. foreach (string vehicleCode in vehicleCodes)
  10605. {
  10606. if (string.IsNullOrEmpty(vehicleCode))
  10607. portNos.Add("");
  10608. else
  10609. {
  10610. // 查询
  10611. string cavityData = string.Empty;
  10612. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10613. if (string.IsNullOrEmpty(cavityData))
  10614. cavityData = "";
  10615. if (snResult1 != 0)
  10616. {
  10617. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10618. writeToPLC_Flag1.Name = "d3MES_FLAG";
  10619. writeToPLC_Flag1.Adress = 2463;
  10620. writeToPLC_Flag1.Value = (short)4;
  10621. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  10622. stopwatch1.Stop();
  10623. AddMessage(LogType.Info,
  10624. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" +
  10625. stopwatch1.ElapsedMilliseconds + "ms");
  10626. return;
  10627. }
  10628. string[] partSNs = cavityData.Split('.');
  10629. if (partSNs != null && partSNs.Length >= 1)
  10630. portNos.Add(partSNs[0]);
  10631. else
  10632. portNos.Add("");
  10633. }
  10634. }
  10635. #endregion 查询15个产品SN
  10636. // 调用MES进站(最多15个)
  10637. stopwatch2.Start();
  10638. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  10639. for (int i = 0; i < vehicleCodes.Count; i++)
  10640. {
  10641. // 循环进站
  10642. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  10643. {
  10644. // 产品SN(物料码)校验
  10645. string portNo = portNos[i];
  10646. List<TestItem> item = new List<TestItem>();
  10647. item.Add(new TestItem()
  10648. {
  10649. Parameter_name = "弹夹码",
  10650. Parameter_value = sn,
  10651. });
  10652. item.Add(new TestItem()
  10653. {
  10654. Parameter_name = "弹夹穴位",
  10655. Parameter_value = (i + 1).ToString(),
  10656. });
  10657. item.Add(new TestItem()
  10658. {
  10659. Parameter_name = "载具码",
  10660. Parameter_value = vehicleCodes[i],
  10661. });
  10662. item.Add(new TestItem()
  10663. {
  10664. Parameter_name = "载具穴号",
  10665. Parameter_value = "1",
  10666. });
  10667. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode,
  10668. GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  10669. }
  10670. }
  10671. stopwatch2.Stop();
  10672. short result = 0;
  10673. bool haveMesWarn = results.Contains(5);
  10674. bool havePCWarn = results.Contains(6);
  10675. if (haveMesWarn)
  10676. result = 2; // 5->2
  10677. else if (havePCWarn)
  10678. result = 6; // 6->4
  10679. else
  10680. result = 1;
  10681. // MES_Flag 为4MES报错
  10682. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10683. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10684. writeToPLC_Flag.Name = "d4MES_FLAG";
  10685. writeToPLC_Flag.Adress = 2496;
  10686. writeToPLC_Flag.Value = result;
  10687. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10688. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10689. }
  10690. catch (Exception ex)
  10691. {
  10692. stopwatch2.Stop();
  10693. // MES_Flag 为4上位机报错
  10694. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  10695. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10696. writeToPLC_Flag.Name = "d4MES_FLAG";
  10697. writeToPLC_Flag.Adress = 2496;
  10698. writeToPLC_Flag.Value = (short)4;
  10699. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10700. string str = ex.StackTrace;
  10701. AddMessage_Station(stationNameStr, LogType.Error,
  10702. $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10703. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10704. }
  10705. stopwatch1.Stop();
  10706. AddMessage(LogType.Info,
  10707. stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  10708. stopwatch2.ElapsedMilliseconds + "ms");
  10709. }
  10710. // 上次采集到的SN
  10711. //private string sn_S4_4出站接口 = string.Empty;
  10712. /// <summary>
  10713. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  10714. /// </summary>
  10715. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  10716. {
  10717. Stopwatch stopwatch1 = new Stopwatch();
  10718. Stopwatch stopwatch2 = new Stopwatch();
  10719. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  10720. string stationNameStr = stationCode + stationName;
  10721. string processItem = stationName; // 测试项目
  10722. try
  10723. {
  10724. stopwatch1.Start();
  10725. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  10726. //string batch_num = GlobalContext.BatchNumber; // 批次号
  10727. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  10728. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  10729. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  10730. sn = sn.Replace("\0", "");
  10731. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  10732. bool isPass = d4Result == 1; // 产品结果 bool
  10733. #region 查询15个载具码
  10734. List<string> vehicleCodes = new List<string>(); // 15个载具码
  10735. string vehicleData = string.Empty;
  10736. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  10737. if (string.IsNullOrEmpty(vehicleData))
  10738. vehicleData = "";
  10739. if (snResult1 != 0)
  10740. {
  10741. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10742. writeToPLC_Flag1.Name = "d4MES_FLAG";
  10743. writeToPLC_Flag1.Adress = 2496;
  10744. writeToPLC_Flag1.Value = (short)4;
  10745. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  10746. stopwatch1.Stop();
  10747. AddMessage(LogType.Info,
  10748. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  10749. return;
  10750. }
  10751. string[] cavitySNs = vehicleData.Split('.');
  10752. if (cavitySNs != null && cavitySNs.Length > 0)
  10753. {
  10754. for (int i = 0; i < cavitySNs.Length; i++)
  10755. {
  10756. if (string.IsNullOrEmpty(cavitySNs[i]))
  10757. vehicleCodes.Add("");
  10758. else
  10759. vehicleCodes.Add(cavitySNs[i]);
  10760. }
  10761. }
  10762. #endregion 查询15个载具码
  10763. // 统一查 产品SN列表
  10764. List<string> partNos = new List<string>();
  10765. foreach (string vehicleCode in vehicleCodes)
  10766. {
  10767. if (string.IsNullOrEmpty(vehicleCode))
  10768. partNos.Add("");
  10769. else
  10770. {
  10771. string partNo = "";
  10772. #region 查询载具上的产品信息
  10773. string cavityData = string.Empty;
  10774. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  10775. if (string.IsNullOrEmpty(cavityData))
  10776. cavityData = "";
  10777. if (snResult != 0)
  10778. {
  10779. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10780. writeToPLC_Flag1.Name = "d4MES_FLAG";
  10781. writeToPLC_Flag1.Adress = 2496;
  10782. writeToPLC_Flag1.Value = (short)4;
  10783. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  10784. stopwatch1.Stop();
  10785. AddMessage(LogType.Info,
  10786. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10787. "ms");
  10788. return;
  10789. }
  10790. string[] partSNs = cavityData.Split('.');
  10791. if (partSNs != null && partSNs.Length >= 1)
  10792. partNo = partSNs[0];
  10793. #endregion 查询载具上的产品信息
  10794. partNos.Add(partNo);
  10795. }
  10796. }
  10797. // 调用MES出站
  10798. stopwatch2.Start();
  10799. // 统一上传
  10800. List<int> results = new List<int>();
  10801. for (int i = 0; i < partNos.Count; i++)
  10802. {
  10803. string index = (i + 1).ToString(); // 弹夹穴号
  10804. if (string.IsNullOrEmpty(partNos[i]))
  10805. results.Add(1);
  10806. else
  10807. {
  10808. List<TestItem> items1 = new List<TestItem>();
  10809. items1.Add(new TestItem()
  10810. {
  10811. Parameter_name = "弹夹码",
  10812. Parameter_value = sn,
  10813. Parameter_unit = ""
  10814. });
  10815. items1.Add(new TestItem()
  10816. {
  10817. Parameter_name = "弹夹穴号",
  10818. Parameter_value = index,
  10819. Parameter_unit = ""
  10820. });
  10821. items1.Add(new TestItem()
  10822. {
  10823. Parameter_name = "载具码",
  10824. Parameter_value = vehicleCodes[i],
  10825. Parameter_unit = ""
  10826. });
  10827. items1.Add(new TestItem()
  10828. {
  10829. Parameter_name = "载具穴号",
  10830. Parameter_value = "1",
  10831. Parameter_unit = ""
  10832. });
  10833. items1.Add(new TestItem()
  10834. {
  10835. Parameter_name = "产品结果",
  10836. Parameter_value = d4Result == 1 ? "OK" : "NG",
  10837. Parameter_unit = ""
  10838. });
  10839. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  10840. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  10841. results.Add(result1);
  10842. }
  10843. }
  10844. short result = 0;
  10845. if (results.All(a => a == 1))
  10846. result = 1;
  10847. else if (results.Contains(3))
  10848. result = 3;
  10849. else if (results.Contains(2))
  10850. result = 2;
  10851. else if (results.Contains(4))
  10852. result = 4;
  10853. else
  10854. result = 4;
  10855. stopwatch2.Stop();
  10856. // MES_Flag 为4MES报错
  10857. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  10858. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10859. writeToPLC_Flag.Name = "d4MES_FLAG";
  10860. writeToPLC_Flag.Adress = 2496;
  10861. writeToPLC_Flag.Value = result;
  10862. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10863. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  10864. }
  10865. catch (Exception ex)
  10866. {
  10867. stopwatch2.Restart();
  10868. // MES_Flag 为4上位机报错
  10869. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  10870. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10871. writeToPLC_Flag.Name = "d4MES_FLAG";
  10872. writeToPLC_Flag.Adress = 2496;
  10873. writeToPLC_Flag.Value = (short)4;
  10874. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  10875. string str = ex.StackTrace;
  10876. AddMessage_Station(stationNameStr, LogType.Error,
  10877. $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  10878. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10879. stopwatch2.Stop();
  10880. }
  10881. stopwatch1.Stop();
  10882. AddMessage(LogType.Info,
  10883. stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  10884. stopwatch2.ElapsedMilliseconds + "ms");
  10885. }
  10886. /// <summary>
  10887. /// [S4] 取放桁架 - S4_5弹夹扫码
  10888. /// </summary>
  10889. /// <param name="plcNo">PLC编号</param>
  10890. /// <param name="stationNameStr">工站全称</param>
  10891. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  10892. {
  10893. Stopwatch stopwatch1 = new Stopwatch();
  10894. Stopwatch stopwatch2 = new Stopwatch();
  10895. try
  10896. {
  10897. stopwatch1.Start();
  10898. // ZS 弹夹扫码
  10899. string d5BulletclipCode = " "; // 扫到的码
  10900. short d5BulletclipScanCode = 2;
  10901. stopwatch2.Start();
  10902. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  10903. //// MES_Flag
  10904. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  10905. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10906. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  10907. writeToPLC_Flag.Adress = 2528;
  10908. writeToPLC_Flag.Value = d5BulletclipScanCode;
  10909. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10910. {
  10911. Name = "d5BulletclipCode",
  10912. Adress = 2529,
  10913. ValueType = PLCValueType.String,
  10914. ValueTypeStrLength = 20,
  10915. Value = d5BulletclipCode
  10916. });
  10917. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  10918. stopwatch2.Stop();
  10919. }
  10920. catch (Exception ex)
  10921. {
  10922. string str = ex.StackTrace;
  10923. AddMessage_Station(stationNameStr, LogType.Error,
  10924. $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" +
  10925. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  10926. stopwatch2.Start();
  10927. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  10928. //// MES_Flag
  10929. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  10930. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  10931. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  10932. writeToPLC_Flag.Adress = 2528;
  10933. writeToPLC_Flag.Value = (short)6;
  10934. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10935. {
  10936. Name = "d5BulletclipCode",
  10937. Adress = 2529,
  10938. ValueType = PLCValueType.String,
  10939. ValueTypeStrLength = 20,
  10940. Value = " "
  10941. });
  10942. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  10943. stopwatch2.Stop();
  10944. }
  10945. stopwatch1.Stop();
  10946. AddMessage(LogType.Info,
  10947. stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  10948. stopwatch2.ElapsedMilliseconds + "ms");
  10949. }
  10950. /// <summary>
  10951. /// [S4] 取放桁架 - S4_5载具扫码
  10952. /// </summary>
  10953. /// <param name="plcNo">PLC编号</param>
  10954. /// <param name="stationNameStr">工站全称</param>
  10955. private void S4_5载具扫码(int plcNo, string stationNameStr)
  10956. {
  10957. Stopwatch stopwatch1 = new Stopwatch();
  10958. Stopwatch stopwatch2 = new Stopwatch();
  10959. try
  10960. {
  10961. stopwatch1.Start();
  10962. // ZS 载具扫码
  10963. string d5VehicleCode = " "; // 扫到的码
  10964. short d5VehicleScanCode = 2;
  10965. #region 进站
  10966. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  10967. {
  10968. // 查产品SN
  10969. #region 查询载具上的产品信息
  10970. string cavityData = string.Empty;
  10971. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  10972. if (string.IsNullOrEmpty(cavityData))
  10973. cavityData = "";
  10974. if (snResult != 0)
  10975. {
  10976. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  10977. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  10978. writeToPLC_Flag1.Adress = 2559;
  10979. writeToPLC_Flag1.Value = (short)6;
  10980. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  10981. {
  10982. Name = "d5VehicleCode",
  10983. Adress = 2560,
  10984. ValueType = PLCValueType.String,
  10985. ValueTypeStrLength = 20,
  10986. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  10987. });
  10988. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  10989. stopwatch1.Stop();
  10990. AddMessage(LogType.Info,
  10991. stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  10992. "ms");
  10993. return;
  10994. }
  10995. string[] cavitySNs = cavityData.Split('.');
  10996. string partNo = "";
  10997. if (cavitySNs != null && cavitySNs.Length >= 1)
  10998. {
  10999. partNo = cavitySNs[0];
  11000. }
  11001. #endregion 查询载具上的产品信息
  11002. List<TestItem> item = new List<TestItem>();
  11003. item.Add(new TestItem()
  11004. {
  11005. Parameter_name = "载具码",
  11006. Parameter_value = d5VehicleCode,
  11007. });
  11008. item.Add(new TestItem()
  11009. {
  11010. Parameter_name = "载具穴号",
  11011. Parameter_value = "1",
  11012. });
  11013. stopwatch2.Start();
  11014. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  11015. partNo, item, out string errorMsg);
  11016. stopwatch2.Stop();
  11017. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  11018. }
  11019. #endregion 进站
  11020. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  11021. //// MES_Flag
  11022. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  11023. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11024. writeToPLC_Flag.Name = "d5VehicleScanCode";
  11025. writeToPLC_Flag.Adress = 2559;
  11026. writeToPLC_Flag.Value = d5VehicleScanCode;
  11027. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  11028. {
  11029. Name = "d5VehicleCode",
  11030. Adress = 2560,
  11031. ValueType = PLCValueType.String,
  11032. ValueTypeStrLength = 20,
  11033. Value = d5VehicleCode
  11034. });
  11035. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  11036. }
  11037. catch (Exception ex)
  11038. {
  11039. string str = ex.StackTrace;
  11040. AddMessage_Station(stationNameStr, LogType.Error,
  11041. $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" +
  11042. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11043. stopwatch2.Start();
  11044. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  11045. //// MES_Flag
  11046. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  11047. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11048. writeToPLC_Flag.Name = "d5VehicleScanCode";
  11049. writeToPLC_Flag.Adress = 2559;
  11050. writeToPLC_Flag.Value = (short)6;
  11051. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  11052. {
  11053. Name = "d5VehicleCode",
  11054. Adress = 2560,
  11055. ValueType = PLCValueType.String,
  11056. ValueTypeStrLength = 20,
  11057. Value = " "
  11058. });
  11059. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  11060. stopwatch2.Stop();
  11061. }
  11062. stopwatch1.Stop();
  11063. AddMessage(LogType.Info,
  11064. stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11065. stopwatch2.ElapsedMilliseconds + "ms");
  11066. }
  11067. // 上次采集到的SN
  11068. //private string sn_S4_5出站接口 = string.Empty;
  11069. /// <summary>
  11070. /// [S4] 取放桁架 - S4_5出站接口
  11071. /// </summary>
  11072. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  11073. {
  11074. Stopwatch stopwatch1 = new Stopwatch();
  11075. Stopwatch stopwatch2 = new Stopwatch();
  11076. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  11077. string stationNameStr = stationCode + stationName;
  11078. string processItem = stationName; // 测试项目
  11079. try
  11080. {
  11081. stopwatch1.Start();
  11082. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  11083. //string batch_num = GlobalContext.BatchNumber; // 批次号
  11084. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  11085. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  11086. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  11087. sn = sn.Replace("\0", "");
  11088. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  11089. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  11090. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  11091. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  11092. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  11093. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  11094. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  11095. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  11096. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  11097. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  11098. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  11099. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  11100. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  11101. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  11102. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  11103. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  11104. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  11105. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  11106. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  11107. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  11108. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  11109. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  11110. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  11111. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  11112. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  11113. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  11114. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  11115. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  11116. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  11117. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  11118. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  11119. bool pass = d5Result == 1;
  11120. // 存 载具SN列表
  11121. List<string> vehicleCodes = new List<string>()
  11122. {
  11123. d5VehicleCode1, d5VehicleCode2, d5VehicleCode3, d5VehicleCode4, d5VehicleCode5,
  11124. d5VehicleCode6, d5VehicleCode7, d5VehicleCode8, d5VehicleCode9, d5VehicleCode10,
  11125. d5VehicleCode11, d5VehicleCode12, d5VehicleCode13, d5VehicleCode14, d5VehicleCode15
  11126. };
  11127. // 统一查 产品SN列表
  11128. List<string> partNos = new List<string>();
  11129. foreach (string vehicleCode in vehicleCodes)
  11130. {
  11131. if (string.IsNullOrEmpty(vehicleCode))
  11132. partNos.Add("");
  11133. else
  11134. {
  11135. string partNo = "";
  11136. #region 查询载具上的产品信息
  11137. string cavityData = string.Empty;
  11138. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  11139. if (string.IsNullOrEmpty(cavityData))
  11140. cavityData = "";
  11141. if (snResult != 0)
  11142. {
  11143. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11144. writeToPLC_Flag1.Name = "d5MES_FLAG";
  11145. writeToPLC_Flag1.Adress = 2591;
  11146. writeToPLC_Flag1.Value = (short)4;
  11147. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  11148. stopwatch1.Stop();
  11149. AddMessage(LogType.Info,
  11150. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
  11151. "ms");
  11152. return;
  11153. }
  11154. string[] cavitySNs = cavityData.Split('.');
  11155. if (cavitySNs != null && cavitySNs.Length >= 1)
  11156. partNo = cavitySNs[0];
  11157. #endregion 查询载具上的产品信息
  11158. partNos.Add(partNo);
  11159. }
  11160. }
  11161. // 统一上传
  11162. stopwatch2.Start();
  11163. List<int> results = new List<int>();
  11164. for (int i = 0; i < partNos.Count; i++)
  11165. {
  11166. string index = (i + 1).ToString(); // 弹夹穴号
  11167. if (string.IsNullOrEmpty(partNos[i]))
  11168. results.Add(1);
  11169. else
  11170. {
  11171. List<TestItem> items1 = new List<TestItem>();
  11172. items1.Add(new TestItem()
  11173. {
  11174. Parameter_name = "弹夹码",
  11175. Parameter_value = sn,
  11176. Parameter_unit = ""
  11177. });
  11178. items1.Add(new TestItem()
  11179. {
  11180. Parameter_name = "弹夹穴号",
  11181. Parameter_value = index,
  11182. Parameter_unit = ""
  11183. });
  11184. items1.Add(new TestItem()
  11185. {
  11186. Parameter_name = "载具码",
  11187. Parameter_value = vehicleCodes[i],
  11188. Parameter_unit = ""
  11189. });
  11190. items1.Add(new TestItem()
  11191. {
  11192. Parameter_name = "载具穴号",
  11193. Parameter_value = "1",
  11194. Parameter_unit = ""
  11195. });
  11196. items1.Add(new TestItem()
  11197. {
  11198. Parameter_name = "产品结果",
  11199. Parameter_value = d5Result == 1 ? "OK" : "NG",
  11200. Parameter_unit = ""
  11201. });
  11202. int result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
  11203. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  11204. results.Add(result1);
  11205. }
  11206. }
  11207. short result = 0;
  11208. if (results.All(a => a == 1))
  11209. result = 1;
  11210. else if (results.Contains(3))
  11211. result = 3;
  11212. else if (results.Contains(2))
  11213. result = 2;
  11214. else if (results.Contains(4))
  11215. result = 4;
  11216. else
  11217. result = 4;
  11218. stopwatch2.Stop();
  11219. #region 存储绑定数据到 边线MES系统中
  11220. if (result == 1)
  11221. {
  11222. // 删除绑定信息
  11223. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  11224. if (resultMesR != 0)
  11225. {
  11226. result = 4;
  11227. AddMessage_Station(stationNameStr, LogType.Error,
  11228. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  11229. }
  11230. }
  11231. #endregion 存储绑定数据到 边线MES系统中
  11232. // MES_Flag 为4MES报错
  11233. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11234. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11235. writeToPLC_Flag.Name = "d5MES_FLAG";
  11236. writeToPLC_Flag.Adress = 2591;
  11237. writeToPLC_Flag.Value = result;
  11238. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  11239. OnMessage(LogType.Debug,
  11240. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  11241. }
  11242. catch (Exception ex)
  11243. {
  11244. stopwatch2.Restart();
  11245. // MES_Flag 为4上位机报错
  11246. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  11247. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11248. writeToPLC_Flag.Name = "d5MES_FLAG";
  11249. writeToPLC_Flag.Adress = 2591;
  11250. writeToPLC_Flag.Value = (short)4;
  11251. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  11252. stopwatch2.Stop();
  11253. string str = ex.StackTrace;
  11254. AddMessage_Station(stationNameStr, LogType.Error,
  11255. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11256. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11257. }
  11258. stopwatch1.Stop();
  11259. AddMessage(LogType.Info,
  11260. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11261. stopwatch2.ElapsedMilliseconds + "ms");
  11262. }
  11263. /// <summary>
  11264. /// [S4] 取放桁架 - S4_5节拍接口
  11265. /// </summary>
  11266. /// <param name="plcNo">PLC编号</param>
  11267. /// <param name="stationNameStr">工站全称</param>
  11268. private void S4_5节拍接口(int plcNo, string stationNameStr)
  11269. {
  11270. Stopwatch stopwatch1 = new Stopwatch();
  11271. Stopwatch stopwatch2 = new Stopwatch();
  11272. string resultStr = string.Empty;
  11273. try
  11274. {
  11275. stopwatch1.Start();
  11276. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  11277. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  11278. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  11279. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  11280. if (!actionBool)
  11281. {
  11282. stopwatch2.Start();
  11283. // MES_Flag
  11284. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  11285. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11286. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  11287. writeToPLC_Flag1.Adress = 2924;
  11288. writeToPLC_Flag1.Value = (short)4;
  11289. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  11290. stopwatch2.Stop();
  11291. AddMessage(LogType.Info,
  11292. stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  11293. "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  11294. return;
  11295. }
  11296. string d5OEEPartNo = string.Empty; // 物料码
  11297. if (string.IsNullOrEmpty(d5OEEProductSN))
  11298. {
  11299. stopwatch2.Start();
  11300. // MES_Flag
  11301. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11302. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11303. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  11304. writeToPLC_Flag1.Adress = 2924;
  11305. writeToPLC_Flag1.Value = (short)1;
  11306. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  11307. stopwatch2.Stop();
  11308. AddMessage(LogType.Info,
  11309. stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11310. stopwatch2.ElapsedMilliseconds + "ms");
  11311. return;
  11312. }
  11313. else
  11314. {
  11315. // 查产品SN
  11316. d5OEEPartNo = "Test"; // ZS
  11317. }
  11318. short d5OEEMES_FLAG = 0;
  11319. // 上传OEE
  11320. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  11321. d5OEEMES_FLAG = result.Item1;
  11322. resultStr = result.Item2;
  11323. stopwatch2.Start();
  11324. // MES_Flag
  11325. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11326. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11327. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  11328. writeToPLC_Flag.Adress = 2924;
  11329. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  11330. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  11331. stopwatch2.Stop();
  11332. }
  11333. catch (Exception ex)
  11334. {
  11335. string str = ex.StackTrace;
  11336. AddMessage_Station(stationNameStr, LogType.Error,
  11337. $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  11338. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11339. // MES_Flag
  11340. stopwatch2.Start();
  11341. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  11342. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11343. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  11344. writeToPLC_Flag.Adress = 2924;
  11345. writeToPLC_Flag.Value = (short)4;
  11346. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  11347. stopwatch2.Stop();
  11348. }
  11349. stopwatch1.Stop();
  11350. AddMessage(LogType.Info,
  11351. stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11352. stopwatch2.ElapsedMilliseconds + "ms");
  11353. }
  11354. #endregion [S4] 取放桁架
  11355. #endregion PLC4 刘果段
  11356. #region PLC5 张超凡
  11357. #region [S5] Tray盘下料装备
  11358. /// <summary>
  11359. /// S5工位的数据- 触发信号上次的值
  11360. /// </summary>
  11361. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  11362. /// <summary>
  11363. /// S5工位的数据(含触发信号)
  11364. /// </summary>
  11365. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  11366. /// <summary>
  11367. /// S5工位的数据- 回写点位
  11368. /// </summary>
  11369. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  11370. /// <summary>
  11371. /// [S5] Tray盘下料装备
  11372. /// </summary>
  11373. /// <param name="plcNo">PLC编号</param>
  11374. //private void ReadStation_S5(int plcNo)
  11375. //{
  11376. // // [S1] Tray盘上料装备
  11377. // // [S2] FCT
  11378. // // [S3] 值板机
  11379. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  11380. // // [S5] Tray盘下料装备
  11381. // /// 上位机心跳
  11382. // /// 获取设备报警数据与状态信息
  11383. // string stationCode = "[S5]";
  11384. // string stationName = "Tray盘下料装备";
  11385. // string stationNameStr = stationCode + stationName;
  11386. // #region 创建字典
  11387. // // 触发信号字典 赋值
  11388. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  11389. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  11390. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  11391. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  11392. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  11393. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  11394. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  11395. // // PLC数据字典 赋值
  11396. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  11397. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  11398. // s5PLCData.Add("e1ProductSN_Check", ""); //
  11399. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  11400. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  11401. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  11402. // s5PLCData.Add("e1PartNo", ""); // 物料码
  11403. // s5PLCData.Add("e1Result", 0); // 产品结果
  11404. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  11405. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  11406. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  11407. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  11408. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  11409. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  11410. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  11411. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  11412. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  11413. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  11414. // #endregion 创建字典
  11415. // while (IsRun)
  11416. // {
  11417. // try
  11418. // {
  11419. // if (!GlobalContext._IsCon_Funs5)
  11420. // {
  11421. // UpdatePLCMonitor(1, plcNo, 0);
  11422. // continue;
  11423. // }
  11424. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  11425. // {
  11426. // Stopwatch stopwatch1 = new Stopwatch();
  11427. // Stopwatch stopwatch2 = new Stopwatch();
  11428. // stopwatch1.Start();
  11429. // stopwatch2.Start();
  11430. // #region 一次性读取所有数据
  11431. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  11432. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  11433. // int[] datas = data1.Concat(data2).ToArray();
  11434. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  11435. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  11436. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  11437. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  11438. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  11439. // s5PLCData["e1MES_FLAG"] = datas[35];
  11440. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  11441. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  11442. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  11443. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  11444. // s5PLCData["e1Result"] = datas[76];
  11445. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  11446. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  11447. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  11448. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  11449. // s5PLCData["e1OEEType"] = datas[109];
  11450. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  11451. // s5PLCData["e1AGVUpStart"] = datas[121];
  11452. // s5PLCData["e1AGVUpEnd"] = datas[122];
  11453. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  11454. // s5PLCData["e1AGVDownStart"] = datas[134];
  11455. // s5PLCData["e1AGVDownEnd"] = datas[135];
  11456. // #endregion 一次性读取所有数据
  11457. // stopwatch2.Stop();
  11458. // #region 回写操作,写后清空flag
  11459. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  11460. // #endregion 回写操作,写后清空flag
  11461. // #region 进站校验
  11462. // try
  11463. // {
  11464. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  11465. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  11466. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  11467. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  11468. // {
  11469. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  11470. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  11471. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  11472. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  11473. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  11474. // }
  11475. // }
  11476. // catch (Exception ex)
  11477. // {
  11478. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  11479. // string str = ex.StackTrace;
  11480. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11481. // }
  11482. // #endregion 进站校验
  11483. // #region 出站接口
  11484. // try
  11485. // {
  11486. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  11487. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  11488. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  11489. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  11490. // {
  11491. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  11492. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  11493. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  11494. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  11495. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  11496. // }
  11497. // }
  11498. // catch (Exception ex)
  11499. // {
  11500. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  11501. // string str = ex.StackTrace;
  11502. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11503. // }
  11504. // #endregion 出站接口
  11505. // #region 节拍接口
  11506. // try
  11507. // {
  11508. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  11509. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  11510. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  11511. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  11512. // {
  11513. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  11514. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  11515. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  11516. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  11517. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  11518. // }
  11519. // }
  11520. // catch (Exception ex)
  11521. // {
  11522. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  11523. // string str = ex.StackTrace;
  11524. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11525. // }
  11526. // #endregion 节拍接口
  11527. // #region AGV上料
  11528. // // AGV上料叫AGV信号
  11529. // try
  11530. // {
  11531. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  11532. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  11533. // if (e1AGVUpCall != e1AGVUpCallOld)
  11534. // {
  11535. // if (e1AGVUpCall == 1) // 0->1
  11536. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  11537. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  11538. // }
  11539. // }
  11540. // catch (Exception ex)
  11541. // {
  11542. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  11543. // string str = ex.StackTrace;
  11544. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11545. // }
  11546. // // AGV上料完成信号
  11547. // try
  11548. // {
  11549. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  11550. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  11551. // if (e1AGVUpEnd != e1AGVUpEndOld)
  11552. // {
  11553. // if (e1AGVUpEnd == 1) // 0->1
  11554. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  11555. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  11556. // }
  11557. // }
  11558. // catch (Exception ex)
  11559. // {
  11560. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  11561. // string str = ex.StackTrace;
  11562. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11563. // }
  11564. // #endregion AGV上料
  11565. // #region AGV下料
  11566. // // AGV下料叫agv信号
  11567. // try
  11568. // {
  11569. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  11570. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  11571. // if (e1AGVDownCall != e1AGVDownCallOld)
  11572. // {
  11573. // if (e1AGVDownCall == 1) // 0->1
  11574. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  11575. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  11576. // }
  11577. // }
  11578. // catch (Exception ex)
  11579. // {
  11580. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  11581. // string str = ex.StackTrace;
  11582. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11583. // }
  11584. // // AGV下料完成信号
  11585. // try
  11586. // {
  11587. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  11588. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  11589. // if (e1AGVDownEnd != e1AGVDownEndOld)
  11590. // {
  11591. // if (e1AGVDownEnd == 1) // 0->1
  11592. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  11593. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  11594. // }
  11595. // }
  11596. // catch (Exception ex)
  11597. // {
  11598. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  11599. // string str = ex.StackTrace;
  11600. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11601. // }
  11602. // #endregion AGV下料
  11603. // #region 心跳
  11604. // try
  11605. // {
  11606. // short states = 0;
  11607. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  11608. // }
  11609. // catch (Exception ex)
  11610. // {
  11611. // string str = ex.StackTrace;
  11612. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11613. // }
  11614. // #endregion 心跳
  11615. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  11616. // stopwatch1.Stop();
  11617. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  11618. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  11619. // }
  11620. // else
  11621. // {
  11622. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  11623. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  11624. // Funs[plcNo].Connect();
  11625. // }
  11626. // }
  11627. // catch (Exception ex)
  11628. // {
  11629. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  11630. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  11631. // Funs[plcNo].ReConnect();
  11632. // }
  11633. // Thread.Sleep(IntervalReadPLC);
  11634. // }
  11635. //}
  11636. /// <summary>
  11637. /// [S5] Tray盘下料装备 - 进站校验
  11638. /// </summary>
  11639. /// <param name="plcNo">PLC编号</param>
  11640. /// <param name="stationNameStr">工站全称</param>
  11641. private void S5进站校验(int plcNo, string stationNameStr)
  11642. {
  11643. Stopwatch stopwatch1 = new Stopwatch();
  11644. Stopwatch stopwatch2 = new Stopwatch();
  11645. try
  11646. {
  11647. stopwatch1.Start();
  11648. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  11649. sn = sn.Replace("\0", "");
  11650. // 获取产品SN By 载具码
  11651. #region 查询载具上的产品信息
  11652. string cavityData = string.Empty;
  11653. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  11654. if (string.IsNullOrEmpty(cavityData))
  11655. cavityData = "";
  11656. if (snResult != 0)
  11657. {
  11658. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11659. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  11660. writeToPLC_Flag1.Adress = 2003;
  11661. writeToPLC_Flag1.Value = (short)6;
  11662. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  11663. stopwatch1.Stop();
  11664. AddMessage(LogType.Info,
  11665. stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11666. return;
  11667. }
  11668. string[] cavitySNs = cavityData.Split('.');
  11669. string partNo = string.Empty;
  11670. if (cavitySNs != null && cavitySNs.Length >= 1)
  11671. partNo = cavitySNs[0];
  11672. #endregion 查询载具上的产品信息
  11673. // 产品SN(物料码)校验
  11674. List<TestItem> item = new List<TestItem>();
  11675. item.Add(new TestItem()
  11676. {
  11677. Parameter_name = "载具码",
  11678. Parameter_value = sn,
  11679. });
  11680. item.Add(new TestItem()
  11681. {
  11682. Parameter_name = "载具穴号",
  11683. Parameter_value = "1",
  11684. });
  11685. stopwatch2.Start();
  11686. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
  11687. partNo, item, out string errorMsg);
  11688. stopwatch2.Stop();
  11689. short e1MES_FLAG_Check = (short)result;
  11690. // MES_Flag
  11691. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  11692. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11693. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  11694. writeToPLC_Flag.Adress = 2003;
  11695. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  11696. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  11697. }
  11698. catch (Exception ex)
  11699. {
  11700. string str = ex.StackTrace;
  11701. AddMessage_Station(stationNameStr, LogType.Error,
  11702. $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
  11703. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11704. // MES_Flag
  11705. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  11706. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11707. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  11708. writeToPLC_Flag.Adress = 2003;
  11709. writeToPLC_Flag.Value = (short)6;
  11710. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  11711. }
  11712. stopwatch1.Stop();
  11713. AddMessage(LogType.Info,
  11714. stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
  11715. stopwatch2.ElapsedMilliseconds + "ms");
  11716. }
  11717. /// <summary>
  11718. /// [S5] Tray盘下料装备 - 出站接口
  11719. /// </summary>
  11720. /// <param name="plcNo"></param>
  11721. /// <param name="stationCode"></param>
  11722. /// <param name="stationName"></param>
  11723. private void S5出站接口(int plcNo, string stationCode, string stationName)
  11724. {
  11725. Stopwatch stopwatch1 = new Stopwatch();
  11726. Stopwatch stopwatch2 = new Stopwatch();
  11727. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  11728. string stationNameStr = stationCode + stationName;
  11729. string processItem = stationName; // 测试项目
  11730. try
  11731. {
  11732. stopwatch1.Start();
  11733. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  11734. //string batch_num = GlobalContext.BatchNumber; // 批次号
  11735. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  11736. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  11737. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  11738. sn = sn.Replace("\0", "");
  11739. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  11740. //partNo = partNo.Replace("\0", "");
  11741. #region 查询载具上的产品信息
  11742. string cavityData = string.Empty;
  11743. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  11744. if (string.IsNullOrEmpty(cavityData))
  11745. cavityData = "";
  11746. if (snResult != 0)
  11747. {
  11748. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11749. writeToPLC_Flag1.Name = "e1MES_FLAG";
  11750. writeToPLC_Flag1.Adress = 2035;
  11751. writeToPLC_Flag1.Value = (short)4;
  11752. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  11753. stopwatch1.Stop();
  11754. AddMessage(LogType.Info,
  11755. stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  11756. return;
  11757. }
  11758. string[] cavitySNs = cavityData.Split('.');
  11759. string partNo = string.Empty;
  11760. if (cavitySNs != null && cavitySNs.Length >= 1)
  11761. partNo = cavitySNs[0];
  11762. #endregion 查询载具上的产品信息
  11763. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  11764. bool pass = e1Result == 1;
  11765. stopwatch2.Start();
  11766. // 上传MES
  11767. List<TestItem> items = new List<TestItem>();
  11768. items.Add(new TestItem()
  11769. {
  11770. Parameter_name = "载具码",
  11771. Parameter_value = sn,
  11772. Parameter_unit = ""
  11773. });
  11774. items.Add(new TestItem()
  11775. {
  11776. Parameter_name = "载具穴号",
  11777. Parameter_value = "1",
  11778. Parameter_unit = ""
  11779. });
  11780. items.Add(new TestItem()
  11781. {
  11782. Parameter_name = "产品结果",
  11783. Parameter_value = e1Result == 1 ? "OK" : "NG",
  11784. Parameter_unit = ""
  11785. });
  11786. int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
  11787. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  11788. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  11789. short result = result1 == 1 ? (short)1 : (short)3;
  11790. stopwatch2.Stop();
  11791. #region 存储绑定数据到 边线MES系统中
  11792. if (result == 1)
  11793. {
  11794. // 删除绑定信息
  11795. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  11796. if (resultMesR != 0)
  11797. {
  11798. result = 4;
  11799. AddMessage_Station(stationNameStr, LogType.Error,
  11800. $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  11801. }
  11802. }
  11803. #endregion 存储绑定数据到 边线MES系统中
  11804. // MES_Flag 为MES报错
  11805. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11806. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  11807. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11808. writeToPLC_Flag.Name = "e1MES_FLAG";
  11809. writeToPLC_Flag.Adress = 2035;
  11810. writeToPLC_Flag.Value = result;
  11811. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  11812. OnMessage(LogType.Debug,
  11813. $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  11814. }
  11815. catch (Exception ex)
  11816. {
  11817. stopwatch2.Restart();
  11818. // MES_Flag 为4上位机报错
  11819. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  11820. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11821. writeToPLC_Flag.Name = "e1MES_FLAG";
  11822. writeToPLC_Flag.Adress = 2035;
  11823. writeToPLC_Flag.Value = (short)4;
  11824. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  11825. stopwatch2.Stop();
  11826. string str = ex.StackTrace;
  11827. AddMessage_Station(stationNameStr, LogType.Error,
  11828. $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  11829. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11830. }
  11831. stopwatch1.Stop();
  11832. AddMessage(LogType.Info,
  11833. stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
  11834. stopwatch2.ElapsedMilliseconds + "ms");
  11835. }
  11836. /// <summary>
  11837. /// [S5] Tray盘下料装备 - 节拍接口
  11838. /// </summary>
  11839. /// <param name="plcNo">PLC编号</param>
  11840. /// <param name="stationNameStr">工站全称</param>
  11841. //private void S5节拍接口(int plcNo, string stationNameStr)
  11842. //{
  11843. // Stopwatch stopwatch1 = new Stopwatch();
  11844. // Stopwatch stopwatch2 = new Stopwatch();
  11845. // string resultStr = string.Empty;
  11846. // try
  11847. // {
  11848. // stopwatch1.Start();
  11849. // string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  11850. // string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  11851. // e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  11852. // bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  11853. // if (!actionBool)
  11854. // {
  11855. // stopwatch2.Start();
  11856. // // MES_Flag
  11857. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11858. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11859. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  11860. // writeToPLC_Flag1.Adress = 2088;
  11861. // writeToPLC_Flag1.Value = (short)4;
  11862. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  11863. // stopwatch2.Stop();
  11864. // AddMessage(LogType.Info,
  11865. // stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
  11866. // "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  11867. // return;
  11868. // }
  11869. // string e1OEEPartNo = string.Empty; // 物料码
  11870. // if (string.IsNullOrEmpty(e1OEEProductSN))
  11871. // {
  11872. // stopwatch2.Start();
  11873. // // MES_Flag
  11874. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11875. // WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  11876. // writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  11877. // writeToPLC_Flag1.Adress = 2088;
  11878. // writeToPLC_Flag1.Value = (short)1;
  11879. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  11880. // stopwatch2.Stop();
  11881. // AddMessage(LogType.Info,
  11882. // stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11883. // stopwatch2.ElapsedMilliseconds + "ms");
  11884. // return;
  11885. // }
  11886. // else
  11887. // {
  11888. // // 查产品SN
  11889. // e1OEEPartNo = "Test"; // ZS
  11890. // }
  11891. // short e1OEEMES_FLAG = 0;
  11892. // // 上传OEE
  11893. // (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  11894. // e1OEEMES_FLAG = result.Item1;
  11895. // resultStr = result.Item2;
  11896. // stopwatch2.Start();
  11897. // // MES_Flag
  11898. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  11899. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11900. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  11901. // writeToPLC_Flag.Adress = 2088;
  11902. // writeToPLC_Flag.Value = e1OEEMES_FLAG;
  11903. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  11904. // stopwatch2.Stop();
  11905. // }
  11906. // catch (Exception ex)
  11907. // {
  11908. // string str = ex.StackTrace;
  11909. // AddMessage_Station(stationNameStr, LogType.Error,
  11910. // $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
  11911. // str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11912. // // MES_Flag
  11913. // stopwatch2.Start();
  11914. // //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  11915. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11916. // writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  11917. // writeToPLC_Flag.Adress = 2088;
  11918. // writeToPLC_Flag.Value = (short)4;
  11919. // SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  11920. // stopwatch2.Stop();
  11921. // }
  11922. // stopwatch1.Stop();
  11923. // AddMessage(LogType.Info,
  11924. // stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11925. // stopwatch2.ElapsedMilliseconds + "ms");
  11926. //}
  11927. /// <summary>
  11928. /// [S5] Tray盘下料装备 - AGV上料叫agv
  11929. /// </summary>
  11930. /// <param name="plcNo">PLC编号</param>
  11931. /// <param name="stationNameStr">工站全称</param>
  11932. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  11933. {
  11934. Stopwatch stopwatch1 = new Stopwatch();
  11935. Stopwatch stopwatch2 = new Stopwatch();
  11936. try
  11937. {
  11938. stopwatch1.Start();
  11939. // ZS 呼叫AGV
  11940. short e1AGVUpCall = 2;
  11941. stopwatch2.Start();
  11942. // e1AGVUpCall
  11943. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11944. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11945. writeToPLC_Flag.Name = "e1AGVUpCall";
  11946. writeToPLC_Flag.Adress = 2120;
  11947. writeToPLC_Flag.Value = e1AGVUpCall;
  11948. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  11949. stopwatch2.Stop();
  11950. }
  11951. catch (Exception ex)
  11952. {
  11953. string str = ex.StackTrace;
  11954. AddMessage_Station(stationNameStr, LogType.Error,
  11955. $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  11956. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  11957. // e1AGVUpCall
  11958. stopwatch2.Start();
  11959. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  11960. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11961. writeToPLC_Flag.Name = "e1AGVUpCall";
  11962. writeToPLC_Flag.Adress = 2120;
  11963. writeToPLC_Flag.Value = (short)4;
  11964. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  11965. stopwatch2.Stop();
  11966. }
  11967. stopwatch1.Stop();
  11968. AddMessage(LogType.Info,
  11969. stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  11970. stopwatch2.ElapsedMilliseconds + "ms");
  11971. }
  11972. /// <summary>
  11973. /// [S5] Tray盘下料装备 - AGV上料完成
  11974. /// </summary>
  11975. /// <param name="plcNo">PLC编号</param>
  11976. /// <param name="stationNameStr">工站全称</param>
  11977. private void S5AGV上料完成(int plcNo, string stationNameStr)
  11978. {
  11979. Stopwatch stopwatch1 = new Stopwatch();
  11980. Stopwatch stopwatch2 = new Stopwatch();
  11981. try
  11982. {
  11983. stopwatch1.Start();
  11984. // ZS AGV上料完成,让小车离开
  11985. short e1AGVUpEnd = 2;
  11986. stopwatch2.Start();
  11987. // e1AGVUpEnd
  11988. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  11989. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  11990. writeToPLC_Flag.Name = "e1AGVUpEnd";
  11991. writeToPLC_Flag.Adress = 2122;
  11992. writeToPLC_Flag.Value = e1AGVUpEnd;
  11993. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  11994. stopwatch2.Stop();
  11995. }
  11996. catch (Exception ex)
  11997. {
  11998. string str = ex.StackTrace;
  11999. AddMessage_Station(stationNameStr, LogType.Error,
  12000. $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
  12001. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12002. // e1AGVUpEnd
  12003. stopwatch2.Start();
  12004. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  12005. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12006. writeToPLC_Flag.Name = "e1AGVUpEnd";
  12007. writeToPLC_Flag.Adress = 2122;
  12008. writeToPLC_Flag.Value = (short)4;
  12009. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  12010. stopwatch2.Stop();
  12011. }
  12012. stopwatch1.Stop();
  12013. AddMessage(LogType.Info,
  12014. stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12015. stopwatch2.ElapsedMilliseconds + "ms");
  12016. }
  12017. /// <summary>
  12018. /// [S5] Tray盘下料装备 - AGV下料叫agv
  12019. /// </summary>
  12020. /// <param name="plcNo">PLC编号</param>
  12021. /// <param name="stationNameStr">工站全称</param>
  12022. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  12023. {
  12024. Stopwatch stopwatch1 = new Stopwatch();
  12025. Stopwatch stopwatch2 = new Stopwatch();
  12026. try
  12027. {
  12028. stopwatch1.Start();
  12029. // ZS 呼叫AGV
  12030. short e1AGVDownCall = 2;
  12031. stopwatch2.Start();
  12032. // e1AGVDownCall
  12033. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  12034. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12035. writeToPLC_Flag.Name = "e1AGVDownCall";
  12036. writeToPLC_Flag.Adress = 2133;
  12037. writeToPLC_Flag.Value = e1AGVDownCall;
  12038. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  12039. stopwatch2.Stop();
  12040. }
  12041. catch (Exception ex)
  12042. {
  12043. string str = ex.StackTrace;
  12044. AddMessage_Station(stationNameStr, LogType.Error,
  12045. $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
  12046. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12047. // e1AGVDownCall
  12048. stopwatch2.Start();
  12049. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  12050. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12051. writeToPLC_Flag.Name = "e1AGVDownCall";
  12052. writeToPLC_Flag.Adress = 2133;
  12053. writeToPLC_Flag.Value = (short)4;
  12054. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  12055. stopwatch2.Stop();
  12056. }
  12057. stopwatch1.Stop();
  12058. AddMessage(LogType.Info,
  12059. stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12060. stopwatch2.ElapsedMilliseconds + "ms");
  12061. }
  12062. /// <summary>
  12063. /// [S5] Tray盘下料装备 - AGV下料完成
  12064. /// </summary>
  12065. /// <param name="plcNo">PLC编号</param>
  12066. /// <param name="stationNameStr">工站全称</param>
  12067. private void S5AGV下料完成(int plcNo, string stationNameStr)
  12068. {
  12069. Stopwatch stopwatch1 = new Stopwatch();
  12070. Stopwatch stopwatch2 = new Stopwatch();
  12071. try
  12072. {
  12073. stopwatch1.Start();
  12074. // ZS AGV上料完成,让小车离开
  12075. short e1AGVDownEnd = 2;
  12076. stopwatch2.Start();
  12077. // e1AGVDownEnd
  12078. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  12079. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12080. writeToPLC_Flag.Name = "e1AGVDownEnd";
  12081. writeToPLC_Flag.Adress = 2135;
  12082. writeToPLC_Flag.Value = e1AGVDownEnd;
  12083. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  12084. stopwatch2.Stop();
  12085. }
  12086. catch (Exception ex)
  12087. {
  12088. string str = ex.StackTrace;
  12089. AddMessage_Station(stationNameStr, LogType.Error,
  12090. $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
  12091. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12092. // e1AGVDownEnd
  12093. stopwatch2.Start();
  12094. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  12095. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  12096. writeToPLC_Flag.Name = "e1AGVDownEnd";
  12097. writeToPLC_Flag.Adress = 2135;
  12098. writeToPLC_Flag.Value = (short)4;
  12099. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  12100. stopwatch2.Stop();
  12101. }
  12102. stopwatch1.Stop();
  12103. AddMessage(LogType.Info,
  12104. stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
  12105. stopwatch2.ElapsedMilliseconds + "ms");
  12106. }
  12107. #endregion [S5] Tray盘下料装备
  12108. #endregion PLC5 张超凡
  12109. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  12110. /// <summary>
  12111. /// PLC读取到的数据 -添加数据
  12112. /// </summary>
  12113. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  12114. {
  12115. if (sxPlcData.ContainsKey(newKey))
  12116. sxPlcData[newKey] = newValue;
  12117. else
  12118. sxPlcData.Add(newKey, newValue);
  12119. }
  12120. /// <summary>
  12121. /// PLC需要写入的数据 -添加数据
  12122. /// </summary>
  12123. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey,
  12124. WriteToPLC_Flag newValue)
  12125. {
  12126. if (sxPLCWriteData.ContainsKey(newKey))
  12127. sxPLCWriteData[newKey] = newValue;
  12128. else
  12129. sxPLCWriteData.Add(newKey, newValue);
  12130. }
  12131. /// <summary>
  12132. /// PLC回写操作,写后清空flag
  12133. /// </summary>
  12134. /// <param name="modbusClient">modbus对象</param>
  12135. /// <param name="pLCReadDatas">读取到的数据字典</param>
  12136. /// <param name="pLCWriteDatas">需要写入的数据</param>
  12137. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas,
  12138. ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  12139. {
  12140. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  12141. {
  12142. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  12143. for (int i = 0; i < pLCWriteDatas.Count; i++)
  12144. {
  12145. string mesFlagName = pLCWriteDatas[i].Name;
  12146. int mesFlagAdress = pLCWriteDatas[i].Adress;
  12147. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  12148. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  12149. {
  12150. // 先回写数据
  12151. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  12152. for (int j = 0; j < writeToPLCDatas.Count; j++)
  12153. {
  12154. int mesDataAdress = writeToPLCDatas[j].Adress;
  12155. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  12156. switch (mesDataType)
  12157. {
  12158. case PLCValueType.Short:
  12159. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  12160. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  12161. break;
  12162. case PLCValueType.String:
  12163. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  12164. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  12165. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr,
  12166. mesDataValueStrLength);
  12167. break;
  12168. }
  12169. }
  12170. // 再回写信号
  12171. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  12172. // 存储读取数据的字典
  12173. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  12174. // 存储写入数据的字典 - 清空写入值
  12175. pLCWriteDatas[i].Value = (short)0;
  12176. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  12177. }
  12178. }
  12179. }
  12180. }
  12181. /// <summary>
  12182. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  12183. /// </summary>
  12184. /// <param name="no">3</param>
  12185. /// <param name="stationCode">设备编号</param>
  12186. /// <param name="stationNameStr">设备名称</param>
  12187. /// <param name="plcOrder">车间订单号</param>
  12188. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  12189. {
  12190. try
  12191. {
  12192. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  12193. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  12194. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  12195. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  12196. int result1 = 0;
  12197. switch (stationCode)
  12198. {
  12199. case 2:
  12200. case 3:
  12201. case 4:
  12202. case 6:
  12203. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  12204. break;
  12205. case 102:
  12206. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  12207. break;
  12208. case 103:
  12209. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  12210. break;
  12211. case 104:
  12212. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  12213. break;
  12214. case 106:
  12215. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  12216. break;
  12217. default:
  12218. // MES_Flag 为“6未找到正确设备编号”
  12219. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  12220. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  12221. return;
  12222. }
  12223. short result = result1 == 1 ? (short)1 : (short)2;
  12224. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  12225. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  12226. }
  12227. catch (Exception ex)
  12228. {
  12229. // MES_Flag 为2上位机报错
  12230. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  12231. string str = ex.StackTrace;
  12232. AddMessage_Station(stationNameStr, LogType.Error,
  12233. $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
  12234. str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  12235. }
  12236. }
  12237. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  12238. #region UI刷新
  12239. /// <summary>
  12240. /// 更新商品信息的UI + 下发产品信息(SN)
  12241. /// </summary>
  12242. private void UpdateProductInfo()
  12243. {
  12244. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  12245. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  12246. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  12247. //txt_CurSupplierCode.Text = ""; // 供应商代号
  12248. }
  12249. /// <summary>
  12250. /// 更新PLC连接状态的UI
  12251. /// </summary>
  12252. /// <param name="no">PLC编号</param>
  12253. /// <param name="status">状态</param>
  12254. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  12255. {
  12256. if (this != null && !this.IsDisposed)
  12257. {
  12258. switch (imgNo)
  12259. {
  12260. case 1:
  12261. this.BeginInvoke(new Action(() => { picPLC.Image = imageListState.Images[status]; }));
  12262. break;
  12263. case 2:
  12264. this.BeginInvoke(new Action(() => { pictureBox2.Image = imageListState.Images[status]; }));
  12265. break;
  12266. case 3:
  12267. this.BeginInvoke(new Action(() => { pictureBox3.Image = imageListState.Images[status]; }));
  12268. break;
  12269. case 4:
  12270. this.BeginInvoke(new Action(() => { pictureBox4.Image = imageListState.Images[status]; }));
  12271. break;
  12272. case 5:
  12273. this.BeginInvoke(new Action(() => { pictureBox5.Image = imageListState.Images[status]; }));
  12274. break;
  12275. case 6:
  12276. this.BeginInvoke(new Action(() => { pictureBox6.Image = imageListState.Images[status]; }));
  12277. break;
  12278. case 7:
  12279. this.BeginInvoke(new Action(() => { pictureBox7.Image = imageListState.Images[status]; }));
  12280. break;
  12281. case 8:
  12282. this.BeginInvoke(new Action(() => { pictureBox8.Image = imageListState.Images[status]; }));
  12283. break;
  12284. default:
  12285. break;
  12286. }
  12287. }
  12288. Task.Run(() => // 更新PLC交互页的指示灯
  12289. {
  12290. try
  12291. {
  12292. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  12293. {
  12294. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  12295. }
  12296. }
  12297. catch
  12298. {
  12299. }
  12300. });
  12301. }
  12302. #endregion UI刷新
  12303. #region 日志
  12304. /// <summary>
  12305. /// 添加各工位运行日志(同步至PLC交互页面)
  12306. /// </summary>
  12307. /// <param name="stationNameStr">工站名称</param>
  12308. /// <param name="logType">日志类型</param>
  12309. /// <param name="message">日志内容</param>
  12310. /// <param name="snNumber">产品数字SN</param>
  12311. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  12312. {
  12313. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")))
  12314. {
  12315. AddMessage(logType, message); // 首页展示+日志记录
  12316. }
  12317. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  12318. {
  12319. StationName = stationNameStr,
  12320. SnNumber = snNumber,
  12321. Message = message,
  12322. CreateTime = DateTime.Now
  12323. };
  12324. // PLC交互页展示
  12325. Task.Run(() =>
  12326. {
  12327. try
  12328. {
  12329. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  12330. {
  12331. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  12332. }
  12333. }
  12334. catch
  12335. {
  12336. }
  12337. });
  12338. }
  12339. /// <summary>
  12340. /// 添加运行日志
  12341. /// </summary>
  12342. /// <param name="logType">日志类型</param>
  12343. /// <param name="message">日志内容</param>
  12344. public void AddMessage(LogType logType, string message)
  12345. {
  12346. OnMessage(logType, message);
  12347. string date = DateTime.Now.ToString("yyyy/MM/dd");
  12348. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  12349. string msgShow = time + "--> " + message + "\r\n";
  12350. try
  12351. {
  12352. this.BeginInvoke(new Action(() =>
  12353. {
  12354. systemLog.Rows.Insert(0, date, time, message);
  12355. if (systemLog.Rows.Count >= 100)
  12356. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  12357. }));
  12358. }
  12359. catch (Exception ex) { }
  12360. }
  12361. /// <summary>
  12362. /// 添加运行日志-保存
  12363. /// </summary>
  12364. /// <param name="logType">日志类型</param>
  12365. /// <param name="message">日志内容</param>
  12366. private void OnMessage(LogType logType, string msg)
  12367. {
  12368. MessageEvent?.Invoke(logType, msg);
  12369. }
  12370. /// <summary>
  12371. /// 保存PLC写入日志
  12372. /// </summary>
  12373. /// <param name="logType"></param>
  12374. /// <param name="logValue"></param>
  12375. private void WritePLCLog(LogType logType, string logValue)
  12376. {
  12377. switch ((int)logType)
  12378. {
  12379. case 0:
  12380. _PLCLogNet.WriteDebug(logValue);
  12381. break;
  12382. case 1:
  12383. _PLCLogNet.WriteInfo(logValue);
  12384. break;
  12385. case 2:
  12386. _PLCLogNet.WriteWarn(logValue);
  12387. break;
  12388. case 3:
  12389. _PLCLogNet.WriteError(logValue);
  12390. break;
  12391. default:
  12392. _PLCLogNet.WriteFatal(logValue);
  12393. break;
  12394. }
  12395. }
  12396. /// <summary>
  12397. /// IOT Mqtt回调方法- With DataId
  12398. /// </summary>
  12399. /// <param name="id"></param>
  12400. /// <param name="v"></param>
  12401. /// <param name="dataId"></param>
  12402. public void CallbackWithDataId(string id, string msg, string dataId)
  12403. {
  12404. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  12405. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  12406. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  12407. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  12408. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  12409. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  12410. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  12411. }
  12412. /// <summary>
  12413. /// AGV Mqtt回调方法- 记录Log并处理数据
  12414. /// </summary>
  12415. /// <param name="obj"></param>
  12416. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  12417. {
  12418. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  12419. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  12420. // 接收到的信息
  12421. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  12422. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  12423. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  12424. {
  12425. }
  12426. }
  12427. #endregion 日志
  12428. //private void button1_Click(object sender, EventArgs e)
  12429. //{
  12430. // OpenDailogFalg=true;
  12431. // if (OpenDailogFalg)
  12432. // {
  12433. // using (var dialog = new BandBarodeDialog())
  12434. // {
  12435. // string strCarrierBarcode = "N801A-003";
  12436. // dialog._CarrierBarcode = strCarrierBarcode;
  12437. // string sn = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  12438. // dialog._ProductBarcode = sn;
  12439. // var rs = dialog.ShowDialog();
  12440. // if (rs == DialogResult.OK)
  12441. // {
  12442. // AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  12443. // OpenDailogFalg = false;//关闭扫码
  12444. // }
  12445. // }
  12446. // }
  12447. //}
  12448. }
  12449. }