Form_Home.cs 581 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979
  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. /*
  40. * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  41. */
  42. namespace MainForm
  43. {
  44. /// <summary>
  45. /// 记录日志的委托
  46. /// </summary>
  47. /// <param name="logType">日志类型</param>
  48. /// <param name="message">日志信息</param>
  49. public delegate void HomeMessageHandler(LogType logType, string message);
  50. /// <summary>
  51. /// 主页窗体
  52. /// </summary>
  53. public partial class Form_Home : Form
  54. {
  55. #region 常量
  56. //文本常量
  57. private const string Head = "开始采集";
  58. private const string Tail = "采集完成";
  59. private const string Body = "工位出站数据";
  60. private const string BodyCheck = "工位点检数据";
  61. private const string BodyRun = "整线运行数据";
  62. private const string BodyAlarm = "整线报警数据";
  63. #endregion 常量
  64. #region 变量
  65. /// <summary>
  66. /// 委托-记录日志的方法
  67. /// </summary>
  68. public event HomeMessageHandler MessageEvent;
  69. /// <summary>
  70. /// 日志接口
  71. /// </summary>
  72. ILogNet _PLCLogNet;
  73. /// <summary>
  74. /// 用于记录IOT MQTT日志
  75. /// </summary>
  76. ILogNet _IOTMqttLogNet;
  77. /// <summary>
  78. /// 用于记录AGV MQTT日志
  79. /// </summary>
  80. ILogNet _AGVMqttLogNet;
  81. //private int DataSwitch = 1; // 1-SQLServer;2-Excel
  82. // 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
  83. // 间隔时间
  84. private int IntervalReadPLC = 300; //ms 读PLC
  85. private int IntervalMonitorMES = 1000; //ms MES心跳
  86. private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
  87. // 软件状态
  88. private bool IsRun = true;
  89. #region PLC 与 TCP对象
  90. // 定义一个字典,存plc对象(通讯)
  91. ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
  92. Dictionary<int, ModbusClientHelper> Funs = new Dictionary<int, ModbusClientHelper>();
  93. // 定义TCPClient对象列表
  94. Dictionary<int, HPSocket_TcpClientHelper> _HPSocket_TcpClients = new Dictionary<int, HPSocket_TcpClientHelper>();
  95. // 定义MQTTHelper对象
  96. MQTTHelper _MQTTHelper = new MQTTHelper();
  97. #endregion PLC 与 TCP对象
  98. /// <summary>
  99. /// 上次的设备运行信息
  100. /// </summary>
  101. private string lineWorkingData1_OldStr = string.Empty;
  102. /// <summary>
  103. /// 设备报警字典-当前结果
  104. /// Dictionary<工位代码,List<报警信息>>
  105. /// </summary>
  106. private Dictionary<string, List<Alarm>> DicAlarms_Cur = new Dictionary<string, List<Alarm>>();
  107. Dictionary<int, Inovance_EIP> FunsEip = new Dictionary<int, Inovance_EIP>();
  108. #endregion 变量
  109. #region 窗体基础事件
  110. /// <summary>
  111. /// 初始化
  112. /// </summary>
  113. public Form_Home()
  114. {
  115. InitializeComponent();
  116. CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
  117. _PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  118. _IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  119. _AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
  120. GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
  121. }
  122. /// <summary>
  123. /// 窗体加载事件
  124. /// </summary>
  125. private void Form_Home_Load(object sender, EventArgs e)
  126. {
  127. try
  128. {
  129. AddMessage(LogType.Info, "开始初始化程序");
  130. InitalDicAlarm(); // 实例化报警字典
  131. //组建plc对象字典
  132. //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
  133. //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
  134. if (GlobalContext.IsUsePLC1)
  135. FunsEip.Add(1, new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
  136. //Funs.Add(1, new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort, 2001)); // Tray盘上料装备(板测)
  137. if (GlobalContext.IsUsePLC2)
  138. //Funs.Add(2, new ModbusClientHelper(GlobalContext.Machine2Address, GlobalContext.MachinePort, 2001)); // FCT(板测),
  139. FunsEip.Add(2, new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
  140. if (GlobalContext.IsUsePLC3)
  141. FunsEip.Add(3, new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
  142. //Funs.Add(3, new ModbusClientHelper(GlobalContext.Machine3Address, GlobalContext.MachinePort, 2001)); // 值板机,
  143. if (GlobalContext.IsUsePLC4)
  144. FunsEip.Add(4, new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
  145. //Funs.Add(4, new ModbusClientHelper(GlobalContext.Machine4Address, GlobalContext.MachinePort, 2001)); // 取放桁
  146. if (GlobalContext.IsUsePLC5)
  147. FunsEip.Add(5, new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
  148. //Funs.Add(5, new ModbusClientHelper(GlobalContext.Machine5Address, GlobalContext.MachinePort, 2001)); //Tray盘下料装备
  149. if (GlobalContext.IsUsePLC6)
  150. FunsEip.Add(6, new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
  151. if (GlobalContext.IsUsePLC7)
  152. FunsEip.Add(7, new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
  153. if (GlobalContext.IsUsePLC8)
  154. FunsEip.Add(8, new Inovance_EIP(GlobalContext.PC8Address, GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
  155. if (GlobalContext.IsUsePLC9)
  156. FunsEip.Add(9, new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
  157. foreach (Inovance_EIP plcEIP in FunsEip.Values)
  158. {
  159. if (plcEIP != null)
  160. {
  161. try
  162. {
  163. (int, string) result = plcEIP.Connect();
  164. }
  165. catch (Exception ex)
  166. {
  167. MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
  168. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  169. }
  170. }
  171. }
  172. /*
  173. //plc1Alarm.Connect();
  174. foreach (ModbusClientHelper modbusClient in Funs.Values)
  175. {
  176. if (modbusClient != null)
  177. {
  178. try
  179. {
  180. modbusClient.Connect();
  181. }
  182. catch (Exception ex)
  183. {
  184. MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
  185. "PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  186. }
  187. }
  188. }
  189. */
  190. // 采集任务
  191. Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
  192. List<Task> TaskReadProcess = new List<Task>(); // 线程-触发点位(PLC)的线程
  193. //TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
  194. if (GlobalContext.IsUsePLC1)
  195. TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
  196. if (GlobalContext.IsUsePLC2)
  197. TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
  198. if (GlobalContext.IsUsePLC3)
  199. TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
  200. if (GlobalContext.IsUsePLC4)
  201. TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
  202. if (GlobalContext.IsUsePLC5)
  203. TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
  204. if (GlobalContext.IsUsePLC6)
  205. TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
  206. if (GlobalContext.IsUsePLC7)
  207. TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
  208. if (GlobalContext.IsUsePLC8)
  209. TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
  210. if (GlobalContext.IsUsePLC9)
  211. TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
  212. #region 初始化
  213. try
  214. {
  215. // 开启边线MES(绑定/查询数据)
  216. //int mesRoute = XiaomiMES_RouteCommunication.Init();
  217. //if (mesRoute == 0)
  218. //{
  219. // //picMESStatus.Image = imageListState.Images[1];
  220. // //GlobalContext.MESIsConnect = true;
  221. // AddMessage(LogType.Info, "小米MES边线初始连接成功!");
  222. //}
  223. //else
  224. //{
  225. // //picMESStatus.Image = imageListState.Images[0];
  226. // //GlobalContext.MESIsConnect = false;
  227. // AddMessage(LogType.Info, $"小米MES边线初始连接失败!");
  228. //}
  229. // 开启MES(Http)
  230. if (GlobalContext.IsUseMES)
  231. {
  232. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  233. if (mesret)
  234. {
  235. picMESStatus.Image = imageListState.Images[1];
  236. GlobalContext.MESIsConnect = true;
  237. AddMessage(LogType.Info, "小米MES初始连接成功!");
  238. }
  239. else
  240. {
  241. picMESStatus.Image = imageListState.Images[0];
  242. GlobalContext.MESIsConnect = false;
  243. AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
  244. }
  245. }
  246. // 开启IOT(MQTT)
  247. if (GlobalContext.IsUseIot)
  248. {
  249. string addr = GlobalContext.MQTTServerHost;
  250. int port = GlobalContext.MQTTServerPort;
  251. //生产环境需要修改
  252. int qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666, 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. // 设置回调函数
  259. XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  260. // 配置参数
  261. XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
  262. // fds
  263. param.parameter.fds.address = "http://file-cm.be.mi.com/file/x5/file/upload/mqtt";
  264. param.parameter.fds.appId = "Auto-Soft";
  265. param.parameter.fds.appKey = "d11ec2b9-0e7a-4086-a80c-a1ec716e0896";
  266. // mes
  267. param.parameter.mes.address = GlobalContext.ServerIp;
  268. param.parameter.mes.appId = GlobalContext.MESAppId;
  269. param.parameter.mes.appKey = GlobalContext.MESAppKey;
  270. // mqtt
  271. param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
  272. param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
  273. param.parameter.mqtt.username = GlobalContext.MQTTAppId;
  274. param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
  275. // 设备配置
  276. param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
  277. if (GlobalContext.IsUsePLC1)
  278. {
  279. param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
  280. param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
  281. }
  282. if (GlobalContext.IsUsePLC2)
  283. {
  284. param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
  285. param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
  286. }
  287. if (GlobalContext.IsUsePLC3)
  288. {
  289. param.parameter.equipment.deviceCode = GlobalContext.S3_device_code; // 装备编码
  290. param.parameter.equipment.stationCode = GlobalContext.S3_station; // ⼯位Id
  291. }
  292. if (GlobalContext.IsUsePLC4)
  293. {
  294. param.parameter.equipment.deviceCode = GlobalContext.S4_1_device_code; // 装备编码
  295. param.parameter.equipment.stationCode = GlobalContext.S4_1_station; // ⼯位Id
  296. }
  297. if (GlobalContext.IsUsePLC5)
  298. {
  299. param.parameter.equipment.deviceCode = GlobalContext.S5_device_code; // 装备编码
  300. param.parameter.equipment.stationCode = GlobalContext.S5_station; // ⼯位Id
  301. }
  302. if (GlobalContext.IsUsePLC6)
  303. {
  304. param.parameter.equipment.deviceCode = GlobalContext.S6_device_code; // 装备编码
  305. param.parameter.equipment.stationCode = GlobalContext.S6_station; // ⼯位Id
  306. }
  307. if (GlobalContext.IsUsePLC7)
  308. {
  309. param.parameter.equipment.deviceCode = GlobalContext.S7_device_code; // 装备编码
  310. param.parameter.equipment.stationCode = GlobalContext.S7_station; // ⼯位Id
  311. }
  312. if (GlobalContext.IsUsePLC8)
  313. {
  314. param.parameter.equipment.deviceCode = GlobalContext.S8_device_code; // 装备编码
  315. param.parameter.equipment.stationCode = GlobalContext.S8_station; // ⼯位Id
  316. }
  317. if (GlobalContext.IsUsePLC9)
  318. {
  319. param.parameter.equipment.deviceCode = GlobalContext.S9_device_code; // 装备编码
  320. param.parameter.equipment.stationCode = GlobalContext.S9_station; // ⼯位Id
  321. }
  322. param.parameter.equipment.project = GlobalContext.Project_Code;
  323. param.parameter.equipment.productMode = "debug";
  324. //
  325. param.parameter.other.logLevel = 0;
  326. param.parameter.other.LogPath = "D:\\Test";
  327. XiaomiMqttClient_Extend.ParameterConfig(param);
  328. }
  329. else
  330. {
  331. picIot.Image = imageListState.Images[0];
  332. AddMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  333. }
  334. }
  335. // 开启AGV(Http与MQTT)
  336. if (GlobalContext.IsUseAGV)
  337. {
  338. // AGV HTTP
  339. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  340. if (mesret1)
  341. {
  342. picAgvHttp.Image = imageListState.Images[1];
  343. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  344. }
  345. else
  346. {
  347. picAgvHttp.Image = imageListState.Images[0];
  348. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  349. }
  350. string agvMqttIp = GlobalContext.MQTTServerHost;
  351. int agvMqttPort = GlobalContext.MQTTServerPort;
  352. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  353. ResultData_MQTT result_MQTT = _MQTTHelper.CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  354. // AGV MQTT
  355. if (result_MQTT.ResultCode == 1)
  356. {
  357. picAgvMqtt.Image = imageListState.Images[1];
  358. GlobalContext.AGVMQTTIsConnect = true;
  359. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  360. ResultData_MQTT result = XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  361. AddMessage(LogType.Info, $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  362. }
  363. else
  364. {
  365. picAgvMqtt.Image = imageListState.Images[0];
  366. GlobalContext.AGVMQTTIsConnect = false;
  367. AddMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  368. }
  369. }
  370. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  371. Task.Run(MonitorMESConnect);
  372. // 查询PLC连接状态
  373. foreach (int plcNo in FunsEip.Keys)
  374. {
  375. bool connected = FunsEip[plcNo].IsConnected;
  376. if (connected)
  377. {
  378. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  379. AddMessage(LogType.Info, msg);
  380. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  381. }
  382. else
  383. {
  384. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  385. AddMessage(LogType.Info, msg);
  386. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  387. }
  388. }
  389. // PLC4时 初始化扫码器TCP
  390. //if (GlobalContext.IsUsePLC4)
  391. // HpTCPClientInit();
  392. // 开启PLC的业务处理线程-监听PLC点位+状态
  393. foreach (Task task in TaskReadProcess)
  394. {
  395. if (task != null)
  396. task.Start();
  397. }
  398. //// 开启“获取线体报警数据”的线程
  399. //TaskReadAlarm.Start();
  400. ////下传MES信息给1工位(先判断下plc对象数量)
  401. //if (Funs.Count > 1)
  402. // DownLoadProductInfo(1);
  403. AddMessage(LogType.Info, "程序初始化完成");
  404. }
  405. catch (Exception ex)
  406. {
  407. string str = ex.StackTrace;
  408. this.BeginInvoke(new Action(() =>
  409. {
  410. AddMessage(LogType.Error, "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  411. }));
  412. }
  413. #endregion
  414. }
  415. catch (Exception ex)
  416. {
  417. string str = ex.StackTrace;
  418. OnMessage(LogType.Info, "主窗体的首页初始化出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  419. if (ex.Message != null && ex.Message.Contains("timed out"))
  420. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  421. else
  422. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  423. }
  424. }
  425. /// <summary>
  426. /// 窗体关闭事件
  427. /// </summary>
  428. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  429. {
  430. Closed2();
  431. }
  432. public void Closed2()
  433. {
  434. try
  435. {
  436. IsRun = false;
  437. Thread.Sleep(IntervalReadPLC);
  438. // 断开TCP
  439. int count = _HPSocket_TcpClients.Count();
  440. for (int i = 0; i < count; i++)
  441. {
  442. try
  443. {
  444. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  445. {
  446. _HPSocket_TcpClients[i].Stop();
  447. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  448. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  449. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  450. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  451. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  452. }
  453. }
  454. catch { }
  455. }
  456. // 关闭Iot
  457. try { XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath, GlobalContext.MqttServerName); } catch { }
  458. // 关闭AGV Mqtt
  459. try { _MQTTHelper.DisconnectAsync_Client().Wait(); } catch { }
  460. }
  461. catch { }
  462. }
  463. #endregion 窗体基础事件
  464. #region 监控MES状态
  465. /// <summary>
  466. /// 监控MES连接状态
  467. /// </summary>
  468. private void MonitorMESConnect()
  469. {
  470. while (IsRun) // 运行被控线程
  471. {
  472. try
  473. {
  474. // 开启MES(Http)
  475. if (GlobalContext.IsUseMES)
  476. {
  477. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  478. if (mesret)
  479. {
  480. picMESStatus.Image = imageListState.Images[1];
  481. GlobalContext.MESIsConnect = true;
  482. }
  483. else
  484. {
  485. picMESStatus.Image = imageListState.Images[0];
  486. GlobalContext.MESIsConnect = false;
  487. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  488. }
  489. }
  490. // 开启IOT(MQTT)
  491. if (GlobalContext.IsUseIot)
  492. {
  493. bool iIot = XiaomiMqttClient.IsOpen;
  494. if (iIot)
  495. picIot.Image = imageListState.Images[1];
  496. else
  497. {
  498. picIot.Image = imageListState.Images[0];
  499. OnMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  500. }
  501. }
  502. // 开启AGV(Http与MQTT)
  503. if (GlobalContext.IsUseAGV)
  504. {
  505. // AGV Http
  506. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  507. if (mesret1)
  508. picAgvHttp.Image = imageListState.Images[1];
  509. else
  510. {
  511. picAgvHttp.Image = imageListState.Images[0];
  512. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  513. }
  514. // AGV MQTT
  515. if (GlobalContext.AGVMQTTIsConnect)
  516. picAgvMqtt.Image = imageListState.Images[1];
  517. else
  518. {
  519. picAgvMqtt.Image = imageListState.Images[0];
  520. OnMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  521. }
  522. }
  523. }
  524. catch (Exception ex)
  525. {
  526. string str = ex.StackTrace;
  527. AddMessage(LogType.Error, "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  528. }
  529. Thread.Sleep(IntervalMonitorMES);
  530. }
  531. }
  532. #endregion 监控MES连接状态
  533. #region 采集设备状态、运行数据、报警数据
  534. /// <summary>
  535. /// 请求设备状态 5000
  536. /// </summary>
  537. /// <param name="no">1</param>
  538. /// <param name="stationNameStr"></param>
  539. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  540. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  541. {
  542. try
  543. {
  544. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  545. {
  546. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  547. return result;
  548. }
  549. else
  550. {
  551. return 0;
  552. }
  553. }
  554. catch (Exception ex)
  555. {
  556. string str = ex.StackTrace;
  557. AddMessage_Station(stationNameStr, LogType.Error, "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  558. return 0;
  559. }
  560. }
  561. /// <summary>
  562. /// 检查是否可采集点检数据 - 不取新值
  563. /// 5000不为1时可点检
  564. /// </summary>
  565. /// <returns></returns>
  566. public bool CheckCanSpotcheck1(int deviceState)
  567. {
  568. //return true;
  569. //D5000 = 1,代表设备控制状态处于运行状态
  570. //D5000 = 2, 代表设备控制状态处于故障状态
  571. //D5000 = 3,代表设备控制状态处于缺料状态
  572. //D5000 = 4, 代表设备控制状态处于待机状态
  573. //D5000 = 5,代表设备控制状态处于维修状态
  574. return deviceState != 1;
  575. }
  576. /// <summary>
  577. /// 检查是否可采集产品数据 - 不取新值
  578. /// </summary>
  579. /// <returns></returns>
  580. public bool CheckCanCollData(int deviceState)
  581. {
  582. return deviceState == 0; // 点检时该值不为0
  583. }
  584. /// <summary>
  585. /// 获取设备报警数据与获取设备运行信息
  586. /// </summary>
  587. private async void ReadAlarmAllPLC()
  588. {
  589. // [S1] Tray盘上料装备(板测)
  590. // [S2] FCT(板测)
  591. // [S3] 值板机
  592. // [S4] 取放桁架
  593. // [S5] Tray盘下料装备
  594. /// 上位机心跳
  595. /// 获取设备报警数据与状态信息
  596. string stationNameStr = "获取设备报警数据与状态信息";
  597. while (IsRun)
  598. {
  599. try
  600. {
  601. if (!GlobalContext._IsCon_plc1Alarm)
  602. {
  603. UpdatePLCMonitor(1, -2, 0);
  604. continue;
  605. }
  606. if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  607. {
  608. DateTime dtNow = DateTime.Now;
  609. #region 获取设备运行信息
  610. try
  611. {
  612. LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  613. lineWorkingData1.GUID = Guid.NewGuid().ToString();
  614. lineWorkingData1.LineName = GlobalContext.LineCode;
  615. //
  616. lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  617. lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  618. lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  619. lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  620. lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  621. lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  622. lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  623. lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  624. lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  625. lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  626. lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  627. lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  628. lineWorkingData1.CreateTime = DateTime.Now;
  629. string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  630. // UI展示-展示到设备状态页
  631. if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  632. {
  633. // 查询数据库最新一条数据,确定是不是更新
  634. string qSql = @"SELECT top(1) [GUID]
  635. ,[LineName]
  636. ,[BootTimeLong]
  637. ,[NormalTimeLong]
  638. ,[StandbyTimeLong]
  639. ,[FaultTimeLong]
  640. ,[MaterialShortageTimeLong]
  641. ,[MaintenanceTimeLong]
  642. ,[FaultNumber]
  643. ,[OutputNumber]
  644. ,[QualifiedNumber]
  645. ,[QualifiedRate]
  646. ,[DesignRhythm]
  647. ,[RealityRhythm]
  648. ,[CreateTime]
  649. FROM [LineWorkingData]
  650. where [CreateTime] > '{0}'
  651. and [LineName]='{1}'
  652. order by [CreateTime] desc
  653. ";
  654. qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  655. var ds = SQLHelper_New.Query(qSql, null);
  656. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  657. {
  658. var dataDBlast = new LineWorkingData_ThisTime();
  659. dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  660. dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  661. dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  662. dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  663. if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  664. {
  665. dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  666. dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  667. dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  668. dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  669. dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  670. dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  671. dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  672. dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  673. dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  674. dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  675. dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  676. dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  677. string usql = dataDBlast.ToStringUpdate();
  678. SQLHelper_New.ExecuteSQL(usql, null);
  679. lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  680. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  681. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  682. }
  683. }
  684. else
  685. {
  686. // 插入
  687. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  688. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  689. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  690. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  691. }
  692. }
  693. else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  694. {
  695. LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  696. //// 本次开机设备运行情况
  697. //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  698. //Task.Run(() =>
  699. //{
  700. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  701. // {
  702. // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  703. // }
  704. //});
  705. // 本日设备运行情况
  706. // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  707. if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  708. {
  709. // 更新
  710. lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  711. lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  712. lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  713. lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  714. lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  715. lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  716. lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  717. lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  718. lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  719. lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  720. lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  721. lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  722. SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  723. lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  724. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  725. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  726. }
  727. else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  728. {
  729. // 插入
  730. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  731. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  732. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  733. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  734. }
  735. await Task.Run(() =>
  736. {
  737. try
  738. {
  739. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  740. {
  741. Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  742. }
  743. }
  744. catch { }
  745. });
  746. }
  747. }
  748. catch (Exception ex)
  749. {
  750. string str = ex.StackTrace;
  751. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  752. }
  753. #endregion 获取设备运行信息
  754. #region 报警数据
  755. try
  756. {
  757. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  758. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  759. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  760. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  761. for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  762. {
  763. short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  764. dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  765. if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  766. {
  767. isNeedUpdUI = true; // 需要更新历史报警UI信息
  768. // 记录
  769. dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  770. switch (dicAlarms_Cur_PLC1[i].是否报警)
  771. {
  772. case true: // 报警
  773. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  774. {
  775. GUID = Guid.NewGuid().ToString(),
  776. LineName = GlobalContext.LineCode, // 线体
  777. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  778. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  779. StartTime = dtNow // 开始时间
  780. };
  781. // 传输到页面
  782. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  783. {
  784. 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  785. 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  786. 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  787. 开始时间 = dtNow
  788. });
  789. // 新增到数据库
  790. var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  791. SaveAlarmDataByDB(stationNameStr, data1, false);
  792. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  793. break;
  794. case false: // 消除报警
  795. if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  796. {
  797. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  798. {
  799. GUID = Guid.NewGuid().ToString(),
  800. LineName = GlobalContext.LineCode, // 线体
  801. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  802. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  803. StartTime = dtNow, // 开始时间
  804. EndTime = dtNow, // 开始时间
  805. PersistTime = 1, // 耗时1s
  806. };
  807. // 新增
  808. var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  809. SaveAlarmDataByDB(stationNameStr, data2, false);
  810. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  811. }
  812. else
  813. {
  814. dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  815. dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  816. - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  817. // 修改
  818. var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  819. SaveAlarmDataByDB(stationNameStr, data3, true);
  820. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  821. }
  822. break;
  823. default:
  824. break;
  825. }
  826. }
  827. }
  828. DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  829. // 有新报警则更新
  830. if (isNeedUpdUI)
  831. {
  832. // UI展示 - 展示到设备状态页
  833. await Task.Run(() =>
  834. {
  835. try
  836. {
  837. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  838. {
  839. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  840. if (Form_Main.formDevAlarm.Visible)
  841. {
  842. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  843. }
  844. }
  845. }
  846. catch { }
  847. });
  848. }
  849. }
  850. catch (Exception ex)
  851. {
  852. string str = ex.StackTrace;
  853. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  854. }
  855. #endregion 报警数据
  856. UpdatePLCMonitor(1, -2, 1);
  857. }
  858. else
  859. {
  860. UpdatePLCMonitor(1, -2, 0);
  861. }
  862. }
  863. catch (Exception ex)
  864. {
  865. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  866. }
  867. Thread.Sleep(IntervalAlarm);
  868. }
  869. }
  870. #endregion 轮询PLC
  871. #region 下发订单信息
  872. ///// <summary>
  873. ///// 壳体上料(下发工单)的交互逻辑
  874. ///// </summary>
  875. ///// <param name="no"></param>
  876. ///// <exception cref="NotImplementedException"></exception>
  877. //private void ReadStation_DownOrderInfo(int plcNo)
  878. //{
  879. // // [S1] Tray盘上料装备(板测)
  880. // // [S2] FCT(板测)
  881. // // [S3] 值板机
  882. // // [S4] 取放桁架
  883. // // [S5] Tray盘下料装备
  884. // /// 上位机心跳
  885. // /// 获取设备报警数据与状态信息
  886. // string stationNameStr = "[S0]壳体上料";
  887. // while (IsRun)
  888. // {
  889. // try
  890. // {
  891. // if (!GlobalContext._IsCon_Funs1)
  892. // {
  893. // UpdatePLCMonitor(plcNo, 0);
  894. // continue;
  895. // }
  896. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  897. // {
  898. // #region 壳体上料(下发工单)
  899. // try
  900. // {
  901. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  902. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  903. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  904. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  905. // // 重置数据和信号
  906. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  907. // {
  908. // // 清空写给PLC的数据
  909. // int[] i497 = new int[1] { 0 };
  910. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  911. // // MES_Flag重置为0
  912. // int[] i500 = new int[1] { 0 };
  913. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  914. // }
  915. // }
  916. // catch (Exception ex)
  917. // {
  918. // string str = ex.StackTrace;
  919. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  920. // }
  921. // #endregion 壳体上料(下发工单)
  922. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  923. // }
  924. // else
  925. // {
  926. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  927. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  928. //
  929. // Funs[plcNo].Connect();
  930. // }
  931. // }
  932. // catch (Exception ex)
  933. // {
  934. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  935. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  936. //
  937. // Funs[plcNo].ReConnect();
  938. // }
  939. // Thread.Sleep(IntervalReadPLC);
  940. // }
  941. //}
  942. ///// <summary>
  943. ///// 下发订单信息到PLC
  944. ///// </summary>
  945. ///// <param name="no">PLC编号</param>
  946. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  947. //{
  948. // try
  949. // {
  950. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  951. // {
  952. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  953. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  954. // }
  955. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  956. // }
  957. // catch (Exception ex)
  958. // {
  959. // string str = ex.StackTrace;
  960. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  961. // }
  962. //}
  963. /// <summary>
  964. /// 下发清料信号
  965. /// </summary>
  966. /// <param name="no">PLC编号</param>
  967. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  968. {
  969. try
  970. {
  971. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  972. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  973. return true;
  974. }
  975. catch (Exception ex)
  976. {
  977. string str = ex.StackTrace;
  978. AddMessage_Station(stationNameStr, LogType.Error, "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  979. return false;
  980. }
  981. }
  982. #endregion 下发订单信息
  983. #region Xiaomi 贲流
  984. #region 公共方法
  985. private static bool ProgressState = false;
  986. private static readonly object lockObj = new object(); // 锁对象
  987. private static bool isCollectingFlagLeft;
  988. private static bool isCollectingFlagRight;
  989. /// <summary>
  990. /// float[]转为string
  991. /// </summary>
  992. public string FloatArrayToString(float[] nScrewResults)
  993. {
  994. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  995. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  996. }
  997. /// <summary>
  998. /// short[]转为string
  999. /// </summary>
  1000. public string ShortArrayToString(short[] nScrewResults)
  1001. {
  1002. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  1003. return string.Join(",", nScrewResults);
  1004. }
  1005. /// <summary>
  1006. /// 写入PLC重复三次
  1007. /// </summary>
  1008. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount, T inObj)
  1009. {
  1010. int i = 0;
  1011. int nRet = 0;
  1012. string strRet = "";
  1013. try
  1014. {
  1015. while (i < 3) // 最多上传三次
  1016. {
  1017. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  1018. if (nRet == 0) //成功
  1019. {
  1020. break;
  1021. }
  1022. else
  1023. {
  1024. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  1025. i++;
  1026. }
  1027. }
  1028. return (nRet, strRet);
  1029. }
  1030. catch (Exception ex)
  1031. {
  1032. return (1, ex.Message);
  1033. }
  1034. }
  1035. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes, short[] nScrewOrders, short[] nScrewResults)
  1036. {
  1037. try
  1038. {
  1039. // 获取当前日期
  1040. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1041. // 构建保存路径
  1042. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  1043. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction,"螺丝Mes数据");
  1044. // 确保目录存在
  1045. Directory.CreateDirectory(savePath);
  1046. // 文件名
  1047. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  1048. string filePath = Path.Combine(savePath, fileName);
  1049. // 确保不会超出数组长度,只取前14个或数组的实际长度
  1050. int count = Math.Min(14, fScrewTimes.Length);
  1051. using (StreamWriter sw = new StreamWriter(filePath))
  1052. {
  1053. for (int i = 0; i < count; i++)
  1054. {
  1055. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  1056. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  1057. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  1058. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  1059. sw.WriteLine(); // 空行分隔不同螺丝的信息
  1060. }
  1061. }
  1062. return (0, "");
  1063. }
  1064. catch (Exception ex)
  1065. {
  1066. return (1, ex.Message);
  1067. }
  1068. }
  1069. /// <summary>
  1070. /// 调用进站接口并保存进站数据
  1071. /// </summary>
  1072. /// <param name="stationNameStr">工站信息</param>
  1073. /// <param name="workorder_code">工单号</param>
  1074. /// <param name="mtltmrk">型号(物料号)</param>
  1075. /// <param name="sn">产品SN</param>
  1076. /// <param name="items">进站数据</param>
  1077. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1078. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn, List<TestItem> items, string MachineId, string StationId)
  1079. {
  1080. int result = 0;
  1081. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1082. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1083. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1084. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1085. inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1086. inRequest_Body.unitSn = sn; // 产品SN
  1087. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1088. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1089. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1090. StationIn stationIn = new StationIn()
  1091. {
  1092. Workorder_code = workorder_code, // 车间订单号
  1093. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1094. Sn = sn, // SN
  1095. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1096. Parameter_values = items, // 进站数据
  1097. Write_user = inRequest_Body.userId, // 员工Id
  1098. Test_time = inRequest_Body.clientTime // 进站时间
  1099. };
  1100. // 本地数据
  1101. string sql = stationIn.ToStringInsert(0);
  1102. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1103. result = ret == "成功" ? 1 : 6;
  1104. //await Task.Delay(200);
  1105. // 上传MES
  1106. if (GlobalContext.IsSendStationIn)
  1107. {
  1108. try
  1109. {
  1110. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1111. string mesRet = string.Empty;
  1112. int i = 0;
  1113. while (i < 2) // 1009会多次尝试上传
  1114. {
  1115. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1116. if (response != null && response.header.code == "200")
  1117. break;
  1118. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1119. i++;
  1120. i++;
  1121. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1122. // 记录失败原因
  1123. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + json_Body);
  1124. }
  1125. if (response?.header?.code == "200")
  1126. {
  1127. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1128. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1129. result = ret_Upd == "成功" ? 1 : 6;
  1130. AddMessage( LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功");
  1131. }
  1132. else
  1133. {
  1134. result = 5;
  1135. AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1136. }
  1137. string sql_response = stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1138. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1139. }
  1140. catch (Exception ex)
  1141. {
  1142. result = 6;
  1143. string str = ex.StackTrace;
  1144. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1145. }
  1146. }
  1147. return result;
  1148. }
  1149. /// <summary>
  1150. /// 选择如何记录出站数据
  1151. /// </summary>
  1152. /// <param name="items">出站数据</param>
  1153. /// <param name="equipmentCode">设备编号</param>
  1154. /// <param name="processItem">测试项目</param>
  1155. /// <param name="workorder_code">车间订单号</param>
  1156. /// <param name="batch_num">批次号</param>
  1157. /// <param name="mtltmrk">型号</param>
  1158. /// <param name="proDate">日期</param>
  1159. /// <param name="supplierCode">供应商代码</param>
  1160. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1161. /// <returns>上传成功时返回1;失败返回0</returns>
  1162. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode, string processItem,
  1163. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1164. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode)
  1165. {
  1166. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
  1167. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode);
  1168. }
  1169. /// <summary>
  1170. /// 添加出站数据(提交到MES+本地保存到数据库)
  1171. /// </summary>
  1172. /// <param name="items">出站数据</param>
  1173. /// <param name="equipmentCode">设备编号</param>
  1174. /// <param name="processItem">测试项目</param>
  1175. /// <param name="workorder_code">车间订单号</param>
  1176. /// <param name="batch_num">批次号</param>
  1177. /// <param name="mtltmrk">型号</param>
  1178. /// <param name="proDate">日期</param>
  1179. /// <param name="supplierCode">供应商代码</param>
  1180. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1181. /// <returns>上传成功时返回1;失败返回0</returns>
  1182. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1183. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1184. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode)
  1185. {
  1186. int upload = 0;
  1187. int result = 0;
  1188. ProcessData processData = new ProcessData()
  1189. {
  1190. Equipment_code = equipmentCode,
  1191. Workorder_code = workorder_code,
  1192. Batch_number = batch_num,
  1193. Sn = sn, // SN
  1194. Testitem = processItem,
  1195. Parameter_values = items,
  1196. Write_user = GlobalContext.CurrentUser,
  1197. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1198. };
  1199. // 本地数据
  1200. string sql = processData.ToStringInsert(upload);
  1201. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1202. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1203. // 上传MES
  1204. if (GlobalContext.IsSendProcessData)
  1205. {
  1206. try
  1207. {
  1208. string id = processData.ID.Copy();
  1209. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1210. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1211. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1212. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1213. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1214. outRequest_Body.unitSn = sn; // 产品SN
  1215. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1216. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1217. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1218. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1219. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1220. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1221. if (!string.IsNullOrEmpty(partBarcode))
  1222. {
  1223. outRequest_Body.unitData.keyMaterial.Add(
  1224. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1225. {
  1226. bindSort = 1,
  1227. materialSn = partBarcode
  1228. }); // 设备数据 - 部件码
  1229. }
  1230. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1231. if (GlobalContext.IsSendProcessData)
  1232. {
  1233. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1234. string mesRet = string.Empty;
  1235. int i = 0;
  1236. while (i < 2) // 1009会多次尝试上传
  1237. {
  1238. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1239. if (response != null && response.header.code == "200")
  1240. break;
  1241. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1242. i++;
  1243. i++;
  1244. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1245. // 记录失败原因
  1246. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1247. }
  1248. if (response?.header?.code == "200")
  1249. {
  1250. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1251. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1252. result = 1;
  1253. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1254. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1255. }
  1256. else
  1257. {
  1258. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:"+ mesRet);
  1259. }
  1260. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(JsonConvert.SerializeObject(outRequest_Body),
  1261. JsonConvert.SerializeObject(response), id);
  1262. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1263. }
  1264. }
  1265. catch (Exception ex)
  1266. {
  1267. string str = ex.StackTrace;
  1268. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1269. }
  1270. }
  1271. return result;
  1272. }
  1273. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1274. //{
  1275. // Stopwatch stopwatch = new Stopwatch();
  1276. // stopwatch.Start();
  1277. // try
  1278. // {
  1279. // // 初始化 AtlasScrew 实例
  1280. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1281. // atlasScrew1.Initial();
  1282. // // 存储结果的列表
  1283. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1284. // // 存储角度和扭力的字符串列表
  1285. // List<string> angleStrs = new List<string>();
  1286. // List<string> torqueStrs = new List<string>();
  1287. // // 上一次获取的数据
  1288. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1289. // while (isExitAtlasLeft) // 检查是否收集数据
  1290. // {
  1291. // // 获取当前数据
  1292. // var currentResult = atlasScrew1.GetResults();
  1293. // // 判断是否为新数据
  1294. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1295. // {
  1296. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1297. // // 更新角度和扭力的字符串列表
  1298. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1299. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1300. // // 计算角度、扭力、起始扭力和最大扭力
  1301. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1302. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1303. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1304. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1305. // // 将新数据添加到结果列表
  1306. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1307. // // 更新上一次获取的数据
  1308. // lastResult = currentResult;
  1309. // }
  1310. // // 等待一段时间后再次检查
  1311. // Thread.Sleep(20); // 轮询间隔时间
  1312. // // 如果触发了出站,则退出循环
  1313. // if (!isExitAtlasLeft)
  1314. // {
  1315. // break;
  1316. // }
  1317. // }
  1318. // // 生成文件名
  1319. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1320. // // 写入数据到文件
  1321. // using (StreamWriter writer = new StreamWriter(fileName))
  1322. // {
  1323. // // 写入标题行
  1324. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1325. // // 写入每一行数据
  1326. // foreach (var result in results)
  1327. // {
  1328. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1329. // }
  1330. // }
  1331. // stopwatch.Stop();
  1332. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1333. // }
  1334. // catch (Exception ex)
  1335. // {
  1336. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1337. // }
  1338. // finally
  1339. // {
  1340. // // 重置标志变量
  1341. // isExitAtlasLeft = false;
  1342. // }
  1343. //}
  1344. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1345. //{
  1346. // Stopwatch stopwatch = new Stopwatch();
  1347. // stopwatch.Start();
  1348. // try
  1349. // {
  1350. // // 初始化 AtlasScrew 实例
  1351. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1352. // atlasScrew2.Initial();
  1353. // // 存储结果的列表
  1354. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1355. // // 上一次获取的数据
  1356. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1357. // while (isExitAtlasRight) // 检查是否收集数据
  1358. // {
  1359. // // 获取当前数据
  1360. // var currentResult = atlasScrew2.GetResults();
  1361. // // 判断是否为新数据
  1362. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1363. // {
  1364. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1365. // // 将新数据写入PLC
  1366. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1367. // // 将新数据添加到结果列表
  1368. // results.Add(currentResult);
  1369. // // 更新上一次获取的数据
  1370. // lastResult = currentResult;
  1371. // }
  1372. // // 等待一段时间后再次检查
  1373. // Thread.Sleep(20); // 轮询间隔时间
  1374. // // 如果触发了出站,则退出循环
  1375. // if (!isExitAtlasRight)
  1376. // {
  1377. // break;
  1378. // }
  1379. // }
  1380. // // 将所有数据写入文件
  1381. // //WriteDataToFile(sn, direction, results);
  1382. // stopwatch.Stop();
  1383. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1384. // }
  1385. // catch (Exception ex)
  1386. // {
  1387. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1388. // }
  1389. // finally
  1390. // {
  1391. // // 重置标志变量
  1392. // isExitAtlasRight = false;
  1393. // }
  1394. //}
  1395. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1396. {
  1397. Stopwatch stopwatch = new Stopwatch();
  1398. stopwatch.Start();
  1399. int nRet = 0;
  1400. string strRet = "";
  1401. try
  1402. {
  1403. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1404. while (isCollectingFlagLeft)
  1405. {
  1406. // 从缓存中获取所有未处理的数据
  1407. var cachedData = atlasScrew.GetCachedDataLeft();
  1408. foreach (var currentResult in cachedData)
  1409. {
  1410. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1411. {
  1412. continue; // 跳过无效数据
  1413. }
  1414. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1415. // 写入PLC
  1416. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1417. {
  1418. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1419. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1420. };
  1421. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1422. if (nRet != 0)
  1423. {
  1424. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1425. }
  1426. else
  1427. {
  1428. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1429. }
  1430. // 构建保存路径
  1431. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1432. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1433. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1434. Directory.CreateDirectory(savePath); // 确保目录存在
  1435. // 构建文件名(以 SN + 序号命名)
  1436. string fileName = $"{sn}_{fileCounter}.txt";
  1437. string filePath = Path.Combine(savePath, fileName);
  1438. // 写入文件
  1439. using (StreamWriter writer = new StreamWriter(filePath))
  1440. {
  1441. writer.WriteLine("精度, 扭力");
  1442. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1443. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1444. {
  1445. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1446. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1447. writer.WriteLine($"{precision}, {torque}");
  1448. }
  1449. }
  1450. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1451. // 增加文件计数器
  1452. fileCounter++;
  1453. }
  1454. // 如果没有更多数据,则短暂休眠以节省资源
  1455. if (!cachedData.Any())
  1456. {
  1457. Thread.Sleep(10); // 根据需要调整休眠时间
  1458. }
  1459. // 如果触发了出站,则退出循环
  1460. if (!isCollectingFlagLeft)
  1461. {
  1462. break;
  1463. }
  1464. }
  1465. stopwatch.Stop();
  1466. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1467. }
  1468. catch (Exception ex)
  1469. {
  1470. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1471. }
  1472. finally
  1473. {
  1474. isCollectingFlagLeft = false;
  1475. }
  1476. }
  1477. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1478. {
  1479. Stopwatch stopwatch = new Stopwatch();
  1480. stopwatch.Start();
  1481. int nRet = 0;
  1482. string strRet = "";
  1483. try
  1484. {
  1485. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1486. while (isCollectingFlagRight)
  1487. {
  1488. // 从缓存中获取所有未处理的数据
  1489. var cachedData = atlasScrew.GetCachedDataLeft();
  1490. foreach (var currentResult in cachedData)
  1491. {
  1492. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1493. {
  1494. continue; // 跳过无效数据
  1495. }
  1496. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1497. // 写入PLC
  1498. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1499. {
  1500. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1501. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1502. };
  1503. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1504. if (nRet != 0)
  1505. {
  1506. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1507. }
  1508. else
  1509. {
  1510. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1511. }
  1512. // 构建保存路径
  1513. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1514. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1515. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction,"曲线");
  1516. Directory.CreateDirectory(savePath); // 确保目录存在
  1517. // 构建文件名(以 SN + 序号命名)
  1518. string fileName = $"{sn}_{fileCounter}.txt";
  1519. string filePath = Path.Combine(savePath, fileName);
  1520. // 写入文件
  1521. using (StreamWriter writer = new StreamWriter(filePath))
  1522. {
  1523. writer.WriteLine("精度, 扭力");
  1524. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1525. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1526. {
  1527. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1528. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1529. writer.WriteLine($"{precision}, {torque}");
  1530. }
  1531. }
  1532. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1533. // 增加文件计数器
  1534. fileCounter++;
  1535. }
  1536. // 如果没有更多数据,则短暂休眠以节省资源
  1537. if (!cachedData.Any())
  1538. {
  1539. Thread.Sleep(10); // 根据需要调整休眠时间
  1540. }
  1541. // 如果触发了出站,则退出循环
  1542. if (!isCollectingFlagRight)
  1543. {
  1544. break;
  1545. }
  1546. }
  1547. stopwatch.Stop();
  1548. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1549. }
  1550. catch (Exception ex)
  1551. {
  1552. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1553. }
  1554. finally
  1555. {
  1556. isCollectingFlagRight = false;
  1557. }
  1558. }
  1559. #endregion
  1560. #region S1
  1561. /// <summary>
  1562. /// [S1] 壳体清洁上料装备
  1563. /// </summary>
  1564. /// <param name="plcNo">PLC编号</param>
  1565. private void ReadStation_S1(int plcNo)
  1566. {
  1567. string stationCode = "[OP10]";
  1568. string stationName = "壳体清洁上料";
  1569. string stationNameStr = stationCode + stationName;
  1570. string tagBaseName = "g_OP10_MES"; //标签变量名称
  1571. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1572. string tagAgvCommName = "agvCommFrmPC";
  1573. string tagBarsetName = "BarcodeSet";
  1574. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  1575. (int, string) result;
  1576. while (true)
  1577. {
  1578. try
  1579. {
  1580. if (!GlobalContext._IsCon_Funs1)
  1581. {
  1582. UpdatePLCMonitor(1, plcNo, 0);
  1583. continue;
  1584. }
  1585. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1586. {
  1587. Stopwatch stopwatch1 = new Stopwatch();
  1588. Stopwatch stopwatch2 = new Stopwatch();
  1589. stopwatch1.Start();
  1590. stopwatch2.Start();
  1591. #region 一次性读取所有数据
  1592. // 一次性读取所有数据
  1593. result = FunsEip[plcNo].Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData,this); //读取单个结构体数据
  1594. if (result.Item1 != 0)
  1595. {
  1596. //richTextBox1.AppendText("\n" + strRet);
  1597. }
  1598. else
  1599. {
  1600. //richTextBox1.AppendText("\n" + "读取成功");
  1601. }
  1602. #endregion 一次性读取所有数据
  1603. stopwatch2.Stop();
  1604. #region 进站
  1605. try
  1606. {
  1607. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1608. {
  1609. lock (lockObj)
  1610. {
  1611. if (!ProgressState)
  1612. {
  1613. ProgressState = true;
  1614. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  1615. }
  1616. }
  1617. }
  1618. }
  1619. catch (Exception ex)
  1620. {
  1621. ProgressState = false;
  1622. string str = ex.StackTrace;
  1623. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1624. }
  1625. #endregion 进站
  1626. #region 出站
  1627. try
  1628. {
  1629. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1630. {
  1631. lock (lockObj)
  1632. {
  1633. if (!ProgressState)
  1634. {
  1635. ProgressState = true;
  1636. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1637. }
  1638. }
  1639. }
  1640. }
  1641. catch (Exception ex)
  1642. {
  1643. ProgressState = false;
  1644. string str = ex.StackTrace;
  1645. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1646. }
  1647. #endregion 进站
  1648. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1649. stopwatch1.Stop();
  1650. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1651. }
  1652. else
  1653. {
  1654. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1655. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1656. FunsEip[plcNo].Connect(); // 重连
  1657. }
  1658. }
  1659. catch (Exception ex)
  1660. {
  1661. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1662. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1663. }
  1664. Thread.Sleep(IntervalReadPLC);
  1665. }
  1666. }
  1667. /// <summary>
  1668. /// [S1] 壳体清洁上料 - 进站
  1669. /// </summary>
  1670. /// <param name="plcNo">PLC编号</param>
  1671. /// <param name="stationNameStr">工站全称</param>
  1672. /// <param name="stPLC_MesData"></param>
  1673. /// <param name="tagMesCommName"></param>
  1674. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  1675. {
  1676. Stopwatch stopwatch1 = new Stopwatch();
  1677. Stopwatch stopwatch2 = new Stopwatch();
  1678. try
  1679. {
  1680. stopwatch1.Start();
  1681. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1682. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  1683. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1684. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  1685. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  1686. if (string.IsNullOrEmpty(sn))
  1687. {
  1688. ProgressState = false;
  1689. return;
  1690. }
  1691. //正式生产就用PLC中取的
  1692. //sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;
  1693. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  1694. sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1695. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1696. //绑定载具和产品
  1697. ResponseMessage message = new ResponseMessage();
  1698. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  1699. if (message.result == false)
  1700. {
  1701. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  1702. }
  1703. // 产品SN进站
  1704. List<TestItem> item = new List<TestItem>();
  1705. stopwatch2.Start();
  1706. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1707. stopwatch2.Stop();
  1708. //指令执行结果 1:OK 110:失败
  1709. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1710. //进站结果写入PLC
  1711. CommandFromPLC resultToPlC = new CommandFromPLC();
  1712. resultToPlC.cmd = 0;
  1713. resultToPlC.cmdParam = 0;
  1714. resultToPlC.cmdResult = mesResultFrmWeb;
  1715. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1716. }
  1717. catch (Exception ex)
  1718. {
  1719. string str = ex.StackTrace;
  1720. AddMessage( LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1721. CommandFromPLC resultToPlC = new CommandFromPLC();
  1722. resultToPlC.cmd = 0;
  1723. resultToPlC.cmdParam = 0; //指令参数
  1724. resultToPlC.cmdResult = 110;
  1725. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1726. }
  1727. stopwatch1.Stop();
  1728. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  1729. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1730. ProgressState = false;
  1731. }
  1732. /// <summary>
  1733. /// [S1] 壳体清洁上料 - 出站接口
  1734. /// </summary>
  1735. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1736. {
  1737. Stopwatch stopwatch1 = new Stopwatch();
  1738. Stopwatch stopwatch2 = new Stopwatch();
  1739. try
  1740. {
  1741. stopwatch1.Start();
  1742. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  1743. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1744. string processItem = stationName; // 项目
  1745. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1746. string supplierCode = ""; // 供应商代码
  1747. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  1748. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  1749. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  1750. string sn = string.Empty;
  1751. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1752. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  1753. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  1754. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1755. a1Result = 1;
  1756. bool pass = a1Result == 1;
  1757. //根据载具码获取产品码
  1758. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1759. if (string.IsNullOrEmpty(strProductBarcode))
  1760. {
  1761. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1762. }
  1763. sn = strProductBarcode;
  1764. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1765. List<TestItem> items = new List<TestItem>();
  1766. items.Add(new TestItem()
  1767. {
  1768. Parameter_name = "载具码",
  1769. Parameter_value = CarrierBarcode,
  1770. Parameter_unit = ""
  1771. });
  1772. items.Add(new TestItem()
  1773. {
  1774. Parameter_name = "产品码",
  1775. Parameter_value = sn,
  1776. Parameter_unit = ""
  1777. });
  1778. //出站接口
  1779. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1780. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  1781. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1782. stopwatch2.Start();
  1783. //进站结果写入PLC
  1784. CommandFromPLC resultToPlC = new CommandFromPLC();
  1785. resultToPlC.cmd = 0;
  1786. resultToPlC.cmdParam = 0; //指令参数
  1787. resultToPlC.cmdResult = mesResultFrmWeb;
  1788. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1789. stopwatch2.Stop();
  1790. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  1791. //保存PLC返回MES数据到本地
  1792. ResponseMessage message = new ResponseMessage();
  1793. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  1794. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress, stPLC_MesData.mesData.fCleanSpeed,
  1795. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime, stPLC_MesData.mesData.nCleanCount,
  1796. stPLC_MesData.mesData.nRemainCount);
  1797. if (message.result == false)
  1798. {
  1799. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  1800. }
  1801. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  1802. }
  1803. catch (Exception ex)
  1804. {
  1805. stopwatch2.Start();
  1806. CommandFromPLC resultToPlC = new CommandFromPLC();
  1807. resultToPlC.cmd = 0;
  1808. resultToPlC.cmdParam = 0; //指令参数
  1809. resultToPlC.cmdResult = 110;
  1810. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1811. stopwatch2.Stop();
  1812. string str = ex.StackTrace;
  1813. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1814. }
  1815. stopwatch1.Stop();
  1816. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1817. ProgressState = false;
  1818. }
  1819. #endregion
  1820. #region S2
  1821. /// <summary>
  1822. /// [S2] 上盖板上料装备
  1823. /// </summary>
  1824. /// <param name="plcNo">PLC编号</param>
  1825. private void ReadStation_S2(int plcNo)
  1826. {
  1827. string stationCode = "[OP20]";
  1828. string stationName = "上盖板上料装备";
  1829. string stationNameStr = stationCode + stationName;
  1830. string tagBaseName = "g_OP20_MES"; //标签变量名称
  1831. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1832. string tagAgvCommName = "agvCommFrmPC";
  1833. string tagBarsetName = "BarcodeSet";
  1834. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  1835. (int, string) result;
  1836. while (true)
  1837. {
  1838. try
  1839. {
  1840. if (!GlobalContext._IsCon_Funs2)
  1841. {
  1842. UpdatePLCMonitor(1, plcNo, 0);
  1843. continue;
  1844. }
  1845. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1846. {
  1847. Stopwatch stopwatch1 = new Stopwatch();
  1848. Stopwatch stopwatch2 = new Stopwatch();
  1849. stopwatch1.Start();
  1850. stopwatch2.Start();
  1851. #region 一次性读取所有数据
  1852. // 一次性读取所有数据
  1853. result = FunsEip[plcNo].Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  1854. if (result.Item1 != 0)
  1855. {
  1856. //richTextBox1.AppendText("\n" + strRet);
  1857. }
  1858. else
  1859. {
  1860. //richTextBox1.AppendText("\n" + "读取成功");
  1861. }
  1862. #endregion 一次性读取所有数据
  1863. stopwatch2.Stop();
  1864. #region 进站
  1865. try
  1866. {
  1867. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1868. {
  1869. lock (lockObj)
  1870. {
  1871. if (!ProgressState)
  1872. {
  1873. ProgressState = true;
  1874. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  1875. }
  1876. }
  1877. }
  1878. }
  1879. catch (Exception ex)
  1880. {
  1881. ProgressState = false;
  1882. string str = ex.StackTrace;
  1883. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1884. }
  1885. #endregion 进站
  1886. #region 出站
  1887. try
  1888. {
  1889. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1890. {
  1891. lock (lockObj)
  1892. {
  1893. if (!ProgressState)
  1894. {
  1895. ProgressState = true;
  1896. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1897. }
  1898. }
  1899. }
  1900. }
  1901. catch (Exception ex)
  1902. {
  1903. ProgressState = false;
  1904. string str = ex.StackTrace;
  1905. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1906. }
  1907. #endregion 进站
  1908. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1909. stopwatch1.Stop();
  1910. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  1911. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1912. }
  1913. else
  1914. {
  1915. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1916. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1917. FunsEip[plcNo].Connect();
  1918. }
  1919. }
  1920. catch (Exception ex)
  1921. {
  1922. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1923. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1924. //Funs[plcNo].ReConnect();
  1925. }
  1926. Thread.Sleep(IntervalReadPLC);
  1927. }
  1928. }
  1929. /// <summary>
  1930. /// [S2] 上盖板上料装备
  1931. /// </summary>
  1932. /// <param name="plcNo">PLC编号</param>
  1933. /// <param name="stationNameStr">工站全称</param>
  1934. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  1935. {
  1936. Stopwatch stopwatch1 = new Stopwatch();
  1937. Stopwatch stopwatch2 = new Stopwatch();
  1938. try
  1939. {
  1940. stopwatch1.Start();
  1941. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1942. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  1943. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1944. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  1945. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  1946. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  1947. //根据载具码获取产品码
  1948. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  1949. if (string.IsNullOrEmpty(strProductBarcode))
  1950. {
  1951. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1952. }
  1953. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  1954. //if (sn != strProductBarcode)
  1955. //{
  1956. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  1957. //}
  1958. sn = strProductBarcode;
  1959. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  1960. // 产品SN(物料码)校验
  1961. List<TestItem> item = new List<TestItem>();
  1962. stopwatch2.Start();
  1963. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1964. stopwatch2.Stop();
  1965. //指令执行结果 1:OK 110:失败
  1966. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1967. //进站结果写入PLC
  1968. CommandFromPLC resultToPlC = new CommandFromPLC();
  1969. resultToPlC.cmd = 0;
  1970. resultToPlC.cmdParam = 0; //指令参数
  1971. resultToPlC.cmdResult = mesResultFrmWeb;
  1972. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1973. }
  1974. catch (Exception ex)
  1975. {
  1976. string str = ex.StackTrace;
  1977. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1978. CommandFromPLC resultToPlC = new CommandFromPLC();
  1979. resultToPlC.cmd = 0;
  1980. resultToPlC.cmdParam = 0; //指令参数
  1981. resultToPlC.cmdResult = 110;
  1982. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1983. }
  1984. stopwatch1.Stop();
  1985. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  1986. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1987. ProgressState = false;
  1988. }
  1989. /// <summary>
  1990. /// [S2] 上盖板上料装备 - 出站接口
  1991. /// </summary>
  1992. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1993. {
  1994. Stopwatch stopwatch1 = new Stopwatch();
  1995. Stopwatch stopwatch2 = new Stopwatch();
  1996. try
  1997. {
  1998. stopwatch1.Start();
  1999. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2000. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2001. string processItem = stationName; // 测试项目
  2002. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2003. string supplierCode = ""; // 供应商代码
  2004. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2005. string batch_num = GlobalContext.BatchNumber; // 批次号
  2006. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2007. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2008. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2009. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  2010. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  2011. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  2012. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2013. bool pass = a1Result == 1;
  2014. //根据载具码获取产品码
  2015. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2016. if (string.IsNullOrEmpty(strProductBarcode))
  2017. {
  2018. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2019. }
  2020. sn = strProductBarcode;
  2021. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2022. List<TestItem> items = new List<TestItem>();
  2023. items.Add(new TestItem()
  2024. {
  2025. Parameter_name = "载具码",
  2026. Parameter_value = CarrierBarcode,
  2027. Parameter_unit = ""
  2028. });
  2029. items.Add(new TestItem()
  2030. {
  2031. Parameter_name = "产品码",
  2032. Parameter_value = sn,
  2033. Parameter_unit = ""
  2034. });
  2035. items.Add(new TestItem()
  2036. {
  2037. Parameter_name = "部件码",
  2038. Parameter_value = PartBarcode,
  2039. Parameter_unit = ""
  2040. });
  2041. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2042. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  2043. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2044. stopwatch2.Start();
  2045. //进站结果写入PLC
  2046. CommandFromPLC resultToPlC = new CommandFromPLC();
  2047. resultToPlC.cmd = 0;
  2048. resultToPlC.cmdParam = 0; //指令参数
  2049. resultToPlC.cmdResult = mesResultFrmWeb;
  2050. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2051. stopwatch2.Stop();
  2052. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2053. //保存PLC返回MES数据到本地
  2054. ResponseMessage message = new ResponseMessage();
  2055. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  2056. if (message.result == false)
  2057. {
  2058. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2059. }
  2060. if (!string.IsNullOrEmpty(PartBarcode))
  2061. {
  2062. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  2063. if (message.result == false)
  2064. {
  2065. AddMessage(LogType.Error, message.text);
  2066. }
  2067. }
  2068. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2069. }
  2070. catch (Exception ex)
  2071. {
  2072. stopwatch2.Start();
  2073. CommandFromPLC resultToPlC = new CommandFromPLC();
  2074. resultToPlC.cmd = 0;
  2075. resultToPlC.cmdParam = 0; //指令参数
  2076. resultToPlC.cmdResult = 110;
  2077. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2078. stopwatch2.Stop();
  2079. string str = ex.StackTrace;
  2080. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2081. }
  2082. stopwatch1.Stop();
  2083. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2084. ProgressState = false;
  2085. }
  2086. #endregion
  2087. #region S3
  2088. /// <summary>
  2089. /// [S3] 点散热胶装备
  2090. /// </summary>
  2091. /// <param name="plcNo">PLC编号</param>
  2092. private void ReadStation_S3(int plcNo)
  2093. {
  2094. string stationCode = "[OP30]";
  2095. string stationName = "点散热胶装备";
  2096. string stationNameStr = stationCode + stationName;
  2097. string tagBaseName = "g_OP30_MES"; //标签变量名称
  2098. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2099. string tagAgvCommName = "agvCommFrmPC";
  2100. string tagBarsetName = "BarcodeSet";
  2101. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  2102. (int, string) result;
  2103. #region 创建字典
  2104. // 触发信号字典 赋值
  2105. s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2106. s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2107. s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2108. s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2109. s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2110. // PLC数据字典 赋值
  2111. s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2112. s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  2113. s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2114. s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2115. s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  2116. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2117. s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2118. s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2119. s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  2120. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2121. s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  2122. s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  2123. s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  2124. s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2125. s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  2126. s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  2127. //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  2128. s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2129. s3PLCData.Add("c1Result", 0); // 产品结果
  2130. s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2131. s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  2132. s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  2133. s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  2134. #endregion 创建字典
  2135. while (true)
  2136. {
  2137. try
  2138. {
  2139. if (!GlobalContext._IsCon_Funs2)
  2140. {
  2141. UpdatePLCMonitor(1, plcNo, 0);
  2142. continue;
  2143. }
  2144. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2145. {
  2146. Stopwatch stopwatch1 = new Stopwatch();
  2147. Stopwatch stopwatch2 = new Stopwatch();
  2148. stopwatch1.Start();
  2149. stopwatch2.Start();
  2150. #region 一次性读取所有数据
  2151. // 一次性读取所有数据
  2152. result = FunsEip[plcNo].Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2153. if (result.Item1 != 0)
  2154. {
  2155. //richTextBox1.AppendText("\n" + strRet);
  2156. }
  2157. else
  2158. {
  2159. //richTextBox1.AppendText("\n" + "读取成功");
  2160. }
  2161. #endregion 一次性读取所有数据
  2162. stopwatch2.Stop();
  2163. #region 左边进站
  2164. try
  2165. {
  2166. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2167. {
  2168. lock (lockObj)
  2169. {
  2170. if (!ProgressState)
  2171. {
  2172. ProgressState = true;
  2173. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  2174. }
  2175. }
  2176. }
  2177. }
  2178. catch (Exception ex)
  2179. {
  2180. ProgressState = false;
  2181. string str = ex.StackTrace;
  2182. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2183. }
  2184. #endregion 左边进站
  2185. #region 左边出站
  2186. try
  2187. {
  2188. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2189. {
  2190. lock (lockObj)
  2191. {
  2192. if (!ProgressState)
  2193. {
  2194. ProgressState = true;
  2195. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  2196. }
  2197. }
  2198. }
  2199. }
  2200. catch (Exception ex)
  2201. {
  2202. ProgressState = false;
  2203. string str = ex.StackTrace;
  2204. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2205. }
  2206. #endregion 左边出站
  2207. #region 右边进站
  2208. try
  2209. {
  2210. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2211. {
  2212. lock (lockObj)
  2213. {
  2214. if (!ProgressState)
  2215. {
  2216. ProgressState = true;
  2217. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right." + tagBarsetName,"Right", out ProgressState));
  2218. }
  2219. }
  2220. }
  2221. }
  2222. catch (Exception ex)
  2223. {
  2224. ProgressState = false;
  2225. string str = ex.StackTrace;
  2226. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2227. }
  2228. #endregion 右边进站
  2229. #region 右边出站
  2230. try
  2231. {
  2232. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2233. {
  2234. lock (lockObj)
  2235. {
  2236. if (!ProgressState)
  2237. {
  2238. ProgressState = true;
  2239. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  2240. }
  2241. }
  2242. }
  2243. }
  2244. catch (Exception ex)
  2245. {
  2246. string str = ex.StackTrace;
  2247. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2248. }
  2249. #endregion 右边出站
  2250. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2251. stopwatch1.Stop();
  2252. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2253. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2254. }
  2255. else
  2256. {
  2257. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2258. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2259. FunsEip[plcNo].Connect();
  2260. }
  2261. }
  2262. catch (Exception ex)
  2263. {
  2264. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2265. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2266. //Funs[plcNo].ReConnect();
  2267. }
  2268. Thread.Sleep(IntervalReadPLC);
  2269. }
  2270. }
  2271. /// <summary>
  2272. /// [S3] 点散热胶装备 - 进站
  2273. /// </summary>
  2274. /// <param name="plcNo">PLC编号</param>
  2275. /// <param name="stationNameStr">工站全称</param>
  2276. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName,string direction, out bool ProgressState)
  2277. {
  2278. Stopwatch stopwatch1 = new Stopwatch();
  2279. Stopwatch stopwatch2 = new Stopwatch();
  2280. try
  2281. {
  2282. stopwatch1.Start();
  2283. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_进站开始");
  2284. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2285. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  2286. string StationId=string.Empty;
  2287. if (direction=="Left")
  2288. {
  2289. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2290. }
  2291. if (direction == "Right")
  2292. {
  2293. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2294. }
  2295. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2296. //载具码验证产品码
  2297. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2298. if (string.IsNullOrEmpty(strProductBarcode))
  2299. {
  2300. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2301. }
  2302. sn = strProductBarcode;
  2303. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  2304. // 产品SN(物料码)校验
  2305. List<TestItem> item = new List<TestItem>();
  2306. stopwatch2.Start();
  2307. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2308. stopwatch2.Stop();
  2309. //指令执行结果 1:OK 110:失败
  2310. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2311. //进站结果写入PLC
  2312. CommandFromPLC resultToPlC = new CommandFromPLC();
  2313. resultToPlC.cmd = 0;
  2314. resultToPlC.cmdParam = 0; //指令参数
  2315. resultToPlC.cmdResult = mesResultFrmWeb;
  2316. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2317. }
  2318. catch (Exception ex)
  2319. {
  2320. string str = ex.StackTrace;
  2321. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2322. CommandFromPLC resultToPlC = new CommandFromPLC();
  2323. resultToPlC.cmd = 0;
  2324. resultToPlC.cmdParam = 0; //指令参数
  2325. resultToPlC.cmdResult = 110;
  2326. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2327. }
  2328. stopwatch1.Stop();
  2329. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  2330. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2331. ProgressState = false;
  2332. }
  2333. /// <summary>
  2334. /// [S3] 点散热胶装备 - 出站
  2335. /// </summary>
  2336. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  2337. {
  2338. Stopwatch stopwatch1 = new Stopwatch();
  2339. Stopwatch stopwatch2 = new Stopwatch();
  2340. try
  2341. {
  2342. stopwatch1.Start();
  2343. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  2344. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2345. string processItem = stationName; // 测试项目
  2346. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2347. string supplierCode = ""; // 供应商代码
  2348. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2349. string batch_num = GlobalContext.BatchNumber; // 批次号
  2350. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2351. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2352. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2353. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  2354. string StationId = string.Empty;
  2355. if (direction == "Left")
  2356. {
  2357. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2358. }
  2359. if (direction == "Right")
  2360. {
  2361. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2362. }
  2363. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2364. bool pass = a1Result == 1;
  2365. //根据载具码获取产品码
  2366. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2367. if (string.IsNullOrEmpty(strProductBarcode))
  2368. {
  2369. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2370. }
  2371. sn = strProductBarcode;
  2372. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2373. List<TestItem> items = new List<TestItem>();
  2374. items.Add(new TestItem()
  2375. {
  2376. Parameter_name = "载具码",
  2377. Parameter_value = CarrierBarcode,
  2378. Parameter_unit = ""
  2379. });
  2380. items.Add(new TestItem()
  2381. {
  2382. Parameter_name = "产品码",
  2383. Parameter_value = sn,
  2384. Parameter_unit = ""
  2385. });
  2386. int result1 = 1;
  2387. if (direction == "Right")
  2388. {
  2389. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2390. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2391. }
  2392. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2393. stopwatch2.Start();
  2394. //进站结果写入PLC
  2395. CommandFromPLC resultToPlC = new CommandFromPLC();
  2396. resultToPlC.cmd = 0;
  2397. resultToPlC.cmdParam = 0; //指令参数
  2398. resultToPlC.cmdResult = mesResultFrmWeb;
  2399. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2400. stopwatch2.Stop();
  2401. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  2402. //保存PLC返回MES数据到本地
  2403. ResponseMessage message = new ResponseMessage();
  2404. if (direction == "Left")
  2405. {
  2406. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2407. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2408. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2409. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2410. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2411. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2412. if (message.result == false)
  2413. {
  2414. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2415. }
  2416. }
  2417. if (direction == "Right")
  2418. {
  2419. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2420. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2421. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2422. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2423. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2424. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2425. if (message.result == false)
  2426. {
  2427. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2428. }
  2429. }
  2430. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2431. }
  2432. catch (Exception ex)
  2433. {
  2434. stopwatch2.Start();
  2435. CommandFromPLC resultToPlC = new CommandFromPLC();
  2436. resultToPlC.cmd = 0;
  2437. resultToPlC.cmdParam = 0; //指令参数
  2438. resultToPlC.cmdResult = 110;
  2439. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2440. stopwatch2.Stop();
  2441. string str = ex.StackTrace;
  2442. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2443. }
  2444. stopwatch1.Stop();
  2445. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2446. ProgressState = false;
  2447. }
  2448. #endregion S3
  2449. #region S4
  2450. /// <summary>
  2451. /// [S4] 点胶检测设备
  2452. /// </summary>
  2453. /// <param name="plcNo">PLC编号</param>
  2454. private void ReadStation_S4(int plcNo)
  2455. {
  2456. string stationCode = "[OP40]";
  2457. string stationName = "胶线检测";
  2458. string stationNameStr = stationCode + stationName;
  2459. string tagBaseName = "g_OP40_MES"; //标签变量名称
  2460. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2461. string tagAgvCommName = "agvCommFrmPC";
  2462. string tagBarsetName = "BarcodeSet";
  2463. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  2464. (int, string) result;
  2465. while (true)
  2466. {
  2467. try
  2468. {
  2469. if (!GlobalContext._IsCon_Funs1)
  2470. {
  2471. UpdatePLCMonitor(1, plcNo, 0);
  2472. continue;
  2473. }
  2474. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2475. {
  2476. Stopwatch stopwatch1 = new Stopwatch();
  2477. Stopwatch stopwatch2 = new Stopwatch();
  2478. stopwatch1.Start();
  2479. stopwatch2.Start();
  2480. #region 一次性读取所有数据
  2481. // 一次性读取所有数据
  2482. result = FunsEip[plcNo].Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2483. if (result.Item1 != 0)
  2484. {
  2485. //richTextBox1.AppendText("\n" + strRet);
  2486. }
  2487. else
  2488. {
  2489. //richTextBox1.AppendText("\n" + "读取成功");
  2490. }
  2491. #endregion 一次性读取所有数据
  2492. stopwatch2.Stop();
  2493. #region 进站
  2494. try
  2495. {
  2496. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2497. {
  2498. lock (lockObj)
  2499. {
  2500. if (!ProgressState)
  2501. {
  2502. ProgressState = true;
  2503. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2504. }
  2505. }
  2506. }
  2507. }
  2508. catch (Exception ex)
  2509. {
  2510. ProgressState = false;
  2511. string str = ex.StackTrace;
  2512. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2513. }
  2514. #endregion 进站
  2515. #region 出站
  2516. try
  2517. {
  2518. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2519. {
  2520. lock (lockObj)
  2521. {
  2522. if (!ProgressState)
  2523. {
  2524. ProgressState = true;
  2525. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2526. }
  2527. }
  2528. }
  2529. }
  2530. catch (Exception ex)
  2531. {
  2532. string str = ex.StackTrace;
  2533. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2534. }
  2535. #endregion 进站
  2536. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2537. stopwatch1.Stop();
  2538. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2539. }
  2540. else
  2541. {
  2542. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2543. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2544. FunsEip[plcNo].Connect(); // 重连
  2545. }
  2546. }
  2547. catch (Exception ex)
  2548. {
  2549. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2550. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2551. }
  2552. Thread.Sleep(IntervalReadPLC);
  2553. }
  2554. }
  2555. /// <summary>
  2556. /// [S4] 点胶检测设备 - 进站
  2557. /// </summary>
  2558. /// <param name="plcNo">PLC编号</param>
  2559. /// <param name="stationNameStr">工站全称</param>
  2560. /// <param name="stPLC_MesData"></param>
  2561. /// <param name="tagMesCommName"></param>
  2562. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2563. {
  2564. Stopwatch stopwatch1 = new Stopwatch();
  2565. Stopwatch stopwatch2 = new Stopwatch();
  2566. try
  2567. {
  2568. stopwatch1.Start();
  2569. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2570. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2571. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  2572. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  2573. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2574. //载具码验证产品码
  2575. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2576. if (string.IsNullOrEmpty(strProductBarcode))
  2577. {
  2578. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2579. }
  2580. sn = strProductBarcode;
  2581. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2582. // 产品SN(物料码)校验
  2583. List<TestItem> item = new List<TestItem>();
  2584. stopwatch2.Start();
  2585. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2586. stopwatch2.Stop();
  2587. //指令执行结果 1:OK 110:失败
  2588. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2589. //进站结果写入PLC
  2590. CommandFromPLC resultToPlC = new CommandFromPLC();
  2591. resultToPlC.cmd = 0;
  2592. resultToPlC.cmdParam = 0; //指令参数
  2593. resultToPlC.cmdResult = mesResultFrmWeb;
  2594. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2595. }
  2596. catch (Exception ex)
  2597. {
  2598. string str = ex.StackTrace;
  2599. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2600. CommandFromPLC resultToPlC = new CommandFromPLC();
  2601. resultToPlC.cmd = 0;
  2602. resultToPlC.cmdParam = 0; //指令参数
  2603. resultToPlC.cmdResult = 110;
  2604. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2605. }
  2606. stopwatch1.Stop();
  2607. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2608. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2609. ProgressState = false;
  2610. }
  2611. /// <summary>
  2612. /// [S4] 点胶检测设备 - 出站接口
  2613. /// </summary>
  2614. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2615. {
  2616. Stopwatch stopwatch1 = new Stopwatch();
  2617. Stopwatch stopwatch2 = new Stopwatch();
  2618. try
  2619. {
  2620. stopwatch1.Start();
  2621. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2622. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2623. string processItem = stationName; // 测试项目
  2624. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2625. string supplierCode = ""; // 供应商代码
  2626. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2627. string batch_num = GlobalContext.BatchNumber; // 批次号
  2628. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2629. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2630. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2631. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  2632. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  2633. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2634. bool pass = a1Result == 1;
  2635. //根据载具码获取产品码
  2636. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2637. if (string.IsNullOrEmpty(strProductBarcode))
  2638. {
  2639. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2640. }
  2641. sn = strProductBarcode;
  2642. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2643. List<TestItem> items = new List<TestItem>();
  2644. items.Add(new TestItem()
  2645. {
  2646. Parameter_name = "载具码",
  2647. Parameter_value = CarrierBarcode,
  2648. Parameter_unit = ""
  2649. });
  2650. items.Add(new TestItem()
  2651. {
  2652. Parameter_name = "产品码",
  2653. Parameter_value = sn,
  2654. Parameter_unit = ""
  2655. });
  2656. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2657. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2658. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2659. stopwatch2.Start();
  2660. //进站结果写入PLC
  2661. CommandFromPLC resultToPlC = new CommandFromPLC();
  2662. resultToPlC.cmd = 0;
  2663. resultToPlC.cmdParam = 0; //指令参数
  2664. resultToPlC.cmdResult = mesResultFrmWeb;
  2665. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2666. stopwatch2.Stop();
  2667. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2668. //保存PLC返回MES数据到本地
  2669. ResponseMessage message = new ResponseMessage();
  2670. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  2671. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  2672. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  2673. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  2674. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  2675. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  2676. if (message.result == false)
  2677. {
  2678. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2679. }
  2680. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2681. }
  2682. catch (Exception ex)
  2683. {
  2684. stopwatch2.Start();
  2685. CommandFromPLC resultToPlC = new CommandFromPLC();
  2686. resultToPlC.cmd = 0;
  2687. resultToPlC.cmdParam = 0; //指令参数
  2688. resultToPlC.cmdResult = 110;
  2689. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2690. stopwatch2.Stop();
  2691. string str = ex.StackTrace;
  2692. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2693. }
  2694. stopwatch1.Stop();
  2695. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2696. ProgressState = false;
  2697. }
  2698. #endregion
  2699. #region S5
  2700. /// <summary>
  2701. /// [S5] 点胶检测设备
  2702. /// </summary>
  2703. /// <param name="plcNo">PLC编号</param>
  2704. private void ReadStation_S5(int plcNo)
  2705. {
  2706. string stationCode = "[OP50]";
  2707. string stationName = "ADD板上料组装装备";
  2708. string stationNameStr = stationCode + stationName;
  2709. string tagBaseName = "g_OP50_MES"; //标签变量名称
  2710. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2711. string tagAgvCommName = "agvCommFrmPC";
  2712. string tagBarsetName = "BarcodeSet";
  2713. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  2714. (int, string) result;
  2715. while (true)
  2716. {
  2717. try
  2718. {
  2719. if (!GlobalContext._IsCon_Funs1)
  2720. {
  2721. UpdatePLCMonitor(1, plcNo, 0);
  2722. continue;
  2723. }
  2724. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2725. {
  2726. Stopwatch stopwatch1 = new Stopwatch();
  2727. Stopwatch stopwatch2 = new Stopwatch();
  2728. stopwatch1.Start();
  2729. stopwatch2.Start();
  2730. #region 一次性读取所有数据
  2731. // 一次性读取所有数据
  2732. result = FunsEip[plcNo].Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2733. if (result.Item1 != 0)
  2734. {
  2735. //richTextBox1.AppendText("\n" + strRet);
  2736. }
  2737. else
  2738. {
  2739. //richTextBox1.AppendText("\n" + "读取成功");
  2740. }
  2741. #endregion 一次性读取所有数据
  2742. stopwatch2.Stop();
  2743. #region 进站
  2744. try
  2745. {
  2746. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2747. {
  2748. lock (lockObj)
  2749. {
  2750. if (!ProgressState)
  2751. {
  2752. ProgressState = true;
  2753. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2754. }
  2755. }
  2756. }
  2757. }
  2758. catch (Exception ex)
  2759. {
  2760. ProgressState = false;
  2761. string str = ex.StackTrace;
  2762. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2763. }
  2764. #endregion 进站
  2765. #region 出站
  2766. try
  2767. {
  2768. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2769. {
  2770. lock (lockObj)
  2771. {
  2772. if (!ProgressState)
  2773. {
  2774. ProgressState = true;
  2775. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2776. }
  2777. }
  2778. }
  2779. }
  2780. catch (Exception ex)
  2781. {
  2782. ProgressState = false;
  2783. string str = ex.StackTrace;
  2784. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2785. }
  2786. #endregion 进站
  2787. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2788. stopwatch1.Stop();
  2789. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2790. }
  2791. else
  2792. {
  2793. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2794. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2795. FunsEip[plcNo].Connect(); // 重连
  2796. }
  2797. }
  2798. catch (Exception ex)
  2799. {
  2800. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2801. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2802. }
  2803. Thread.Sleep(IntervalReadPLC);
  2804. }
  2805. }
  2806. /// <summary>
  2807. /// [S5] 点胶检测设备 - 进站
  2808. /// </summary>
  2809. /// <param name="plcNo">PLC编号</param>
  2810. /// <param name="stationNameStr">工站全称</param>
  2811. /// <param name="stPLC_MesData"></param>
  2812. /// <param name="tagMesCommName"></param>
  2813. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2814. {
  2815. Stopwatch stopwatch1 = new Stopwatch();
  2816. Stopwatch stopwatch2 = new Stopwatch();
  2817. try
  2818. {
  2819. stopwatch1.Start();
  2820. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2821. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2822. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2823. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  2824. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  2825. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2826. //载具码验证产品码 //载具码验证产品码
  2827. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2828. if (string.IsNullOrEmpty(strProductBarcode))
  2829. {
  2830. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2831. }
  2832. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  2833. //if (sn != strProductBarcode)
  2834. //{
  2835. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  2836. //}
  2837. sn = strProductBarcode;
  2838. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2839. // 产品SN(物料码)校验
  2840. List<TestItem> item = new List<TestItem>();
  2841. stopwatch2.Start();
  2842. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2843. stopwatch2.Stop();
  2844. //指令执行结果 1:OK 110:失败
  2845. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2846. //进站结果写入PLC
  2847. CommandFromPLC resultToPlC = new CommandFromPLC();
  2848. resultToPlC.cmd = 0;
  2849. resultToPlC.cmdParam = 0; //指令参数
  2850. resultToPlC.cmdResult = mesResultFrmWeb;
  2851. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2852. }
  2853. catch (Exception ex)
  2854. {
  2855. string str = ex.StackTrace;
  2856. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2857. CommandFromPLC resultToPlC = new CommandFromPLC();
  2858. resultToPlC.cmd = 0;
  2859. resultToPlC.cmdParam = 0; //指令参数
  2860. resultToPlC.cmdResult = 110;
  2861. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2862. }
  2863. stopwatch1.Stop();
  2864. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2865. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2866. ProgressState = false;
  2867. }
  2868. /// <summary>
  2869. /// [S5] 点胶检测设备 - 出站接口
  2870. /// </summary>
  2871. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2872. {
  2873. Stopwatch stopwatch1 = new Stopwatch();
  2874. Stopwatch stopwatch2 = new Stopwatch();
  2875. try
  2876. {
  2877. stopwatch1.Start();
  2878. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2879. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2880. string processItem = stationName; // 测试项目
  2881. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2882. string supplierCode = ""; // 供应商代码
  2883. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2884. string batch_num = GlobalContext.BatchNumber; // 批次号
  2885. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2886. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2887. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
  2888. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2889. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  2890. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  2891. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2892. bool pass = a1Result == 1;
  2893. //根据载具码获取产品码
  2894. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2895. if (string.IsNullOrEmpty(strProductBarcode))
  2896. {
  2897. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2898. }
  2899. sn = strProductBarcode;
  2900. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2901. List<TestItem> items = new List<TestItem>();
  2902. items.Add(new TestItem()
  2903. {
  2904. Parameter_name = "载具码",
  2905. Parameter_value = CarrierBarcode,
  2906. Parameter_unit = ""
  2907. });
  2908. items.Add(new TestItem()
  2909. {
  2910. Parameter_name = "产品码",
  2911. Parameter_value = sn,
  2912. Parameter_unit = ""
  2913. });
  2914. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2915. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  2916. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2917. stopwatch2.Start();
  2918. //进站结果写入PLC
  2919. CommandFromPLC resultToPlC = new CommandFromPLC();
  2920. resultToPlC.cmd = 0;
  2921. resultToPlC.cmdParam = 0; //指令参数
  2922. resultToPlC.cmdResult = mesResultFrmWeb;
  2923. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2924. stopwatch2.Stop();
  2925. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2926. //保存PLC返回MES数据到本地
  2927. ResponseMessage message = new ResponseMessage();
  2928. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  2929. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB, stPLC_MesData.mesData.nRemainCount, "");
  2930. if (message.result == false)
  2931. {
  2932. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2933. }
  2934. //保存部件码信息
  2935. if (!string.IsNullOrEmpty(PartBarcode))
  2936. {
  2937. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  2938. if (message.result == false)
  2939. {
  2940. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  2941. }
  2942. }
  2943. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2944. }
  2945. catch (Exception ex)
  2946. {
  2947. stopwatch2.Start();
  2948. CommandFromPLC resultToPlC = new CommandFromPLC();
  2949. resultToPlC.cmd = 0;
  2950. resultToPlC.cmdParam = 0; //指令参数
  2951. resultToPlC.cmdResult = 110;
  2952. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2953. stopwatch2.Stop();
  2954. string str = ex.StackTrace;
  2955. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2956. }
  2957. stopwatch1.Stop();
  2958. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2959. ProgressState = false;
  2960. }
  2961. #endregion
  2962. #region S6
  2963. /// <summary>
  2964. /// [S6] 顶盖装配设备
  2965. /// </summary>
  2966. /// <param name="plcNo">PLC编号</param>
  2967. private void ReadStation_S6(int plcNo)
  2968. {
  2969. string stationCode = "[OP60]";
  2970. string stationName = "组上盖板";
  2971. string stationNameStr = stationCode + stationName;
  2972. string tagBaseName = "g_OP60_MES"; //标签变量名称
  2973. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2974. string tagAgvCommName = "agvCommFrmPC";
  2975. string tagBarsetName = "BarcodeSet";
  2976. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  2977. (int, string) result;
  2978. while (true)
  2979. {
  2980. try
  2981. {
  2982. if (!GlobalContext._IsCon_Funs1)
  2983. {
  2984. UpdatePLCMonitor(1, plcNo, 0);
  2985. continue;
  2986. }
  2987. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2988. {
  2989. Stopwatch stopwatch1 = new Stopwatch();
  2990. Stopwatch stopwatch2 = new Stopwatch();
  2991. stopwatch1.Start();
  2992. stopwatch2.Start();
  2993. #region 一次性读取所有数据
  2994. // 一次性读取所有数据
  2995. result = FunsEip[plcNo].Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2996. if (result.Item1 != 0)
  2997. {
  2998. //richTextBox1.AppendText("\n" + strRet);
  2999. }
  3000. else
  3001. {
  3002. //richTextBox1.AppendText("\n" + "读取成功");
  3003. }
  3004. #endregion 一次性读取所有数据
  3005. stopwatch2.Stop();
  3006. #region 进站
  3007. try
  3008. {
  3009. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3010. {
  3011. lock (lockObj)
  3012. {
  3013. if (!ProgressState)
  3014. {
  3015. ProgressState = true;
  3016. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3017. }
  3018. }
  3019. }
  3020. }
  3021. catch (Exception ex)
  3022. {
  3023. ProgressState = false;
  3024. string str = ex.StackTrace;
  3025. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3026. }
  3027. #endregion 进站
  3028. #region 出站
  3029. try
  3030. {
  3031. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3032. {
  3033. lock (lockObj)
  3034. {
  3035. if (!ProgressState)
  3036. {
  3037. ProgressState = true; ;
  3038. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3039. }
  3040. }
  3041. }
  3042. }
  3043. catch (Exception ex)
  3044. {
  3045. ProgressState = false;
  3046. string str = ex.StackTrace;
  3047. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3048. }
  3049. #endregion 进站
  3050. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3051. stopwatch1.Stop();
  3052. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3053. }
  3054. else
  3055. {
  3056. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3057. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3058. FunsEip[plcNo].Connect(); // 重连
  3059. }
  3060. }
  3061. catch (Exception ex)
  3062. {
  3063. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3064. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3065. }
  3066. Thread.Sleep(IntervalReadPLC);
  3067. }
  3068. }
  3069. /// <summary>
  3070. /// [S6] 顶盖装配设备 - 进站
  3071. /// </summary>
  3072. /// <param name="plcNo">PLC编号</param>
  3073. /// <param name="stationNameStr">工站全称</param>
  3074. /// <param name="stPLC_MesData"></param>
  3075. /// <param name="tagMesCommName"></param>
  3076. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3077. {
  3078. Stopwatch stopwatch1 = new Stopwatch();
  3079. Stopwatch stopwatch2 = new Stopwatch();
  3080. try
  3081. {
  3082. stopwatch1.Start();
  3083. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3084. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3085. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  3086. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  3087. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3088. //载具码验证产品码
  3089. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3090. if (string.IsNullOrEmpty(strProductBarcode))
  3091. {
  3092. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3093. }
  3094. sn = strProductBarcode;
  3095. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3096. // 产品SN(物料码)校验
  3097. List<TestItem> item = new List<TestItem>();
  3098. stopwatch2.Start();
  3099. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3100. stopwatch2.Stop();
  3101. //指令执行结果 1:OK 110:失败
  3102. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3103. //进站结果写入PLC
  3104. CommandFromPLC resultToPlC = new CommandFromPLC();
  3105. resultToPlC.cmd = 0;
  3106. resultToPlC.cmdParam = 0; //指令参数
  3107. resultToPlC.cmdResult = mesResultFrmWeb;
  3108. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3109. }
  3110. catch (Exception ex)
  3111. {
  3112. string str = ex.StackTrace;
  3113. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3114. CommandFromPLC resultToPlC = new CommandFromPLC();
  3115. resultToPlC.cmd = 0;
  3116. resultToPlC.cmdParam = 0; //指令参数
  3117. resultToPlC.cmdResult = 110;
  3118. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3119. }
  3120. stopwatch1.Stop();
  3121. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3122. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3123. ProgressState = false;
  3124. }
  3125. /// <summary>
  3126. /// [S6] 顶盖装配设备 - 出站接口
  3127. /// </summary>
  3128. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3129. {
  3130. Stopwatch stopwatch1 = new Stopwatch();
  3131. Stopwatch stopwatch2 = new Stopwatch();
  3132. try
  3133. {
  3134. stopwatch1.Start();
  3135. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3136. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3137. string processItem = stationName; // 测试项目
  3138. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3139. string supplierCode = ""; // 供应商代码
  3140. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3141. string batch_num = GlobalContext.BatchNumber; // 批次号
  3142. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3143. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3144. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3145. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  3146. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  3147. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3148. bool pass = a1Result == 1;
  3149. //根据载具码获取产品码
  3150. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3151. if (string.IsNullOrEmpty(strProductBarcode))
  3152. {
  3153. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3154. }
  3155. sn = strProductBarcode;
  3156. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3157. List<TestItem> items = new List<TestItem>();
  3158. items.Add(new TestItem()
  3159. {
  3160. Parameter_name = "载具码",
  3161. Parameter_value = CarrierBarcode,
  3162. Parameter_unit = ""
  3163. });
  3164. items.Add(new TestItem()
  3165. {
  3166. Parameter_name = "产品码",
  3167. Parameter_value = sn,
  3168. Parameter_unit = ""
  3169. });
  3170. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3171. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3172. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3173. stopwatch2.Start();
  3174. //进站结果写入PLC
  3175. CommandFromPLC resultToPlC = new CommandFromPLC();
  3176. resultToPlC.cmd = 0;
  3177. resultToPlC.cmdParam = 0; //指令参数
  3178. resultToPlC.cmdResult = mesResultFrmWeb;
  3179. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3180. stopwatch2.Stop();
  3181. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3182. //保存PLC返回MES数据到本地
  3183. ResponseMessage message = new ResponseMessage();
  3184. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  3185. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  3186. if (message.result == false)
  3187. {
  3188. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3189. }
  3190. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3191. }
  3192. catch (Exception ex)
  3193. {
  3194. stopwatch2.Start();
  3195. CommandFromPLC resultToPlC = new CommandFromPLC();
  3196. resultToPlC.cmd = 0;
  3197. resultToPlC.cmdParam = 0; //指令参数
  3198. resultToPlC.cmdResult = 110;
  3199. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3200. stopwatch2.Stop();
  3201. string str = ex.StackTrace;
  3202. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3203. }
  3204. stopwatch1.Stop();
  3205. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3206. ProgressState = false;
  3207. }
  3208. #endregion
  3209. #region S7
  3210. /// <summary>
  3211. /// [S7] 锁螺丝设备
  3212. /// </summary>
  3213. /// <param name="plcNo">PLC编号</param>
  3214. private void ReadStation_S7(int plcNo)
  3215. {
  3216. string stationCode = "[OP70]";
  3217. string stationName = "上盖板锁螺丝";
  3218. string stationNameStr = stationCode + stationName;
  3219. string tagBaseName = "g_OP70_MES"; //标签变量名称
  3220. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3221. string tagAgvCommName = "agvCommFrmPC";
  3222. string tagBarsetName = "BarcodeSet";
  3223. string tagScrewDataset = "screwDataset";
  3224. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  3225. (int, string) result;
  3226. AtlasScrew atlasScrewLeft= new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort, 3000, 3000,"Left");
  3227. atlasScrewLeft.Initial();
  3228. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort, 3000, 3000,"Right");
  3229. atlasScrewRight.Initial();
  3230. while (true)
  3231. {
  3232. try
  3233. {
  3234. if (!GlobalContext._IsCon_Funs1)
  3235. {
  3236. UpdatePLCMonitor(1, plcNo, 0);
  3237. continue;
  3238. }
  3239. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3240. {
  3241. Stopwatch stopwatch1 = new Stopwatch();
  3242. Stopwatch stopwatch2 = new Stopwatch();
  3243. stopwatch1.Start();
  3244. stopwatch2.Start();
  3245. #region 一次性读取所有数据
  3246. // 一次性读取所有数据
  3247. result = FunsEip[plcNo].Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3248. if (result.Item1 != 0)
  3249. {
  3250. //richTextBox1.AppendText("\n" + strRet);
  3251. }
  3252. else
  3253. {
  3254. //richTextBox1.AppendText("\n" + "读取成功");
  3255. }
  3256. #endregion 一次性读取所有数据
  3257. stopwatch2.Stop();
  3258. #region 左边进站
  3259. try
  3260. {
  3261. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3262. {
  3263. lock (lockObj)
  3264. {
  3265. if (!ProgressState)
  3266. {
  3267. ProgressState = true;
  3268. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName,"Left", out ProgressState, atlasScrewLeft));
  3269. }
  3270. }
  3271. }
  3272. }
  3273. catch (Exception ex)
  3274. {
  3275. ProgressState = false;
  3276. string str = ex.StackTrace;
  3277. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3278. }
  3279. #endregion 左边进站
  3280. #region 左边出站
  3281. try
  3282. {
  3283. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3284. {
  3285. lock (lockObj)
  3286. {
  3287. if (!ProgressState)
  3288. {
  3289. ProgressState = true;
  3290. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  3291. }
  3292. }
  3293. }
  3294. }
  3295. catch (Exception ex)
  3296. {
  3297. ProgressState = false;
  3298. string str = ex.StackTrace;
  3299. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3300. }
  3301. #endregion 左边出站
  3302. #region 右边进站
  3303. try
  3304. {
  3305. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3306. {
  3307. lock (lockObj)
  3308. {
  3309. if (!ProgressState)
  3310. {
  3311. ProgressState = true;
  3312. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right" + tagBarsetName,"Right", out ProgressState, atlasScrewRight));
  3313. }
  3314. }
  3315. }
  3316. }
  3317. catch (Exception ex)
  3318. {
  3319. ProgressState = false;
  3320. string str = ex.StackTrace;
  3321. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3322. }
  3323. #endregion 右边进站
  3324. #region 右边出站
  3325. try
  3326. {
  3327. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3328. {
  3329. lock (lockObj)
  3330. {
  3331. if (!ProgressState)
  3332. {
  3333. ProgressState = true;
  3334. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  3335. }
  3336. }
  3337. }
  3338. }
  3339. catch (Exception ex)
  3340. {
  3341. ProgressState = false;
  3342. string str = ex.StackTrace;
  3343. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3344. }
  3345. #endregion 右边出站
  3346. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3347. stopwatch1.Stop();
  3348. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3349. }
  3350. else
  3351. {
  3352. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3353. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3354. FunsEip[plcNo].Connect(); // 重连
  3355. }
  3356. }
  3357. catch (Exception ex)
  3358. {
  3359. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3360. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3361. }
  3362. Thread.Sleep(IntervalReadPLC);
  3363. }
  3364. }
  3365. /// <summary>
  3366. /// [S7] 锁螺丝设备 - 进站
  3367. /// </summary>
  3368. /// <param name="plcNo">PLC编号</param>
  3369. /// <param name="stationNameStr">工站全称</param>
  3370. /// <param name="stPLC_MesData"></param>
  3371. /// <param name="tagMesCommName"></param>
  3372. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName, string direction,out bool ProgressState, AtlasScrew atlasScrew)
  3373. {
  3374. Stopwatch stopwatch1 = new Stopwatch();
  3375. Stopwatch stopwatch2 = new Stopwatch();
  3376. string atlasSn=string.Empty;
  3377. try
  3378. {
  3379. stopwatch1.Start();
  3380. AddMessage(LogType.Info, stationNameStr +"_"+ direction+"_进站开始");
  3381. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3382. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  3383. string StationId = string.Empty; // 工位ID(可配置)
  3384. if (direction == "Left")
  3385. {
  3386. StationId = GlobalContext.S7_StationId_1;
  3387. }
  3388. if (direction == "Right")
  3389. {
  3390. StationId = GlobalContext.S7_StationId_2;
  3391. }
  3392. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3393. //载具码验证产品码
  3394. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3395. if (string.IsNullOrEmpty(strProductBarcode))
  3396. {
  3397. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3398. }
  3399. sn = strProductBarcode;
  3400. atlasSn= strProductBarcode;
  3401. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3402. if (direction == "Left")
  3403. {
  3404. isCollectingFlagLeft = false;//采集螺丝数据结束
  3405. }
  3406. if (direction == "Right")
  3407. {
  3408. isCollectingFlagRight = false;//采集螺丝数据结束
  3409. }
  3410. // 产品SN(物料码)校验
  3411. List<TestItem> item = new List<TestItem>();
  3412. stopwatch2.Start();
  3413. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3414. stopwatch2.Stop();
  3415. //指令执行结果 1:OK 110:失败
  3416. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3417. //进站结果写入PLC
  3418. CommandFromPLC resultToPlC = new CommandFromPLC();
  3419. resultToPlC.cmd = 0;
  3420. resultToPlC.cmdParam = 0; //指令参数
  3421. resultToPlC.cmdResult = mesResultFrmWeb;
  3422. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3423. }
  3424. catch (Exception ex)
  3425. {
  3426. string str = ex.StackTrace;
  3427. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3428. CommandFromPLC resultToPlC = new CommandFromPLC();
  3429. resultToPlC.cmd = 0;
  3430. resultToPlC.cmdParam = 0; //指令参数
  3431. resultToPlC.cmdResult = 110;
  3432. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3433. }
  3434. stopwatch1.Stop();
  3435. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3436. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3437. ProgressState = false;
  3438. //开始采集螺丝数据
  3439. if (direction == "Left")
  3440. {
  3441. isCollectingFlagLeft = true;
  3442. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  3443. }
  3444. if (direction == "Right")
  3445. {
  3446. isCollectingFlagRight = true;
  3447. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  3448. }
  3449. }
  3450. /// <summary>
  3451. /// [S7] 锁螺丝设备 - 出站
  3452. /// </summary>
  3453. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  3454. {
  3455. Stopwatch stopwatch1 = new Stopwatch();
  3456. Stopwatch stopwatch2 = new Stopwatch();
  3457. try
  3458. {
  3459. stopwatch1.Start();
  3460. AddMessage(LogType.Info, stationNameStr +"_"+ direction+ "_出站开始");
  3461. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3462. string processItem = stationName; // 测试项目
  3463. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3464. string supplierCode = ""; // 供应商代码
  3465. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3466. string batch_num = GlobalContext.BatchNumber; // 批次号
  3467. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3468. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3469. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3470. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  3471. string StationId = string.Empty; // 工位ID(可配置)
  3472. if (direction == "Left")
  3473. {
  3474. StationId = GlobalContext.S7_StationId_1;
  3475. }
  3476. if (direction == "Right")
  3477. {
  3478. StationId = GlobalContext.S7_StationId_2;
  3479. }
  3480. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3481. a1Result = 1;
  3482. bool pass = a1Result == 1;
  3483. //根据载具码获取产品码
  3484. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3485. if (string.IsNullOrEmpty(strProductBarcode))
  3486. {
  3487. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3488. }
  3489. sn = strProductBarcode;
  3490. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3491. List<TestItem> items = new List<TestItem>();
  3492. items.Add(new TestItem()
  3493. {
  3494. Parameter_name = "载具码",
  3495. Parameter_value = CarrierBarcode,
  3496. Parameter_unit = ""
  3497. });
  3498. items.Add(new TestItem()
  3499. {
  3500. Parameter_name = "产品码",
  3501. Parameter_value = sn,
  3502. Parameter_unit = ""
  3503. });
  3504. int result1 = 1;
  3505. if (direction == "Right")
  3506. {
  3507. SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3508. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3509. }
  3510. //if (direction == "Left")
  3511. //{
  3512. // isCollectingFlagLeft = false;//采集螺丝数据结束
  3513. //}
  3514. //if (direction == "Right")
  3515. //{
  3516. // isCollectingFlagRight = false;//采集螺丝数据结束
  3517. //}
  3518. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3519. stopwatch2.Start();
  3520. //进站结果写入PLC
  3521. CommandFromPLC resultToPlC = new CommandFromPLC();
  3522. resultToPlC.cmd = 0;
  3523. resultToPlC.cmdParam = 0; //指令参数
  3524. resultToPlC.cmdResult = mesResultFrmWeb;
  3525. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3526. stopwatch2.Stop();
  3527. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  3528. //保存PLC返回MES数据到本地
  3529. ResponseMessage message = new ResponseMessage();
  3530. if (direction == "Left")
  3531. {
  3532. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3533. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3534. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3535. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  3536. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3537. if (message.result == false)
  3538. {
  3539. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  3540. }
  3541. }
  3542. if (direction == "Right")
  3543. {
  3544. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3545. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3546. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3547. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  3548. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3549. if (message.result == false)
  3550. {
  3551. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  3552. }
  3553. }
  3554. //保存螺丝数据到txt
  3555. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes, stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  3556. if (result.Item1 != 0)
  3557. {
  3558. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  3559. }
  3560. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_保存加工数据到本地成功");
  3561. }
  3562. catch (Exception ex)
  3563. {
  3564. stopwatch2.Start();
  3565. CommandFromPLC resultToPlC = new CommandFromPLC();
  3566. resultToPlC.cmd = 0;
  3567. resultToPlC.cmdParam = 0; //指令参数
  3568. resultToPlC.cmdResult = 110;
  3569. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3570. stopwatch2.Stop();
  3571. string str = ex.StackTrace;
  3572. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3573. }
  3574. stopwatch1.Stop();
  3575. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3576. ProgressState = false;
  3577. }
  3578. #endregion
  3579. #region S8
  3580. /// <summary>
  3581. /// [S8] 3D螺丝高度检测设备
  3582. /// </summary>
  3583. /// <param name="plcNo">PLC编号</param>
  3584. private void ReadStation_S8(int plcNo)
  3585. {
  3586. string stationCode = "[OP80]";
  3587. string stationName = "NG下料";
  3588. string stationNameStr = stationCode + stationName;
  3589. string tagBaseName = "g_OP80_MES"; //标签变量名称
  3590. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3591. string tagAgvCommName = "agvCommFrmPC";
  3592. string tagBarsetName = "BarcodeSet";
  3593. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  3594. (int, string) result;
  3595. while (true)
  3596. {
  3597. try
  3598. {
  3599. if (!GlobalContext._IsCon_Funs1)
  3600. {
  3601. UpdatePLCMonitor(1, plcNo, 0);
  3602. continue;
  3603. }
  3604. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3605. {
  3606. Stopwatch stopwatch1 = new Stopwatch();
  3607. Stopwatch stopwatch2 = new Stopwatch();
  3608. stopwatch1.Start();
  3609. stopwatch2.Start();
  3610. #region 一次性读取所有数据
  3611. // 一次性读取所有数据
  3612. result = FunsEip[plcNo].Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3613. if (result.Item1 != 0)
  3614. {
  3615. //richTextBox1.AppendText("\n" + strRet);
  3616. }
  3617. else
  3618. {
  3619. //richTextBox1.AppendText("\n" + "读取成功");
  3620. }
  3621. #endregion 一次性读取所有数据
  3622. stopwatch2.Stop();
  3623. #region 进站
  3624. try
  3625. {
  3626. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3627. {
  3628. lock (lockObj)
  3629. {
  3630. if (!ProgressState)
  3631. {
  3632. ProgressState = true;
  3633. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3634. }
  3635. }
  3636. }
  3637. }
  3638. catch (Exception ex)
  3639. {
  3640. ProgressState = false;
  3641. string str = ex.StackTrace;
  3642. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3643. }
  3644. #endregion 进站
  3645. #region 出站
  3646. try
  3647. {
  3648. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3649. {
  3650. lock (lockObj)
  3651. {
  3652. if (!ProgressState)
  3653. {
  3654. ProgressState = true;
  3655. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3656. }
  3657. }
  3658. }
  3659. }
  3660. catch (Exception ex)
  3661. {
  3662. ProgressState = false;
  3663. string str = ex.StackTrace;
  3664. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3665. }
  3666. #endregion 进站
  3667. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3668. stopwatch1.Stop();
  3669. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3670. }
  3671. else
  3672. {
  3673. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3674. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3675. FunsEip[plcNo].Connect(); // 重连
  3676. }
  3677. }
  3678. catch (Exception ex)
  3679. {
  3680. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3681. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3682. }
  3683. Thread.Sleep(IntervalReadPLC);
  3684. }
  3685. }
  3686. /// <summary>
  3687. /// [S8] 3D螺丝高度检测设备 - 进站
  3688. /// </summary>
  3689. /// <param name="plcNo">PLC编号</param>
  3690. /// <param name="stationNameStr">工站全称</param>
  3691. /// <param name="stPLC_MesData"></param>
  3692. /// <param name="tagMesCommName"></param>
  3693. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3694. {
  3695. Stopwatch stopwatch1 = new Stopwatch();
  3696. Stopwatch stopwatch2 = new Stopwatch();
  3697. try
  3698. {
  3699. stopwatch1.Start();
  3700. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3701. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3702. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  3703. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  3704. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3705. //载具码验证产品码
  3706. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3707. if (string.IsNullOrEmpty(strProductBarcode))
  3708. {
  3709. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3710. }
  3711. sn = strProductBarcode;
  3712. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3713. // 产品SN(物料码)校验
  3714. List<TestItem> item = new List<TestItem>();
  3715. stopwatch2.Start();
  3716. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3717. stopwatch2.Stop();
  3718. //指令执行结果 1:OK 110:失败
  3719. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3720. //进站结果写入PLC
  3721. CommandFromPLC resultToPlC = new CommandFromPLC();
  3722. resultToPlC.cmd = 0;
  3723. resultToPlC.cmdParam = 0; //指令参数
  3724. resultToPlC.cmdResult = mesResultFrmWeb;
  3725. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3726. }
  3727. catch (Exception ex)
  3728. {
  3729. string str = ex.StackTrace;
  3730. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3731. CommandFromPLC resultToPlC = new CommandFromPLC();
  3732. resultToPlC.cmd = 0;
  3733. resultToPlC.cmdParam = 0; //指令参数
  3734. resultToPlC.cmdResult = 110;
  3735. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3736. }
  3737. stopwatch1.Stop();
  3738. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3739. ProgressState = false;
  3740. }
  3741. /// <summary>
  3742. /// [S8] 3D螺丝高度检测设备 - 出站接口
  3743. /// </summary>
  3744. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3745. {
  3746. Stopwatch stopwatch1 = new Stopwatch();
  3747. Stopwatch stopwatch2 = new Stopwatch();
  3748. try
  3749. {
  3750. stopwatch1.Start();
  3751. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3752. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3753. string processItem = stationName; // 测试项目
  3754. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3755. string supplierCode = ""; // 供应商代码
  3756. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3757. string batch_num = GlobalContext.BatchNumber; // 批次号
  3758. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3759. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3760. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3761. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  3762. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  3763. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3764. bool pass = a1Result == 1;
  3765. //根据载具码获取产品码
  3766. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3767. if (string.IsNullOrEmpty(strProductBarcode))
  3768. {
  3769. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3770. }
  3771. sn = strProductBarcode;
  3772. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3773. List<TestItem> items = new List<TestItem>();
  3774. items.Add(new TestItem()
  3775. {
  3776. Parameter_name = "载具码",
  3777. Parameter_value = CarrierBarcode,
  3778. Parameter_unit = ""
  3779. });
  3780. items.Add(new TestItem()
  3781. {
  3782. Parameter_name = "产品码",
  3783. Parameter_value = sn,
  3784. Parameter_unit = ""
  3785. });
  3786. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3787. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3788. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3789. stopwatch2.Start();
  3790. //进站结果写入PLC
  3791. CommandFromPLC resultToPlC = new CommandFromPLC();
  3792. resultToPlC.cmd = 0;
  3793. resultToPlC.cmdParam = 0; //指令参数
  3794. resultToPlC.cmdResult = mesResultFrmWeb;
  3795. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3796. stopwatch2.Stop();
  3797. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3798. //保存PLC返回MES数据到本地
  3799. ResponseMessage message = new ResponseMessage();
  3800. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  3801. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3802. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  3803. if (message.result == false)
  3804. {
  3805. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3806. }
  3807. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3808. }
  3809. catch (Exception ex)
  3810. {
  3811. stopwatch2.Start();
  3812. CommandFromPLC resultToPlC = new CommandFromPLC();
  3813. resultToPlC.cmd = 0;
  3814. resultToPlC.cmdParam = 0; //指令参数
  3815. resultToPlC.cmdResult = 110;
  3816. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3817. stopwatch2.Stop();
  3818. string str = ex.StackTrace;
  3819. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3820. }
  3821. stopwatch1.Stop();
  3822. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3823. ProgressState = false;
  3824. }
  3825. #endregion
  3826. #region S9
  3827. /// <summary>
  3828. /// [S9] 下料设备
  3829. /// </summary>
  3830. /// <param name="plcNo">PLC编号</param>
  3831. private void ReadStation_S9(int plcNo)
  3832. {
  3833. string stationCode = "[OP90]";
  3834. string stationName = "半成品下料";
  3835. string stationNameStr = stationCode + stationName;
  3836. string tagBaseName = "g_OP90_MES"; //标签变量名称
  3837. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3838. string tagAgvCommName = "agvCommFrmPC";
  3839. string tagBarsetName = "BarcodeSet";
  3840. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  3841. (int, string) result;
  3842. while (true)
  3843. {
  3844. try
  3845. {
  3846. if (!GlobalContext._IsCon_Funs1)
  3847. {
  3848. UpdatePLCMonitor(1, plcNo, 0);
  3849. continue;
  3850. }
  3851. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3852. {
  3853. Stopwatch stopwatch1 = new Stopwatch();
  3854. Stopwatch stopwatch2 = new Stopwatch();
  3855. stopwatch1.Start();
  3856. stopwatch2.Start();
  3857. #region 一次性读取所有数据
  3858. // 一次性读取所有数据
  3859. result = FunsEip[plcNo].Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3860. if (result.Item1 != 0)
  3861. {
  3862. //richTextBox1.AppendText("\n" + strRet);
  3863. }
  3864. else
  3865. {
  3866. //richTextBox1.AppendText("\n" + "读取成功");
  3867. }
  3868. #endregion 一次性读取所有数据
  3869. stopwatch2.Stop();
  3870. #region 进站
  3871. try
  3872. {
  3873. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3874. {
  3875. lock (lockObj)
  3876. {
  3877. if (!ProgressState)
  3878. {
  3879. ProgressState = true;
  3880. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3881. }
  3882. }
  3883. }
  3884. }
  3885. catch (Exception ex)
  3886. {
  3887. ProgressState = false;
  3888. string str = ex.StackTrace;
  3889. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3890. }
  3891. #endregion 进站
  3892. #region 出站
  3893. try
  3894. {
  3895. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3896. {
  3897. lock (lockObj)
  3898. {
  3899. if (!ProgressState)
  3900. {
  3901. ProgressState = true;
  3902. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3903. }
  3904. }
  3905. }
  3906. }
  3907. catch (Exception ex)
  3908. {
  3909. ProgressState = false;
  3910. string str = ex.StackTrace;
  3911. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3912. }
  3913. #endregion 进站
  3914. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3915. stopwatch1.Stop();
  3916. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3917. }
  3918. else
  3919. {
  3920. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3921. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3922. FunsEip[plcNo].Connect(); // 重连
  3923. }
  3924. }
  3925. catch (Exception ex)
  3926. {
  3927. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3928. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3929. }
  3930. Thread.Sleep(IntervalReadPLC);
  3931. }
  3932. }
  3933. /// <summary>
  3934. /// [S9] 下料设备 - 进站
  3935. /// </summary>
  3936. /// <param name="plcNo">PLC编号</param>
  3937. /// <param name="stationNameStr">工站全称</param>
  3938. /// <param name="stPLC_MesData"></param>
  3939. /// <param name="tagMesCommName"></param>
  3940. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3941. {
  3942. Stopwatch stopwatch1 = new Stopwatch();
  3943. Stopwatch stopwatch2 = new Stopwatch();
  3944. try
  3945. {
  3946. stopwatch1.Start();
  3947. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3948. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3949. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  3950. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  3951. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3952. //载具码验证产品码
  3953. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3954. if (string.IsNullOrEmpty(strProductBarcode))
  3955. {
  3956. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3957. }
  3958. sn = strProductBarcode;
  3959. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3960. // 产品SN(物料码)校验
  3961. List<TestItem> item = new List<TestItem>();
  3962. stopwatch2.Start();
  3963. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3964. stopwatch2.Stop();
  3965. //指令执行结果 1:OK 110:失败
  3966. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3967. //进站结果写入PLC
  3968. CommandFromPLC resultToPlC = new CommandFromPLC();
  3969. resultToPlC.cmd = 0;
  3970. resultToPlC.cmdParam = 0; //指令参数
  3971. resultToPlC.cmdResult = mesResultFrmWeb;
  3972. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3973. }
  3974. catch (Exception ex)
  3975. {
  3976. string str = ex.StackTrace;
  3977. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3978. CommandFromPLC resultToPlC = new CommandFromPLC();
  3979. resultToPlC.cmd = 0;
  3980. resultToPlC.cmdParam = 0; //指令参数
  3981. resultToPlC.cmdResult = 110;
  3982. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3983. }
  3984. stopwatch1.Stop();
  3985. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3986. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3987. ProgressState = false;
  3988. }
  3989. /// <summary>
  3990. /// [S9] 下料设备 - 出站接口
  3991. /// </summary>
  3992. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3993. {
  3994. Stopwatch stopwatch1 = new Stopwatch();
  3995. Stopwatch stopwatch2 = new Stopwatch();
  3996. try
  3997. {
  3998. stopwatch1.Start();
  3999. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  4000. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4001. string processItem = stationName; // 测试项目
  4002. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4003. string supplierCode = ""; // 供应商代码
  4004. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4005. string batch_num = GlobalContext.BatchNumber; // 批次号
  4006. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4007. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  4008. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  4009. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  4010. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  4011. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  4012. bool pass = a1Result == 1;
  4013. //根据载具码获取产品码
  4014. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  4015. if (string.IsNullOrEmpty(strProductBarcode))
  4016. {
  4017. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  4018. }
  4019. sn = strProductBarcode;
  4020. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  4021. List<TestItem> items = new List<TestItem>();
  4022. items.Add(new TestItem()
  4023. {
  4024. Parameter_name = "载具码",
  4025. Parameter_value = CarrierBarcode,
  4026. Parameter_unit = ""
  4027. });
  4028. items.Add(new TestItem()
  4029. {
  4030. Parameter_name = "产品码",
  4031. Parameter_value = sn,
  4032. Parameter_unit = ""
  4033. });
  4034. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4035. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  4036. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  4037. stopwatch2.Start();
  4038. //进站结果写入PLC
  4039. CommandFromPLC resultToPlC = new CommandFromPLC();
  4040. resultToPlC.cmd = 0;
  4041. resultToPlC.cmdParam = 0; //指令参数
  4042. resultToPlC.cmdResult = mesResultFrmWeb;
  4043. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4044. stopwatch2.Stop();
  4045. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  4046. //保存PLC返回MES数据到本地
  4047. ResponseMessage message = new ResponseMessage();
  4048. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  4049. if (message.result == false)
  4050. {
  4051. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  4052. }
  4053. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  4054. if (result1 == 1)
  4055. {
  4056. //载具码解除绑定
  4057. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  4058. if (message.result == false)
  4059. {
  4060. AddMessage(LogType.Error, message.text);
  4061. }
  4062. }
  4063. }
  4064. catch (Exception ex)
  4065. {
  4066. stopwatch2.Start();
  4067. CommandFromPLC resultToPlC = new CommandFromPLC();
  4068. resultToPlC.cmd = 0;
  4069. resultToPlC.cmdParam = 0; //指令参数
  4070. resultToPlC.cmdResult = 110;
  4071. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4072. stopwatch2.Stop();
  4073. string str = ex.StackTrace;
  4074. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4075. }
  4076. stopwatch1.Stop();
  4077. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4078. ProgressState = false;
  4079. }
  4080. #endregion
  4081. #endregion Xiaomi
  4082. #region PLC1 张超凡
  4083. #region [S1] Tray盘上料装备(板测)
  4084. /// <summary>
  4085. /// S1工位的数据- 触发信号上次的值
  4086. /// </summary>
  4087. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  4088. /// <summary>
  4089. /// S1工位的数据(含触发信号)
  4090. /// </summary>
  4091. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  4092. /// <summary>
  4093. /// S1工位的数据- 回写点位
  4094. /// </summary>
  4095. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  4096. ///// <summary>
  4097. ///// 触发信号
  4098. ///// </summary>
  4099. //private ManualResetEvent[] MreTasks;
  4100. /// <summary>
  4101. /// [S1] Tray盘上料装备(板测)
  4102. /// </summary>
  4103. /// <param name="plcNo">PLC编号</param>
  4104. //private void ReadStation_S1(int plcNo)
  4105. //{
  4106. // // [S1] Tray盘上料装备
  4107. // // [S2] FCT
  4108. // // [S3] 值板机
  4109. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  4110. // // [S5] Tray盘下料装备
  4111. // string stationCode = "[S1]";
  4112. // string stationName = "Tray盘上料装备";
  4113. // string stationNameStr = stationCode + stationName;
  4114. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4115. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4116. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4117. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4118. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4119. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4120. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4121. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4122. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  4123. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4124. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  4125. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4126. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4127. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  4128. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  4129. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4130. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  4131. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  4132. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4133. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  4134. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  4135. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  4136. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  4137. // s1PLCData.Add("a1Result", 0); // 产品结果
  4138. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4139. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  4140. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  4141. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  4142. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  4143. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4144. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  4145. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4146. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  4147. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  4148. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  4149. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4150. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  4151. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  4152. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4153. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  4154. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  4155. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4156. // while (IsRun)
  4157. // {
  4158. // try
  4159. // {
  4160. // if (!GlobalContext._IsCon_Funs1)
  4161. // {
  4162. // UpdatePLCMonitor(1, plcNo, 0);
  4163. // continue;
  4164. // }
  4165. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  4166. // {
  4167. // Stopwatch stopwatch1 = new Stopwatch();
  4168. // Stopwatch stopwatch2 = new Stopwatch();
  4169. // stopwatch1.Start();
  4170. // stopwatch2.Start();
  4171. // #region 一次性读取所有数据
  4172. // // 一次性读取所有数据
  4173. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  4174. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  4175. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  4176. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  4177. // int[] datas = data1.Concat(data2).ToArray();
  4178. // datas = datas.Concat(data3).ToArray();
  4179. // datas = datas.Concat(data4).ToArray();
  4180. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  4181. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  4182. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  4183. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  4184. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  4185. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  4186. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  4187. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  4188. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  4189. // s1PLCData["a1MES_FLAG"] = datas[109];
  4190. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  4191. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  4192. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  4193. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  4194. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  4195. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  4196. // s1PLCData["a1Result"] = datas[170];
  4197. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  4198. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  4199. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  4200. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  4201. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  4202. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  4203. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  4204. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  4205. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  4206. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  4207. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  4208. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  4209. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  4210. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  4211. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  4212. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  4213. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  4214. // s1PLCData["a1AGVUpStart"] = datas[308];
  4215. // s1PLCData["a1AGVUpEnd"] = datas[309];
  4216. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  4217. // s1PLCData["a1AGVDownStart"] = datas[321];
  4218. // s1PLCData["a1AGVDownEnd"] = datas[322];
  4219. // #endregion 一次性读取所有数据
  4220. // stopwatch2.Stop();
  4221. // #region 回写操作,写后清空flag
  4222. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  4223. // #endregion 回写操作,写后清空flag
  4224. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4225. // try
  4226. // {
  4227. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  4228. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  4229. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  4230. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  4231. // {
  4232. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  4233. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  4234. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  4235. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  4236. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  4237. // }
  4238. // }
  4239. // catch (Exception ex)
  4240. // {
  4241. // // 6代表上位机报警
  4242. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  4243. // string str = ex.StackTrace;
  4244. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4245. // }
  4246. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4247. // #region 上料进站校验
  4248. // try
  4249. // {
  4250. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  4251. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  4252. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  4253. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  4254. // {
  4255. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  4256. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  4257. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  4258. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  4259. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  4260. // }
  4261. // }
  4262. // catch (Exception ex)
  4263. // {
  4264. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4265. // string str = ex.StackTrace;
  4266. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4267. // }
  4268. // #endregion 上料进站校验
  4269. // #region Tray盘上料装备-出站接口
  4270. // try
  4271. // {
  4272. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  4273. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  4274. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  4275. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  4276. // {
  4277. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  4278. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  4279. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  4280. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  4281. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  4282. // }
  4283. // }
  4284. // catch (Exception ex)
  4285. // {
  4286. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  4287. // string str = ex.StackTrace;
  4288. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4289. // }
  4290. // #endregion Tray盘上料装备-出站接口
  4291. // #region Tray盘上料装备-将SN发给ICT标机
  4292. // try
  4293. // {
  4294. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  4295. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  4296. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  4297. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  4298. // {
  4299. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  4300. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  4301. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  4302. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  4303. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  4304. // }
  4305. // }
  4306. // catch (Exception ex)
  4307. // {
  4308. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4309. // string str = ex.StackTrace;
  4310. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4311. // }
  4312. // #endregion Tray盘上料装备-将SN发给ICT标机
  4313. // #region Tray盘上料装备-点检数据
  4314. // //try
  4315. // //{
  4316. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  4317. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  4318. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  4319. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  4320. // // if (pLC_Flag && !mES_Flag) // 1 0
  4321. // // {
  4322. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  4323. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  4324. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  4325. // // }
  4326. // // else if (!pLC_Flag && mES_Flag) // 0 1
  4327. // // {
  4328. // // // 清空写给PLC的数据
  4329. // // // MES_Flag重置为0
  4330. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  4331. // // }
  4332. // //}
  4333. // //catch (Exception ex)
  4334. // //{
  4335. // // // MES_Flag 为2上位机报错
  4336. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4337. // // string str = ex.StackTrace;
  4338. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4339. // //}
  4340. // #endregion Tray盘上料装备-点检数据
  4341. // #region 节拍接口
  4342. // try
  4343. // {
  4344. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  4345. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  4346. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  4347. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  4348. // {
  4349. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  4350. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  4351. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  4352. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  4353. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  4354. // }
  4355. // }
  4356. // catch (Exception ex)
  4357. // {
  4358. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4359. // string str = ex.StackTrace;
  4360. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4361. // }
  4362. // #endregion 节拍接口
  4363. // #region AGV上料
  4364. // // AGV上料叫AGV信号
  4365. // try
  4366. // {
  4367. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  4368. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  4369. // if (a1AGVUpCall != a1AGVUpCallOld)
  4370. // {
  4371. // if (a1AGVUpCall == 1) // 0->1
  4372. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  4373. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  4374. // }
  4375. // }
  4376. // catch (Exception ex)
  4377. // {
  4378. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4379. // string str = ex.StackTrace;
  4380. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4381. // }
  4382. // // AGV上料完成信号
  4383. // try
  4384. // {
  4385. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  4386. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  4387. // if (a1AGVUpEnd != a1AGVUpEndOld)
  4388. // {
  4389. // if (a1AGVUpEnd == 1) // 0->1
  4390. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  4391. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  4392. // }
  4393. // }
  4394. // catch (Exception ex)
  4395. // {
  4396. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  4397. // string str = ex.StackTrace;
  4398. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4399. // }
  4400. // #endregion AGV上料
  4401. // #region AGV下料
  4402. // // AGV下料叫agv信号
  4403. // try
  4404. // {
  4405. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  4406. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  4407. // if (a1AGVDownCall != a1AGVDownCallOld)
  4408. // {
  4409. // if (a1AGVDownCall == 1) // 0->1
  4410. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  4411. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  4412. // }
  4413. // }
  4414. // catch (Exception ex)
  4415. // {
  4416. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  4417. // string str = ex.StackTrace;
  4418. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4419. // }
  4420. // // AGV下料完成信号
  4421. // try
  4422. // {
  4423. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  4424. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  4425. // if (a1AGVDownEnd != a1AGVDownEndOld)
  4426. // {
  4427. // if (a1AGVDownEnd == 1) // 0->1
  4428. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  4429. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  4430. // }
  4431. // }
  4432. // catch (Exception ex)
  4433. // {
  4434. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  4435. // string str = ex.StackTrace;
  4436. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4437. // }
  4438. // #endregion AGV下料
  4439. // #region 心跳
  4440. // try
  4441. // {
  4442. // short states = 0;
  4443. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  4444. // }
  4445. // catch (Exception ex)
  4446. // {
  4447. // string str = ex.StackTrace;
  4448. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4449. // }
  4450. // #endregion 心跳
  4451. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4452. // stopwatch1.Stop();
  4453. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  4454. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4455. // }
  4456. // else
  4457. // {
  4458. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4459. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4460. // Funs[plcNo].Connect(); // 重连
  4461. // }
  4462. // }
  4463. // catch (Exception ex)
  4464. // {
  4465. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4466. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4467. // Funs[plcNo].ReConnect();
  4468. // }
  4469. // Thread.Sleep(IntervalReadPLC);
  4470. // }
  4471. //}
  4472. /// <summary>
  4473. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  4474. /// </summary>
  4475. /// <param name="plcNo">PLC编号</param>
  4476. /// <param name="stationNameStr">工站全称</param>
  4477. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  4478. {
  4479. Stopwatch stopwatch1 = new Stopwatch();
  4480. Stopwatch stopwatch2 = new Stopwatch();
  4481. try
  4482. {
  4483. stopwatch1.Start();
  4484. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  4485. sn = sn.Replace("\0", "");
  4486. #region 查询载具上的产品信息
  4487. string cavityData = string.Empty;
  4488. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  4489. if (string.IsNullOrEmpty(cavityData))
  4490. cavityData = "";
  4491. if (snResult != 0)
  4492. {
  4493. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4494. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  4495. writeToPLC_Flag1.Adress = 2003;
  4496. writeToPLC_Flag1.Value = (short)6;
  4497. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  4498. stopwatch1.Stop();
  4499. AddMessage(LogType.Info, stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  4500. return;
  4501. }
  4502. #endregion 查询载具上的产品信息
  4503. string[] cavitySNs = cavityData.Split('.');
  4504. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  4505. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  4506. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  4507. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  4508. if (cavitySNs != null && cavitySNs.Length >= 2)
  4509. {
  4510. a1CavitySN1_VehicleStates = cavitySNs[0];
  4511. a1CavitySN2_VehicleStates = cavitySNs[1];
  4512. a1CavityResult1_VehicleStates = 2;
  4513. a1CavityResult2_VehicleStates = 2;
  4514. }
  4515. if (a1CavitySN1_VehicleStates == "假产品")
  4516. a1CavityResult1_VehicleStates = 3;
  4517. if (a1CavitySN2_VehicleStates == "假产品")
  4518. a1CavityResult2_VehicleStates = 3;
  4519. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4520. // 回写
  4521. stopwatch2.Start();
  4522. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  4523. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  4524. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  4525. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  4526. //// MES_Flag
  4527. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  4528. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4529. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4530. writeToPLC_Flag.Adress = 2003;
  4531. writeToPLC_Flag.Value = mES_Flag;
  4532. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  4533. {
  4534. Name = "a1CavitySN1_VehicleStates",
  4535. Adress = 2024,
  4536. ValueType = PLCValueType.String,
  4537. ValueTypeStrLength = 20,
  4538. Value = a1CavitySN1_VehicleStates
  4539. });
  4540. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  4541. {
  4542. Name = "a1CavitySN2_VehicleStates",
  4543. Adress = 2044,
  4544. ValueType = PLCValueType.String,
  4545. ValueTypeStrLength = 20,
  4546. Value = a1CavitySN2_VehicleStates
  4547. });
  4548. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4549. {
  4550. Name = "a1CavityResult1_VehicleStates",
  4551. Adress = 2064,
  4552. ValueType = PLCValueType.Short,
  4553. Value = a1CavityResult1_VehicleStates
  4554. });
  4555. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4556. {
  4557. Name = "a1CavityResult2_VehicleStates",
  4558. Adress = 2065,
  4559. ValueType = PLCValueType.Short,
  4560. Value = a1CavityResult2_VehicleStates
  4561. });
  4562. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4563. stopwatch2.Stop();
  4564. }
  4565. catch (Exception ex)
  4566. {
  4567. string str = ex.StackTrace;
  4568. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4569. // MES_Flag
  4570. stopwatch2.Start();
  4571. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  4572. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4573. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4574. writeToPLC_Flag.Adress = 2003;
  4575. writeToPLC_Flag.Value = (short)6;
  4576. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4577. stopwatch2.Stop();
  4578. }
  4579. stopwatch1.Stop();
  4580. AddMessage(LogType.Info, stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4581. }
  4582. /// <summary>
  4583. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  4584. /// </summary>
  4585. /// <param name="plcNo">PLC编号</param>
  4586. /// <param name="stationNameStr">工站全称</param>
  4587. private void S1上料进站校验(int plcNo, string stationNameStr)
  4588. {
  4589. Stopwatch stopwatch1 = new Stopwatch();
  4590. Stopwatch stopwatch2 = new Stopwatch();
  4591. try
  4592. {
  4593. stopwatch1.Start();
  4594. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  4595. sn = sn.Replace("\0", "");
  4596. // 保存进站数据+调用进站MES接口
  4597. List<TestItem> item = new List<TestItem>();
  4598. stopwatch2.Start();
  4599. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, out string errorMsg);
  4600. stopwatch2.Stop();
  4601. short a1MES_FLAG_Check = (short)result;
  4602. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4603. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4604. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4605. writeToPLC_Flag.Adress = 2077;
  4606. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  4607. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4608. }
  4609. catch (Exception ex)
  4610. {
  4611. string str = ex.StackTrace;
  4612. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4613. // MES_Flag
  4614. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4615. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4616. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4617. writeToPLC_Flag.Adress = 2077;
  4618. writeToPLC_Flag.Value = (short)6;
  4619. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4620. }
  4621. stopwatch1.Stop();
  4622. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4623. }
  4624. /// <summary>
  4625. /// [S1] Tray盘上料装备(板测)- 出站接口
  4626. /// </summary>
  4627. /// <param name="plcNo"></param>
  4628. /// <param name="stationCode"></param>
  4629. /// <param name="stationName"></param>
  4630. private void S1出站接口(int plcNo, string stationCode, string stationName)
  4631. {
  4632. Stopwatch stopwatch1 = new Stopwatch();
  4633. Stopwatch stopwatch2 = new Stopwatch();
  4634. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4635. string stationNameStr = stationCode + stationName;
  4636. string processItem = stationName; // 测试项目
  4637. try
  4638. {
  4639. stopwatch1.Start();
  4640. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4641. //string batch_num = GlobalContext.BatchNumber; // 批次号
  4642. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4643. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4644. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  4645. sn = sn.Replace("\0", "");
  4646. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  4647. partNo1 = partNo1.Replace("\0", "");
  4648. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  4649. partNo2 = partNo2.Replace("\0", "");
  4650. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  4651. bool pass = a1Result == 1;
  4652. stopwatch2.Start();
  4653. // 产品1
  4654. List<TestItem> items = new List<TestItem>();
  4655. items.Add(new TestItem()
  4656. {
  4657. Parameter_name = "载具码",
  4658. Parameter_value = sn,
  4659. Parameter_unit = ""
  4660. });
  4661. items.Add(new TestItem()
  4662. {
  4663. Parameter_name = "载具穴号",
  4664. Parameter_value = "1",
  4665. Parameter_unit = ""
  4666. });
  4667. items.Add(new TestItem()
  4668. {
  4669. Parameter_name = "产品结果",
  4670. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4671. Parameter_unit = ""
  4672. });
  4673. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4674. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  4675. // 产品2
  4676. items = new List<TestItem>();
  4677. items.Add(new TestItem()
  4678. {
  4679. Parameter_name = "载具码",
  4680. Parameter_value = sn,
  4681. Parameter_unit = ""
  4682. });
  4683. items.Add(new TestItem()
  4684. {
  4685. Parameter_name = "载具穴号",
  4686. Parameter_value = "2",
  4687. Parameter_unit = ""
  4688. });
  4689. items.Add(new TestItem()
  4690. {
  4691. Parameter_name = "产品结果",
  4692. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4693. Parameter_unit = ""
  4694. });
  4695. int result2 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4696. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  4697. short result = 0;
  4698. List<int> results = new List<int>() { result1, result2 };
  4699. if (result1 == 1 && result2 == 1)
  4700. result = 1;
  4701. else if (results.Contains(3))
  4702. result = 3;
  4703. else if (results.Contains(2))
  4704. result = 2;
  4705. else if (results.Contains(4))
  4706. result = 4;
  4707. else
  4708. result = 4;
  4709. stopwatch2.Stop();
  4710. #region 存储绑定数据到 边线MES系统中
  4711. if (result == 1)
  4712. {
  4713. string data = string.Concat(partNo1, ".", partNo2);
  4714. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  4715. if (resultMesR != 0)
  4716. {
  4717. result = 4;
  4718. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  4719. }
  4720. }
  4721. #endregion 存储绑定数据到 边线MES系统中
  4722. // MES_Flag 为MES报错
  4723. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4724. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  4725. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4726. writeToPLC_Flag.Name = "a1MES_FLAG";
  4727. writeToPLC_Flag.Adress = 2109;
  4728. writeToPLC_Flag.Value = result;
  4729. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4730. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4731. }
  4732. catch (Exception ex)
  4733. {
  4734. stopwatch2.Restart();
  4735. // MES_Flag 为4上位机报错
  4736. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  4737. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4738. writeToPLC_Flag.Name = "a1MES_FLAG";
  4739. writeToPLC_Flag.Adress = 2109;
  4740. writeToPLC_Flag.Value = (short)4;
  4741. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4742. stopwatch2.Stop();
  4743. string str = ex.StackTrace;
  4744. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4745. }
  4746. stopwatch1.Stop();
  4747. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4748. }
  4749. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  4750. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  4751. //{
  4752. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4753. // string stationNameStr = stationCode + stationName;
  4754. // string processItem = stationName; // 测试项目
  4755. // try
  4756. // {
  4757. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4758. // string accno = "1"; // 工序编号
  4759. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  4760. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  4761. // List<OneCheckItem> items = new List<OneCheckItem>()
  4762. // {
  4763. // new OneCheckItem()
  4764. // {
  4765. // Onecheck_name="胶圈装配行程设定上限",
  4766. // Onecheck_content="上限值",
  4767. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  4768. // },
  4769. // };
  4770. // OneCheckData oneCheckData = new OneCheckData()
  4771. // {
  4772. // Line_code = GlobalContext.LineCode,
  4773. // Line_name = GlobalContext.LineName,
  4774. // Equipment_code = equipmentCode,
  4775. // Equipment_name = equipmentCode,
  4776. // Workorder_code = workorder_code,
  4777. // Procedure_code = accno,
  4778. // Procedure_name = processItem,
  4779. // Oneckeck_values = items,
  4780. // Onecheck_empcode = "",
  4781. // Onecheck_empname = "",
  4782. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  4783. // };
  4784. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  4785. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  4786. // short result = result1 == 1 ? (short)1 : (short)2;
  4787. // // MES_Flag 为4MES报错
  4788. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  4789. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4790. // }
  4791. // catch (Exception ex)
  4792. // {
  4793. // // MES_Flag 为2上位机报错
  4794. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4795. // string str = ex.StackTrace;
  4796. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4797. // }
  4798. //}
  4799. // ReadStation_S1_2 节拍接口+AGV
  4800. /// <summary>
  4801. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  4802. /// </summary>
  4803. /// <param name="plcNo">PLC编号</param>
  4804. /// <param name="stationNameStr">工站全称</param>
  4805. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  4806. {
  4807. Stopwatch stopwatch1 = new Stopwatch();
  4808. Stopwatch stopwatch2 = new Stopwatch();
  4809. try
  4810. {
  4811. stopwatch1.Start();
  4812. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  4813. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  4814. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  4815. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  4816. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  4817. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  4818. // ZS 将SN发给ICT标机(串口)
  4819. short a1MES_FLAG_ICT = 1;
  4820. stopwatch2.Start();
  4821. // MES_Flag
  4822. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  4823. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4824. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4825. writeToPLC_Flag.Adress = 2182;
  4826. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  4827. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4828. stopwatch2.Stop();
  4829. }
  4830. catch (Exception ex)
  4831. {
  4832. string str = ex.StackTrace;
  4833. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4834. stopwatch2.Start();
  4835. // MES_Flag
  4836. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4837. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4838. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4839. writeToPLC_Flag.Adress = 2182;
  4840. writeToPLC_Flag.Value = (short)4;
  4841. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4842. stopwatch2.Stop();
  4843. }
  4844. stopwatch1.Stop();
  4845. AddMessage(LogType.Info, stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4846. }
  4847. /// <summary>
  4848. /// [S1] Tray盘上料装备(板测)- 节拍接口
  4849. /// </summary>
  4850. /// <param name="plcNo">PLC编号</param>
  4851. /// <param name="stationNameStr">工站全称</param>
  4852. private void S1节拍接口(int plcNo, string stationNameStr)
  4853. {
  4854. Stopwatch stopwatch1 = new Stopwatch();
  4855. Stopwatch stopwatch2 = new Stopwatch();
  4856. string resultStr = string.Empty;
  4857. try
  4858. {
  4859. stopwatch1.Start();
  4860. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  4861. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  4862. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  4863. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  4864. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  4865. string a1OEEPartNum = ((int)s1PLCData["a1OEEPartNum"]).ToString(); // 穴位号
  4866. a1OEEPartNum = a1OEEPartNum.Replace("\0", "");
  4867. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4868. if (!actionBool)
  4869. {
  4870. stopwatch2.Start();
  4871. // MES_Flag
  4872. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4873. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4874. writeToPLC_Flag1.Name = "a1OEEMES_FLAG";
  4875. writeToPLC_Flag1.Adress = 2254;
  4876. writeToPLC_Flag1.Value = (short)1;
  4877. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag1);
  4878. stopwatch2.Stop();
  4879. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4880. return;
  4881. }
  4882. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode))
  4883. {
  4884. stopwatch2.Start();
  4885. // MES_Flag
  4886. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4887. WriteToPLC_Flag writeToPLC_Flag2 = new WriteToPLC_Flag(); // MES_Flag
  4888. writeToPLC_Flag2.Name = "a1OEEMES_FLAG";
  4889. writeToPLC_Flag2.Adress = 2254;
  4890. writeToPLC_Flag2.Value = (short)1;
  4891. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag2);
  4892. stopwatch2.Stop();
  4893. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4894. return;
  4895. }
  4896. else if (string.IsNullOrEmpty(a1OEEPartNo) && !string.IsNullOrEmpty(a1OEEVehicleCode))
  4897. { // 查产品SN
  4898. a1OEEPartNo = "Test"; // ZS
  4899. }
  4900. short a1OEEMES_FLAG = 0;
  4901. // 上传OEE
  4902. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  4903. a1OEEMES_FLAG = result.Item1;
  4904. resultStr = result.Item2;
  4905. stopwatch2.Start();
  4906. // MES_Flag
  4907. //Funs[plcNo].WriteMultipleRegisters<short>(2254, a1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4908. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4909. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  4910. writeToPLC_Flag.Adress = 2254;
  4911. writeToPLC_Flag.Value = a1OEEMES_FLAG;
  4912. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  4913. stopwatch2.Stop();
  4914. }
  4915. catch (Exception ex)
  4916. {
  4917. string str = ex.StackTrace;
  4918. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4919. // MES_Flag
  4920. stopwatch2.Start();
  4921. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4922. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4923. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  4924. writeToPLC_Flag.Adress = 2254;
  4925. writeToPLC_Flag.Value = (short)4;
  4926. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  4927. stopwatch2.Stop();
  4928. }
  4929. stopwatch1.Stop();
  4930. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4931. }
  4932. /// <summary>
  4933. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  4934. /// </summary>
  4935. /// <param name="plcNo">PLC编号</param>
  4936. /// <param name="stationNameStr">工站全称</param>
  4937. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  4938. {
  4939. Stopwatch stopwatch1 = new Stopwatch();
  4940. Stopwatch stopwatch2 = new Stopwatch();
  4941. try
  4942. {
  4943. stopwatch1.Start();
  4944. // ZS 呼叫AGV
  4945. short a1AGVUpCall = 2;
  4946. stopwatch2.Start();
  4947. // a1AGVUpCall
  4948. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4949. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4950. writeToPLC_Flag.Name = "a1AGVUpCall";
  4951. writeToPLC_Flag.Adress = 2307;
  4952. writeToPLC_Flag.Value = a1AGVUpCall;
  4953. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  4954. stopwatch2.Stop();
  4955. }
  4956. catch (Exception ex)
  4957. {
  4958. string str = ex.StackTrace;
  4959. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4960. // a1AGVUpCall
  4961. stopwatch2.Start();
  4962. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4963. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4964. writeToPLC_Flag.Name = "a1AGVUpCall";
  4965. writeToPLC_Flag.Adress = 2307;
  4966. writeToPLC_Flag.Value = (short)4;
  4967. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  4968. stopwatch2.Stop();
  4969. }
  4970. stopwatch1.Stop();
  4971. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4972. }
  4973. /// <summary>
  4974. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  4975. /// </summary>
  4976. /// <param name="plcNo">PLC编号</param>
  4977. /// <param name="stationNameStr">工站全称</param>
  4978. private void S1AGV上料完成(int plcNo, string stationNameStr)
  4979. {
  4980. Stopwatch stopwatch1 = new Stopwatch();
  4981. Stopwatch stopwatch2 = new Stopwatch();
  4982. try
  4983. {
  4984. stopwatch1.Start();
  4985. // ZS AGV上料完成,让小车离开
  4986. short a1AGVUpEnd = 2;
  4987. stopwatch2.Start();
  4988. // a1AGVUpEnd
  4989. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4990. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4991. writeToPLC_Flag.Name = "a1AGVUpEnd";
  4992. writeToPLC_Flag.Adress = 2309;
  4993. writeToPLC_Flag.Value = a1AGVUpEnd;
  4994. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  4995. stopwatch2.Stop();
  4996. }
  4997. catch (Exception ex)
  4998. {
  4999. string str = ex.StackTrace;
  5000. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5001. // a1AGVUpEnd
  5002. stopwatch2.Start();
  5003. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  5004. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5005. writeToPLC_Flag.Name = "a1AGVUpEnd";
  5006. writeToPLC_Flag.Adress = 2309;
  5007. writeToPLC_Flag.Value = (short)4;
  5008. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  5009. stopwatch2.Stop();
  5010. }
  5011. stopwatch1.Stop();
  5012. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5013. }
  5014. /// <summary>
  5015. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  5016. /// </summary>
  5017. /// <param name="plcNo">PLC编号</param>
  5018. /// <param name="stationNameStr">工站全称</param>
  5019. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  5020. {
  5021. Stopwatch stopwatch1 = new Stopwatch();
  5022. Stopwatch stopwatch2 = new Stopwatch();
  5023. try
  5024. {
  5025. stopwatch1.Start();
  5026. // ZS 呼叫AGV
  5027. short a1AGVDownCall = 2;
  5028. stopwatch2.Start();
  5029. // a1AGVDownCall
  5030. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5031. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5032. writeToPLC_Flag.Name = "a1AGVDownCall";
  5033. writeToPLC_Flag.Adress = 2320;
  5034. writeToPLC_Flag.Value = a1AGVDownCall;
  5035. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5036. stopwatch2.Stop();
  5037. }
  5038. catch (Exception ex)
  5039. {
  5040. string str = ex.StackTrace;
  5041. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5042. // a1AGVDownCall
  5043. stopwatch2.Start();
  5044. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  5045. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5046. writeToPLC_Flag.Name = "a1AGVDownCall";
  5047. writeToPLC_Flag.Adress = 2320;
  5048. writeToPLC_Flag.Value = (short)4;
  5049. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  5050. stopwatch2.Stop();
  5051. }
  5052. stopwatch1.Stop();
  5053. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5054. }
  5055. /// <summary>
  5056. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  5057. /// </summary>
  5058. /// <param name="plcNo">PLC编号</param>
  5059. /// <param name="stationNameStr">工站全称</param>
  5060. private void S1AGV下料完成(int plcNo, string stationNameStr)
  5061. {
  5062. Stopwatch stopwatch1 = new Stopwatch();
  5063. Stopwatch stopwatch2 = new Stopwatch();
  5064. try
  5065. {
  5066. stopwatch1.Start();
  5067. // ZS AGV上料完成,让小车离开
  5068. short a1AGVDownEnd = 2;
  5069. stopwatch2.Start();
  5070. // a1AGVDownEnd
  5071. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5072. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5073. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5074. writeToPLC_Flag.Adress = 2322;
  5075. writeToPLC_Flag.Value = a1AGVDownEnd;
  5076. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5077. stopwatch2.Stop();
  5078. }
  5079. catch (Exception ex)
  5080. {
  5081. string str = ex.StackTrace;
  5082. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5083. // a1AGVDownEnd
  5084. stopwatch2.Start();
  5085. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  5086. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5087. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5088. writeToPLC_Flag.Adress = 2322;
  5089. writeToPLC_Flag.Value = (short)4;
  5090. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5091. stopwatch2.Stop();
  5092. }
  5093. stopwatch1.Stop();
  5094. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5095. }
  5096. #endregion [S1] Tray盘上料装备(板测)
  5097. #endregion PLC1 张超凡
  5098. #region PLC2 李晓奇
  5099. #region [S2] FCT(板测)
  5100. /// <summary>
  5101. /// S2工位的数据- 触发信号上次的值
  5102. /// </summary>
  5103. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  5104. /// <summary>
  5105. /// S2工位的数据(含触发信号)
  5106. /// </summary>
  5107. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  5108. /// <summary>
  5109. /// S2工位的数据- 回写点位
  5110. /// </summary>
  5111. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5112. /// <summary>
  5113. /// [S2] FCT(板测)
  5114. /// </summary>
  5115. /// <param name="plcNo">PLC编号</param>
  5116. //private void ReadStation_S2(int plcNo)
  5117. //{
  5118. // // [S1] Tray盘上料装备
  5119. // // [S2] FCT
  5120. // // [S3] 值板机
  5121. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5122. // // [S5] Tray盘下料装备
  5123. // /// 上位机心跳
  5124. // /// 获取设备报警数据与状态信息
  5125. // string stationCode = "[S2]";
  5126. // string stationName = "FCT";
  5127. // string stationNameStr = stationCode + stationName;
  5128. // #region 创建字典
  5129. // // 触发信号字典 赋值
  5130. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5131. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  5132. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5133. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5134. // // PLC数据字典 赋值
  5135. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  5136. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  5137. // s2PLCData.Add("b1ProductSN_Check", 0);
  5138. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  5139. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  5140. // s2PLCData.Add("b1ProductSN_Unbind", "");
  5141. // s2PLCData.Add("b1ProductSN_Bind", "");
  5142. // s2PLCData.Add("b1Part1SN_Bind", "");
  5143. // s2PLCData.Add("b1Part2SN_Bind", "");
  5144. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  5145. // s2PLCData.Add("b1MES_FLAG", 0);
  5146. // s2PLCData.Add("b1ProductSN", 0);
  5147. // s2PLCData.Add("b1Part1Result", 0);
  5148. // s2PLCData.Add("b1Part2Result", 0);
  5149. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  5150. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  5151. // s2PLCData.Add("b1OEEProductSN", "");
  5152. // s2PLCData.Add("b1OEEType", 0);
  5153. // #endregion 创建字典
  5154. // while (IsRun)
  5155. // {
  5156. // try
  5157. // {
  5158. // if (!GlobalContext._IsCon_Funs2)
  5159. // {
  5160. // UpdatePLCMonitor(1, plcNo, 0);
  5161. // continue;
  5162. // }
  5163. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5164. // {
  5165. // Stopwatch stopwatch1 = new Stopwatch();
  5166. // Stopwatch stopwatch2 = new Stopwatch();
  5167. // stopwatch1.Start();
  5168. // stopwatch2.Start();
  5169. // #region 一次性读取所有数据
  5170. // // 一次性读取所有数据
  5171. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  5172. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  5173. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  5174. // int[] datas = data1.Concat(data2).ToArray();
  5175. // datas = datas.Concat(data3).ToArray();
  5176. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  5177. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  5178. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5179. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  5180. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  5181. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  5182. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  5183. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  5184. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  5185. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  5186. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  5187. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  5188. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  5189. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  5190. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  5191. // s2PLCData["b1MES_FLAG"] = datas[169];
  5192. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  5193. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  5194. // s2PLCData["b1Part1Result"] = datas[190];
  5195. // s2PLCData["b1Part2Result"] = datas[191];
  5196. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  5197. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  5198. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  5199. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  5200. // s2PLCData["b1OEEType"] = datas[224];
  5201. // #endregion 一次性读取所有数据
  5202. // stopwatch2.Stop();
  5203. // #region 回写操作,写后清空flag
  5204. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  5205. // #endregion 回写操作,写后清空flag
  5206. // #region 进站校验
  5207. // try
  5208. // {
  5209. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  5210. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5211. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  5212. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  5213. // {
  5214. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  5215. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5216. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  5217. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5218. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  5219. // }
  5220. // }
  5221. // catch (Exception ex)
  5222. // {
  5223. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5224. // string str = ex.StackTrace;
  5225. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5226. // }
  5227. // #endregion 进站校验
  5228. // #region 二穴载具解绑/绑定(产品换载具)
  5229. // try
  5230. // {
  5231. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  5232. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5233. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  5234. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  5235. // {
  5236. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  5237. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5238. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  5239. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  5240. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  5241. // }
  5242. // }
  5243. // catch (Exception ex)
  5244. // {
  5245. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5246. // string str = ex.StackTrace;
  5247. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5248. // }
  5249. // #endregion 二穴载具解绑/绑定(产品换载具)
  5250. // #region FCT-出站接口
  5251. // try
  5252. // {
  5253. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  5254. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  5255. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  5256. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  5257. // {
  5258. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  5259. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5260. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  5261. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  5262. // }
  5263. // }
  5264. // catch (Exception ex)
  5265. // {
  5266. // // MES_Flag 为6上位机报错
  5267. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  5268. // string str = ex.StackTrace;
  5269. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5270. // }
  5271. // #endregion FCT-出站接口
  5272. // #region 节拍接口
  5273. // try
  5274. // {
  5275. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  5276. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  5277. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  5278. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  5279. // {
  5280. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  5281. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5282. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  5283. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  5284. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  5285. // }
  5286. // }
  5287. // catch (Exception ex)
  5288. // {
  5289. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5290. // string str = ex.StackTrace;
  5291. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5292. // }
  5293. // #endregion 节拍接口
  5294. // #region 心跳
  5295. // try
  5296. // {
  5297. // short states = 0;
  5298. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  5299. // }
  5300. // catch (Exception ex)
  5301. // {
  5302. // string str = ex.StackTrace;
  5303. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5304. // }
  5305. // #endregion 心跳
  5306. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5307. // stopwatch1.Stop();
  5308. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  5309. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5310. // }
  5311. // else
  5312. // {
  5313. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5314. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5315. // Funs[plcNo].Connect();
  5316. // }
  5317. // }
  5318. // catch (Exception ex)
  5319. // {
  5320. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5321. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5322. // Funs[plcNo].ReConnect();
  5323. // }
  5324. // Thread.Sleep(IntervalReadPLC);
  5325. // }
  5326. //}
  5327. /// <summary>
  5328. /// [S2] FCT(板测)- 进站校验
  5329. /// </summary>
  5330. /// <param name="plcNo">PLC编号</param>
  5331. /// <param name="stationNameStr">工站全称</param>
  5332. private void S2进站校验(int plcNo, string stationNameStr)
  5333. {
  5334. Stopwatch stopwatch1 = new Stopwatch();
  5335. Stopwatch stopwatch2 = new Stopwatch();
  5336. try
  5337. {
  5338. stopwatch1.Start();
  5339. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  5340. sn = sn.Replace("\0", "");
  5341. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5342. // 查询物料码By载具码 并判断是不是假产品
  5343. string cavityData = string.Empty;
  5344. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  5345. if (string.IsNullOrEmpty(cavityData))
  5346. cavityData = "";
  5347. if (snResult != 0)
  5348. {
  5349. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5350. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  5351. writeToPLC_Flag1.Adress = 2003;
  5352. writeToPLC_Flag1.Value = (short)6;
  5353. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  5354. stopwatch1.Stop();
  5355. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5356. return;
  5357. }
  5358. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5359. string[] cavitySNs = cavityData.Split('.');
  5360. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  5361. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  5362. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5363. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5364. if (cavitySNs != null && cavitySNs.Length >= 2)
  5365. {
  5366. b1Part1SN_Check = cavitySNs[0];
  5367. b1Part2SN_Check = cavitySNs[1];
  5368. b1Part1Result_Check = 2;
  5369. b1Part2Result_Check = 2;
  5370. }
  5371. if (b1Part1SN_Check == "假产品")
  5372. b1Part1Result_Check = 3;
  5373. if (b1Part2SN_Check == "假产品")
  5374. b1Part2Result_Check = 3;
  5375. // 调用MES进站
  5376. stopwatch2.Start();
  5377. // 调用MES进站 - 产品1
  5378. List<TestItem> item;
  5379. int result1 = b1Part1Result_Check;
  5380. if (result1 != 3)
  5381. {
  5382. item = new List<TestItem>();
  5383. item.Add(new TestItem()
  5384. {
  5385. Parameter_name = "载具码",
  5386. Parameter_value = sn,
  5387. });
  5388. item.Add(new TestItem()
  5389. {
  5390. Parameter_name = "载具穴号",
  5391. Parameter_value = "1",
  5392. });
  5393. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part1SN_Check, item, out string errorMsg);
  5394. }
  5395. // 调用MES进站 - 产品2
  5396. int result2 = b1Part2Result_Check;
  5397. if (result2 != 3)
  5398. {
  5399. item = new List<TestItem>();
  5400. item.Add(new TestItem()
  5401. {
  5402. Parameter_name = "载具码",
  5403. Parameter_value = sn,
  5404. });
  5405. item.Add(new TestItem()
  5406. {
  5407. Parameter_name = "载具穴号",
  5408. Parameter_value = "2",
  5409. });
  5410. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part2SN_Check, item, out string errorMsg);
  5411. }
  5412. stopwatch2.Stop();
  5413. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5414. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5415. int result = result1;
  5416. if (result == 1)
  5417. result = result2;
  5418. short b1MES_FLAG_Check = (short)result;
  5419. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  5420. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  5421. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  5422. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  5423. //// MES_Flag
  5424. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5425. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5426. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5427. writeToPLC_Flag.Adress = 2003;
  5428. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  5429. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5430. {
  5431. Name = "b1Part1SN_Check",
  5432. Adress = 2024,
  5433. ValueType = PLCValueType.String,
  5434. ValueTypeStrLength = 20,
  5435. Value = b1Part1SN_Check
  5436. });
  5437. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5438. {
  5439. Name = "b1Part2SN_Check",
  5440. Adress = 2044,
  5441. ValueType = PLCValueType.String,
  5442. ValueTypeStrLength = 20,
  5443. Value = b1Part2SN_Check
  5444. });
  5445. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5446. {
  5447. Name = "b1Part1Result_Check",
  5448. Adress = 2064,
  5449. ValueType = PLCValueType.Short,
  5450. Value = b1Part1Result_Check
  5451. });
  5452. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5453. {
  5454. Name = "b1Part2Result_Check",
  5455. Adress = 2065,
  5456. ValueType = PLCValueType.Short,
  5457. Value = b1Part2Result_Check
  5458. });
  5459. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5460. }
  5461. catch (Exception ex)
  5462. {
  5463. string str = ex.StackTrace;
  5464. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5465. // MES_Flag
  5466. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5467. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5468. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5469. writeToPLC_Flag.Adress = 2003;
  5470. writeToPLC_Flag.Value = (short)6;
  5471. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5472. }
  5473. stopwatch1.Stop();
  5474. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5475. }
  5476. /// <summary>
  5477. /// [S2] FCT(板测)- 二穴载具解绑绑定
  5478. /// </summary>
  5479. /// <param name="plcNo">PLC编号</param>
  5480. /// <param name="stationNameStr">工站全称</param>
  5481. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  5482. {
  5483. Stopwatch stopwatch1 = new Stopwatch();
  5484. Stopwatch stopwatch2 = new Stopwatch();
  5485. try
  5486. {
  5487. stopwatch1.Start();
  5488. // 产品换载具
  5489. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  5490. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  5491. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  5492. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  5493. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  5494. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  5495. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  5496. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  5497. stopwatch2.Start();
  5498. #region 查询载具上的产品信息
  5499. //string cavityData = string.Empty;
  5500. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  5501. //if (string.IsNullOrEmpty(cavityData))
  5502. // cavityData = "";
  5503. //if (snResult != 0)
  5504. //{
  5505. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5506. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5507. // writeToPLC_Flag.Adress = 2077;
  5508. // writeToPLC_Flag.Value = (short)6;
  5509. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5510. // stopwatch1.Stop();
  5511. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5512. // return;
  5513. //}
  5514. #endregion 查询载具上的产品信息
  5515. #region 解绑(边线MES系统)
  5516. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  5517. if (snResult != 0)
  5518. {
  5519. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5520. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5521. writeToPLC_Flag1.Adress = 2077;
  5522. writeToPLC_Flag1.Value = (short)6;
  5523. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5524. stopwatch1.Stop();
  5525. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5526. return;
  5527. }
  5528. #endregion 解绑(边线MES系统)
  5529. #region 存储绑定数据到 边线MES系统中
  5530. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  5531. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  5532. if (snResult != 0)
  5533. {
  5534. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5535. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5536. writeToPLC_Flag1.Adress = 2077;
  5537. writeToPLC_Flag1.Value = (short)6;
  5538. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5539. stopwatch1.Stop();
  5540. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5541. return;
  5542. }
  5543. #endregion 存储绑定数据到 边线MES系统中
  5544. stopwatch2.Stop();
  5545. short b1MES_FLAG_Unbind = 1;
  5546. // MES_Flag
  5547. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5548. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5549. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5550. writeToPLC_Flag.Adress = 2077;
  5551. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  5552. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5553. }
  5554. catch (Exception ex)
  5555. {
  5556. string str = ex.StackTrace;
  5557. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5558. // MES_Flag
  5559. stopwatch2.Start();
  5560. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5561. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5562. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5563. writeToPLC_Flag.Adress = 2077;
  5564. writeToPLC_Flag.Value = (short)6;
  5565. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5566. stopwatch2.Stop();
  5567. }
  5568. stopwatch1.Stop();
  5569. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5570. }
  5571. //// 上次采集到的SN
  5572. //private string sn_FCT = string.Empty;
  5573. /// <summary>
  5574. /// [S2] FCT(板测)- 出站数据
  5575. /// </summary>
  5576. private void S2出站接口(int plcNo, string stationCode, string stationName)
  5577. {
  5578. Stopwatch stopwatch1 = new Stopwatch();
  5579. Stopwatch stopwatch2 = new Stopwatch();
  5580. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5581. string stationNameStr = stationCode + stationName;
  5582. string processItem = stationName; // 测试项目
  5583. try
  5584. {
  5585. stopwatch1.Start();
  5586. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5587. //string batch_num = GlobalContext.BatchNumber; // 批次号
  5588. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5589. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5590. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  5591. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  5592. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  5593. bool pass1 = b1Part1Result == 1;
  5594. bool pass2 = b1Part2Result == 1;
  5595. #region 根据 载具SN 查 物料SN
  5596. string cavityData = string.Empty;
  5597. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  5598. if (string.IsNullOrEmpty(cavityData))
  5599. cavityData = "";
  5600. if (snResult != 0)
  5601. {
  5602. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5603. writeToPLC_Flag1.Name = "b1MES_FLAG";
  5604. writeToPLC_Flag1.Adress = 2169;
  5605. writeToPLC_Flag1.Value = (short)4;
  5606. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  5607. stopwatch1.Stop();
  5608. AddMessage(LogType.Info, stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5609. return;
  5610. }
  5611. #endregion 根据 载具SN 查 物料SN
  5612. string[] cavitySNs = cavityData.Split('.');
  5613. string b1ProductSN1 = string.Empty;
  5614. string b1ProductSN2 = string.Empty;
  5615. if (cavitySNs != null && cavitySNs.Length >= 2)
  5616. {
  5617. b1ProductSN1 = cavitySNs[0];
  5618. b1ProductSN2 = cavitySNs[1];
  5619. }
  5620. stopwatch2.Start();
  5621. // 产品1
  5622. int result1 = 0;
  5623. if (b1ProductSN1 == "假产品")
  5624. result1 = 1;
  5625. else
  5626. {
  5627. List<TestItem> items1 = new List<TestItem>();
  5628. items1.Add(new TestItem()
  5629. {
  5630. Parameter_name = "载具码",
  5631. Parameter_value = b1ProductSN.ToString(),
  5632. Parameter_unit = ""
  5633. });
  5634. items1.Add(new TestItem()
  5635. {
  5636. Parameter_name = "载具穴号",
  5637. Parameter_value = "1",
  5638. Parameter_unit = ""
  5639. });
  5640. items1.Add(new TestItem()
  5641. {
  5642. Parameter_name = "产品结果",
  5643. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  5644. Parameter_unit = ""
  5645. });
  5646. result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  5647. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  5648. }
  5649. // 产品2
  5650. int result2 = 0;
  5651. if (b1ProductSN1 == "假产品")
  5652. result2 = 1;
  5653. else
  5654. {
  5655. List<TestItem> items2 = new List<TestItem>();
  5656. items2.Add(new TestItem()
  5657. {
  5658. Parameter_name = "载具码",
  5659. Parameter_value = b1ProductSN.ToString(),
  5660. Parameter_unit = ""
  5661. });
  5662. items2.Add(new TestItem()
  5663. {
  5664. Parameter_name = "载具穴号",
  5665. Parameter_value = "2",
  5666. Parameter_unit = ""
  5667. });
  5668. items2.Add(new TestItem()
  5669. {
  5670. Parameter_name = "产品结果",
  5671. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  5672. Parameter_unit = ""
  5673. });
  5674. result2 = SwitctProcessData(stationNameStr, items2, equipmentCode, processItem
  5675. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  5676. }
  5677. short result = 0;
  5678. List<int> results = new List<int>() { result1, result2 };
  5679. if (result1 == 1 && result2 == 1)
  5680. result = 1;
  5681. else if (results.Contains(3))
  5682. result = 3;
  5683. else if (results.Contains(2))
  5684. result = 2;
  5685. else if (results.Contains(4))
  5686. result = 4;
  5687. else
  5688. result = 4;
  5689. stopwatch2.Stop();
  5690. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5691. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5692. writeToPLC_Flag.Name = "b1MES_FLAG";
  5693. writeToPLC_Flag.Adress = 2169;
  5694. writeToPLC_Flag.Value = result;
  5695. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5696. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  5697. }
  5698. catch (Exception ex)
  5699. {
  5700. stopwatch2.Restart();
  5701. // MES_Flag 为4上位机报错
  5702. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  5703. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5704. writeToPLC_Flag.Name = "b1MES_FLAG";
  5705. writeToPLC_Flag.Adress = 2169;
  5706. writeToPLC_Flag.Value = (short)4;
  5707. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5708. stopwatch2.Stop();
  5709. string str = ex.StackTrace;
  5710. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5711. }
  5712. stopwatch1.Stop();
  5713. AddMessage(LogType.Info, stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5714. }
  5715. /// <summary>
  5716. /// [S2] FCT(板测)- 节拍接口
  5717. /// </summary>
  5718. /// <param name="plcNo">PLC编号</param>
  5719. /// <param name="stationNameStr">工站全称</param>
  5720. private void S2节拍接口(int plcNo, string stationNameStr)
  5721. {
  5722. Stopwatch stopwatch1 = new Stopwatch();
  5723. Stopwatch stopwatch2 = new Stopwatch();
  5724. string resultStr = string.Empty;
  5725. try
  5726. {
  5727. stopwatch1.Start();
  5728. string oEEType = ((int)s2PLCData["b1OEEType"]).ToString(); // 节拍类型(plc写入)
  5729. string b1OEEProductSN = (string)s2PLCData["b1OEEProductSN"]; // 载具SN
  5730. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5731. if (!actionBool)
  5732. {
  5733. stopwatch2.Start();
  5734. // MES_Flag
  5735. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5736. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5737. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5738. writeToPLC_Flag1.Adress = 2203;
  5739. writeToPLC_Flag1.Value = (short)4;
  5740. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5741. stopwatch2.Stop();
  5742. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5743. return;
  5744. }
  5745. string b1OEEPartNo = string.Empty; // 物料码
  5746. if (string.IsNullOrEmpty(b1OEEProductSN))
  5747. {
  5748. stopwatch2.Start();
  5749. // MES_Flag
  5750. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5751. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5752. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5753. writeToPLC_Flag1.Adress = 2203;
  5754. writeToPLC_Flag1.Value = (short)1;
  5755. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5756. stopwatch2.Stop();
  5757. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5758. return;
  5759. }
  5760. else
  5761. { // 查产品SN
  5762. b1OEEPartNo = "Test"; // ZS
  5763. }
  5764. short b1OEEMES_FLAG = 0;
  5765. // 上传OEE
  5766. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, b1OEEPartNo, b1OEEProductSN);
  5767. b1OEEMES_FLAG = result.Item1;
  5768. resultStr = result.Item2;
  5769. stopwatch2.Start();
  5770. // MES_Flag
  5771. //Funs[plcNo].WriteMultipleRegisters<short>(2203, b1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5772. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5773. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5774. writeToPLC_Flag.Adress = 2203;
  5775. writeToPLC_Flag.Value = b1OEEMES_FLAG;
  5776. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5777. stopwatch2.Stop();
  5778. }
  5779. catch (Exception ex)
  5780. {
  5781. string str = ex.StackTrace;
  5782. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5783. // MES_Flag
  5784. stopwatch2.Start();
  5785. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5786. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5787. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5788. writeToPLC_Flag.Adress = 2203;
  5789. writeToPLC_Flag.Value = (short)4;
  5790. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5791. stopwatch2.Stop();
  5792. }
  5793. stopwatch1.Stop();
  5794. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5795. }
  5796. #endregion [S2] FCT(板测)
  5797. #endregion PLC2 李晓奇
  5798. #region PLC3 刘永村
  5799. #region [S3] 值板机
  5800. /// <summary>
  5801. /// S3工位的数据- 触发信号上次的值
  5802. /// </summary>
  5803. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  5804. /// <summary>
  5805. /// S3工位的数据(含触发信号)
  5806. /// </summary>
  5807. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  5808. /// <summary>
  5809. /// S3工位的数据- 回写点位
  5810. /// </summary>
  5811. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5812. /// <summary>
  5813. /// [S3] 值板机
  5814. /// </summary>
  5815. /// <param name="plcNo">PLC编号</param>
  5816. //private void ReadStation_S3(int plcNo)
  5817. //{
  5818. // // [S1] Tray盘上料装备
  5819. // // [S2] FCT
  5820. // // [S3] 值板机
  5821. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5822. // // [S5] Tray盘下料装备
  5823. // /// 上位机心跳
  5824. // /// 获取设备报警数据与状态信息
  5825. // string stationCode = "[S3]";
  5826. // string stationName = "值板机";
  5827. // string stationNameStr = stationCode + stationName;
  5828. // #region 创建字典
  5829. // // 触发信号字典 赋值
  5830. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5831. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5832. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5833. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5834. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5835. // // PLC数据字典 赋值
  5836. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5837. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  5838. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5839. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5840. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  5841. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5842. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5843. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5844. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  5845. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5846. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  5847. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  5848. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5849. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5850. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  5851. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  5852. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  5853. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5854. // s3PLCData.Add("c1Result", 0); // 产品结果
  5855. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5856. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  5857. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  5858. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  5859. // #endregion 创建字典
  5860. // while (IsRun)
  5861. // {
  5862. // try
  5863. // {
  5864. // if (!GlobalContext._IsCon_Funs3)
  5865. // {
  5866. // UpdatePLCMonitor(1, plcNo, 0);
  5867. // continue;
  5868. // }
  5869. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5870. // {
  5871. // Stopwatch stopwatch1 = new Stopwatch();
  5872. // Stopwatch stopwatch2 = new Stopwatch();
  5873. // stopwatch1.Start();
  5874. // stopwatch2.Start();
  5875. // #region 一次性读取所有数据
  5876. // // 一次性读取所有数据
  5877. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  5878. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  5879. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  5880. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  5881. // int[] datas = data1.Concat(data2).ToArray();
  5882. // datas = datas.Concat(data3).ToArray();
  5883. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  5884. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  5885. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5886. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  5887. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  5888. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  5889. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5890. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  5891. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  5892. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  5893. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  5894. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5895. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  5896. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  5897. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  5898. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  5899. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5900. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  5901. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  5902. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  5903. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  5904. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  5905. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  5906. // #endregion 一次性读取所有数据
  5907. // stopwatch2.Stop();
  5908. // #region 回写操作,写后清空flag
  5909. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  5910. // #endregion 回写操作,写后清空flag
  5911. // #region S3进站校验
  5912. // try
  5913. // {
  5914. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  5915. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  5916. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  5917. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  5918. // {
  5919. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  5920. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5921. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  5922. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5923. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  5924. // }
  5925. // }
  5926. // catch (Exception ex)
  5927. // {
  5928. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5929. // string str = ex.StackTrace;
  5930. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5931. // }
  5932. // #endregion S3进站校验
  5933. // #region S3二穴载具解绑
  5934. // try
  5935. // {
  5936. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  5937. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  5938. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  5939. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  5940. // {
  5941. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  5942. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  5943. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  5944. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  5945. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  5946. // }
  5947. // }
  5948. // catch (Exception ex)
  5949. // {
  5950. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  5951. // string str = ex.StackTrace;
  5952. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5953. // }
  5954. // #endregion S3二穴载具解绑
  5955. // #region S3二穴载具绑定
  5956. // try
  5957. // {
  5958. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  5959. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  5960. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  5961. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  5962. // {
  5963. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  5964. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5965. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  5966. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  5967. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  5968. // }
  5969. // }
  5970. // catch (Exception ex)
  5971. // {
  5972. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  5973. // string str = ex.StackTrace;
  5974. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5975. // }
  5976. // #endregion S3二穴载具绑定
  5977. // #region S3出站接口(+一穴载具绑定)
  5978. // try
  5979. // {
  5980. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  5981. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  5982. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  5983. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  5984. // {
  5985. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  5986. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5987. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  5988. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  5989. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  5990. // }
  5991. // }
  5992. // catch (Exception ex)
  5993. // {
  5994. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  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 S3出站接口(+一穴载具绑定)
  5999. // #region S3节拍接口
  6000. // try
  6001. // {
  6002. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  6003. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  6004. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  6005. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  6006. // {
  6007. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  6008. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6009. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  6010. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  6011. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  6012. // }
  6013. // }
  6014. // catch (Exception ex)
  6015. // {
  6016. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6017. // string str = ex.StackTrace;
  6018. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6019. // }
  6020. // #endregion S3节拍接口
  6021. // #region 心跳
  6022. // try
  6023. // {
  6024. // short states = 0;
  6025. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  6026. // }
  6027. // catch (Exception ex)
  6028. // {
  6029. // string str = ex.StackTrace;
  6030. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6031. // }
  6032. // #endregion 心跳
  6033. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  6034. // stopwatch1.Stop();
  6035. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  6036. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  6037. // }
  6038. // else
  6039. // {
  6040. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6041. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  6042. // Funs[plcNo].Connect();
  6043. // }
  6044. // }
  6045. // catch (Exception ex)
  6046. // {
  6047. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  6048. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  6049. // Funs[plcNo].ReConnect();
  6050. // }
  6051. // Thread.Sleep(IntervalReadPLC);
  6052. // }
  6053. //}
  6054. /// <summary>
  6055. /// [S3] 值板机- 进站校验
  6056. /// </summary>
  6057. /// <param name="plcNo">PLC编号</param>
  6058. /// <param name="stationNameStr">工站全称</param>
  6059. private void S3进站校验(int plcNo, string stationNameStr)
  6060. {
  6061. Stopwatch stopwatch1 = new Stopwatch();
  6062. Stopwatch stopwatch2 = new Stopwatch();
  6063. try
  6064. {
  6065. stopwatch1.Start();
  6066. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  6067. sn = sn.Replace("\0", "");
  6068. #region 查询载具上的产品信息
  6069. string cavityData = string.Empty;
  6070. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6071. if (string.IsNullOrEmpty(cavityData))
  6072. cavityData = "";
  6073. if (snResult != 0)
  6074. {
  6075. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6076. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  6077. writeToPLC_Flag1.Adress = 2003;
  6078. writeToPLC_Flag1.Value = (short)6;
  6079. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  6080. stopwatch1.Stop();
  6081. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6082. return;
  6083. }
  6084. #endregion 查询载具上的产品信息
  6085. string[] cavitySNs = cavityData.Split('.');
  6086. string part1Str = ""; // 产品1的SN码
  6087. string part2Str = ""; // 产品2的SN码
  6088. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  6089. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  6090. if (cavitySNs != null && cavitySNs.Length >= 2)
  6091. {
  6092. part1Str = cavitySNs[0];
  6093. part2Str = cavitySNs[1];
  6094. c1Part1Result_Check = 2;
  6095. c1Part2Result_Check = 2;
  6096. }
  6097. if (part1Str == "假产品")
  6098. c1Part1Result_Check = 3;
  6099. if (part2Str == "假产品")
  6100. c1Part2Result_Check = 3;
  6101. // 调用MES进站
  6102. stopwatch2.Start();
  6103. // 调用MES进站 - 产品1
  6104. List<TestItem> item;
  6105. int result1 = c1Part1Result_Check;
  6106. if (result1 != 3)
  6107. {
  6108. item = new List<TestItem>();
  6109. item.Add(new TestItem()
  6110. {
  6111. Parameter_name = "载具码",
  6112. Parameter_value = sn,
  6113. });
  6114. item.Add(new TestItem()
  6115. {
  6116. Parameter_name = "载具穴号",
  6117. Parameter_value = "1",
  6118. });
  6119. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part1Str, item, out string errorMsg);
  6120. }
  6121. // 调用MES进站 - 产品2
  6122. int result2 = c1Part2Result_Check;
  6123. if (result2 != 3)
  6124. {
  6125. item = new List<TestItem>();
  6126. item.Add(new TestItem()
  6127. {
  6128. Parameter_name = "载具码",
  6129. Parameter_value = sn,
  6130. });
  6131. item.Add(new TestItem()
  6132. {
  6133. Parameter_name = "载具穴号",
  6134. Parameter_value = "2",
  6135. });
  6136. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part2Str, item, out string errorMsg);
  6137. }
  6138. stopwatch2.Stop();
  6139. if (result1 == 2)
  6140. c1Part1Result_Check = 2;
  6141. if (result2 == 2)
  6142. c1Part2Result_Check = 2;
  6143. int result = result1;
  6144. if (result == 1)
  6145. result = result2;
  6146. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  6147. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  6148. short c1MES_FLAG_Check = (short)result;
  6149. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  6150. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  6151. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  6152. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  6153. //// MES_Flag
  6154. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6155. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6156. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6157. writeToPLC_Flag.Adress = 2003;
  6158. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  6159. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6160. {
  6161. Name = "c1Part1Result_Check",
  6162. Adress = 2024,
  6163. ValueType = PLCValueType.Short,
  6164. Value = c1Part1Result_Check
  6165. });
  6166. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6167. {
  6168. Name = "c1Part2Result_Check",
  6169. Adress = 2025,
  6170. ValueType = PLCValueType.Short,
  6171. Value = c1Part2Result_Check
  6172. });
  6173. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6174. {
  6175. Name = "c1Part1Num_Check",
  6176. Adress = 2026,
  6177. ValueType = PLCValueType.Short,
  6178. Value = c1Part1Num_Check
  6179. });
  6180. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6181. {
  6182. Name = "c1Part2Num_Check",
  6183. Adress = 2027,
  6184. ValueType = PLCValueType.Short,
  6185. Value = c1Part2Num_Check
  6186. });
  6187. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6188. }
  6189. catch (Exception ex)
  6190. {
  6191. string str = ex.StackTrace;
  6192. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6193. // MES_Flag
  6194. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6195. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6196. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6197. writeToPLC_Flag.Adress = 2003;
  6198. writeToPLC_Flag.Value = (short)6;
  6199. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6200. }
  6201. stopwatch1.Stop();
  6202. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6203. }
  6204. /// <summary>
  6205. /// [S3] 值板机 - 二穴载具解绑
  6206. /// </summary>
  6207. /// <param name="plcNo">PLC编号</param>
  6208. /// <param name="stationNameStr">工站全称</param>
  6209. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  6210. {
  6211. Stopwatch stopwatch1 = new Stopwatch();
  6212. Stopwatch stopwatch2 = new Stopwatch();
  6213. try
  6214. {
  6215. stopwatch1.Start();
  6216. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6217. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6218. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6219. // 解绑
  6220. #region 查询载具上的产品信息
  6221. string cavityData = string.Empty;
  6222. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6223. if (string.IsNullOrEmpty(cavityData))
  6224. cavityData = "";
  6225. if (snResult != 0)
  6226. {
  6227. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6228. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  6229. writeToPLC_Flag1.Adress = 2082;
  6230. writeToPLC_Flag1.Value = (short)6;
  6231. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  6232. stopwatch1.Stop();
  6233. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6234. return;
  6235. }
  6236. #endregion 查询载具上的产品信息
  6237. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6238. #region 解绑
  6239. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6240. {
  6241. // 删除
  6242. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6243. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  6244. }
  6245. else
  6246. {
  6247. string data_new = string.Join(".", cavitySNs);
  6248. // 删除再插入
  6249. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6250. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6251. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6252. }
  6253. #endregion 解绑
  6254. short c1MES_FLAG_Unbind = 1;
  6255. stopwatch2.Start();
  6256. // MES_Flag
  6257. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6258. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6259. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6260. writeToPLC_Flag.Adress = 2082;
  6261. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  6262. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6263. stopwatch2.Stop();
  6264. }
  6265. catch (Exception ex)
  6266. {
  6267. string str = ex.StackTrace;
  6268. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6269. // MES_Flag
  6270. stopwatch2.Start();
  6271. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  6272. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6273. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6274. writeToPLC_Flag.Adress = 2082;
  6275. writeToPLC_Flag.Value = (short)6;
  6276. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6277. stopwatch2.Stop();
  6278. }
  6279. stopwatch1.Stop();
  6280. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6281. }
  6282. /// <summary>
  6283. /// [S3] 值板机 - 二穴载具绑定
  6284. /// </summary>
  6285. /// <param name="plcNo">PLC编号</param>
  6286. /// <param name="stationNameStr">工站全称</param>
  6287. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  6288. {
  6289. Stopwatch stopwatch1 = new Stopwatch();
  6290. Stopwatch stopwatch2 = new Stopwatch();
  6291. try
  6292. {
  6293. stopwatch1.Start();
  6294. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6295. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6296. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  6297. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  6298. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6299. stopwatch2.Start();
  6300. #region 查询载具上的产品信息
  6301. string cavityData = string.Empty;
  6302. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6303. if (string.IsNullOrEmpty(cavityData))
  6304. cavityData = "";
  6305. if (snResult != 0)
  6306. {
  6307. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6308. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  6309. writeToPLC_Flag1.Adress = 2115;
  6310. writeToPLC_Flag1.Value = (short)6;
  6311. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  6312. stopwatch1.Stop();
  6313. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6314. return;
  6315. }
  6316. #endregion 查询载具上的产品信息
  6317. // 产品换载具
  6318. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6319. string partSn1 = "";
  6320. string partSn2 = "";
  6321. if (cavitySNs != null && cavitySNs.Length >= 2)
  6322. {
  6323. partSn1 = cavitySNs[0];
  6324. partSn2 = cavitySNs[1];
  6325. }
  6326. string data_new = string.Empty;
  6327. // 是否是两个穴位交换
  6328. if (c1CavityReverse_Bind == 1)
  6329. {
  6330. // 交换
  6331. data_new = string.Concat(partSn2, ".", partSn1);
  6332. }
  6333. else
  6334. { // 不交换
  6335. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  6336. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  6337. cavitySNs[c1VehicleCavityFr_Bind] = "";
  6338. data_new = string.Join(".", cavitySNs);
  6339. }
  6340. // 删除再插入
  6341. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6342. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6343. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  6344. stopwatch2.Stop();
  6345. short c1MES_FLAG_Bind = 1;
  6346. // MES_Flag
  6347. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6348. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6349. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6350. writeToPLC_Flag.Adress = 2115;
  6351. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  6352. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6353. }
  6354. catch (Exception ex)
  6355. {
  6356. string str = ex.StackTrace;
  6357. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6358. // MES_Flag
  6359. stopwatch2.Start();
  6360. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6361. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6362. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6363. writeToPLC_Flag.Adress = 2115;
  6364. writeToPLC_Flag.Value = (short)6;
  6365. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6366. stopwatch2.Stop();
  6367. }
  6368. stopwatch1.Stop();
  6369. AddMessage(LogType.Info, stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6370. }
  6371. //// 上次采集到的SN
  6372. //private string sn_值板机 = string.Empty;
  6373. /// <summary>
  6374. /// [S3] 值板机 - 出站接口
  6375. /// </summary>
  6376. /// <param name="plcNo">PLC编号</param>
  6377. private void S3出站接口(int plcNo, string stationCode, string stationName)
  6378. {
  6379. Stopwatch stopwatch1 = new Stopwatch();
  6380. Stopwatch stopwatch2 = new Stopwatch();
  6381. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6382. string stationNameStr = stationCode + stationName;
  6383. string processItem = stationName; // 测试项目
  6384. try
  6385. {
  6386. stopwatch1.Start();
  6387. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6388. //string batch_num = GlobalContext.BatchNumber; // 批次号
  6389. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6390. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6391. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  6392. sn = sn.Replace("\0", "");
  6393. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  6394. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6395. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6396. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  6397. bool pass = c1Result == 1;
  6398. // 查sn
  6399. #region 查询载具上的产品信息
  6400. string cavityData = string.Empty;
  6401. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6402. if (string.IsNullOrEmpty(cavityData))
  6403. cavityData = "";
  6404. if (snResult != 0)
  6405. {
  6406. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6407. writeToPLC_Flag1.Name = "c1MES_FLAG";
  6408. writeToPLC_Flag1.Adress = 2150;
  6409. writeToPLC_Flag1.Value = (short)4;
  6410. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  6411. stopwatch1.Stop();
  6412. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6413. return;
  6414. }
  6415. #endregion 查询载具上的产品信息
  6416. string[] cavitySNs = cavityData.Split('.');
  6417. string productSN = "";
  6418. if (cavitySNs != null && cavitySNs.Length >= 2)
  6419. {
  6420. productSN = cavitySNs[c1VehicleCavity];
  6421. cavitySNs[c1VehicleCavity] = "";
  6422. }
  6423. stopwatch2.Start();
  6424. List<TestItem> items = new List<TestItem>();
  6425. items.Add(new TestItem()
  6426. {
  6427. Parameter_name = "二穴载具码",
  6428. Parameter_value = c1ProductSN_Check,
  6429. Parameter_unit = ""
  6430. });
  6431. items.Add(new TestItem()
  6432. {
  6433. Parameter_name = "二穴载具穴号",
  6434. Parameter_value = c1VehicleCavity.ToString(),
  6435. Parameter_unit = ""
  6436. });
  6437. items.Add(new TestItem()
  6438. {
  6439. Parameter_name = "一穴载具码",
  6440. Parameter_value = sn,
  6441. Parameter_unit = ""
  6442. });
  6443. items.Add(new TestItem()
  6444. {
  6445. Parameter_name = "一穴载具穴号",
  6446. Parameter_value = "1",
  6447. Parameter_unit = ""
  6448. });
  6449. items.Add(new TestItem()
  6450. {
  6451. Parameter_name = "产品结果",
  6452. Parameter_value = c1Result == 1 ? "OK" : "NG",
  6453. Parameter_unit = ""
  6454. });
  6455. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6456. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  6457. short result = (short)result1;
  6458. stopwatch2.Stop();
  6459. #region 存储绑定数据到 边线MES系统中
  6460. if (result == 1)
  6461. {
  6462. string data = string.Concat(productSN);
  6463. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  6464. if (resultMesR != 0)
  6465. {
  6466. result = 4;
  6467. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  6468. }
  6469. }
  6470. #endregion 存储绑定数据到 边线MES系统中
  6471. #region 产品从 来源载具(二穴载具)中删除
  6472. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6473. {
  6474. // 删除
  6475. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6476. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  6477. }
  6478. else
  6479. {
  6480. string data_new = string.Join(".", cavitySNs);
  6481. // 删除再插入
  6482. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6483. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6484. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6485. }
  6486. #endregion 产品从 来源载具(二穴载具)中删除
  6487. // MES_Flag 为MES报错
  6488. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6489. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  6490. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6491. writeToPLC_Flag.Name = "c1MES_FLAG";
  6492. writeToPLC_Flag.Adress = 2150;
  6493. writeToPLC_Flag.Value = result;
  6494. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6495. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  6496. }
  6497. catch (Exception ex)
  6498. {
  6499. stopwatch2.Restart();
  6500. // MES_Flag 为4上位机报错
  6501. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  6502. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6503. writeToPLC_Flag.Name = "c1MES_FLAG";
  6504. writeToPLC_Flag.Adress = 2150;
  6505. writeToPLC_Flag.Value = (short)4;
  6506. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6507. stopwatch2.Stop();
  6508. string str = ex.StackTrace;
  6509. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6510. }
  6511. stopwatch1.Stop();
  6512. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6513. }
  6514. /// <summary>
  6515. /// [S3] 值板机- 节拍接口
  6516. /// </summary>
  6517. /// <param name="plcNo">PLC编号</param>
  6518. /// <param name="stationNameStr">工站全称</param>
  6519. private void S3节拍接口(int plcNo, string stationNameStr)
  6520. {
  6521. Stopwatch stopwatch1 = new Stopwatch();
  6522. Stopwatch stopwatch2 = new Stopwatch();
  6523. string resultStr = string.Empty;
  6524. try
  6525. {
  6526. stopwatch1.Start();
  6527. string oEEType = ((int)s3PLCData["c1OEEType"]).ToString(); // 节拍类型(plc写入)
  6528. string c1OEEProductSN = (string)s3PLCData["c1OEEProductSN"]; // 载具SN
  6529. c1OEEProductSN = c1OEEProductSN.Replace("\0", "");
  6530. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6531. if (!actionBool)
  6532. {
  6533. stopwatch2.Start();
  6534. // MES_Flag
  6535. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6536. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6537. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6538. writeToPLC_Flag1.Adress = 2204;
  6539. writeToPLC_Flag1.Value = (short)4;
  6540. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6541. stopwatch2.Stop();
  6542. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6543. return;
  6544. }
  6545. string c1OEEPartNo = string.Empty; // 物料码
  6546. if (string.IsNullOrEmpty(c1OEEProductSN))
  6547. {
  6548. stopwatch2.Start();
  6549. // MES_Flag
  6550. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6551. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6552. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6553. writeToPLC_Flag1.Adress = 2204;
  6554. writeToPLC_Flag1.Value = (short)1;
  6555. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6556. stopwatch2.Stop();
  6557. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6558. return;
  6559. }
  6560. else
  6561. { // 查产品SN
  6562. c1OEEPartNo = "Test"; // ZS
  6563. }
  6564. short c1OEEMES_FLAG = 0;
  6565. // 上传OEE
  6566. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, c1OEEPartNo, c1OEEProductSN);
  6567. c1OEEMES_FLAG = result.Item1;
  6568. resultStr = result.Item2;
  6569. stopwatch2.Start();
  6570. // MES_Flag
  6571. //Funs[plcNo].WriteMultipleRegisters<short>(2204, c1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6572. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6573. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6574. writeToPLC_Flag.Adress = 2204;
  6575. writeToPLC_Flag.Value = c1OEEMES_FLAG;
  6576. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6577. stopwatch2.Stop();
  6578. }
  6579. catch (Exception ex)
  6580. {
  6581. string str = ex.StackTrace;
  6582. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6583. // MES_Flag
  6584. stopwatch2.Start();
  6585. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6586. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6587. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6588. writeToPLC_Flag.Adress = 2204;
  6589. writeToPLC_Flag.Value = (short)4;
  6590. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6591. stopwatch2.Stop();
  6592. }
  6593. stopwatch1.Stop();
  6594. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6595. }
  6596. #endregion [S3] 值板机
  6597. #endregion PLC3 刘永村
  6598. #region PLC4 刘果段
  6599. #region [S4] 取放桁架
  6600. /// <summary>
  6601. /// S4工位的数据- 触发信号上次的值
  6602. /// </summary>
  6603. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  6604. /// <summary>
  6605. /// S4工位的数据(含触发信号)
  6606. /// </summary>
  6607. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  6608. /// <summary>
  6609. /// S4工位的数据- 回写点位
  6610. /// </summary>
  6611. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6612. /// <summary>
  6613. /// [S4] 取放桁架
  6614. /// </summary>
  6615. /// <param name="plcNo">PLC编号</param>
  6616. //private void ReadStation_S4(int plcNo)
  6617. //{
  6618. // // [S1] Tray盘上料装备
  6619. // // [S2] FCT
  6620. // // [S3] 值板机
  6621. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6622. // // [S5] Tray盘下料装备
  6623. // /// 上位机心跳
  6624. // /// 获取设备报警数据与状态信息
  6625. // string stationCode = "[S4_1]";
  6626. // string stationName = "载具下线装备";
  6627. // string stationNameStr = stationCode + stationName;
  6628. // string stationCode2 = "[S4_2]";
  6629. // string stationName2 = "桁架";
  6630. // string stationNameStr2 = stationCode2 + stationName2;
  6631. // string stationCode3 = "[S4_3]";
  6632. // string stationName3 = "提升机1";
  6633. // string stationNameStr3 = stationCode3 + stationName3;
  6634. // string stationCode4 = "[S4_4]";
  6635. // string stationName4 = "提升机2";
  6636. // string stationNameStr4 = stationCode4 + stationName4;
  6637. // string stationCode5 = "[S4_5]";
  6638. // string stationName5 = "载具上线装备";
  6639. // string stationNameStr5 = stationCode5 + stationName5;
  6640. // #region 创建字典
  6641. // // 触发信号字典 赋值
  6642. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6643. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6644. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6645. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6646. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6647. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6648. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6649. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6650. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6651. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6652. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6653. // // PLC数据字典 赋值
  6654. // // 载具下线装备(弹夹上线)
  6655. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6656. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  6657. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6658. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  6659. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6660. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  6661. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  6662. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6663. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6664. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6665. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6666. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6667. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6668. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6669. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6670. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6671. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6672. // s4PLCData.Add("d1Result", 0); // 产品结果
  6673. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6674. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  6675. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  6676. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  6677. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6678. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  6679. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  6680. // // 真空标机(提升机)
  6681. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6682. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  6683. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  6684. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  6685. // s4PLCData.Add("d3Result", 0); // 产品结果
  6686. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6687. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  6688. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  6689. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  6690. // s4PLCData.Add("d4Result", 0); // 产品结果
  6691. // // 载具上线装备(弹夹下线)
  6692. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6693. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  6694. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6695. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  6696. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6697. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  6698. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  6699. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6700. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6701. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6702. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6703. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6704. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6705. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6706. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6707. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6708. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6709. // s4PLCData.Add("d5Result", 0); // 产品结果
  6710. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6711. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  6712. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  6713. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  6714. // #endregion 创建字典
  6715. // while (IsRun)
  6716. // {
  6717. // try
  6718. // {
  6719. // if (!GlobalContext._IsCon_Funs4)
  6720. // {
  6721. // UpdatePLCMonitor(1, plcNo, 0);
  6722. // continue;
  6723. // }
  6724. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6725. // {
  6726. // Stopwatch stopwatch1 = new Stopwatch();
  6727. // Stopwatch stopwatch2 = new Stopwatch();
  6728. // stopwatch1.Start();
  6729. // stopwatch2.Start();
  6730. // #region 一次性读取所有数据
  6731. // // 载具下线装备(弹夹上线)
  6732. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6733. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6734. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6735. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  6736. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  6737. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  6738. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  6739. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  6740. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  6741. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  6742. // int[] datas = data1.Concat(data2).ToArray();
  6743. // datas = datas.Concat(data3).ToArray();
  6744. // datas = datas.Concat(data4).ToArray();
  6745. // datas = datas.Concat(data5).ToArray();
  6746. // datas = datas.Concat(data6).ToArray();
  6747. // datas = datas.Concat(data7).ToArray();
  6748. // datas = datas.Concat(data8).ToArray();
  6749. // datas = datas.Concat(data9).ToArray();
  6750. // datas = datas.Concat(data10).ToArray();
  6751. // // 载具下线装备(弹夹上线)
  6752. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  6753. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  6754. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  6755. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  6756. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  6757. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  6758. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  6759. // s4PLCData["d1MES_FLAG"] = datas[65];
  6760. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  6761. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  6762. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  6763. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  6764. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  6765. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  6766. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  6767. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  6768. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  6769. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  6770. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  6771. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  6772. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  6773. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  6774. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  6775. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  6776. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  6777. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  6778. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  6779. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  6780. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  6781. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  6782. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  6783. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  6784. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  6785. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  6786. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  6787. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  6788. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  6789. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  6790. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  6791. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  6792. // s4PLCData["d1Result"] = datas[386];
  6793. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  6794. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  6795. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  6796. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  6797. // s4PLCData["d1OEEType"] = datas[419];
  6798. // // 桁架(查询标机中弹夹的状态)
  6799. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  6800. // s4PLCData["d2BulletclipStates"] = datas[431];
  6801. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  6802. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  6803. // // 真空标机
  6804. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  6805. // s4PLCData["d3MES_FLAG"] = datas[463];
  6806. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  6807. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  6808. // s4PLCData["d3Result"] = datas[484];
  6809. // s4PLCData["d3Type"] = datas[485];
  6810. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  6811. // s4PLCData["d4MES_FLAG"] = datas[496];
  6812. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  6813. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  6814. // s4PLCData["d4Result"] = datas[517];
  6815. // s4PLCData["d4Type"] = datas[518];
  6816. // // 载具上线装备(弹夹下线)
  6817. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  6818. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  6819. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  6820. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  6821. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  6822. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  6823. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  6824. // s4PLCData["d5MES_FLAG"] = datas[591];
  6825. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  6826. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  6827. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  6828. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  6829. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  6830. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  6831. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  6832. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  6833. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  6834. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  6835. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  6836. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  6837. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  6838. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  6839. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  6840. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  6841. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  6842. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  6843. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  6844. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  6845. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  6846. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  6847. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  6848. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  6849. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  6850. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  6851. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  6852. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  6853. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  6854. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  6855. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  6856. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  6857. // s4PLCData["d5Result"] = datas[912];
  6858. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  6859. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  6860. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  6861. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  6862. // s4PLCData["d5OEEType"] = datas[945];
  6863. // #endregion 一次性读取所有数据
  6864. // stopwatch2.Stop();
  6865. // #region 回写操作,写后清空flag
  6866. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  6867. // #endregion 回写操作,写后清空flag
  6868. // // N801A-S4_1 弹夹扫码
  6869. // #region N801A-S4_1 弹夹扫码
  6870. // try
  6871. // {
  6872. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  6873. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  6874. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  6875. // {
  6876. // if (d1BulletclipScanCode == 1) // 0->1
  6877. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6878. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  6879. // }
  6880. // }
  6881. // catch (Exception ex)
  6882. // {
  6883. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  6884. // string str = ex.StackTrace;
  6885. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6886. // }
  6887. // #endregion N801A-S4_1 弹夹扫码
  6888. // // N801A-S4_1 载具扫码
  6889. // #region N801A-S4_1 载具扫码
  6890. // try
  6891. // {
  6892. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  6893. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  6894. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  6895. // {
  6896. // if (d1VehicleScanCode == 1) // 0->1
  6897. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6898. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  6899. // }
  6900. // }
  6901. // catch (Exception ex)
  6902. // {
  6903. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  6904. // string str = ex.StackTrace;
  6905. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6906. // }
  6907. // #endregion N801A-S4_1 载具扫码
  6908. // // N801A-S4_1 出站接口
  6909. // #region N801A-S4_1 出站接口
  6910. // try
  6911. // {
  6912. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  6913. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  6914. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  6915. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  6916. // {
  6917. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  6918. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6919. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  6920. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  6921. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  6922. // }
  6923. // }
  6924. // catch (Exception ex)
  6925. // {
  6926. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  6927. // string str = ex.StackTrace;
  6928. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6929. // }
  6930. // #endregion N801A-S4_1 出站接口
  6931. // // N801A-S4_1 节拍接口
  6932. // #region N801A-S4_1 节拍接口
  6933. // try
  6934. // {
  6935. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  6936. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  6937. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  6938. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  6939. // {
  6940. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  6941. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6942. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  6943. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  6944. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  6945. // }
  6946. // }
  6947. // catch (Exception ex)
  6948. // {
  6949. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  6950. // string str = ex.StackTrace;
  6951. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6952. // }
  6953. // #endregion N801A-S4_1 节拍接口
  6954. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  6955. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  6956. // try
  6957. // {
  6958. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  6959. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  6960. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  6961. // {
  6962. // if (d2BulletclipScanCode == 1) // 0->1
  6963. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  6964. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  6965. // }
  6966. // }
  6967. // catch (Exception ex)
  6968. // {
  6969. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  6970. // string str = ex.StackTrace;
  6971. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6972. // }
  6973. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  6974. // // N801A-S4_3 真空标机1 数据
  6975. // #region N801A-S4_3 真空标机1
  6976. // try
  6977. // {
  6978. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  6979. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  6980. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  6981. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  6982. // {
  6983. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  6984. // {
  6985. // int stationType = (int)s4PLCData["d3Type"];
  6986. // if (stationType == 1)
  6987. // {
  6988. // // S4_3进站接口
  6989. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  6990. // }
  6991. // else if (stationType == 2)
  6992. // {
  6993. // // S4_3出站接口
  6994. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  6995. // }
  6996. // }
  6997. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  6998. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  6999. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  7000. // }
  7001. // }
  7002. // catch (Exception ex)
  7003. // {
  7004. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7005. // string str = ex.StackTrace;
  7006. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7007. // }
  7008. // #endregion N801A-S4_3 真空标机1
  7009. // // N801A-S4_4 真空标机2 数据
  7010. // #region N801A-S4_4 真空标机2
  7011. // try
  7012. // {
  7013. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  7014. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  7015. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  7016. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  7017. // {
  7018. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  7019. // {
  7020. // int stationType = (int)s4PLCData["d4Type"];
  7021. // if (stationType == 1)
  7022. // {
  7023. // // S4_4进站接口
  7024. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  7025. // }
  7026. // else if (stationType == 2)
  7027. // {
  7028. // // S4_4出站接口
  7029. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  7030. // }
  7031. // }
  7032. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  7033. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  7034. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  7035. // }
  7036. // }
  7037. // catch (Exception ex)
  7038. // {
  7039. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  7040. // string str = ex.StackTrace;
  7041. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7042. // }
  7043. // #endregion N801A-S4_4 真空标机2
  7044. // // N801A-S4_5 弹夹扫码 数据
  7045. // #region N801A-S4_5 弹夹扫码
  7046. // try
  7047. // {
  7048. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  7049. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  7050. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  7051. // {
  7052. // if (d5BulletclipScanCode == 1) // 0->1
  7053. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7054. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  7055. // }
  7056. // }
  7057. // catch (Exception ex)
  7058. // {
  7059. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  7060. // string str = ex.StackTrace;
  7061. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7062. // }
  7063. // #endregion N801A-S4_5 弹夹扫码
  7064. // // N801A-S4_5 载具扫码 数据
  7065. // #region N801A-S4_5 载具扫码
  7066. // try
  7067. // {
  7068. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  7069. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  7070. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  7071. // {
  7072. // if (d5VehicleScanCode == 1) // 0->1
  7073. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7074. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  7075. // }
  7076. // }
  7077. // catch (Exception ex)
  7078. // {
  7079. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  7080. // string str = ex.StackTrace;
  7081. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7082. // }
  7083. // #endregion N801A-S4_5 载具扫码
  7084. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  7085. // #region N801A-S4_5 出站接口
  7086. // try
  7087. // {
  7088. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  7089. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  7090. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  7091. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  7092. // {
  7093. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  7094. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  7095. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  7096. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  7097. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  7098. // }
  7099. // }
  7100. // catch (Exception ex)
  7101. // {
  7102. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  7103. // string str = ex.StackTrace;
  7104. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7105. // }
  7106. // #endregion N801A-S4_5 出站接口
  7107. // // N801A-S4_5 节拍接口 数据
  7108. // #region N801A-S4_5 节拍接口
  7109. // try
  7110. // {
  7111. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  7112. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  7113. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  7114. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  7115. // {
  7116. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  7117. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  7118. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  7119. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  7120. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  7121. // }
  7122. // }
  7123. // catch (Exception ex)
  7124. // {
  7125. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  7126. // string str = ex.StackTrace;
  7127. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7128. // }
  7129. // #endregion N801A-S4_5 节拍接口
  7130. // #region 心跳
  7131. // try
  7132. // {
  7133. // short states = 0;
  7134. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7135. // }
  7136. // catch (Exception ex)
  7137. // {
  7138. // string str = ex.StackTrace;
  7139. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7140. // }
  7141. // #endregion 心跳
  7142. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7143. // stopwatch1.Stop();
  7144. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7145. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7146. // }
  7147. // else
  7148. // {
  7149. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7150. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  7151. // Funs[plcNo].Connect();
  7152. // }
  7153. // }
  7154. // catch (Exception ex)
  7155. // {
  7156. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7157. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  7158. // Funs[plcNo].ReConnect();
  7159. // }
  7160. // Thread.Sleep(IntervalReadPLC);
  7161. // }
  7162. //}
  7163. /// <summary>
  7164. /// [S4] 取放桁架 - S4_1弹夹扫码
  7165. /// </summary>
  7166. /// <param name="plcNo">PLC编号</param>
  7167. /// <param name="stationNameStr">工站全称</param>
  7168. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  7169. {
  7170. Stopwatch stopwatch1 = new Stopwatch();
  7171. Stopwatch stopwatch2 = new Stopwatch();
  7172. try
  7173. {
  7174. stopwatch1.Start();
  7175. // ZS 弹夹扫码
  7176. string d1BulletclipCode = " "; // 扫到的码
  7177. short d1BulletclipScanCode = 2;
  7178. stopwatch2.Start();
  7179. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  7180. //// MES_Flag
  7181. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7182. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7183. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7184. writeToPLC_Flag.Adress = 2002;
  7185. writeToPLC_Flag.Value = d1BulletclipScanCode;
  7186. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7187. {
  7188. Name = "d1BulletclipCode",
  7189. Adress = 2003,
  7190. ValueType = PLCValueType.String,
  7191. ValueTypeStrLength = 20,
  7192. Value = d1BulletclipCode
  7193. });
  7194. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7195. stopwatch2.Stop();
  7196. }
  7197. catch (Exception ex)
  7198. {
  7199. string str = ex.StackTrace;
  7200. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7201. stopwatch2.Start();
  7202. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  7203. //// MES_Flag
  7204. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  7205. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7206. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7207. writeToPLC_Flag.Adress = 2002;
  7208. writeToPLC_Flag.Value = (short)6;
  7209. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7210. {
  7211. Name = "d1BulletclipCode",
  7212. Adress = 2003,
  7213. ValueType = PLCValueType.String,
  7214. ValueTypeStrLength = 20,
  7215. Value = " "
  7216. });
  7217. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7218. stopwatch2.Stop();
  7219. }
  7220. stopwatch1.Stop();
  7221. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7222. }
  7223. /// <summary>
  7224. /// [S4] 取放桁架 - S4_1载具扫码
  7225. /// </summary>
  7226. /// <param name="plcNo">PLC编号</param>
  7227. /// <param name="stationNameStr">工站全称</param>
  7228. private void S4_1载具扫码(int plcNo, string stationNameStr)
  7229. {
  7230. Stopwatch stopwatch1 = new Stopwatch();
  7231. Stopwatch stopwatch2 = new Stopwatch();
  7232. try
  7233. {
  7234. stopwatch1.Start();
  7235. // ZS 载具扫码
  7236. string d1VehicleCode = ""; // 扫到的码
  7237. short d1VehicleScanCode = 2;
  7238. #region 进站
  7239. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  7240. {
  7241. #region 查询载具上的产品信息
  7242. string cavityData = string.Empty;
  7243. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  7244. if (string.IsNullOrEmpty(cavityData))
  7245. cavityData = "";
  7246. if (snResult != 0)
  7247. {
  7248. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7249. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  7250. writeToPLC_Flag1.Adress = 2033;
  7251. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  7252. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7253. {
  7254. Name = "d1VehicleCode",
  7255. Adress = 2034,
  7256. ValueType = PLCValueType.String,
  7257. ValueTypeStrLength = 20,
  7258. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7259. });
  7260. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  7261. stopwatch1.Stop();
  7262. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7263. return;
  7264. }
  7265. string[] cavitySNs = cavityData.Split('.');
  7266. string partNo = "";
  7267. if (cavitySNs != null && cavitySNs.Length >= 1)
  7268. {
  7269. partNo = cavitySNs[0];
  7270. }
  7271. #endregion 查询载具上的产品信息
  7272. List<TestItem> item = new List<TestItem>();
  7273. item.Add(new TestItem()
  7274. {
  7275. Parameter_name = "载具码",
  7276. Parameter_value = d1VehicleCode,
  7277. });
  7278. item.Add(new TestItem()
  7279. {
  7280. Parameter_name = "载具穴号",
  7281. Parameter_value = "1",
  7282. });
  7283. stopwatch2.Start();
  7284. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  7285. stopwatch2.Stop();
  7286. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  7287. }
  7288. #endregion 进站
  7289. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  7290. //// MES_Flag
  7291. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7292. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7293. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7294. writeToPLC_Flag.Adress = 2033;
  7295. writeToPLC_Flag.Value = d1VehicleScanCode;
  7296. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7297. {
  7298. Name = "d1VehicleCode",
  7299. Adress = 2034,
  7300. ValueType = PLCValueType.String,
  7301. ValueTypeStrLength = 20,
  7302. Value = d1VehicleCode
  7303. });
  7304. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7305. }
  7306. catch (Exception ex)
  7307. {
  7308. string str = ex.StackTrace;
  7309. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7310. stopwatch2.Start();
  7311. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  7312. //// MES_Flag
  7313. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  7314. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7315. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7316. writeToPLC_Flag.Adress = 2033;
  7317. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  7318. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7319. {
  7320. Name = "d1VehicleCode",
  7321. Adress = 2034,
  7322. ValueType = PLCValueType.String,
  7323. ValueTypeStrLength = 20,
  7324. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7325. });
  7326. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7327. stopwatch2.Stop();
  7328. }
  7329. stopwatch1.Stop();
  7330. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7331. }
  7332. // 上次采集到的SN
  7333. //private string sn_S4_1出站接口 = string.Empty;
  7334. /// <summary>
  7335. /// [S4] 取放桁架 - S4_1出站接口
  7336. /// </summary>
  7337. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  7338. {
  7339. Stopwatch stopwatch1 = new Stopwatch();
  7340. Stopwatch stopwatch2 = new Stopwatch();
  7341. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7342. string stationNameStr = stationCode + stationName;
  7343. string processItem = stationName; // 测试项目
  7344. try
  7345. {
  7346. stopwatch1.Start();
  7347. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7348. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7349. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7350. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7351. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  7352. sn = sn.Replace("\0", "");
  7353. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  7354. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  7355. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  7356. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  7357. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  7358. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  7359. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  7360. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  7361. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  7362. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  7363. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  7364. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  7365. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  7366. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  7367. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  7368. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  7369. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  7370. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  7371. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  7372. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  7373. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  7374. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  7375. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  7376. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  7377. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  7378. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  7379. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  7380. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  7381. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  7382. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  7383. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  7384. bool pass = d1Result == 1;
  7385. // 存 载具SN列表
  7386. List<string> vehicleCodes = new List<string>()
  7387. {
  7388. d1VehicleCode1,d1VehicleCode2,d1VehicleCode3,d1VehicleCode4,d1VehicleCode5,
  7389. d1VehicleCode6,d1VehicleCode7,d1VehicleCode8,d1VehicleCode9,d1VehicleCode10,
  7390. d1VehicleCode11,d1VehicleCode12,d1VehicleCode13,d1VehicleCode14,d1VehicleCode15
  7391. };
  7392. // 统一查 产品SN列表
  7393. List<string> partNos = new List<string>();
  7394. foreach (string vehicleCode in vehicleCodes)
  7395. {
  7396. if (string.IsNullOrEmpty(vehicleCode))
  7397. partNos.Add("");
  7398. else
  7399. {
  7400. string partNo = "";
  7401. #region 查询载具上的产品信息
  7402. string cavityData = string.Empty;
  7403. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7404. if (string.IsNullOrEmpty(cavityData))
  7405. cavityData = "";
  7406. if (snResult != 0)
  7407. {
  7408. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7409. writeToPLC_Flag1.Name = "d1MES_FLAG";
  7410. writeToPLC_Flag1.Adress = 2065;
  7411. writeToPLC_Flag1.Value = (short)4;
  7412. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  7413. stopwatch1.Stop();
  7414. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7415. return;
  7416. }
  7417. string[] cavitySNs = cavityData.Split('.');
  7418. if (cavitySNs != null && cavitySNs.Length >= 1)
  7419. partNo = cavitySNs[0];
  7420. #endregion 查询载具上的产品信息
  7421. partNos.Add(partNo);
  7422. }
  7423. }
  7424. // 统一上传
  7425. stopwatch2.Start();
  7426. List<int> results = new List<int>();
  7427. for (int i = 0; i < partNos.Count; i++)
  7428. {
  7429. string index = (i + 1).ToString(); // 弹夹穴号
  7430. if (string.IsNullOrEmpty(partNos[i]))
  7431. results.Add(1);
  7432. else
  7433. {
  7434. List<TestItem> items1 = new List<TestItem>();
  7435. items1.Add(new TestItem()
  7436. {
  7437. Parameter_name = "弹夹码",
  7438. Parameter_value = sn,
  7439. Parameter_unit = ""
  7440. });
  7441. items1.Add(new TestItem()
  7442. {
  7443. Parameter_name = "弹夹穴号",
  7444. Parameter_value = index,
  7445. Parameter_unit = ""
  7446. });
  7447. items1.Add(new TestItem()
  7448. {
  7449. Parameter_name = "载具码",
  7450. Parameter_value = vehicleCodes[i],
  7451. Parameter_unit = ""
  7452. });
  7453. items1.Add(new TestItem()
  7454. {
  7455. Parameter_name = "载具穴号",
  7456. Parameter_value = "1",
  7457. Parameter_unit = ""
  7458. });
  7459. items1.Add(new TestItem()
  7460. {
  7461. Parameter_name = "产品结果",
  7462. Parameter_value = d1Result == 1 ? "OK" : "NG",
  7463. Parameter_unit = ""
  7464. });
  7465. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7466. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  7467. results.Add(result1);
  7468. }
  7469. }
  7470. short result = 0;
  7471. if (results.All(a => a == 1))
  7472. result = 1;
  7473. else if (results.Contains(3))
  7474. result = 3;
  7475. else if (results.Contains(2))
  7476. result = 2;
  7477. else if (results.Contains(4))
  7478. result = 4;
  7479. else
  7480. result = 4;
  7481. stopwatch2.Stop();
  7482. #region 存储绑定数据到 边线MES系统中
  7483. if (result == 1)
  7484. {
  7485. string data = string.Join(".", vehicleCodes);
  7486. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7487. if (resultMesR != 0)
  7488. {
  7489. result = 4;
  7490. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  7491. }
  7492. }
  7493. #endregion 存储绑定数据到 边线MES系统中
  7494. // MES_Flag 为4MES报错
  7495. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7496. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7497. writeToPLC_Flag.Name = "d1MES_FLAG";
  7498. writeToPLC_Flag.Adress = 2065;
  7499. writeToPLC_Flag.Value = result;
  7500. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7501. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7502. }
  7503. catch (Exception ex)
  7504. {
  7505. stopwatch2.Restart();
  7506. // MES_Flag 为4上位机报错
  7507. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  7508. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7509. writeToPLC_Flag.Name = "d1MES_FLAG";
  7510. writeToPLC_Flag.Adress = 2065;
  7511. writeToPLC_Flag.Value = (short)4;
  7512. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7513. stopwatch2.Stop();
  7514. string str = ex.StackTrace;
  7515. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7516. }
  7517. stopwatch1.Stop();
  7518. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7519. }
  7520. /// <summary>
  7521. /// [S4] 取放桁架 - S4_1节拍接口
  7522. /// </summary>
  7523. /// <param name="plcNo">PLC编号</param>
  7524. /// <param name="stationNameStr">工站全称</param>
  7525. private void S4_1节拍接口(int plcNo, string stationNameStr)
  7526. {
  7527. Stopwatch stopwatch1 = new Stopwatch();
  7528. Stopwatch stopwatch2 = new Stopwatch();
  7529. string resultStr = string.Empty;
  7530. try
  7531. {
  7532. stopwatch1.Start();
  7533. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  7534. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  7535. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  7536. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7537. if (!actionBool)
  7538. {
  7539. stopwatch2.Start();
  7540. // MES_Flag
  7541. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7542. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7543. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7544. writeToPLC_Flag1.Adress = 2398;
  7545. writeToPLC_Flag1.Value = (short)4;
  7546. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7547. stopwatch2.Stop();
  7548. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7549. return;
  7550. }
  7551. string d1OEEPartNo = string.Empty; // 物料码
  7552. if (string.IsNullOrEmpty(d1OEEProductSN))
  7553. {
  7554. stopwatch2.Start();
  7555. // MES_Flag
  7556. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7557. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7558. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7559. writeToPLC_Flag1.Adress = 2398;
  7560. writeToPLC_Flag1.Value = (short)1;
  7561. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7562. stopwatch2.Stop();
  7563. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7564. return;
  7565. }
  7566. else
  7567. { // 查产品SN ZS
  7568. d1OEEPartNo = "Test";
  7569. }
  7570. short d1OEEMES_FLAG = 0;
  7571. // 上传OEE
  7572. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  7573. d1OEEMES_FLAG = result.Item1;
  7574. resultStr = result.Item2;
  7575. stopwatch2.Start();
  7576. // MES_Flag
  7577. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7578. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7579. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7580. writeToPLC_Flag.Adress = 2398;
  7581. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  7582. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7583. stopwatch2.Stop();
  7584. }
  7585. catch (Exception ex)
  7586. {
  7587. string str = ex.StackTrace;
  7588. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7589. // MES_Flag
  7590. stopwatch2.Start();
  7591. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7592. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7593. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7594. writeToPLC_Flag.Adress = 2398;
  7595. writeToPLC_Flag.Value = (short)4;
  7596. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7597. stopwatch2.Stop();
  7598. }
  7599. stopwatch1.Stop();
  7600. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7601. }
  7602. /// <summary>
  7603. /// [S4] 取放桁架 - S4_2桁架
  7604. /// </summary>
  7605. /// <param name="plcNo">PLC编号</param>
  7606. /// <param name="stationNameStr">工站全称</param>
  7607. private void S4_2桁架(int plcNo, string stationNameStr)
  7608. {
  7609. Stopwatch stopwatch1 = new Stopwatch();
  7610. Stopwatch stopwatch2 = new Stopwatch();
  7611. try
  7612. {
  7613. stopwatch1.Start();
  7614. // ZS 弹夹扫码
  7615. string d2BulletclipCode = " "; // 扫到的码
  7616. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  7617. short d2BulletclipScanCode = 2;
  7618. stopwatch2.Start();
  7619. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  7620. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  7621. //// MES_Flag
  7622. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7623. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7624. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7625. writeToPLC_Flag.Adress = 2430;
  7626. writeToPLC_Flag.Value = d2BulletclipScanCode;
  7627. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7628. {
  7629. Name = "d2BulletclipCode",
  7630. Adress = 2432,
  7631. ValueType = PLCValueType.String,
  7632. ValueTypeStrLength = 20,
  7633. Value = d2BulletclipCode
  7634. });
  7635. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7636. {
  7637. Name = "d2BulletclipStates",
  7638. Adress = 2431,
  7639. ValueType = PLCValueType.Short,
  7640. Value = d2BulletclipStates
  7641. });
  7642. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7643. stopwatch2.Stop();
  7644. }
  7645. catch (Exception ex)
  7646. {
  7647. string str = ex.StackTrace;
  7648. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7649. stopwatch2.Start();
  7650. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  7651. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  7652. // MES_Flag
  7653. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7654. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7655. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7656. writeToPLC_Flag.Adress = 2430;
  7657. writeToPLC_Flag.Value = (short)6;
  7658. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7659. {
  7660. Name = "d2BulletclipCode",
  7661. Adress = 2432,
  7662. ValueType = PLCValueType.String,
  7663. ValueTypeStrLength = 20,
  7664. Value = " "
  7665. });
  7666. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7667. {
  7668. Name = "d2BulletclipStates",
  7669. Adress = 2431,
  7670. ValueType = PLCValueType.Short,
  7671. Value = (short)0
  7672. });
  7673. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7674. stopwatch2.Stop();
  7675. }
  7676. stopwatch1.Stop();
  7677. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7678. }
  7679. // 上次采集到的SN
  7680. //private string sn_S4_3进站接口 = string.Empty;
  7681. /// <summary>
  7682. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  7683. /// </summary>
  7684. private void S4_3进站接口(int plcNo, string stationNameStr)
  7685. {
  7686. Stopwatch stopwatch1 = new Stopwatch();
  7687. Stopwatch stopwatch2 = new Stopwatch();
  7688. try
  7689. {
  7690. stopwatch1.Start();
  7691. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7692. sn = sn.Replace("\0", "");
  7693. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7694. #region 查询15个载具码
  7695. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7696. string vehicleData = string.Empty;
  7697. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7698. if (string.IsNullOrEmpty(vehicleData))
  7699. vehicleData = "";
  7700. if (snResult != 0)
  7701. {
  7702. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7703. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7704. writeToPLC_Flag1.Adress = 2463;
  7705. writeToPLC_Flag1.Value = (short)4;
  7706. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7707. stopwatch1.Stop();
  7708. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7709. return;
  7710. }
  7711. string[] cavitySNs = vehicleData.Split('.');
  7712. if (cavitySNs != null && cavitySNs.Length > 0)
  7713. {
  7714. for (int i = 0; i < cavitySNs.Length; i++)
  7715. {
  7716. if (string.IsNullOrEmpty(cavitySNs[i]))
  7717. vehicleCodes.Add("");
  7718. else
  7719. vehicleCodes.Add(cavitySNs[i]);
  7720. }
  7721. }
  7722. #endregion 查询15个载具码
  7723. #region 查询15个产品SN
  7724. List<string> portNos = new List<string>(); // 15个产品SN
  7725. foreach (string vehicleCode in vehicleCodes)
  7726. {
  7727. if (string.IsNullOrEmpty(vehicleCode))
  7728. portNos.Add("");
  7729. else
  7730. {
  7731. // 查询
  7732. string cavityData = string.Empty;
  7733. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7734. if (string.IsNullOrEmpty(cavityData))
  7735. cavityData = "";
  7736. if (snResult1 != 0)
  7737. {
  7738. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7739. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7740. writeToPLC_Flag1.Adress = 2463;
  7741. writeToPLC_Flag1.Value = (short)4;
  7742. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7743. stopwatch1.Stop();
  7744. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7745. return;
  7746. }
  7747. string[] partSNs = cavityData.Split('.');
  7748. if (partSNs != null && partSNs.Length >= 1)
  7749. portNos.Add(partSNs[0]);
  7750. else
  7751. portNos.Add("");
  7752. }
  7753. }
  7754. #endregion 查询15个产品SN
  7755. // 调用MES进站(最多15个)
  7756. stopwatch2.Start();
  7757. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  7758. for (int i = 0; i < vehicleCodes.Count; i++)
  7759. {
  7760. // 循环进站
  7761. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  7762. {
  7763. // 产品SN(物料码)校验
  7764. string portNo = portNos[i];
  7765. List<TestItem> item = new List<TestItem>();
  7766. item.Add(new TestItem()
  7767. {
  7768. Parameter_name = "弹夹码",
  7769. Parameter_value = sn,
  7770. });
  7771. item.Add(new TestItem()
  7772. {
  7773. Parameter_name = "弹夹穴位",
  7774. Parameter_value = (i + 1).ToString(),
  7775. });
  7776. item.Add(new TestItem()
  7777. {
  7778. Parameter_name = "载具码",
  7779. Parameter_value = vehicleCodes[i],
  7780. });
  7781. item.Add(new TestItem()
  7782. {
  7783. Parameter_name = "载具穴号",
  7784. Parameter_value = "1",
  7785. });
  7786. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  7787. }
  7788. }
  7789. stopwatch2.Stop();
  7790. short result = 0;
  7791. bool haveMesWarn = results.Contains(5);
  7792. bool havePCWarn = results.Contains(6);
  7793. if (haveMesWarn)
  7794. result = 2; // 5->2
  7795. else if (havePCWarn)
  7796. result = 6; // 6->4
  7797. else
  7798. result = 1;
  7799. // MES_Flag 为4MES报错
  7800. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7801. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7802. writeToPLC_Flag.Name = "d3MES_FLAG";
  7803. writeToPLC_Flag.Adress = 2463;
  7804. writeToPLC_Flag.Value = result;
  7805. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7806. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7807. }
  7808. catch (Exception ex)
  7809. {
  7810. stopwatch2.Stop();
  7811. // MES_Flag 为4上位机报错
  7812. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7813. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7814. writeToPLC_Flag.Name = "d3MES_FLAG";
  7815. writeToPLC_Flag.Adress = 2463;
  7816. writeToPLC_Flag.Value = (short)4;
  7817. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7818. string str = ex.StackTrace;
  7819. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7820. }
  7821. stopwatch1.Stop();
  7822. AddMessage(LogType.Info, stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7823. }
  7824. // 上次采集到的SN
  7825. //private string sn_S4_3出站接口 = string.Empty;
  7826. /// <summary>
  7827. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  7828. /// </summary>
  7829. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  7830. {
  7831. Stopwatch stopwatch1 = new Stopwatch();
  7832. Stopwatch stopwatch2 = new Stopwatch();
  7833. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7834. string stationNameStr = stationCode + stationName;
  7835. string processItem = stationName; // 测试项目
  7836. try
  7837. {
  7838. stopwatch1.Start();
  7839. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7840. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7841. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7842. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7843. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7844. sn = sn.Replace("\0", "");
  7845. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7846. bool isPass = d3Result == 1; // 产品结果 bool
  7847. #region 查询15个载具码
  7848. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7849. string vehicleData = string.Empty;
  7850. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7851. if (string.IsNullOrEmpty(vehicleData))
  7852. vehicleData = "";
  7853. if (snResult1 != 0)
  7854. {
  7855. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7856. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7857. writeToPLC_Flag1.Adress = 2463;
  7858. writeToPLC_Flag1.Value = (short)4;
  7859. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7860. stopwatch1.Stop();
  7861. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7862. return;
  7863. }
  7864. string[] cavitySNs = vehicleData.Split('.');
  7865. if (cavitySNs != null && cavitySNs.Length > 0)
  7866. {
  7867. for (int i = 0; i < cavitySNs.Length; i++)
  7868. {
  7869. if (string.IsNullOrEmpty(cavitySNs[i]))
  7870. vehicleCodes.Add("");
  7871. else
  7872. vehicleCodes.Add(cavitySNs[i]);
  7873. }
  7874. }
  7875. #endregion 查询15个载具码
  7876. // 统一查 产品SN列表
  7877. List<string> partNos = new List<string>();
  7878. foreach (string vehicleCode in vehicleCodes)
  7879. {
  7880. if (string.IsNullOrEmpty(vehicleCode))
  7881. partNos.Add("");
  7882. else
  7883. {
  7884. string partNo = "";
  7885. #region 查询载具上的产品信息
  7886. string cavityData = string.Empty;
  7887. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7888. if (string.IsNullOrEmpty(cavityData))
  7889. cavityData = "";
  7890. if (snResult != 0)
  7891. {
  7892. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7893. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7894. writeToPLC_Flag1.Adress = 2463;
  7895. writeToPLC_Flag1.Value = (short)4;
  7896. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7897. stopwatch1.Stop();
  7898. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7899. return;
  7900. }
  7901. string[] partSNs = cavityData.Split('.');
  7902. if (partSNs != null && partSNs.Length >= 1)
  7903. partNo = partSNs[0];
  7904. #endregion 查询载具上的产品信息
  7905. partNos.Add(partNo);
  7906. }
  7907. }
  7908. // 统一上传 - 调用MES出站
  7909. stopwatch2.Start();
  7910. List<int> results = new List<int>();
  7911. for (int i = 0; i < partNos.Count; i++)
  7912. {
  7913. string index = (i + 1).ToString(); // 弹夹穴号
  7914. if (string.IsNullOrEmpty(partNos[i]))
  7915. results.Add(1);
  7916. else
  7917. {
  7918. List<TestItem> items1 = new List<TestItem>();
  7919. items1.Add(new TestItem()
  7920. {
  7921. Parameter_name = "弹夹码",
  7922. Parameter_value = sn,
  7923. Parameter_unit = ""
  7924. });
  7925. items1.Add(new TestItem()
  7926. {
  7927. Parameter_name = "弹夹穴号",
  7928. Parameter_value = index,
  7929. Parameter_unit = ""
  7930. });
  7931. items1.Add(new TestItem()
  7932. {
  7933. Parameter_name = "载具码",
  7934. Parameter_value = vehicleCodes[i],
  7935. Parameter_unit = ""
  7936. });
  7937. items1.Add(new TestItem()
  7938. {
  7939. Parameter_name = "载具穴号",
  7940. Parameter_value = "1",
  7941. Parameter_unit = ""
  7942. });
  7943. items1.Add(new TestItem()
  7944. {
  7945. Parameter_name = "产品结果",
  7946. Parameter_value = d3Result == 1 ? "OK" : "NG",
  7947. Parameter_unit = ""
  7948. });
  7949. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7950. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  7951. results.Add(result1);
  7952. }
  7953. }
  7954. short result = 0;
  7955. if (results.All(a => a == 1))
  7956. result = 1;
  7957. else if (results.Contains(3))
  7958. result = 3;
  7959. else if (results.Contains(2))
  7960. result = 2;
  7961. else if (results.Contains(4))
  7962. result = 4;
  7963. else
  7964. result = 4;
  7965. stopwatch2.Stop();
  7966. // MES_Flag 为4MES报错
  7967. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7968. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7969. writeToPLC_Flag.Name = "d3MES_FLAG";
  7970. writeToPLC_Flag.Adress = 2463;
  7971. writeToPLC_Flag.Value = result;
  7972. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7973. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7974. }
  7975. catch (Exception ex)
  7976. {
  7977. stopwatch2.Restart();
  7978. // MES_Flag 为4上位机报错
  7979. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7980. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7981. writeToPLC_Flag.Name = "d3MES_FLAG";
  7982. writeToPLC_Flag.Adress = 2463;
  7983. writeToPLC_Flag.Value = (short)4;
  7984. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7985. string str = ex.StackTrace;
  7986. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7987. stopwatch2.Stop();
  7988. }
  7989. stopwatch1.Stop();
  7990. AddMessage(LogType.Info, stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7991. }
  7992. // 上次采集到的SN
  7993. //private string sn_S4_4进站接口 = string.Empty;
  7994. /// <summary>
  7995. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  7996. /// </summary>
  7997. private void S4_4进站接口(int plcNo, string stationNameStr)
  7998. {
  7999. Stopwatch stopwatch1 = new Stopwatch();
  8000. Stopwatch stopwatch2 = new Stopwatch();
  8001. try
  8002. {
  8003. stopwatch1.Start();
  8004. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8005. sn = sn.Replace("\0", "");
  8006. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8007. #region 查询15个载具码
  8008. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8009. string vehicleData = string.Empty;
  8010. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8011. if (string.IsNullOrEmpty(vehicleData))
  8012. vehicleData = "";
  8013. if (snResult != 0)
  8014. {
  8015. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8016. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8017. writeToPLC_Flag1.Adress = 2463;
  8018. writeToPLC_Flag1.Value = (short)4;
  8019. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8020. stopwatch1.Stop();
  8021. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8022. return;
  8023. }
  8024. string[] cavitySNs = vehicleData.Split('.');
  8025. if (cavitySNs != null && cavitySNs.Length > 0)
  8026. {
  8027. for (int i = 0; i < cavitySNs.Length; i++)
  8028. {
  8029. if (string.IsNullOrEmpty(cavitySNs[i]))
  8030. vehicleCodes.Add("");
  8031. else
  8032. vehicleCodes.Add(cavitySNs[i]);
  8033. }
  8034. }
  8035. #endregion 查询15个载具码
  8036. #region 查询15个产品SN
  8037. List<string> portNos = new List<string>(); // 15个产品SN
  8038. foreach (string vehicleCode in vehicleCodes)
  8039. {
  8040. if (string.IsNullOrEmpty(vehicleCode))
  8041. portNos.Add("");
  8042. else
  8043. {
  8044. // 查询
  8045. string cavityData = string.Empty;
  8046. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8047. if (string.IsNullOrEmpty(cavityData))
  8048. cavityData = "";
  8049. if (snResult1 != 0)
  8050. {
  8051. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8052. writeToPLC_Flag1.Name = "d3MES_FLAG";
  8053. writeToPLC_Flag1.Adress = 2463;
  8054. writeToPLC_Flag1.Value = (short)4;
  8055. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  8056. stopwatch1.Stop();
  8057. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8058. return;
  8059. }
  8060. string[] partSNs = cavityData.Split('.');
  8061. if (partSNs != null && partSNs.Length >= 1)
  8062. portNos.Add(partSNs[0]);
  8063. else
  8064. portNos.Add("");
  8065. }
  8066. }
  8067. #endregion 查询15个产品SN
  8068. // 调用MES进站(最多15个)
  8069. stopwatch2.Start();
  8070. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  8071. for (int i = 0; i < vehicleCodes.Count; i++)
  8072. {
  8073. // 循环进站
  8074. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  8075. {
  8076. // 产品SN(物料码)校验
  8077. string portNo = portNos[i];
  8078. List<TestItem> item = new List<TestItem>();
  8079. item.Add(new TestItem()
  8080. {
  8081. Parameter_name = "弹夹码",
  8082. Parameter_value = sn,
  8083. });
  8084. item.Add(new TestItem()
  8085. {
  8086. Parameter_name = "弹夹穴位",
  8087. Parameter_value = (i + 1).ToString(),
  8088. });
  8089. item.Add(new TestItem()
  8090. {
  8091. Parameter_name = "载具码",
  8092. Parameter_value = vehicleCodes[i],
  8093. });
  8094. item.Add(new TestItem()
  8095. {
  8096. Parameter_name = "载具穴号",
  8097. Parameter_value = "1",
  8098. });
  8099. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  8100. }
  8101. }
  8102. stopwatch2.Stop();
  8103. short result = 0;
  8104. bool haveMesWarn = results.Contains(5);
  8105. bool havePCWarn = results.Contains(6);
  8106. if (haveMesWarn)
  8107. result = 2; // 5->2
  8108. else if (havePCWarn)
  8109. result = 6; // 6->4
  8110. else
  8111. result = 1;
  8112. // MES_Flag 为4MES报错
  8113. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8114. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8115. writeToPLC_Flag.Name = "d4MES_FLAG";
  8116. writeToPLC_Flag.Adress = 2496;
  8117. writeToPLC_Flag.Value = result;
  8118. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8119. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8120. }
  8121. catch (Exception ex)
  8122. {
  8123. stopwatch2.Stop();
  8124. // MES_Flag 为4上位机报错
  8125. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8126. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8127. writeToPLC_Flag.Name = "d4MES_FLAG";
  8128. writeToPLC_Flag.Adress = 2496;
  8129. writeToPLC_Flag.Value = (short)4;
  8130. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8131. string str = ex.StackTrace;
  8132. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8133. }
  8134. stopwatch1.Stop();
  8135. AddMessage(LogType.Info, stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8136. }
  8137. // 上次采集到的SN
  8138. //private string sn_S4_4出站接口 = string.Empty;
  8139. /// <summary>
  8140. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  8141. /// </summary>
  8142. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  8143. {
  8144. Stopwatch stopwatch1 = new Stopwatch();
  8145. Stopwatch stopwatch2 = new Stopwatch();
  8146. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8147. string stationNameStr = stationCode + stationName;
  8148. string processItem = stationName; // 测试项目
  8149. try
  8150. {
  8151. stopwatch1.Start();
  8152. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8153. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8154. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8155. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8156. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8157. sn = sn.Replace("\0", "");
  8158. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8159. bool isPass = d4Result == 1; // 产品结果 bool
  8160. #region 查询15个载具码
  8161. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8162. string vehicleData = string.Empty;
  8163. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8164. if (string.IsNullOrEmpty(vehicleData))
  8165. vehicleData = "";
  8166. if (snResult1 != 0)
  8167. {
  8168. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8169. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8170. writeToPLC_Flag1.Adress = 2496;
  8171. writeToPLC_Flag1.Value = (short)4;
  8172. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8173. stopwatch1.Stop();
  8174. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8175. return;
  8176. }
  8177. string[] cavitySNs = vehicleData.Split('.');
  8178. if (cavitySNs != null && cavitySNs.Length > 0)
  8179. {
  8180. for (int i = 0; i < cavitySNs.Length; i++)
  8181. {
  8182. if (string.IsNullOrEmpty(cavitySNs[i]))
  8183. vehicleCodes.Add("");
  8184. else
  8185. vehicleCodes.Add(cavitySNs[i]);
  8186. }
  8187. }
  8188. #endregion 查询15个载具码
  8189. // 统一查 产品SN列表
  8190. List<string> partNos = new List<string>();
  8191. foreach (string vehicleCode in vehicleCodes)
  8192. {
  8193. if (string.IsNullOrEmpty(vehicleCode))
  8194. partNos.Add("");
  8195. else
  8196. {
  8197. string partNo = "";
  8198. #region 查询载具上的产品信息
  8199. string cavityData = string.Empty;
  8200. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8201. if (string.IsNullOrEmpty(cavityData))
  8202. cavityData = "";
  8203. if (snResult != 0)
  8204. {
  8205. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8206. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8207. writeToPLC_Flag1.Adress = 2496;
  8208. writeToPLC_Flag1.Value = (short)4;
  8209. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8210. stopwatch1.Stop();
  8211. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8212. return;
  8213. }
  8214. string[] partSNs = cavityData.Split('.');
  8215. if (partSNs != null && partSNs.Length >= 1)
  8216. partNo = partSNs[0];
  8217. #endregion 查询载具上的产品信息
  8218. partNos.Add(partNo);
  8219. }
  8220. }
  8221. // 调用MES出站
  8222. stopwatch2.Start();
  8223. // 统一上传
  8224. List<int> results = new List<int>();
  8225. for (int i = 0; i < partNos.Count; i++)
  8226. {
  8227. string index = (i + 1).ToString(); // 弹夹穴号
  8228. if (string.IsNullOrEmpty(partNos[i]))
  8229. results.Add(1);
  8230. else
  8231. {
  8232. List<TestItem> items1 = new List<TestItem>();
  8233. items1.Add(new TestItem()
  8234. {
  8235. Parameter_name = "弹夹码",
  8236. Parameter_value = sn,
  8237. Parameter_unit = ""
  8238. });
  8239. items1.Add(new TestItem()
  8240. {
  8241. Parameter_name = "弹夹穴号",
  8242. Parameter_value = index,
  8243. Parameter_unit = ""
  8244. });
  8245. items1.Add(new TestItem()
  8246. {
  8247. Parameter_name = "载具码",
  8248. Parameter_value = vehicleCodes[i],
  8249. Parameter_unit = ""
  8250. });
  8251. items1.Add(new TestItem()
  8252. {
  8253. Parameter_name = "载具穴号",
  8254. Parameter_value = "1",
  8255. Parameter_unit = ""
  8256. });
  8257. items1.Add(new TestItem()
  8258. {
  8259. Parameter_name = "产品结果",
  8260. Parameter_value = d4Result == 1 ? "OK" : "NG",
  8261. Parameter_unit = ""
  8262. });
  8263. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8264. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8265. results.Add(result1);
  8266. }
  8267. }
  8268. short result = 0;
  8269. if (results.All(a => a == 1))
  8270. result = 1;
  8271. else if (results.Contains(3))
  8272. result = 3;
  8273. else if (results.Contains(2))
  8274. result = 2;
  8275. else if (results.Contains(4))
  8276. result = 4;
  8277. else
  8278. result = 4;
  8279. stopwatch2.Stop();
  8280. // MES_Flag 为4MES报错
  8281. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8282. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8283. writeToPLC_Flag.Name = "d4MES_FLAG";
  8284. writeToPLC_Flag.Adress = 2496;
  8285. writeToPLC_Flag.Value = result;
  8286. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8287. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8288. }
  8289. catch (Exception ex)
  8290. {
  8291. stopwatch2.Restart();
  8292. // MES_Flag 为4上位机报错
  8293. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8294. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8295. writeToPLC_Flag.Name = "d4MES_FLAG";
  8296. writeToPLC_Flag.Adress = 2496;
  8297. writeToPLC_Flag.Value = (short)4;
  8298. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8299. string str = ex.StackTrace;
  8300. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8301. stopwatch2.Stop();
  8302. }
  8303. stopwatch1.Stop();
  8304. AddMessage(LogType.Info, stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8305. }
  8306. /// <summary>
  8307. /// [S4] 取放桁架 - S4_5弹夹扫码
  8308. /// </summary>
  8309. /// <param name="plcNo">PLC编号</param>
  8310. /// <param name="stationNameStr">工站全称</param>
  8311. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  8312. {
  8313. Stopwatch stopwatch1 = new Stopwatch();
  8314. Stopwatch stopwatch2 = new Stopwatch();
  8315. try
  8316. {
  8317. stopwatch1.Start();
  8318. // ZS 弹夹扫码
  8319. string d5BulletclipCode = " "; // 扫到的码
  8320. short d5BulletclipScanCode = 2;
  8321. stopwatch2.Start();
  8322. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  8323. //// MES_Flag
  8324. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8325. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8326. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8327. writeToPLC_Flag.Adress = 2528;
  8328. writeToPLC_Flag.Value = d5BulletclipScanCode;
  8329. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8330. {
  8331. Name = "d5BulletclipCode",
  8332. Adress = 2529,
  8333. ValueType = PLCValueType.String,
  8334. ValueTypeStrLength = 20,
  8335. Value = d5BulletclipCode
  8336. });
  8337. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8338. stopwatch2.Stop();
  8339. }
  8340. catch (Exception ex)
  8341. {
  8342. string str = ex.StackTrace;
  8343. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8344. stopwatch2.Start();
  8345. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  8346. //// MES_Flag
  8347. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  8348. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8349. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8350. writeToPLC_Flag.Adress = 2528;
  8351. writeToPLC_Flag.Value = (short)6;
  8352. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8353. {
  8354. Name = "d5BulletclipCode",
  8355. Adress = 2529,
  8356. ValueType = PLCValueType.String,
  8357. ValueTypeStrLength = 20,
  8358. Value = " "
  8359. });
  8360. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8361. stopwatch2.Stop();
  8362. }
  8363. stopwatch1.Stop();
  8364. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8365. }
  8366. /// <summary>
  8367. /// [S4] 取放桁架 - S4_5载具扫码
  8368. /// </summary>
  8369. /// <param name="plcNo">PLC编号</param>
  8370. /// <param name="stationNameStr">工站全称</param>
  8371. private void S4_5载具扫码(int plcNo, string stationNameStr)
  8372. {
  8373. Stopwatch stopwatch1 = new Stopwatch();
  8374. Stopwatch stopwatch2 = new Stopwatch();
  8375. try
  8376. {
  8377. stopwatch1.Start();
  8378. // ZS 载具扫码
  8379. string d5VehicleCode = " "; // 扫到的码
  8380. short d5VehicleScanCode = 2;
  8381. #region 进站
  8382. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  8383. {
  8384. // 查产品SN
  8385. #region 查询载具上的产品信息
  8386. string cavityData = string.Empty;
  8387. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  8388. if (string.IsNullOrEmpty(cavityData))
  8389. cavityData = "";
  8390. if (snResult != 0)
  8391. {
  8392. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8393. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  8394. writeToPLC_Flag1.Adress = 2559;
  8395. writeToPLC_Flag1.Value = (short)6;
  8396. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8397. {
  8398. Name = "d5VehicleCode",
  8399. Adress = 2560,
  8400. ValueType = PLCValueType.String,
  8401. ValueTypeStrLength = 20,
  8402. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  8403. });
  8404. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  8405. stopwatch1.Stop();
  8406. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8407. return;
  8408. }
  8409. string[] cavitySNs = cavityData.Split('.');
  8410. string partNo = "";
  8411. if (cavitySNs != null && cavitySNs.Length >= 1)
  8412. {
  8413. partNo = cavitySNs[0];
  8414. }
  8415. #endregion 查询载具上的产品信息
  8416. List<TestItem> item = new List<TestItem>();
  8417. item.Add(new TestItem()
  8418. {
  8419. Parameter_name = "载具码",
  8420. Parameter_value = d5VehicleCode,
  8421. });
  8422. item.Add(new TestItem()
  8423. {
  8424. Parameter_name = "载具穴号",
  8425. Parameter_value = "1",
  8426. });
  8427. stopwatch2.Start();
  8428. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  8429. stopwatch2.Stop();
  8430. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  8431. }
  8432. #endregion 进站
  8433. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  8434. //// MES_Flag
  8435. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8436. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8437. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8438. writeToPLC_Flag.Adress = 2559;
  8439. writeToPLC_Flag.Value = d5VehicleScanCode;
  8440. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8441. {
  8442. Name = "d5VehicleCode",
  8443. Adress = 2560,
  8444. ValueType = PLCValueType.String,
  8445. ValueTypeStrLength = 20,
  8446. Value = d5VehicleCode
  8447. });
  8448. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8449. }
  8450. catch (Exception ex)
  8451. {
  8452. string str = ex.StackTrace;
  8453. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8454. stopwatch2.Start();
  8455. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  8456. //// MES_Flag
  8457. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  8458. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8459. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8460. writeToPLC_Flag.Adress = 2559;
  8461. writeToPLC_Flag.Value = (short)6;
  8462. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8463. {
  8464. Name = "d5VehicleCode",
  8465. Adress = 2560,
  8466. ValueType = PLCValueType.String,
  8467. ValueTypeStrLength = 20,
  8468. Value = " "
  8469. });
  8470. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8471. stopwatch2.Stop();
  8472. }
  8473. stopwatch1.Stop();
  8474. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8475. }
  8476. // 上次采集到的SN
  8477. //private string sn_S4_5出站接口 = string.Empty;
  8478. /// <summary>
  8479. /// [S4] 取放桁架 - S4_5出站接口
  8480. /// </summary>
  8481. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  8482. {
  8483. Stopwatch stopwatch1 = new Stopwatch();
  8484. Stopwatch stopwatch2 = new Stopwatch();
  8485. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8486. string stationNameStr = stationCode + stationName;
  8487. string processItem = stationName; // 测试项目
  8488. try
  8489. {
  8490. stopwatch1.Start();
  8491. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8492. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8493. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8494. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8495. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  8496. sn = sn.Replace("\0", "");
  8497. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  8498. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  8499. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  8500. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  8501. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  8502. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  8503. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  8504. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  8505. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  8506. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  8507. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  8508. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  8509. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  8510. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  8511. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  8512. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  8513. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  8514. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  8515. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  8516. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  8517. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  8518. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  8519. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  8520. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  8521. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  8522. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  8523. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  8524. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  8525. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  8526. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  8527. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  8528. bool pass = d5Result == 1;
  8529. // 存 载具SN列表
  8530. List<string> vehicleCodes = new List<string>()
  8531. {
  8532. d5VehicleCode1,d5VehicleCode2,d5VehicleCode3,d5VehicleCode4,d5VehicleCode5,
  8533. d5VehicleCode6,d5VehicleCode7,d5VehicleCode8,d5VehicleCode9,d5VehicleCode10,
  8534. d5VehicleCode11,d5VehicleCode12,d5VehicleCode13,d5VehicleCode14,d5VehicleCode15
  8535. };
  8536. // 统一查 产品SN列表
  8537. List<string> partNos = new List<string>();
  8538. foreach (string vehicleCode in vehicleCodes)
  8539. {
  8540. if (string.IsNullOrEmpty(vehicleCode))
  8541. partNos.Add("");
  8542. else
  8543. {
  8544. string partNo = "";
  8545. #region 查询载具上的产品信息
  8546. string cavityData = string.Empty;
  8547. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8548. if (string.IsNullOrEmpty(cavityData))
  8549. cavityData = "";
  8550. if (snResult != 0)
  8551. {
  8552. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8553. writeToPLC_Flag1.Name = "d5MES_FLAG";
  8554. writeToPLC_Flag1.Adress = 2591;
  8555. writeToPLC_Flag1.Value = (short)4;
  8556. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  8557. stopwatch1.Stop();
  8558. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8559. return;
  8560. }
  8561. string[] cavitySNs = cavityData.Split('.');
  8562. if (cavitySNs != null && cavitySNs.Length >= 1)
  8563. partNo = cavitySNs[0];
  8564. #endregion 查询载具上的产品信息
  8565. partNos.Add(partNo);
  8566. }
  8567. }
  8568. // 统一上传
  8569. stopwatch2.Start();
  8570. List<int> results = new List<int>();
  8571. for (int i = 0; i < partNos.Count; i++)
  8572. {
  8573. string index = (i + 1).ToString(); // 弹夹穴号
  8574. if (string.IsNullOrEmpty(partNos[i]))
  8575. results.Add(1);
  8576. else
  8577. {
  8578. List<TestItem> items1 = new List<TestItem>();
  8579. items1.Add(new TestItem()
  8580. {
  8581. Parameter_name = "弹夹码",
  8582. Parameter_value = sn,
  8583. Parameter_unit = ""
  8584. });
  8585. items1.Add(new TestItem()
  8586. {
  8587. Parameter_name = "弹夹穴号",
  8588. Parameter_value = index,
  8589. Parameter_unit = ""
  8590. });
  8591. items1.Add(new TestItem()
  8592. {
  8593. Parameter_name = "载具码",
  8594. Parameter_value = vehicleCodes[i],
  8595. Parameter_unit = ""
  8596. });
  8597. items1.Add(new TestItem()
  8598. {
  8599. Parameter_name = "载具穴号",
  8600. Parameter_value = "1",
  8601. Parameter_unit = ""
  8602. });
  8603. items1.Add(new TestItem()
  8604. {
  8605. Parameter_name = "产品结果",
  8606. Parameter_value = d5Result == 1 ? "OK" : "NG",
  8607. Parameter_unit = ""
  8608. });
  8609. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8610. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  8611. results.Add(result1);
  8612. }
  8613. }
  8614. short result = 0;
  8615. if (results.All(a => a == 1))
  8616. result = 1;
  8617. else if (results.Contains(3))
  8618. result = 3;
  8619. else if (results.Contains(2))
  8620. result = 2;
  8621. else if (results.Contains(4))
  8622. result = 4;
  8623. else
  8624. result = 4;
  8625. stopwatch2.Stop();
  8626. #region 存储绑定数据到 边线MES系统中
  8627. if (result == 1)
  8628. {
  8629. // 删除绑定信息
  8630. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  8631. if (resultMesR != 0)
  8632. {
  8633. result = 4;
  8634. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  8635. }
  8636. }
  8637. #endregion 存储绑定数据到 边线MES系统中
  8638. // MES_Flag 为4MES报错
  8639. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8640. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8641. writeToPLC_Flag.Name = "d5MES_FLAG";
  8642. writeToPLC_Flag.Adress = 2591;
  8643. writeToPLC_Flag.Value = result;
  8644. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8645. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8646. }
  8647. catch (Exception ex)
  8648. {
  8649. stopwatch2.Restart();
  8650. // MES_Flag 为4上位机报错
  8651. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  8652. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8653. writeToPLC_Flag.Name = "d5MES_FLAG";
  8654. writeToPLC_Flag.Adress = 2591;
  8655. writeToPLC_Flag.Value = (short)4;
  8656. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8657. stopwatch2.Stop();
  8658. string str = ex.StackTrace;
  8659. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8660. }
  8661. stopwatch1.Stop();
  8662. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8663. }
  8664. /// <summary>
  8665. /// [S4] 取放桁架 - S4_5节拍接口
  8666. /// </summary>
  8667. /// <param name="plcNo">PLC编号</param>
  8668. /// <param name="stationNameStr">工站全称</param>
  8669. private void S4_5节拍接口(int plcNo, string stationNameStr)
  8670. {
  8671. Stopwatch stopwatch1 = new Stopwatch();
  8672. Stopwatch stopwatch2 = new Stopwatch();
  8673. string resultStr = string.Empty;
  8674. try
  8675. {
  8676. stopwatch1.Start();
  8677. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  8678. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  8679. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  8680. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8681. if (!actionBool)
  8682. {
  8683. stopwatch2.Start();
  8684. // MES_Flag
  8685. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  8686. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8687. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8688. writeToPLC_Flag1.Adress = 2924;
  8689. writeToPLC_Flag1.Value = (short)4;
  8690. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8691. stopwatch2.Stop();
  8692. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8693. return;
  8694. }
  8695. string d5OEEPartNo = string.Empty; // 物料码
  8696. if (string.IsNullOrEmpty(d5OEEProductSN))
  8697. {
  8698. stopwatch2.Start();
  8699. // MES_Flag
  8700. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8701. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8702. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8703. writeToPLC_Flag1.Adress = 2924;
  8704. writeToPLC_Flag1.Value = (short)1;
  8705. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8706. stopwatch2.Stop();
  8707. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8708. return;
  8709. }
  8710. else
  8711. { // 查产品SN
  8712. d5OEEPartNo = "Test"; // ZS
  8713. }
  8714. short d5OEEMES_FLAG = 0;
  8715. // 上传OEE
  8716. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  8717. d5OEEMES_FLAG = result.Item1;
  8718. resultStr = result.Item2;
  8719. stopwatch2.Start();
  8720. // MES_Flag
  8721. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8722. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8723. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8724. writeToPLC_Flag.Adress = 2924;
  8725. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  8726. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8727. stopwatch2.Stop();
  8728. }
  8729. catch (Exception ex)
  8730. {
  8731. string str = ex.StackTrace;
  8732. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8733. // MES_Flag
  8734. stopwatch2.Start();
  8735. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  8736. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8737. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8738. writeToPLC_Flag.Adress = 2924;
  8739. writeToPLC_Flag.Value = (short)4;
  8740. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8741. stopwatch2.Stop();
  8742. }
  8743. stopwatch1.Stop();
  8744. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8745. }
  8746. #endregion [S4] 取放桁架
  8747. #endregion PLC4 刘果段
  8748. #region PLC5 张超凡
  8749. #region [S5] Tray盘下料装备
  8750. /// <summary>
  8751. /// S5工位的数据- 触发信号上次的值
  8752. /// </summary>
  8753. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  8754. /// <summary>
  8755. /// S5工位的数据(含触发信号)
  8756. /// </summary>
  8757. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  8758. /// <summary>
  8759. /// S5工位的数据- 回写点位
  8760. /// </summary>
  8761. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8762. /// <summary>
  8763. /// [S5] Tray盘下料装备
  8764. /// </summary>
  8765. /// <param name="plcNo">PLC编号</param>
  8766. //private void ReadStation_S5(int plcNo)
  8767. //{
  8768. // // [S1] Tray盘上料装备
  8769. // // [S2] FCT
  8770. // // [S3] 值板机
  8771. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8772. // // [S5] Tray盘下料装备
  8773. // /// 上位机心跳
  8774. // /// 获取设备报警数据与状态信息
  8775. // string stationCode = "[S5]";
  8776. // string stationName = "Tray盘下料装备";
  8777. // string stationNameStr = stationCode + stationName;
  8778. // #region 创建字典
  8779. // // 触发信号字典 赋值
  8780. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8781. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8782. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8783. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8784. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  8785. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8786. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  8787. // // PLC数据字典 赋值
  8788. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8789. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  8790. // s5PLCData.Add("e1ProductSN_Check", ""); //
  8791. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8792. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  8793. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  8794. // s5PLCData.Add("e1PartNo", ""); // 物料码
  8795. // s5PLCData.Add("e1Result", 0); // 产品结果
  8796. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8797. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  8798. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  8799. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  8800. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8801. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  8802. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  8803. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8804. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  8805. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  8806. // #endregion 创建字典
  8807. // while (IsRun)
  8808. // {
  8809. // try
  8810. // {
  8811. // if (!GlobalContext._IsCon_Funs5)
  8812. // {
  8813. // UpdatePLCMonitor(1, plcNo, 0);
  8814. // continue;
  8815. // }
  8816. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8817. // {
  8818. // Stopwatch stopwatch1 = new Stopwatch();
  8819. // Stopwatch stopwatch2 = new Stopwatch();
  8820. // stopwatch1.Start();
  8821. // stopwatch2.Start();
  8822. // #region 一次性读取所有数据
  8823. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8824. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  8825. // int[] datas = data1.Concat(data2).ToArray();
  8826. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  8827. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  8828. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8829. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  8830. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  8831. // s5PLCData["e1MES_FLAG"] = datas[35];
  8832. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  8833. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  8834. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  8835. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  8836. // s5PLCData["e1Result"] = datas[76];
  8837. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  8838. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  8839. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  8840. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  8841. // s5PLCData["e1OEEType"] = datas[109];
  8842. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  8843. // s5PLCData["e1AGVUpStart"] = datas[121];
  8844. // s5PLCData["e1AGVUpEnd"] = datas[122];
  8845. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  8846. // s5PLCData["e1AGVDownStart"] = datas[134];
  8847. // s5PLCData["e1AGVDownEnd"] = datas[135];
  8848. // #endregion 一次性读取所有数据
  8849. // stopwatch2.Stop();
  8850. // #region 回写操作,写后清空flag
  8851. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  8852. // #endregion 回写操作,写后清空flag
  8853. // #region 进站校验
  8854. // try
  8855. // {
  8856. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  8857. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  8858. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  8859. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  8860. // {
  8861. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  8862. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8863. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  8864. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8865. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  8866. // }
  8867. // }
  8868. // catch (Exception ex)
  8869. // {
  8870. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8871. // string str = ex.StackTrace;
  8872. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8873. // }
  8874. // #endregion 进站校验
  8875. // #region 出站接口
  8876. // try
  8877. // {
  8878. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  8879. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  8880. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  8881. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  8882. // {
  8883. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  8884. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8885. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  8886. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  8887. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  8888. // }
  8889. // }
  8890. // catch (Exception ex)
  8891. // {
  8892. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  8893. // string str = ex.StackTrace;
  8894. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8895. // }
  8896. // #endregion 出站接口
  8897. // #region 节拍接口
  8898. // try
  8899. // {
  8900. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  8901. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  8902. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  8903. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  8904. // {
  8905. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  8906. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8907. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  8908. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  8909. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  8910. // }
  8911. // }
  8912. // catch (Exception ex)
  8913. // {
  8914. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  8915. // string str = ex.StackTrace;
  8916. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8917. // }
  8918. // #endregion 节拍接口
  8919. // #region AGV上料
  8920. // // AGV上料叫AGV信号
  8921. // try
  8922. // {
  8923. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  8924. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  8925. // if (e1AGVUpCall != e1AGVUpCallOld)
  8926. // {
  8927. // if (e1AGVUpCall == 1) // 0->1
  8928. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  8929. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  8930. // }
  8931. // }
  8932. // catch (Exception ex)
  8933. // {
  8934. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  8935. // string str = ex.StackTrace;
  8936. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8937. // }
  8938. // // AGV上料完成信号
  8939. // try
  8940. // {
  8941. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  8942. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  8943. // if (e1AGVUpEnd != e1AGVUpEndOld)
  8944. // {
  8945. // if (e1AGVUpEnd == 1) // 0->1
  8946. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  8947. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  8948. // }
  8949. // }
  8950. // catch (Exception ex)
  8951. // {
  8952. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  8953. // string str = ex.StackTrace;
  8954. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8955. // }
  8956. // #endregion AGV上料
  8957. // #region AGV下料
  8958. // // AGV下料叫agv信号
  8959. // try
  8960. // {
  8961. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  8962. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  8963. // if (e1AGVDownCall != e1AGVDownCallOld)
  8964. // {
  8965. // if (e1AGVDownCall == 1) // 0->1
  8966. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  8967. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  8968. // }
  8969. // }
  8970. // catch (Exception ex)
  8971. // {
  8972. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  8973. // string str = ex.StackTrace;
  8974. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8975. // }
  8976. // // AGV下料完成信号
  8977. // try
  8978. // {
  8979. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  8980. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  8981. // if (e1AGVDownEnd != e1AGVDownEndOld)
  8982. // {
  8983. // if (e1AGVDownEnd == 1) // 0->1
  8984. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  8985. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  8986. // }
  8987. // }
  8988. // catch (Exception ex)
  8989. // {
  8990. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  8991. // string str = ex.StackTrace;
  8992. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8993. // }
  8994. // #endregion AGV下料
  8995. // #region 心跳
  8996. // try
  8997. // {
  8998. // short states = 0;
  8999. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  9000. // }
  9001. // catch (Exception ex)
  9002. // {
  9003. // string str = ex.StackTrace;
  9004. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9005. // }
  9006. // #endregion 心跳
  9007. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  9008. // stopwatch1.Stop();
  9009. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  9010. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  9011. // }
  9012. // else
  9013. // {
  9014. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9015. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  9016. // Funs[plcNo].Connect();
  9017. // }
  9018. // }
  9019. // catch (Exception ex)
  9020. // {
  9021. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  9022. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  9023. // Funs[plcNo].ReConnect();
  9024. // }
  9025. // Thread.Sleep(IntervalReadPLC);
  9026. // }
  9027. //}
  9028. /// <summary>
  9029. /// [S5] Tray盘下料装备 - 进站校验
  9030. /// </summary>
  9031. /// <param name="plcNo">PLC编号</param>
  9032. /// <param name="stationNameStr">工站全称</param>
  9033. private void S5进站校验(int plcNo, string stationNameStr)
  9034. {
  9035. Stopwatch stopwatch1 = new Stopwatch();
  9036. Stopwatch stopwatch2 = new Stopwatch();
  9037. try
  9038. {
  9039. stopwatch1.Start();
  9040. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  9041. sn = sn.Replace("\0", "");
  9042. // 获取产品SN By 载具码
  9043. #region 查询载具上的产品信息
  9044. string cavityData = string.Empty;
  9045. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9046. if (string.IsNullOrEmpty(cavityData))
  9047. cavityData = "";
  9048. if (snResult != 0)
  9049. {
  9050. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9051. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  9052. writeToPLC_Flag1.Adress = 2003;
  9053. writeToPLC_Flag1.Value = (short)6;
  9054. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  9055. stopwatch1.Stop();
  9056. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9057. return;
  9058. }
  9059. string[] cavitySNs = cavityData.Split('.');
  9060. string partNo = string.Empty;
  9061. if (cavitySNs != null && cavitySNs.Length >= 1)
  9062. partNo = cavitySNs[0];
  9063. #endregion 查询载具上的产品信息
  9064. // 产品SN(物料码)校验
  9065. List<TestItem> item = new List<TestItem>();
  9066. item.Add(new TestItem()
  9067. {
  9068. Parameter_name = "载具码",
  9069. Parameter_value = sn,
  9070. });
  9071. item.Add(new TestItem()
  9072. {
  9073. Parameter_name = "载具穴号",
  9074. Parameter_value = "1",
  9075. });
  9076. stopwatch2.Start();
  9077. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  9078. stopwatch2.Stop();
  9079. short e1MES_FLAG_Check = (short)result;
  9080. // MES_Flag
  9081. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9082. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9083. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9084. writeToPLC_Flag.Adress = 2003;
  9085. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  9086. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9087. }
  9088. catch (Exception ex)
  9089. {
  9090. string str = ex.StackTrace;
  9091. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9092. // MES_Flag
  9093. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9094. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9095. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9096. writeToPLC_Flag.Adress = 2003;
  9097. writeToPLC_Flag.Value = (short)6;
  9098. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9099. }
  9100. stopwatch1.Stop();
  9101. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9102. }
  9103. /// <summary>
  9104. /// [S5] Tray盘下料装备 - 出站接口
  9105. /// </summary>
  9106. /// <param name="plcNo"></param>
  9107. /// <param name="stationCode"></param>
  9108. /// <param name="stationName"></param>
  9109. private void S5出站接口(int plcNo, string stationCode, string stationName)
  9110. {
  9111. Stopwatch stopwatch1 = new Stopwatch();
  9112. Stopwatch stopwatch2 = new Stopwatch();
  9113. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9114. string stationNameStr = stationCode + stationName;
  9115. string processItem = stationName; // 测试项目
  9116. try
  9117. {
  9118. stopwatch1.Start();
  9119. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9120. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9121. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9122. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9123. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  9124. sn = sn.Replace("\0", "");
  9125. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  9126. //partNo = partNo.Replace("\0", "");
  9127. #region 查询载具上的产品信息
  9128. string cavityData = string.Empty;
  9129. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9130. if (string.IsNullOrEmpty(cavityData))
  9131. cavityData = "";
  9132. if (snResult != 0)
  9133. {
  9134. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9135. writeToPLC_Flag1.Name = "e1MES_FLAG";
  9136. writeToPLC_Flag1.Adress = 2035;
  9137. writeToPLC_Flag1.Value = (short)4;
  9138. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  9139. stopwatch1.Stop();
  9140. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9141. return;
  9142. }
  9143. string[] cavitySNs = cavityData.Split('.');
  9144. string partNo = string.Empty;
  9145. if (cavitySNs != null && cavitySNs.Length >= 1)
  9146. partNo = cavitySNs[0];
  9147. #endregion 查询载具上的产品信息
  9148. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  9149. bool pass = e1Result == 1;
  9150. stopwatch2.Start();
  9151. // 上传MES
  9152. List<TestItem> items = new List<TestItem>();
  9153. items.Add(new TestItem()
  9154. {
  9155. Parameter_name = "载具码",
  9156. Parameter_value = sn,
  9157. Parameter_unit = ""
  9158. });
  9159. items.Add(new TestItem()
  9160. {
  9161. Parameter_name = "载具穴号",
  9162. Parameter_value = "1",
  9163. Parameter_unit = ""
  9164. });
  9165. items.Add(new TestItem()
  9166. {
  9167. Parameter_name = "产品结果",
  9168. Parameter_value = e1Result == 1 ? "OK" : "NG",
  9169. Parameter_unit = ""
  9170. });
  9171. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  9172. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  9173. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  9174. short result = result1 == 1 ? (short)1 : (short)3;
  9175. stopwatch2.Stop();
  9176. #region 存储绑定数据到 边线MES系统中
  9177. if (result == 1)
  9178. {
  9179. // 删除绑定信息
  9180. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  9181. if (resultMesR != 0)
  9182. {
  9183. result = 4;
  9184. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  9185. }
  9186. }
  9187. #endregion 存储绑定数据到 边线MES系统中
  9188. // MES_Flag 为MES报错
  9189. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9190. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  9191. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9192. writeToPLC_Flag.Name = "e1MES_FLAG";
  9193. writeToPLC_Flag.Adress = 2035;
  9194. writeToPLC_Flag.Value = result;
  9195. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9196. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9197. }
  9198. catch (Exception ex)
  9199. {
  9200. stopwatch2.Restart();
  9201. // MES_Flag 为4上位机报错
  9202. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  9203. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9204. writeToPLC_Flag.Name = "e1MES_FLAG";
  9205. writeToPLC_Flag.Adress = 2035;
  9206. writeToPLC_Flag.Value = (short)4;
  9207. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9208. stopwatch2.Stop();
  9209. string str = ex.StackTrace;
  9210. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9211. }
  9212. stopwatch1.Stop();
  9213. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9214. }
  9215. /// <summary>
  9216. /// [S5] Tray盘下料装备 - 节拍接口
  9217. /// </summary>
  9218. /// <param name="plcNo">PLC编号</param>
  9219. /// <param name="stationNameStr">工站全称</param>
  9220. private void S5节拍接口(int plcNo, string stationNameStr)
  9221. {
  9222. Stopwatch stopwatch1 = new Stopwatch();
  9223. Stopwatch stopwatch2 = new Stopwatch();
  9224. string resultStr = string.Empty;
  9225. try
  9226. {
  9227. stopwatch1.Start();
  9228. string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  9229. string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  9230. e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  9231. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9232. if (!actionBool)
  9233. {
  9234. stopwatch2.Start();
  9235. // MES_Flag
  9236. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9237. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9238. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9239. writeToPLC_Flag1.Adress = 2088;
  9240. writeToPLC_Flag1.Value = (short)4;
  9241. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9242. stopwatch2.Stop();
  9243. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9244. return;
  9245. }
  9246. string e1OEEPartNo = string.Empty; // 物料码
  9247. if (string.IsNullOrEmpty(e1OEEProductSN))
  9248. {
  9249. stopwatch2.Start();
  9250. // MES_Flag
  9251. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9252. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9253. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9254. writeToPLC_Flag1.Adress = 2088;
  9255. writeToPLC_Flag1.Value = (short)1;
  9256. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9257. stopwatch2.Stop();
  9258. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9259. return;
  9260. }
  9261. else
  9262. { // 查产品SN
  9263. e1OEEPartNo = "Test"; // ZS
  9264. }
  9265. short e1OEEMES_FLAG = 0;
  9266. // 上传OEE
  9267. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  9268. e1OEEMES_FLAG = result.Item1;
  9269. resultStr = result.Item2;
  9270. stopwatch2.Start();
  9271. // MES_Flag
  9272. //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9273. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9274. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9275. writeToPLC_Flag.Adress = 2088;
  9276. writeToPLC_Flag.Value = e1OEEMES_FLAG;
  9277. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9278. stopwatch2.Stop();
  9279. }
  9280. catch (Exception ex)
  9281. {
  9282. string str = ex.StackTrace;
  9283. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9284. // MES_Flag
  9285. stopwatch2.Start();
  9286. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9287. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9288. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9289. writeToPLC_Flag.Adress = 2088;
  9290. writeToPLC_Flag.Value = (short)4;
  9291. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9292. stopwatch2.Stop();
  9293. }
  9294. stopwatch1.Stop();
  9295. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9296. }
  9297. /// <summary>
  9298. /// [S5] Tray盘下料装备 - AGV上料叫agv
  9299. /// </summary>
  9300. /// <param name="plcNo">PLC编号</param>
  9301. /// <param name="stationNameStr">工站全称</param>
  9302. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  9303. {
  9304. Stopwatch stopwatch1 = new Stopwatch();
  9305. Stopwatch stopwatch2 = new Stopwatch();
  9306. try
  9307. {
  9308. stopwatch1.Start();
  9309. // ZS 呼叫AGV
  9310. short e1AGVUpCall = 2;
  9311. stopwatch2.Start();
  9312. // e1AGVUpCall
  9313. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9314. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9315. writeToPLC_Flag.Name = "e1AGVUpCall";
  9316. writeToPLC_Flag.Adress = 2120;
  9317. writeToPLC_Flag.Value = e1AGVUpCall;
  9318. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9319. stopwatch2.Stop();
  9320. }
  9321. catch (Exception ex)
  9322. {
  9323. string str = ex.StackTrace;
  9324. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9325. // e1AGVUpCall
  9326. stopwatch2.Start();
  9327. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9328. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9329. writeToPLC_Flag.Name = "e1AGVUpCall";
  9330. writeToPLC_Flag.Adress = 2120;
  9331. writeToPLC_Flag.Value = (short)4;
  9332. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9333. stopwatch2.Stop();
  9334. }
  9335. stopwatch1.Stop();
  9336. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9337. }
  9338. /// <summary>
  9339. /// [S5] Tray盘下料装备 - AGV上料完成
  9340. /// </summary>
  9341. /// <param name="plcNo">PLC编号</param>
  9342. /// <param name="stationNameStr">工站全称</param>
  9343. private void S5AGV上料完成(int plcNo, string stationNameStr)
  9344. {
  9345. Stopwatch stopwatch1 = new Stopwatch();
  9346. Stopwatch stopwatch2 = new Stopwatch();
  9347. try
  9348. {
  9349. stopwatch1.Start();
  9350. // ZS AGV上料完成,让小车离开
  9351. short e1AGVUpEnd = 2;
  9352. stopwatch2.Start();
  9353. // e1AGVUpEnd
  9354. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9355. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9356. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9357. writeToPLC_Flag.Adress = 2122;
  9358. writeToPLC_Flag.Value = e1AGVUpEnd;
  9359. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9360. stopwatch2.Stop();
  9361. }
  9362. catch (Exception ex)
  9363. {
  9364. string str = ex.StackTrace;
  9365. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9366. // e1AGVUpEnd
  9367. stopwatch2.Start();
  9368. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9369. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9370. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9371. writeToPLC_Flag.Adress = 2122;
  9372. writeToPLC_Flag.Value = (short)4;
  9373. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9374. stopwatch2.Stop();
  9375. }
  9376. stopwatch1.Stop();
  9377. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9378. }
  9379. /// <summary>
  9380. /// [S5] Tray盘下料装备 - AGV下料叫agv
  9381. /// </summary>
  9382. /// <param name="plcNo">PLC编号</param>
  9383. /// <param name="stationNameStr">工站全称</param>
  9384. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  9385. {
  9386. Stopwatch stopwatch1 = new Stopwatch();
  9387. Stopwatch stopwatch2 = new Stopwatch();
  9388. try
  9389. {
  9390. stopwatch1.Start();
  9391. // ZS 呼叫AGV
  9392. short e1AGVDownCall = 2;
  9393. stopwatch2.Start();
  9394. // e1AGVDownCall
  9395. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9396. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9397. writeToPLC_Flag.Name = "e1AGVDownCall";
  9398. writeToPLC_Flag.Adress = 2133;
  9399. writeToPLC_Flag.Value = e1AGVDownCall;
  9400. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9401. stopwatch2.Stop();
  9402. }
  9403. catch (Exception ex)
  9404. {
  9405. string str = ex.StackTrace;
  9406. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9407. // e1AGVDownCall
  9408. stopwatch2.Start();
  9409. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9410. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9411. writeToPLC_Flag.Name = "e1AGVDownCall";
  9412. writeToPLC_Flag.Adress = 2133;
  9413. writeToPLC_Flag.Value = (short)4;
  9414. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9415. stopwatch2.Stop();
  9416. }
  9417. stopwatch1.Stop();
  9418. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9419. }
  9420. /// <summary>
  9421. /// [S5] Tray盘下料装备 - AGV下料完成
  9422. /// </summary>
  9423. /// <param name="plcNo">PLC编号</param>
  9424. /// <param name="stationNameStr">工站全称</param>
  9425. private void S5AGV下料完成(int plcNo, string stationNameStr)
  9426. {
  9427. Stopwatch stopwatch1 = new Stopwatch();
  9428. Stopwatch stopwatch2 = new Stopwatch();
  9429. try
  9430. {
  9431. stopwatch1.Start();
  9432. // ZS AGV上料完成,让小车离开
  9433. short e1AGVDownEnd = 2;
  9434. stopwatch2.Start();
  9435. // e1AGVDownEnd
  9436. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9437. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9438. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9439. writeToPLC_Flag.Adress = 2135;
  9440. writeToPLC_Flag.Value = e1AGVDownEnd;
  9441. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9442. stopwatch2.Stop();
  9443. }
  9444. catch (Exception ex)
  9445. {
  9446. string str = ex.StackTrace;
  9447. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9448. // e1AGVDownEnd
  9449. stopwatch2.Start();
  9450. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9451. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9452. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9453. writeToPLC_Flag.Adress = 2135;
  9454. writeToPLC_Flag.Value = (short)4;
  9455. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9456. stopwatch2.Stop();
  9457. }
  9458. stopwatch1.Stop();
  9459. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9460. }
  9461. #endregion [S5] Tray盘下料装备
  9462. #endregion PLC5 张超凡
  9463. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  9464. /// <summary>
  9465. /// PLC读取到的数据 -添加数据
  9466. /// </summary>
  9467. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  9468. {
  9469. if (sxPlcData.ContainsKey(newKey))
  9470. sxPlcData[newKey] = newValue;
  9471. else
  9472. sxPlcData.Add(newKey, newValue);
  9473. }
  9474. /// <summary>
  9475. /// PLC需要写入的数据 -添加数据
  9476. /// </summary>
  9477. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey, WriteToPLC_Flag newValue)
  9478. {
  9479. if (sxPLCWriteData.ContainsKey(newKey))
  9480. sxPLCWriteData[newKey] = newValue;
  9481. else
  9482. sxPLCWriteData.Add(newKey, newValue);
  9483. }
  9484. /// <summary>
  9485. /// PLC回写操作,写后清空flag
  9486. /// </summary>
  9487. /// <param name="modbusClient">modbus对象</param>
  9488. /// <param name="pLCReadDatas">读取到的数据字典</param>
  9489. /// <param name="pLCWriteDatas">需要写入的数据</param>
  9490. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas, ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  9491. {
  9492. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  9493. {
  9494. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  9495. for (int i = 0; i < pLCWriteDatas.Count; i++)
  9496. {
  9497. string mesFlagName = pLCWriteDatas[i].Name;
  9498. int mesFlagAdress = pLCWriteDatas[i].Adress;
  9499. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  9500. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  9501. {
  9502. // 先回写数据
  9503. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  9504. for (int j = 0; j < writeToPLCDatas.Count; j++)
  9505. {
  9506. int mesDataAdress = writeToPLCDatas[j].Adress;
  9507. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  9508. switch (mesDataType)
  9509. {
  9510. case PLCValueType.Short:
  9511. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  9512. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  9513. break;
  9514. case PLCValueType.String:
  9515. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  9516. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  9517. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr, mesDataValueStrLength);
  9518. break;
  9519. }
  9520. }
  9521. // 再回写信号
  9522. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  9523. // 存储读取数据的字典
  9524. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  9525. // 存储写入数据的字典 - 清空写入值
  9526. pLCWriteDatas[i].Value = (short)0;
  9527. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  9528. }
  9529. }
  9530. }
  9531. }
  9532. /// <summary>
  9533. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  9534. /// </summary>
  9535. /// <param name="no">3</param>
  9536. /// <param name="stationCode">设备编号</param>
  9537. /// <param name="stationNameStr">设备名称</param>
  9538. /// <param name="plcOrder">车间订单号</param>
  9539. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  9540. {
  9541. try
  9542. {
  9543. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  9544. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  9545. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  9546. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  9547. int result1 = 0;
  9548. switch (stationCode)
  9549. {
  9550. case 2:
  9551. case 3:
  9552. case 4:
  9553. case 6:
  9554. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  9555. break;
  9556. case 102:
  9557. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  9558. break;
  9559. case 103:
  9560. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  9561. break;
  9562. case 104:
  9563. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  9564. break;
  9565. case 106:
  9566. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  9567. break;
  9568. default:
  9569. // MES_Flag 为“6未找到正确设备编号”
  9570. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  9571. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  9572. return;
  9573. }
  9574. short result = result1 == 1 ? (short)1 : (short)2;
  9575. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  9576. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  9577. }
  9578. catch (Exception ex)
  9579. {
  9580. // MES_Flag 为2上位机报错
  9581. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  9582. string str = ex.StackTrace;
  9583. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9584. }
  9585. }
  9586. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  9587. #region UI刷新
  9588. /// <summary>
  9589. /// 更新商品信息的UI + 下发产品信息(SN)
  9590. /// </summary>
  9591. private void UpdateProductInfo()
  9592. {
  9593. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  9594. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  9595. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  9596. //txt_CurSupplierCode.Text = ""; // 供应商代号
  9597. }
  9598. /// <summary>
  9599. /// 更新PLC连接状态的UI
  9600. /// </summary>
  9601. /// <param name="no">PLC编号</param>
  9602. /// <param name="status">状态</param>
  9603. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  9604. {
  9605. if (this != null && !this.IsDisposed)
  9606. {
  9607. switch (imgNo)
  9608. {
  9609. case 1:
  9610. this.BeginInvoke(new Action(() =>
  9611. {
  9612. picPLC.Image = imageListState.Images[status];
  9613. }));
  9614. break;
  9615. case 2:
  9616. this.BeginInvoke(new Action(() =>
  9617. {
  9618. pictureBox2.Image = imageListState.Images[status];
  9619. }));
  9620. break;
  9621. case 3:
  9622. this.BeginInvoke(new Action(() =>
  9623. {
  9624. pictureBox3.Image = imageListState.Images[status];
  9625. }));
  9626. break;
  9627. case 4:
  9628. this.BeginInvoke(new Action(() =>
  9629. {
  9630. pictureBox4.Image = imageListState.Images[status];
  9631. }));
  9632. break;
  9633. case 5:
  9634. this.BeginInvoke(new Action(() =>
  9635. {
  9636. pictureBox5.Image = imageListState.Images[status];
  9637. }));
  9638. break;
  9639. case 6:
  9640. this.BeginInvoke(new Action(() =>
  9641. {
  9642. pictureBox6.Image = imageListState.Images[status];
  9643. }));
  9644. break;
  9645. case 7:
  9646. this.BeginInvoke(new Action(() =>
  9647. {
  9648. pictureBox7.Image = imageListState.Images[status];
  9649. }));
  9650. break;
  9651. case 8:
  9652. this.BeginInvoke(new Action(() =>
  9653. {
  9654. pictureBox8.Image = imageListState.Images[status];
  9655. }));
  9656. break;
  9657. default:
  9658. break;
  9659. }
  9660. }
  9661. Task.Run(() => // 更新PLC交互页的指示灯
  9662. {
  9663. try
  9664. {
  9665. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9666. {
  9667. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  9668. }
  9669. }
  9670. catch { }
  9671. });
  9672. }
  9673. #endregion UI刷新
  9674. #region 日志
  9675. /// <summary>
  9676. /// 添加各工位运行日志(同步至PLC交互页面)
  9677. /// </summary>
  9678. /// <param name="stationNameStr">工站名称</param>
  9679. /// <param name="logType">日志类型</param>
  9680. /// <param name="message">日志内容</param>
  9681. /// <param name="snNumber">产品数字SN</param>
  9682. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  9683. {
  9684. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")
  9685. && (message.Contains("更新整线运行数据完毕") || message.Contains("更新整线报警数据完毕"))
  9686. ))
  9687. {
  9688. AddMessage(logType, message); // 首页展示+日志记录
  9689. }
  9690. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  9691. {
  9692. StationName = stationNameStr,
  9693. SnNumber = snNumber,
  9694. Message = message,
  9695. CreateTime = DateTime.Now
  9696. };
  9697. // PLC交互页展示
  9698. Task.Run(() =>
  9699. {
  9700. try
  9701. {
  9702. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9703. {
  9704. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  9705. }
  9706. }
  9707. catch { }
  9708. });
  9709. }
  9710. /// <summary>
  9711. /// 添加运行日志
  9712. /// </summary>
  9713. /// <param name="logType">日志类型</param>
  9714. /// <param name="message">日志内容</param>
  9715. public void AddMessage(LogType logType, string message)
  9716. {
  9717. OnMessage(logType, message);
  9718. string date = DateTime.Now.ToString("yyyy/MM/dd");
  9719. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  9720. string msgShow = time + "--> " + message + "\r\n";
  9721. this.BeginInvoke(new Action(() =>
  9722. {
  9723. systemLog.Rows.Insert(0, date, time, message);
  9724. if (systemLog.Rows.Count >= 100)
  9725. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  9726. }));
  9727. }
  9728. /// <summary>
  9729. /// 添加运行日志-保存
  9730. /// </summary>
  9731. /// <param name="logType">日志类型</param>
  9732. /// <param name="message">日志内容</param>
  9733. private void OnMessage(LogType logType, string msg)
  9734. {
  9735. MessageEvent?.Invoke(logType, msg);
  9736. }
  9737. /// <summary>
  9738. /// 保存PLC写入日志
  9739. /// </summary>
  9740. /// <param name="logType"></param>
  9741. /// <param name="logValue"></param>
  9742. private void WritePLCLog(LogType logType, string logValue)
  9743. {
  9744. switch ((int)logType)
  9745. {
  9746. case 0:
  9747. _PLCLogNet.WriteDebug(logValue);
  9748. break;
  9749. case 1:
  9750. _PLCLogNet.WriteInfo(logValue);
  9751. break;
  9752. case 2:
  9753. _PLCLogNet.WriteWarn(logValue);
  9754. break;
  9755. case 3:
  9756. _PLCLogNet.WriteError(logValue);
  9757. break;
  9758. default:
  9759. _PLCLogNet.WriteFatal(logValue);
  9760. break;
  9761. }
  9762. }
  9763. /// <summary>
  9764. /// IOT Mqtt回调方法- With DataId
  9765. /// </summary>
  9766. /// <param name="id"></param>
  9767. /// <param name="v"></param>
  9768. /// <param name="dataId"></param>
  9769. public void CallbackWithDataId(string id, string msg, string dataId)
  9770. {
  9771. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  9772. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  9773. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  9774. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  9775. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  9776. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9777. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  9778. }
  9779. /// <summary>
  9780. /// AGV Mqtt回调方法- 记录Log并处理数据
  9781. /// </summary>
  9782. /// <param name="obj"></param>
  9783. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  9784. {
  9785. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9786. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  9787. // 接收到的信息
  9788. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  9789. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  9790. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  9791. {
  9792. }
  9793. }
  9794. #endregion 日志
  9795. /// <summary>
  9796. /// 实例化报警字典
  9797. /// </summary>
  9798. private void InitalDicAlarm()
  9799. {
  9800. #region 第一个工站(这里未区分工位,所以下面出现的‘工位代码’使用‘线别代码’代替)
  9801. List<Alarm> keyValues1 = new List<Alarm>
  9802. {
  9803. #region 第一组报警(电机)
  9804. new Alarm { 报警类型 = "电机故障", 报警详情 = "料盘搬运_Y轴电机故障" ,关联的PLC地址 = 5100 },
  9805. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_X轴电机故障" ,关联的PLC地址 = 5101 },
  9806. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_Z轴电机故障" ,关联的PLC地址 = 5102 },
  9807. new Alarm { 报警类型 = "电机故障", 报警详情 = "载具搬运_X轴电机故障" ,关联的PLC地址 = 5103 },
  9808. new Alarm { 报警类型 = "电机故障", 报警详情 = "镭射_X轴电机故障" ,关联的PLC地址 = 5104 },
  9809. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_X轴电机故障" ,关联的PLC地址 = 5105 },
  9810. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_Z轴电机故障" ,关联的PLC地址 = 5106 },
  9811. new Alarm { 报警类型 = "电机故障", 报警详情 = "下相机_X轴电机故障" ,关联的PLC地址 = 5107 },
  9812. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_Y轴电机故障" ,关联的PLC地址 = 5108 },
  9813. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_X轴电机故障" ,关联的PLC地址 = 5109 },
  9814. #endregion 第一组报警(电机)
  9815. #region 第二组报警(气缸)
  9816. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料进退气缸故障" ,关联的PLC地址 = 5200 },
  9817. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料升降气缸故障" ,关联的PLC地址 = 5201 },
  9818. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓顶升气缸故障" ,关联的PLC地址 = 5202 },
  9819. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体取料夹爪气缸故障" ,关联的PLC地址 = 5203 },
  9820. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料仓顶升气缸故障" ,关联的PLC地址 = 5204 },
  9821. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料平移气缸故障" ,关联的PLC地址 = 5205 },
  9822. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料升降气缸故障" ,关联的PLC地址 = 5206 },
  9823. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料夹爪气缸故障" ,关联的PLC地址 = 5207 },
  9824. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料旋转气缸故障" ,关联的PLC地址 = 5208 },
  9825. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装平移气缸故障" ,关联的PLC地址 = 5209 },
  9826. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装升降气缸故障" ,关联的PLC地址 = 5210 },
  9827. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装夹爪气缸故障" ,关联的PLC地址 = 5211 },
  9828. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装撑开气缸故障" ,关联的PLC地址 = 5212 },
  9829. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸1故障" ,关联的PLC地址 = 5213 },
  9830. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸2故障" ,关联的PLC地址 = 5214 },
  9831. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具下料移载气缸故障" ,关联的PLC地址 = 5215 },
  9832. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具侧推气缸故障" ,关联的PLC地址 = 5216 },
  9833. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具回流气缸故障" ,关联的PLC地址 = 5217 },
  9834. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2压料气缸故障" ,关联的PLC地址 = 5218 },
  9835. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2电测气缸故障" ,关联的PLC地址 = 5219 },
  9836. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2气密气缸故障" ,关联的PLC地址 = 5220 },
  9837. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3下压气缸故障" ,关联的PLC地址 = 5221 },
  9838. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3上顶气缸故障" ,关联的PLC地址 = 5222 },
  9839. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位5相机升降气缸故障" ,关联的PLC地址 = 5223 },
  9840. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组升降气缸故障" ,关联的PLC地址 = 5224 },
  9841. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸1故障" ,关联的PLC地址 = 5225 },
  9842. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸2故障" ,关联的PLC地址 = 5226 },
  9843. new Alarm { 报警类型 = "气缸故障", 报警详情 = "机械手夹爪气缸故障" ,关联的PLC地址 = 5227 },
  9844. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位4:镭射压料气缸故障" ,关联的PLC地址 = 5228 },
  9845. #endregion 第二组报警(气缸)
  9846. #region 第三组报警(其他故障)
  9847. new Alarm { 报警类型 = "其他故障", 报警详情 = "上料处缺料报警" ,关联的PLC地址 = 5300 },
  9848. new Alarm { 报警类型 = "其他故障", 报警详情 = "震盘缺料报警" ,关联的PLC地址 = 5301 },
  9849. new Alarm { 报警类型 = "其他故障", 报警详情 = "成品仓料满报警" ,关联的PLC地址 = 5302 },
  9850. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照超时报警" ,关联的PLC地址 = 5303 },
  9851. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照NG报警" ,关联的PLC地址 = 5304 },
  9852. new Alarm { 报警类型 = "其他故障", 报警详情 = "玻璃门打开报警" ,关联的PLC地址 = 5305 },
  9853. #endregion 第三组报警(其他故障)
  9854. };
  9855. DicAlarms_Cur.Add(GlobalContext.LineCode, keyValues1); // 这里使用线体代替工位
  9856. #endregion 第一个工站(这里使用线体代替工位)
  9857. # region 第二个工站-原来的写法(废弃)
  9858. //keyValues = new Dictionary<int, AlarmData[]>();
  9859. ////1
  9860. //dicAlarmName = new Dictionary<int, Alarm>();
  9861. //dicAlarmName.Add(0, new Alarm { Name = "M01衬套组模组X电机报警" });
  9862. //dicAlarmName.Add(1, new Alarm { Name = "M02衬套组模组Y电机报警" });
  9863. //dicAlarmName.Add(2, new Alarm { Name = "M03衬套组模组Z电机报警" });
  9864. //dicAlarmName.Add(3, new Alarm { Name = "M04衬套组模组U电机报警" });
  9865. //dicAlarmName.Add(4, new Alarm { Name = "M05外流线皮带电机报警" });
  9866. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9867. //for (int i = 0; i < dicAlarmName.Count; i++)
  9868. //{
  9869. // alarmDatas[i] = new AlarmData();
  9870. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9871. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9872. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9873. // alarmDatas[i].AlarmType = 1;
  9874. //}
  9875. //keyValues.Add(1, alarmDatas);
  9876. ////2
  9877. //dicAlarmName = new Dictionary<int, Alarm>();
  9878. //dicAlarmName.Add(0, new Alarm { Name = "C01定位气缸故障" });
  9879. //dicAlarmName.Add(1, new Alarm { Name = "C02左推料气缸故障" });
  9880. //dicAlarmName.Add(2, new Alarm { Name = "C03右推料气缸故障" });
  9881. //dicAlarmName.Add(3, new Alarm { Name = "C04左压料气缸故障" });
  9882. //dicAlarmName.Add(4, new Alarm { Name = "C05右压料气缸故障" });
  9883. //dicAlarmName.Add(5, new Alarm { Name = "C06切料气缸故障" });
  9884. //dicAlarmName.Add(6, new Alarm { Name = "C07左入料吹气气缸故障" });
  9885. //dicAlarmName.Add(7, new Alarm { Name = "C08右入料吹气气缸故障" });
  9886. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9887. //for (int i = 0; i < dicAlarmName.Count; i++)
  9888. //{
  9889. // alarmDatas[i] = new AlarmData();
  9890. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9891. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9892. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9893. // alarmDatas[i].AlarmType = 2;
  9894. //}
  9895. //keyValues.Add(2, alarmDatas);
  9896. ////3
  9897. //dicAlarmName = new Dictionary<int, Alarm>();
  9898. //dicAlarmName.Add(0, new Alarm { Name = "安全门报警" });
  9899. //dicAlarmName.Add(1, new Alarm { Name = "联机通信故障" });
  9900. //dicAlarmName.Add(2, new Alarm { Name = "连续NG报警" });
  9901. //dicAlarmName.Add(3, new Alarm { Name = "合格率低于设定值报警" });
  9902. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9903. //for (int i = 0; i < dicAlarmName.Count; i++)
  9904. //{
  9905. // alarmDatas[i] = new AlarmData();
  9906. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-3";
  9907. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9908. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9909. // alarmDatas[i].AlarmType = 3;
  9910. //}
  9911. //keyValues.Add(3, alarmDatas);
  9912. //DicAlarms.Add(2, keyValues);
  9913. #endregion 第二个工站-原来的写法(废弃)
  9914. }
  9915. }
  9916. }