Form_Home.cs 579 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970
  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 static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
  40. /*
  41. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  42. */
  43. namespace MainForm
  44. {
  45. /// <summary>
  46. /// 记录日志的委托
  47. /// </summary>
  48. /// <param name="logType">日志类型</param>
  49. /// <param name="message">日志信息</param>
  50. public delegate void HomeMessageHandler(LogType logType, string message);
  51. /// <summary>
  52. /// 主页窗体
  53. /// </summary>
  54. public partial class Form_Home : Form
  55. {
  56. #region 常量
  57. //文本常量
  58. private const string Head = "开始采集";
  59. private const string Tail = "采集完成";
  60. private const string Body = "工位出站数据";
  61. private const string BodyCheck = "工位点检数据";
  62. private const string BodyRun = "整线运行数据";
  63. private const string BodyAlarm = "整线报警数据";
  64. #endregion 常量
  65. #region 变量
  66. /// <summary>
  67. /// 委托-记录日志的方法
  68. /// </summary>
  69. public event HomeMessageHandler MessageEvent;
  70. /// <summary>
  71. /// 日志接口
  72. /// </summary>
  73. ILogNet _PLCLogNet;
  74. /// <summary>
  75. /// 用于记录IOT MQTT日志
  76. /// </summary>
  77. ILogNet _IOTMqttLogNet;
  78. /// <summary>
  79. /// 用于记录AGV MQTT日志
  80. /// </summary>
  81. ILogNet _AGVMqttLogNet;
  82. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  83. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  84. // 间隔时间
  85. private int IntervalReadPLC = 300; //ms 读PLC
  86. private int IntervalMonitorMES = 1000; //ms MES心跳
  87. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  88. // 软件状态
  89. private bool IsRun = true;
  90. #region PLC 与 TCP对象
  91. // 定义一个字典,存plc对象(通讯)
  92. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  93. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  94. // 定义TCPClient对象列表
  95. Dictionary<int, HPSocket_TcpClientHelper> _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  96. // 定义MQTTHelper对象
  97. MQTTHelper _MQTTHelper = new MQTTHelper();
  98. #endregion PLC 与 TCP对象
  99. /// <summary>
  100. /// 上次的设备运行信息
  101. /// </summary>
  102. private string lineWorkingData1_OldStr = string.Empty;
  103. /// <summary>
  104. /// 设备报警字典-当前结果
  105. /// Dictionary<工位代码,List<报警信息>>
  106. /// </summary>
  107. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  108. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  109. #endregion 变量
  110. #region 窗体基础事件
  111. /// <summary>
  112. /// 初始化
  113. /// </summary>
  114. public Form_Home()
  115. {
  116. InitializeComponent();
  117. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  118. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  119. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  120. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  121. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  122. }
  123. /// <summary>
  124. /// 窗体加载事件
  125. /// </summary>
  126. private void Form_Home_Load(object sender, EventArgs e)
  127. {
  128. try
  129. {
  130. AddMessage(LogType.Info, "开始初始化程序");
  131. InitalDicAlarm(); // 实例化报警字典
  132. //组建plc对象字典
  133. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  134. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  135. if (GlobalContext.IsUsePLC1)
  136. FunsEip.Add(1, new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  137. //Funs.Add(1, new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort, 2001)); // Tray盘上料装备(板测)
  138. if (GlobalContext.IsUsePLC2)
  139. //Funs.Add(2, new ModbusClientHelper(GlobalContext.Machine2Address, GlobalContext.MachinePort, 2001)); // FCT(板测),
  140. FunsEip.Add(2, new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  141. if (GlobalContext.IsUsePLC3)
  142. FunsEip.Add(3, new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  143. //Funs.Add(3, new ModbusClientHelper(GlobalContext.Machine3Address, GlobalContext.MachinePort, 2001)); // 值板机,
  144. if (GlobalContext.IsUsePLC4)
  145. FunsEip.Add(4, new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  146. //Funs.Add(4, new ModbusClientHelper(GlobalContext.Machine4Address, GlobalContext.MachinePort, 2001)); // 取放桁
  147. if (GlobalContext.IsUsePLC5)
  148. FunsEip.Add(5, new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  149. //Funs.Add(5, new ModbusClientHelper(GlobalContext.Machine5Address, GlobalContext.MachinePort, 2001)); //Tray盘下料装备
  150. if (GlobalContext.IsUsePLC6)
  151. FunsEip.Add(6, new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  152. if (GlobalContext.IsUsePLC7)
  153. FunsEip.Add(7, new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  154. if (GlobalContext.IsUsePLC8)
  155. FunsEip.Add(8, new Inovance_EIP(GlobalContext.PC8Address, GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  156. if (GlobalContext.IsUsePLC9)
  157. FunsEip.Add(9, new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  158. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  159. {
  160. if (plcEIP != null)
  161. {
  162. try
  163. {
  164. (int, string) result = plcEIP.Connect();
  165. }
  166. catch (Exception ex)
  167. {
  168. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  169. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  170. }
  171. }
  172. }
  173. /*
  174. //plc1Alarm.Connect();
  175. foreach (ModbusClientHelper modbusClient in Funs.Values)
  176. {
  177. if (modbusClient != null)
  178. {
  179. try
  180. {
  181. modbusClient.Connect();
  182. }
  183. catch (Exception ex)
  184. {
  185. MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
  186. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  187. }
  188. }
  189. }
  190. */
  191. // 采集任务
  192. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  193. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  194. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  195. if (GlobalContext.IsUsePLC1)
  196. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  197. if (GlobalContext.IsUsePLC2)
  198. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  199. if (GlobalContext.IsUsePLC3)
  200. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  201. if (GlobalContext.IsUsePLC4)
  202. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  203. if (GlobalContext.IsUsePLC5)
  204. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  205. if (GlobalContext.IsUsePLC6)
  206. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  207. if (GlobalContext.IsUsePLC7)
  208. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  209. if (GlobalContext.IsUsePLC8)
  210. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  211. if (GlobalContext.IsUsePLC9)
  212. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  213. #region 初始化
  214. try
  215. {
  216. // 开启边线MES(绑定/查询数据)
  217. //int mesRoute = XiaomiMES_RouteCommunication.Init();
  218. //if (mesRoute == 0)
  219. //{
  220. // //picMESStatus.Image = imageListState.Images[1];
  221. // //GlobalContext.MESIsConnect = true;
  222. // AddMessage(LogType.Info, "小米MES边线初始连接成功!");
  223. //}
  224. //else
  225. //{
  226. // //picMESStatus.Image = imageListState.Images[0];
  227. // //GlobalContext.MESIsConnect = false;
  228. // AddMessage(LogType.Info, $"小米MES边线初始连接失败!");
  229. //}
  230. // 开启MES(Http)
  231. if (GlobalContext.IsUseMES)
  232. {
  233. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  234. if (mesret)
  235. {
  236. picMESStatus.Image = imageListState.Images[1];
  237. GlobalContext.MESIsConnect = true;
  238. AddMessage(LogType.Info, "小米MES初始连接成功!");
  239. }
  240. else
  241. {
  242. picMESStatus.Image = imageListState.Images[0];
  243. GlobalContext.MESIsConnect = false;
  244. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  245. }
  246. }
  247. // 开启IOT(MQTT)
  248. if (GlobalContext.IsUseIot)
  249. {
  250. string addr = GlobalContext.MQTTServerHost;
  251. int port = GlobalContext.MQTTServerPort;
  252. int qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer(addr, port, GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  253. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult;
  254. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  255. {
  256. picIot.Image = imageListState.Images[1];
  257. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  258. XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  259. }
  260. else
  261. {
  262. picIot.Image = imageListState.Images[0];
  263. AddMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  264. }
  265. }
  266. // 开启AGV(Http与MQTT)
  267. if (GlobalContext.IsUseAGV)
  268. {
  269. // AGV HTTP
  270. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  271. if (mesret1)
  272. {
  273. picAgvHttp.Image = imageListState.Images[1];
  274. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  275. }
  276. else
  277. {
  278. picAgvHttp.Image = imageListState.Images[0];
  279. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  280. }
  281. string agvMqttIp = GlobalContext.MQTTServerHost;
  282. int agvMqttPort = GlobalContext.MQTTServerPort;
  283. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  284. ResultData_MQTT result_MQTT = _MQTTHelper.CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  285. // AGV MQTT
  286. if (result_MQTT.ResultCode == 1)
  287. {
  288. picAgvMqtt.Image = imageListState.Images[1];
  289. GlobalContext.AGVMQTTIsConnect = true;
  290. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  291. ResultData_MQTT result = XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  292. AddMessage(LogType.Info, $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  293. }
  294. else
  295. {
  296. picAgvMqtt.Image = imageListState.Images[0];
  297. GlobalContext.AGVMQTTIsConnect = false;
  298. AddMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  299. }
  300. }
  301. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  302. Task.Run(MonitorMESConnect);
  303. // 查询PLC连接状态
  304. foreach (int plcNo in FunsEip.Keys)
  305. {
  306. bool connected = FunsEip[plcNo].IsConnected;
  307. if (connected)
  308. {
  309. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  310. AddMessage(LogType.Info, msg);
  311. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  312. }
  313. else
  314. {
  315. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  316. AddMessage(LogType.Info, msg);
  317. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  318. }
  319. }
  320. // PLC4时 初始化扫码器TCP
  321. //if (GlobalContext.IsUsePLC4)
  322. // HpTCPClientInit();
  323. // 开启PLC的业务处理线程-监听PLC点位+状态
  324. foreach (Task task in TaskReadProcess)
  325. {
  326. if (task != null)
  327. task.Start();
  328. }
  329. //// 开启“获取线体报警数据”的线程
  330. //TaskReadAlarm.Start();
  331. ////下传MES信息给1工位(先判断下plc对象数量)
  332. //if (Funs.Count > 1)
  333. // DownLoadProductInfo(1);
  334. AddMessage(LogType.Info, "程序初始化完成");
  335. }
  336. catch (Exception ex)
  337. {
  338. string str = ex.StackTrace;
  339. this.BeginInvoke(new Action(() =>
  340. {
  341. AddMessage(LogType.Error, "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  342. }));
  343. }
  344. #endregion
  345. }
  346. catch (Exception ex)
  347. {
  348. string str = ex.StackTrace;
  349. OnMessage(LogType.Info, "主窗体的首页初始化出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  350. if (ex.Message != null && ex.Message.Contains("timed out"))
  351. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  352. else
  353. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  354. }
  355. }
  356. /// <summary>
  357. /// 窗体关闭事件
  358. /// </summary>
  359. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  360. {
  361. Closed2();
  362. }
  363. public void Closed2()
  364. {
  365. try
  366. {
  367. IsRun = false;
  368. Thread.Sleep(IntervalReadPLC);
  369. // 断开TCP
  370. int count = _HPSocket_TcpClients.Count();
  371. for (int i = 0; i < count; i++)
  372. {
  373. try
  374. {
  375. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  376. {
  377. _HPSocket_TcpClients[i].Stop();
  378. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  379. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  380. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  381. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  382. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  383. }
  384. }
  385. catch { }
  386. }
  387. // 关闭Iot
  388. try { XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath, GlobalContext.MqttServerName); } catch { }
  389. // 关闭AGV Mqtt
  390. try { _MQTTHelper.DisconnectAsync_Client().Wait(); } catch { }
  391. }
  392. catch { }
  393. }
  394. #endregion 窗体基础事件
  395. #region 监控MES状态
  396. /// <summary>
  397. /// 监控MES连接状态
  398. /// </summary>
  399. private void MonitorMESConnect()
  400. {
  401. while (IsRun) // 运行被控线程
  402. {
  403. try
  404. {
  405. // 开启MES(Http)
  406. if (GlobalContext.IsUseMES)
  407. {
  408. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  409. if (mesret)
  410. {
  411. picMESStatus.Image = imageListState.Images[1];
  412. GlobalContext.MESIsConnect = true;
  413. }
  414. else
  415. {
  416. picMESStatus.Image = imageListState.Images[0];
  417. GlobalContext.MESIsConnect = false;
  418. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  419. }
  420. }
  421. // 开启IOT(MQTT)
  422. if (GlobalContext.IsUseIot)
  423. {
  424. bool iIot = XiaomiMqttClient.IsOpen;
  425. if (iIot)
  426. picIot.Image = imageListState.Images[1];
  427. else
  428. {
  429. picIot.Image = imageListState.Images[0];
  430. OnMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  431. }
  432. }
  433. // 开启AGV(Http与MQTT)
  434. if (GlobalContext.IsUseAGV)
  435. {
  436. // AGV Http
  437. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  438. if (mesret1)
  439. picAgvHttp.Image = imageListState.Images[1];
  440. else
  441. {
  442. picAgvHttp.Image = imageListState.Images[0];
  443. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  444. }
  445. // AGV MQTT
  446. if (GlobalContext.AGVMQTTIsConnect)
  447. picAgvMqtt.Image = imageListState.Images[1];
  448. else
  449. {
  450. picAgvMqtt.Image = imageListState.Images[0];
  451. OnMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  452. }
  453. }
  454. }
  455. catch (Exception ex)
  456. {
  457. string str = ex.StackTrace;
  458. AddMessage(LogType.Error, "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  459. }
  460. Thread.Sleep(IntervalMonitorMES);
  461. }
  462. }
  463. #endregion 监控MES连接状态
  464. #region 采集设备状态、运行数据、报警数据
  465. /// <summary>
  466. /// 请求设备状态 5000
  467. /// </summary>
  468. /// <param name="no">1</param>
  469. /// <param name="stationNameStr"></param>
  470. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  471. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  472. {
  473. try
  474. {
  475. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  476. {
  477. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  478. return result;
  479. }
  480. else
  481. {
  482. return 0;
  483. }
  484. }
  485. catch (Exception ex)
  486. {
  487. string str = ex.StackTrace;
  488. AddMessage_Station(stationNameStr, LogType.Error, "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  489. return 0;
  490. }
  491. }
  492. /// <summary>
  493. /// 检查是否可采集点检数据 - 不取新值
  494. /// 5000不为1时可点检
  495. /// </summary>
  496. /// <returns></returns>
  497. public bool CheckCanSpotcheck1(int deviceState)
  498. {
  499. //return true;
  500. //D5000 = 1,代表设备控制状态处于运行状态
  501. //D5000 = 2, 代表设备控制状态处于故障状态
  502. //D5000 = 3,代表设备控制状态处于缺料状态
  503. //D5000 = 4, 代表设备控制状态处于待机状态
  504. //D5000 = 5,代表设备控制状态处于维修状态
  505. return deviceState != 1;
  506. }
  507. /// <summary>
  508. /// 检查是否可采集产品数据 - 不取新值
  509. /// </summary>
  510. /// <returns></returns>
  511. public bool CheckCanCollData(int deviceState)
  512. {
  513. return deviceState == 0; // 点检时该值不为0
  514. }
  515. /// <summary>
  516. /// 获取设备报警数据与获取设备运行信息
  517. /// </summary>
  518. private async void ReadAlarmAllPLC()
  519. {
  520. // [S1] Tray盘上料装备(板测)
  521. // [S2] FCT(板测)
  522. // [S3] 值板机
  523. // [S4] 取放桁架
  524. // [S5] Tray盘下料装备
  525. /// 上位机心跳
  526. /// 获取设备报警数据与状态信息
  527. string stationNameStr = "获取设备报警数据与状态信息";
  528. while (IsRun)
  529. {
  530. try
  531. {
  532. if (!GlobalContext._IsCon_plc1Alarm)
  533. {
  534. UpdatePLCMonitor(1, -2, 0);
  535. continue;
  536. }
  537. if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  538. {
  539. DateTime dtNow = DateTime.Now;
  540. #region 获取设备运行信息
  541. try
  542. {
  543. LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  544. lineWorkingData1.GUID = Guid.NewGuid().ToString();
  545. lineWorkingData1.LineName = GlobalContext.LineCode;
  546. //
  547. lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  548. lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  549. lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  550. lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  551. lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  552. lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  553. lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  554. lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  555. lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  556. lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  557. lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  558. lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  559. lineWorkingData1.CreateTime = DateTime.Now;
  560. string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  561. // UI展示-展示到设备状态页
  562. if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  563. {
  564. // 查询数据库最新一条数据,确定是不是更新
  565. string qSql = @"SELECT top(1) [GUID]
  566. ,[LineName]
  567. ,[BootTimeLong]
  568. ,[NormalTimeLong]
  569. ,[StandbyTimeLong]
  570. ,[FaultTimeLong]
  571. ,[MaterialShortageTimeLong]
  572. ,[MaintenanceTimeLong]
  573. ,[FaultNumber]
  574. ,[OutputNumber]
  575. ,[QualifiedNumber]
  576. ,[QualifiedRate]
  577. ,[DesignRhythm]
  578. ,[RealityRhythm]
  579. ,[CreateTime]
  580. FROM [LineWorkingData]
  581. where [CreateTime] > '{0}'
  582. and [LineName]='{1}'
  583. order by [CreateTime] desc
  584. ";
  585. qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  586. var ds = SQLHelper_New.Query(qSql, null);
  587. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  588. {
  589. var dataDBlast = new LineWorkingData_ThisTime();
  590. dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  591. dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  592. dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  593. dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  594. if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  595. {
  596. dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  597. dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  598. dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  599. dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  600. dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  601. dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  602. dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  603. dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  604. dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  605. dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  606. dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  607. dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  608. string usql = dataDBlast.ToStringUpdate();
  609. SQLHelper_New.ExecuteSQL(usql, null);
  610. lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  611. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  612. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  613. }
  614. }
  615. else
  616. {
  617. // 插入
  618. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  619. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  620. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  621. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  622. }
  623. }
  624. else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  625. {
  626. LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  627. //// 本次开机设备运行情况
  628. //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  629. //Task.Run(() =>
  630. //{
  631. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  632. // {
  633. // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  634. // }
  635. //});
  636. // 本日设备运行情况
  637. // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  638. if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  639. {
  640. // 更新
  641. lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  642. lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  643. lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  644. lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  645. lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  646. lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  647. lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  648. lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  649. lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  650. lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  651. lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  652. lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  653. SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  654. lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  655. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  656. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  657. }
  658. else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  659. {
  660. // 插入
  661. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  662. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  663. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  664. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  665. }
  666. await Task.Run(() =>
  667. {
  668. try
  669. {
  670. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  671. {
  672. Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  673. }
  674. }
  675. catch { }
  676. });
  677. }
  678. }
  679. catch (Exception ex)
  680. {
  681. string str = ex.StackTrace;
  682. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  683. }
  684. #endregion 获取设备运行信息
  685. #region 报警数据
  686. try
  687. {
  688. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  689. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  690. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  691. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  692. for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  693. {
  694. short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  695. dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  696. if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  697. {
  698. isNeedUpdUI = true; // 需要更新历史报警UI信息
  699. // 记录
  700. dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  701. switch (dicAlarms_Cur_PLC1[i].是否报警)
  702. {
  703. case true: // 报警
  704. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  705. {
  706. GUID = Guid.NewGuid().ToString(),
  707. LineName = GlobalContext.LineCode, // 线体
  708. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  709. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  710. StartTime = dtNow // 开始时间
  711. };
  712. // 传输到页面
  713. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  714. {
  715. 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  716. 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  717. 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  718. 开始时间 = dtNow
  719. });
  720. // 新增到数据库
  721. var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  722. SaveAlarmDataByDB(stationNameStr, data1, false);
  723. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  724. break;
  725. case false: // 消除报警
  726. if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  727. {
  728. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  729. {
  730. GUID = Guid.NewGuid().ToString(),
  731. LineName = GlobalContext.LineCode, // 线体
  732. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  733. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  734. StartTime = dtNow, // 开始时间
  735. EndTime = dtNow, // 开始时间
  736. PersistTime = 1, // 耗时1s
  737. };
  738. // 新增
  739. var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  740. SaveAlarmDataByDB(stationNameStr, data2, false);
  741. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  742. }
  743. else
  744. {
  745. dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  746. dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  747. - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  748. // 修改
  749. var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  750. SaveAlarmDataByDB(stationNameStr, data3, true);
  751. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  752. }
  753. break;
  754. default:
  755. break;
  756. }
  757. }
  758. }
  759. DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  760. // 有新报警则更新
  761. if (isNeedUpdUI)
  762. {
  763. // UI展示 - 展示到设备状态页
  764. await Task.Run(() =>
  765. {
  766. try
  767. {
  768. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  769. {
  770. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  771. if (Form_Main.formDevAlarm.Visible)
  772. {
  773. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  774. }
  775. }
  776. }
  777. catch { }
  778. });
  779. }
  780. }
  781. catch (Exception ex)
  782. {
  783. string str = ex.StackTrace;
  784. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  785. }
  786. #endregion 报警数据
  787. UpdatePLCMonitor(1, -2, 1);
  788. }
  789. else
  790. {
  791. UpdatePLCMonitor(1, -2, 0);
  792. }
  793. }
  794. catch (Exception ex)
  795. {
  796. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  797. }
  798. Thread.Sleep(IntervalAlarm);
  799. }
  800. }
  801. #endregion 轮询PLC
  802. #region 下发订单信息
  803. ///// <summary>
  804. ///// 壳体上料(下发工单)的交互逻辑
  805. ///// </summary>
  806. ///// <param name="no"></param>
  807. ///// <exception cref="NotImplementedException"></exception>
  808. //private void ReadStation_DownOrderInfo(int plcNo)
  809. //{
  810. // // [S1] Tray盘上料装备(板测)
  811. // // [S2] FCT(板测)
  812. // // [S3] 值板机
  813. // // [S4] 取放桁架
  814. // // [S5] Tray盘下料装备
  815. // /// 上位机心跳
  816. // /// 获取设备报警数据与状态信息
  817. // string stationNameStr = "[S0]壳体上料";
  818. // while (IsRun)
  819. // {
  820. // try
  821. // {
  822. // if (!GlobalContext._IsCon_Funs1)
  823. // {
  824. // UpdatePLCMonitor(plcNo, 0);
  825. // continue;
  826. // }
  827. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  828. // {
  829. // #region 壳体上料(下发工单)
  830. // try
  831. // {
  832. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  833. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  834. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  835. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  836. // // 重置数据和信号
  837. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  838. // {
  839. // // 清空写给PLC的数据
  840. // int[] i497 = new int[1] { 0 };
  841. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  842. // // MES_Flag重置为0
  843. // int[] i500 = new int[1] { 0 };
  844. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  845. // }
  846. // }
  847. // catch (Exception ex)
  848. // {
  849. // string str = ex.StackTrace;
  850. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  851. // }
  852. // #endregion 壳体上料(下发工单)
  853. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  854. // }
  855. // else
  856. // {
  857. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  858. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  859. //
  860. // Funs[plcNo].Connect();
  861. // }
  862. // }
  863. // catch (Exception ex)
  864. // {
  865. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  866. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  867. //
  868. // Funs[plcNo].ReConnect();
  869. // }
  870. // Thread.Sleep(IntervalReadPLC);
  871. // }
  872. //}
  873. ///// <summary>
  874. ///// 下发订单信息到PLC
  875. ///// </summary>
  876. ///// <param name="no">PLC编号</param>
  877. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  878. //{
  879. // try
  880. // {
  881. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  882. // {
  883. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  884. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  885. // }
  886. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  887. // }
  888. // catch (Exception ex)
  889. // {
  890. // string str = ex.StackTrace;
  891. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  892. // }
  893. //}
  894. /// <summary>
  895. /// 下发清料信号
  896. /// </summary>
  897. /// <param name="no">PLC编号</param>
  898. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  899. {
  900. try
  901. {
  902. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  903. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  904. return true;
  905. }
  906. catch (Exception ex)
  907. {
  908. string str = ex.StackTrace;
  909. AddMessage_Station(stationNameStr, LogType.Error, "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  910. return false;
  911. }
  912. }
  913. #endregion 下发订单信息
  914. #region Xiaomi 贲流
  915. #region 公共方法
  916. private static bool ProgressState = false;
  917. private static readonly object lockObj = new object(); // 锁对象
  918. private static bool isCollectingFlagLeft;
  919. private static bool isCollectingFlagRight;
  920. private bool OpenDailogFalg = true;//是否开启扫码弹窗标识
  921. /// <summary>
  922. /// float[]转为string
  923. /// </summary>
  924. public string FloatArrayToString(float[] nScrewResults)
  925. {
  926. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  927. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  928. }
  929. /// <summary>
  930. /// short[]转为string
  931. /// </summary>
  932. public string ShortArrayToString(short[] nScrewResults)
  933. {
  934. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  935. return string.Join(",", nScrewResults);
  936. }
  937. /// <summary>
  938. /// 写入PLC重复三次
  939. /// </summary>
  940. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount, T inObj)
  941. {
  942. int i = 0;
  943. int nRet = 0;
  944. string strRet = "";
  945. try
  946. {
  947. while (i < 3) // 最多上传三次
  948. {
  949. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  950. if (nRet == 0) //成功
  951. {
  952. break;
  953. }
  954. else
  955. {
  956. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  957. i++;
  958. }
  959. }
  960. return (nRet, strRet);
  961. }
  962. catch (Exception ex)
  963. {
  964. return (1, ex.Message);
  965. }
  966. }
  967. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes, short[] nScrewOrders, short[] nScrewResults)
  968. {
  969. try
  970. {
  971. // 获取当前日期
  972. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  973. // 构建保存路径
  974. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  975. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction,"螺丝Mes数据");
  976. // 确保目录存在
  977. Directory.CreateDirectory(savePath);
  978. // 文件名
  979. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  980. string filePath = Path.Combine(savePath, fileName);
  981. // 确保不会超出数组长度,只取前14个或数组的实际长度
  982. int count = Math.Min(14, fScrewTimes.Length);
  983. using (StreamWriter sw = new StreamWriter(filePath))
  984. {
  985. for (int i = 0; i < count; i++)
  986. {
  987. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  988. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  989. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  990. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  991. sw.WriteLine(); // 空行分隔不同螺丝的信息
  992. }
  993. }
  994. return (0, "");
  995. }
  996. catch (Exception ex)
  997. {
  998. return (1, ex.Message);
  999. }
  1000. }
  1001. /// <summary>
  1002. /// 调用进站接口并保存进站数据
  1003. /// </summary>
  1004. /// <param name="stationNameStr">工站信息</param>
  1005. /// <param name="workorder_code">工单号</param>
  1006. /// <param name="mtltmrk">型号(物料号)</param>
  1007. /// <param name="sn">产品SN</param>
  1008. /// <param name="items">进站数据</param>
  1009. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1010. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn, List<TestItem> items, string MachineId, string StationId)
  1011. {
  1012. int result = 0;
  1013. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1014. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1015. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1016. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1017. inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1018. inRequest_Body.unitSn = sn; // 产品SN
  1019. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1020. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1021. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1022. StationIn stationIn = new StationIn()
  1023. {
  1024. Workorder_code = workorder_code, // 车间订单号
  1025. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1026. Sn = sn, // SN
  1027. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1028. Parameter_values = items, // 进站数据
  1029. Write_user = inRequest_Body.userId, // 员工Id
  1030. Test_time = inRequest_Body.clientTime // 进站时间
  1031. };
  1032. // 本地数据
  1033. string sql = stationIn.ToStringInsert(0);
  1034. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1035. result = ret == "成功" ? 1 : 6;
  1036. //await Task.Delay(200);
  1037. // 上传MES
  1038. if (GlobalContext.IsSendStationIn)
  1039. {
  1040. try
  1041. {
  1042. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1043. string mesRet = string.Empty;
  1044. int i = 0;
  1045. while (i < 2) // 1009会多次尝试上传
  1046. {
  1047. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1048. if (response != null && response.header.code == "200")
  1049. break;
  1050. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1051. i++;
  1052. i++;
  1053. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1054. // 记录失败原因
  1055. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + json_Body);
  1056. }
  1057. if (response?.header?.code == "200")
  1058. {
  1059. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1060. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1061. result = ret_Upd == "成功" ? 1 : 6;
  1062. AddMessage( LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功");
  1063. }
  1064. else
  1065. {
  1066. result = 5;
  1067. AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1068. }
  1069. string sql_response = stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1070. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1071. }
  1072. catch (Exception ex)
  1073. {
  1074. result = 6;
  1075. string str = ex.StackTrace;
  1076. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1077. }
  1078. }
  1079. return result;
  1080. }
  1081. /// <summary>
  1082. /// 选择如何记录出站数据
  1083. /// </summary>
  1084. /// <param name="items">出站数据</param>
  1085. /// <param name="equipmentCode">设备编号</param>
  1086. /// <param name="processItem">测试项目</param>
  1087. /// <param name="workorder_code">车间订单号</param>
  1088. /// <param name="batch_num">批次号</param>
  1089. /// <param name="mtltmrk">型号</param>
  1090. /// <param name="proDate">日期</param>
  1091. /// <param name="supplierCode">供应商代码</param>
  1092. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1093. /// <returns>上传成功时返回1;失败返回0</returns>
  1094. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode, string processItem,
  1095. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1096. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode)
  1097. {
  1098. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
  1099. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode);
  1100. }
  1101. /// <summary>
  1102. /// 添加出站数据(提交到MES+本地保存到数据库)
  1103. /// </summary>
  1104. /// <param name="items">出站数据</param>
  1105. /// <param name="equipmentCode">设备编号</param>
  1106. /// <param name="processItem">测试项目</param>
  1107. /// <param name="workorder_code">车间订单号</param>
  1108. /// <param name="batch_num">批次号</param>
  1109. /// <param name="mtltmrk">型号</param>
  1110. /// <param name="proDate">日期</param>
  1111. /// <param name="supplierCode">供应商代码</param>
  1112. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1113. /// <returns>上传成功时返回1;失败返回0</returns>
  1114. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1115. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1116. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode)
  1117. {
  1118. int upload = 0;
  1119. int result = 0;
  1120. ProcessData processData = new ProcessData()
  1121. {
  1122. Equipment_code = equipmentCode,
  1123. Workorder_code = workorder_code,
  1124. Batch_number = batch_num,
  1125. Sn = sn, // SN
  1126. Testitem = processItem,
  1127. Parameter_values = items,
  1128. Write_user = GlobalContext.CurrentUser,
  1129. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1130. };
  1131. // 本地数据
  1132. string sql = processData.ToStringInsert(upload);
  1133. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1134. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1135. // 上传MES
  1136. if (GlobalContext.IsSendProcessData)
  1137. {
  1138. try
  1139. {
  1140. string id = processData.ID.Copy();
  1141. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1142. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1143. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1144. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1145. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1146. outRequest_Body.unitSn = sn; // 产品SN
  1147. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1148. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1149. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1150. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1151. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1152. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1153. if (!string.IsNullOrEmpty(partBarcode))
  1154. {
  1155. outRequest_Body.unitData.keyMaterial.Add(
  1156. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1157. {
  1158. bindSort = 1,
  1159. materialSn = partBarcode
  1160. }); // 设备数据 - 部件码
  1161. }
  1162. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1163. if (GlobalContext.IsSendProcessData)
  1164. {
  1165. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1166. string mesRet = string.Empty;
  1167. int i = 0;
  1168. while (i < 2) // 1009会多次尝试上传
  1169. {
  1170. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1171. if (response != null && response.header.code == "200")
  1172. break;
  1173. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1174. i++;
  1175. i++;
  1176. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1177. // 记录失败原因
  1178. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1179. }
  1180. if (response?.header?.code == "200")
  1181. {
  1182. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1183. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1184. result = 1;
  1185. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1186. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1187. }
  1188. else
  1189. {
  1190. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:"+ mesRet);
  1191. }
  1192. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(JsonConvert.SerializeObject(outRequest_Body),
  1193. JsonConvert.SerializeObject(response), id);
  1194. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1195. }
  1196. }
  1197. catch (Exception ex)
  1198. {
  1199. string str = ex.StackTrace;
  1200. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1201. }
  1202. }
  1203. return result;
  1204. }
  1205. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1206. //{
  1207. // Stopwatch stopwatch = new Stopwatch();
  1208. // stopwatch.Start();
  1209. // try
  1210. // {
  1211. // // 初始化 AtlasScrew 实例
  1212. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1213. // atlasScrew1.Initial();
  1214. // // 存储结果的列表
  1215. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1216. // // 存储角度和扭力的字符串列表
  1217. // List<string> angleStrs = new List<string>();
  1218. // List<string> torqueStrs = new List<string>();
  1219. // // 上一次获取的数据
  1220. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1221. // while (isExitAtlasLeft) // 检查是否收集数据
  1222. // {
  1223. // // 获取当前数据
  1224. // var currentResult = atlasScrew1.GetResults();
  1225. // // 判断是否为新数据
  1226. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1227. // {
  1228. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1229. // // 更新角度和扭力的字符串列表
  1230. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1231. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1232. // // 计算角度、扭力、起始扭力和最大扭力
  1233. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1234. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1235. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1236. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1237. // // 将新数据添加到结果列表
  1238. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1239. // // 更新上一次获取的数据
  1240. // lastResult = currentResult;
  1241. // }
  1242. // // 等待一段时间后再次检查
  1243. // Thread.Sleep(20); // 轮询间隔时间
  1244. // // 如果触发了出站,则退出循环
  1245. // if (!isExitAtlasLeft)
  1246. // {
  1247. // break;
  1248. // }
  1249. // }
  1250. // // 生成文件名
  1251. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1252. // // 写入数据到文件
  1253. // using (StreamWriter writer = new StreamWriter(fileName))
  1254. // {
  1255. // // 写入标题行
  1256. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1257. // // 写入每一行数据
  1258. // foreach (var result in results)
  1259. // {
  1260. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1261. // }
  1262. // }
  1263. // stopwatch.Stop();
  1264. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1265. // }
  1266. // catch (Exception ex)
  1267. // {
  1268. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1269. // }
  1270. // finally
  1271. // {
  1272. // // 重置标志变量
  1273. // isExitAtlasLeft = false;
  1274. // }
  1275. //}
  1276. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1277. //{
  1278. // Stopwatch stopwatch = new Stopwatch();
  1279. // stopwatch.Start();
  1280. // try
  1281. // {
  1282. // // 初始化 AtlasScrew 实例
  1283. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1284. // atlasScrew2.Initial();
  1285. // // 存储结果的列表
  1286. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1287. // // 上一次获取的数据
  1288. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1289. // while (isExitAtlasRight) // 检查是否收集数据
  1290. // {
  1291. // // 获取当前数据
  1292. // var currentResult = atlasScrew2.GetResults();
  1293. // // 判断是否为新数据
  1294. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1295. // {
  1296. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1297. // // 将新数据写入PLC
  1298. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1299. // // 将新数据添加到结果列表
  1300. // results.Add(currentResult);
  1301. // // 更新上一次获取的数据
  1302. // lastResult = currentResult;
  1303. // }
  1304. // // 等待一段时间后再次检查
  1305. // Thread.Sleep(20); // 轮询间隔时间
  1306. // // 如果触发了出站,则退出循环
  1307. // if (!isExitAtlasRight)
  1308. // {
  1309. // break;
  1310. // }
  1311. // }
  1312. // // 将所有数据写入文件
  1313. // //WriteDataToFile(sn, direction, results);
  1314. // stopwatch.Stop();
  1315. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1316. // }
  1317. // catch (Exception ex)
  1318. // {
  1319. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1320. // }
  1321. // finally
  1322. // {
  1323. // // 重置标志变量
  1324. // isExitAtlasRight = false;
  1325. // }
  1326. //}
  1327. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1328. {
  1329. Stopwatch stopwatch = new Stopwatch();
  1330. stopwatch.Start();
  1331. int nRet = 0;
  1332. string strRet = "";
  1333. try
  1334. {
  1335. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1336. while (isCollectingFlagLeft)
  1337. {
  1338. // 从缓存中获取所有未处理的数据
  1339. var cachedData = atlasScrew.GetCachedDataLeft();
  1340. foreach (var currentResult in cachedData)
  1341. {
  1342. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1343. {
  1344. continue; // 跳过无效数据
  1345. }
  1346. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1347. // 写入PLC
  1348. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1349. {
  1350. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1351. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1352. };
  1353. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1354. if (nRet != 0)
  1355. {
  1356. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1357. }
  1358. else
  1359. {
  1360. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1361. }
  1362. // 构建保存路径
  1363. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1364. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1365. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1366. Directory.CreateDirectory(savePath); // 确保目录存在
  1367. // 构建文件名(以 SN + 序号命名)
  1368. string fileName = $"{sn}_{fileCounter}.txt";
  1369. string filePath = Path.Combine(savePath, fileName);
  1370. // 写入文件
  1371. using (StreamWriter writer = new StreamWriter(filePath))
  1372. {
  1373. writer.WriteLine("精度, 扭力");
  1374. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1375. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1376. {
  1377. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1378. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1379. writer.WriteLine($"{precision}, {torque}");
  1380. }
  1381. }
  1382. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1383. // 增加文件计数器
  1384. fileCounter++;
  1385. }
  1386. // 如果没有更多数据,则短暂休眠以节省资源
  1387. if (!cachedData.Any())
  1388. {
  1389. Thread.Sleep(10); // 根据需要调整休眠时间
  1390. }
  1391. // 如果触发了出站,则退出循环
  1392. if (!isCollectingFlagLeft)
  1393. {
  1394. break;
  1395. }
  1396. }
  1397. stopwatch.Stop();
  1398. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1399. }
  1400. catch (Exception ex)
  1401. {
  1402. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1403. }
  1404. finally
  1405. {
  1406. isCollectingFlagLeft = false;
  1407. }
  1408. }
  1409. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1410. {
  1411. Stopwatch stopwatch = new Stopwatch();
  1412. stopwatch.Start();
  1413. int nRet = 0;
  1414. string strRet = "";
  1415. try
  1416. {
  1417. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1418. while (isCollectingFlagRight)
  1419. {
  1420. // 从缓存中获取所有未处理的数据
  1421. var cachedData = atlasScrew.GetCachedDataLeft();
  1422. foreach (var currentResult in cachedData)
  1423. {
  1424. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1425. {
  1426. continue; // 跳过无效数据
  1427. }
  1428. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1429. // 写入PLC
  1430. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1431. {
  1432. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1433. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1434. };
  1435. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1436. if (nRet != 0)
  1437. {
  1438. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1439. }
  1440. else
  1441. {
  1442. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1443. }
  1444. // 构建保存路径
  1445. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1446. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1447. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction,"曲线");
  1448. Directory.CreateDirectory(savePath); // 确保目录存在
  1449. // 构建文件名(以 SN + 序号命名)
  1450. string fileName = $"{sn}_{fileCounter}.txt";
  1451. string filePath = Path.Combine(savePath, fileName);
  1452. // 写入文件
  1453. using (StreamWriter writer = new StreamWriter(filePath))
  1454. {
  1455. writer.WriteLine("精度, 扭力");
  1456. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1457. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1458. {
  1459. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1460. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1461. writer.WriteLine($"{precision}, {torque}");
  1462. }
  1463. }
  1464. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1465. // 增加文件计数器
  1466. fileCounter++;
  1467. }
  1468. // 如果没有更多数据,则短暂休眠以节省资源
  1469. if (!cachedData.Any())
  1470. {
  1471. Thread.Sleep(10); // 根据需要调整休眠时间
  1472. }
  1473. // 如果触发了出站,则退出循环
  1474. if (!isCollectingFlagRight)
  1475. {
  1476. break;
  1477. }
  1478. }
  1479. stopwatch.Stop();
  1480. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1481. }
  1482. catch (Exception ex)
  1483. {
  1484. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1485. }
  1486. finally
  1487. {
  1488. isCollectingFlagRight = false;
  1489. }
  1490. }
  1491. #endregion
  1492. #region S1
  1493. /// <summary>
  1494. /// [S1] 壳体清洁上料装备
  1495. /// </summary>
  1496. /// <param name="plcNo">PLC编号</param>
  1497. private void ReadStation_S1(int plcNo)
  1498. {
  1499. string stationCode = "[OP10]";
  1500. string stationName = "壳体清洁上料";
  1501. string stationNameStr = stationCode + stationName;
  1502. string tagBaseName = "g_OP10_MES"; //标签变量名称
  1503. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1504. string tagAgvCommName = "agvCommFrmPC";
  1505. string tagBarsetName = "BarcodeSet";
  1506. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  1507. (int, string) result;
  1508. while (true)
  1509. {
  1510. try
  1511. {
  1512. if (!GlobalContext._IsCon_Funs1)
  1513. {
  1514. UpdatePLCMonitor(1, plcNo, 0);
  1515. continue;
  1516. }
  1517. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1518. {
  1519. Stopwatch stopwatch1 = new Stopwatch();
  1520. Stopwatch stopwatch2 = new Stopwatch();
  1521. stopwatch1.Start();
  1522. stopwatch2.Start();
  1523. #region 一次性读取所有数据
  1524. // 一次性读取所有数据
  1525. result = FunsEip[plcNo].Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData,this); //读取单个结构体数据
  1526. if (result.Item1 != 0)
  1527. {
  1528. //richTextBox1.AppendText("\n" + strRet);
  1529. }
  1530. else
  1531. {
  1532. //richTextBox1.AppendText("\n" + "读取成功");
  1533. }
  1534. #endregion 一次性读取所有数据
  1535. stopwatch2.Stop();
  1536. #region 进站
  1537. try
  1538. {
  1539. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1540. {
  1541. lock (lockObj)
  1542. {
  1543. if (!ProgressState)
  1544. {
  1545. ProgressState = true;
  1546. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  1547. }
  1548. }
  1549. }
  1550. }
  1551. catch (Exception ex)
  1552. {
  1553. ProgressState = false;
  1554. string str = ex.StackTrace;
  1555. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1556. }
  1557. #endregion 进站
  1558. #region 出站
  1559. try
  1560. {
  1561. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1562. {
  1563. lock (lockObj)
  1564. {
  1565. if (!ProgressState)
  1566. {
  1567. ProgressState = true;
  1568. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1569. stPLC_MesData.mesCommFrmPLC.cmd = 0;//清除入站申请
  1570. }
  1571. }
  1572. }
  1573. }
  1574. catch (Exception ex)
  1575. {
  1576. ProgressState = false;
  1577. string str = ex.StackTrace;
  1578. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1579. }
  1580. #endregion 出站
  1581. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1582. stopwatch1.Stop();
  1583. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1584. }
  1585. else
  1586. {
  1587. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1588. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1589. FunsEip[plcNo].Connect(); // 重连
  1590. }
  1591. }
  1592. catch (Exception ex)
  1593. {
  1594. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1595. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1596. }
  1597. Thread.Sleep(IntervalReadPLC);
  1598. }
  1599. }
  1600. /// <summary>
  1601. /// [S1] 壳体清洁上料 - 进站
  1602. /// </summary>
  1603. /// <param name="plcNo">PLC编号</param>
  1604. /// <param name="stationNameStr">工站全称</param>
  1605. /// <param name="stPLC_MesData"></param>
  1606. /// <param name="tagMesCommName"></param>
  1607. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  1608. {
  1609. Stopwatch stopwatch1 = new Stopwatch();
  1610. Stopwatch stopwatch2 = new Stopwatch();
  1611. try
  1612. {
  1613. stopwatch1.Start();
  1614. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1615. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  1616. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1617. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  1618. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  1619. if (string.IsNullOrEmpty(sn))
  1620. {
  1621. ProgressState = false;
  1622. return;
  1623. }
  1624. //正式生产就用PLC中取的
  1625. //sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;
  1626. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  1627. sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1628. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1629. //绑定载具和产品
  1630. ResponseMessage message = new ResponseMessage();
  1631. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  1632. if (message.result == false)
  1633. {
  1634. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  1635. }
  1636. // 产品SN进站
  1637. List<TestItem> item = new List<TestItem>();
  1638. stopwatch2.Start();
  1639. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1640. stopwatch2.Stop();
  1641. //指令执行结果 1:OK 110:失败
  1642. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1643. //进站结果写入PLC
  1644. CommandFromPLC resultToPlC = new CommandFromPLC();
  1645. resultToPlC.cmd = 0;
  1646. resultToPlC.cmdParam = 0;
  1647. resultToPlC.cmdResult = mesResultFrmWeb;
  1648. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1649. }
  1650. catch (Exception ex)
  1651. {
  1652. string str = ex.StackTrace;
  1653. AddMessage( LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1654. CommandFromPLC resultToPlC = new CommandFromPLC();
  1655. resultToPlC.cmd = 0;
  1656. resultToPlC.cmdParam = 0; //指令参数
  1657. resultToPlC.cmdResult = 110;
  1658. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1659. }
  1660. stopwatch1.Stop();
  1661. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  1662. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1663. ProgressState = false;
  1664. }
  1665. /// <summary>
  1666. /// [S1] 壳体清洁上料 - 出站接口
  1667. /// </summary>
  1668. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1669. {
  1670. Stopwatch stopwatch1 = new Stopwatch();
  1671. Stopwatch stopwatch2 = new Stopwatch();
  1672. try
  1673. {
  1674. stopwatch1.Start();
  1675. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  1676. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1677. string processItem = stationName; // 项目
  1678. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1679. string supplierCode = ""; // 供应商代码
  1680. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  1681. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  1682. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  1683. string sn = string.Empty;
  1684. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1685. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  1686. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  1687. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1688. a1Result = 1;
  1689. bool pass = a1Result == 1;
  1690. //根据载具码获取产品码
  1691. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1692. if (string.IsNullOrEmpty(strProductBarcode))
  1693. {
  1694. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1695. }
  1696. sn = strProductBarcode;
  1697. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1698. List<TestItem> items = new List<TestItem>();
  1699. items.Add(new TestItem()
  1700. {
  1701. Parameter_name = "载具码",
  1702. Parameter_value = CarrierBarcode,
  1703. Parameter_unit = ""
  1704. });
  1705. items.Add(new TestItem()
  1706. {
  1707. Parameter_name = "产品码",
  1708. Parameter_value = sn,
  1709. Parameter_unit = ""
  1710. });
  1711. //出站接口
  1712. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1713. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  1714. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1715. stopwatch2.Start();
  1716. //进站结果写入PLC
  1717. CommandFromPLC resultToPlC = new CommandFromPLC();
  1718. resultToPlC.cmd = 0;
  1719. resultToPlC.cmdParam = 0; //指令参数
  1720. resultToPlC.cmdResult = mesResultFrmWeb;
  1721. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1722. stopwatch2.Stop();
  1723. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  1724. //保存PLC返回MES数据到本地
  1725. ResponseMessage message = new ResponseMessage();
  1726. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  1727. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress, stPLC_MesData.mesData.fCleanSpeed,
  1728. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime, stPLC_MesData.mesData.nCleanCount,
  1729. stPLC_MesData.mesData.nRemainCount);
  1730. if (message.result == false)
  1731. {
  1732. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  1733. }
  1734. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  1735. }
  1736. catch (Exception ex)
  1737. {
  1738. stopwatch2.Start();
  1739. CommandFromPLC resultToPlC = new CommandFromPLC();
  1740. resultToPlC.cmd = 0;
  1741. resultToPlC.cmdParam = 0; //指令参数
  1742. resultToPlC.cmdResult = 110;
  1743. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1744. stopwatch2.Stop();
  1745. string str = ex.StackTrace;
  1746. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1747. }
  1748. stopwatch1.Stop();
  1749. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1750. ProgressState = false;
  1751. }
  1752. #endregion
  1753. #region S2
  1754. /// <summary>
  1755. /// [S2] 上盖板上料装备
  1756. /// </summary>
  1757. /// <param name="plcNo">PLC编号</param>
  1758. private void ReadStation_S2(int plcNo)
  1759. {
  1760. string stationCode = "[OP20]";
  1761. string stationName = "上盖板上料装备";
  1762. string stationNameStr = stationCode + stationName;
  1763. string tagBaseName = "g_OP20_MES"; //标签变量名称
  1764. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1765. string tagAgvCommName = "agvCommFrmPC";
  1766. string tagBarsetName = "BarcodeSet";
  1767. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  1768. (int, string) result;
  1769. while (true)
  1770. {
  1771. try
  1772. {
  1773. if (!GlobalContext._IsCon_Funs2)
  1774. {
  1775. UpdatePLCMonitor(1, plcNo, 0);
  1776. continue;
  1777. }
  1778. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1779. {
  1780. Stopwatch stopwatch1 = new Stopwatch();
  1781. Stopwatch stopwatch2 = new Stopwatch();
  1782. stopwatch1.Start();
  1783. stopwatch2.Start();
  1784. #region 一次性读取所有数据
  1785. // 一次性读取所有数据
  1786. result = FunsEip[plcNo].Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  1787. if (result.Item1 != 0)
  1788. {
  1789. //richTextBox1.AppendText("\n" + strRet);
  1790. }
  1791. else
  1792. {
  1793. //richTextBox1.AppendText("\n" + "读取成功");
  1794. }
  1795. #endregion 一次性读取所有数据
  1796. stopwatch2.Stop();
  1797. #region 进站
  1798. try
  1799. {
  1800. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1801. {
  1802. lock (lockObj)
  1803. {
  1804. if (!ProgressState)
  1805. {
  1806. ProgressState = true;
  1807. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  1808. }
  1809. }
  1810. }
  1811. }
  1812. catch (Exception ex)
  1813. {
  1814. ProgressState = false;
  1815. string str = ex.StackTrace;
  1816. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1817. }
  1818. #endregion 进站
  1819. #region 出站
  1820. try
  1821. {
  1822. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1823. {
  1824. lock (lockObj)
  1825. {
  1826. if (!ProgressState)
  1827. {
  1828. ProgressState = true;
  1829. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1830. stPLC_MesData.mesCommFrmPLC.cmd = 0;//清除入站申请
  1831. }
  1832. }
  1833. }
  1834. }
  1835. catch (Exception ex)
  1836. {
  1837. ProgressState = false;
  1838. string str = ex.StackTrace;
  1839. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1840. }
  1841. #endregion 出站
  1842. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1843. stopwatch1.Stop();
  1844. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  1845. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1846. }
  1847. else
  1848. {
  1849. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1850. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1851. FunsEip[plcNo].Connect();
  1852. }
  1853. }
  1854. catch (Exception ex)
  1855. {
  1856. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1857. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1858. //Funs[plcNo].ReConnect();
  1859. }
  1860. Thread.Sleep(IntervalReadPLC);
  1861. }
  1862. }
  1863. /// <summary>
  1864. /// [S2] 上盖板上料装备
  1865. /// </summary>
  1866. /// <param name="plcNo">PLC编号</param>
  1867. /// <param name="stationNameStr">工站全称</param>
  1868. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  1869. {
  1870. Stopwatch stopwatch1 = new Stopwatch();
  1871. Stopwatch stopwatch2 = new Stopwatch();
  1872. try
  1873. {
  1874. stopwatch1.Start();
  1875. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1876. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  1877. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1878. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  1879. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  1880. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  1881. //根据载具码获取产品码
  1882. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  1883. if (string.IsNullOrEmpty(strProductBarcode))
  1884. {
  1885. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1886. }
  1887. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  1888. //if (sn != strProductBarcode)
  1889. //{
  1890. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  1891. //}
  1892. sn = strProductBarcode;
  1893. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  1894. // 产品SN(物料码)校验
  1895. List<TestItem> item = new List<TestItem>();
  1896. stopwatch2.Start();
  1897. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1898. stopwatch2.Stop();
  1899. //指令执行结果 1:OK 110:失败
  1900. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1901. //进站结果写入PLC
  1902. CommandFromPLC resultToPlC = new CommandFromPLC();
  1903. resultToPlC.cmd = 0;
  1904. resultToPlC.cmdParam = 0; //指令参数
  1905. resultToPlC.cmdResult = mesResultFrmWeb;
  1906. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1907. }
  1908. catch (Exception ex)
  1909. {
  1910. string str = ex.StackTrace;
  1911. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1912. CommandFromPLC resultToPlC = new CommandFromPLC();
  1913. resultToPlC.cmd = 0;
  1914. resultToPlC.cmdParam = 0; //指令参数
  1915. resultToPlC.cmdResult = 110;
  1916. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1917. }
  1918. stopwatch1.Stop();
  1919. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  1920. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1921. ProgressState = false;
  1922. }
  1923. /// <summary>
  1924. /// [S2] 上盖板上料装备 - 出站接口
  1925. /// </summary>
  1926. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1927. {
  1928. Stopwatch stopwatch1 = new Stopwatch();
  1929. Stopwatch stopwatch2 = new Stopwatch();
  1930. try
  1931. {
  1932. stopwatch1.Start();
  1933. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  1934. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1935. string processItem = stationName; // 测试项目
  1936. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1937. string supplierCode = ""; // 供应商代码
  1938. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  1939. string batch_num = GlobalContext.BatchNumber; // 批次号
  1940. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  1941. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  1942. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1943. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  1944. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  1945. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  1946. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1947. bool pass = a1Result == 1;
  1948. //根据载具码获取产品码
  1949. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1950. if (string.IsNullOrEmpty(strProductBarcode))
  1951. {
  1952. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1953. }
  1954. sn = strProductBarcode;
  1955. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1956. List<TestItem> items = new List<TestItem>();
  1957. items.Add(new TestItem()
  1958. {
  1959. Parameter_name = "载具码",
  1960. Parameter_value = CarrierBarcode,
  1961. Parameter_unit = ""
  1962. });
  1963. items.Add(new TestItem()
  1964. {
  1965. Parameter_name = "产品码",
  1966. Parameter_value = sn,
  1967. Parameter_unit = ""
  1968. });
  1969. items.Add(new TestItem()
  1970. {
  1971. Parameter_name = "部件码",
  1972. Parameter_value = PartBarcode,
  1973. Parameter_unit = ""
  1974. });
  1975. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1976. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  1977. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1978. stopwatch2.Start();
  1979. //进站结果写入PLC
  1980. CommandFromPLC resultToPlC = new CommandFromPLC();
  1981. resultToPlC.cmd = 0;
  1982. resultToPlC.cmdParam = 0; //指令参数
  1983. resultToPlC.cmdResult = mesResultFrmWeb;
  1984. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1985. stopwatch2.Stop();
  1986. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  1987. //保存PLC返回MES数据到本地
  1988. ResponseMessage message = new ResponseMessage();
  1989. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  1990. if (message.result == false)
  1991. {
  1992. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  1993. }
  1994. if (!string.IsNullOrEmpty(PartBarcode))
  1995. {
  1996. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  1997. if (message.result == false)
  1998. {
  1999. AddMessage(LogType.Error, message.text);
  2000. }
  2001. }
  2002. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2003. }
  2004. catch (Exception ex)
  2005. {
  2006. stopwatch2.Start();
  2007. CommandFromPLC resultToPlC = new CommandFromPLC();
  2008. resultToPlC.cmd = 0;
  2009. resultToPlC.cmdParam = 0; //指令参数
  2010. resultToPlC.cmdResult = 110;
  2011. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2012. stopwatch2.Stop();
  2013. string str = ex.StackTrace;
  2014. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2015. }
  2016. stopwatch1.Stop();
  2017. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2018. ProgressState = false;
  2019. }
  2020. #endregion
  2021. #region S3
  2022. /// <summary>
  2023. /// [S3] 点散热胶装备
  2024. /// </summary>
  2025. /// <param name="plcNo">PLC编号</param>
  2026. private void ReadStation_S3(int plcNo)
  2027. {
  2028. string stationCode = "[OP30]";
  2029. string stationName = "点散热胶装备";
  2030. string stationNameStr = stationCode + stationName;
  2031. string tagBaseName = "g_OP30_MES"; //标签变量名称
  2032. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2033. string tagAgvCommName = "agvCommFrmPC";
  2034. string tagBarsetName = "BarcodeSet";
  2035. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  2036. (int, string) result;
  2037. #region 创建字典
  2038. // 触发信号字典 赋值
  2039. s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2040. s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2041. s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2042. s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2043. s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2044. // PLC数据字典 赋值
  2045. s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2046. s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  2047. s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2048. s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2049. s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  2050. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2051. s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2052. s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2053. s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  2054. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2055. s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  2056. s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  2057. s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  2058. s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2059. s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  2060. s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  2061. //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  2062. s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2063. s3PLCData.Add("c1Result", 0); // 产品结果
  2064. s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2065. s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  2066. s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  2067. s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  2068. #endregion 创建字典
  2069. while (true)
  2070. {
  2071. try
  2072. {
  2073. if (!GlobalContext._IsCon_Funs2)
  2074. {
  2075. UpdatePLCMonitor(1, plcNo, 0);
  2076. continue;
  2077. }
  2078. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2079. {
  2080. Stopwatch stopwatch1 = new Stopwatch();
  2081. Stopwatch stopwatch2 = new Stopwatch();
  2082. stopwatch1.Start();
  2083. stopwatch2.Start();
  2084. #region 一次性读取所有数据
  2085. // 一次性读取所有数据
  2086. result = FunsEip[plcNo].Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2087. if (result.Item1 != 0)
  2088. {
  2089. //richTextBox1.AppendText("\n" + strRet);
  2090. }
  2091. else
  2092. {
  2093. //richTextBox1.AppendText("\n" + "读取成功");
  2094. }
  2095. #endregion 一次性读取所有数据
  2096. stopwatch2.Stop();
  2097. #region 左边进站
  2098. try
  2099. {
  2100. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2101. {
  2102. lock (lockObj)
  2103. {
  2104. if (!ProgressState)
  2105. {
  2106. ProgressState = true;
  2107. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  2108. }
  2109. }
  2110. }
  2111. }
  2112. catch (Exception ex)
  2113. {
  2114. ProgressState = false;
  2115. string str = ex.StackTrace;
  2116. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2117. }
  2118. #endregion 左边进站
  2119. #region 左边出站
  2120. try
  2121. {
  2122. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2123. {
  2124. lock (lockObj)
  2125. {
  2126. if (!ProgressState)
  2127. {
  2128. ProgressState = true;
  2129. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  2130. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  2131. }
  2132. }
  2133. }
  2134. }
  2135. catch (Exception ex)
  2136. {
  2137. ProgressState = false;
  2138. string str = ex.StackTrace;
  2139. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2140. }
  2141. #endregion 左边出站
  2142. #region 右边进站
  2143. try
  2144. {
  2145. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2146. {
  2147. lock (lockObj)
  2148. {
  2149. if (!ProgressState)
  2150. {
  2151. ProgressState = true;
  2152. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right." + tagBarsetName,"Right", out ProgressState));
  2153. }
  2154. }
  2155. }
  2156. }
  2157. catch (Exception ex)
  2158. {
  2159. ProgressState = false;
  2160. string str = ex.StackTrace;
  2161. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2162. }
  2163. #endregion 右边进站
  2164. #region 右边出站
  2165. try
  2166. {
  2167. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2168. {
  2169. lock (lockObj)
  2170. {
  2171. if (!ProgressState)
  2172. {
  2173. ProgressState = true;
  2174. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  2175. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  2176. }
  2177. }
  2178. }
  2179. }
  2180. catch (Exception ex)
  2181. {
  2182. string str = ex.StackTrace;
  2183. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2184. }
  2185. #endregion 右边出站
  2186. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2187. stopwatch1.Stop();
  2188. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2189. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2190. }
  2191. else
  2192. {
  2193. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2194. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2195. FunsEip[plcNo].Connect();
  2196. }
  2197. }
  2198. catch (Exception ex)
  2199. {
  2200. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2201. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2202. //Funs[plcNo].ReConnect();
  2203. }
  2204. Thread.Sleep(IntervalReadPLC);
  2205. }
  2206. }
  2207. /// <summary>
  2208. /// [S3] 点散热胶装备 - 进站
  2209. /// </summary>
  2210. /// <param name="plcNo">PLC编号</param>
  2211. /// <param name="stationNameStr">工站全称</param>
  2212. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName,string direction, out bool ProgressState)
  2213. {
  2214. Stopwatch stopwatch1 = new Stopwatch();
  2215. Stopwatch stopwatch2 = new Stopwatch();
  2216. try
  2217. {
  2218. stopwatch1.Start();
  2219. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_进站开始");
  2220. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2221. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  2222. string StationId=string.Empty;
  2223. if (direction=="Left")
  2224. {
  2225. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2226. }
  2227. if (direction == "Right")
  2228. {
  2229. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2230. }
  2231. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2232. //载具码验证产品码
  2233. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2234. if (string.IsNullOrEmpty(strProductBarcode))
  2235. {
  2236. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2237. }
  2238. sn = strProductBarcode;
  2239. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  2240. // 产品SN(物料码)校验
  2241. List<TestItem> item = new List<TestItem>();
  2242. stopwatch2.Start();
  2243. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2244. stopwatch2.Stop();
  2245. //指令执行结果 1:OK 110:失败
  2246. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2247. //进站结果写入PLC
  2248. CommandFromPLC resultToPlC = new CommandFromPLC();
  2249. resultToPlC.cmd = 0;
  2250. resultToPlC.cmdParam = 0; //指令参数
  2251. resultToPlC.cmdResult = mesResultFrmWeb;
  2252. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2253. }
  2254. catch (Exception ex)
  2255. {
  2256. string str = ex.StackTrace;
  2257. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2258. CommandFromPLC resultToPlC = new CommandFromPLC();
  2259. resultToPlC.cmd = 0;
  2260. resultToPlC.cmdParam = 0; //指令参数
  2261. resultToPlC.cmdResult = 110;
  2262. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2263. }
  2264. stopwatch1.Stop();
  2265. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  2266. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2267. ProgressState = false;
  2268. }
  2269. /// <summary>
  2270. /// [S3] 点散热胶装备 - 出站
  2271. /// </summary>
  2272. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  2273. {
  2274. Stopwatch stopwatch1 = new Stopwatch();
  2275. Stopwatch stopwatch2 = new Stopwatch();
  2276. try
  2277. {
  2278. stopwatch1.Start();
  2279. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  2280. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2281. string processItem = stationName; // 测试项目
  2282. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2283. string supplierCode = ""; // 供应商代码
  2284. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2285. string batch_num = GlobalContext.BatchNumber; // 批次号
  2286. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2287. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2288. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2289. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  2290. string StationId = string.Empty;
  2291. if (direction == "Left")
  2292. {
  2293. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2294. }
  2295. if (direction == "Right")
  2296. {
  2297. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2298. }
  2299. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2300. bool pass = a1Result == 1;
  2301. //根据载具码获取产品码
  2302. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2303. if (string.IsNullOrEmpty(strProductBarcode))
  2304. {
  2305. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2306. }
  2307. sn = strProductBarcode;
  2308. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2309. List<TestItem> items = new List<TestItem>();
  2310. items.Add(new TestItem()
  2311. {
  2312. Parameter_name = "载具码",
  2313. Parameter_value = CarrierBarcode,
  2314. Parameter_unit = ""
  2315. });
  2316. items.Add(new TestItem()
  2317. {
  2318. Parameter_name = "产品码",
  2319. Parameter_value = sn,
  2320. Parameter_unit = ""
  2321. });
  2322. int result1 = 1;
  2323. if (direction == "Right")
  2324. {
  2325. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2326. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2327. }
  2328. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2329. stopwatch2.Start();
  2330. //进站结果写入PLC
  2331. CommandFromPLC resultToPlC = new CommandFromPLC();
  2332. resultToPlC.cmd = 0;
  2333. resultToPlC.cmdParam = 0; //指令参数
  2334. resultToPlC.cmdResult = mesResultFrmWeb;
  2335. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2336. stopwatch2.Stop();
  2337. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  2338. //保存PLC返回MES数据到本地
  2339. ResponseMessage message = new ResponseMessage();
  2340. if (direction == "Left")
  2341. {
  2342. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2343. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2344. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2345. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2346. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2347. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2348. if (message.result == false)
  2349. {
  2350. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2351. }
  2352. }
  2353. if (direction == "Right")
  2354. {
  2355. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2356. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2357. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2358. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2359. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2360. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2361. if (message.result == false)
  2362. {
  2363. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2364. }
  2365. }
  2366. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2367. }
  2368. catch (Exception ex)
  2369. {
  2370. stopwatch2.Start();
  2371. CommandFromPLC resultToPlC = new CommandFromPLC();
  2372. resultToPlC.cmd = 0;
  2373. resultToPlC.cmdParam = 0; //指令参数
  2374. resultToPlC.cmdResult = 110;
  2375. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2376. stopwatch2.Stop();
  2377. string str = ex.StackTrace;
  2378. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2379. }
  2380. stopwatch1.Stop();
  2381. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2382. ProgressState = false;
  2383. }
  2384. #endregion S3
  2385. #region S4
  2386. /// <summary>
  2387. /// [S4] 点胶检测设备
  2388. /// </summary>
  2389. /// <param name="plcNo">PLC编号</param>
  2390. private void ReadStation_S4(int plcNo)
  2391. {
  2392. string stationCode = "[OP40]";
  2393. string stationName = "胶线检测";
  2394. string stationNameStr = stationCode + stationName;
  2395. string tagBaseName = "g_OP40_MES"; //标签变量名称
  2396. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2397. string tagAgvCommName = "agvCommFrmPC";
  2398. string tagBarsetName = "BarcodeSet";
  2399. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  2400. (int, string) result;
  2401. while (true)
  2402. {
  2403. try
  2404. {
  2405. if (!GlobalContext._IsCon_Funs1)
  2406. {
  2407. UpdatePLCMonitor(1, plcNo, 0);
  2408. continue;
  2409. }
  2410. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2411. {
  2412. Stopwatch stopwatch1 = new Stopwatch();
  2413. Stopwatch stopwatch2 = new Stopwatch();
  2414. stopwatch1.Start();
  2415. stopwatch2.Start();
  2416. #region 一次性读取所有数据
  2417. // 一次性读取所有数据
  2418. result = FunsEip[plcNo].Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2419. if (result.Item1 != 0)
  2420. {
  2421. //richTextBox1.AppendText("\n" + strRet);
  2422. }
  2423. else
  2424. {
  2425. //richTextBox1.AppendText("\n" + "读取成功");
  2426. }
  2427. #endregion 一次性读取所有数据
  2428. stopwatch2.Stop();
  2429. #region 进站
  2430. try
  2431. {
  2432. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2433. {
  2434. lock (lockObj)
  2435. {
  2436. if (!ProgressState)
  2437. {
  2438. ProgressState = true;
  2439. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2440. }
  2441. }
  2442. }
  2443. }
  2444. catch (Exception ex)
  2445. {
  2446. ProgressState = false;
  2447. string str = ex.StackTrace;
  2448. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2449. }
  2450. #endregion 进站
  2451. #region 出站
  2452. try
  2453. {
  2454. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2455. {
  2456. lock (lockObj)
  2457. {
  2458. if (!ProgressState)
  2459. {
  2460. ProgressState = true;
  2461. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2462. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2463. }
  2464. }
  2465. }
  2466. }
  2467. catch (Exception ex)
  2468. {
  2469. string str = ex.StackTrace;
  2470. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2471. }
  2472. #endregion 出站
  2473. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2474. stopwatch1.Stop();
  2475. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2476. }
  2477. else
  2478. {
  2479. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2480. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2481. FunsEip[plcNo].Connect(); // 重连
  2482. }
  2483. }
  2484. catch (Exception ex)
  2485. {
  2486. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2487. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2488. }
  2489. Thread.Sleep(IntervalReadPLC);
  2490. }
  2491. }
  2492. /// <summary>
  2493. /// [S4] 点胶检测设备 - 进站
  2494. /// </summary>
  2495. /// <param name="plcNo">PLC编号</param>
  2496. /// <param name="stationNameStr">工站全称</param>
  2497. /// <param name="stPLC_MesData"></param>
  2498. /// <param name="tagMesCommName"></param>
  2499. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2500. {
  2501. Stopwatch stopwatch1 = new Stopwatch();
  2502. Stopwatch stopwatch2 = new Stopwatch();
  2503. try
  2504. {
  2505. stopwatch1.Start();
  2506. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2507. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2508. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  2509. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  2510. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2511. //载具码验证产品码
  2512. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2513. if (string.IsNullOrEmpty(strProductBarcode))
  2514. {
  2515. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2516. }
  2517. sn = strProductBarcode;
  2518. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2519. // 产品SN(物料码)校验
  2520. List<TestItem> item = new List<TestItem>();
  2521. stopwatch2.Start();
  2522. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2523. stopwatch2.Stop();
  2524. //指令执行结果 1:OK 110:失败
  2525. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2526. //进站结果写入PLC
  2527. CommandFromPLC resultToPlC = new CommandFromPLC();
  2528. resultToPlC.cmd = 0;
  2529. resultToPlC.cmdParam = 0; //指令参数
  2530. resultToPlC.cmdResult = mesResultFrmWeb;
  2531. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2532. }
  2533. catch (Exception ex)
  2534. {
  2535. string str = ex.StackTrace;
  2536. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2537. CommandFromPLC resultToPlC = new CommandFromPLC();
  2538. resultToPlC.cmd = 0;
  2539. resultToPlC.cmdParam = 0; //指令参数
  2540. resultToPlC.cmdResult = 110;
  2541. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2542. }
  2543. stopwatch1.Stop();
  2544. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2545. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2546. ProgressState = false;
  2547. }
  2548. /// <summary>
  2549. /// [S4] 点胶检测设备 - 出站接口
  2550. /// </summary>
  2551. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2552. {
  2553. Stopwatch stopwatch1 = new Stopwatch();
  2554. Stopwatch stopwatch2 = new Stopwatch();
  2555. try
  2556. {
  2557. stopwatch1.Start();
  2558. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2559. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2560. string processItem = stationName; // 测试项目
  2561. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2562. string supplierCode = ""; // 供应商代码
  2563. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2564. string batch_num = GlobalContext.BatchNumber; // 批次号
  2565. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2566. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2567. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2568. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  2569. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  2570. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2571. bool pass = a1Result == 1;
  2572. //根据载具码获取产品码
  2573. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2574. if (string.IsNullOrEmpty(strProductBarcode))
  2575. {
  2576. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2577. }
  2578. sn = strProductBarcode;
  2579. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2580. List<TestItem> items = new List<TestItem>();
  2581. items.Add(new TestItem()
  2582. {
  2583. Parameter_name = "载具码",
  2584. Parameter_value = CarrierBarcode,
  2585. Parameter_unit = ""
  2586. });
  2587. items.Add(new TestItem()
  2588. {
  2589. Parameter_name = "产品码",
  2590. Parameter_value = sn,
  2591. Parameter_unit = ""
  2592. });
  2593. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2594. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2595. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2596. stopwatch2.Start();
  2597. //进站结果写入PLC
  2598. CommandFromPLC resultToPlC = new CommandFromPLC();
  2599. resultToPlC.cmd = 0;
  2600. resultToPlC.cmdParam = 0; //指令参数
  2601. resultToPlC.cmdResult = mesResultFrmWeb;
  2602. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2603. stopwatch2.Stop();
  2604. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2605. //保存PLC返回MES数据到本地
  2606. ResponseMessage message = new ResponseMessage();
  2607. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  2608. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  2609. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  2610. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  2611. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  2612. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  2613. if (message.result == false)
  2614. {
  2615. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2616. }
  2617. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2618. }
  2619. catch (Exception ex)
  2620. {
  2621. stopwatch2.Start();
  2622. CommandFromPLC resultToPlC = new CommandFromPLC();
  2623. resultToPlC.cmd = 0;
  2624. resultToPlC.cmdParam = 0; //指令参数
  2625. resultToPlC.cmdResult = 110;
  2626. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2627. stopwatch2.Stop();
  2628. string str = ex.StackTrace;
  2629. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2630. }
  2631. stopwatch1.Stop();
  2632. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2633. ProgressState = false;
  2634. }
  2635. #endregion
  2636. #region S5
  2637. /// <summary>
  2638. /// [S5] 点胶检测设备
  2639. /// </summary>
  2640. /// <param name="plcNo">PLC编号</param>
  2641. private void ReadStation_S5(int plcNo)
  2642. {
  2643. string stationCode = "[OP50]";
  2644. string stationName = "ADD板上料组装装备";
  2645. string stationNameStr = stationCode + stationName;
  2646. string tagBaseName = "g_OP50_MES"; //标签变量名称
  2647. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2648. string tagAgvCommName = "agvCommFrmPC";
  2649. string tagBarsetName = "BarcodeSet";
  2650. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  2651. (int, string) result;
  2652. while (true)
  2653. {
  2654. try
  2655. {
  2656. if (!GlobalContext._IsCon_Funs1)
  2657. {
  2658. UpdatePLCMonitor(1, plcNo, 0);
  2659. continue;
  2660. }
  2661. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2662. {
  2663. Stopwatch stopwatch1 = new Stopwatch();
  2664. Stopwatch stopwatch2 = new Stopwatch();
  2665. stopwatch1.Start();
  2666. stopwatch2.Start();
  2667. #region 一次性读取所有数据
  2668. // 一次性读取所有数据
  2669. result = FunsEip[plcNo].Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2670. if (result.Item1 != 0)
  2671. {
  2672. //richTextBox1.AppendText("\n" + strRet);
  2673. }
  2674. else
  2675. {
  2676. //richTextBox1.AppendText("\n" + "读取成功");
  2677. }
  2678. #endregion 一次性读取所有数据
  2679. stopwatch2.Stop();
  2680. #region 进站
  2681. try
  2682. {
  2683. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2684. {
  2685. lock (lockObj)
  2686. {
  2687. if (!ProgressState)
  2688. {
  2689. ProgressState = true;
  2690. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2691. }
  2692. }
  2693. }
  2694. }
  2695. catch (Exception ex)
  2696. {
  2697. ProgressState = false;
  2698. string str = ex.StackTrace;
  2699. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2700. }
  2701. #endregion 进站
  2702. #region 出站
  2703. try
  2704. {
  2705. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2706. {
  2707. lock (lockObj)
  2708. {
  2709. if (!ProgressState)
  2710. {
  2711. ProgressState = true;
  2712. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2713. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2714. }
  2715. }
  2716. }
  2717. }
  2718. catch (Exception ex)
  2719. {
  2720. ProgressState = false;
  2721. string str = ex.StackTrace;
  2722. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2723. }
  2724. #endregion 出站
  2725. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2726. stopwatch1.Stop();
  2727. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2728. }
  2729. else
  2730. {
  2731. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2732. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2733. FunsEip[plcNo].Connect(); // 重连
  2734. }
  2735. }
  2736. catch (Exception ex)
  2737. {
  2738. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2739. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2740. }
  2741. Thread.Sleep(IntervalReadPLC);
  2742. }
  2743. }
  2744. /// <summary>
  2745. /// [S5] 点胶检测设备 - 进站
  2746. /// </summary>
  2747. /// <param name="plcNo">PLC编号</param>
  2748. /// <param name="stationNameStr">工站全称</param>
  2749. /// <param name="stPLC_MesData"></param>
  2750. /// <param name="tagMesCommName"></param>
  2751. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2752. {
  2753. Stopwatch stopwatch1 = new Stopwatch();
  2754. Stopwatch stopwatch2 = new Stopwatch();
  2755. try
  2756. {
  2757. stopwatch1.Start();
  2758. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2759. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2760. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2761. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  2762. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  2763. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码
  2764. string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
  2765. //绑定载具和产品
  2766. ResponseMessage message = new ResponseMessage();
  2767. message = SQLHelper.PCBCarrierBind(strCarrierBarcode, pcbBarcode);
  2768. if (message.result == false)
  2769. {
  2770. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  2771. }
  2772. //载具码验证产品码 //载具码验证产品码
  2773. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2774. if (string.IsNullOrEmpty(strProductBarcode))
  2775. {
  2776. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2777. }
  2778. sn = strProductBarcode;
  2779. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn};PCB码:{pcbBarcode}");
  2780. // 产品SN(物料码)校验
  2781. List<TestItem> item = new List<TestItem>();
  2782. stopwatch2.Start();
  2783. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2784. stopwatch2.Stop();
  2785. //指令执行结果 1:OK 110:失败
  2786. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2787. //进站结果写入PLC
  2788. CommandFromPLC resultToPlC = new CommandFromPLC();
  2789. resultToPlC.cmd = 0;
  2790. resultToPlC.cmdParam = 0; //指令参数
  2791. resultToPlC.cmdResult = mesResultFrmWeb;
  2792. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2793. }
  2794. catch (Exception ex)
  2795. {
  2796. string str = ex.StackTrace;
  2797. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2798. CommandFromPLC resultToPlC = new CommandFromPLC();
  2799. resultToPlC.cmd = 0;
  2800. resultToPlC.cmdParam = 0; //指令参数
  2801. resultToPlC.cmdResult = 110;
  2802. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2803. }
  2804. stopwatch1.Stop();
  2805. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2806. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2807. ProgressState = false;
  2808. }
  2809. /// <summary>
  2810. /// [S5] 点胶检测设备 - 出站接口
  2811. /// </summary>
  2812. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2813. {
  2814. Stopwatch stopwatch1 = new Stopwatch();
  2815. Stopwatch stopwatch2 = new Stopwatch();
  2816. try
  2817. {
  2818. stopwatch1.Start();
  2819. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2820. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2821. string processItem = stationName; // 测试项目
  2822. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2823. string supplierCode = ""; // 供应商代码
  2824. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2825. string batch_num = GlobalContext.BatchNumber; // 批次号
  2826. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2827. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2828. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
  2829. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2830. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  2831. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  2832. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2833. bool pass = a1Result == 1;
  2834. //根据载具码获取产品码
  2835. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2836. if (string.IsNullOrEmpty(strProductBarcode))
  2837. {
  2838. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2839. }
  2840. sn = strProductBarcode;
  2841. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2842. List<TestItem> items = new List<TestItem>();
  2843. items.Add(new TestItem()
  2844. {
  2845. Parameter_name = "载具码",
  2846. Parameter_value = CarrierBarcode,
  2847. Parameter_unit = ""
  2848. });
  2849. items.Add(new TestItem()
  2850. {
  2851. Parameter_name = "产品码",
  2852. Parameter_value = sn,
  2853. Parameter_unit = ""
  2854. });
  2855. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2856. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  2857. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2858. stopwatch2.Start();
  2859. //进站结果写入PLC
  2860. CommandFromPLC resultToPlC = new CommandFromPLC();
  2861. resultToPlC.cmd = 0;
  2862. resultToPlC.cmdParam = 0; //指令参数
  2863. resultToPlC.cmdResult = mesResultFrmWeb;
  2864. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2865. stopwatch2.Stop();
  2866. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2867. //保存PLC返回MES数据到本地
  2868. ResponseMessage message = new ResponseMessage();
  2869. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  2870. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB, stPLC_MesData.mesData.nRemainCount, "");
  2871. if (message.result == false)
  2872. {
  2873. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2874. }
  2875. //保存部件码信息
  2876. if (!string.IsNullOrEmpty(PartBarcode))
  2877. {
  2878. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  2879. if (message.result == false)
  2880. {
  2881. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  2882. }
  2883. }
  2884. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2885. }
  2886. catch (Exception ex)
  2887. {
  2888. stopwatch2.Start();
  2889. CommandFromPLC resultToPlC = new CommandFromPLC();
  2890. resultToPlC.cmd = 0;
  2891. resultToPlC.cmdParam = 0; //指令参数
  2892. resultToPlC.cmdResult = 110;
  2893. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2894. stopwatch2.Stop();
  2895. string str = ex.StackTrace;
  2896. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2897. }
  2898. stopwatch1.Stop();
  2899. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2900. ProgressState = false;
  2901. }
  2902. #endregion
  2903. #region S6
  2904. /// <summary>
  2905. /// [S6] 顶盖装配设备
  2906. /// </summary>
  2907. /// <param name="plcNo">PLC编号</param>
  2908. private void ReadStation_S6(int plcNo)
  2909. {
  2910. string stationCode = "[OP60]";
  2911. string stationName = "组上盖板";
  2912. string stationNameStr = stationCode + stationName;
  2913. string tagBaseName = "g_OP60_MES"; //标签变量名称
  2914. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2915. string tagAgvCommName = "agvCommFrmPC";
  2916. string tagBarsetName = "BarcodeSet";
  2917. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  2918. (int, string) result;
  2919. while (true)
  2920. {
  2921. try
  2922. {
  2923. if (!GlobalContext._IsCon_Funs1)
  2924. {
  2925. UpdatePLCMonitor(1, plcNo, 0);
  2926. continue;
  2927. }
  2928. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2929. {
  2930. Stopwatch stopwatch1 = new Stopwatch();
  2931. Stopwatch stopwatch2 = new Stopwatch();
  2932. stopwatch1.Start();
  2933. stopwatch2.Start();
  2934. #region 一次性读取所有数据
  2935. // 一次性读取所有数据
  2936. result = FunsEip[plcNo].Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2937. if (result.Item1 != 0)
  2938. {
  2939. //richTextBox1.AppendText("\n" + strRet);
  2940. }
  2941. else
  2942. {
  2943. //richTextBox1.AppendText("\n" + "读取成功");
  2944. }
  2945. #endregion 一次性读取所有数据
  2946. stopwatch2.Stop();
  2947. #region 进站
  2948. try
  2949. {
  2950. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2951. {
  2952. lock (lockObj)
  2953. {
  2954. if (!ProgressState)
  2955. {
  2956. ProgressState = true;
  2957. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2958. }
  2959. }
  2960. }
  2961. }
  2962. catch (Exception ex)
  2963. {
  2964. ProgressState = false;
  2965. string str = ex.StackTrace;
  2966. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2967. }
  2968. #endregion 进站
  2969. #region 出站
  2970. try
  2971. {
  2972. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2973. {
  2974. lock (lockObj)
  2975. {
  2976. if (!ProgressState)
  2977. {
  2978. ProgressState = true; ;
  2979. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2980. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2981. }
  2982. }
  2983. }
  2984. }
  2985. catch (Exception ex)
  2986. {
  2987. ProgressState = false;
  2988. string str = ex.StackTrace;
  2989. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2990. }
  2991. #endregion 出站
  2992. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2993. stopwatch1.Stop();
  2994. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2995. }
  2996. else
  2997. {
  2998. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2999. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3000. FunsEip[plcNo].Connect(); // 重连
  3001. }
  3002. }
  3003. catch (Exception ex)
  3004. {
  3005. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3006. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3007. }
  3008. Thread.Sleep(IntervalReadPLC);
  3009. }
  3010. }
  3011. /// <summary>
  3012. /// [S6] 顶盖装配设备 - 进站
  3013. /// </summary>
  3014. /// <param name="plcNo">PLC编号</param>
  3015. /// <param name="stationNameStr">工站全称</param>
  3016. /// <param name="stPLC_MesData"></param>
  3017. /// <param name="tagMesCommName"></param>
  3018. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3019. {
  3020. Stopwatch stopwatch1 = new Stopwatch();
  3021. Stopwatch stopwatch2 = new Stopwatch();
  3022. try
  3023. {
  3024. stopwatch1.Start();
  3025. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3026. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3027. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  3028. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  3029. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3030. strCarrierBarcode = "N801A-003";
  3031. //载具码验证产品码
  3032. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3033. if (string.IsNullOrEmpty(strProductBarcode))
  3034. {
  3035. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3036. }
  3037. sn = strProductBarcode;
  3038. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3039. if (OpenDailogFalg)
  3040. {
  3041. using (var dialog = new BandBarodeDialog())
  3042. {
  3043. dialog._CarrierBarcode = strCarrierBarcode;
  3044. dialog._ProductBarcode = sn;
  3045. var rs = dialog.ShowDialog();
  3046. if (rs == DialogResult.OK)
  3047. {
  3048. AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  3049. OpenDailogFalg = false;//关闭扫码
  3050. }
  3051. else {
  3052. ProgressState = false;
  3053. return;
  3054. }
  3055. }
  3056. }
  3057. // 产品SN(物料码)校验
  3058. List<TestItem> item = new List<TestItem>();
  3059. stopwatch2.Start();
  3060. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3061. stopwatch2.Stop();
  3062. //指令执行结果 1:OK 110:失败
  3063. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3064. //进站结果写入PLC
  3065. CommandFromPLC resultToPlC = new CommandFromPLC();
  3066. resultToPlC.cmd = 0;
  3067. resultToPlC.cmdParam = 0; //指令参数
  3068. resultToPlC.cmdResult = mesResultFrmWeb;
  3069. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3070. }
  3071. catch (Exception ex)
  3072. {
  3073. string str = ex.StackTrace;
  3074. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3075. CommandFromPLC resultToPlC = new CommandFromPLC();
  3076. resultToPlC.cmd = 0;
  3077. resultToPlC.cmdParam = 0; //指令参数
  3078. resultToPlC.cmdResult = 110;
  3079. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3080. }
  3081. stopwatch1.Stop();
  3082. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3083. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3084. ProgressState = false;
  3085. OpenDailogFalg = true; //开启下一个物料的扫码
  3086. }
  3087. /// <summary>
  3088. /// [S6] 顶盖装配设备 - 出站接口
  3089. /// </summary>
  3090. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3091. {
  3092. Stopwatch stopwatch1 = new Stopwatch();
  3093. Stopwatch stopwatch2 = new Stopwatch();
  3094. try
  3095. {
  3096. stopwatch1.Start();
  3097. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3098. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3099. string processItem = stationName; // 测试项目
  3100. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3101. string supplierCode = ""; // 供应商代码
  3102. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3103. string batch_num = GlobalContext.BatchNumber; // 批次号
  3104. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3105. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3106. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3107. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  3108. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  3109. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3110. bool pass = a1Result == 1;
  3111. //根据载具码获取产品码
  3112. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3113. if (string.IsNullOrEmpty(strProductBarcode))
  3114. {
  3115. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3116. }
  3117. sn = strProductBarcode;
  3118. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3119. List<TestItem> items = new List<TestItem>();
  3120. items.Add(new TestItem()
  3121. {
  3122. Parameter_name = "载具码",
  3123. Parameter_value = CarrierBarcode,
  3124. Parameter_unit = ""
  3125. });
  3126. items.Add(new TestItem()
  3127. {
  3128. Parameter_name = "产品码",
  3129. Parameter_value = sn,
  3130. Parameter_unit = ""
  3131. });
  3132. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3133. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3134. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3135. stopwatch2.Start();
  3136. //进站结果写入PLC
  3137. CommandFromPLC resultToPlC = new CommandFromPLC();
  3138. resultToPlC.cmd = 0;
  3139. resultToPlC.cmdParam = 0; //指令参数
  3140. resultToPlC.cmdResult = mesResultFrmWeb;
  3141. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3142. stopwatch2.Stop();
  3143. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3144. //保存PLC返回MES数据到本地
  3145. ResponseMessage message = new ResponseMessage();
  3146. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  3147. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  3148. if (message.result == false)
  3149. {
  3150. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3151. }
  3152. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3153. }
  3154. catch (Exception ex)
  3155. {
  3156. stopwatch2.Start();
  3157. CommandFromPLC resultToPlC = new CommandFromPLC();
  3158. resultToPlC.cmd = 0;
  3159. resultToPlC.cmdParam = 0; //指令参数
  3160. resultToPlC.cmdResult = 110;
  3161. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3162. stopwatch2.Stop();
  3163. string str = ex.StackTrace;
  3164. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3165. }
  3166. stopwatch1.Stop();
  3167. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3168. ProgressState = false;
  3169. }
  3170. #endregion
  3171. #region S7
  3172. /// <summary>
  3173. /// [S7] 锁螺丝设备
  3174. /// </summary>
  3175. /// <param name="plcNo">PLC编号</param>
  3176. private void ReadStation_S7(int plcNo)
  3177. {
  3178. string stationCode = "[OP70]";
  3179. string stationName = "上盖板锁螺丝";
  3180. string stationNameStr = stationCode + stationName;
  3181. string tagBaseName = "g_OP70_MES"; //标签变量名称
  3182. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3183. string tagAgvCommName = "agvCommFrmPC";
  3184. string tagBarsetName = "BarcodeSet";
  3185. string tagScrewDataset = "screwDataset";
  3186. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  3187. (int, string) result;
  3188. AtlasScrew atlasScrewLeft= new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort, 3000, 3000,"Left");
  3189. atlasScrewLeft.Initial();
  3190. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort, 3000, 3000,"Right");
  3191. atlasScrewRight.Initial();
  3192. while (true)
  3193. {
  3194. try
  3195. {
  3196. if (!GlobalContext._IsCon_Funs1)
  3197. {
  3198. UpdatePLCMonitor(1, plcNo, 0);
  3199. continue;
  3200. }
  3201. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3202. {
  3203. Stopwatch stopwatch1 = new Stopwatch();
  3204. Stopwatch stopwatch2 = new Stopwatch();
  3205. stopwatch1.Start();
  3206. stopwatch2.Start();
  3207. #region 一次性读取所有数据
  3208. // 一次性读取所有数据
  3209. result = FunsEip[plcNo].Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3210. if (result.Item1 != 0)
  3211. {
  3212. //richTextBox1.AppendText("\n" + strRet);
  3213. }
  3214. else
  3215. {
  3216. //richTextBox1.AppendText("\n" + "读取成功");
  3217. }
  3218. #endregion 一次性读取所有数据
  3219. stopwatch2.Stop();
  3220. #region 左边进站
  3221. try
  3222. {
  3223. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3224. {
  3225. lock (lockObj)
  3226. {
  3227. if (!ProgressState)
  3228. {
  3229. ProgressState = true;
  3230. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName,"Left", out ProgressState, atlasScrewLeft));
  3231. }
  3232. }
  3233. }
  3234. }
  3235. catch (Exception ex)
  3236. {
  3237. ProgressState = false;
  3238. string str = ex.StackTrace;
  3239. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3240. }
  3241. #endregion 左边进站
  3242. #region 左边出站
  3243. try
  3244. {
  3245. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3246. {
  3247. lock (lockObj)
  3248. {
  3249. if (!ProgressState)
  3250. {
  3251. ProgressState = true;
  3252. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  3253. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  3254. }
  3255. }
  3256. }
  3257. }
  3258. catch (Exception ex)
  3259. {
  3260. ProgressState = false;
  3261. string str = ex.StackTrace;
  3262. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3263. }
  3264. #endregion 左边出站
  3265. #region 右边进站
  3266. try
  3267. {
  3268. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3269. {
  3270. lock (lockObj)
  3271. {
  3272. if (!ProgressState)
  3273. {
  3274. ProgressState = true;
  3275. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right" + tagBarsetName,"Right", out ProgressState, atlasScrewRight));
  3276. }
  3277. }
  3278. }
  3279. }
  3280. catch (Exception ex)
  3281. {
  3282. ProgressState = false;
  3283. string str = ex.StackTrace;
  3284. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3285. }
  3286. #endregion 右边进站
  3287. #region 右边出站
  3288. try
  3289. {
  3290. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3291. {
  3292. lock (lockObj)
  3293. {
  3294. if (!ProgressState)
  3295. {
  3296. ProgressState = true;
  3297. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  3298. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  3299. }
  3300. }
  3301. }
  3302. }
  3303. catch (Exception ex)
  3304. {
  3305. ProgressState = false;
  3306. string str = ex.StackTrace;
  3307. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3308. }
  3309. #endregion 右边出站
  3310. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3311. stopwatch1.Stop();
  3312. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3313. }
  3314. else
  3315. {
  3316. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3317. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3318. FunsEip[plcNo].Connect(); // 重连
  3319. }
  3320. }
  3321. catch (Exception ex)
  3322. {
  3323. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3324. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3325. }
  3326. Thread.Sleep(IntervalReadPLC);
  3327. }
  3328. }
  3329. /// <summary>
  3330. /// [S7] 锁螺丝设备 - 进站
  3331. /// </summary>
  3332. /// <param name="plcNo">PLC编号</param>
  3333. /// <param name="stationNameStr">工站全称</param>
  3334. /// <param name="stPLC_MesData"></param>
  3335. /// <param name="tagMesCommName"></param>
  3336. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName, string direction,out bool ProgressState, AtlasScrew atlasScrew)
  3337. {
  3338. Stopwatch stopwatch1 = new Stopwatch();
  3339. Stopwatch stopwatch2 = new Stopwatch();
  3340. string atlasSn=string.Empty;
  3341. try
  3342. {
  3343. stopwatch1.Start();
  3344. AddMessage(LogType.Info, stationNameStr +"_"+ direction+"_进站开始");
  3345. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3346. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  3347. string StationId = string.Empty; // 工位ID(可配置)
  3348. if (direction == "Left")
  3349. {
  3350. StationId = GlobalContext.S7_StationId_1;
  3351. }
  3352. if (direction == "Right")
  3353. {
  3354. StationId = GlobalContext.S7_StationId_2;
  3355. }
  3356. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3357. //载具码验证产品码
  3358. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3359. if (string.IsNullOrEmpty(strProductBarcode))
  3360. {
  3361. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3362. }
  3363. sn = strProductBarcode;
  3364. atlasSn= strProductBarcode;
  3365. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3366. if (direction == "Left")
  3367. {
  3368. isCollectingFlagLeft = false;//采集螺丝数据结束
  3369. }
  3370. if (direction == "Right")
  3371. {
  3372. isCollectingFlagRight = false;//采集螺丝数据结束
  3373. }
  3374. // 产品SN(物料码)校验
  3375. List<TestItem> item = new List<TestItem>();
  3376. stopwatch2.Start();
  3377. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3378. stopwatch2.Stop();
  3379. //指令执行结果 1:OK 110:失败
  3380. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3381. //进站结果写入PLC
  3382. CommandFromPLC resultToPlC = new CommandFromPLC();
  3383. resultToPlC.cmd = 0;
  3384. resultToPlC.cmdParam = 0; //指令参数
  3385. resultToPlC.cmdResult = mesResultFrmWeb;
  3386. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3387. }
  3388. catch (Exception ex)
  3389. {
  3390. string str = ex.StackTrace;
  3391. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3392. CommandFromPLC resultToPlC = new CommandFromPLC();
  3393. resultToPlC.cmd = 0;
  3394. resultToPlC.cmdParam = 0; //指令参数
  3395. resultToPlC.cmdResult = 110;
  3396. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3397. }
  3398. stopwatch1.Stop();
  3399. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3400. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3401. ProgressState = false;
  3402. //开始采集螺丝数据
  3403. if (direction == "Left")
  3404. {
  3405. isCollectingFlagLeft = true;
  3406. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  3407. }
  3408. if (direction == "Right")
  3409. {
  3410. isCollectingFlagRight = true;
  3411. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  3412. }
  3413. }
  3414. /// <summary>
  3415. /// [S7] 锁螺丝设备 - 出站
  3416. /// </summary>
  3417. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  3418. {
  3419. Stopwatch stopwatch1 = new Stopwatch();
  3420. Stopwatch stopwatch2 = new Stopwatch();
  3421. try
  3422. {
  3423. stopwatch1.Start();
  3424. AddMessage(LogType.Info, stationNameStr +"_"+ direction+ "_出站开始");
  3425. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3426. string processItem = stationName; // 测试项目
  3427. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3428. string supplierCode = ""; // 供应商代码
  3429. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3430. string batch_num = GlobalContext.BatchNumber; // 批次号
  3431. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3432. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3433. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3434. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  3435. string StationId = string.Empty; // 工位ID(可配置)
  3436. if (direction == "Left")
  3437. {
  3438. StationId = GlobalContext.S7_StationId_1;
  3439. }
  3440. if (direction == "Right")
  3441. {
  3442. StationId = GlobalContext.S7_StationId_2;
  3443. }
  3444. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3445. a1Result = 1;
  3446. bool pass = a1Result == 1;
  3447. //根据载具码获取产品码
  3448. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3449. if (string.IsNullOrEmpty(strProductBarcode))
  3450. {
  3451. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3452. }
  3453. sn = strProductBarcode;
  3454. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3455. List<TestItem> items = new List<TestItem>();
  3456. items.Add(new TestItem()
  3457. {
  3458. Parameter_name = "载具码",
  3459. Parameter_value = CarrierBarcode,
  3460. Parameter_unit = ""
  3461. });
  3462. items.Add(new TestItem()
  3463. {
  3464. Parameter_name = "产品码",
  3465. Parameter_value = sn,
  3466. Parameter_unit = ""
  3467. });
  3468. int result1 = 1;
  3469. if (direction == "Right")
  3470. {
  3471. SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3472. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3473. }
  3474. //if (direction == "Left")
  3475. //{
  3476. // isCollectingFlagLeft = false;//采集螺丝数据结束
  3477. //}
  3478. //if (direction == "Right")
  3479. //{
  3480. // isCollectingFlagRight = false;//采集螺丝数据结束
  3481. //}
  3482. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3483. stopwatch2.Start();
  3484. //进站结果写入PLC
  3485. CommandFromPLC resultToPlC = new CommandFromPLC();
  3486. resultToPlC.cmd = 0;
  3487. resultToPlC.cmdParam = 0; //指令参数
  3488. resultToPlC.cmdResult = mesResultFrmWeb;
  3489. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3490. stopwatch2.Stop();
  3491. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  3492. //保存PLC返回MES数据到本地
  3493. ResponseMessage message = new ResponseMessage();
  3494. if (direction == "Left")
  3495. {
  3496. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3497. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3498. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3499. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  3500. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3501. if (message.result == false)
  3502. {
  3503. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  3504. }
  3505. }
  3506. if (direction == "Right")
  3507. {
  3508. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3509. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3510. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3511. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  3512. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3513. if (message.result == false)
  3514. {
  3515. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  3516. }
  3517. }
  3518. //保存螺丝数据到txt
  3519. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes, stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  3520. if (result.Item1 != 0)
  3521. {
  3522. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  3523. }
  3524. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_保存加工数据到本地成功");
  3525. }
  3526. catch (Exception ex)
  3527. {
  3528. stopwatch2.Start();
  3529. CommandFromPLC resultToPlC = new CommandFromPLC();
  3530. resultToPlC.cmd = 0;
  3531. resultToPlC.cmdParam = 0; //指令参数
  3532. resultToPlC.cmdResult = 110;
  3533. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3534. stopwatch2.Stop();
  3535. string str = ex.StackTrace;
  3536. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3537. }
  3538. stopwatch1.Stop();
  3539. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3540. ProgressState = false;
  3541. }
  3542. #endregion
  3543. #region S8
  3544. /// <summary>
  3545. /// [S8] 3D螺丝高度检测设备
  3546. /// </summary>
  3547. /// <param name="plcNo">PLC编号</param>
  3548. private void ReadStation_S8(int plcNo)
  3549. {
  3550. string stationCode = "[OP80]";
  3551. string stationName = "NG下料";
  3552. string stationNameStr = stationCode + stationName;
  3553. string tagBaseName = "g_OP80_MES"; //标签变量名称
  3554. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3555. string tagAgvCommName = "agvCommFrmPC";
  3556. string tagBarsetName = "BarcodeSet";
  3557. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  3558. (int, string) result;
  3559. while (true)
  3560. {
  3561. try
  3562. {
  3563. if (!GlobalContext._IsCon_Funs1)
  3564. {
  3565. UpdatePLCMonitor(1, plcNo, 0);
  3566. continue;
  3567. }
  3568. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3569. {
  3570. Stopwatch stopwatch1 = new Stopwatch();
  3571. Stopwatch stopwatch2 = new Stopwatch();
  3572. stopwatch1.Start();
  3573. stopwatch2.Start();
  3574. #region 一次性读取所有数据
  3575. // 一次性读取所有数据
  3576. result = FunsEip[plcNo].Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3577. if (result.Item1 != 0)
  3578. {
  3579. //richTextBox1.AppendText("\n" + strRet);
  3580. }
  3581. else
  3582. {
  3583. //richTextBox1.AppendText("\n" + "读取成功");
  3584. }
  3585. #endregion 一次性读取所有数据
  3586. stopwatch2.Stop();
  3587. #region 进站
  3588. try
  3589. {
  3590. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3591. {
  3592. lock (lockObj)
  3593. {
  3594. if (!ProgressState)
  3595. {
  3596. ProgressState = true;
  3597. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3598. }
  3599. }
  3600. }
  3601. }
  3602. catch (Exception ex)
  3603. {
  3604. ProgressState = false;
  3605. string str = ex.StackTrace;
  3606. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3607. }
  3608. #endregion 进站
  3609. #region 出站
  3610. try
  3611. {
  3612. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3613. {
  3614. lock (lockObj)
  3615. {
  3616. if (!ProgressState)
  3617. {
  3618. ProgressState = true;
  3619. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3620. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3621. }
  3622. }
  3623. }
  3624. }
  3625. catch (Exception ex)
  3626. {
  3627. ProgressState = false;
  3628. string str = ex.StackTrace;
  3629. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3630. }
  3631. #endregion 出站
  3632. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3633. stopwatch1.Stop();
  3634. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3635. }
  3636. else
  3637. {
  3638. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3639. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3640. FunsEip[plcNo].Connect(); // 重连
  3641. }
  3642. }
  3643. catch (Exception ex)
  3644. {
  3645. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3646. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3647. }
  3648. Thread.Sleep(IntervalReadPLC);
  3649. }
  3650. }
  3651. /// <summary>
  3652. /// [S8] 3D螺丝高度检测设备 - 进站
  3653. /// </summary>
  3654. /// <param name="plcNo">PLC编号</param>
  3655. /// <param name="stationNameStr">工站全称</param>
  3656. /// <param name="stPLC_MesData"></param>
  3657. /// <param name="tagMesCommName"></param>
  3658. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3659. {
  3660. Stopwatch stopwatch1 = new Stopwatch();
  3661. Stopwatch stopwatch2 = new Stopwatch();
  3662. try
  3663. {
  3664. stopwatch1.Start();
  3665. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3666. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3667. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  3668. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  3669. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3670. //载具码验证产品码
  3671. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3672. if (string.IsNullOrEmpty(strProductBarcode))
  3673. {
  3674. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3675. }
  3676. sn = strProductBarcode;
  3677. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3678. // 产品SN(物料码)校验
  3679. List<TestItem> item = new List<TestItem>();
  3680. stopwatch2.Start();
  3681. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3682. stopwatch2.Stop();
  3683. //指令执行结果 1:OK 110:失败
  3684. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3685. //进站结果写入PLC
  3686. CommandFromPLC resultToPlC = new CommandFromPLC();
  3687. resultToPlC.cmd = 0;
  3688. resultToPlC.cmdParam = 0; //指令参数
  3689. resultToPlC.cmdResult = mesResultFrmWeb;
  3690. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3691. }
  3692. catch (Exception ex)
  3693. {
  3694. string str = ex.StackTrace;
  3695. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3696. CommandFromPLC resultToPlC = new CommandFromPLC();
  3697. resultToPlC.cmd = 0;
  3698. resultToPlC.cmdParam = 0; //指令参数
  3699. resultToPlC.cmdResult = 110;
  3700. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3701. }
  3702. stopwatch1.Stop();
  3703. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3704. ProgressState = false;
  3705. }
  3706. /// <summary>
  3707. /// [S8] 3D螺丝高度检测设备 - 出站接口
  3708. /// </summary>
  3709. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3710. {
  3711. Stopwatch stopwatch1 = new Stopwatch();
  3712. Stopwatch stopwatch2 = new Stopwatch();
  3713. try
  3714. {
  3715. stopwatch1.Start();
  3716. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3717. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3718. string processItem = stationName; // 测试项目
  3719. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3720. string supplierCode = ""; // 供应商代码
  3721. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3722. string batch_num = GlobalContext.BatchNumber; // 批次号
  3723. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3724. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3725. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3726. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  3727. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  3728. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3729. bool pass = a1Result == 1;
  3730. //根据载具码获取产品码
  3731. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3732. if (string.IsNullOrEmpty(strProductBarcode))
  3733. {
  3734. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3735. }
  3736. sn = strProductBarcode;
  3737. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3738. List<TestItem> items = new List<TestItem>();
  3739. items.Add(new TestItem()
  3740. {
  3741. Parameter_name = "载具码",
  3742. Parameter_value = CarrierBarcode,
  3743. Parameter_unit = ""
  3744. });
  3745. items.Add(new TestItem()
  3746. {
  3747. Parameter_name = "产品码",
  3748. Parameter_value = sn,
  3749. Parameter_unit = ""
  3750. });
  3751. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3752. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3753. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3754. stopwatch2.Start();
  3755. //进站结果写入PLC
  3756. CommandFromPLC resultToPlC = new CommandFromPLC();
  3757. resultToPlC.cmd = 0;
  3758. resultToPlC.cmdParam = 0; //指令参数
  3759. resultToPlC.cmdResult = mesResultFrmWeb;
  3760. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3761. stopwatch2.Stop();
  3762. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3763. //保存PLC返回MES数据到本地
  3764. ResponseMessage message = new ResponseMessage();
  3765. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  3766. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3767. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  3768. if (message.result == false)
  3769. {
  3770. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3771. }
  3772. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3773. }
  3774. catch (Exception ex)
  3775. {
  3776. stopwatch2.Start();
  3777. CommandFromPLC resultToPlC = new CommandFromPLC();
  3778. resultToPlC.cmd = 0;
  3779. resultToPlC.cmdParam = 0; //指令参数
  3780. resultToPlC.cmdResult = 110;
  3781. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3782. stopwatch2.Stop();
  3783. string str = ex.StackTrace;
  3784. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3785. }
  3786. stopwatch1.Stop();
  3787. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3788. ProgressState = false;
  3789. }
  3790. #endregion
  3791. #region S9
  3792. /// <summary>
  3793. /// [S9] 下料设备
  3794. /// </summary>
  3795. /// <param name="plcNo">PLC编号</param>
  3796. private void ReadStation_S9(int plcNo)
  3797. {
  3798. string stationCode = "[OP90]";
  3799. string stationName = "半成品下料";
  3800. string stationNameStr = stationCode + stationName;
  3801. string tagBaseName = "g_OP90_MES"; //标签变量名称
  3802. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3803. string tagAgvCommName = "agvCommFrmPC";
  3804. string tagBarsetName = "BarcodeSet";
  3805. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  3806. (int, string) result;
  3807. while (true)
  3808. {
  3809. try
  3810. {
  3811. if (!GlobalContext._IsCon_Funs1)
  3812. {
  3813. UpdatePLCMonitor(1, plcNo, 0);
  3814. continue;
  3815. }
  3816. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3817. {
  3818. Stopwatch stopwatch1 = new Stopwatch();
  3819. Stopwatch stopwatch2 = new Stopwatch();
  3820. stopwatch1.Start();
  3821. stopwatch2.Start();
  3822. #region 一次性读取所有数据
  3823. // 一次性读取所有数据
  3824. result = FunsEip[plcNo].Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3825. if (result.Item1 != 0)
  3826. {
  3827. //richTextBox1.AppendText("\n" + strRet);
  3828. }
  3829. else
  3830. {
  3831. //richTextBox1.AppendText("\n" + "读取成功");
  3832. }
  3833. #endregion 一次性读取所有数据
  3834. stopwatch2.Stop();
  3835. #region 进站
  3836. try
  3837. {
  3838. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3839. {
  3840. lock (lockObj)
  3841. {
  3842. if (!ProgressState)
  3843. {
  3844. ProgressState = true;
  3845. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3846. }
  3847. }
  3848. }
  3849. }
  3850. catch (Exception ex)
  3851. {
  3852. ProgressState = false;
  3853. string str = ex.StackTrace;
  3854. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3855. }
  3856. #endregion 进站
  3857. #region 出站
  3858. try
  3859. {
  3860. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3861. {
  3862. lock (lockObj)
  3863. {
  3864. if (!ProgressState)
  3865. {
  3866. ProgressState = true;
  3867. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3868. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3869. }
  3870. }
  3871. }
  3872. }
  3873. catch (Exception ex)
  3874. {
  3875. ProgressState = false;
  3876. string str = ex.StackTrace;
  3877. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3878. }
  3879. #endregion 出站
  3880. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3881. stopwatch1.Stop();
  3882. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3883. }
  3884. else
  3885. {
  3886. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3887. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3888. FunsEip[plcNo].Connect(); // 重连
  3889. }
  3890. }
  3891. catch (Exception ex)
  3892. {
  3893. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3894. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3895. }
  3896. Thread.Sleep(IntervalReadPLC);
  3897. }
  3898. }
  3899. /// <summary>
  3900. /// [S9] 下料设备 - 进站
  3901. /// </summary>
  3902. /// <param name="plcNo">PLC编号</param>
  3903. /// <param name="stationNameStr">工站全称</param>
  3904. /// <param name="stPLC_MesData"></param>
  3905. /// <param name="tagMesCommName"></param>
  3906. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3907. {
  3908. Stopwatch stopwatch1 = new Stopwatch();
  3909. Stopwatch stopwatch2 = new Stopwatch();
  3910. try
  3911. {
  3912. stopwatch1.Start();
  3913. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3914. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3915. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  3916. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  3917. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3918. //载具码验证产品码
  3919. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3920. if (string.IsNullOrEmpty(strProductBarcode))
  3921. {
  3922. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3923. }
  3924. sn = strProductBarcode;
  3925. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3926. // 产品SN(物料码)校验
  3927. List<TestItem> item = new List<TestItem>();
  3928. stopwatch2.Start();
  3929. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3930. stopwatch2.Stop();
  3931. //指令执行结果 1:OK 110:失败
  3932. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3933. //进站结果写入PLC
  3934. CommandFromPLC resultToPlC = new CommandFromPLC();
  3935. resultToPlC.cmd = 0;
  3936. resultToPlC.cmdParam = 0; //指令参数
  3937. resultToPlC.cmdResult = mesResultFrmWeb;
  3938. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3939. }
  3940. catch (Exception ex)
  3941. {
  3942. string str = ex.StackTrace;
  3943. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3944. CommandFromPLC resultToPlC = new CommandFromPLC();
  3945. resultToPlC.cmd = 0;
  3946. resultToPlC.cmdParam = 0; //指令参数
  3947. resultToPlC.cmdResult = 110;
  3948. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3949. }
  3950. stopwatch1.Stop();
  3951. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3952. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3953. ProgressState = false;
  3954. }
  3955. /// <summary>
  3956. /// [S9] 下料设备 - 出站接口
  3957. /// </summary>
  3958. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3959. {
  3960. Stopwatch stopwatch1 = new Stopwatch();
  3961. Stopwatch stopwatch2 = new Stopwatch();
  3962. try
  3963. {
  3964. stopwatch1.Start();
  3965. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3966. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3967. string processItem = stationName; // 测试项目
  3968. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3969. string supplierCode = ""; // 供应商代码
  3970. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3971. string batch_num = GlobalContext.BatchNumber; // 批次号
  3972. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3973. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3974. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3975. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  3976. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  3977. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3978. bool pass = a1Result == 1;
  3979. //根据载具码获取产品码
  3980. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3981. if (string.IsNullOrEmpty(strProductBarcode))
  3982. {
  3983. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3984. }
  3985. sn = strProductBarcode;
  3986. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3987. List<TestItem> items = new List<TestItem>();
  3988. items.Add(new TestItem()
  3989. {
  3990. Parameter_name = "载具码",
  3991. Parameter_value = CarrierBarcode,
  3992. Parameter_unit = ""
  3993. });
  3994. items.Add(new TestItem()
  3995. {
  3996. Parameter_name = "产品码",
  3997. Parameter_value = sn,
  3998. Parameter_unit = ""
  3999. });
  4000. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4001. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  4002. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4003. stopwatch2.Start();
  4004. //进站结果写入PLC
  4005. CommandFromPLC resultToPlC = new CommandFromPLC();
  4006. resultToPlC.cmd = 0;
  4007. resultToPlC.cmdParam = 0; //指令参数
  4008. resultToPlC.cmdResult = mesResultFrmWeb;
  4009. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4010. stopwatch2.Stop();
  4011. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4012. //保存PLC返回MES数据到本地
  4013. ResponseMessage message = new ResponseMessage();
  4014. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  4015. if (message.result == false)
  4016. {
  4017. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4018. }
  4019. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4020. if (result1 == 1)
  4021. {
  4022. //载具码解除绑定
  4023. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  4024. if (message.result == false)
  4025. {
  4026. AddMessage(LogType.Error, message.text);
  4027. }
  4028. }
  4029. }
  4030. catch (Exception ex)
  4031. {
  4032. stopwatch2.Start();
  4033. CommandFromPLC resultToPlC = new CommandFromPLC();
  4034. resultToPlC.cmd = 0;
  4035. resultToPlC.cmdParam = 0; //指令参数
  4036. resultToPlC.cmdResult = 110;
  4037. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4038. stopwatch2.Stop();
  4039. string str = ex.StackTrace;
  4040. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4041. }
  4042. stopwatch1.Stop();
  4043. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4044. ProgressState = false;
  4045. }
  4046. #endregion
  4047. #endregion Xiaomi
  4048. #region PLC1 张超凡
  4049. #region [S1] Tray盘上料装备(板测)
  4050. /// <summary>
  4051. /// S1工位的数据- 触发信号上次的值
  4052. /// </summary>
  4053. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  4054. /// <summary>
  4055. /// S1工位的数据(含触发信号)
  4056. /// </summary>
  4057. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  4058. /// <summary>
  4059. /// S1工位的数据- 回写点位
  4060. /// </summary>
  4061. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  4062. ///// <summary>
  4063. ///// 触发信号
  4064. ///// </summary>
  4065. //private ManualResetEvent[] MreTasks;
  4066. /// <summary>
  4067. /// [S1] Tray盘上料装备(板测)
  4068. /// </summary>
  4069. /// <param name="plcNo">PLC编号</param>
  4070. //private void ReadStation_S1(int plcNo)
  4071. //{
  4072. // // [S1] Tray盘上料装备
  4073. // // [S2] FCT
  4074. // // [S3] 值板机
  4075. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  4076. // // [S5] Tray盘下料装备
  4077. // string stationCode = "[S1]";
  4078. // string stationName = "Tray盘上料装备";
  4079. // string stationNameStr = stationCode + stationName;
  4080. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4081. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4082. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4083. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4084. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4085. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4086. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4087. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4088. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  4089. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4090. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  4091. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4092. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4093. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  4094. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  4095. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4096. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  4097. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  4098. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4099. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  4100. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  4101. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  4102. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  4103. // s1PLCData.Add("a1Result", 0); // 产品结果
  4104. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4105. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  4106. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  4107. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  4108. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  4109. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4110. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  4111. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4112. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  4113. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  4114. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  4115. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4116. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  4117. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  4118. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4119. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  4120. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  4121. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4122. // while (IsRun)
  4123. // {
  4124. // try
  4125. // {
  4126. // if (!GlobalContext._IsCon_Funs1)
  4127. // {
  4128. // UpdatePLCMonitor(1, plcNo, 0);
  4129. // continue;
  4130. // }
  4131. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  4132. // {
  4133. // Stopwatch stopwatch1 = new Stopwatch();
  4134. // Stopwatch stopwatch2 = new Stopwatch();
  4135. // stopwatch1.Start();
  4136. // stopwatch2.Start();
  4137. // #region 一次性读取所有数据
  4138. // // 一次性读取所有数据
  4139. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  4140. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  4141. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  4142. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  4143. // int[] datas = data1.Concat(data2).ToArray();
  4144. // datas = datas.Concat(data3).ToArray();
  4145. // datas = datas.Concat(data4).ToArray();
  4146. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  4147. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  4148. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  4149. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  4150. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  4151. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  4152. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  4153. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  4154. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  4155. // s1PLCData["a1MES_FLAG"] = datas[109];
  4156. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  4157. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  4158. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  4159. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  4160. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  4161. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  4162. // s1PLCData["a1Result"] = datas[170];
  4163. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  4164. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  4165. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  4166. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  4167. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  4168. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  4169. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  4170. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  4171. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  4172. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  4173. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  4174. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  4175. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  4176. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  4177. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  4178. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  4179. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  4180. // s1PLCData["a1AGVUpStart"] = datas[308];
  4181. // s1PLCData["a1AGVUpEnd"] = datas[309];
  4182. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  4183. // s1PLCData["a1AGVDownStart"] = datas[321];
  4184. // s1PLCData["a1AGVDownEnd"] = datas[322];
  4185. // #endregion 一次性读取所有数据
  4186. // stopwatch2.Stop();
  4187. // #region 回写操作,写后清空flag
  4188. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  4189. // #endregion 回写操作,写后清空flag
  4190. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4191. // try
  4192. // {
  4193. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  4194. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  4195. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  4196. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  4197. // {
  4198. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  4199. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  4200. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  4201. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  4202. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  4203. // }
  4204. // }
  4205. // catch (Exception ex)
  4206. // {
  4207. // // 6代表上位机报警
  4208. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  4209. // string str = ex.StackTrace;
  4210. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4211. // }
  4212. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4213. // #region 上料进站校验
  4214. // try
  4215. // {
  4216. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  4217. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  4218. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  4219. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  4220. // {
  4221. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  4222. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  4223. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  4224. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  4225. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  4226. // }
  4227. // }
  4228. // catch (Exception ex)
  4229. // {
  4230. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4231. // string str = ex.StackTrace;
  4232. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4233. // }
  4234. // #endregion 上料进站校验
  4235. // #region Tray盘上料装备-出站接口
  4236. // try
  4237. // {
  4238. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  4239. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  4240. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  4241. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  4242. // {
  4243. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  4244. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  4245. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  4246. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  4247. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  4248. // }
  4249. // }
  4250. // catch (Exception ex)
  4251. // {
  4252. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  4253. // string str = ex.StackTrace;
  4254. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4255. // }
  4256. // #endregion Tray盘上料装备-出站接口
  4257. // #region Tray盘上料装备-将SN发给ICT标机
  4258. // try
  4259. // {
  4260. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  4261. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  4262. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  4263. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  4264. // {
  4265. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  4266. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  4267. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  4268. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  4269. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  4270. // }
  4271. // }
  4272. // catch (Exception ex)
  4273. // {
  4274. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4275. // string str = ex.StackTrace;
  4276. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4277. // }
  4278. // #endregion Tray盘上料装备-将SN发给ICT标机
  4279. // #region Tray盘上料装备-点检数据
  4280. // //try
  4281. // //{
  4282. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  4283. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  4284. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  4285. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  4286. // // if (pLC_Flag && !mES_Flag) // 1 0
  4287. // // {
  4288. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  4289. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  4290. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  4291. // // }
  4292. // // else if (!pLC_Flag && mES_Flag) // 0 1
  4293. // // {
  4294. // // // 清空写给PLC的数据
  4295. // // // MES_Flag重置为0
  4296. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  4297. // // }
  4298. // //}
  4299. // //catch (Exception ex)
  4300. // //{
  4301. // // // MES_Flag 为2上位机报错
  4302. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4303. // // string str = ex.StackTrace;
  4304. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4305. // //}
  4306. // #endregion Tray盘上料装备-点检数据
  4307. // #region 节拍接口
  4308. // try
  4309. // {
  4310. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  4311. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  4312. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  4313. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  4314. // {
  4315. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  4316. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  4317. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  4318. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  4319. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  4320. // }
  4321. // }
  4322. // catch (Exception ex)
  4323. // {
  4324. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4325. // string str = ex.StackTrace;
  4326. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4327. // }
  4328. // #endregion 节拍接口
  4329. // #region AGV上料
  4330. // // AGV上料叫AGV信号
  4331. // try
  4332. // {
  4333. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  4334. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  4335. // if (a1AGVUpCall != a1AGVUpCallOld)
  4336. // {
  4337. // if (a1AGVUpCall == 1) // 0->1
  4338. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  4339. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  4340. // }
  4341. // }
  4342. // catch (Exception ex)
  4343. // {
  4344. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4345. // string str = ex.StackTrace;
  4346. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4347. // }
  4348. // // AGV上料完成信号
  4349. // try
  4350. // {
  4351. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  4352. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  4353. // if (a1AGVUpEnd != a1AGVUpEndOld)
  4354. // {
  4355. // if (a1AGVUpEnd == 1) // 0->1
  4356. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  4357. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  4358. // }
  4359. // }
  4360. // catch (Exception ex)
  4361. // {
  4362. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  4363. // string str = ex.StackTrace;
  4364. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4365. // }
  4366. // #endregion AGV上料
  4367. // #region AGV下料
  4368. // // AGV下料叫agv信号
  4369. // try
  4370. // {
  4371. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  4372. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  4373. // if (a1AGVDownCall != a1AGVDownCallOld)
  4374. // {
  4375. // if (a1AGVDownCall == 1) // 0->1
  4376. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  4377. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  4378. // }
  4379. // }
  4380. // catch (Exception ex)
  4381. // {
  4382. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  4383. // string str = ex.StackTrace;
  4384. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4385. // }
  4386. // // AGV下料完成信号
  4387. // try
  4388. // {
  4389. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  4390. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  4391. // if (a1AGVDownEnd != a1AGVDownEndOld)
  4392. // {
  4393. // if (a1AGVDownEnd == 1) // 0->1
  4394. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  4395. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  4396. // }
  4397. // }
  4398. // catch (Exception ex)
  4399. // {
  4400. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  4401. // string str = ex.StackTrace;
  4402. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4403. // }
  4404. // #endregion AGV下料
  4405. // #region 心跳
  4406. // try
  4407. // {
  4408. // short states = 0;
  4409. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  4410. // }
  4411. // catch (Exception ex)
  4412. // {
  4413. // string str = ex.StackTrace;
  4414. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4415. // }
  4416. // #endregion 心跳
  4417. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4418. // stopwatch1.Stop();
  4419. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  4420. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4421. // }
  4422. // else
  4423. // {
  4424. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4425. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4426. // Funs[plcNo].Connect(); // 重连
  4427. // }
  4428. // }
  4429. // catch (Exception ex)
  4430. // {
  4431. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4432. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4433. // Funs[plcNo].ReConnect();
  4434. // }
  4435. // Thread.Sleep(IntervalReadPLC);
  4436. // }
  4437. //}
  4438. /// <summary>
  4439. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  4440. /// </summary>
  4441. /// <param name="plcNo">PLC编号</param>
  4442. /// <param name="stationNameStr">工站全称</param>
  4443. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  4444. {
  4445. Stopwatch stopwatch1 = new Stopwatch();
  4446. Stopwatch stopwatch2 = new Stopwatch();
  4447. try
  4448. {
  4449. stopwatch1.Start();
  4450. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  4451. sn = sn.Replace("\0", "");
  4452. #region 查询载具上的产品信息
  4453. string cavityData = string.Empty;
  4454. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  4455. if (string.IsNullOrEmpty(cavityData))
  4456. cavityData = "";
  4457. if (snResult != 0)
  4458. {
  4459. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4460. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  4461. writeToPLC_Flag1.Adress = 2003;
  4462. writeToPLC_Flag1.Value = (short)6;
  4463. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  4464. stopwatch1.Stop();
  4465. AddMessage(LogType.Info, stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  4466. return;
  4467. }
  4468. #endregion 查询载具上的产品信息
  4469. string[] cavitySNs = cavityData.Split('.');
  4470. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  4471. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  4472. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  4473. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  4474. if (cavitySNs != null && cavitySNs.Length >= 2)
  4475. {
  4476. a1CavitySN1_VehicleStates = cavitySNs[0];
  4477. a1CavitySN2_VehicleStates = cavitySNs[1];
  4478. a1CavityResult1_VehicleStates = 2;
  4479. a1CavityResult2_VehicleStates = 2;
  4480. }
  4481. if (a1CavitySN1_VehicleStates == "假产品")
  4482. a1CavityResult1_VehicleStates = 3;
  4483. if (a1CavitySN2_VehicleStates == "假产品")
  4484. a1CavityResult2_VehicleStates = 3;
  4485. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4486. // 回写
  4487. stopwatch2.Start();
  4488. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  4489. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  4490. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  4491. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  4492. //// MES_Flag
  4493. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  4494. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4495. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4496. writeToPLC_Flag.Adress = 2003;
  4497. writeToPLC_Flag.Value = mES_Flag;
  4498. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  4499. {
  4500. Name = "a1CavitySN1_VehicleStates",
  4501. Adress = 2024,
  4502. ValueType = PLCValueType.String,
  4503. ValueTypeStrLength = 20,
  4504. Value = a1CavitySN1_VehicleStates
  4505. });
  4506. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  4507. {
  4508. Name = "a1CavitySN2_VehicleStates",
  4509. Adress = 2044,
  4510. ValueType = PLCValueType.String,
  4511. ValueTypeStrLength = 20,
  4512. Value = a1CavitySN2_VehicleStates
  4513. });
  4514. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4515. {
  4516. Name = "a1CavityResult1_VehicleStates",
  4517. Adress = 2064,
  4518. ValueType = PLCValueType.Short,
  4519. Value = a1CavityResult1_VehicleStates
  4520. });
  4521. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4522. {
  4523. Name = "a1CavityResult2_VehicleStates",
  4524. Adress = 2065,
  4525. ValueType = PLCValueType.Short,
  4526. Value = a1CavityResult2_VehicleStates
  4527. });
  4528. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4529. stopwatch2.Stop();
  4530. }
  4531. catch (Exception ex)
  4532. {
  4533. string str = ex.StackTrace;
  4534. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4535. // MES_Flag
  4536. stopwatch2.Start();
  4537. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  4538. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4539. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4540. writeToPLC_Flag.Adress = 2003;
  4541. writeToPLC_Flag.Value = (short)6;
  4542. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4543. stopwatch2.Stop();
  4544. }
  4545. stopwatch1.Stop();
  4546. AddMessage(LogType.Info, stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4547. }
  4548. /// <summary>
  4549. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  4550. /// </summary>
  4551. /// <param name="plcNo">PLC编号</param>
  4552. /// <param name="stationNameStr">工站全称</param>
  4553. private void S1上料进站校验(int plcNo, string stationNameStr)
  4554. {
  4555. Stopwatch stopwatch1 = new Stopwatch();
  4556. Stopwatch stopwatch2 = new Stopwatch();
  4557. try
  4558. {
  4559. stopwatch1.Start();
  4560. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  4561. sn = sn.Replace("\0", "");
  4562. // 保存进站数据+调用进站MES接口
  4563. List<TestItem> item = new List<TestItem>();
  4564. stopwatch2.Start();
  4565. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, out string errorMsg);
  4566. stopwatch2.Stop();
  4567. short a1MES_FLAG_Check = (short)result;
  4568. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4569. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4570. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4571. writeToPLC_Flag.Adress = 2077;
  4572. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  4573. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4574. }
  4575. catch (Exception ex)
  4576. {
  4577. string str = ex.StackTrace;
  4578. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4579. // MES_Flag
  4580. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4581. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4582. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4583. writeToPLC_Flag.Adress = 2077;
  4584. writeToPLC_Flag.Value = (short)6;
  4585. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4586. }
  4587. stopwatch1.Stop();
  4588. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4589. }
  4590. /// <summary>
  4591. /// [S1] Tray盘上料装备(板测)- 出站接口
  4592. /// </summary>
  4593. /// <param name="plcNo"></param>
  4594. /// <param name="stationCode"></param>
  4595. /// <param name="stationName"></param>
  4596. private void S1出站接口(int plcNo, string stationCode, string stationName)
  4597. {
  4598. Stopwatch stopwatch1 = new Stopwatch();
  4599. Stopwatch stopwatch2 = new Stopwatch();
  4600. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4601. string stationNameStr = stationCode + stationName;
  4602. string processItem = stationName; // 测试项目
  4603. try
  4604. {
  4605. stopwatch1.Start();
  4606. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4607. //string batch_num = GlobalContext.BatchNumber; // 批次号
  4608. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4609. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4610. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  4611. sn = sn.Replace("\0", "");
  4612. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  4613. partNo1 = partNo1.Replace("\0", "");
  4614. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  4615. partNo2 = partNo2.Replace("\0", "");
  4616. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  4617. bool pass = a1Result == 1;
  4618. stopwatch2.Start();
  4619. // 产品1
  4620. List<TestItem> items = new List<TestItem>();
  4621. items.Add(new TestItem()
  4622. {
  4623. Parameter_name = "载具码",
  4624. Parameter_value = sn,
  4625. Parameter_unit = ""
  4626. });
  4627. items.Add(new TestItem()
  4628. {
  4629. Parameter_name = "载具穴号",
  4630. Parameter_value = "1",
  4631. Parameter_unit = ""
  4632. });
  4633. items.Add(new TestItem()
  4634. {
  4635. Parameter_name = "产品结果",
  4636. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4637. Parameter_unit = ""
  4638. });
  4639. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4640. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  4641. // 产品2
  4642. items = new List<TestItem>();
  4643. items.Add(new TestItem()
  4644. {
  4645. Parameter_name = "载具码",
  4646. Parameter_value = sn,
  4647. Parameter_unit = ""
  4648. });
  4649. items.Add(new TestItem()
  4650. {
  4651. Parameter_name = "载具穴号",
  4652. Parameter_value = "2",
  4653. Parameter_unit = ""
  4654. });
  4655. items.Add(new TestItem()
  4656. {
  4657. Parameter_name = "产品结果",
  4658. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4659. Parameter_unit = ""
  4660. });
  4661. int result2 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4662. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  4663. short result = 0;
  4664. List<int> results = new List<int>() { result1, result2 };
  4665. if (result1 == 1 && result2 == 1)
  4666. result = 1;
  4667. else if (results.Contains(3))
  4668. result = 3;
  4669. else if (results.Contains(2))
  4670. result = 2;
  4671. else if (results.Contains(4))
  4672. result = 4;
  4673. else
  4674. result = 4;
  4675. stopwatch2.Stop();
  4676. #region 存储绑定数据到 边线MES系统中
  4677. if (result == 1)
  4678. {
  4679. string data = string.Concat(partNo1, ".", partNo2);
  4680. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  4681. if (resultMesR != 0)
  4682. {
  4683. result = 4;
  4684. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  4685. }
  4686. }
  4687. #endregion 存储绑定数据到 边线MES系统中
  4688. // MES_Flag 为MES报错
  4689. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4690. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  4691. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4692. writeToPLC_Flag.Name = "a1MES_FLAG";
  4693. writeToPLC_Flag.Adress = 2109;
  4694. writeToPLC_Flag.Value = result;
  4695. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4696. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4697. }
  4698. catch (Exception ex)
  4699. {
  4700. stopwatch2.Restart();
  4701. // MES_Flag 为4上位机报错
  4702. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  4703. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4704. writeToPLC_Flag.Name = "a1MES_FLAG";
  4705. writeToPLC_Flag.Adress = 2109;
  4706. writeToPLC_Flag.Value = (short)4;
  4707. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4708. stopwatch2.Stop();
  4709. string str = ex.StackTrace;
  4710. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4711. }
  4712. stopwatch1.Stop();
  4713. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4714. }
  4715. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  4716. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  4717. //{
  4718. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4719. // string stationNameStr = stationCode + stationName;
  4720. // string processItem = stationName; // 测试项目
  4721. // try
  4722. // {
  4723. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4724. // string accno = "1"; // 工序编号
  4725. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  4726. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  4727. // List<OneCheckItem> items = new List<OneCheckItem>()
  4728. // {
  4729. // new OneCheckItem()
  4730. // {
  4731. // Onecheck_name="胶圈装配行程设定上限",
  4732. // Onecheck_content="上限值",
  4733. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  4734. // },
  4735. // };
  4736. // OneCheckData oneCheckData = new OneCheckData()
  4737. // {
  4738. // Line_code = GlobalContext.LineCode,
  4739. // Line_name = GlobalContext.LineName,
  4740. // Equipment_code = equipmentCode,
  4741. // Equipment_name = equipmentCode,
  4742. // Workorder_code = workorder_code,
  4743. // Procedure_code = accno,
  4744. // Procedure_name = processItem,
  4745. // Oneckeck_values = items,
  4746. // Onecheck_empcode = "",
  4747. // Onecheck_empname = "",
  4748. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  4749. // };
  4750. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  4751. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  4752. // short result = result1 == 1 ? (short)1 : (short)2;
  4753. // // MES_Flag 为4MES报错
  4754. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  4755. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4756. // }
  4757. // catch (Exception ex)
  4758. // {
  4759. // // MES_Flag 为2上位机报错
  4760. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4761. // string str = ex.StackTrace;
  4762. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4763. // }
  4764. //}
  4765. // ReadStation_S1_2 节拍接口+AGV
  4766. /// <summary>
  4767. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  4768. /// </summary>
  4769. /// <param name="plcNo">PLC编号</param>
  4770. /// <param name="stationNameStr">工站全称</param>
  4771. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  4772. {
  4773. Stopwatch stopwatch1 = new Stopwatch();
  4774. Stopwatch stopwatch2 = new Stopwatch();
  4775. try
  4776. {
  4777. stopwatch1.Start();
  4778. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  4779. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  4780. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  4781. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  4782. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  4783. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  4784. // ZS 将SN发给ICT标机(串口)
  4785. short a1MES_FLAG_ICT = 1;
  4786. stopwatch2.Start();
  4787. // MES_Flag
  4788. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  4789. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4790. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4791. writeToPLC_Flag.Adress = 2182;
  4792. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  4793. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4794. stopwatch2.Stop();
  4795. }
  4796. catch (Exception ex)
  4797. {
  4798. string str = ex.StackTrace;
  4799. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4800. stopwatch2.Start();
  4801. // MES_Flag
  4802. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4803. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4804. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4805. writeToPLC_Flag.Adress = 2182;
  4806. writeToPLC_Flag.Value = (short)4;
  4807. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4808. stopwatch2.Stop();
  4809. }
  4810. stopwatch1.Stop();
  4811. AddMessage(LogType.Info, stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4812. }
  4813. /// <summary>
  4814. /// [S1] Tray盘上料装备(板测)- 节拍接口
  4815. /// </summary>
  4816. /// <param name="plcNo">PLC编号</param>
  4817. /// <param name="stationNameStr">工站全称</param>
  4818. private void S1节拍接口(int plcNo, string stationNameStr)
  4819. {
  4820. Stopwatch stopwatch1 = new Stopwatch();
  4821. Stopwatch stopwatch2 = new Stopwatch();
  4822. string resultStr = string.Empty;
  4823. try
  4824. {
  4825. stopwatch1.Start();
  4826. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  4827. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  4828. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  4829. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  4830. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  4831. string a1OEEPartNum = ((int)s1PLCData["a1OEEPartNum"]).ToString(); // 穴位号
  4832. a1OEEPartNum = a1OEEPartNum.Replace("\0", "");
  4833. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4834. if (!actionBool)
  4835. {
  4836. stopwatch2.Start();
  4837. // MES_Flag
  4838. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4839. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4840. writeToPLC_Flag1.Name = "a1OEEMES_FLAG";
  4841. writeToPLC_Flag1.Adress = 2254;
  4842. writeToPLC_Flag1.Value = (short)1;
  4843. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag1);
  4844. stopwatch2.Stop();
  4845. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4846. return;
  4847. }
  4848. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode))
  4849. {
  4850. stopwatch2.Start();
  4851. // MES_Flag
  4852. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4853. WriteToPLC_Flag writeToPLC_Flag2 = new WriteToPLC_Flag(); // MES_Flag
  4854. writeToPLC_Flag2.Name = "a1OEEMES_FLAG";
  4855. writeToPLC_Flag2.Adress = 2254;
  4856. writeToPLC_Flag2.Value = (short)1;
  4857. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag2);
  4858. stopwatch2.Stop();
  4859. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4860. return;
  4861. }
  4862. else if (string.IsNullOrEmpty(a1OEEPartNo) && !string.IsNullOrEmpty(a1OEEVehicleCode))
  4863. { // 查产品SN
  4864. a1OEEPartNo = "Test"; // ZS
  4865. }
  4866. short a1OEEMES_FLAG = 0;
  4867. // 上传OEE
  4868. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  4869. a1OEEMES_FLAG = result.Item1;
  4870. resultStr = result.Item2;
  4871. stopwatch2.Start();
  4872. // MES_Flag
  4873. //Funs[plcNo].WriteMultipleRegisters<short>(2254, a1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4874. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4875. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  4876. writeToPLC_Flag.Adress = 2254;
  4877. writeToPLC_Flag.Value = a1OEEMES_FLAG;
  4878. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  4879. stopwatch2.Stop();
  4880. }
  4881. catch (Exception ex)
  4882. {
  4883. string str = ex.StackTrace;
  4884. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4885. // MES_Flag
  4886. stopwatch2.Start();
  4887. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4888. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4889. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  4890. writeToPLC_Flag.Adress = 2254;
  4891. writeToPLC_Flag.Value = (short)4;
  4892. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  4893. stopwatch2.Stop();
  4894. }
  4895. stopwatch1.Stop();
  4896. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4897. }
  4898. /// <summary>
  4899. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  4900. /// </summary>
  4901. /// <param name="plcNo">PLC编号</param>
  4902. /// <param name="stationNameStr">工站全称</param>
  4903. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  4904. {
  4905. Stopwatch stopwatch1 = new Stopwatch();
  4906. Stopwatch stopwatch2 = new Stopwatch();
  4907. try
  4908. {
  4909. stopwatch1.Start();
  4910. // ZS 呼叫AGV
  4911. short a1AGVUpCall = 2;
  4912. stopwatch2.Start();
  4913. // a1AGVUpCall
  4914. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4915. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4916. writeToPLC_Flag.Name = "a1AGVUpCall";
  4917. writeToPLC_Flag.Adress = 2307;
  4918. writeToPLC_Flag.Value = a1AGVUpCall;
  4919. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  4920. stopwatch2.Stop();
  4921. }
  4922. catch (Exception ex)
  4923. {
  4924. string str = ex.StackTrace;
  4925. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4926. // a1AGVUpCall
  4927. stopwatch2.Start();
  4928. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4929. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4930. writeToPLC_Flag.Name = "a1AGVUpCall";
  4931. writeToPLC_Flag.Adress = 2307;
  4932. writeToPLC_Flag.Value = (short)4;
  4933. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  4934. stopwatch2.Stop();
  4935. }
  4936. stopwatch1.Stop();
  4937. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4938. }
  4939. /// <summary>
  4940. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  4941. /// </summary>
  4942. /// <param name="plcNo">PLC编号</param>
  4943. /// <param name="stationNameStr">工站全称</param>
  4944. private void S1AGV上料完成(int plcNo, string stationNameStr)
  4945. {
  4946. Stopwatch stopwatch1 = new Stopwatch();
  4947. Stopwatch stopwatch2 = new Stopwatch();
  4948. try
  4949. {
  4950. stopwatch1.Start();
  4951. // ZS AGV上料完成,让小车离开
  4952. short a1AGVUpEnd = 2;
  4953. stopwatch2.Start();
  4954. // a1AGVUpEnd
  4955. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4956. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4957. writeToPLC_Flag.Name = "a1AGVUpEnd";
  4958. writeToPLC_Flag.Adress = 2309;
  4959. writeToPLC_Flag.Value = a1AGVUpEnd;
  4960. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  4961. stopwatch2.Stop();
  4962. }
  4963. catch (Exception ex)
  4964. {
  4965. string str = ex.StackTrace;
  4966. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4967. // a1AGVUpEnd
  4968. stopwatch2.Start();
  4969. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  4970. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4971. writeToPLC_Flag.Name = "a1AGVUpEnd";
  4972. writeToPLC_Flag.Adress = 2309;
  4973. writeToPLC_Flag.Value = (short)4;
  4974. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  4975. stopwatch2.Stop();
  4976. }
  4977. stopwatch1.Stop();
  4978. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4979. }
  4980. /// <summary>
  4981. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  4982. /// </summary>
  4983. /// <param name="plcNo">PLC编号</param>
  4984. /// <param name="stationNameStr">工站全称</param>
  4985. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  4986. {
  4987. Stopwatch stopwatch1 = new Stopwatch();
  4988. Stopwatch stopwatch2 = new Stopwatch();
  4989. try
  4990. {
  4991. stopwatch1.Start();
  4992. // ZS 呼叫AGV
  4993. short a1AGVDownCall = 2;
  4994. stopwatch2.Start();
  4995. // a1AGVDownCall
  4996. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4997. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4998. writeToPLC_Flag.Name = "a1AGVDownCall";
  4999. writeToPLC_Flag.Adress = 2320;
  5000. writeToPLC_Flag.Value = a1AGVDownCall;
  5001. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5002. stopwatch2.Stop();
  5003. }
  5004. catch (Exception ex)
  5005. {
  5006. string str = ex.StackTrace;
  5007. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5008. // a1AGVDownCall
  5009. stopwatch2.Start();
  5010. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  5011. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5012. writeToPLC_Flag.Name = "a1AGVDownCall";
  5013. writeToPLC_Flag.Adress = 2320;
  5014. writeToPLC_Flag.Value = (short)4;
  5015. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5016. stopwatch2.Stop();
  5017. }
  5018. stopwatch1.Stop();
  5019. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5020. }
  5021. /// <summary>
  5022. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  5023. /// </summary>
  5024. /// <param name="plcNo">PLC编号</param>
  5025. /// <param name="stationNameStr">工站全称</param>
  5026. private void S1AGV下料完成(int plcNo, string stationNameStr)
  5027. {
  5028. Stopwatch stopwatch1 = new Stopwatch();
  5029. Stopwatch stopwatch2 = new Stopwatch();
  5030. try
  5031. {
  5032. stopwatch1.Start();
  5033. // ZS AGV上料完成,让小车离开
  5034. short a1AGVDownEnd = 2;
  5035. stopwatch2.Start();
  5036. // a1AGVDownEnd
  5037. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5038. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5039. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5040. writeToPLC_Flag.Adress = 2322;
  5041. writeToPLC_Flag.Value = a1AGVDownEnd;
  5042. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5043. stopwatch2.Stop();
  5044. }
  5045. catch (Exception ex)
  5046. {
  5047. string str = ex.StackTrace;
  5048. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5049. // a1AGVDownEnd
  5050. stopwatch2.Start();
  5051. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  5052. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5053. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5054. writeToPLC_Flag.Adress = 2322;
  5055. writeToPLC_Flag.Value = (short)4;
  5056. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5057. stopwatch2.Stop();
  5058. }
  5059. stopwatch1.Stop();
  5060. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5061. }
  5062. #endregion [S1] Tray盘上料装备(板测)
  5063. #endregion PLC1 张超凡
  5064. #region PLC2 李晓奇
  5065. #region [S2] FCT(板测)
  5066. /// <summary>
  5067. /// S2工位的数据- 触发信号上次的值
  5068. /// </summary>
  5069. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  5070. /// <summary>
  5071. /// S2工位的数据(含触发信号)
  5072. /// </summary>
  5073. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  5074. /// <summary>
  5075. /// S2工位的数据- 回写点位
  5076. /// </summary>
  5077. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5078. /// <summary>
  5079. /// [S2] FCT(板测)
  5080. /// </summary>
  5081. /// <param name="plcNo">PLC编号</param>
  5082. //private void ReadStation_S2(int plcNo)
  5083. //{
  5084. // // [S1] Tray盘上料装备
  5085. // // [S2] FCT
  5086. // // [S3] 值板机
  5087. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5088. // // [S5] Tray盘下料装备
  5089. // /// 上位机心跳
  5090. // /// 获取设备报警数据与状态信息
  5091. // string stationCode = "[S2]";
  5092. // string stationName = "FCT";
  5093. // string stationNameStr = stationCode + stationName;
  5094. // #region 创建字典
  5095. // // 触发信号字典 赋值
  5096. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5097. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  5098. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5099. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5100. // // PLC数据字典 赋值
  5101. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  5102. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  5103. // s2PLCData.Add("b1ProductSN_Check", 0);
  5104. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  5105. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  5106. // s2PLCData.Add("b1ProductSN_Unbind", "");
  5107. // s2PLCData.Add("b1ProductSN_Bind", "");
  5108. // s2PLCData.Add("b1Part1SN_Bind", "");
  5109. // s2PLCData.Add("b1Part2SN_Bind", "");
  5110. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  5111. // s2PLCData.Add("b1MES_FLAG", 0);
  5112. // s2PLCData.Add("b1ProductSN", 0);
  5113. // s2PLCData.Add("b1Part1Result", 0);
  5114. // s2PLCData.Add("b1Part2Result", 0);
  5115. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  5116. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  5117. // s2PLCData.Add("b1OEEProductSN", "");
  5118. // s2PLCData.Add("b1OEEType", 0);
  5119. // #endregion 创建字典
  5120. // while (IsRun)
  5121. // {
  5122. // try
  5123. // {
  5124. // if (!GlobalContext._IsCon_Funs2)
  5125. // {
  5126. // UpdatePLCMonitor(1, plcNo, 0);
  5127. // continue;
  5128. // }
  5129. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5130. // {
  5131. // Stopwatch stopwatch1 = new Stopwatch();
  5132. // Stopwatch stopwatch2 = new Stopwatch();
  5133. // stopwatch1.Start();
  5134. // stopwatch2.Start();
  5135. // #region 一次性读取所有数据
  5136. // // 一次性读取所有数据
  5137. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  5138. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  5139. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  5140. // int[] datas = data1.Concat(data2).ToArray();
  5141. // datas = datas.Concat(data3).ToArray();
  5142. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  5143. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  5144. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5145. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  5146. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  5147. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  5148. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  5149. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  5150. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  5151. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  5152. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  5153. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  5154. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  5155. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  5156. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  5157. // s2PLCData["b1MES_FLAG"] = datas[169];
  5158. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  5159. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  5160. // s2PLCData["b1Part1Result"] = datas[190];
  5161. // s2PLCData["b1Part2Result"] = datas[191];
  5162. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  5163. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  5164. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  5165. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  5166. // s2PLCData["b1OEEType"] = datas[224];
  5167. // #endregion 一次性读取所有数据
  5168. // stopwatch2.Stop();
  5169. // #region 回写操作,写后清空flag
  5170. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  5171. // #endregion 回写操作,写后清空flag
  5172. // #region 进站校验
  5173. // try
  5174. // {
  5175. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  5176. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5177. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  5178. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  5179. // {
  5180. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  5181. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5182. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  5183. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5184. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  5185. // }
  5186. // }
  5187. // catch (Exception ex)
  5188. // {
  5189. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5190. // string str = ex.StackTrace;
  5191. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5192. // }
  5193. // #endregion 进站校验
  5194. // #region 二穴载具解绑/绑定(产品换载具)
  5195. // try
  5196. // {
  5197. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  5198. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5199. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  5200. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  5201. // {
  5202. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  5203. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5204. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  5205. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  5206. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  5207. // }
  5208. // }
  5209. // catch (Exception ex)
  5210. // {
  5211. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5212. // string str = ex.StackTrace;
  5213. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5214. // }
  5215. // #endregion 二穴载具解绑/绑定(产品换载具)
  5216. // #region FCT-出站接口
  5217. // try
  5218. // {
  5219. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  5220. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  5221. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  5222. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  5223. // {
  5224. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  5225. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5226. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  5227. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  5228. // }
  5229. // }
  5230. // catch (Exception ex)
  5231. // {
  5232. // // MES_Flag 为6上位机报错
  5233. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  5234. // string str = ex.StackTrace;
  5235. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5236. // }
  5237. // #endregion FCT-出站接口
  5238. // #region 节拍接口
  5239. // try
  5240. // {
  5241. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  5242. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  5243. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  5244. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  5245. // {
  5246. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  5247. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5248. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  5249. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  5250. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  5251. // }
  5252. // }
  5253. // catch (Exception ex)
  5254. // {
  5255. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5256. // string str = ex.StackTrace;
  5257. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5258. // }
  5259. // #endregion 节拍接口
  5260. // #region 心跳
  5261. // try
  5262. // {
  5263. // short states = 0;
  5264. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  5265. // }
  5266. // catch (Exception ex)
  5267. // {
  5268. // string str = ex.StackTrace;
  5269. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5270. // }
  5271. // #endregion 心跳
  5272. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5273. // stopwatch1.Stop();
  5274. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  5275. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5276. // }
  5277. // else
  5278. // {
  5279. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5280. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5281. // Funs[plcNo].Connect();
  5282. // }
  5283. // }
  5284. // catch (Exception ex)
  5285. // {
  5286. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5287. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5288. // Funs[plcNo].ReConnect();
  5289. // }
  5290. // Thread.Sleep(IntervalReadPLC);
  5291. // }
  5292. //}
  5293. /// <summary>
  5294. /// [S2] FCT(板测)- 进站校验
  5295. /// </summary>
  5296. /// <param name="plcNo">PLC编号</param>
  5297. /// <param name="stationNameStr">工站全称</param>
  5298. private void S2进站校验(int plcNo, string stationNameStr)
  5299. {
  5300. Stopwatch stopwatch1 = new Stopwatch();
  5301. Stopwatch stopwatch2 = new Stopwatch();
  5302. try
  5303. {
  5304. stopwatch1.Start();
  5305. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  5306. sn = sn.Replace("\0", "");
  5307. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5308. // 查询物料码By载具码 并判断是不是假产品
  5309. string cavityData = string.Empty;
  5310. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  5311. if (string.IsNullOrEmpty(cavityData))
  5312. cavityData = "";
  5313. if (snResult != 0)
  5314. {
  5315. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5316. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  5317. writeToPLC_Flag1.Adress = 2003;
  5318. writeToPLC_Flag1.Value = (short)6;
  5319. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  5320. stopwatch1.Stop();
  5321. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5322. return;
  5323. }
  5324. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5325. string[] cavitySNs = cavityData.Split('.');
  5326. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  5327. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  5328. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5329. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5330. if (cavitySNs != null && cavitySNs.Length >= 2)
  5331. {
  5332. b1Part1SN_Check = cavitySNs[0];
  5333. b1Part2SN_Check = cavitySNs[1];
  5334. b1Part1Result_Check = 2;
  5335. b1Part2Result_Check = 2;
  5336. }
  5337. if (b1Part1SN_Check == "假产品")
  5338. b1Part1Result_Check = 3;
  5339. if (b1Part2SN_Check == "假产品")
  5340. b1Part2Result_Check = 3;
  5341. // 调用MES进站
  5342. stopwatch2.Start();
  5343. // 调用MES进站 - 产品1
  5344. List<TestItem> item;
  5345. int result1 = b1Part1Result_Check;
  5346. if (result1 != 3)
  5347. {
  5348. item = new List<TestItem>();
  5349. item.Add(new TestItem()
  5350. {
  5351. Parameter_name = "载具码",
  5352. Parameter_value = sn,
  5353. });
  5354. item.Add(new TestItem()
  5355. {
  5356. Parameter_name = "载具穴号",
  5357. Parameter_value = "1",
  5358. });
  5359. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part1SN_Check, item, out string errorMsg);
  5360. }
  5361. // 调用MES进站 - 产品2
  5362. int result2 = b1Part2Result_Check;
  5363. if (result2 != 3)
  5364. {
  5365. item = new List<TestItem>();
  5366. item.Add(new TestItem()
  5367. {
  5368. Parameter_name = "载具码",
  5369. Parameter_value = sn,
  5370. });
  5371. item.Add(new TestItem()
  5372. {
  5373. Parameter_name = "载具穴号",
  5374. Parameter_value = "2",
  5375. });
  5376. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part2SN_Check, item, out string errorMsg);
  5377. }
  5378. stopwatch2.Stop();
  5379. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5380. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5381. int result = result1;
  5382. if (result == 1)
  5383. result = result2;
  5384. short b1MES_FLAG_Check = (short)result;
  5385. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  5386. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  5387. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  5388. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  5389. //// MES_Flag
  5390. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5391. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5392. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5393. writeToPLC_Flag.Adress = 2003;
  5394. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  5395. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5396. {
  5397. Name = "b1Part1SN_Check",
  5398. Adress = 2024,
  5399. ValueType = PLCValueType.String,
  5400. ValueTypeStrLength = 20,
  5401. Value = b1Part1SN_Check
  5402. });
  5403. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5404. {
  5405. Name = "b1Part2SN_Check",
  5406. Adress = 2044,
  5407. ValueType = PLCValueType.String,
  5408. ValueTypeStrLength = 20,
  5409. Value = b1Part2SN_Check
  5410. });
  5411. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5412. {
  5413. Name = "b1Part1Result_Check",
  5414. Adress = 2064,
  5415. ValueType = PLCValueType.Short,
  5416. Value = b1Part1Result_Check
  5417. });
  5418. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5419. {
  5420. Name = "b1Part2Result_Check",
  5421. Adress = 2065,
  5422. ValueType = PLCValueType.Short,
  5423. Value = b1Part2Result_Check
  5424. });
  5425. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5426. }
  5427. catch (Exception ex)
  5428. {
  5429. string str = ex.StackTrace;
  5430. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5431. // MES_Flag
  5432. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5433. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5434. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5435. writeToPLC_Flag.Adress = 2003;
  5436. writeToPLC_Flag.Value = (short)6;
  5437. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5438. }
  5439. stopwatch1.Stop();
  5440. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5441. }
  5442. /// <summary>
  5443. /// [S2] FCT(板测)- 二穴载具解绑绑定
  5444. /// </summary>
  5445. /// <param name="plcNo">PLC编号</param>
  5446. /// <param name="stationNameStr">工站全称</param>
  5447. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  5448. {
  5449. Stopwatch stopwatch1 = new Stopwatch();
  5450. Stopwatch stopwatch2 = new Stopwatch();
  5451. try
  5452. {
  5453. stopwatch1.Start();
  5454. // 产品换载具
  5455. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  5456. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  5457. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  5458. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  5459. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  5460. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  5461. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  5462. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  5463. stopwatch2.Start();
  5464. #region 查询载具上的产品信息
  5465. //string cavityData = string.Empty;
  5466. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  5467. //if (string.IsNullOrEmpty(cavityData))
  5468. // cavityData = "";
  5469. //if (snResult != 0)
  5470. //{
  5471. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5472. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5473. // writeToPLC_Flag.Adress = 2077;
  5474. // writeToPLC_Flag.Value = (short)6;
  5475. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5476. // stopwatch1.Stop();
  5477. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5478. // return;
  5479. //}
  5480. #endregion 查询载具上的产品信息
  5481. #region 解绑(边线MES系统)
  5482. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  5483. if (snResult != 0)
  5484. {
  5485. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5486. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5487. writeToPLC_Flag1.Adress = 2077;
  5488. writeToPLC_Flag1.Value = (short)6;
  5489. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5490. stopwatch1.Stop();
  5491. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5492. return;
  5493. }
  5494. #endregion 解绑(边线MES系统)
  5495. #region 存储绑定数据到 边线MES系统中
  5496. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  5497. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  5498. if (snResult != 0)
  5499. {
  5500. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5501. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5502. writeToPLC_Flag1.Adress = 2077;
  5503. writeToPLC_Flag1.Value = (short)6;
  5504. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5505. stopwatch1.Stop();
  5506. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5507. return;
  5508. }
  5509. #endregion 存储绑定数据到 边线MES系统中
  5510. stopwatch2.Stop();
  5511. short b1MES_FLAG_Unbind = 1;
  5512. // MES_Flag
  5513. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5514. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5515. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5516. writeToPLC_Flag.Adress = 2077;
  5517. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  5518. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5519. }
  5520. catch (Exception ex)
  5521. {
  5522. string str = ex.StackTrace;
  5523. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5524. // MES_Flag
  5525. stopwatch2.Start();
  5526. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5527. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5528. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5529. writeToPLC_Flag.Adress = 2077;
  5530. writeToPLC_Flag.Value = (short)6;
  5531. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5532. stopwatch2.Stop();
  5533. }
  5534. stopwatch1.Stop();
  5535. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5536. }
  5537. //// 上次采集到的SN
  5538. //private string sn_FCT = string.Empty;
  5539. /// <summary>
  5540. /// [S2] FCT(板测)- 出站数据
  5541. /// </summary>
  5542. private void S2出站接口(int plcNo, string stationCode, string stationName)
  5543. {
  5544. Stopwatch stopwatch1 = new Stopwatch();
  5545. Stopwatch stopwatch2 = new Stopwatch();
  5546. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5547. string stationNameStr = stationCode + stationName;
  5548. string processItem = stationName; // 测试项目
  5549. try
  5550. {
  5551. stopwatch1.Start();
  5552. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5553. //string batch_num = GlobalContext.BatchNumber; // 批次号
  5554. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5555. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5556. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  5557. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  5558. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  5559. bool pass1 = b1Part1Result == 1;
  5560. bool pass2 = b1Part2Result == 1;
  5561. #region 根据 载具SN 查 物料SN
  5562. string cavityData = string.Empty;
  5563. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  5564. if (string.IsNullOrEmpty(cavityData))
  5565. cavityData = "";
  5566. if (snResult != 0)
  5567. {
  5568. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5569. writeToPLC_Flag1.Name = "b1MES_FLAG";
  5570. writeToPLC_Flag1.Adress = 2169;
  5571. writeToPLC_Flag1.Value = (short)4;
  5572. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  5573. stopwatch1.Stop();
  5574. AddMessage(LogType.Info, stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5575. return;
  5576. }
  5577. #endregion 根据 载具SN 查 物料SN
  5578. string[] cavitySNs = cavityData.Split('.');
  5579. string b1ProductSN1 = string.Empty;
  5580. string b1ProductSN2 = string.Empty;
  5581. if (cavitySNs != null && cavitySNs.Length >= 2)
  5582. {
  5583. b1ProductSN1 = cavitySNs[0];
  5584. b1ProductSN2 = cavitySNs[1];
  5585. }
  5586. stopwatch2.Start();
  5587. // 产品1
  5588. int result1 = 0;
  5589. if (b1ProductSN1 == "假产品")
  5590. result1 = 1;
  5591. else
  5592. {
  5593. List<TestItem> items1 = new List<TestItem>();
  5594. items1.Add(new TestItem()
  5595. {
  5596. Parameter_name = "载具码",
  5597. Parameter_value = b1ProductSN.ToString(),
  5598. Parameter_unit = ""
  5599. });
  5600. items1.Add(new TestItem()
  5601. {
  5602. Parameter_name = "载具穴号",
  5603. Parameter_value = "1",
  5604. Parameter_unit = ""
  5605. });
  5606. items1.Add(new TestItem()
  5607. {
  5608. Parameter_name = "产品结果",
  5609. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  5610. Parameter_unit = ""
  5611. });
  5612. result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  5613. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  5614. }
  5615. // 产品2
  5616. int result2 = 0;
  5617. if (b1ProductSN1 == "假产品")
  5618. result2 = 1;
  5619. else
  5620. {
  5621. List<TestItem> items2 = new List<TestItem>();
  5622. items2.Add(new TestItem()
  5623. {
  5624. Parameter_name = "载具码",
  5625. Parameter_value = b1ProductSN.ToString(),
  5626. Parameter_unit = ""
  5627. });
  5628. items2.Add(new TestItem()
  5629. {
  5630. Parameter_name = "载具穴号",
  5631. Parameter_value = "2",
  5632. Parameter_unit = ""
  5633. });
  5634. items2.Add(new TestItem()
  5635. {
  5636. Parameter_name = "产品结果",
  5637. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  5638. Parameter_unit = ""
  5639. });
  5640. result2 = SwitctProcessData(stationNameStr, items2, equipmentCode, processItem
  5641. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  5642. }
  5643. short result = 0;
  5644. List<int> results = new List<int>() { result1, result2 };
  5645. if (result1 == 1 && result2 == 1)
  5646. result = 1;
  5647. else if (results.Contains(3))
  5648. result = 3;
  5649. else if (results.Contains(2))
  5650. result = 2;
  5651. else if (results.Contains(4))
  5652. result = 4;
  5653. else
  5654. result = 4;
  5655. stopwatch2.Stop();
  5656. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5657. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5658. writeToPLC_Flag.Name = "b1MES_FLAG";
  5659. writeToPLC_Flag.Adress = 2169;
  5660. writeToPLC_Flag.Value = result;
  5661. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5662. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  5663. }
  5664. catch (Exception ex)
  5665. {
  5666. stopwatch2.Restart();
  5667. // MES_Flag 为4上位机报错
  5668. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  5669. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5670. writeToPLC_Flag.Name = "b1MES_FLAG";
  5671. writeToPLC_Flag.Adress = 2169;
  5672. writeToPLC_Flag.Value = (short)4;
  5673. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5674. stopwatch2.Stop();
  5675. string str = ex.StackTrace;
  5676. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5677. }
  5678. stopwatch1.Stop();
  5679. AddMessage(LogType.Info, stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5680. }
  5681. /// <summary>
  5682. /// [S2] FCT(板测)- 节拍接口
  5683. /// </summary>
  5684. /// <param name="plcNo">PLC编号</param>
  5685. /// <param name="stationNameStr">工站全称</param>
  5686. private void S2节拍接口(int plcNo, string stationNameStr)
  5687. {
  5688. Stopwatch stopwatch1 = new Stopwatch();
  5689. Stopwatch stopwatch2 = new Stopwatch();
  5690. string resultStr = string.Empty;
  5691. try
  5692. {
  5693. stopwatch1.Start();
  5694. string oEEType = ((int)s2PLCData["b1OEEType"]).ToString(); // 节拍类型(plc写入)
  5695. string b1OEEProductSN = (string)s2PLCData["b1OEEProductSN"]; // 载具SN
  5696. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5697. if (!actionBool)
  5698. {
  5699. stopwatch2.Start();
  5700. // MES_Flag
  5701. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5702. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5703. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5704. writeToPLC_Flag1.Adress = 2203;
  5705. writeToPLC_Flag1.Value = (short)4;
  5706. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5707. stopwatch2.Stop();
  5708. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5709. return;
  5710. }
  5711. string b1OEEPartNo = string.Empty; // 物料码
  5712. if (string.IsNullOrEmpty(b1OEEProductSN))
  5713. {
  5714. stopwatch2.Start();
  5715. // MES_Flag
  5716. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5717. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5718. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5719. writeToPLC_Flag1.Adress = 2203;
  5720. writeToPLC_Flag1.Value = (short)1;
  5721. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5722. stopwatch2.Stop();
  5723. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5724. return;
  5725. }
  5726. else
  5727. { // 查产品SN
  5728. b1OEEPartNo = "Test"; // ZS
  5729. }
  5730. short b1OEEMES_FLAG = 0;
  5731. // 上传OEE
  5732. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, b1OEEPartNo, b1OEEProductSN);
  5733. b1OEEMES_FLAG = result.Item1;
  5734. resultStr = result.Item2;
  5735. stopwatch2.Start();
  5736. // MES_Flag
  5737. //Funs[plcNo].WriteMultipleRegisters<short>(2203, b1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5738. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5739. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5740. writeToPLC_Flag.Adress = 2203;
  5741. writeToPLC_Flag.Value = b1OEEMES_FLAG;
  5742. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5743. stopwatch2.Stop();
  5744. }
  5745. catch (Exception ex)
  5746. {
  5747. string str = ex.StackTrace;
  5748. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5749. // MES_Flag
  5750. stopwatch2.Start();
  5751. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5752. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5753. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5754. writeToPLC_Flag.Adress = 2203;
  5755. writeToPLC_Flag.Value = (short)4;
  5756. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5757. stopwatch2.Stop();
  5758. }
  5759. stopwatch1.Stop();
  5760. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5761. }
  5762. #endregion [S2] FCT(板测)
  5763. #endregion PLC2 李晓奇
  5764. #region PLC3 刘永村
  5765. #region [S3] 值板机
  5766. /// <summary>
  5767. /// S3工位的数据- 触发信号上次的值
  5768. /// </summary>
  5769. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  5770. /// <summary>
  5771. /// S3工位的数据(含触发信号)
  5772. /// </summary>
  5773. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  5774. /// <summary>
  5775. /// S3工位的数据- 回写点位
  5776. /// </summary>
  5777. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5778. /// <summary>
  5779. /// [S3] 值板机
  5780. /// </summary>
  5781. /// <param name="plcNo">PLC编号</param>
  5782. //private void ReadStation_S3(int plcNo)
  5783. //{
  5784. // // [S1] Tray盘上料装备
  5785. // // [S2] FCT
  5786. // // [S3] 值板机
  5787. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5788. // // [S5] Tray盘下料装备
  5789. // /// 上位机心跳
  5790. // /// 获取设备报警数据与状态信息
  5791. // string stationCode = "[S3]";
  5792. // string stationName = "值板机";
  5793. // string stationNameStr = stationCode + stationName;
  5794. // #region 创建字典
  5795. // // 触发信号字典 赋值
  5796. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5797. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5798. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5799. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5800. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5801. // // PLC数据字典 赋值
  5802. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5803. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  5804. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5805. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5806. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  5807. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5808. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5809. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5810. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  5811. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5812. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  5813. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  5814. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5815. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5816. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  5817. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  5818. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  5819. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5820. // s3PLCData.Add("c1Result", 0); // 产品结果
  5821. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5822. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  5823. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  5824. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  5825. // #endregion 创建字典
  5826. // while (IsRun)
  5827. // {
  5828. // try
  5829. // {
  5830. // if (!GlobalContext._IsCon_Funs3)
  5831. // {
  5832. // UpdatePLCMonitor(1, plcNo, 0);
  5833. // continue;
  5834. // }
  5835. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5836. // {
  5837. // Stopwatch stopwatch1 = new Stopwatch();
  5838. // Stopwatch stopwatch2 = new Stopwatch();
  5839. // stopwatch1.Start();
  5840. // stopwatch2.Start();
  5841. // #region 一次性读取所有数据
  5842. // // 一次性读取所有数据
  5843. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  5844. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  5845. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  5846. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  5847. // int[] datas = data1.Concat(data2).ToArray();
  5848. // datas = datas.Concat(data3).ToArray();
  5849. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  5850. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  5851. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5852. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  5853. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  5854. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  5855. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5856. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  5857. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  5858. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  5859. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  5860. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5861. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  5862. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  5863. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  5864. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  5865. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5866. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  5867. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  5868. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  5869. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  5870. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  5871. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  5872. // #endregion 一次性读取所有数据
  5873. // stopwatch2.Stop();
  5874. // #region 回写操作,写后清空flag
  5875. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  5876. // #endregion 回写操作,写后清空flag
  5877. // #region S3进站校验
  5878. // try
  5879. // {
  5880. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  5881. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  5882. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  5883. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  5884. // {
  5885. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  5886. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5887. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  5888. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5889. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  5890. // }
  5891. // }
  5892. // catch (Exception ex)
  5893. // {
  5894. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5895. // string str = ex.StackTrace;
  5896. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5897. // }
  5898. // #endregion S3进站校验
  5899. // #region S3二穴载具解绑
  5900. // try
  5901. // {
  5902. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  5903. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  5904. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  5905. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  5906. // {
  5907. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  5908. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  5909. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  5910. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  5911. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  5912. // }
  5913. // }
  5914. // catch (Exception ex)
  5915. // {
  5916. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  5917. // string str = ex.StackTrace;
  5918. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5919. // }
  5920. // #endregion S3二穴载具解绑
  5921. // #region S3二穴载具绑定
  5922. // try
  5923. // {
  5924. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  5925. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  5926. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  5927. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  5928. // {
  5929. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  5930. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5931. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  5932. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  5933. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  5934. // }
  5935. // }
  5936. // catch (Exception ex)
  5937. // {
  5938. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  5939. // string str = ex.StackTrace;
  5940. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5941. // }
  5942. // #endregion S3二穴载具绑定
  5943. // #region S3出站接口(+一穴载具绑定)
  5944. // try
  5945. // {
  5946. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  5947. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  5948. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  5949. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  5950. // {
  5951. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  5952. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5953. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  5954. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  5955. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  5956. // }
  5957. // }
  5958. // catch (Exception ex)
  5959. // {
  5960. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  5961. // string str = ex.StackTrace;
  5962. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5963. // }
  5964. // #endregion S3出站接口(+一穴载具绑定)
  5965. // #region S3节拍接口
  5966. // try
  5967. // {
  5968. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  5969. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  5970. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  5971. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  5972. // {
  5973. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  5974. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5975. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  5976. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  5977. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  5978. // }
  5979. // }
  5980. // catch (Exception ex)
  5981. // {
  5982. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  5983. // string str = ex.StackTrace;
  5984. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5985. // }
  5986. // #endregion S3节拍接口
  5987. // #region 心跳
  5988. // try
  5989. // {
  5990. // short states = 0;
  5991. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  5992. // }
  5993. // catch (Exception ex)
  5994. // {
  5995. // string str = ex.StackTrace;
  5996. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5997. // }
  5998. // #endregion 心跳
  5999. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6000. // stopwatch1.Stop();
  6001. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  6002. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6003. // }
  6004. // else
  6005. // {
  6006. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6007. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6008. // Funs[plcNo].Connect();
  6009. // }
  6010. // }
  6011. // catch (Exception ex)
  6012. // {
  6013. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6014. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6015. // Funs[plcNo].ReConnect();
  6016. // }
  6017. // Thread.Sleep(IntervalReadPLC);
  6018. // }
  6019. //}
  6020. /// <summary>
  6021. /// [S3] 值板机- 进站校验
  6022. /// </summary>
  6023. /// <param name="plcNo">PLC编号</param>
  6024. /// <param name="stationNameStr">工站全称</param>
  6025. private void S3进站校验(int plcNo, string stationNameStr)
  6026. {
  6027. Stopwatch stopwatch1 = new Stopwatch();
  6028. Stopwatch stopwatch2 = new Stopwatch();
  6029. try
  6030. {
  6031. stopwatch1.Start();
  6032. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  6033. sn = sn.Replace("\0", "");
  6034. #region 查询载具上的产品信息
  6035. string cavityData = string.Empty;
  6036. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6037. if (string.IsNullOrEmpty(cavityData))
  6038. cavityData = "";
  6039. if (snResult != 0)
  6040. {
  6041. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6042. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  6043. writeToPLC_Flag1.Adress = 2003;
  6044. writeToPLC_Flag1.Value = (short)6;
  6045. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  6046. stopwatch1.Stop();
  6047. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6048. return;
  6049. }
  6050. #endregion 查询载具上的产品信息
  6051. string[] cavitySNs = cavityData.Split('.');
  6052. string part1Str = ""; // 产品1的SN码
  6053. string part2Str = ""; // 产品2的SN码
  6054. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  6055. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  6056. if (cavitySNs != null && cavitySNs.Length >= 2)
  6057. {
  6058. part1Str = cavitySNs[0];
  6059. part2Str = cavitySNs[1];
  6060. c1Part1Result_Check = 2;
  6061. c1Part2Result_Check = 2;
  6062. }
  6063. if (part1Str == "假产品")
  6064. c1Part1Result_Check = 3;
  6065. if (part2Str == "假产品")
  6066. c1Part2Result_Check = 3;
  6067. // 调用MES进站
  6068. stopwatch2.Start();
  6069. // 调用MES进站 - 产品1
  6070. List<TestItem> item;
  6071. int result1 = c1Part1Result_Check;
  6072. if (result1 != 3)
  6073. {
  6074. item = new List<TestItem>();
  6075. item.Add(new TestItem()
  6076. {
  6077. Parameter_name = "载具码",
  6078. Parameter_value = sn,
  6079. });
  6080. item.Add(new TestItem()
  6081. {
  6082. Parameter_name = "载具穴号",
  6083. Parameter_value = "1",
  6084. });
  6085. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part1Str, item, out string errorMsg);
  6086. }
  6087. // 调用MES进站 - 产品2
  6088. int result2 = c1Part2Result_Check;
  6089. if (result2 != 3)
  6090. {
  6091. item = new List<TestItem>();
  6092. item.Add(new TestItem()
  6093. {
  6094. Parameter_name = "载具码",
  6095. Parameter_value = sn,
  6096. });
  6097. item.Add(new TestItem()
  6098. {
  6099. Parameter_name = "载具穴号",
  6100. Parameter_value = "2",
  6101. });
  6102. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part2Str, item, out string errorMsg);
  6103. }
  6104. stopwatch2.Stop();
  6105. if (result1 == 2)
  6106. c1Part1Result_Check = 2;
  6107. if (result2 == 2)
  6108. c1Part2Result_Check = 2;
  6109. int result = result1;
  6110. if (result == 1)
  6111. result = result2;
  6112. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  6113. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  6114. short c1MES_FLAG_Check = (short)result;
  6115. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  6116. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  6117. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  6118. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  6119. //// MES_Flag
  6120. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6121. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6122. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6123. writeToPLC_Flag.Adress = 2003;
  6124. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  6125. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6126. {
  6127. Name = "c1Part1Result_Check",
  6128. Adress = 2024,
  6129. ValueType = PLCValueType.Short,
  6130. Value = c1Part1Result_Check
  6131. });
  6132. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6133. {
  6134. Name = "c1Part2Result_Check",
  6135. Adress = 2025,
  6136. ValueType = PLCValueType.Short,
  6137. Value = c1Part2Result_Check
  6138. });
  6139. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6140. {
  6141. Name = "c1Part1Num_Check",
  6142. Adress = 2026,
  6143. ValueType = PLCValueType.Short,
  6144. Value = c1Part1Num_Check
  6145. });
  6146. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6147. {
  6148. Name = "c1Part2Num_Check",
  6149. Adress = 2027,
  6150. ValueType = PLCValueType.Short,
  6151. Value = c1Part2Num_Check
  6152. });
  6153. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6154. }
  6155. catch (Exception ex)
  6156. {
  6157. string str = ex.StackTrace;
  6158. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6159. // MES_Flag
  6160. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6161. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6162. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6163. writeToPLC_Flag.Adress = 2003;
  6164. writeToPLC_Flag.Value = (short)6;
  6165. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6166. }
  6167. stopwatch1.Stop();
  6168. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6169. }
  6170. /// <summary>
  6171. /// [S3] 值板机 - 二穴载具解绑
  6172. /// </summary>
  6173. /// <param name="plcNo">PLC编号</param>
  6174. /// <param name="stationNameStr">工站全称</param>
  6175. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  6176. {
  6177. Stopwatch stopwatch1 = new Stopwatch();
  6178. Stopwatch stopwatch2 = new Stopwatch();
  6179. try
  6180. {
  6181. stopwatch1.Start();
  6182. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6183. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6184. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6185. // 解绑
  6186. #region 查询载具上的产品信息
  6187. string cavityData = string.Empty;
  6188. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6189. if (string.IsNullOrEmpty(cavityData))
  6190. cavityData = "";
  6191. if (snResult != 0)
  6192. {
  6193. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6194. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  6195. writeToPLC_Flag1.Adress = 2082;
  6196. writeToPLC_Flag1.Value = (short)6;
  6197. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  6198. stopwatch1.Stop();
  6199. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6200. return;
  6201. }
  6202. #endregion 查询载具上的产品信息
  6203. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6204. #region 解绑
  6205. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6206. {
  6207. // 删除
  6208. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6209. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  6210. }
  6211. else
  6212. {
  6213. string data_new = string.Join(".", cavitySNs);
  6214. // 删除再插入
  6215. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6216. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6217. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6218. }
  6219. #endregion 解绑
  6220. short c1MES_FLAG_Unbind = 1;
  6221. stopwatch2.Start();
  6222. // MES_Flag
  6223. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6224. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6225. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6226. writeToPLC_Flag.Adress = 2082;
  6227. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  6228. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6229. stopwatch2.Stop();
  6230. }
  6231. catch (Exception ex)
  6232. {
  6233. string str = ex.StackTrace;
  6234. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6235. // MES_Flag
  6236. stopwatch2.Start();
  6237. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  6238. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6239. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6240. writeToPLC_Flag.Adress = 2082;
  6241. writeToPLC_Flag.Value = (short)6;
  6242. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6243. stopwatch2.Stop();
  6244. }
  6245. stopwatch1.Stop();
  6246. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6247. }
  6248. /// <summary>
  6249. /// [S3] 值板机 - 二穴载具绑定
  6250. /// </summary>
  6251. /// <param name="plcNo">PLC编号</param>
  6252. /// <param name="stationNameStr">工站全称</param>
  6253. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  6254. {
  6255. Stopwatch stopwatch1 = new Stopwatch();
  6256. Stopwatch stopwatch2 = new Stopwatch();
  6257. try
  6258. {
  6259. stopwatch1.Start();
  6260. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6261. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6262. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  6263. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  6264. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6265. stopwatch2.Start();
  6266. #region 查询载具上的产品信息
  6267. string cavityData = string.Empty;
  6268. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6269. if (string.IsNullOrEmpty(cavityData))
  6270. cavityData = "";
  6271. if (snResult != 0)
  6272. {
  6273. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6274. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  6275. writeToPLC_Flag1.Adress = 2115;
  6276. writeToPLC_Flag1.Value = (short)6;
  6277. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  6278. stopwatch1.Stop();
  6279. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6280. return;
  6281. }
  6282. #endregion 查询载具上的产品信息
  6283. // 产品换载具
  6284. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6285. string partSn1 = "";
  6286. string partSn2 = "";
  6287. if (cavitySNs != null && cavitySNs.Length >= 2)
  6288. {
  6289. partSn1 = cavitySNs[0];
  6290. partSn2 = cavitySNs[1];
  6291. }
  6292. string data_new = string.Empty;
  6293. // 是否是两个穴位交换
  6294. if (c1CavityReverse_Bind == 1)
  6295. {
  6296. // 交换
  6297. data_new = string.Concat(partSn2, ".", partSn1);
  6298. }
  6299. else
  6300. { // 不交换
  6301. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  6302. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  6303. cavitySNs[c1VehicleCavityFr_Bind] = "";
  6304. data_new = string.Join(".", cavitySNs);
  6305. }
  6306. // 删除再插入
  6307. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6308. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6309. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  6310. stopwatch2.Stop();
  6311. short c1MES_FLAG_Bind = 1;
  6312. // MES_Flag
  6313. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6314. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6315. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6316. writeToPLC_Flag.Adress = 2115;
  6317. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  6318. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6319. }
  6320. catch (Exception ex)
  6321. {
  6322. string str = ex.StackTrace;
  6323. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6324. // MES_Flag
  6325. stopwatch2.Start();
  6326. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6327. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6328. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6329. writeToPLC_Flag.Adress = 2115;
  6330. writeToPLC_Flag.Value = (short)6;
  6331. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6332. stopwatch2.Stop();
  6333. }
  6334. stopwatch1.Stop();
  6335. AddMessage(LogType.Info, stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6336. }
  6337. //// 上次采集到的SN
  6338. //private string sn_值板机 = string.Empty;
  6339. /// <summary>
  6340. /// [S3] 值板机 - 出站接口
  6341. /// </summary>
  6342. /// <param name="plcNo">PLC编号</param>
  6343. private void S3出站接口(int plcNo, string stationCode, string stationName)
  6344. {
  6345. Stopwatch stopwatch1 = new Stopwatch();
  6346. Stopwatch stopwatch2 = new Stopwatch();
  6347. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6348. string stationNameStr = stationCode + stationName;
  6349. string processItem = stationName; // 测试项目
  6350. try
  6351. {
  6352. stopwatch1.Start();
  6353. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6354. //string batch_num = GlobalContext.BatchNumber; // 批次号
  6355. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6356. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6357. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  6358. sn = sn.Replace("\0", "");
  6359. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  6360. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6361. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6362. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  6363. bool pass = c1Result == 1;
  6364. // 查sn
  6365. #region 查询载具上的产品信息
  6366. string cavityData = string.Empty;
  6367. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6368. if (string.IsNullOrEmpty(cavityData))
  6369. cavityData = "";
  6370. if (snResult != 0)
  6371. {
  6372. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6373. writeToPLC_Flag1.Name = "c1MES_FLAG";
  6374. writeToPLC_Flag1.Adress = 2150;
  6375. writeToPLC_Flag1.Value = (short)4;
  6376. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  6377. stopwatch1.Stop();
  6378. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6379. return;
  6380. }
  6381. #endregion 查询载具上的产品信息
  6382. string[] cavitySNs = cavityData.Split('.');
  6383. string productSN = "";
  6384. if (cavitySNs != null && cavitySNs.Length >= 2)
  6385. {
  6386. productSN = cavitySNs[c1VehicleCavity];
  6387. cavitySNs[c1VehicleCavity] = "";
  6388. }
  6389. stopwatch2.Start();
  6390. List<TestItem> items = new List<TestItem>();
  6391. items.Add(new TestItem()
  6392. {
  6393. Parameter_name = "二穴载具码",
  6394. Parameter_value = c1ProductSN_Check,
  6395. Parameter_unit = ""
  6396. });
  6397. items.Add(new TestItem()
  6398. {
  6399. Parameter_name = "二穴载具穴号",
  6400. Parameter_value = c1VehicleCavity.ToString(),
  6401. Parameter_unit = ""
  6402. });
  6403. items.Add(new TestItem()
  6404. {
  6405. Parameter_name = "一穴载具码",
  6406. Parameter_value = sn,
  6407. Parameter_unit = ""
  6408. });
  6409. items.Add(new TestItem()
  6410. {
  6411. Parameter_name = "一穴载具穴号",
  6412. Parameter_value = "1",
  6413. Parameter_unit = ""
  6414. });
  6415. items.Add(new TestItem()
  6416. {
  6417. Parameter_name = "产品结果",
  6418. Parameter_value = c1Result == 1 ? "OK" : "NG",
  6419. Parameter_unit = ""
  6420. });
  6421. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6422. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  6423. short result = (short)result1;
  6424. stopwatch2.Stop();
  6425. #region 存储绑定数据到 边线MES系统中
  6426. if (result == 1)
  6427. {
  6428. string data = string.Concat(productSN);
  6429. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  6430. if (resultMesR != 0)
  6431. {
  6432. result = 4;
  6433. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  6434. }
  6435. }
  6436. #endregion 存储绑定数据到 边线MES系统中
  6437. #region 产品从 来源载具(二穴载具)中删除
  6438. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6439. {
  6440. // 删除
  6441. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6442. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  6443. }
  6444. else
  6445. {
  6446. string data_new = string.Join(".", cavitySNs);
  6447. // 删除再插入
  6448. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6449. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6450. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6451. }
  6452. #endregion 产品从 来源载具(二穴载具)中删除
  6453. // MES_Flag 为MES报错
  6454. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6455. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  6456. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6457. writeToPLC_Flag.Name = "c1MES_FLAG";
  6458. writeToPLC_Flag.Adress = 2150;
  6459. writeToPLC_Flag.Value = result;
  6460. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6461. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  6462. }
  6463. catch (Exception ex)
  6464. {
  6465. stopwatch2.Restart();
  6466. // MES_Flag 为4上位机报错
  6467. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  6468. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6469. writeToPLC_Flag.Name = "c1MES_FLAG";
  6470. writeToPLC_Flag.Adress = 2150;
  6471. writeToPLC_Flag.Value = (short)4;
  6472. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6473. stopwatch2.Stop();
  6474. string str = ex.StackTrace;
  6475. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6476. }
  6477. stopwatch1.Stop();
  6478. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6479. }
  6480. /// <summary>
  6481. /// [S3] 值板机- 节拍接口
  6482. /// </summary>
  6483. /// <param name="plcNo">PLC编号</param>
  6484. /// <param name="stationNameStr">工站全称</param>
  6485. private void S3节拍接口(int plcNo, string stationNameStr)
  6486. {
  6487. Stopwatch stopwatch1 = new Stopwatch();
  6488. Stopwatch stopwatch2 = new Stopwatch();
  6489. string resultStr = string.Empty;
  6490. try
  6491. {
  6492. stopwatch1.Start();
  6493. string oEEType = ((int)s3PLCData["c1OEEType"]).ToString(); // 节拍类型(plc写入)
  6494. string c1OEEProductSN = (string)s3PLCData["c1OEEProductSN"]; // 载具SN
  6495. c1OEEProductSN = c1OEEProductSN.Replace("\0", "");
  6496. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6497. if (!actionBool)
  6498. {
  6499. stopwatch2.Start();
  6500. // MES_Flag
  6501. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6502. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6503. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6504. writeToPLC_Flag1.Adress = 2204;
  6505. writeToPLC_Flag1.Value = (short)4;
  6506. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6507. stopwatch2.Stop();
  6508. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6509. return;
  6510. }
  6511. string c1OEEPartNo = string.Empty; // 物料码
  6512. if (string.IsNullOrEmpty(c1OEEProductSN))
  6513. {
  6514. stopwatch2.Start();
  6515. // MES_Flag
  6516. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6517. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6518. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6519. writeToPLC_Flag1.Adress = 2204;
  6520. writeToPLC_Flag1.Value = (short)1;
  6521. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6522. stopwatch2.Stop();
  6523. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6524. return;
  6525. }
  6526. else
  6527. { // 查产品SN
  6528. c1OEEPartNo = "Test"; // ZS
  6529. }
  6530. short c1OEEMES_FLAG = 0;
  6531. // 上传OEE
  6532. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, c1OEEPartNo, c1OEEProductSN);
  6533. c1OEEMES_FLAG = result.Item1;
  6534. resultStr = result.Item2;
  6535. stopwatch2.Start();
  6536. // MES_Flag
  6537. //Funs[plcNo].WriteMultipleRegisters<short>(2204, c1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6538. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6539. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6540. writeToPLC_Flag.Adress = 2204;
  6541. writeToPLC_Flag.Value = c1OEEMES_FLAG;
  6542. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6543. stopwatch2.Stop();
  6544. }
  6545. catch (Exception ex)
  6546. {
  6547. string str = ex.StackTrace;
  6548. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6549. // MES_Flag
  6550. stopwatch2.Start();
  6551. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6552. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6553. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6554. writeToPLC_Flag.Adress = 2204;
  6555. writeToPLC_Flag.Value = (short)4;
  6556. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6557. stopwatch2.Stop();
  6558. }
  6559. stopwatch1.Stop();
  6560. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6561. }
  6562. #endregion [S3] 值板机
  6563. #endregion PLC3 刘永村
  6564. #region PLC4 刘果段
  6565. #region [S4] 取放桁架
  6566. /// <summary>
  6567. /// S4工位的数据- 触发信号上次的值
  6568. /// </summary>
  6569. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  6570. /// <summary>
  6571. /// S4工位的数据(含触发信号)
  6572. /// </summary>
  6573. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  6574. /// <summary>
  6575. /// S4工位的数据- 回写点位
  6576. /// </summary>
  6577. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6578. /// <summary>
  6579. /// [S4] 取放桁架
  6580. /// </summary>
  6581. /// <param name="plcNo">PLC编号</param>
  6582. //private void ReadStation_S4(int plcNo)
  6583. //{
  6584. // // [S1] Tray盘上料装备
  6585. // // [S2] FCT
  6586. // // [S3] 值板机
  6587. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6588. // // [S5] Tray盘下料装备
  6589. // /// 上位机心跳
  6590. // /// 获取设备报警数据与状态信息
  6591. // string stationCode = "[S4_1]";
  6592. // string stationName = "载具下线装备";
  6593. // string stationNameStr = stationCode + stationName;
  6594. // string stationCode2 = "[S4_2]";
  6595. // string stationName2 = "桁架";
  6596. // string stationNameStr2 = stationCode2 + stationName2;
  6597. // string stationCode3 = "[S4_3]";
  6598. // string stationName3 = "提升机1";
  6599. // string stationNameStr3 = stationCode3 + stationName3;
  6600. // string stationCode4 = "[S4_4]";
  6601. // string stationName4 = "提升机2";
  6602. // string stationNameStr4 = stationCode4 + stationName4;
  6603. // string stationCode5 = "[S4_5]";
  6604. // string stationName5 = "载具上线装备";
  6605. // string stationNameStr5 = stationCode5 + stationName5;
  6606. // #region 创建字典
  6607. // // 触发信号字典 赋值
  6608. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6609. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6610. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6611. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6612. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6613. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6614. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6615. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6616. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6617. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6618. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6619. // // PLC数据字典 赋值
  6620. // // 载具下线装备(弹夹上线)
  6621. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6622. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  6623. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6624. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  6625. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6626. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  6627. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  6628. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6629. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6630. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6631. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6632. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6633. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6634. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6635. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6636. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6637. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6638. // s4PLCData.Add("d1Result", 0); // 产品结果
  6639. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6640. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  6641. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  6642. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  6643. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6644. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  6645. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  6646. // // 真空标机(提升机)
  6647. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6648. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  6649. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  6650. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  6651. // s4PLCData.Add("d3Result", 0); // 产品结果
  6652. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6653. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  6654. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  6655. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  6656. // s4PLCData.Add("d4Result", 0); // 产品结果
  6657. // // 载具上线装备(弹夹下线)
  6658. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6659. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  6660. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6661. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  6662. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6663. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  6664. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  6665. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6666. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6667. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6668. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6669. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6670. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6671. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6672. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6673. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6674. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6675. // s4PLCData.Add("d5Result", 0); // 产品结果
  6676. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6677. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  6678. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  6679. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  6680. // #endregion 创建字典
  6681. // while (IsRun)
  6682. // {
  6683. // try
  6684. // {
  6685. // if (!GlobalContext._IsCon_Funs4)
  6686. // {
  6687. // UpdatePLCMonitor(1, plcNo, 0);
  6688. // continue;
  6689. // }
  6690. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6691. // {
  6692. // Stopwatch stopwatch1 = new Stopwatch();
  6693. // Stopwatch stopwatch2 = new Stopwatch();
  6694. // stopwatch1.Start();
  6695. // stopwatch2.Start();
  6696. // #region 一次性读取所有数据
  6697. // // 载具下线装备(弹夹上线)
  6698. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6699. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6700. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6701. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  6702. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  6703. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  6704. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  6705. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  6706. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  6707. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  6708. // int[] datas = data1.Concat(data2).ToArray();
  6709. // datas = datas.Concat(data3).ToArray();
  6710. // datas = datas.Concat(data4).ToArray();
  6711. // datas = datas.Concat(data5).ToArray();
  6712. // datas = datas.Concat(data6).ToArray();
  6713. // datas = datas.Concat(data7).ToArray();
  6714. // datas = datas.Concat(data8).ToArray();
  6715. // datas = datas.Concat(data9).ToArray();
  6716. // datas = datas.Concat(data10).ToArray();
  6717. // // 载具下线装备(弹夹上线)
  6718. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  6719. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  6720. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  6721. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  6722. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  6723. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  6724. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  6725. // s4PLCData["d1MES_FLAG"] = datas[65];
  6726. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  6727. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  6728. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  6729. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  6730. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  6731. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  6732. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  6733. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  6734. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  6735. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  6736. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  6737. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  6738. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  6739. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  6740. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  6741. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  6742. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  6743. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  6744. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  6745. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  6746. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  6747. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  6748. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  6749. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  6750. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  6751. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  6752. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  6753. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  6754. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  6755. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  6756. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  6757. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  6758. // s4PLCData["d1Result"] = datas[386];
  6759. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  6760. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  6761. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  6762. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  6763. // s4PLCData["d1OEEType"] = datas[419];
  6764. // // 桁架(查询标机中弹夹的状态)
  6765. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  6766. // s4PLCData["d2BulletclipStates"] = datas[431];
  6767. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  6768. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  6769. // // 真空标机
  6770. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  6771. // s4PLCData["d3MES_FLAG"] = datas[463];
  6772. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  6773. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  6774. // s4PLCData["d3Result"] = datas[484];
  6775. // s4PLCData["d3Type"] = datas[485];
  6776. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  6777. // s4PLCData["d4MES_FLAG"] = datas[496];
  6778. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  6779. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  6780. // s4PLCData["d4Result"] = datas[517];
  6781. // s4PLCData["d4Type"] = datas[518];
  6782. // // 载具上线装备(弹夹下线)
  6783. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  6784. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  6785. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  6786. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  6787. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  6788. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  6789. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  6790. // s4PLCData["d5MES_FLAG"] = datas[591];
  6791. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  6792. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  6793. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  6794. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  6795. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  6796. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  6797. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  6798. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  6799. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  6800. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  6801. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  6802. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  6803. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  6804. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  6805. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  6806. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  6807. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  6808. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  6809. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  6810. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  6811. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  6812. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  6813. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  6814. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  6815. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  6816. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  6817. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  6818. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  6819. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  6820. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  6821. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  6822. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  6823. // s4PLCData["d5Result"] = datas[912];
  6824. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  6825. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  6826. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  6827. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  6828. // s4PLCData["d5OEEType"] = datas[945];
  6829. // #endregion 一次性读取所有数据
  6830. // stopwatch2.Stop();
  6831. // #region 回写操作,写后清空flag
  6832. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  6833. // #endregion 回写操作,写后清空flag
  6834. // // N801A-S4_1 弹夹扫码
  6835. // #region N801A-S4_1 弹夹扫码
  6836. // try
  6837. // {
  6838. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  6839. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  6840. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  6841. // {
  6842. // if (d1BulletclipScanCode == 1) // 0->1
  6843. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6844. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  6845. // }
  6846. // }
  6847. // catch (Exception ex)
  6848. // {
  6849. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  6850. // string str = ex.StackTrace;
  6851. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6852. // }
  6853. // #endregion N801A-S4_1 弹夹扫码
  6854. // // N801A-S4_1 载具扫码
  6855. // #region N801A-S4_1 载具扫码
  6856. // try
  6857. // {
  6858. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  6859. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  6860. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  6861. // {
  6862. // if (d1VehicleScanCode == 1) // 0->1
  6863. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6864. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  6865. // }
  6866. // }
  6867. // catch (Exception ex)
  6868. // {
  6869. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  6870. // string str = ex.StackTrace;
  6871. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6872. // }
  6873. // #endregion N801A-S4_1 载具扫码
  6874. // // N801A-S4_1 出站接口
  6875. // #region N801A-S4_1 出站接口
  6876. // try
  6877. // {
  6878. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  6879. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  6880. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  6881. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  6882. // {
  6883. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  6884. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6885. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  6886. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  6887. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  6888. // }
  6889. // }
  6890. // catch (Exception ex)
  6891. // {
  6892. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  6893. // string str = ex.StackTrace;
  6894. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6895. // }
  6896. // #endregion N801A-S4_1 出站接口
  6897. // // N801A-S4_1 节拍接口
  6898. // #region N801A-S4_1 节拍接口
  6899. // try
  6900. // {
  6901. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  6902. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  6903. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  6904. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  6905. // {
  6906. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  6907. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6908. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  6909. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  6910. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  6911. // }
  6912. // }
  6913. // catch (Exception ex)
  6914. // {
  6915. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  6916. // string str = ex.StackTrace;
  6917. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6918. // }
  6919. // #endregion N801A-S4_1 节拍接口
  6920. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  6921. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  6922. // try
  6923. // {
  6924. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  6925. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  6926. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  6927. // {
  6928. // if (d2BulletclipScanCode == 1) // 0->1
  6929. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  6930. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  6931. // }
  6932. // }
  6933. // catch (Exception ex)
  6934. // {
  6935. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  6936. // string str = ex.StackTrace;
  6937. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6938. // }
  6939. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  6940. // // N801A-S4_3 真空标机1 数据
  6941. // #region N801A-S4_3 真空标机1
  6942. // try
  6943. // {
  6944. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  6945. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  6946. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  6947. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  6948. // {
  6949. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  6950. // {
  6951. // int stationType = (int)s4PLCData["d3Type"];
  6952. // if (stationType == 1)
  6953. // {
  6954. // // S4_3进站接口
  6955. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  6956. // }
  6957. // else if (stationType == 2)
  6958. // {
  6959. // // S4_3出站接口
  6960. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  6961. // }
  6962. // }
  6963. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  6964. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  6965. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  6966. // }
  6967. // }
  6968. // catch (Exception ex)
  6969. // {
  6970. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  6971. // string str = ex.StackTrace;
  6972. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6973. // }
  6974. // #endregion N801A-S4_3 真空标机1
  6975. // // N801A-S4_4 真空标机2 数据
  6976. // #region N801A-S4_4 真空标机2
  6977. // try
  6978. // {
  6979. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  6980. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  6981. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  6982. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  6983. // {
  6984. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  6985. // {
  6986. // int stationType = (int)s4PLCData["d4Type"];
  6987. // if (stationType == 1)
  6988. // {
  6989. // // S4_4进站接口
  6990. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  6991. // }
  6992. // else if (stationType == 2)
  6993. // {
  6994. // // S4_4出站接口
  6995. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  6996. // }
  6997. // }
  6998. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  6999. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  7000. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  7001. // }
  7002. // }
  7003. // catch (Exception ex)
  7004. // {
  7005. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  7006. // string str = ex.StackTrace;
  7007. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7008. // }
  7009. // #endregion N801A-S4_4 真空标机2
  7010. // // N801A-S4_5 弹夹扫码 数据
  7011. // #region N801A-S4_5 弹夹扫码
  7012. // try
  7013. // {
  7014. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  7015. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  7016. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  7017. // {
  7018. // if (d5BulletclipScanCode == 1) // 0->1
  7019. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7020. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  7021. // }
  7022. // }
  7023. // catch (Exception ex)
  7024. // {
  7025. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  7026. // string str = ex.StackTrace;
  7027. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7028. // }
  7029. // #endregion N801A-S4_5 弹夹扫码
  7030. // // N801A-S4_5 载具扫码 数据
  7031. // #region N801A-S4_5 载具扫码
  7032. // try
  7033. // {
  7034. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  7035. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  7036. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  7037. // {
  7038. // if (d5VehicleScanCode == 1) // 0->1
  7039. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7040. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  7041. // }
  7042. // }
  7043. // catch (Exception ex)
  7044. // {
  7045. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  7046. // string str = ex.StackTrace;
  7047. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7048. // }
  7049. // #endregion N801A-S4_5 载具扫码
  7050. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  7051. // #region N801A-S4_5 出站接口
  7052. // try
  7053. // {
  7054. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  7055. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  7056. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  7057. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  7058. // {
  7059. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  7060. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  7061. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  7062. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  7063. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  7064. // }
  7065. // }
  7066. // catch (Exception ex)
  7067. // {
  7068. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  7069. // string str = ex.StackTrace;
  7070. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7071. // }
  7072. // #endregion N801A-S4_5 出站接口
  7073. // // N801A-S4_5 节拍接口 数据
  7074. // #region N801A-S4_5 节拍接口
  7075. // try
  7076. // {
  7077. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  7078. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  7079. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  7080. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  7081. // {
  7082. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  7083. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  7084. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  7085. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  7086. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  7087. // }
  7088. // }
  7089. // catch (Exception ex)
  7090. // {
  7091. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  7092. // string str = ex.StackTrace;
  7093. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7094. // }
  7095. // #endregion N801A-S4_5 节拍接口
  7096. // #region 心跳
  7097. // try
  7098. // {
  7099. // short states = 0;
  7100. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7101. // }
  7102. // catch (Exception ex)
  7103. // {
  7104. // string str = ex.StackTrace;
  7105. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7106. // }
  7107. // #endregion 心跳
  7108. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7109. // stopwatch1.Stop();
  7110. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7111. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7112. // }
  7113. // else
  7114. // {
  7115. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7116. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  7117. // Funs[plcNo].Connect();
  7118. // }
  7119. // }
  7120. // catch (Exception ex)
  7121. // {
  7122. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7123. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  7124. // Funs[plcNo].ReConnect();
  7125. // }
  7126. // Thread.Sleep(IntervalReadPLC);
  7127. // }
  7128. //}
  7129. /// <summary>
  7130. /// [S4] 取放桁架 - S4_1弹夹扫码
  7131. /// </summary>
  7132. /// <param name="plcNo">PLC编号</param>
  7133. /// <param name="stationNameStr">工站全称</param>
  7134. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  7135. {
  7136. Stopwatch stopwatch1 = new Stopwatch();
  7137. Stopwatch stopwatch2 = new Stopwatch();
  7138. try
  7139. {
  7140. stopwatch1.Start();
  7141. // ZS 弹夹扫码
  7142. string d1BulletclipCode = " "; // 扫到的码
  7143. short d1BulletclipScanCode = 2;
  7144. stopwatch2.Start();
  7145. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  7146. //// MES_Flag
  7147. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7148. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7149. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7150. writeToPLC_Flag.Adress = 2002;
  7151. writeToPLC_Flag.Value = d1BulletclipScanCode;
  7152. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7153. {
  7154. Name = "d1BulletclipCode",
  7155. Adress = 2003,
  7156. ValueType = PLCValueType.String,
  7157. ValueTypeStrLength = 20,
  7158. Value = d1BulletclipCode
  7159. });
  7160. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7161. stopwatch2.Stop();
  7162. }
  7163. catch (Exception ex)
  7164. {
  7165. string str = ex.StackTrace;
  7166. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7167. stopwatch2.Start();
  7168. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  7169. //// MES_Flag
  7170. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  7171. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7172. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7173. writeToPLC_Flag.Adress = 2002;
  7174. writeToPLC_Flag.Value = (short)6;
  7175. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7176. {
  7177. Name = "d1BulletclipCode",
  7178. Adress = 2003,
  7179. ValueType = PLCValueType.String,
  7180. ValueTypeStrLength = 20,
  7181. Value = " "
  7182. });
  7183. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7184. stopwatch2.Stop();
  7185. }
  7186. stopwatch1.Stop();
  7187. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7188. }
  7189. /// <summary>
  7190. /// [S4] 取放桁架 - S4_1载具扫码
  7191. /// </summary>
  7192. /// <param name="plcNo">PLC编号</param>
  7193. /// <param name="stationNameStr">工站全称</param>
  7194. private void S4_1载具扫码(int plcNo, string stationNameStr)
  7195. {
  7196. Stopwatch stopwatch1 = new Stopwatch();
  7197. Stopwatch stopwatch2 = new Stopwatch();
  7198. try
  7199. {
  7200. stopwatch1.Start();
  7201. // ZS 载具扫码
  7202. string d1VehicleCode = ""; // 扫到的码
  7203. short d1VehicleScanCode = 2;
  7204. #region 进站
  7205. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  7206. {
  7207. #region 查询载具上的产品信息
  7208. string cavityData = string.Empty;
  7209. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  7210. if (string.IsNullOrEmpty(cavityData))
  7211. cavityData = "";
  7212. if (snResult != 0)
  7213. {
  7214. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7215. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  7216. writeToPLC_Flag1.Adress = 2033;
  7217. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  7218. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7219. {
  7220. Name = "d1VehicleCode",
  7221. Adress = 2034,
  7222. ValueType = PLCValueType.String,
  7223. ValueTypeStrLength = 20,
  7224. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7225. });
  7226. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  7227. stopwatch1.Stop();
  7228. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7229. return;
  7230. }
  7231. string[] cavitySNs = cavityData.Split('.');
  7232. string partNo = "";
  7233. if (cavitySNs != null && cavitySNs.Length >= 1)
  7234. {
  7235. partNo = cavitySNs[0];
  7236. }
  7237. #endregion 查询载具上的产品信息
  7238. List<TestItem> item = new List<TestItem>();
  7239. item.Add(new TestItem()
  7240. {
  7241. Parameter_name = "载具码",
  7242. Parameter_value = d1VehicleCode,
  7243. });
  7244. item.Add(new TestItem()
  7245. {
  7246. Parameter_name = "载具穴号",
  7247. Parameter_value = "1",
  7248. });
  7249. stopwatch2.Start();
  7250. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  7251. stopwatch2.Stop();
  7252. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  7253. }
  7254. #endregion 进站
  7255. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  7256. //// MES_Flag
  7257. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7258. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7259. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7260. writeToPLC_Flag.Adress = 2033;
  7261. writeToPLC_Flag.Value = d1VehicleScanCode;
  7262. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7263. {
  7264. Name = "d1VehicleCode",
  7265. Adress = 2034,
  7266. ValueType = PLCValueType.String,
  7267. ValueTypeStrLength = 20,
  7268. Value = d1VehicleCode
  7269. });
  7270. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7271. }
  7272. catch (Exception ex)
  7273. {
  7274. string str = ex.StackTrace;
  7275. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7276. stopwatch2.Start();
  7277. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  7278. //// MES_Flag
  7279. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  7280. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7281. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7282. writeToPLC_Flag.Adress = 2033;
  7283. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  7284. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7285. {
  7286. Name = "d1VehicleCode",
  7287. Adress = 2034,
  7288. ValueType = PLCValueType.String,
  7289. ValueTypeStrLength = 20,
  7290. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7291. });
  7292. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7293. stopwatch2.Stop();
  7294. }
  7295. stopwatch1.Stop();
  7296. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7297. }
  7298. // 上次采集到的SN
  7299. //private string sn_S4_1出站接口 = string.Empty;
  7300. /// <summary>
  7301. /// [S4] 取放桁架 - S4_1出站接口
  7302. /// </summary>
  7303. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  7304. {
  7305. Stopwatch stopwatch1 = new Stopwatch();
  7306. Stopwatch stopwatch2 = new Stopwatch();
  7307. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7308. string stationNameStr = stationCode + stationName;
  7309. string processItem = stationName; // 测试项目
  7310. try
  7311. {
  7312. stopwatch1.Start();
  7313. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7314. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7315. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7316. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7317. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  7318. sn = sn.Replace("\0", "");
  7319. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  7320. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  7321. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  7322. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  7323. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  7324. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  7325. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  7326. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  7327. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  7328. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  7329. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  7330. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  7331. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  7332. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  7333. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  7334. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  7335. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  7336. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  7337. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  7338. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  7339. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  7340. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  7341. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  7342. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  7343. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  7344. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  7345. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  7346. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  7347. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  7348. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  7349. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  7350. bool pass = d1Result == 1;
  7351. // 存 载具SN列表
  7352. List<string> vehicleCodes = new List<string>()
  7353. {
  7354. d1VehicleCode1,d1VehicleCode2,d1VehicleCode3,d1VehicleCode4,d1VehicleCode5,
  7355. d1VehicleCode6,d1VehicleCode7,d1VehicleCode8,d1VehicleCode9,d1VehicleCode10,
  7356. d1VehicleCode11,d1VehicleCode12,d1VehicleCode13,d1VehicleCode14,d1VehicleCode15
  7357. };
  7358. // 统一查 产品SN列表
  7359. List<string> partNos = new List<string>();
  7360. foreach (string vehicleCode in vehicleCodes)
  7361. {
  7362. if (string.IsNullOrEmpty(vehicleCode))
  7363. partNos.Add("");
  7364. else
  7365. {
  7366. string partNo = "";
  7367. #region 查询载具上的产品信息
  7368. string cavityData = string.Empty;
  7369. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7370. if (string.IsNullOrEmpty(cavityData))
  7371. cavityData = "";
  7372. if (snResult != 0)
  7373. {
  7374. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7375. writeToPLC_Flag1.Name = "d1MES_FLAG";
  7376. writeToPLC_Flag1.Adress = 2065;
  7377. writeToPLC_Flag1.Value = (short)4;
  7378. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  7379. stopwatch1.Stop();
  7380. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7381. return;
  7382. }
  7383. string[] cavitySNs = cavityData.Split('.');
  7384. if (cavitySNs != null && cavitySNs.Length >= 1)
  7385. partNo = cavitySNs[0];
  7386. #endregion 查询载具上的产品信息
  7387. partNos.Add(partNo);
  7388. }
  7389. }
  7390. // 统一上传
  7391. stopwatch2.Start();
  7392. List<int> results = new List<int>();
  7393. for (int i = 0; i < partNos.Count; i++)
  7394. {
  7395. string index = (i + 1).ToString(); // 弹夹穴号
  7396. if (string.IsNullOrEmpty(partNos[i]))
  7397. results.Add(1);
  7398. else
  7399. {
  7400. List<TestItem> items1 = new List<TestItem>();
  7401. items1.Add(new TestItem()
  7402. {
  7403. Parameter_name = "弹夹码",
  7404. Parameter_value = sn,
  7405. Parameter_unit = ""
  7406. });
  7407. items1.Add(new TestItem()
  7408. {
  7409. Parameter_name = "弹夹穴号",
  7410. Parameter_value = index,
  7411. Parameter_unit = ""
  7412. });
  7413. items1.Add(new TestItem()
  7414. {
  7415. Parameter_name = "载具码",
  7416. Parameter_value = vehicleCodes[i],
  7417. Parameter_unit = ""
  7418. });
  7419. items1.Add(new TestItem()
  7420. {
  7421. Parameter_name = "载具穴号",
  7422. Parameter_value = "1",
  7423. Parameter_unit = ""
  7424. });
  7425. items1.Add(new TestItem()
  7426. {
  7427. Parameter_name = "产品结果",
  7428. Parameter_value = d1Result == 1 ? "OK" : "NG",
  7429. Parameter_unit = ""
  7430. });
  7431. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7432. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  7433. results.Add(result1);
  7434. }
  7435. }
  7436. short result = 0;
  7437. if (results.All(a => a == 1))
  7438. result = 1;
  7439. else if (results.Contains(3))
  7440. result = 3;
  7441. else if (results.Contains(2))
  7442. result = 2;
  7443. else if (results.Contains(4))
  7444. result = 4;
  7445. else
  7446. result = 4;
  7447. stopwatch2.Stop();
  7448. #region 存储绑定数据到 边线MES系统中
  7449. if (result == 1)
  7450. {
  7451. string data = string.Join(".", vehicleCodes);
  7452. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7453. if (resultMesR != 0)
  7454. {
  7455. result = 4;
  7456. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  7457. }
  7458. }
  7459. #endregion 存储绑定数据到 边线MES系统中
  7460. // MES_Flag 为4MES报错
  7461. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7462. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7463. writeToPLC_Flag.Name = "d1MES_FLAG";
  7464. writeToPLC_Flag.Adress = 2065;
  7465. writeToPLC_Flag.Value = result;
  7466. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7467. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7468. }
  7469. catch (Exception ex)
  7470. {
  7471. stopwatch2.Restart();
  7472. // MES_Flag 为4上位机报错
  7473. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  7474. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7475. writeToPLC_Flag.Name = "d1MES_FLAG";
  7476. writeToPLC_Flag.Adress = 2065;
  7477. writeToPLC_Flag.Value = (short)4;
  7478. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7479. stopwatch2.Stop();
  7480. string str = ex.StackTrace;
  7481. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7482. }
  7483. stopwatch1.Stop();
  7484. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7485. }
  7486. /// <summary>
  7487. /// [S4] 取放桁架 - S4_1节拍接口
  7488. /// </summary>
  7489. /// <param name="plcNo">PLC编号</param>
  7490. /// <param name="stationNameStr">工站全称</param>
  7491. private void S4_1节拍接口(int plcNo, string stationNameStr)
  7492. {
  7493. Stopwatch stopwatch1 = new Stopwatch();
  7494. Stopwatch stopwatch2 = new Stopwatch();
  7495. string resultStr = string.Empty;
  7496. try
  7497. {
  7498. stopwatch1.Start();
  7499. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  7500. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  7501. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  7502. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7503. if (!actionBool)
  7504. {
  7505. stopwatch2.Start();
  7506. // MES_Flag
  7507. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7508. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7509. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7510. writeToPLC_Flag1.Adress = 2398;
  7511. writeToPLC_Flag1.Value = (short)4;
  7512. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7513. stopwatch2.Stop();
  7514. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7515. return;
  7516. }
  7517. string d1OEEPartNo = string.Empty; // 物料码
  7518. if (string.IsNullOrEmpty(d1OEEProductSN))
  7519. {
  7520. stopwatch2.Start();
  7521. // MES_Flag
  7522. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7523. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7524. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7525. writeToPLC_Flag1.Adress = 2398;
  7526. writeToPLC_Flag1.Value = (short)1;
  7527. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7528. stopwatch2.Stop();
  7529. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7530. return;
  7531. }
  7532. else
  7533. { // 查产品SN ZS
  7534. d1OEEPartNo = "Test";
  7535. }
  7536. short d1OEEMES_FLAG = 0;
  7537. // 上传OEE
  7538. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  7539. d1OEEMES_FLAG = result.Item1;
  7540. resultStr = result.Item2;
  7541. stopwatch2.Start();
  7542. // MES_Flag
  7543. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7544. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7545. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7546. writeToPLC_Flag.Adress = 2398;
  7547. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  7548. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7549. stopwatch2.Stop();
  7550. }
  7551. catch (Exception ex)
  7552. {
  7553. string str = ex.StackTrace;
  7554. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7555. // MES_Flag
  7556. stopwatch2.Start();
  7557. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7558. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7559. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7560. writeToPLC_Flag.Adress = 2398;
  7561. writeToPLC_Flag.Value = (short)4;
  7562. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7563. stopwatch2.Stop();
  7564. }
  7565. stopwatch1.Stop();
  7566. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7567. }
  7568. /// <summary>
  7569. /// [S4] 取放桁架 - S4_2桁架
  7570. /// </summary>
  7571. /// <param name="plcNo">PLC编号</param>
  7572. /// <param name="stationNameStr">工站全称</param>
  7573. private void S4_2桁架(int plcNo, string stationNameStr)
  7574. {
  7575. Stopwatch stopwatch1 = new Stopwatch();
  7576. Stopwatch stopwatch2 = new Stopwatch();
  7577. try
  7578. {
  7579. stopwatch1.Start();
  7580. // ZS 弹夹扫码
  7581. string d2BulletclipCode = " "; // 扫到的码
  7582. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  7583. short d2BulletclipScanCode = 2;
  7584. stopwatch2.Start();
  7585. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  7586. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  7587. //// MES_Flag
  7588. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7589. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7590. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7591. writeToPLC_Flag.Adress = 2430;
  7592. writeToPLC_Flag.Value = d2BulletclipScanCode;
  7593. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7594. {
  7595. Name = "d2BulletclipCode",
  7596. Adress = 2432,
  7597. ValueType = PLCValueType.String,
  7598. ValueTypeStrLength = 20,
  7599. Value = d2BulletclipCode
  7600. });
  7601. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7602. {
  7603. Name = "d2BulletclipStates",
  7604. Adress = 2431,
  7605. ValueType = PLCValueType.Short,
  7606. Value = d2BulletclipStates
  7607. });
  7608. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7609. stopwatch2.Stop();
  7610. }
  7611. catch (Exception ex)
  7612. {
  7613. string str = ex.StackTrace;
  7614. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7615. stopwatch2.Start();
  7616. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  7617. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  7618. // MES_Flag
  7619. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7620. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7621. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7622. writeToPLC_Flag.Adress = 2430;
  7623. writeToPLC_Flag.Value = (short)6;
  7624. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7625. {
  7626. Name = "d2BulletclipCode",
  7627. Adress = 2432,
  7628. ValueType = PLCValueType.String,
  7629. ValueTypeStrLength = 20,
  7630. Value = " "
  7631. });
  7632. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7633. {
  7634. Name = "d2BulletclipStates",
  7635. Adress = 2431,
  7636. ValueType = PLCValueType.Short,
  7637. Value = (short)0
  7638. });
  7639. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7640. stopwatch2.Stop();
  7641. }
  7642. stopwatch1.Stop();
  7643. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7644. }
  7645. // 上次采集到的SN
  7646. //private string sn_S4_3进站接口 = string.Empty;
  7647. /// <summary>
  7648. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  7649. /// </summary>
  7650. private void S4_3进站接口(int plcNo, string stationNameStr)
  7651. {
  7652. Stopwatch stopwatch1 = new Stopwatch();
  7653. Stopwatch stopwatch2 = new Stopwatch();
  7654. try
  7655. {
  7656. stopwatch1.Start();
  7657. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7658. sn = sn.Replace("\0", "");
  7659. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7660. #region 查询15个载具码
  7661. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7662. string vehicleData = string.Empty;
  7663. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7664. if (string.IsNullOrEmpty(vehicleData))
  7665. vehicleData = "";
  7666. if (snResult != 0)
  7667. {
  7668. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7669. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7670. writeToPLC_Flag1.Adress = 2463;
  7671. writeToPLC_Flag1.Value = (short)4;
  7672. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7673. stopwatch1.Stop();
  7674. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7675. return;
  7676. }
  7677. string[] cavitySNs = vehicleData.Split('.');
  7678. if (cavitySNs != null && cavitySNs.Length > 0)
  7679. {
  7680. for (int i = 0; i < cavitySNs.Length; i++)
  7681. {
  7682. if (string.IsNullOrEmpty(cavitySNs[i]))
  7683. vehicleCodes.Add("");
  7684. else
  7685. vehicleCodes.Add(cavitySNs[i]);
  7686. }
  7687. }
  7688. #endregion 查询15个载具码
  7689. #region 查询15个产品SN
  7690. List<string> portNos = new List<string>(); // 15个产品SN
  7691. foreach (string vehicleCode in vehicleCodes)
  7692. {
  7693. if (string.IsNullOrEmpty(vehicleCode))
  7694. portNos.Add("");
  7695. else
  7696. {
  7697. // 查询
  7698. string cavityData = string.Empty;
  7699. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7700. if (string.IsNullOrEmpty(cavityData))
  7701. cavityData = "";
  7702. if (snResult1 != 0)
  7703. {
  7704. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7705. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7706. writeToPLC_Flag1.Adress = 2463;
  7707. writeToPLC_Flag1.Value = (short)4;
  7708. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7709. stopwatch1.Stop();
  7710. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7711. return;
  7712. }
  7713. string[] partSNs = cavityData.Split('.');
  7714. if (partSNs != null && partSNs.Length >= 1)
  7715. portNos.Add(partSNs[0]);
  7716. else
  7717. portNos.Add("");
  7718. }
  7719. }
  7720. #endregion 查询15个产品SN
  7721. // 调用MES进站(最多15个)
  7722. stopwatch2.Start();
  7723. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  7724. for (int i = 0; i < vehicleCodes.Count; i++)
  7725. {
  7726. // 循环进站
  7727. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  7728. {
  7729. // 产品SN(物料码)校验
  7730. string portNo = portNos[i];
  7731. List<TestItem> item = new List<TestItem>();
  7732. item.Add(new TestItem()
  7733. {
  7734. Parameter_name = "弹夹码",
  7735. Parameter_value = sn,
  7736. });
  7737. item.Add(new TestItem()
  7738. {
  7739. Parameter_name = "弹夹穴位",
  7740. Parameter_value = (i + 1).ToString(),
  7741. });
  7742. item.Add(new TestItem()
  7743. {
  7744. Parameter_name = "载具码",
  7745. Parameter_value = vehicleCodes[i],
  7746. });
  7747. item.Add(new TestItem()
  7748. {
  7749. Parameter_name = "载具穴号",
  7750. Parameter_value = "1",
  7751. });
  7752. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  7753. }
  7754. }
  7755. stopwatch2.Stop();
  7756. short result = 0;
  7757. bool haveMesWarn = results.Contains(5);
  7758. bool havePCWarn = results.Contains(6);
  7759. if (haveMesWarn)
  7760. result = 2; // 5->2
  7761. else if (havePCWarn)
  7762. result = 6; // 6->4
  7763. else
  7764. result = 1;
  7765. // MES_Flag 为4MES报错
  7766. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7767. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7768. writeToPLC_Flag.Name = "d3MES_FLAG";
  7769. writeToPLC_Flag.Adress = 2463;
  7770. writeToPLC_Flag.Value = result;
  7771. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7772. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7773. }
  7774. catch (Exception ex)
  7775. {
  7776. stopwatch2.Stop();
  7777. // MES_Flag 为4上位机报错
  7778. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7779. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7780. writeToPLC_Flag.Name = "d3MES_FLAG";
  7781. writeToPLC_Flag.Adress = 2463;
  7782. writeToPLC_Flag.Value = (short)4;
  7783. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7784. string str = ex.StackTrace;
  7785. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7786. }
  7787. stopwatch1.Stop();
  7788. AddMessage(LogType.Info, stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7789. }
  7790. // 上次采集到的SN
  7791. //private string sn_S4_3出站接口 = string.Empty;
  7792. /// <summary>
  7793. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  7794. /// </summary>
  7795. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  7796. {
  7797. Stopwatch stopwatch1 = new Stopwatch();
  7798. Stopwatch stopwatch2 = new Stopwatch();
  7799. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7800. string stationNameStr = stationCode + stationName;
  7801. string processItem = stationName; // 测试项目
  7802. try
  7803. {
  7804. stopwatch1.Start();
  7805. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7806. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7807. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7808. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7809. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7810. sn = sn.Replace("\0", "");
  7811. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7812. bool isPass = d3Result == 1; // 产品结果 bool
  7813. #region 查询15个载具码
  7814. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7815. string vehicleData = string.Empty;
  7816. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7817. if (string.IsNullOrEmpty(vehicleData))
  7818. vehicleData = "";
  7819. if (snResult1 != 0)
  7820. {
  7821. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7822. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7823. writeToPLC_Flag1.Adress = 2463;
  7824. writeToPLC_Flag1.Value = (short)4;
  7825. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7826. stopwatch1.Stop();
  7827. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7828. return;
  7829. }
  7830. string[] cavitySNs = vehicleData.Split('.');
  7831. if (cavitySNs != null && cavitySNs.Length > 0)
  7832. {
  7833. for (int i = 0; i < cavitySNs.Length; i++)
  7834. {
  7835. if (string.IsNullOrEmpty(cavitySNs[i]))
  7836. vehicleCodes.Add("");
  7837. else
  7838. vehicleCodes.Add(cavitySNs[i]);
  7839. }
  7840. }
  7841. #endregion 查询15个载具码
  7842. // 统一查 产品SN列表
  7843. List<string> partNos = new List<string>();
  7844. foreach (string vehicleCode in vehicleCodes)
  7845. {
  7846. if (string.IsNullOrEmpty(vehicleCode))
  7847. partNos.Add("");
  7848. else
  7849. {
  7850. string partNo = "";
  7851. #region 查询载具上的产品信息
  7852. string cavityData = string.Empty;
  7853. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7854. if (string.IsNullOrEmpty(cavityData))
  7855. cavityData = "";
  7856. if (snResult != 0)
  7857. {
  7858. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7859. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7860. writeToPLC_Flag1.Adress = 2463;
  7861. writeToPLC_Flag1.Value = (short)4;
  7862. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7863. stopwatch1.Stop();
  7864. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7865. return;
  7866. }
  7867. string[] partSNs = cavityData.Split('.');
  7868. if (partSNs != null && partSNs.Length >= 1)
  7869. partNo = partSNs[0];
  7870. #endregion 查询载具上的产品信息
  7871. partNos.Add(partNo);
  7872. }
  7873. }
  7874. // 统一上传 - 调用MES出站
  7875. stopwatch2.Start();
  7876. List<int> results = new List<int>();
  7877. for (int i = 0; i < partNos.Count; i++)
  7878. {
  7879. string index = (i + 1).ToString(); // 弹夹穴号
  7880. if (string.IsNullOrEmpty(partNos[i]))
  7881. results.Add(1);
  7882. else
  7883. {
  7884. List<TestItem> items1 = new List<TestItem>();
  7885. items1.Add(new TestItem()
  7886. {
  7887. Parameter_name = "弹夹码",
  7888. Parameter_value = sn,
  7889. Parameter_unit = ""
  7890. });
  7891. items1.Add(new TestItem()
  7892. {
  7893. Parameter_name = "弹夹穴号",
  7894. Parameter_value = index,
  7895. Parameter_unit = ""
  7896. });
  7897. items1.Add(new TestItem()
  7898. {
  7899. Parameter_name = "载具码",
  7900. Parameter_value = vehicleCodes[i],
  7901. Parameter_unit = ""
  7902. });
  7903. items1.Add(new TestItem()
  7904. {
  7905. Parameter_name = "载具穴号",
  7906. Parameter_value = "1",
  7907. Parameter_unit = ""
  7908. });
  7909. items1.Add(new TestItem()
  7910. {
  7911. Parameter_name = "产品结果",
  7912. Parameter_value = d3Result == 1 ? "OK" : "NG",
  7913. Parameter_unit = ""
  7914. });
  7915. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7916. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  7917. results.Add(result1);
  7918. }
  7919. }
  7920. short result = 0;
  7921. if (results.All(a => a == 1))
  7922. result = 1;
  7923. else if (results.Contains(3))
  7924. result = 3;
  7925. else if (results.Contains(2))
  7926. result = 2;
  7927. else if (results.Contains(4))
  7928. result = 4;
  7929. else
  7930. result = 4;
  7931. stopwatch2.Stop();
  7932. // MES_Flag 为4MES报错
  7933. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7934. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7935. writeToPLC_Flag.Name = "d3MES_FLAG";
  7936. writeToPLC_Flag.Adress = 2463;
  7937. writeToPLC_Flag.Value = result;
  7938. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7939. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7940. }
  7941. catch (Exception ex)
  7942. {
  7943. stopwatch2.Restart();
  7944. // MES_Flag 为4上位机报错
  7945. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7946. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7947. writeToPLC_Flag.Name = "d3MES_FLAG";
  7948. writeToPLC_Flag.Adress = 2463;
  7949. writeToPLC_Flag.Value = (short)4;
  7950. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7951. string str = ex.StackTrace;
  7952. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7953. stopwatch2.Stop();
  7954. }
  7955. stopwatch1.Stop();
  7956. AddMessage(LogType.Info, stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7957. }
  7958. // 上次采集到的SN
  7959. //private string sn_S4_4进站接口 = string.Empty;
  7960. /// <summary>
  7961. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  7962. /// </summary>
  7963. private void S4_4进站接口(int plcNo, string stationNameStr)
  7964. {
  7965. Stopwatch stopwatch1 = new Stopwatch();
  7966. Stopwatch stopwatch2 = new Stopwatch();
  7967. try
  7968. {
  7969. stopwatch1.Start();
  7970. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  7971. sn = sn.Replace("\0", "");
  7972. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  7973. #region 查询15个载具码
  7974. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7975. string vehicleData = string.Empty;
  7976. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7977. if (string.IsNullOrEmpty(vehicleData))
  7978. vehicleData = "";
  7979. if (snResult != 0)
  7980. {
  7981. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7982. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7983. writeToPLC_Flag1.Adress = 2463;
  7984. writeToPLC_Flag1.Value = (short)4;
  7985. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7986. stopwatch1.Stop();
  7987. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7988. return;
  7989. }
  7990. string[] cavitySNs = vehicleData.Split('.');
  7991. if (cavitySNs != null && cavitySNs.Length > 0)
  7992. {
  7993. for (int i = 0; i < cavitySNs.Length; i++)
  7994. {
  7995. if (string.IsNullOrEmpty(cavitySNs[i]))
  7996. vehicleCodes.Add("");
  7997. else
  7998. vehicleCodes.Add(cavitySNs[i]);
  7999. }
  8000. }
  8001. #endregion 查询15个载具码
  8002. #region 查询15个产品SN
  8003. List<string> portNos = new List<string>(); // 15个产品SN
  8004. foreach (string vehicleCode in vehicleCodes)
  8005. {
  8006. if (string.IsNullOrEmpty(vehicleCode))
  8007. portNos.Add("");
  8008. else
  8009. {
  8010. // 查询
  8011. string cavityData = string.Empty;
  8012. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8013. if (string.IsNullOrEmpty(cavityData))
  8014. cavityData = "";
  8015. if (snResult1 != 0)
  8016. {
  8017. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8018. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8019. writeToPLC_Flag1.Adress = 2463;
  8020. writeToPLC_Flag1.Value = (short)4;
  8021. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8022. stopwatch1.Stop();
  8023. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8024. return;
  8025. }
  8026. string[] partSNs = cavityData.Split('.');
  8027. if (partSNs != null && partSNs.Length >= 1)
  8028. portNos.Add(partSNs[0]);
  8029. else
  8030. portNos.Add("");
  8031. }
  8032. }
  8033. #endregion 查询15个产品SN
  8034. // 调用MES进站(最多15个)
  8035. stopwatch2.Start();
  8036. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  8037. for (int i = 0; i < vehicleCodes.Count; i++)
  8038. {
  8039. // 循环进站
  8040. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  8041. {
  8042. // 产品SN(物料码)校验
  8043. string portNo = portNos[i];
  8044. List<TestItem> item = new List<TestItem>();
  8045. item.Add(new TestItem()
  8046. {
  8047. Parameter_name = "弹夹码",
  8048. Parameter_value = sn,
  8049. });
  8050. item.Add(new TestItem()
  8051. {
  8052. Parameter_name = "弹夹穴位",
  8053. Parameter_value = (i + 1).ToString(),
  8054. });
  8055. item.Add(new TestItem()
  8056. {
  8057. Parameter_name = "载具码",
  8058. Parameter_value = vehicleCodes[i],
  8059. });
  8060. item.Add(new TestItem()
  8061. {
  8062. Parameter_name = "载具穴号",
  8063. Parameter_value = "1",
  8064. });
  8065. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  8066. }
  8067. }
  8068. stopwatch2.Stop();
  8069. short result = 0;
  8070. bool haveMesWarn = results.Contains(5);
  8071. bool havePCWarn = results.Contains(6);
  8072. if (haveMesWarn)
  8073. result = 2; // 5->2
  8074. else if (havePCWarn)
  8075. result = 6; // 6->4
  8076. else
  8077. result = 1;
  8078. // MES_Flag 为4MES报错
  8079. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8080. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8081. writeToPLC_Flag.Name = "d4MES_FLAG";
  8082. writeToPLC_Flag.Adress = 2496;
  8083. writeToPLC_Flag.Value = result;
  8084. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8085. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8086. }
  8087. catch (Exception ex)
  8088. {
  8089. stopwatch2.Stop();
  8090. // MES_Flag 为4上位机报错
  8091. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8092. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8093. writeToPLC_Flag.Name = "d4MES_FLAG";
  8094. writeToPLC_Flag.Adress = 2496;
  8095. writeToPLC_Flag.Value = (short)4;
  8096. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8097. string str = ex.StackTrace;
  8098. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8099. }
  8100. stopwatch1.Stop();
  8101. AddMessage(LogType.Info, stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8102. }
  8103. // 上次采集到的SN
  8104. //private string sn_S4_4出站接口 = string.Empty;
  8105. /// <summary>
  8106. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  8107. /// </summary>
  8108. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  8109. {
  8110. Stopwatch stopwatch1 = new Stopwatch();
  8111. Stopwatch stopwatch2 = new Stopwatch();
  8112. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8113. string stationNameStr = stationCode + stationName;
  8114. string processItem = stationName; // 测试项目
  8115. try
  8116. {
  8117. stopwatch1.Start();
  8118. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8119. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8120. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8121. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8122. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8123. sn = sn.Replace("\0", "");
  8124. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8125. bool isPass = d4Result == 1; // 产品结果 bool
  8126. #region 查询15个载具码
  8127. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8128. string vehicleData = string.Empty;
  8129. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8130. if (string.IsNullOrEmpty(vehicleData))
  8131. vehicleData = "";
  8132. if (snResult1 != 0)
  8133. {
  8134. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8135. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8136. writeToPLC_Flag1.Adress = 2496;
  8137. writeToPLC_Flag1.Value = (short)4;
  8138. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8139. stopwatch1.Stop();
  8140. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8141. return;
  8142. }
  8143. string[] cavitySNs = vehicleData.Split('.');
  8144. if (cavitySNs != null && cavitySNs.Length > 0)
  8145. {
  8146. for (int i = 0; i < cavitySNs.Length; i++)
  8147. {
  8148. if (string.IsNullOrEmpty(cavitySNs[i]))
  8149. vehicleCodes.Add("");
  8150. else
  8151. vehicleCodes.Add(cavitySNs[i]);
  8152. }
  8153. }
  8154. #endregion 查询15个载具码
  8155. // 统一查 产品SN列表
  8156. List<string> partNos = new List<string>();
  8157. foreach (string vehicleCode in vehicleCodes)
  8158. {
  8159. if (string.IsNullOrEmpty(vehicleCode))
  8160. partNos.Add("");
  8161. else
  8162. {
  8163. string partNo = "";
  8164. #region 查询载具上的产品信息
  8165. string cavityData = string.Empty;
  8166. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8167. if (string.IsNullOrEmpty(cavityData))
  8168. cavityData = "";
  8169. if (snResult != 0)
  8170. {
  8171. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8172. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8173. writeToPLC_Flag1.Adress = 2496;
  8174. writeToPLC_Flag1.Value = (short)4;
  8175. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8176. stopwatch1.Stop();
  8177. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8178. return;
  8179. }
  8180. string[] partSNs = cavityData.Split('.');
  8181. if (partSNs != null && partSNs.Length >= 1)
  8182. partNo = partSNs[0];
  8183. #endregion 查询载具上的产品信息
  8184. partNos.Add(partNo);
  8185. }
  8186. }
  8187. // 调用MES出站
  8188. stopwatch2.Start();
  8189. // 统一上传
  8190. List<int> results = new List<int>();
  8191. for (int i = 0; i < partNos.Count; i++)
  8192. {
  8193. string index = (i + 1).ToString(); // 弹夹穴号
  8194. if (string.IsNullOrEmpty(partNos[i]))
  8195. results.Add(1);
  8196. else
  8197. {
  8198. List<TestItem> items1 = new List<TestItem>();
  8199. items1.Add(new TestItem()
  8200. {
  8201. Parameter_name = "弹夹码",
  8202. Parameter_value = sn,
  8203. Parameter_unit = ""
  8204. });
  8205. items1.Add(new TestItem()
  8206. {
  8207. Parameter_name = "弹夹穴号",
  8208. Parameter_value = index,
  8209. Parameter_unit = ""
  8210. });
  8211. items1.Add(new TestItem()
  8212. {
  8213. Parameter_name = "载具码",
  8214. Parameter_value = vehicleCodes[i],
  8215. Parameter_unit = ""
  8216. });
  8217. items1.Add(new TestItem()
  8218. {
  8219. Parameter_name = "载具穴号",
  8220. Parameter_value = "1",
  8221. Parameter_unit = ""
  8222. });
  8223. items1.Add(new TestItem()
  8224. {
  8225. Parameter_name = "产品结果",
  8226. Parameter_value = d4Result == 1 ? "OK" : "NG",
  8227. Parameter_unit = ""
  8228. });
  8229. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8230. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8231. results.Add(result1);
  8232. }
  8233. }
  8234. short result = 0;
  8235. if (results.All(a => a == 1))
  8236. result = 1;
  8237. else if (results.Contains(3))
  8238. result = 3;
  8239. else if (results.Contains(2))
  8240. result = 2;
  8241. else if (results.Contains(4))
  8242. result = 4;
  8243. else
  8244. result = 4;
  8245. stopwatch2.Stop();
  8246. // MES_Flag 为4MES报错
  8247. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8248. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8249. writeToPLC_Flag.Name = "d4MES_FLAG";
  8250. writeToPLC_Flag.Adress = 2496;
  8251. writeToPLC_Flag.Value = result;
  8252. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8253. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8254. }
  8255. catch (Exception ex)
  8256. {
  8257. stopwatch2.Restart();
  8258. // MES_Flag 为4上位机报错
  8259. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8260. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8261. writeToPLC_Flag.Name = "d4MES_FLAG";
  8262. writeToPLC_Flag.Adress = 2496;
  8263. writeToPLC_Flag.Value = (short)4;
  8264. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8265. string str = ex.StackTrace;
  8266. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8267. stopwatch2.Stop();
  8268. }
  8269. stopwatch1.Stop();
  8270. AddMessage(LogType.Info, stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8271. }
  8272. /// <summary>
  8273. /// [S4] 取放桁架 - S4_5弹夹扫码
  8274. /// </summary>
  8275. /// <param name="plcNo">PLC编号</param>
  8276. /// <param name="stationNameStr">工站全称</param>
  8277. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  8278. {
  8279. Stopwatch stopwatch1 = new Stopwatch();
  8280. Stopwatch stopwatch2 = new Stopwatch();
  8281. try
  8282. {
  8283. stopwatch1.Start();
  8284. // ZS 弹夹扫码
  8285. string d5BulletclipCode = " "; // 扫到的码
  8286. short d5BulletclipScanCode = 2;
  8287. stopwatch2.Start();
  8288. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  8289. //// MES_Flag
  8290. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8291. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8292. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8293. writeToPLC_Flag.Adress = 2528;
  8294. writeToPLC_Flag.Value = d5BulletclipScanCode;
  8295. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8296. {
  8297. Name = "d5BulletclipCode",
  8298. Adress = 2529,
  8299. ValueType = PLCValueType.String,
  8300. ValueTypeStrLength = 20,
  8301. Value = d5BulletclipCode
  8302. });
  8303. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8304. stopwatch2.Stop();
  8305. }
  8306. catch (Exception ex)
  8307. {
  8308. string str = ex.StackTrace;
  8309. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8310. stopwatch2.Start();
  8311. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  8312. //// MES_Flag
  8313. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  8314. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8315. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8316. writeToPLC_Flag.Adress = 2528;
  8317. writeToPLC_Flag.Value = (short)6;
  8318. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8319. {
  8320. Name = "d5BulletclipCode",
  8321. Adress = 2529,
  8322. ValueType = PLCValueType.String,
  8323. ValueTypeStrLength = 20,
  8324. Value = " "
  8325. });
  8326. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8327. stopwatch2.Stop();
  8328. }
  8329. stopwatch1.Stop();
  8330. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8331. }
  8332. /// <summary>
  8333. /// [S4] 取放桁架 - S4_5载具扫码
  8334. /// </summary>
  8335. /// <param name="plcNo">PLC编号</param>
  8336. /// <param name="stationNameStr">工站全称</param>
  8337. private void S4_5载具扫码(int plcNo, string stationNameStr)
  8338. {
  8339. Stopwatch stopwatch1 = new Stopwatch();
  8340. Stopwatch stopwatch2 = new Stopwatch();
  8341. try
  8342. {
  8343. stopwatch1.Start();
  8344. // ZS 载具扫码
  8345. string d5VehicleCode = " "; // 扫到的码
  8346. short d5VehicleScanCode = 2;
  8347. #region 进站
  8348. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  8349. {
  8350. // 查产品SN
  8351. #region 查询载具上的产品信息
  8352. string cavityData = string.Empty;
  8353. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  8354. if (string.IsNullOrEmpty(cavityData))
  8355. cavityData = "";
  8356. if (snResult != 0)
  8357. {
  8358. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8359. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  8360. writeToPLC_Flag1.Adress = 2559;
  8361. writeToPLC_Flag1.Value = (short)6;
  8362. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8363. {
  8364. Name = "d5VehicleCode",
  8365. Adress = 2560,
  8366. ValueType = PLCValueType.String,
  8367. ValueTypeStrLength = 20,
  8368. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  8369. });
  8370. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  8371. stopwatch1.Stop();
  8372. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8373. return;
  8374. }
  8375. string[] cavitySNs = cavityData.Split('.');
  8376. string partNo = "";
  8377. if (cavitySNs != null && cavitySNs.Length >= 1)
  8378. {
  8379. partNo = cavitySNs[0];
  8380. }
  8381. #endregion 查询载具上的产品信息
  8382. List<TestItem> item = new List<TestItem>();
  8383. item.Add(new TestItem()
  8384. {
  8385. Parameter_name = "载具码",
  8386. Parameter_value = d5VehicleCode,
  8387. });
  8388. item.Add(new TestItem()
  8389. {
  8390. Parameter_name = "载具穴号",
  8391. Parameter_value = "1",
  8392. });
  8393. stopwatch2.Start();
  8394. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  8395. stopwatch2.Stop();
  8396. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  8397. }
  8398. #endregion 进站
  8399. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  8400. //// MES_Flag
  8401. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8402. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8403. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8404. writeToPLC_Flag.Adress = 2559;
  8405. writeToPLC_Flag.Value = d5VehicleScanCode;
  8406. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8407. {
  8408. Name = "d5VehicleCode",
  8409. Adress = 2560,
  8410. ValueType = PLCValueType.String,
  8411. ValueTypeStrLength = 20,
  8412. Value = d5VehicleCode
  8413. });
  8414. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8415. }
  8416. catch (Exception ex)
  8417. {
  8418. string str = ex.StackTrace;
  8419. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8420. stopwatch2.Start();
  8421. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  8422. //// MES_Flag
  8423. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  8424. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8425. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8426. writeToPLC_Flag.Adress = 2559;
  8427. writeToPLC_Flag.Value = (short)6;
  8428. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8429. {
  8430. Name = "d5VehicleCode",
  8431. Adress = 2560,
  8432. ValueType = PLCValueType.String,
  8433. ValueTypeStrLength = 20,
  8434. Value = " "
  8435. });
  8436. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8437. stopwatch2.Stop();
  8438. }
  8439. stopwatch1.Stop();
  8440. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8441. }
  8442. // 上次采集到的SN
  8443. //private string sn_S4_5出站接口 = string.Empty;
  8444. /// <summary>
  8445. /// [S4] 取放桁架 - S4_5出站接口
  8446. /// </summary>
  8447. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  8448. {
  8449. Stopwatch stopwatch1 = new Stopwatch();
  8450. Stopwatch stopwatch2 = new Stopwatch();
  8451. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8452. string stationNameStr = stationCode + stationName;
  8453. string processItem = stationName; // 测试项目
  8454. try
  8455. {
  8456. stopwatch1.Start();
  8457. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8458. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8459. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8460. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8461. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  8462. sn = sn.Replace("\0", "");
  8463. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  8464. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  8465. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  8466. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  8467. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  8468. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  8469. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  8470. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  8471. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  8472. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  8473. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  8474. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  8475. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  8476. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  8477. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  8478. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  8479. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  8480. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  8481. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  8482. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  8483. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  8484. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  8485. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  8486. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  8487. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  8488. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  8489. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  8490. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  8491. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  8492. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  8493. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  8494. bool pass = d5Result == 1;
  8495. // 存 载具SN列表
  8496. List<string> vehicleCodes = new List<string>()
  8497. {
  8498. d5VehicleCode1,d5VehicleCode2,d5VehicleCode3,d5VehicleCode4,d5VehicleCode5,
  8499. d5VehicleCode6,d5VehicleCode7,d5VehicleCode8,d5VehicleCode9,d5VehicleCode10,
  8500. d5VehicleCode11,d5VehicleCode12,d5VehicleCode13,d5VehicleCode14,d5VehicleCode15
  8501. };
  8502. // 统一查 产品SN列表
  8503. List<string> partNos = new List<string>();
  8504. foreach (string vehicleCode in vehicleCodes)
  8505. {
  8506. if (string.IsNullOrEmpty(vehicleCode))
  8507. partNos.Add("");
  8508. else
  8509. {
  8510. string partNo = "";
  8511. #region 查询载具上的产品信息
  8512. string cavityData = string.Empty;
  8513. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8514. if (string.IsNullOrEmpty(cavityData))
  8515. cavityData = "";
  8516. if (snResult != 0)
  8517. {
  8518. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8519. writeToPLC_Flag1.Name = "d5MES_FLAG";
  8520. writeToPLC_Flag1.Adress = 2591;
  8521. writeToPLC_Flag1.Value = (short)4;
  8522. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  8523. stopwatch1.Stop();
  8524. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8525. return;
  8526. }
  8527. string[] cavitySNs = cavityData.Split('.');
  8528. if (cavitySNs != null && cavitySNs.Length >= 1)
  8529. partNo = cavitySNs[0];
  8530. #endregion 查询载具上的产品信息
  8531. partNos.Add(partNo);
  8532. }
  8533. }
  8534. // 统一上传
  8535. stopwatch2.Start();
  8536. List<int> results = new List<int>();
  8537. for (int i = 0; i < partNos.Count; i++)
  8538. {
  8539. string index = (i + 1).ToString(); // 弹夹穴号
  8540. if (string.IsNullOrEmpty(partNos[i]))
  8541. results.Add(1);
  8542. else
  8543. {
  8544. List<TestItem> items1 = new List<TestItem>();
  8545. items1.Add(new TestItem()
  8546. {
  8547. Parameter_name = "弹夹码",
  8548. Parameter_value = sn,
  8549. Parameter_unit = ""
  8550. });
  8551. items1.Add(new TestItem()
  8552. {
  8553. Parameter_name = "弹夹穴号",
  8554. Parameter_value = index,
  8555. Parameter_unit = ""
  8556. });
  8557. items1.Add(new TestItem()
  8558. {
  8559. Parameter_name = "载具码",
  8560. Parameter_value = vehicleCodes[i],
  8561. Parameter_unit = ""
  8562. });
  8563. items1.Add(new TestItem()
  8564. {
  8565. Parameter_name = "载具穴号",
  8566. Parameter_value = "1",
  8567. Parameter_unit = ""
  8568. });
  8569. items1.Add(new TestItem()
  8570. {
  8571. Parameter_name = "产品结果",
  8572. Parameter_value = d5Result == 1 ? "OK" : "NG",
  8573. Parameter_unit = ""
  8574. });
  8575. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8576. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  8577. results.Add(result1);
  8578. }
  8579. }
  8580. short result = 0;
  8581. if (results.All(a => a == 1))
  8582. result = 1;
  8583. else if (results.Contains(3))
  8584. result = 3;
  8585. else if (results.Contains(2))
  8586. result = 2;
  8587. else if (results.Contains(4))
  8588. result = 4;
  8589. else
  8590. result = 4;
  8591. stopwatch2.Stop();
  8592. #region 存储绑定数据到 边线MES系统中
  8593. if (result == 1)
  8594. {
  8595. // 删除绑定信息
  8596. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  8597. if (resultMesR != 0)
  8598. {
  8599. result = 4;
  8600. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  8601. }
  8602. }
  8603. #endregion 存储绑定数据到 边线MES系统中
  8604. // MES_Flag 为4MES报错
  8605. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8606. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8607. writeToPLC_Flag.Name = "d5MES_FLAG";
  8608. writeToPLC_Flag.Adress = 2591;
  8609. writeToPLC_Flag.Value = result;
  8610. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8611. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8612. }
  8613. catch (Exception ex)
  8614. {
  8615. stopwatch2.Restart();
  8616. // MES_Flag 为4上位机报错
  8617. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  8618. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8619. writeToPLC_Flag.Name = "d5MES_FLAG";
  8620. writeToPLC_Flag.Adress = 2591;
  8621. writeToPLC_Flag.Value = (short)4;
  8622. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8623. stopwatch2.Stop();
  8624. string str = ex.StackTrace;
  8625. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8626. }
  8627. stopwatch1.Stop();
  8628. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8629. }
  8630. /// <summary>
  8631. /// [S4] 取放桁架 - S4_5节拍接口
  8632. /// </summary>
  8633. /// <param name="plcNo">PLC编号</param>
  8634. /// <param name="stationNameStr">工站全称</param>
  8635. private void S4_5节拍接口(int plcNo, string stationNameStr)
  8636. {
  8637. Stopwatch stopwatch1 = new Stopwatch();
  8638. Stopwatch stopwatch2 = new Stopwatch();
  8639. string resultStr = string.Empty;
  8640. try
  8641. {
  8642. stopwatch1.Start();
  8643. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  8644. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  8645. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  8646. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8647. if (!actionBool)
  8648. {
  8649. stopwatch2.Start();
  8650. // MES_Flag
  8651. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  8652. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8653. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8654. writeToPLC_Flag1.Adress = 2924;
  8655. writeToPLC_Flag1.Value = (short)4;
  8656. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8657. stopwatch2.Stop();
  8658. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8659. return;
  8660. }
  8661. string d5OEEPartNo = string.Empty; // 物料码
  8662. if (string.IsNullOrEmpty(d5OEEProductSN))
  8663. {
  8664. stopwatch2.Start();
  8665. // MES_Flag
  8666. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8667. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8668. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8669. writeToPLC_Flag1.Adress = 2924;
  8670. writeToPLC_Flag1.Value = (short)1;
  8671. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8672. stopwatch2.Stop();
  8673. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8674. return;
  8675. }
  8676. else
  8677. { // 查产品SN
  8678. d5OEEPartNo = "Test"; // ZS
  8679. }
  8680. short d5OEEMES_FLAG = 0;
  8681. // 上传OEE
  8682. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  8683. d5OEEMES_FLAG = result.Item1;
  8684. resultStr = result.Item2;
  8685. stopwatch2.Start();
  8686. // MES_Flag
  8687. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8688. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8689. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8690. writeToPLC_Flag.Adress = 2924;
  8691. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  8692. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8693. stopwatch2.Stop();
  8694. }
  8695. catch (Exception ex)
  8696. {
  8697. string str = ex.StackTrace;
  8698. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8699. // MES_Flag
  8700. stopwatch2.Start();
  8701. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  8702. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8703. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8704. writeToPLC_Flag.Adress = 2924;
  8705. writeToPLC_Flag.Value = (short)4;
  8706. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8707. stopwatch2.Stop();
  8708. }
  8709. stopwatch1.Stop();
  8710. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8711. }
  8712. #endregion [S4] 取放桁架
  8713. #endregion PLC4 刘果段
  8714. #region PLC5 张超凡
  8715. #region [S5] Tray盘下料装备
  8716. /// <summary>
  8717. /// S5工位的数据- 触发信号上次的值
  8718. /// </summary>
  8719. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  8720. /// <summary>
  8721. /// S5工位的数据(含触发信号)
  8722. /// </summary>
  8723. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  8724. /// <summary>
  8725. /// S5工位的数据- 回写点位
  8726. /// </summary>
  8727. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8728. /// <summary>
  8729. /// [S5] Tray盘下料装备
  8730. /// </summary>
  8731. /// <param name="plcNo">PLC编号</param>
  8732. //private void ReadStation_S5(int plcNo)
  8733. //{
  8734. // // [S1] Tray盘上料装备
  8735. // // [S2] FCT
  8736. // // [S3] 值板机
  8737. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8738. // // [S5] Tray盘下料装备
  8739. // /// 上位机心跳
  8740. // /// 获取设备报警数据与状态信息
  8741. // string stationCode = "[S5]";
  8742. // string stationName = "Tray盘下料装备";
  8743. // string stationNameStr = stationCode + stationName;
  8744. // #region 创建字典
  8745. // // 触发信号字典 赋值
  8746. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8747. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8748. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8749. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8750. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  8751. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8752. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  8753. // // PLC数据字典 赋值
  8754. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8755. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  8756. // s5PLCData.Add("e1ProductSN_Check", ""); //
  8757. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8758. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  8759. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  8760. // s5PLCData.Add("e1PartNo", ""); // 物料码
  8761. // s5PLCData.Add("e1Result", 0); // 产品结果
  8762. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8763. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  8764. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  8765. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  8766. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8767. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  8768. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  8769. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8770. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  8771. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  8772. // #endregion 创建字典
  8773. // while (IsRun)
  8774. // {
  8775. // try
  8776. // {
  8777. // if (!GlobalContext._IsCon_Funs5)
  8778. // {
  8779. // UpdatePLCMonitor(1, plcNo, 0);
  8780. // continue;
  8781. // }
  8782. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8783. // {
  8784. // Stopwatch stopwatch1 = new Stopwatch();
  8785. // Stopwatch stopwatch2 = new Stopwatch();
  8786. // stopwatch1.Start();
  8787. // stopwatch2.Start();
  8788. // #region 一次性读取所有数据
  8789. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8790. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  8791. // int[] datas = data1.Concat(data2).ToArray();
  8792. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  8793. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  8794. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8795. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  8796. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  8797. // s5PLCData["e1MES_FLAG"] = datas[35];
  8798. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  8799. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  8800. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  8801. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  8802. // s5PLCData["e1Result"] = datas[76];
  8803. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  8804. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  8805. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  8806. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  8807. // s5PLCData["e1OEEType"] = datas[109];
  8808. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  8809. // s5PLCData["e1AGVUpStart"] = datas[121];
  8810. // s5PLCData["e1AGVUpEnd"] = datas[122];
  8811. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  8812. // s5PLCData["e1AGVDownStart"] = datas[134];
  8813. // s5PLCData["e1AGVDownEnd"] = datas[135];
  8814. // #endregion 一次性读取所有数据
  8815. // stopwatch2.Stop();
  8816. // #region 回写操作,写后清空flag
  8817. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  8818. // #endregion 回写操作,写后清空flag
  8819. // #region 进站校验
  8820. // try
  8821. // {
  8822. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  8823. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  8824. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  8825. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  8826. // {
  8827. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  8828. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8829. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  8830. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8831. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  8832. // }
  8833. // }
  8834. // catch (Exception ex)
  8835. // {
  8836. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8837. // string str = ex.StackTrace;
  8838. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8839. // }
  8840. // #endregion 进站校验
  8841. // #region 出站接口
  8842. // try
  8843. // {
  8844. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  8845. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  8846. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  8847. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  8848. // {
  8849. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  8850. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8851. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  8852. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  8853. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  8854. // }
  8855. // }
  8856. // catch (Exception ex)
  8857. // {
  8858. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  8859. // string str = ex.StackTrace;
  8860. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8861. // }
  8862. // #endregion 出站接口
  8863. // #region 节拍接口
  8864. // try
  8865. // {
  8866. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  8867. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  8868. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  8869. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  8870. // {
  8871. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  8872. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8873. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  8874. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  8875. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  8876. // }
  8877. // }
  8878. // catch (Exception ex)
  8879. // {
  8880. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  8881. // string str = ex.StackTrace;
  8882. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8883. // }
  8884. // #endregion 节拍接口
  8885. // #region AGV上料
  8886. // // AGV上料叫AGV信号
  8887. // try
  8888. // {
  8889. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  8890. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  8891. // if (e1AGVUpCall != e1AGVUpCallOld)
  8892. // {
  8893. // if (e1AGVUpCall == 1) // 0->1
  8894. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  8895. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  8896. // }
  8897. // }
  8898. // catch (Exception ex)
  8899. // {
  8900. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  8901. // string str = ex.StackTrace;
  8902. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8903. // }
  8904. // // AGV上料完成信号
  8905. // try
  8906. // {
  8907. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  8908. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  8909. // if (e1AGVUpEnd != e1AGVUpEndOld)
  8910. // {
  8911. // if (e1AGVUpEnd == 1) // 0->1
  8912. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  8913. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  8914. // }
  8915. // }
  8916. // catch (Exception ex)
  8917. // {
  8918. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  8919. // string str = ex.StackTrace;
  8920. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8921. // }
  8922. // #endregion AGV上料
  8923. // #region AGV下料
  8924. // // AGV下料叫agv信号
  8925. // try
  8926. // {
  8927. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  8928. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  8929. // if (e1AGVDownCall != e1AGVDownCallOld)
  8930. // {
  8931. // if (e1AGVDownCall == 1) // 0->1
  8932. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  8933. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  8934. // }
  8935. // }
  8936. // catch (Exception ex)
  8937. // {
  8938. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  8939. // string str = ex.StackTrace;
  8940. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8941. // }
  8942. // // AGV下料完成信号
  8943. // try
  8944. // {
  8945. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  8946. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  8947. // if (e1AGVDownEnd != e1AGVDownEndOld)
  8948. // {
  8949. // if (e1AGVDownEnd == 1) // 0->1
  8950. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  8951. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  8952. // }
  8953. // }
  8954. // catch (Exception ex)
  8955. // {
  8956. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  8957. // string str = ex.StackTrace;
  8958. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8959. // }
  8960. // #endregion AGV下料
  8961. // #region 心跳
  8962. // try
  8963. // {
  8964. // short states = 0;
  8965. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  8966. // }
  8967. // catch (Exception ex)
  8968. // {
  8969. // string str = ex.StackTrace;
  8970. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8971. // }
  8972. // #endregion 心跳
  8973. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  8974. // stopwatch1.Stop();
  8975. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  8976. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  8977. // }
  8978. // else
  8979. // {
  8980. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8981. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  8982. // Funs[plcNo].Connect();
  8983. // }
  8984. // }
  8985. // catch (Exception ex)
  8986. // {
  8987. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8988. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  8989. // Funs[plcNo].ReConnect();
  8990. // }
  8991. // Thread.Sleep(IntervalReadPLC);
  8992. // }
  8993. //}
  8994. /// <summary>
  8995. /// [S5] Tray盘下料装备 - 进站校验
  8996. /// </summary>
  8997. /// <param name="plcNo">PLC编号</param>
  8998. /// <param name="stationNameStr">工站全称</param>
  8999. private void S5进站校验(int plcNo, string stationNameStr)
  9000. {
  9001. Stopwatch stopwatch1 = new Stopwatch();
  9002. Stopwatch stopwatch2 = new Stopwatch();
  9003. try
  9004. {
  9005. stopwatch1.Start();
  9006. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  9007. sn = sn.Replace("\0", "");
  9008. // 获取产品SN By 载具码
  9009. #region 查询载具上的产品信息
  9010. string cavityData = string.Empty;
  9011. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9012. if (string.IsNullOrEmpty(cavityData))
  9013. cavityData = "";
  9014. if (snResult != 0)
  9015. {
  9016. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9017. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  9018. writeToPLC_Flag1.Adress = 2003;
  9019. writeToPLC_Flag1.Value = (short)6;
  9020. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  9021. stopwatch1.Stop();
  9022. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9023. return;
  9024. }
  9025. string[] cavitySNs = cavityData.Split('.');
  9026. string partNo = string.Empty;
  9027. if (cavitySNs != null && cavitySNs.Length >= 1)
  9028. partNo = cavitySNs[0];
  9029. #endregion 查询载具上的产品信息
  9030. // 产品SN(物料码)校验
  9031. List<TestItem> item = new List<TestItem>();
  9032. item.Add(new TestItem()
  9033. {
  9034. Parameter_name = "载具码",
  9035. Parameter_value = sn,
  9036. });
  9037. item.Add(new TestItem()
  9038. {
  9039. Parameter_name = "载具穴号",
  9040. Parameter_value = "1",
  9041. });
  9042. stopwatch2.Start();
  9043. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  9044. stopwatch2.Stop();
  9045. short e1MES_FLAG_Check = (short)result;
  9046. // MES_Flag
  9047. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9048. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9049. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9050. writeToPLC_Flag.Adress = 2003;
  9051. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  9052. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9053. }
  9054. catch (Exception ex)
  9055. {
  9056. string str = ex.StackTrace;
  9057. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9058. // MES_Flag
  9059. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9060. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9061. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9062. writeToPLC_Flag.Adress = 2003;
  9063. writeToPLC_Flag.Value = (short)6;
  9064. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9065. }
  9066. stopwatch1.Stop();
  9067. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9068. }
  9069. /// <summary>
  9070. /// [S5] Tray盘下料装备 - 出站接口
  9071. /// </summary>
  9072. /// <param name="plcNo"></param>
  9073. /// <param name="stationCode"></param>
  9074. /// <param name="stationName"></param>
  9075. private void S5出站接口(int plcNo, string stationCode, string stationName)
  9076. {
  9077. Stopwatch stopwatch1 = new Stopwatch();
  9078. Stopwatch stopwatch2 = new Stopwatch();
  9079. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9080. string stationNameStr = stationCode + stationName;
  9081. string processItem = stationName; // 测试项目
  9082. try
  9083. {
  9084. stopwatch1.Start();
  9085. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9086. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9087. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9088. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9089. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  9090. sn = sn.Replace("\0", "");
  9091. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  9092. //partNo = partNo.Replace("\0", "");
  9093. #region 查询载具上的产品信息
  9094. string cavityData = string.Empty;
  9095. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9096. if (string.IsNullOrEmpty(cavityData))
  9097. cavityData = "";
  9098. if (snResult != 0)
  9099. {
  9100. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9101. writeToPLC_Flag1.Name = "e1MES_FLAG";
  9102. writeToPLC_Flag1.Adress = 2035;
  9103. writeToPLC_Flag1.Value = (short)4;
  9104. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  9105. stopwatch1.Stop();
  9106. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9107. return;
  9108. }
  9109. string[] cavitySNs = cavityData.Split('.');
  9110. string partNo = string.Empty;
  9111. if (cavitySNs != null && cavitySNs.Length >= 1)
  9112. partNo = cavitySNs[0];
  9113. #endregion 查询载具上的产品信息
  9114. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  9115. bool pass = e1Result == 1;
  9116. stopwatch2.Start();
  9117. // 上传MES
  9118. List<TestItem> items = new List<TestItem>();
  9119. items.Add(new TestItem()
  9120. {
  9121. Parameter_name = "载具码",
  9122. Parameter_value = sn,
  9123. Parameter_unit = ""
  9124. });
  9125. items.Add(new TestItem()
  9126. {
  9127. Parameter_name = "载具穴号",
  9128. Parameter_value = "1",
  9129. Parameter_unit = ""
  9130. });
  9131. items.Add(new TestItem()
  9132. {
  9133. Parameter_name = "产品结果",
  9134. Parameter_value = e1Result == 1 ? "OK" : "NG",
  9135. Parameter_unit = ""
  9136. });
  9137. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  9138. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  9139. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  9140. short result = result1 == 1 ? (short)1 : (short)3;
  9141. stopwatch2.Stop();
  9142. #region 存储绑定数据到 边线MES系统中
  9143. if (result == 1)
  9144. {
  9145. // 删除绑定信息
  9146. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  9147. if (resultMesR != 0)
  9148. {
  9149. result = 4;
  9150. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  9151. }
  9152. }
  9153. #endregion 存储绑定数据到 边线MES系统中
  9154. // MES_Flag 为MES报错
  9155. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9156. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  9157. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9158. writeToPLC_Flag.Name = "e1MES_FLAG";
  9159. writeToPLC_Flag.Adress = 2035;
  9160. writeToPLC_Flag.Value = result;
  9161. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9162. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9163. }
  9164. catch (Exception ex)
  9165. {
  9166. stopwatch2.Restart();
  9167. // MES_Flag 为4上位机报错
  9168. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  9169. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9170. writeToPLC_Flag.Name = "e1MES_FLAG";
  9171. writeToPLC_Flag.Adress = 2035;
  9172. writeToPLC_Flag.Value = (short)4;
  9173. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9174. stopwatch2.Stop();
  9175. string str = ex.StackTrace;
  9176. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9177. }
  9178. stopwatch1.Stop();
  9179. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9180. }
  9181. /// <summary>
  9182. /// [S5] Tray盘下料装备 - 节拍接口
  9183. /// </summary>
  9184. /// <param name="plcNo">PLC编号</param>
  9185. /// <param name="stationNameStr">工站全称</param>
  9186. private void S5节拍接口(int plcNo, string stationNameStr)
  9187. {
  9188. Stopwatch stopwatch1 = new Stopwatch();
  9189. Stopwatch stopwatch2 = new Stopwatch();
  9190. string resultStr = string.Empty;
  9191. try
  9192. {
  9193. stopwatch1.Start();
  9194. string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  9195. string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  9196. e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  9197. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9198. if (!actionBool)
  9199. {
  9200. stopwatch2.Start();
  9201. // MES_Flag
  9202. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9203. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9204. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9205. writeToPLC_Flag1.Adress = 2088;
  9206. writeToPLC_Flag1.Value = (short)4;
  9207. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9208. stopwatch2.Stop();
  9209. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9210. return;
  9211. }
  9212. string e1OEEPartNo = string.Empty; // 物料码
  9213. if (string.IsNullOrEmpty(e1OEEProductSN))
  9214. {
  9215. stopwatch2.Start();
  9216. // MES_Flag
  9217. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9218. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9219. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9220. writeToPLC_Flag1.Adress = 2088;
  9221. writeToPLC_Flag1.Value = (short)1;
  9222. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9223. stopwatch2.Stop();
  9224. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9225. return;
  9226. }
  9227. else
  9228. { // 查产品SN
  9229. e1OEEPartNo = "Test"; // ZS
  9230. }
  9231. short e1OEEMES_FLAG = 0;
  9232. // 上传OEE
  9233. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  9234. e1OEEMES_FLAG = result.Item1;
  9235. resultStr = result.Item2;
  9236. stopwatch2.Start();
  9237. // MES_Flag
  9238. //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9239. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9240. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9241. writeToPLC_Flag.Adress = 2088;
  9242. writeToPLC_Flag.Value = e1OEEMES_FLAG;
  9243. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9244. stopwatch2.Stop();
  9245. }
  9246. catch (Exception ex)
  9247. {
  9248. string str = ex.StackTrace;
  9249. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9250. // MES_Flag
  9251. stopwatch2.Start();
  9252. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9253. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9254. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9255. writeToPLC_Flag.Adress = 2088;
  9256. writeToPLC_Flag.Value = (short)4;
  9257. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9258. stopwatch2.Stop();
  9259. }
  9260. stopwatch1.Stop();
  9261. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9262. }
  9263. /// <summary>
  9264. /// [S5] Tray盘下料装备 - AGV上料叫agv
  9265. /// </summary>
  9266. /// <param name="plcNo">PLC编号</param>
  9267. /// <param name="stationNameStr">工站全称</param>
  9268. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  9269. {
  9270. Stopwatch stopwatch1 = new Stopwatch();
  9271. Stopwatch stopwatch2 = new Stopwatch();
  9272. try
  9273. {
  9274. stopwatch1.Start();
  9275. // ZS 呼叫AGV
  9276. short e1AGVUpCall = 2;
  9277. stopwatch2.Start();
  9278. // e1AGVUpCall
  9279. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9280. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9281. writeToPLC_Flag.Name = "e1AGVUpCall";
  9282. writeToPLC_Flag.Adress = 2120;
  9283. writeToPLC_Flag.Value = e1AGVUpCall;
  9284. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9285. stopwatch2.Stop();
  9286. }
  9287. catch (Exception ex)
  9288. {
  9289. string str = ex.StackTrace;
  9290. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9291. // e1AGVUpCall
  9292. stopwatch2.Start();
  9293. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9294. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9295. writeToPLC_Flag.Name = "e1AGVUpCall";
  9296. writeToPLC_Flag.Adress = 2120;
  9297. writeToPLC_Flag.Value = (short)4;
  9298. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9299. stopwatch2.Stop();
  9300. }
  9301. stopwatch1.Stop();
  9302. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9303. }
  9304. /// <summary>
  9305. /// [S5] Tray盘下料装备 - AGV上料完成
  9306. /// </summary>
  9307. /// <param name="plcNo">PLC编号</param>
  9308. /// <param name="stationNameStr">工站全称</param>
  9309. private void S5AGV上料完成(int plcNo, string stationNameStr)
  9310. {
  9311. Stopwatch stopwatch1 = new Stopwatch();
  9312. Stopwatch stopwatch2 = new Stopwatch();
  9313. try
  9314. {
  9315. stopwatch1.Start();
  9316. // ZS AGV上料完成,让小车离开
  9317. short e1AGVUpEnd = 2;
  9318. stopwatch2.Start();
  9319. // e1AGVUpEnd
  9320. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9321. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9322. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9323. writeToPLC_Flag.Adress = 2122;
  9324. writeToPLC_Flag.Value = e1AGVUpEnd;
  9325. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9326. stopwatch2.Stop();
  9327. }
  9328. catch (Exception ex)
  9329. {
  9330. string str = ex.StackTrace;
  9331. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9332. // e1AGVUpEnd
  9333. stopwatch2.Start();
  9334. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9335. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9336. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9337. writeToPLC_Flag.Adress = 2122;
  9338. writeToPLC_Flag.Value = (short)4;
  9339. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9340. stopwatch2.Stop();
  9341. }
  9342. stopwatch1.Stop();
  9343. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9344. }
  9345. /// <summary>
  9346. /// [S5] Tray盘下料装备 - AGV下料叫agv
  9347. /// </summary>
  9348. /// <param name="plcNo">PLC编号</param>
  9349. /// <param name="stationNameStr">工站全称</param>
  9350. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  9351. {
  9352. Stopwatch stopwatch1 = new Stopwatch();
  9353. Stopwatch stopwatch2 = new Stopwatch();
  9354. try
  9355. {
  9356. stopwatch1.Start();
  9357. // ZS 呼叫AGV
  9358. short e1AGVDownCall = 2;
  9359. stopwatch2.Start();
  9360. // e1AGVDownCall
  9361. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9362. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9363. writeToPLC_Flag.Name = "e1AGVDownCall";
  9364. writeToPLC_Flag.Adress = 2133;
  9365. writeToPLC_Flag.Value = e1AGVDownCall;
  9366. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9367. stopwatch2.Stop();
  9368. }
  9369. catch (Exception ex)
  9370. {
  9371. string str = ex.StackTrace;
  9372. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9373. // e1AGVDownCall
  9374. stopwatch2.Start();
  9375. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9376. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9377. writeToPLC_Flag.Name = "e1AGVDownCall";
  9378. writeToPLC_Flag.Adress = 2133;
  9379. writeToPLC_Flag.Value = (short)4;
  9380. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9381. stopwatch2.Stop();
  9382. }
  9383. stopwatch1.Stop();
  9384. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9385. }
  9386. /// <summary>
  9387. /// [S5] Tray盘下料装备 - AGV下料完成
  9388. /// </summary>
  9389. /// <param name="plcNo">PLC编号</param>
  9390. /// <param name="stationNameStr">工站全称</param>
  9391. private void S5AGV下料完成(int plcNo, string stationNameStr)
  9392. {
  9393. Stopwatch stopwatch1 = new Stopwatch();
  9394. Stopwatch stopwatch2 = new Stopwatch();
  9395. try
  9396. {
  9397. stopwatch1.Start();
  9398. // ZS AGV上料完成,让小车离开
  9399. short e1AGVDownEnd = 2;
  9400. stopwatch2.Start();
  9401. // e1AGVDownEnd
  9402. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9403. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9404. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9405. writeToPLC_Flag.Adress = 2135;
  9406. writeToPLC_Flag.Value = e1AGVDownEnd;
  9407. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9408. stopwatch2.Stop();
  9409. }
  9410. catch (Exception ex)
  9411. {
  9412. string str = ex.StackTrace;
  9413. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9414. // e1AGVDownEnd
  9415. stopwatch2.Start();
  9416. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9417. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9418. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9419. writeToPLC_Flag.Adress = 2135;
  9420. writeToPLC_Flag.Value = (short)4;
  9421. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9422. stopwatch2.Stop();
  9423. }
  9424. stopwatch1.Stop();
  9425. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9426. }
  9427. #endregion [S5] Tray盘下料装备
  9428. #endregion PLC5 张超凡
  9429. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  9430. /// <summary>
  9431. /// PLC读取到的数据 -添加数据
  9432. /// </summary>
  9433. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  9434. {
  9435. if (sxPlcData.ContainsKey(newKey))
  9436. sxPlcData[newKey] = newValue;
  9437. else
  9438. sxPlcData.Add(newKey, newValue);
  9439. }
  9440. /// <summary>
  9441. /// PLC需要写入的数据 -添加数据
  9442. /// </summary>
  9443. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey, WriteToPLC_Flag newValue)
  9444. {
  9445. if (sxPLCWriteData.ContainsKey(newKey))
  9446. sxPLCWriteData[newKey] = newValue;
  9447. else
  9448. sxPLCWriteData.Add(newKey, newValue);
  9449. }
  9450. /// <summary>
  9451. /// PLC回写操作,写后清空flag
  9452. /// </summary>
  9453. /// <param name="modbusClient">modbus对象</param>
  9454. /// <param name="pLCReadDatas">读取到的数据字典</param>
  9455. /// <param name="pLCWriteDatas">需要写入的数据</param>
  9456. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas, ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  9457. {
  9458. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  9459. {
  9460. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  9461. for (int i = 0; i < pLCWriteDatas.Count; i++)
  9462. {
  9463. string mesFlagName = pLCWriteDatas[i].Name;
  9464. int mesFlagAdress = pLCWriteDatas[i].Adress;
  9465. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  9466. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  9467. {
  9468. // 先回写数据
  9469. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  9470. for (int j = 0; j < writeToPLCDatas.Count; j++)
  9471. {
  9472. int mesDataAdress = writeToPLCDatas[j].Adress;
  9473. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  9474. switch (mesDataType)
  9475. {
  9476. case PLCValueType.Short:
  9477. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  9478. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  9479. break;
  9480. case PLCValueType.String:
  9481. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  9482. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  9483. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr, mesDataValueStrLength);
  9484. break;
  9485. }
  9486. }
  9487. // 再回写信号
  9488. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  9489. // 存储读取数据的字典
  9490. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  9491. // 存储写入数据的字典 - 清空写入值
  9492. pLCWriteDatas[i].Value = (short)0;
  9493. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  9494. }
  9495. }
  9496. }
  9497. }
  9498. /// <summary>
  9499. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  9500. /// </summary>
  9501. /// <param name="no">3</param>
  9502. /// <param name="stationCode">设备编号</param>
  9503. /// <param name="stationNameStr">设备名称</param>
  9504. /// <param name="plcOrder">车间订单号</param>
  9505. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  9506. {
  9507. try
  9508. {
  9509. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  9510. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  9511. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  9512. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  9513. int result1 = 0;
  9514. switch (stationCode)
  9515. {
  9516. case 2:
  9517. case 3:
  9518. case 4:
  9519. case 6:
  9520. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  9521. break;
  9522. case 102:
  9523. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  9524. break;
  9525. case 103:
  9526. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  9527. break;
  9528. case 104:
  9529. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  9530. break;
  9531. case 106:
  9532. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  9533. break;
  9534. default:
  9535. // MES_Flag 为“6未找到正确设备编号”
  9536. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  9537. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  9538. return;
  9539. }
  9540. short result = result1 == 1 ? (short)1 : (short)2;
  9541. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  9542. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  9543. }
  9544. catch (Exception ex)
  9545. {
  9546. // MES_Flag 为2上位机报错
  9547. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  9548. string str = ex.StackTrace;
  9549. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9550. }
  9551. }
  9552. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  9553. #region UI刷新
  9554. /// <summary>
  9555. /// 更新商品信息的UI + 下发产品信息(SN)
  9556. /// </summary>
  9557. private void UpdateProductInfo()
  9558. {
  9559. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  9560. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  9561. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  9562. //txt_CurSupplierCode.Text = ""; // 供应商代号
  9563. }
  9564. /// <summary>
  9565. /// 更新PLC连接状态的UI
  9566. /// </summary>
  9567. /// <param name="no">PLC编号</param>
  9568. /// <param name="status">状态</param>
  9569. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  9570. {
  9571. if (this != null && !this.IsDisposed)
  9572. {
  9573. switch (imgNo)
  9574. {
  9575. case 1:
  9576. this.BeginInvoke(new Action(() =>
  9577. {
  9578. picPLC.Image = imageListState.Images[status];
  9579. }));
  9580. break;
  9581. case 2:
  9582. this.BeginInvoke(new Action(() =>
  9583. {
  9584. pictureBox2.Image = imageListState.Images[status];
  9585. }));
  9586. break;
  9587. case 3:
  9588. this.BeginInvoke(new Action(() =>
  9589. {
  9590. pictureBox3.Image = imageListState.Images[status];
  9591. }));
  9592. break;
  9593. case 4:
  9594. this.BeginInvoke(new Action(() =>
  9595. {
  9596. pictureBox4.Image = imageListState.Images[status];
  9597. }));
  9598. break;
  9599. case 5:
  9600. this.BeginInvoke(new Action(() =>
  9601. {
  9602. pictureBox5.Image = imageListState.Images[status];
  9603. }));
  9604. break;
  9605. case 6:
  9606. this.BeginInvoke(new Action(() =>
  9607. {
  9608. pictureBox6.Image = imageListState.Images[status];
  9609. }));
  9610. break;
  9611. case 7:
  9612. this.BeginInvoke(new Action(() =>
  9613. {
  9614. pictureBox7.Image = imageListState.Images[status];
  9615. }));
  9616. break;
  9617. case 8:
  9618. this.BeginInvoke(new Action(() =>
  9619. {
  9620. pictureBox8.Image = imageListState.Images[status];
  9621. }));
  9622. break;
  9623. default:
  9624. break;
  9625. }
  9626. }
  9627. Task.Run(() => // 更新PLC交互页的指示灯
  9628. {
  9629. try
  9630. {
  9631. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9632. {
  9633. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  9634. }
  9635. }
  9636. catch { }
  9637. });
  9638. }
  9639. #endregion UI刷新
  9640. #region 日志
  9641. /// <summary>
  9642. /// 添加各工位运行日志(同步至PLC交互页面)
  9643. /// </summary>
  9644. /// <param name="stationNameStr">工站名称</param>
  9645. /// <param name="logType">日志类型</param>
  9646. /// <param name="message">日志内容</param>
  9647. /// <param name="snNumber">产品数字SN</param>
  9648. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  9649. {
  9650. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")
  9651. && (message.Contains("更新整线运行数据完毕") || message.Contains("更新整线报警数据完毕"))
  9652. ))
  9653. {
  9654. AddMessage(logType, message); // 首页展示+日志记录
  9655. }
  9656. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  9657. {
  9658. StationName = stationNameStr,
  9659. SnNumber = snNumber,
  9660. Message = message,
  9661. CreateTime = DateTime.Now
  9662. };
  9663. // PLC交互页展示
  9664. Task.Run(() =>
  9665. {
  9666. try
  9667. {
  9668. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9669. {
  9670. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  9671. }
  9672. }
  9673. catch { }
  9674. });
  9675. }
  9676. /// <summary>
  9677. /// 添加运行日志
  9678. /// </summary>
  9679. /// <param name="logType">日志类型</param>
  9680. /// <param name="message">日志内容</param>
  9681. public void AddMessage(LogType logType, string message)
  9682. {
  9683. OnMessage(logType, message);
  9684. string date = DateTime.Now.ToString("yyyy/MM/dd");
  9685. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  9686. string msgShow = time + "--> " + message + "\r\n";
  9687. this.BeginInvoke(new Action(() =>
  9688. {
  9689. systemLog.Rows.Insert(0, date, time, message);
  9690. if (systemLog.Rows.Count >= 100)
  9691. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  9692. }));
  9693. }
  9694. /// <summary>
  9695. /// 添加运行日志-保存
  9696. /// </summary>
  9697. /// <param name="logType">日志类型</param>
  9698. /// <param name="message">日志内容</param>
  9699. private void OnMessage(LogType logType, string msg)
  9700. {
  9701. MessageEvent?.Invoke(logType, msg);
  9702. }
  9703. /// <summary>
  9704. /// 保存PLC写入日志
  9705. /// </summary>
  9706. /// <param name="logType"></param>
  9707. /// <param name="logValue"></param>
  9708. private void WritePLCLog(LogType logType, string logValue)
  9709. {
  9710. switch ((int)logType)
  9711. {
  9712. case 0:
  9713. _PLCLogNet.WriteDebug(logValue);
  9714. break;
  9715. case 1:
  9716. _PLCLogNet.WriteInfo(logValue);
  9717. break;
  9718. case 2:
  9719. _PLCLogNet.WriteWarn(logValue);
  9720. break;
  9721. case 3:
  9722. _PLCLogNet.WriteError(logValue);
  9723. break;
  9724. default:
  9725. _PLCLogNet.WriteFatal(logValue);
  9726. break;
  9727. }
  9728. }
  9729. /// <summary>
  9730. /// IOT Mqtt回调方法- With DataId
  9731. /// </summary>
  9732. /// <param name="id"></param>
  9733. /// <param name="v"></param>
  9734. /// <param name="dataId"></param>
  9735. public void CallbackWithDataId(string id, string msg, string dataId)
  9736. {
  9737. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  9738. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  9739. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  9740. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  9741. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  9742. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9743. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  9744. }
  9745. /// <summary>
  9746. /// AGV Mqtt回调方法- 记录Log并处理数据
  9747. /// </summary>
  9748. /// <param name="obj"></param>
  9749. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  9750. {
  9751. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9752. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  9753. // 接收到的信息
  9754. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  9755. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  9756. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  9757. {
  9758. }
  9759. }
  9760. #endregion 日志
  9761. /// <summary>
  9762. /// 实例化报警字典
  9763. /// </summary>
  9764. private void InitalDicAlarm()
  9765. {
  9766. #region 第一个工站(这里未区分工位,所以下面出现的‘工位代码’使用‘线别代码’代替)
  9767. List<Alarm> keyValues1 = new List<Alarm>
  9768. {
  9769. #region 第一组报警(电机)
  9770. new Alarm { 报警类型 = "电机故障", 报警详情 = "料盘搬运_Y轴电机故障" ,关联的PLC地址 = 5100 },
  9771. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_X轴电机故障" ,关联的PLC地址 = 5101 },
  9772. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_Z轴电机故障" ,关联的PLC地址 = 5102 },
  9773. new Alarm { 报警类型 = "电机故障", 报警详情 = "载具搬运_X轴电机故障" ,关联的PLC地址 = 5103 },
  9774. new Alarm { 报警类型 = "电机故障", 报警详情 = "镭射_X轴电机故障" ,关联的PLC地址 = 5104 },
  9775. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_X轴电机故障" ,关联的PLC地址 = 5105 },
  9776. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_Z轴电机故障" ,关联的PLC地址 = 5106 },
  9777. new Alarm { 报警类型 = "电机故障", 报警详情 = "下相机_X轴电机故障" ,关联的PLC地址 = 5107 },
  9778. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_Y轴电机故障" ,关联的PLC地址 = 5108 },
  9779. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_X轴电机故障" ,关联的PLC地址 = 5109 },
  9780. #endregion 第一组报警(电机)
  9781. #region 第二组报警(气缸)
  9782. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料进退气缸故障" ,关联的PLC地址 = 5200 },
  9783. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料升降气缸故障" ,关联的PLC地址 = 5201 },
  9784. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓顶升气缸故障" ,关联的PLC地址 = 5202 },
  9785. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体取料夹爪气缸故障" ,关联的PLC地址 = 5203 },
  9786. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料仓顶升气缸故障" ,关联的PLC地址 = 5204 },
  9787. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料平移气缸故障" ,关联的PLC地址 = 5205 },
  9788. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料升降气缸故障" ,关联的PLC地址 = 5206 },
  9789. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料夹爪气缸故障" ,关联的PLC地址 = 5207 },
  9790. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料旋转气缸故障" ,关联的PLC地址 = 5208 },
  9791. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装平移气缸故障" ,关联的PLC地址 = 5209 },
  9792. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装升降气缸故障" ,关联的PLC地址 = 5210 },
  9793. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装夹爪气缸故障" ,关联的PLC地址 = 5211 },
  9794. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装撑开气缸故障" ,关联的PLC地址 = 5212 },
  9795. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸1故障" ,关联的PLC地址 = 5213 },
  9796. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸2故障" ,关联的PLC地址 = 5214 },
  9797. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具下料移载气缸故障" ,关联的PLC地址 = 5215 },
  9798. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具侧推气缸故障" ,关联的PLC地址 = 5216 },
  9799. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具回流气缸故障" ,关联的PLC地址 = 5217 },
  9800. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2压料气缸故障" ,关联的PLC地址 = 5218 },
  9801. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2电测气缸故障" ,关联的PLC地址 = 5219 },
  9802. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2气密气缸故障" ,关联的PLC地址 = 5220 },
  9803. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3下压气缸故障" ,关联的PLC地址 = 5221 },
  9804. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3上顶气缸故障" ,关联的PLC地址 = 5222 },
  9805. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位5相机升降气缸故障" ,关联的PLC地址 = 5223 },
  9806. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组升降气缸故障" ,关联的PLC地址 = 5224 },
  9807. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸1故障" ,关联的PLC地址 = 5225 },
  9808. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸2故障" ,关联的PLC地址 = 5226 },
  9809. new Alarm { 报警类型 = "气缸故障", 报警详情 = "机械手夹爪气缸故障" ,关联的PLC地址 = 5227 },
  9810. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位4:镭射压料气缸故障" ,关联的PLC地址 = 5228 },
  9811. #endregion 第二组报警(气缸)
  9812. #region 第三组报警(其他故障)
  9813. new Alarm { 报警类型 = "其他故障", 报警详情 = "上料处缺料报警" ,关联的PLC地址 = 5300 },
  9814. new Alarm { 报警类型 = "其他故障", 报警详情 = "震盘缺料报警" ,关联的PLC地址 = 5301 },
  9815. new Alarm { 报警类型 = "其他故障", 报警详情 = "成品仓料满报警" ,关联的PLC地址 = 5302 },
  9816. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照超时报警" ,关联的PLC地址 = 5303 },
  9817. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照NG报警" ,关联的PLC地址 = 5304 },
  9818. new Alarm { 报警类型 = "其他故障", 报警详情 = "玻璃门打开报警" ,关联的PLC地址 = 5305 },
  9819. #endregion 第三组报警(其他故障)
  9820. };
  9821. DicAlarms_Cur.Add(GlobalContext.LineCode, keyValues1); // 这里使用线体代替工位
  9822. #endregion 第一个工站(这里使用线体代替工位)
  9823. # region 第二个工站-原来的写法(废弃)
  9824. //keyValues = new Dictionary<int, AlarmData[]>();
  9825. ////1
  9826. //dicAlarmName = new Dictionary<int, Alarm>();
  9827. //dicAlarmName.Add(0, new Alarm { Name = "M01衬套组模组X电机报警" });
  9828. //dicAlarmName.Add(1, new Alarm { Name = "M02衬套组模组Y电机报警" });
  9829. //dicAlarmName.Add(2, new Alarm { Name = "M03衬套组模组Z电机报警" });
  9830. //dicAlarmName.Add(3, new Alarm { Name = "M04衬套组模组U电机报警" });
  9831. //dicAlarmName.Add(4, new Alarm { Name = "M05外流线皮带电机报警" });
  9832. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9833. //for (int i = 0; i < dicAlarmName.Count; i++)
  9834. //{
  9835. // alarmDatas[i] = new AlarmData();
  9836. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9837. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9838. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9839. // alarmDatas[i].AlarmType = 1;
  9840. //}
  9841. //keyValues.Add(1, alarmDatas);
  9842. ////2
  9843. //dicAlarmName = new Dictionary<int, Alarm>();
  9844. //dicAlarmName.Add(0, new Alarm { Name = "C01定位气缸故障" });
  9845. //dicAlarmName.Add(1, new Alarm { Name = "C02左推料气缸故障" });
  9846. //dicAlarmName.Add(2, new Alarm { Name = "C03右推料气缸故障" });
  9847. //dicAlarmName.Add(3, new Alarm { Name = "C04左压料气缸故障" });
  9848. //dicAlarmName.Add(4, new Alarm { Name = "C05右压料气缸故障" });
  9849. //dicAlarmName.Add(5, new Alarm { Name = "C06切料气缸故障" });
  9850. //dicAlarmName.Add(6, new Alarm { Name = "C07左入料吹气气缸故障" });
  9851. //dicAlarmName.Add(7, new Alarm { Name = "C08右入料吹气气缸故障" });
  9852. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9853. //for (int i = 0; i < dicAlarmName.Count; i++)
  9854. //{
  9855. // alarmDatas[i] = new AlarmData();
  9856. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9857. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9858. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9859. // alarmDatas[i].AlarmType = 2;
  9860. //}
  9861. //keyValues.Add(2, alarmDatas);
  9862. ////3
  9863. //dicAlarmName = new Dictionary<int, Alarm>();
  9864. //dicAlarmName.Add(0, new Alarm { Name = "安全门报警" });
  9865. //dicAlarmName.Add(1, new Alarm { Name = "联机通信故障" });
  9866. //dicAlarmName.Add(2, new Alarm { Name = "连续NG报警" });
  9867. //dicAlarmName.Add(3, new Alarm { Name = "合格率低于设定值报警" });
  9868. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9869. //for (int i = 0; i < dicAlarmName.Count; i++)
  9870. //{
  9871. // alarmDatas[i] = new AlarmData();
  9872. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-3";
  9873. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9874. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9875. // alarmDatas[i].AlarmType = 3;
  9876. //}
  9877. //keyValues.Add(3, alarmDatas);
  9878. //DicAlarms.Add(2, keyValues);
  9879. #endregion 第二个工站-原来的写法(废弃)
  9880. }
  9881. private void button1_Click(object sender, EventArgs e)
  9882. {
  9883. OpenDailogFalg=true;
  9884. if (OpenDailogFalg)
  9885. {
  9886. using (var dialog = new BandBarodeDialog())
  9887. {
  9888. string strCarrierBarcode = "N801A-003";
  9889. dialog._CarrierBarcode = strCarrierBarcode;
  9890. string sn = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  9891. dialog._ProductBarcode = sn;
  9892. var rs = dialog.ShowDialog();
  9893. if (rs == DialogResult.OK)
  9894. {
  9895. AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
  9896. OpenDailogFalg = false;//关闭扫码
  9897. }
  9898. }
  9899. }
  9900. }
  9901. }
  9902. }