Form_Home.cs 577 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919
  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. int qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer(addr, port, GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
  252. XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult;
  253. if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
  254. {
  255. picIot.Image = imageListState.Images[1];
  256. AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
  257. XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
  258. }
  259. else
  260. {
  261. picIot.Image = imageListState.Images[0];
  262. AddMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
  263. }
  264. }
  265. // 开启AGV(Http与MQTT)
  266. if (GlobalContext.IsUseAGV)
  267. {
  268. // AGV HTTP
  269. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  270. if (mesret1)
  271. {
  272. picAgvHttp.Image = imageListState.Images[1];
  273. AddMessage(LogType.Info, "AGV Http初始连接成功!");
  274. }
  275. else
  276. {
  277. picAgvHttp.Image = imageListState.Images[0];
  278. AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
  279. }
  280. string agvMqttIp = GlobalContext.MQTTServerHost;
  281. int agvMqttPort = GlobalContext.MQTTServerPort;
  282. Action<ResultData_MQTT> callback = AGVMqttShowLog;
  283. ResultData_MQTT result_MQTT = _MQTTHelper.CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
  284. // AGV MQTT
  285. if (result_MQTT.ResultCode == 1)
  286. {
  287. picAgvMqtt.Image = imageListState.Images[1];
  288. GlobalContext.AGVMQTTIsConnect = true;
  289. AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
  290. ResultData_MQTT result = XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
  291. AddMessage(LogType.Info, $"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
  292. }
  293. else
  294. {
  295. picAgvMqtt.Image = imageListState.Images[0];
  296. GlobalContext.AGVMQTTIsConnect = false;
  297. AddMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
  298. }
  299. }
  300. // 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
  301. Task.Run(MonitorMESConnect);
  302. // 查询PLC连接状态
  303. foreach (int plcNo in FunsEip.Keys)
  304. {
  305. bool connected = FunsEip[plcNo].IsConnected;
  306. if (connected)
  307. {
  308. string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
  309. AddMessage(LogType.Info, msg);
  310. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
  311. }
  312. else
  313. {
  314. string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
  315. AddMessage(LogType.Info, msg);
  316. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  317. }
  318. }
  319. // PLC4时 初始化扫码器TCP
  320. //if (GlobalContext.IsUsePLC4)
  321. // HpTCPClientInit();
  322. // 开启PLC的业务处理线程-监听PLC点位+状态
  323. foreach (Task task in TaskReadProcess)
  324. {
  325. if (task != null)
  326. task.Start();
  327. }
  328. //// 开启“获取线体报警数据”的线程
  329. //TaskReadAlarm.Start();
  330. ////下传MES信息给1工位(先判断下plc对象数量)
  331. //if (Funs.Count > 1)
  332. // DownLoadProductInfo(1);
  333. AddMessage(LogType.Info, "程序初始化完成");
  334. }
  335. catch (Exception ex)
  336. {
  337. string str = ex.StackTrace;
  338. this.BeginInvoke(new Action(() =>
  339. {
  340. AddMessage(LogType.Error, "初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  341. }));
  342. }
  343. #endregion
  344. }
  345. catch (Exception ex)
  346. {
  347. string str = ex.StackTrace;
  348. OnMessage(LogType.Info, "主窗体的首页初始化出错!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  349. if (ex.Message != null && ex.Message.Contains("timed out"))
  350. MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
  351. else
  352. MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
  353. }
  354. }
  355. /// <summary>
  356. /// 窗体关闭事件
  357. /// </summary>
  358. private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
  359. {
  360. Closed2();
  361. }
  362. public void Closed2()
  363. {
  364. try
  365. {
  366. IsRun = false;
  367. Thread.Sleep(IntervalReadPLC);
  368. // 断开TCP
  369. int count = _HPSocket_TcpClients.Count();
  370. for (int i = 0; i < count; i++)
  371. {
  372. try
  373. {
  374. if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
  375. {
  376. _HPSocket_TcpClients[i].Stop();
  377. _HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
  378. _HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
  379. _HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
  380. _HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
  381. _HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
  382. }
  383. }
  384. catch { }
  385. }
  386. // 关闭Iot
  387. try { XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath, GlobalContext.MqttServerName); } catch { }
  388. // 关闭AGV Mqtt
  389. try { _MQTTHelper.DisconnectAsync_Client().Wait(); } catch { }
  390. }
  391. catch { }
  392. }
  393. #endregion 窗体基础事件
  394. #region 监控MES状态
  395. /// <summary>
  396. /// 监控MES连接状态
  397. /// </summary>
  398. private void MonitorMESConnect()
  399. {
  400. while (IsRun) // 运行被控线程
  401. {
  402. try
  403. {
  404. // 开启MES(Http)
  405. if (GlobalContext.IsUseMES)
  406. {
  407. bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
  408. if (mesret)
  409. {
  410. picMESStatus.Image = imageListState.Images[1];
  411. GlobalContext.MESIsConnect = true;
  412. }
  413. else
  414. {
  415. picMESStatus.Image = imageListState.Images[0];
  416. GlobalContext.MESIsConnect = false;
  417. OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
  418. }
  419. }
  420. // 开启IOT(MQTT)
  421. if (GlobalContext.IsUseIot)
  422. {
  423. bool iIot = XiaomiMqttClient.IsOpen;
  424. if (iIot)
  425. picIot.Image = imageListState.Images[1];
  426. else
  427. {
  428. picIot.Image = imageListState.Images[0];
  429. OnMessage(LogType.Info, $"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
  430. }
  431. }
  432. // 开启AGV(Http与MQTT)
  433. if (GlobalContext.IsUseAGV)
  434. {
  435. // AGV Http
  436. bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
  437. if (mesret1)
  438. picAgvHttp.Image = imageListState.Images[1];
  439. else
  440. {
  441. picAgvHttp.Image = imageListState.Images[0];
  442. OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
  443. }
  444. // AGV MQTT
  445. if (GlobalContext.AGVMQTTIsConnect)
  446. picAgvMqtt.Image = imageListState.Images[1];
  447. else
  448. {
  449. picAgvMqtt.Image = imageListState.Images[0];
  450. OnMessage(LogType.Info, $"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
  451. }
  452. }
  453. }
  454. catch (Exception ex)
  455. {
  456. string str = ex.StackTrace;
  457. AddMessage(LogType.Error, "监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  458. }
  459. Thread.Sleep(IntervalMonitorMES);
  460. }
  461. }
  462. #endregion 监控MES连接状态
  463. #region 采集设备状态、运行数据、报警数据
  464. /// <summary>
  465. /// 请求设备状态 5000
  466. /// </summary>
  467. /// <param name="no">1</param>
  468. /// <param name="stationNameStr"></param>
  469. /// <returns>0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;</returns>
  470. public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
  471. {
  472. try
  473. {
  474. if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  475. {
  476. short result = Funs[plcNo].ReadHoldingRegisters<short>(5000); // 5000
  477. return result;
  478. }
  479. else
  480. {
  481. return 0;
  482. }
  483. }
  484. catch (Exception ex)
  485. {
  486. string str = ex.StackTrace;
  487. AddMessage_Station(stationNameStr, LogType.Error, "请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  488. return 0;
  489. }
  490. }
  491. /// <summary>
  492. /// 检查是否可采集点检数据 - 不取新值
  493. /// 5000不为1时可点检
  494. /// </summary>
  495. /// <returns></returns>
  496. public bool CheckCanSpotcheck1(int deviceState)
  497. {
  498. //return true;
  499. //D5000 = 1,代表设备控制状态处于运行状态
  500. //D5000 = 2, 代表设备控制状态处于故障状态
  501. //D5000 = 3,代表设备控制状态处于缺料状态
  502. //D5000 = 4, 代表设备控制状态处于待机状态
  503. //D5000 = 5,代表设备控制状态处于维修状态
  504. return deviceState != 1;
  505. }
  506. /// <summary>
  507. /// 检查是否可采集产品数据 - 不取新值
  508. /// </summary>
  509. /// <returns></returns>
  510. public bool CheckCanCollData(int deviceState)
  511. {
  512. return deviceState == 0; // 点检时该值不为0
  513. }
  514. /// <summary>
  515. /// 获取设备报警数据与获取设备运行信息
  516. /// </summary>
  517. private async void ReadAlarmAllPLC()
  518. {
  519. // [S1] Tray盘上料装备(板测)
  520. // [S2] FCT(板测)
  521. // [S3] 值板机
  522. // [S4] 取放桁架
  523. // [S5] Tray盘下料装备
  524. /// 上位机心跳
  525. /// 获取设备报警数据与状态信息
  526. string stationNameStr = "获取设备报警数据与状态信息";
  527. while (IsRun)
  528. {
  529. try
  530. {
  531. if (!GlobalContext._IsCon_plc1Alarm)
  532. {
  533. UpdatePLCMonitor(1, -2, 0);
  534. continue;
  535. }
  536. if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
  537. {
  538. DateTime dtNow = DateTime.Now;
  539. #region 获取设备运行信息
  540. try
  541. {
  542. LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
  543. lineWorkingData1.GUID = Guid.NewGuid().ToString();
  544. lineWorkingData1.LineName = GlobalContext.LineCode;
  545. //
  546. lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5500); // 本次开机时间(整线)D5500 h
  547. lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5502); // 本次开机运行时间(整线)D5502 h
  548. lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5504); // 本次开机待机时间(整线)D5504 h
  549. lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5506); // 本次开机故障时间(整线)D5506 h
  550. lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5508); // 本次开机缺料时间(整线)D5508 h
  551. lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters<float>(5510); // 本次开机维修时间(整线)D5510 h
  552. lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters<short>(5514); // 本次开机故障停机次数(整线)D5514
  553. lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters<short>(5700); // 本次开机产量(整线) D5700
  554. lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters<short>(5704); // 本次开机合格数量(整线) D5704
  555. lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters<float>(5710); // 本次开机合格率(整线) D5710
  556. lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters<float>(5714); // 设计节拍(整线) D5714
  557. lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters<float>(5716); // 本次开机实际节拍(整线) D5716
  558. lineWorkingData1.CreateTime = DateTime.Now;
  559. string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
  560. // UI展示-展示到设备状态页
  561. if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
  562. {
  563. // 查询数据库最新一条数据,确定是不是更新
  564. string qSql = @"SELECT top(1) [GUID]
  565. ,[LineName]
  566. ,[BootTimeLong]
  567. ,[NormalTimeLong]
  568. ,[StandbyTimeLong]
  569. ,[FaultTimeLong]
  570. ,[MaterialShortageTimeLong]
  571. ,[MaintenanceTimeLong]
  572. ,[FaultNumber]
  573. ,[OutputNumber]
  574. ,[QualifiedNumber]
  575. ,[QualifiedRate]
  576. ,[DesignRhythm]
  577. ,[RealityRhythm]
  578. ,[CreateTime]
  579. FROM [LineWorkingData]
  580. where [CreateTime] > '{0}'
  581. and [LineName]='{1}'
  582. order by [CreateTime] desc
  583. ";
  584. qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
  585. var ds = SQLHelper_New.Query(qSql, null);
  586. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  587. {
  588. var dataDBlast = new LineWorkingData_ThisTime();
  589. dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
  590. dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
  591. dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
  592. dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
  593. if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
  594. {
  595. dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  596. dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  597. dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  598. dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  599. dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  600. dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  601. dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  602. dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  603. dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  604. dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  605. dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  606. dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  607. string usql = dataDBlast.ToStringUpdate();
  608. SQLHelper_New.ExecuteSQL(usql, null);
  609. lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
  610. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  611. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  612. }
  613. }
  614. else
  615. {
  616. // 插入
  617. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  618. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  619. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  620. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  621. }
  622. }
  623. else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
  624. {
  625. LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject<LineWorkingData_ThisTime>(lineWorkingData1_OldStr); // 上次的状态信息
  626. //// 本次开机设备运行情况
  627. //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject<LineWorkingData1_ThisTime>(lineWorkingData1_OldStr);
  628. //Task.Run(() =>
  629. //{
  630. // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  631. // {
  632. // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
  633. // }
  634. //});
  635. // 本日设备运行情况
  636. // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
  637. if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
  638. {
  639. // 更新
  640. lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
  641. lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
  642. lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
  643. lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
  644. lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
  645. lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
  646. lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
  647. lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
  648. lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
  649. lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
  650. lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
  651. lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
  652. SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
  653. lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
  654. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  655. //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
  656. }
  657. else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
  658. {
  659. // 插入
  660. SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
  661. lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
  662. AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
  663. //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
  664. }
  665. await Task.Run(() =>
  666. {
  667. try
  668. {
  669. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
  670. {
  671. Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
  672. }
  673. }
  674. catch { }
  675. });
  676. }
  677. }
  678. catch (Exception ex)
  679. {
  680. string str = ex.StackTrace;
  681. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  682. }
  683. #endregion 获取设备运行信息
  684. #region 报警数据
  685. try
  686. {
  687. List<DeviceAlarm_Cur> deviceAlarm_Curs = new List<DeviceAlarm_Cur>(); // 同步到报警页面用传输载体
  688. bool isNeedUpdUI = false; // 是否需要更新历史报警UI
  689. // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
  690. var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
  691. for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
  692. {
  693. short shortBuf = plc1Alarm.ReadHoldingRegisters<short>(dicAlarms_Cur_PLC1[i].关联的PLC地址);
  694. dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
  695. if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
  696. {
  697. isNeedUpdUI = true; // 需要更新历史报警UI信息
  698. // 记录
  699. dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
  700. switch (dicAlarms_Cur_PLC1[i].是否报警)
  701. {
  702. case true: // 报警
  703. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  704. {
  705. GUID = Guid.NewGuid().ToString(),
  706. LineName = GlobalContext.LineCode, // 线体
  707. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  708. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  709. StartTime = dtNow // 开始时间
  710. };
  711. // 传输到页面
  712. deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
  713. {
  714. 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
  715. 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
  716. 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
  717. 开始时间 = dtNow
  718. });
  719. // 新增到数据库
  720. var data1 = dicAlarms_Cur_PLC1[i].报警数据;
  721. SaveAlarmDataByDB(stationNameStr, data1, false);
  722. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  723. break;
  724. case false: // 消除报警
  725. if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
  726. {
  727. dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
  728. {
  729. GUID = Guid.NewGuid().ToString(),
  730. LineName = GlobalContext.LineCode, // 线体
  731. AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
  732. AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
  733. StartTime = dtNow, // 开始时间
  734. EndTime = dtNow, // 开始时间
  735. PersistTime = 1, // 耗时1s
  736. };
  737. // 新增
  738. var data2 = dicAlarms_Cur_PLC1[i].报警数据;
  739. SaveAlarmDataByDB(stationNameStr, data2, false);
  740. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  741. }
  742. else
  743. {
  744. dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
  745. dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
  746. - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
  747. // 修改
  748. var data3 = dicAlarms_Cur_PLC1[i].报警数据;
  749. SaveAlarmDataByDB(stationNameStr, data3, true);
  750. AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
  751. }
  752. break;
  753. default:
  754. break;
  755. }
  756. }
  757. }
  758. DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
  759. // 有新报警则更新
  760. if (isNeedUpdUI)
  761. {
  762. // UI展示 - 展示到设备状态页
  763. await Task.Run(() =>
  764. {
  765. try
  766. {
  767. if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
  768. {
  769. Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
  770. if (Form_Main.formDevAlarm.Visible)
  771. {
  772. Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
  773. }
  774. }
  775. }
  776. catch { }
  777. });
  778. }
  779. }
  780. catch (Exception ex)
  781. {
  782. string str = ex.StackTrace;
  783. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  784. }
  785. #endregion 报警数据
  786. UpdatePLCMonitor(1, -2, 1);
  787. }
  788. else
  789. {
  790. UpdatePLCMonitor(1, -2, 0);
  791. }
  792. }
  793. catch (Exception ex)
  794. {
  795. AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  796. }
  797. Thread.Sleep(IntervalAlarm);
  798. }
  799. }
  800. #endregion 轮询PLC
  801. #region 下发订单信息
  802. ///// <summary>
  803. ///// 壳体上料(下发工单)的交互逻辑
  804. ///// </summary>
  805. ///// <param name="no"></param>
  806. ///// <exception cref="NotImplementedException"></exception>
  807. //private void ReadStation_DownOrderInfo(int plcNo)
  808. //{
  809. // // [S1] Tray盘上料装备(板测)
  810. // // [S2] FCT(板测)
  811. // // [S3] 值板机
  812. // // [S4] 取放桁架
  813. // // [S5] Tray盘下料装备
  814. // /// 上位机心跳
  815. // /// 获取设备报警数据与状态信息
  816. // string stationNameStr = "[S0]壳体上料";
  817. // while (IsRun)
  818. // {
  819. // try
  820. // {
  821. // if (!GlobalContext._IsCon_Funs1)
  822. // {
  823. // UpdatePLCMonitor(plcNo, 0);
  824. // continue;
  825. // }
  826. // if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
  827. // {
  828. // #region 壳体上料(下发工单)
  829. // try
  830. // {
  831. // Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
  832. // Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
  833. // bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
  834. // bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
  835. // // 重置数据和信号
  836. // if (mES_FLAG_1 && pLC_Flag_1) // 1 1
  837. // {
  838. // // 清空写给PLC的数据
  839. // int[] i497 = new int[1] { 0 };
  840. // Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
  841. // // MES_Flag重置为0
  842. // int[] i500 = new int[1] { 0 };
  843. // Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
  844. // }
  845. // }
  846. // catch (Exception ex)
  847. // {
  848. // string str = ex.StackTrace;
  849. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  850. // }
  851. // #endregion 壳体上料(下发工单)
  852. // UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  853. // }
  854. // else
  855. // {
  856. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  857. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  858. //
  859. // Funs[plcNo].Connect();
  860. // }
  861. // }
  862. // catch (Exception ex)
  863. // {
  864. // UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
  865. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  866. //
  867. // Funs[plcNo].ReConnect();
  868. // }
  869. // Thread.Sleep(IntervalReadPLC);
  870. // }
  871. //}
  872. ///// <summary>
  873. ///// 下发订单信息到PLC
  874. ///// </summary>
  875. ///// <param name="no">PLC编号</param>
  876. //private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
  877. //{
  878. // try
  879. // {
  880. // if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
  881. // {
  882. // Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
  883. // WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
  884. // }
  885. // Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
  886. // }
  887. // catch (Exception ex)
  888. // {
  889. // string str = ex.StackTrace;
  890. // AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  891. // }
  892. //}
  893. /// <summary>
  894. /// 下发清料信号
  895. /// </summary>
  896. /// <param name="no">PLC编号</param>
  897. public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
  898. {
  899. try
  900. {
  901. //Funs[plcNo].ReadHoldingRegisters<int>(496); //
  902. AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
  903. return true;
  904. }
  905. catch (Exception ex)
  906. {
  907. string str = ex.StackTrace;
  908. AddMessage_Station(stationNameStr, LogType.Error, "下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  909. return false;
  910. }
  911. }
  912. #endregion 下发订单信息
  913. #region Xiaomi 贲流
  914. #region 公共方法
  915. private static bool ProgressState = false;
  916. private static readonly object lockObj = new object(); // 锁对象
  917. private static bool isCollectingFlagLeft;
  918. private static bool isCollectingFlagRight;
  919. /// <summary>
  920. /// float[]转为string
  921. /// </summary>
  922. public string FloatArrayToString(float[] nScrewResults)
  923. {
  924. // 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
  925. return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
  926. }
  927. /// <summary>
  928. /// short[]转为string
  929. /// </summary>
  930. public string ShortArrayToString(short[] nScrewResults)
  931. {
  932. // 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
  933. return string.Join(",", nScrewResults);
  934. }
  935. /// <summary>
  936. /// 写入PLC重复三次
  937. /// </summary>
  938. public (int, string) WriteResultToPlc<T>(int plcNo, string stationNameStr, string strTagName, int nCount, T inObj)
  939. {
  940. int i = 0;
  941. int nRet = 0;
  942. string strRet = "";
  943. try
  944. {
  945. while (i < 3) // 最多上传三次
  946. {
  947. (nRet, strRet) = FunsEip[plcNo].Write_SingleTag<T>(strTagName, nCount, inObj);
  948. if (nRet == 0) //成功
  949. {
  950. break;
  951. }
  952. else
  953. {
  954. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
  955. i++;
  956. }
  957. }
  958. return (nRet, strRet);
  959. }
  960. catch (Exception ex)
  961. {
  962. return (1, ex.Message);
  963. }
  964. }
  965. public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes, short[] nScrewOrders, short[] nScrewResults)
  966. {
  967. try
  968. {
  969. // 获取当前日期
  970. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  971. // 构建保存路径
  972. string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
  973. string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction,"螺丝Mes数据");
  974. // 确保目录存在
  975. Directory.CreateDirectory(savePath);
  976. // 文件名
  977. string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
  978. string filePath = Path.Combine(savePath, fileName);
  979. // 确保不会超出数组长度,只取前14个或数组的实际长度
  980. int count = Math.Min(14, fScrewTimes.Length);
  981. using (StreamWriter sw = new StreamWriter(filePath))
  982. {
  983. for (int i = 0; i < count; i++)
  984. {
  985. sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
  986. sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
  987. sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
  988. sw.WriteLine($"锁附结果:{nScrewResults[i]}");
  989. sw.WriteLine(); // 空行分隔不同螺丝的信息
  990. }
  991. }
  992. return (0, "");
  993. }
  994. catch (Exception ex)
  995. {
  996. return (1, ex.Message);
  997. }
  998. }
  999. /// <summary>
  1000. /// 调用进站接口并保存进站数据
  1001. /// </summary>
  1002. /// <param name="stationNameStr">工站信息</param>
  1003. /// <param name="workorder_code">工单号</param>
  1004. /// <param name="mtltmrk">型号(物料号)</param>
  1005. /// <param name="sn">产品SN</param>
  1006. /// <param name="items">进站数据</param>
  1007. /// <returns>1成功;5MES报警;6上位机报警</returns>
  1008. public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn, List<TestItem> items, string MachineId, string StationId)
  1009. {
  1010. int result = 0;
  1011. XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
  1012. inRequest_Body.machineId = MachineId; // 装备ID(可配置)
  1013. inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
  1014. inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1015. inRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1016. inRequest_Body.unitSn = sn; // 产品SN
  1017. inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
  1018. inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
  1019. string json_Body = JsonConvert.SerializeObject(inRequest_Body);
  1020. StationIn stationIn = new StationIn()
  1021. {
  1022. Workorder_code = workorder_code, // 车间订单号
  1023. Mtltmrk = mtltmrk, // 产品型号(物料号)
  1024. Sn = sn, // SN
  1025. StationIn_body = json_Body, // 进站接口Json数据 - Body
  1026. Parameter_values = items, // 进站数据
  1027. Write_user = inRequest_Body.userId, // 员工Id
  1028. Test_time = inRequest_Body.clientTime // 进站时间
  1029. };
  1030. // 本地数据
  1031. string sql = stationIn.ToStringInsert(0);
  1032. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1033. result = ret == "成功" ? 1 : 6;
  1034. //await Task.Delay(200);
  1035. // 上传MES
  1036. if (GlobalContext.IsSendStationIn)
  1037. {
  1038. try
  1039. {
  1040. XmMES_StationInResponse response = new XmMES_StationInResponse();
  1041. string mesRet = string.Empty;
  1042. int i = 0;
  1043. while (i < 2) // 1009会多次尝试上传
  1044. {
  1045. response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
  1046. if (response != null && response.header.code == "200")
  1047. break;
  1048. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1049. i++;
  1050. i++;
  1051. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1052. // 记录失败原因
  1053. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + json_Body);
  1054. }
  1055. if (response?.header?.code == "200")
  1056. {
  1057. string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
  1058. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1059. result = ret_Upd == "成功" ? 1 : 6;
  1060. AddMessage( LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功");
  1061. }
  1062. else
  1063. {
  1064. result = 5;
  1065. AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
  1066. }
  1067. string sql_response = stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
  1068. SQLHelper_New.ExecuteNonQuery(sql_response, null);
  1069. }
  1070. catch (Exception ex)
  1071. {
  1072. result = 6;
  1073. string str = ex.StackTrace;
  1074. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1075. }
  1076. }
  1077. return result;
  1078. }
  1079. /// <summary>
  1080. /// 选择如何记录出站数据
  1081. /// </summary>
  1082. /// <param name="items">出站数据</param>
  1083. /// <param name="equipmentCode">设备编号</param>
  1084. /// <param name="processItem">测试项目</param>
  1085. /// <param name="workorder_code">车间订单号</param>
  1086. /// <param name="batch_num">批次号</param>
  1087. /// <param name="mtltmrk">型号</param>
  1088. /// <param name="proDate">日期</param>
  1089. /// <param name="supplierCode">供应商代码</param>
  1090. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1091. /// <returns>上传成功时返回1;失败返回0</returns>
  1092. private int SwitctProcessData(string stationNameStr, List<TestItem> items, string equipmentCode, string processItem,
  1093. string workorder_code, string batch_num, string mtltmrk, string proDate,
  1094. string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode)
  1095. {
  1096. return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
  1097. proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode);
  1098. }
  1099. /// <summary>
  1100. /// 添加出站数据(提交到MES+本地保存到数据库)
  1101. /// </summary>
  1102. /// <param name="items">出站数据</param>
  1103. /// <param name="equipmentCode">设备编号</param>
  1104. /// <param name="processItem">测试项目</param>
  1105. /// <param name="workorder_code">车间订单号</param>
  1106. /// <param name="batch_num">批次号</param>
  1107. /// <param name="mtltmrk">型号</param>
  1108. /// <param name="proDate">日期</param>
  1109. /// <param name="supplierCode">供应商代码</param>
  1110. /// <param name="sn_Number">产品序列号的 数字序列部分</param>
  1111. /// <returns>上传成功时返回1;失败返回0</returns>
  1112. public int SaveProcessDataByDB(string stationNameStr, List<TestItem> items, string equipmentCode,
  1113. string processItem, string workorder_code, string batch_num, string mtltmrk,
  1114. string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode)
  1115. {
  1116. int upload = 0;
  1117. int result = 0;
  1118. ProcessData processData = new ProcessData()
  1119. {
  1120. Equipment_code = equipmentCode,
  1121. Workorder_code = workorder_code,
  1122. Batch_number = batch_num,
  1123. Sn = sn, // SN
  1124. Testitem = processItem,
  1125. Parameter_values = items,
  1126. Write_user = GlobalContext.CurrentUser,
  1127. Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  1128. };
  1129. // 本地数据
  1130. string sql = processData.ToStringInsert(upload);
  1131. string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
  1132. //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
  1133. // 上传MES
  1134. if (GlobalContext.IsSendProcessData)
  1135. {
  1136. try
  1137. {
  1138. string id = processData.ID.Copy();
  1139. XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
  1140. outRequest_Body.machineId = machineId; // 装备id(可配置)
  1141. outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
  1142. outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
  1143. outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
  1144. outRequest_Body.unitSn = sn; // 产品SN
  1145. outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
  1146. outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
  1147. outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
  1148. outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
  1149. outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
  1150. outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
  1151. if (!string.IsNullOrEmpty(partBarcode))
  1152. {
  1153. outRequest_Body.unitData.keyMaterial.Add(
  1154. new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
  1155. {
  1156. bindSort = 1,
  1157. materialSn = partBarcode
  1158. }); // 设备数据 - 部件码
  1159. }
  1160. string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
  1161. if (GlobalContext.IsSendProcessData)
  1162. {
  1163. XmMES_StationOutResponse response = new XmMES_StationOutResponse();
  1164. string mesRet = string.Empty;
  1165. int i = 0;
  1166. while (i < 2) // 1009会多次尝试上传
  1167. {
  1168. response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
  1169. if (response != null && response.header.code == "200")
  1170. break;
  1171. else if (!mesRet.Contains("1009")) // 1009是未知错误
  1172. i++;
  1173. i++;
  1174. mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
  1175. // 记录失败原因
  1176. OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
  1177. }
  1178. if (response?.header?.code == "200")
  1179. {
  1180. string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
  1181. string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
  1182. result = 1;
  1183. //AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
  1184. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
  1185. }
  1186. else
  1187. {
  1188. AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:"+ mesRet);
  1189. }
  1190. string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(JsonConvert.SerializeObject(outRequest_Body),
  1191. JsonConvert.SerializeObject(response), id);
  1192. SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
  1193. }
  1194. }
  1195. catch (Exception ex)
  1196. {
  1197. string str = ex.StackTrace;
  1198. AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1199. }
  1200. }
  1201. return result;
  1202. }
  1203. //private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1204. //{
  1205. // Stopwatch stopwatch = new Stopwatch();
  1206. // stopwatch.Start();
  1207. // try
  1208. // {
  1209. // // 初始化 AtlasScrew 实例
  1210. // AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1211. // atlasScrew1.Initial();
  1212. // // 存储结果的列表
  1213. // List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
  1214. // // 存储角度和扭力的字符串列表
  1215. // List<string> angleStrs = new List<string>();
  1216. // List<string> torqueStrs = new List<string>();
  1217. // // 上一次获取的数据
  1218. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1219. // while (isExitAtlasLeft) // 检查是否收集数据
  1220. // {
  1221. // // 获取当前数据
  1222. // var currentResult = atlasScrew1.GetResults();
  1223. // // 判断是否为新数据
  1224. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1225. // {
  1226. // OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1227. // // 更新角度和扭力的字符串列表
  1228. // angleStrs.Add(currentResult.JD_MEAN.ToString());
  1229. // torqueStrs.Add(currentResult.NL_MEAN.ToString());
  1230. // // 计算角度、扭力、起始扭力和最大扭力
  1231. // double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
  1232. // double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
  1233. // double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
  1234. // double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
  1235. // // 将新数据添加到结果列表
  1236. // results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
  1237. // // 更新上一次获取的数据
  1238. // lastResult = currentResult;
  1239. // }
  1240. // // 等待一段时间后再次检查
  1241. // Thread.Sleep(20); // 轮询间隔时间
  1242. // // 如果触发了出站,则退出循环
  1243. // if (!isExitAtlasLeft)
  1244. // {
  1245. // break;
  1246. // }
  1247. // }
  1248. // // 生成文件名
  1249. // string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
  1250. // // 写入数据到文件
  1251. // using (StreamWriter writer = new StreamWriter(fileName))
  1252. // {
  1253. // // 写入标题行
  1254. // writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
  1255. // // 写入每一行数据
  1256. // foreach (var result in results)
  1257. // {
  1258. // writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
  1259. // }
  1260. // }
  1261. // stopwatch.Stop();
  1262. // AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1263. // }
  1264. // catch (Exception ex)
  1265. // {
  1266. // AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1267. // }
  1268. // finally
  1269. // {
  1270. // // 重置标志变量
  1271. // isExitAtlasLeft = false;
  1272. // }
  1273. //}
  1274. //private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
  1275. //{
  1276. // Stopwatch stopwatch = new Stopwatch();
  1277. // stopwatch.Start();
  1278. // try
  1279. // {
  1280. // // 初始化 AtlasScrew 实例
  1281. // AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
  1282. // atlasScrew2.Initial();
  1283. // // 存储结果的列表
  1284. // List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
  1285. // // 上一次获取的数据
  1286. // (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
  1287. // while (isExitAtlasRight) // 检查是否收集数据
  1288. // {
  1289. // // 获取当前数据
  1290. // var currentResult = atlasScrew2.GetResults();
  1291. // // 判断是否为新数据
  1292. // if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
  1293. // {
  1294. // AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1295. // // 将新数据写入PLC
  1296. // //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
  1297. // // 将新数据添加到结果列表
  1298. // results.Add(currentResult);
  1299. // // 更新上一次获取的数据
  1300. // lastResult = currentResult;
  1301. // }
  1302. // // 等待一段时间后再次检查
  1303. // Thread.Sleep(20); // 轮询间隔时间
  1304. // // 如果触发了出站,则退出循环
  1305. // if (!isExitAtlasRight)
  1306. // {
  1307. // break;
  1308. // }
  1309. // }
  1310. // // 将所有数据写入文件
  1311. // //WriteDataToFile(sn, direction, results);
  1312. // stopwatch.Stop();
  1313. // OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
  1314. // }
  1315. // catch (Exception ex)
  1316. // {
  1317. // OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
  1318. // }
  1319. // finally
  1320. // {
  1321. // // 重置标志变量
  1322. // isExitAtlasRight = false;
  1323. // }
  1324. //}
  1325. private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
  1326. {
  1327. Stopwatch stopwatch = new Stopwatch();
  1328. stopwatch.Start();
  1329. int nRet = 0;
  1330. string strRet = "";
  1331. try
  1332. {
  1333. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1334. while (isCollectingFlagLeft)
  1335. {
  1336. // 从缓存中获取所有未处理的数据
  1337. var cachedData = atlasScrew.GetCachedDataLeft();
  1338. foreach (var currentResult in cachedData)
  1339. {
  1340. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1341. {
  1342. continue; // 跳过无效数据
  1343. }
  1344. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1345. // 写入PLC
  1346. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1347. {
  1348. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1349. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1350. };
  1351. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1352. if (nRet != 0)
  1353. {
  1354. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1355. }
  1356. else
  1357. {
  1358. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1359. }
  1360. // 构建保存路径
  1361. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1362. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1363. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
  1364. Directory.CreateDirectory(savePath); // 确保目录存在
  1365. // 构建文件名(以 SN + 序号命名)
  1366. string fileName = $"{sn}_{fileCounter}.txt";
  1367. string filePath = Path.Combine(savePath, fileName);
  1368. // 写入文件
  1369. using (StreamWriter writer = new StreamWriter(filePath))
  1370. {
  1371. writer.WriteLine("精度, 扭力");
  1372. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1373. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1374. {
  1375. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1376. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1377. writer.WriteLine($"{precision}, {torque}");
  1378. }
  1379. }
  1380. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1381. // 增加文件计数器
  1382. fileCounter++;
  1383. }
  1384. // 如果没有更多数据,则短暂休眠以节省资源
  1385. if (!cachedData.Any())
  1386. {
  1387. Thread.Sleep(10); // 根据需要调整休眠时间
  1388. }
  1389. // 如果触发了出站,则退出循环
  1390. if (!isCollectingFlagLeft)
  1391. {
  1392. break;
  1393. }
  1394. }
  1395. stopwatch.Stop();
  1396. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1397. }
  1398. catch (Exception ex)
  1399. {
  1400. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1401. }
  1402. finally
  1403. {
  1404. isCollectingFlagLeft = false;
  1405. }
  1406. }
  1407. private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
  1408. {
  1409. Stopwatch stopwatch = new Stopwatch();
  1410. stopwatch.Start();
  1411. int nRet = 0;
  1412. string strRet = "";
  1413. try
  1414. {
  1415. int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
  1416. while (isCollectingFlagRight)
  1417. {
  1418. // 从缓存中获取所有未处理的数据
  1419. var cachedData = atlasScrew.GetCachedDataLeft();
  1420. foreach (var currentResult in cachedData)
  1421. {
  1422. if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
  1423. {
  1424. continue; // 跳过无效数据
  1425. }
  1426. OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
  1427. // 写入PLC
  1428. OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
  1429. {
  1430. fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
  1431. fCircles = float.Parse(currentResult.JD_MEAN.ToString())
  1432. };
  1433. (nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
  1434. if (nRet != 0)
  1435. {
  1436. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
  1437. }
  1438. else
  1439. {
  1440. OnMessage(LogType.Info, $"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
  1441. }
  1442. // 构建保存路径
  1443. string dateFolder = DateTime.Now.ToString("yyyyMMdd");
  1444. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  1445. string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction,"曲线");
  1446. Directory.CreateDirectory(savePath); // 确保目录存在
  1447. // 构建文件名(以 SN + 序号命名)
  1448. string fileName = $"{sn}_{fileCounter}.txt";
  1449. string filePath = Path.Combine(savePath, fileName);
  1450. // 写入文件
  1451. using (StreamWriter writer = new StreamWriter(filePath))
  1452. {
  1453. writer.WriteLine("精度, 扭力");
  1454. // 遍历 Pearkdegree 和 PearkTorque 的所有值
  1455. for (int i = 0; i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length; i++)
  1456. {
  1457. double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
  1458. double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
  1459. writer.WriteLine($"{precision}, {torque}");
  1460. }
  1461. }
  1462. OnMessage(LogType.Info, $"保存文件成功: {filePath}");
  1463. // 增加文件计数器
  1464. fileCounter++;
  1465. }
  1466. // 如果没有更多数据,则短暂休眠以节省资源
  1467. if (!cachedData.Any())
  1468. {
  1469. Thread.Sleep(10); // 根据需要调整休眠时间
  1470. }
  1471. // 如果触发了出站,则退出循环
  1472. if (!isCollectingFlagRight)
  1473. {
  1474. break;
  1475. }
  1476. }
  1477. stopwatch.Stop();
  1478. OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
  1479. }
  1480. catch (Exception ex)
  1481. {
  1482. OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
  1483. }
  1484. finally
  1485. {
  1486. isCollectingFlagRight = false;
  1487. }
  1488. }
  1489. #endregion
  1490. #region S1
  1491. /// <summary>
  1492. /// [S1] 壳体清洁上料装备
  1493. /// </summary>
  1494. /// <param name="plcNo">PLC编号</param>
  1495. private void ReadStation_S1(int plcNo)
  1496. {
  1497. string stationCode = "[OP10]";
  1498. string stationName = "壳体清洁上料";
  1499. string stationNameStr = stationCode + stationName;
  1500. string tagBaseName = "g_OP10_MES"; //标签变量名称
  1501. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1502. string tagAgvCommName = "agvCommFrmPC";
  1503. string tagBarsetName = "BarcodeSet";
  1504. OP10_MesData_t stPLC_MesData; //PLC的MES数据
  1505. (int, string) result;
  1506. while (true)
  1507. {
  1508. try
  1509. {
  1510. if (!GlobalContext._IsCon_Funs1)
  1511. {
  1512. UpdatePLCMonitor(1, plcNo, 0);
  1513. continue;
  1514. }
  1515. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1516. {
  1517. Stopwatch stopwatch1 = new Stopwatch();
  1518. Stopwatch stopwatch2 = new Stopwatch();
  1519. stopwatch1.Start();
  1520. stopwatch2.Start();
  1521. #region 一次性读取所有数据
  1522. // 一次性读取所有数据
  1523. result = FunsEip[plcNo].Read_SingleTag<OP10_MesData_t>(tagBaseName, 1, out stPLC_MesData,this); //读取单个结构体数据
  1524. if (result.Item1 != 0)
  1525. {
  1526. //richTextBox1.AppendText("\n" + strRet);
  1527. }
  1528. else
  1529. {
  1530. //richTextBox1.AppendText("\n" + "读取成功");
  1531. }
  1532. #endregion 一次性读取所有数据
  1533. stopwatch2.Stop();
  1534. #region 进站
  1535. try
  1536. {
  1537. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1538. {
  1539. lock (lockObj)
  1540. {
  1541. if (!ProgressState)
  1542. {
  1543. ProgressState = true;
  1544. Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, out ProgressState));
  1545. }
  1546. }
  1547. }
  1548. }
  1549. catch (Exception ex)
  1550. {
  1551. ProgressState = false;
  1552. string str = ex.StackTrace;
  1553. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1554. }
  1555. #endregion 进站
  1556. #region 出站
  1557. try
  1558. {
  1559. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1560. {
  1561. lock (lockObj)
  1562. {
  1563. if (!ProgressState)
  1564. {
  1565. ProgressState = true;
  1566. Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1567. stPLC_MesData.mesCommFrmPLC.cmd = 0;//清除入站申请
  1568. }
  1569. }
  1570. }
  1571. }
  1572. catch (Exception ex)
  1573. {
  1574. ProgressState = false;
  1575. string str = ex.StackTrace;
  1576. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1577. }
  1578. #endregion 出站
  1579. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1580. stopwatch1.Stop();
  1581. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1582. }
  1583. else
  1584. {
  1585. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1586. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1587. FunsEip[plcNo].Connect(); // 重连
  1588. }
  1589. }
  1590. catch (Exception ex)
  1591. {
  1592. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1593. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1594. }
  1595. Thread.Sleep(IntervalReadPLC);
  1596. }
  1597. }
  1598. /// <summary>
  1599. /// [S1] 壳体清洁上料 - 进站
  1600. /// </summary>
  1601. /// <param name="plcNo">PLC编号</param>
  1602. /// <param name="stationNameStr">工站全称</param>
  1603. /// <param name="stPLC_MesData"></param>
  1604. /// <param name="tagMesCommName"></param>
  1605. private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, out bool ProgressState)
  1606. {
  1607. Stopwatch stopwatch1 = new Stopwatch();
  1608. Stopwatch stopwatch2 = new Stopwatch();
  1609. try
  1610. {
  1611. stopwatch1.Start();
  1612. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1613. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
  1614. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1615. string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
  1616. string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
  1617. if (string.IsNullOrEmpty(sn))
  1618. {
  1619. ProgressState = false;
  1620. return;
  1621. }
  1622. //正式生产就用PLC中取的
  1623. //sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;
  1624. //测试先用9码,正式直接用PLC得到的SN码,截取成9位码
  1625. sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1626. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1627. //绑定载具和产品
  1628. ResponseMessage message = new ResponseMessage();
  1629. message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
  1630. if (message.result == false)
  1631. {
  1632. AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
  1633. }
  1634. // 产品SN进站
  1635. List<TestItem> item = new List<TestItem>();
  1636. stopwatch2.Start();
  1637. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1638. stopwatch2.Stop();
  1639. //指令执行结果 1:OK 110:失败
  1640. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1641. //进站结果写入PLC
  1642. CommandFromPLC resultToPlC = new CommandFromPLC();
  1643. resultToPlC.cmd = 0;
  1644. resultToPlC.cmdParam = 0;
  1645. resultToPlC.cmdResult = mesResultFrmWeb;
  1646. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1647. }
  1648. catch (Exception ex)
  1649. {
  1650. string str = ex.StackTrace;
  1651. AddMessage( LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1652. CommandFromPLC resultToPlC = new CommandFromPLC();
  1653. resultToPlC.cmd = 0;
  1654. resultToPlC.cmdParam = 0; //指令参数
  1655. resultToPlC.cmdResult = 110;
  1656. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1657. }
  1658. stopwatch1.Stop();
  1659. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  1660. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1661. ProgressState = false;
  1662. }
  1663. /// <summary>
  1664. /// [S1] 壳体清洁上料 - 出站接口
  1665. /// </summary>
  1666. private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1667. {
  1668. Stopwatch stopwatch1 = new Stopwatch();
  1669. Stopwatch stopwatch2 = new Stopwatch();
  1670. try
  1671. {
  1672. stopwatch1.Start();
  1673. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  1674. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1675. string processItem = stationName; // 项目
  1676. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1677. string supplierCode = ""; // 供应商代码
  1678. string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
  1679. string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
  1680. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
  1681. string sn = string.Empty;
  1682. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1683. string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
  1684. string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
  1685. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1686. a1Result = 1;
  1687. bool pass = a1Result == 1;
  1688. //根据载具码获取产品码
  1689. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1690. if (string.IsNullOrEmpty(strProductBarcode))
  1691. {
  1692. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1693. }
  1694. sn = strProductBarcode;
  1695. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1696. List<TestItem> items = new List<TestItem>();
  1697. items.Add(new TestItem()
  1698. {
  1699. Parameter_name = "载具码",
  1700. Parameter_value = CarrierBarcode,
  1701. Parameter_unit = ""
  1702. });
  1703. items.Add(new TestItem()
  1704. {
  1705. Parameter_name = "产品码",
  1706. Parameter_value = sn,
  1707. Parameter_unit = ""
  1708. });
  1709. //出站接口
  1710. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1711. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  1712. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1713. stopwatch2.Start();
  1714. //进站结果写入PLC
  1715. CommandFromPLC resultToPlC = new CommandFromPLC();
  1716. resultToPlC.cmd = 0;
  1717. resultToPlC.cmdParam = 0; //指令参数
  1718. resultToPlC.cmdResult = mesResultFrmWeb;
  1719. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1720. stopwatch2.Stop();
  1721. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  1722. //保存PLC返回MES数据到本地
  1723. ResponseMessage message = new ResponseMessage();
  1724. message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
  1725. stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress, stPLC_MesData.mesData.fCleanSpeed,
  1726. stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime, stPLC_MesData.mesData.nCleanCount,
  1727. stPLC_MesData.mesData.nRemainCount);
  1728. if (message.result == false)
  1729. {
  1730. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  1731. }
  1732. AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
  1733. }
  1734. catch (Exception ex)
  1735. {
  1736. stopwatch2.Start();
  1737. CommandFromPLC resultToPlC = new CommandFromPLC();
  1738. resultToPlC.cmd = 0;
  1739. resultToPlC.cmdParam = 0; //指令参数
  1740. resultToPlC.cmdResult = 110;
  1741. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1742. stopwatch2.Stop();
  1743. string str = ex.StackTrace;
  1744. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1745. }
  1746. stopwatch1.Stop();
  1747. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1748. ProgressState = false;
  1749. }
  1750. #endregion
  1751. #region S2
  1752. /// <summary>
  1753. /// [S2] 上盖板上料装备
  1754. /// </summary>
  1755. /// <param name="plcNo">PLC编号</param>
  1756. private void ReadStation_S2(int plcNo)
  1757. {
  1758. string stationCode = "[OP20]";
  1759. string stationName = "上盖板上料装备";
  1760. string stationNameStr = stationCode + stationName;
  1761. string tagBaseName = "g_OP20_MES"; //标签变量名称
  1762. string tagMesCommName = "mesCommToPC"; //标签变量名称
  1763. string tagAgvCommName = "agvCommFrmPC";
  1764. string tagBarsetName = "BarcodeSet";
  1765. OP20_MesData_t stPLC_MesData; //PLC的MES数据
  1766. (int, string) result;
  1767. while (true)
  1768. {
  1769. try
  1770. {
  1771. if (!GlobalContext._IsCon_Funs2)
  1772. {
  1773. UpdatePLCMonitor(1, plcNo, 0);
  1774. continue;
  1775. }
  1776. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  1777. {
  1778. Stopwatch stopwatch1 = new Stopwatch();
  1779. Stopwatch stopwatch2 = new Stopwatch();
  1780. stopwatch1.Start();
  1781. stopwatch2.Start();
  1782. #region 一次性读取所有数据
  1783. // 一次性读取所有数据
  1784. result = FunsEip[plcNo].Read_SingleTag<OP20_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  1785. if (result.Item1 != 0)
  1786. {
  1787. //richTextBox1.AppendText("\n" + strRet);
  1788. }
  1789. else
  1790. {
  1791. //richTextBox1.AppendText("\n" + "读取成功");
  1792. }
  1793. #endregion 一次性读取所有数据
  1794. stopwatch2.Stop();
  1795. #region 进站
  1796. try
  1797. {
  1798. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  1799. {
  1800. lock (lockObj)
  1801. {
  1802. if (!ProgressState)
  1803. {
  1804. ProgressState = true;
  1805. Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  1806. }
  1807. }
  1808. }
  1809. }
  1810. catch (Exception ex)
  1811. {
  1812. ProgressState = false;
  1813. string str = ex.StackTrace;
  1814. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1815. }
  1816. #endregion 进站
  1817. #region 出站
  1818. try
  1819. {
  1820. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  1821. {
  1822. lock (lockObj)
  1823. {
  1824. if (!ProgressState)
  1825. {
  1826. ProgressState = true;
  1827. Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  1828. stPLC_MesData.mesCommFrmPLC.cmd = 0;//清除入站申请
  1829. }
  1830. }
  1831. }
  1832. }
  1833. catch (Exception ex)
  1834. {
  1835. ProgressState = false;
  1836. string str = ex.StackTrace;
  1837. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1838. }
  1839. #endregion 出站
  1840. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  1841. stopwatch1.Stop();
  1842. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  1843. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  1844. }
  1845. else
  1846. {
  1847. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1848. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  1849. FunsEip[plcNo].Connect();
  1850. }
  1851. }
  1852. catch (Exception ex)
  1853. {
  1854. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  1855. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  1856. //Funs[plcNo].ReConnect();
  1857. }
  1858. Thread.Sleep(IntervalReadPLC);
  1859. }
  1860. }
  1861. /// <summary>
  1862. /// [S2] 上盖板上料装备
  1863. /// </summary>
  1864. /// <param name="plcNo">PLC编号</param>
  1865. /// <param name="stationNameStr">工站全称</param>
  1866. private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  1867. {
  1868. Stopwatch stopwatch1 = new Stopwatch();
  1869. Stopwatch stopwatch2 = new Stopwatch();
  1870. try
  1871. {
  1872. stopwatch1.Start();
  1873. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  1874. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
  1875. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  1876. string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
  1877. string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
  1878. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  1879. //根据载具码获取产品码
  1880. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  1881. if (string.IsNullOrEmpty(strProductBarcode))
  1882. {
  1883. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1884. }
  1885. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  1886. //if (sn != strProductBarcode)
  1887. //{
  1888. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  1889. //}
  1890. sn = strProductBarcode;
  1891. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  1892. // 产品SN(物料码)校验
  1893. List<TestItem> item = new List<TestItem>();
  1894. stopwatch2.Start();
  1895. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  1896. stopwatch2.Stop();
  1897. //指令执行结果 1:OK 110:失败
  1898. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  1899. //进站结果写入PLC
  1900. CommandFromPLC resultToPlC = new CommandFromPLC();
  1901. resultToPlC.cmd = 0;
  1902. resultToPlC.cmdParam = 0; //指令参数
  1903. resultToPlC.cmdResult = mesResultFrmWeb;
  1904. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1905. }
  1906. catch (Exception ex)
  1907. {
  1908. string str = ex.StackTrace;
  1909. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  1910. CommandFromPLC resultToPlC = new CommandFromPLC();
  1911. resultToPlC.cmd = 0;
  1912. resultToPlC.cmdParam = 0; //指令参数
  1913. resultToPlC.cmdResult = 110;
  1914. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1915. }
  1916. stopwatch1.Stop();
  1917. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  1918. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  1919. ProgressState = false;
  1920. }
  1921. /// <summary>
  1922. /// [S2] 上盖板上料装备 - 出站接口
  1923. /// </summary>
  1924. private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  1925. {
  1926. Stopwatch stopwatch1 = new Stopwatch();
  1927. Stopwatch stopwatch2 = new Stopwatch();
  1928. try
  1929. {
  1930. stopwatch1.Start();
  1931. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  1932. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  1933. string processItem = stationName; // 测试项目
  1934. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  1935. string supplierCode = ""; // 供应商代码
  1936. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  1937. string batch_num = GlobalContext.BatchNumber; // 批次号
  1938. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  1939. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  1940. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  1941. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
  1942. string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
  1943. string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
  1944. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  1945. bool pass = a1Result == 1;
  1946. //根据载具码获取产品码
  1947. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  1948. if (string.IsNullOrEmpty(strProductBarcode))
  1949. {
  1950. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  1951. }
  1952. sn = strProductBarcode;
  1953. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  1954. List<TestItem> items = new List<TestItem>();
  1955. items.Add(new TestItem()
  1956. {
  1957. Parameter_name = "载具码",
  1958. Parameter_value = CarrierBarcode,
  1959. Parameter_unit = ""
  1960. });
  1961. items.Add(new TestItem()
  1962. {
  1963. Parameter_name = "产品码",
  1964. Parameter_value = sn,
  1965. Parameter_unit = ""
  1966. });
  1967. items.Add(new TestItem()
  1968. {
  1969. Parameter_name = "部件码",
  1970. Parameter_value = PartBarcode,
  1971. Parameter_unit = ""
  1972. });
  1973. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  1974. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  1975. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  1976. stopwatch2.Start();
  1977. //进站结果写入PLC
  1978. CommandFromPLC resultToPlC = new CommandFromPLC();
  1979. resultToPlC.cmd = 0;
  1980. resultToPlC.cmdParam = 0; //指令参数
  1981. resultToPlC.cmdResult = mesResultFrmWeb;
  1982. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  1983. stopwatch2.Stop();
  1984. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  1985. //保存PLC返回MES数据到本地
  1986. ResponseMessage message = new ResponseMessage();
  1987. message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  1988. if (message.result == false)
  1989. {
  1990. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  1991. }
  1992. if (!string.IsNullOrEmpty(PartBarcode))
  1993. {
  1994. message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
  1995. if (message.result == false)
  1996. {
  1997. AddMessage(LogType.Error, message.text);
  1998. }
  1999. }
  2000. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2001. }
  2002. catch (Exception ex)
  2003. {
  2004. stopwatch2.Start();
  2005. CommandFromPLC resultToPlC = new CommandFromPLC();
  2006. resultToPlC.cmd = 0;
  2007. resultToPlC.cmdParam = 0; //指令参数
  2008. resultToPlC.cmdResult = 110;
  2009. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2010. stopwatch2.Stop();
  2011. string str = ex.StackTrace;
  2012. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2013. }
  2014. stopwatch1.Stop();
  2015. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2016. ProgressState = false;
  2017. }
  2018. #endregion
  2019. #region S3
  2020. /// <summary>
  2021. /// [S3] 点散热胶装备
  2022. /// </summary>
  2023. /// <param name="plcNo">PLC编号</param>
  2024. private void ReadStation_S3(int plcNo)
  2025. {
  2026. string stationCode = "[OP30]";
  2027. string stationName = "点散热胶装备";
  2028. string stationNameStr = stationCode + stationName;
  2029. string tagBaseName = "g_OP30_MES"; //标签变量名称
  2030. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2031. string tagAgvCommName = "agvCommFrmPC";
  2032. string tagBarsetName = "BarcodeSet";
  2033. OP30_MesData_t stPLC_MesData; //PLC的MES数据
  2034. (int, string) result;
  2035. #region 创建字典
  2036. // 触发信号字典 赋值
  2037. s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2038. s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2039. s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2040. s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2041. s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2042. // PLC数据字典 赋值
  2043. s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  2044. s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  2045. s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2046. s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  2047. s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  2048. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2049. s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2050. s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  2051. s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  2052. //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  2053. s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  2054. s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  2055. s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  2056. s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  2057. s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  2058. s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  2059. //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  2060. s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  2061. s3PLCData.Add("c1Result", 0); // 产品结果
  2062. s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  2063. s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  2064. s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  2065. s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  2066. #endregion 创建字典
  2067. while (true)
  2068. {
  2069. try
  2070. {
  2071. if (!GlobalContext._IsCon_Funs2)
  2072. {
  2073. UpdatePLCMonitor(1, plcNo, 0);
  2074. continue;
  2075. }
  2076. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2077. {
  2078. Stopwatch stopwatch1 = new Stopwatch();
  2079. Stopwatch stopwatch2 = new Stopwatch();
  2080. stopwatch1.Start();
  2081. stopwatch2.Start();
  2082. #region 一次性读取所有数据
  2083. // 一次性读取所有数据
  2084. result = FunsEip[plcNo].Read_SingleTag<OP30_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2085. if (result.Item1 != 0)
  2086. {
  2087. //richTextBox1.AppendText("\n" + strRet);
  2088. }
  2089. else
  2090. {
  2091. //richTextBox1.AppendText("\n" + "读取成功");
  2092. }
  2093. #endregion 一次性读取所有数据
  2094. stopwatch2.Stop();
  2095. #region 左边进站
  2096. try
  2097. {
  2098. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2099. {
  2100. lock (lockObj)
  2101. {
  2102. if (!ProgressState)
  2103. {
  2104. ProgressState = true;
  2105. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
  2106. }
  2107. }
  2108. }
  2109. }
  2110. catch (Exception ex)
  2111. {
  2112. ProgressState = false;
  2113. string str = ex.StackTrace;
  2114. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2115. }
  2116. #endregion 左边进站
  2117. #region 左边出站
  2118. try
  2119. {
  2120. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2121. {
  2122. lock (lockObj)
  2123. {
  2124. if (!ProgressState)
  2125. {
  2126. ProgressState = true;
  2127. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  2128. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  2129. }
  2130. }
  2131. }
  2132. }
  2133. catch (Exception ex)
  2134. {
  2135. ProgressState = false;
  2136. string str = ex.StackTrace;
  2137. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2138. }
  2139. #endregion 左边出站
  2140. #region 右边进站
  2141. try
  2142. {
  2143. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2144. {
  2145. lock (lockObj)
  2146. {
  2147. if (!ProgressState)
  2148. {
  2149. ProgressState = true;
  2150. Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right." + tagBarsetName,"Right", out ProgressState));
  2151. }
  2152. }
  2153. }
  2154. }
  2155. catch (Exception ex)
  2156. {
  2157. ProgressState = false;
  2158. string str = ex.StackTrace;
  2159. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2160. }
  2161. #endregion 右边进站
  2162. #region 右边出站
  2163. try
  2164. {
  2165. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2166. {
  2167. lock (lockObj)
  2168. {
  2169. if (!ProgressState)
  2170. {
  2171. ProgressState = true;
  2172. Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  2173. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  2174. }
  2175. }
  2176. }
  2177. }
  2178. catch (Exception ex)
  2179. {
  2180. string str = ex.StackTrace;
  2181. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2182. }
  2183. #endregion 右边出站
  2184. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2185. stopwatch1.Stop();
  2186. //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  2187. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2188. }
  2189. else
  2190. {
  2191. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2192. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2193. FunsEip[plcNo].Connect();
  2194. }
  2195. }
  2196. catch (Exception ex)
  2197. {
  2198. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2199. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2200. //Funs[plcNo].ReConnect();
  2201. }
  2202. Thread.Sleep(IntervalReadPLC);
  2203. }
  2204. }
  2205. /// <summary>
  2206. /// [S3] 点散热胶装备 - 进站
  2207. /// </summary>
  2208. /// <param name="plcNo">PLC编号</param>
  2209. /// <param name="stationNameStr">工站全称</param>
  2210. private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName,string direction, out bool ProgressState)
  2211. {
  2212. Stopwatch stopwatch1 = new Stopwatch();
  2213. Stopwatch stopwatch2 = new Stopwatch();
  2214. try
  2215. {
  2216. stopwatch1.Start();
  2217. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_进站开始");
  2218. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2219. string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
  2220. string StationId=string.Empty;
  2221. if (direction=="Left")
  2222. {
  2223. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2224. }
  2225. if (direction == "Right")
  2226. {
  2227. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2228. }
  2229. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2230. //载具码验证产品码
  2231. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2232. if (string.IsNullOrEmpty(strProductBarcode))
  2233. {
  2234. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2235. }
  2236. sn = strProductBarcode;
  2237. AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
  2238. // 产品SN(物料码)校验
  2239. List<TestItem> item = new List<TestItem>();
  2240. stopwatch2.Start();
  2241. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2242. stopwatch2.Stop();
  2243. //指令执行结果 1:OK 110:失败
  2244. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2245. //进站结果写入PLC
  2246. CommandFromPLC resultToPlC = new CommandFromPLC();
  2247. resultToPlC.cmd = 0;
  2248. resultToPlC.cmdParam = 0; //指令参数
  2249. resultToPlC.cmdResult = mesResultFrmWeb;
  2250. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2251. }
  2252. catch (Exception ex)
  2253. {
  2254. string str = ex.StackTrace;
  2255. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2256. CommandFromPLC resultToPlC = new CommandFromPLC();
  2257. resultToPlC.cmd = 0;
  2258. resultToPlC.cmdParam = 0; //指令参数
  2259. resultToPlC.cmdResult = 110;
  2260. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2261. }
  2262. stopwatch1.Stop();
  2263. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  2264. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2265. ProgressState = false;
  2266. }
  2267. /// <summary>
  2268. /// [S3] 点散热胶装备 - 出站
  2269. /// </summary>
  2270. private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  2271. {
  2272. Stopwatch stopwatch1 = new Stopwatch();
  2273. Stopwatch stopwatch2 = new Stopwatch();
  2274. try
  2275. {
  2276. stopwatch1.Start();
  2277. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
  2278. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2279. string processItem = stationName; // 测试项目
  2280. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2281. string supplierCode = ""; // 供应商代码
  2282. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2283. string batch_num = GlobalContext.BatchNumber; // 批次号
  2284. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2285. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2286. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2287. string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
  2288. string StationId = string.Empty;
  2289. if (direction == "Left")
  2290. {
  2291. StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
  2292. }
  2293. if (direction == "Right")
  2294. {
  2295. StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
  2296. }
  2297. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2298. bool pass = a1Result == 1;
  2299. //根据载具码获取产品码
  2300. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2301. if (string.IsNullOrEmpty(strProductBarcode))
  2302. {
  2303. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2304. }
  2305. sn = strProductBarcode;
  2306. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2307. List<TestItem> items = new List<TestItem>();
  2308. items.Add(new TestItem()
  2309. {
  2310. Parameter_name = "载具码",
  2311. Parameter_value = CarrierBarcode,
  2312. Parameter_unit = ""
  2313. });
  2314. items.Add(new TestItem()
  2315. {
  2316. Parameter_name = "产品码",
  2317. Parameter_value = sn,
  2318. Parameter_unit = ""
  2319. });
  2320. int result1 = 1;
  2321. if (direction == "Right")
  2322. {
  2323. result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2324. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2325. }
  2326. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2327. stopwatch2.Start();
  2328. //进站结果写入PLC
  2329. CommandFromPLC resultToPlC = new CommandFromPLC();
  2330. resultToPlC.cmd = 0;
  2331. resultToPlC.cmdParam = 0; //指令参数
  2332. resultToPlC.cmdResult = mesResultFrmWeb;
  2333. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2334. stopwatch2.Stop();
  2335. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  2336. //保存PLC返回MES数据到本地
  2337. ResponseMessage message = new ResponseMessage();
  2338. if (direction == "Left")
  2339. {
  2340. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2341. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2342. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2343. message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2344. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2345. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2346. if (message.result == false)
  2347. {
  2348. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2349. }
  2350. }
  2351. if (direction == "Right")
  2352. {
  2353. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
  2354. string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
  2355. string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
  2356. message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
  2357. stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
  2358. strMesHeightInfos, strIntervalWeights, strRemainGlues);
  2359. if (message.result == false)
  2360. {
  2361. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2362. }
  2363. }
  2364. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2365. }
  2366. catch (Exception ex)
  2367. {
  2368. stopwatch2.Start();
  2369. CommandFromPLC resultToPlC = new CommandFromPLC();
  2370. resultToPlC.cmd = 0;
  2371. resultToPlC.cmdParam = 0; //指令参数
  2372. resultToPlC.cmdResult = 110;
  2373. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2374. stopwatch2.Stop();
  2375. string str = ex.StackTrace;
  2376. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2377. }
  2378. stopwatch1.Stop();
  2379. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2380. ProgressState = false;
  2381. }
  2382. #endregion S3
  2383. #region S4
  2384. /// <summary>
  2385. /// [S4] 点胶检测设备
  2386. /// </summary>
  2387. /// <param name="plcNo">PLC编号</param>
  2388. private void ReadStation_S4(int plcNo)
  2389. {
  2390. string stationCode = "[OP40]";
  2391. string stationName = "胶线检测";
  2392. string stationNameStr = stationCode + stationName;
  2393. string tagBaseName = "g_OP40_MES"; //标签变量名称
  2394. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2395. string tagAgvCommName = "agvCommFrmPC";
  2396. string tagBarsetName = "BarcodeSet";
  2397. OP40_MesData_t stPLC_MesData; //PLC的MES数据
  2398. (int, string) result;
  2399. while (true)
  2400. {
  2401. try
  2402. {
  2403. if (!GlobalContext._IsCon_Funs1)
  2404. {
  2405. UpdatePLCMonitor(1, plcNo, 0);
  2406. continue;
  2407. }
  2408. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2409. {
  2410. Stopwatch stopwatch1 = new Stopwatch();
  2411. Stopwatch stopwatch2 = new Stopwatch();
  2412. stopwatch1.Start();
  2413. stopwatch2.Start();
  2414. #region 一次性读取所有数据
  2415. // 一次性读取所有数据
  2416. result = FunsEip[plcNo].Read_SingleTag<OP40_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2417. if (result.Item1 != 0)
  2418. {
  2419. //richTextBox1.AppendText("\n" + strRet);
  2420. }
  2421. else
  2422. {
  2423. //richTextBox1.AppendText("\n" + "读取成功");
  2424. }
  2425. #endregion 一次性读取所有数据
  2426. stopwatch2.Stop();
  2427. #region 进站
  2428. try
  2429. {
  2430. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2431. {
  2432. lock (lockObj)
  2433. {
  2434. if (!ProgressState)
  2435. {
  2436. ProgressState = true;
  2437. Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2438. }
  2439. }
  2440. }
  2441. }
  2442. catch (Exception ex)
  2443. {
  2444. ProgressState = false;
  2445. string str = ex.StackTrace;
  2446. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2447. }
  2448. #endregion 进站
  2449. #region 出站
  2450. try
  2451. {
  2452. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2453. {
  2454. lock (lockObj)
  2455. {
  2456. if (!ProgressState)
  2457. {
  2458. ProgressState = true;
  2459. Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2460. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2461. }
  2462. }
  2463. }
  2464. }
  2465. catch (Exception ex)
  2466. {
  2467. string str = ex.StackTrace;
  2468. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2469. }
  2470. #endregion 出站
  2471. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2472. stopwatch1.Stop();
  2473. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2474. }
  2475. else
  2476. {
  2477. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2478. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2479. FunsEip[plcNo].Connect(); // 重连
  2480. }
  2481. }
  2482. catch (Exception ex)
  2483. {
  2484. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2485. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2486. }
  2487. Thread.Sleep(IntervalReadPLC);
  2488. }
  2489. }
  2490. /// <summary>
  2491. /// [S4] 点胶检测设备 - 进站
  2492. /// </summary>
  2493. /// <param name="plcNo">PLC编号</param>
  2494. /// <param name="stationNameStr">工站全称</param>
  2495. /// <param name="stPLC_MesData"></param>
  2496. /// <param name="tagMesCommName"></param>
  2497. private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2498. {
  2499. Stopwatch stopwatch1 = new Stopwatch();
  2500. Stopwatch stopwatch2 = new Stopwatch();
  2501. try
  2502. {
  2503. stopwatch1.Start();
  2504. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2505. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2506. string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
  2507. string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
  2508. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2509. //载具码验证产品码
  2510. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2511. if (string.IsNullOrEmpty(strProductBarcode))
  2512. {
  2513. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2514. }
  2515. sn = strProductBarcode;
  2516. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2517. // 产品SN(物料码)校验
  2518. List<TestItem> item = new List<TestItem>();
  2519. stopwatch2.Start();
  2520. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2521. stopwatch2.Stop();
  2522. //指令执行结果 1:OK 110:失败
  2523. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2524. //进站结果写入PLC
  2525. CommandFromPLC resultToPlC = new CommandFromPLC();
  2526. resultToPlC.cmd = 0;
  2527. resultToPlC.cmdParam = 0; //指令参数
  2528. resultToPlC.cmdResult = mesResultFrmWeb;
  2529. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2530. }
  2531. catch (Exception ex)
  2532. {
  2533. string str = ex.StackTrace;
  2534. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2535. CommandFromPLC resultToPlC = new CommandFromPLC();
  2536. resultToPlC.cmd = 0;
  2537. resultToPlC.cmdParam = 0; //指令参数
  2538. resultToPlC.cmdResult = 110;
  2539. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2540. }
  2541. stopwatch1.Stop();
  2542. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2543. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2544. ProgressState = false;
  2545. }
  2546. /// <summary>
  2547. /// [S4] 点胶检测设备 - 出站接口
  2548. /// </summary>
  2549. private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2550. {
  2551. Stopwatch stopwatch1 = new Stopwatch();
  2552. Stopwatch stopwatch2 = new Stopwatch();
  2553. try
  2554. {
  2555. stopwatch1.Start();
  2556. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2557. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2558. string processItem = stationName; // 测试项目
  2559. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2560. string supplierCode = ""; // 供应商代码
  2561. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2562. string batch_num = GlobalContext.BatchNumber; // 批次号
  2563. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2564. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2565. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2566. string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
  2567. string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
  2568. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2569. bool pass = a1Result == 1;
  2570. //根据载具码获取产品码
  2571. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2572. if (string.IsNullOrEmpty(strProductBarcode))
  2573. {
  2574. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2575. }
  2576. sn = strProductBarcode;
  2577. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2578. List<TestItem> items = new List<TestItem>();
  2579. items.Add(new TestItem()
  2580. {
  2581. Parameter_name = "载具码",
  2582. Parameter_value = CarrierBarcode,
  2583. Parameter_unit = ""
  2584. });
  2585. items.Add(new TestItem()
  2586. {
  2587. Parameter_name = "产品码",
  2588. Parameter_value = sn,
  2589. Parameter_unit = ""
  2590. });
  2591. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2592. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  2593. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2594. stopwatch2.Start();
  2595. //进站结果写入PLC
  2596. CommandFromPLC resultToPlC = new CommandFromPLC();
  2597. resultToPlC.cmd = 0;
  2598. resultToPlC.cmdParam = 0; //指令参数
  2599. resultToPlC.cmdResult = mesResultFrmWeb;
  2600. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2601. stopwatch2.Stop();
  2602. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2603. //保存PLC返回MES数据到本地
  2604. ResponseMessage message = new ResponseMessage();
  2605. string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
  2606. string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
  2607. string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
  2608. string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
  2609. message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
  2610. strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
  2611. if (message.result == false)
  2612. {
  2613. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2614. }
  2615. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2616. }
  2617. catch (Exception ex)
  2618. {
  2619. stopwatch2.Start();
  2620. CommandFromPLC resultToPlC = new CommandFromPLC();
  2621. resultToPlC.cmd = 0;
  2622. resultToPlC.cmdParam = 0; //指令参数
  2623. resultToPlC.cmdResult = 110;
  2624. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2625. stopwatch2.Stop();
  2626. string str = ex.StackTrace;
  2627. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2628. }
  2629. stopwatch1.Stop();
  2630. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2631. ProgressState = false;
  2632. }
  2633. #endregion
  2634. #region S5
  2635. /// <summary>
  2636. /// [S5] 点胶检测设备
  2637. /// </summary>
  2638. /// <param name="plcNo">PLC编号</param>
  2639. private void ReadStation_S5(int plcNo)
  2640. {
  2641. string stationCode = "[OP50]";
  2642. string stationName = "ADD板上料组装装备";
  2643. string stationNameStr = stationCode + stationName;
  2644. string tagBaseName = "g_OP50_MES"; //标签变量名称
  2645. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2646. string tagAgvCommName = "agvCommFrmPC";
  2647. string tagBarsetName = "BarcodeSet";
  2648. OP50_MesData_t stPLC_MesData; //PLC的MES数据
  2649. (int, string) result;
  2650. while (true)
  2651. {
  2652. try
  2653. {
  2654. if (!GlobalContext._IsCon_Funs1)
  2655. {
  2656. UpdatePLCMonitor(1, plcNo, 0);
  2657. continue;
  2658. }
  2659. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2660. {
  2661. Stopwatch stopwatch1 = new Stopwatch();
  2662. Stopwatch stopwatch2 = new Stopwatch();
  2663. stopwatch1.Start();
  2664. stopwatch2.Start();
  2665. #region 一次性读取所有数据
  2666. // 一次性读取所有数据
  2667. result = FunsEip[plcNo].Read_SingleTag<OP50_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2668. if (result.Item1 != 0)
  2669. {
  2670. //richTextBox1.AppendText("\n" + strRet);
  2671. }
  2672. else
  2673. {
  2674. //richTextBox1.AppendText("\n" + "读取成功");
  2675. }
  2676. #endregion 一次性读取所有数据
  2677. stopwatch2.Stop();
  2678. #region 进站
  2679. try
  2680. {
  2681. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2682. {
  2683. lock (lockObj)
  2684. {
  2685. if (!ProgressState)
  2686. {
  2687. ProgressState = true;
  2688. Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2689. }
  2690. }
  2691. }
  2692. }
  2693. catch (Exception ex)
  2694. {
  2695. ProgressState = false;
  2696. string str = ex.StackTrace;
  2697. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2698. }
  2699. #endregion 进站
  2700. #region 出站
  2701. try
  2702. {
  2703. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2704. {
  2705. lock (lockObj)
  2706. {
  2707. if (!ProgressState)
  2708. {
  2709. ProgressState = true;
  2710. Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2711. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2712. }
  2713. }
  2714. }
  2715. }
  2716. catch (Exception ex)
  2717. {
  2718. ProgressState = false;
  2719. string str = ex.StackTrace;
  2720. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2721. }
  2722. #endregion 出站
  2723. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2724. stopwatch1.Stop();
  2725. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2726. }
  2727. else
  2728. {
  2729. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2730. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2731. FunsEip[plcNo].Connect(); // 重连
  2732. }
  2733. }
  2734. catch (Exception ex)
  2735. {
  2736. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2737. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  2738. }
  2739. Thread.Sleep(IntervalReadPLC);
  2740. }
  2741. }
  2742. /// <summary>
  2743. /// [S5] 点胶检测设备 - 进站
  2744. /// </summary>
  2745. /// <param name="plcNo">PLC编号</param>
  2746. /// <param name="stationNameStr">工站全称</param>
  2747. /// <param name="stPLC_MesData"></param>
  2748. /// <param name="tagMesCommName"></param>
  2749. private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  2750. {
  2751. Stopwatch stopwatch1 = new Stopwatch();
  2752. Stopwatch stopwatch2 = new Stopwatch();
  2753. try
  2754. {
  2755. stopwatch1.Start();
  2756. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  2757. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  2758. //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
  2759. string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
  2760. string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
  2761. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  2762. //载具码验证产品码 //载具码验证产品码
  2763. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  2764. if (string.IsNullOrEmpty(strProductBarcode))
  2765. {
  2766. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2767. }
  2768. //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
  2769. //if (sn != strProductBarcode)
  2770. //{
  2771. // AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
  2772. //}
  2773. sn = strProductBarcode;
  2774. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  2775. // 产品SN(物料码)校验
  2776. List<TestItem> item = new List<TestItem>();
  2777. stopwatch2.Start();
  2778. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  2779. stopwatch2.Stop();
  2780. //指令执行结果 1:OK 110:失败
  2781. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  2782. //进站结果写入PLC
  2783. CommandFromPLC resultToPlC = new CommandFromPLC();
  2784. resultToPlC.cmd = 0;
  2785. resultToPlC.cmdParam = 0; //指令参数
  2786. resultToPlC.cmdResult = mesResultFrmWeb;
  2787. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2788. }
  2789. catch (Exception ex)
  2790. {
  2791. string str = ex.StackTrace;
  2792. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2793. CommandFromPLC resultToPlC = new CommandFromPLC();
  2794. resultToPlC.cmd = 0;
  2795. resultToPlC.cmdParam = 0; //指令参数
  2796. resultToPlC.cmdResult = 110;
  2797. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2798. }
  2799. stopwatch1.Stop();
  2800. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  2801. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2802. ProgressState = false;
  2803. }
  2804. /// <summary>
  2805. /// [S5] 点胶检测设备 - 出站接口
  2806. /// </summary>
  2807. private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  2808. {
  2809. Stopwatch stopwatch1 = new Stopwatch();
  2810. Stopwatch stopwatch2 = new Stopwatch();
  2811. try
  2812. {
  2813. stopwatch1.Start();
  2814. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  2815. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  2816. string processItem = stationName; // 测试项目
  2817. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  2818. string supplierCode = ""; // 供应商代码
  2819. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  2820. string batch_num = GlobalContext.BatchNumber; // 批次号
  2821. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  2822. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  2823. string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
  2824. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  2825. string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
  2826. string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
  2827. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  2828. bool pass = a1Result == 1;
  2829. //根据载具码获取产品码
  2830. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  2831. if (string.IsNullOrEmpty(strProductBarcode))
  2832. {
  2833. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  2834. }
  2835. sn = strProductBarcode;
  2836. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  2837. List<TestItem> items = new List<TestItem>();
  2838. items.Add(new TestItem()
  2839. {
  2840. Parameter_name = "载具码",
  2841. Parameter_value = CarrierBarcode,
  2842. Parameter_unit = ""
  2843. });
  2844. items.Add(new TestItem()
  2845. {
  2846. Parameter_name = "产品码",
  2847. Parameter_value = sn,
  2848. Parameter_unit = ""
  2849. });
  2850. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  2851. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode);
  2852. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  2853. stopwatch2.Start();
  2854. //进站结果写入PLC
  2855. CommandFromPLC resultToPlC = new CommandFromPLC();
  2856. resultToPlC.cmd = 0;
  2857. resultToPlC.cmdParam = 0; //指令参数
  2858. resultToPlC.cmdResult = mesResultFrmWeb;
  2859. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2860. stopwatch2.Stop();
  2861. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  2862. //保存PLC返回MES数据到本地
  2863. ResponseMessage message = new ResponseMessage();
  2864. message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
  2865. stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB, stPLC_MesData.mesData.nRemainCount, "");
  2866. if (message.result == false)
  2867. {
  2868. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  2869. }
  2870. //保存部件码信息
  2871. if (!string.IsNullOrEmpty(PartBarcode))
  2872. {
  2873. message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
  2874. if (message.result == false)
  2875. {
  2876. AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
  2877. }
  2878. }
  2879. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  2880. }
  2881. catch (Exception ex)
  2882. {
  2883. stopwatch2.Start();
  2884. CommandFromPLC resultToPlC = new CommandFromPLC();
  2885. resultToPlC.cmd = 0;
  2886. resultToPlC.cmdParam = 0; //指令参数
  2887. resultToPlC.cmdResult = 110;
  2888. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  2889. stopwatch2.Stop();
  2890. string str = ex.StackTrace;
  2891. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2892. }
  2893. stopwatch1.Stop();
  2894. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  2895. ProgressState = false;
  2896. }
  2897. #endregion
  2898. #region S6
  2899. /// <summary>
  2900. /// [S6] 顶盖装配设备
  2901. /// </summary>
  2902. /// <param name="plcNo">PLC编号</param>
  2903. private void ReadStation_S6(int plcNo)
  2904. {
  2905. string stationCode = "[OP60]";
  2906. string stationName = "组上盖板";
  2907. string stationNameStr = stationCode + stationName;
  2908. string tagBaseName = "g_OP60_MES"; //标签变量名称
  2909. string tagMesCommName = "mesCommToPC"; //标签变量名称
  2910. string tagAgvCommName = "agvCommFrmPC";
  2911. string tagBarsetName = "BarcodeSet";
  2912. OP60_MesData_t stPLC_MesData; //PLC的MES数据
  2913. (int, string) result;
  2914. while (true)
  2915. {
  2916. try
  2917. {
  2918. if (!GlobalContext._IsCon_Funs1)
  2919. {
  2920. UpdatePLCMonitor(1, plcNo, 0);
  2921. continue;
  2922. }
  2923. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  2924. {
  2925. Stopwatch stopwatch1 = new Stopwatch();
  2926. Stopwatch stopwatch2 = new Stopwatch();
  2927. stopwatch1.Start();
  2928. stopwatch2.Start();
  2929. #region 一次性读取所有数据
  2930. // 一次性读取所有数据
  2931. result = FunsEip[plcNo].Read_SingleTag<OP60_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  2932. if (result.Item1 != 0)
  2933. {
  2934. //richTextBox1.AppendText("\n" + strRet);
  2935. }
  2936. else
  2937. {
  2938. //richTextBox1.AppendText("\n" + "读取成功");
  2939. }
  2940. #endregion 一次性读取所有数据
  2941. stopwatch2.Stop();
  2942. #region 进站
  2943. try
  2944. {
  2945. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  2946. {
  2947. lock (lockObj)
  2948. {
  2949. if (!ProgressState)
  2950. {
  2951. ProgressState = true;
  2952. Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  2953. }
  2954. }
  2955. }
  2956. }
  2957. catch (Exception ex)
  2958. {
  2959. ProgressState = false;
  2960. string str = ex.StackTrace;
  2961. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2962. }
  2963. #endregion 进站
  2964. #region 出站
  2965. try
  2966. {
  2967. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  2968. {
  2969. lock (lockObj)
  2970. {
  2971. if (!ProgressState)
  2972. {
  2973. ProgressState = true; ;
  2974. Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  2975. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  2976. }
  2977. }
  2978. }
  2979. }
  2980. catch (Exception ex)
  2981. {
  2982. ProgressState = false;
  2983. string str = ex.StackTrace;
  2984. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  2985. }
  2986. #endregion 出站
  2987. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  2988. stopwatch1.Stop();
  2989. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  2990. }
  2991. else
  2992. {
  2993. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  2994. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  2995. FunsEip[plcNo].Connect(); // 重连
  2996. }
  2997. }
  2998. catch (Exception ex)
  2999. {
  3000. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3001. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3002. }
  3003. Thread.Sleep(IntervalReadPLC);
  3004. }
  3005. }
  3006. /// <summary>
  3007. /// [S6] 顶盖装配设备 - 进站
  3008. /// </summary>
  3009. /// <param name="plcNo">PLC编号</param>
  3010. /// <param name="stationNameStr">工站全称</param>
  3011. /// <param name="stPLC_MesData"></param>
  3012. /// <param name="tagMesCommName"></param>
  3013. private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3014. {
  3015. Stopwatch stopwatch1 = new Stopwatch();
  3016. Stopwatch stopwatch2 = new Stopwatch();
  3017. try
  3018. {
  3019. stopwatch1.Start();
  3020. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3021. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3022. string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
  3023. string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
  3024. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3025. //载具码验证产品码
  3026. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3027. if (string.IsNullOrEmpty(strProductBarcode))
  3028. {
  3029. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3030. }
  3031. sn = strProductBarcode;
  3032. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3033. // 产品SN(物料码)校验
  3034. List<TestItem> item = new List<TestItem>();
  3035. stopwatch2.Start();
  3036. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3037. stopwatch2.Stop();
  3038. //指令执行结果 1:OK 110:失败
  3039. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3040. //进站结果写入PLC
  3041. CommandFromPLC resultToPlC = new CommandFromPLC();
  3042. resultToPlC.cmd = 0;
  3043. resultToPlC.cmdParam = 0; //指令参数
  3044. resultToPlC.cmdResult = mesResultFrmWeb;
  3045. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3046. }
  3047. catch (Exception ex)
  3048. {
  3049. string str = ex.StackTrace;
  3050. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3051. CommandFromPLC resultToPlC = new CommandFromPLC();
  3052. resultToPlC.cmd = 0;
  3053. resultToPlC.cmdParam = 0; //指令参数
  3054. resultToPlC.cmdResult = 110;
  3055. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3056. }
  3057. stopwatch1.Stop();
  3058. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3059. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3060. ProgressState = false;
  3061. }
  3062. /// <summary>
  3063. /// [S6] 顶盖装配设备 - 出站接口
  3064. /// </summary>
  3065. private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3066. {
  3067. Stopwatch stopwatch1 = new Stopwatch();
  3068. Stopwatch stopwatch2 = new Stopwatch();
  3069. try
  3070. {
  3071. stopwatch1.Start();
  3072. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3073. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3074. string processItem = stationName; // 测试项目
  3075. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3076. string supplierCode = ""; // 供应商代码
  3077. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3078. string batch_num = GlobalContext.BatchNumber; // 批次号
  3079. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3080. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3081. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3082. string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
  3083. string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
  3084. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3085. bool pass = a1Result == 1;
  3086. //根据载具码获取产品码
  3087. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3088. if (string.IsNullOrEmpty(strProductBarcode))
  3089. {
  3090. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3091. }
  3092. sn = strProductBarcode;
  3093. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3094. List<TestItem> items = new List<TestItem>();
  3095. items.Add(new TestItem()
  3096. {
  3097. Parameter_name = "载具码",
  3098. Parameter_value = CarrierBarcode,
  3099. Parameter_unit = ""
  3100. });
  3101. items.Add(new TestItem()
  3102. {
  3103. Parameter_name = "产品码",
  3104. Parameter_value = sn,
  3105. Parameter_unit = ""
  3106. });
  3107. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3108. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3109. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3110. stopwatch2.Start();
  3111. //进站结果写入PLC
  3112. CommandFromPLC resultToPlC = new CommandFromPLC();
  3113. resultToPlC.cmd = 0;
  3114. resultToPlC.cmdParam = 0; //指令参数
  3115. resultToPlC.cmdResult = mesResultFrmWeb;
  3116. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3117. stopwatch2.Stop();
  3118. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3119. //保存PLC返回MES数据到本地
  3120. ResponseMessage message = new ResponseMessage();
  3121. message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
  3122. stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
  3123. if (message.result == false)
  3124. {
  3125. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3126. }
  3127. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3128. }
  3129. catch (Exception ex)
  3130. {
  3131. stopwatch2.Start();
  3132. CommandFromPLC resultToPlC = new CommandFromPLC();
  3133. resultToPlC.cmd = 0;
  3134. resultToPlC.cmdParam = 0; //指令参数
  3135. resultToPlC.cmdResult = 110;
  3136. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3137. stopwatch2.Stop();
  3138. string str = ex.StackTrace;
  3139. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3140. }
  3141. stopwatch1.Stop();
  3142. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3143. ProgressState = false;
  3144. }
  3145. #endregion
  3146. #region S7
  3147. /// <summary>
  3148. /// [S7] 锁螺丝设备
  3149. /// </summary>
  3150. /// <param name="plcNo">PLC编号</param>
  3151. private void ReadStation_S7(int plcNo)
  3152. {
  3153. string stationCode = "[OP70]";
  3154. string stationName = "上盖板锁螺丝";
  3155. string stationNameStr = stationCode + stationName;
  3156. string tagBaseName = "g_OP70_MES"; //标签变量名称
  3157. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3158. string tagAgvCommName = "agvCommFrmPC";
  3159. string tagBarsetName = "BarcodeSet";
  3160. string tagScrewDataset = "screwDataset";
  3161. OP70_MesData_t stPLC_MesData; //PLC的MES数据
  3162. (int, string) result;
  3163. AtlasScrew atlasScrewLeft= new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort, 3000, 3000,"Left");
  3164. atlasScrewLeft.Initial();
  3165. AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort, 3000, 3000,"Right");
  3166. atlasScrewRight.Initial();
  3167. while (true)
  3168. {
  3169. try
  3170. {
  3171. if (!GlobalContext._IsCon_Funs1)
  3172. {
  3173. UpdatePLCMonitor(1, plcNo, 0);
  3174. continue;
  3175. }
  3176. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3177. {
  3178. Stopwatch stopwatch1 = new Stopwatch();
  3179. Stopwatch stopwatch2 = new Stopwatch();
  3180. stopwatch1.Start();
  3181. stopwatch2.Start();
  3182. #region 一次性读取所有数据
  3183. // 一次性读取所有数据
  3184. result = FunsEip[plcNo].Read_SingleTag<OP70_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3185. if (result.Item1 != 0)
  3186. {
  3187. //richTextBox1.AppendText("\n" + strRet);
  3188. }
  3189. else
  3190. {
  3191. //richTextBox1.AppendText("\n" + "读取成功");
  3192. }
  3193. #endregion 一次性读取所有数据
  3194. stopwatch2.Stop();
  3195. #region 左边进站
  3196. try
  3197. {
  3198. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3199. {
  3200. lock (lockObj)
  3201. {
  3202. if (!ProgressState)
  3203. {
  3204. ProgressState = true;
  3205. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, tagBaseName + ".Left." + tagBarsetName,"Left", out ProgressState, atlasScrewLeft));
  3206. }
  3207. }
  3208. }
  3209. }
  3210. catch (Exception ex)
  3211. {
  3212. ProgressState = false;
  3213. string str = ex.StackTrace;
  3214. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3215. }
  3216. #endregion 左边进站
  3217. #region 左边出站
  3218. try
  3219. {
  3220. if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3221. {
  3222. lock (lockObj)
  3223. {
  3224. if (!ProgressState)
  3225. {
  3226. ProgressState = true;
  3227. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left, tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left", out ProgressState));
  3228. stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
  3229. }
  3230. }
  3231. }
  3232. }
  3233. catch (Exception ex)
  3234. {
  3235. ProgressState = false;
  3236. string str = ex.StackTrace;
  3237. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3238. }
  3239. #endregion 左边出站
  3240. #region 右边进站
  3241. try
  3242. {
  3243. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3244. {
  3245. lock (lockObj)
  3246. {
  3247. if (!ProgressState)
  3248. {
  3249. ProgressState = true;
  3250. Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, tagBaseName + ".Right" + tagBarsetName,"Right", out ProgressState, atlasScrewRight));
  3251. }
  3252. }
  3253. }
  3254. }
  3255. catch (Exception ex)
  3256. {
  3257. ProgressState = false;
  3258. string str = ex.StackTrace;
  3259. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3260. }
  3261. #endregion 右边进站
  3262. #region 右边出站
  3263. try
  3264. {
  3265. if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3266. {
  3267. lock (lockObj)
  3268. {
  3269. if (!ProgressState)
  3270. {
  3271. ProgressState = true;
  3272. Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right, tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right", out ProgressState));
  3273. stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
  3274. }
  3275. }
  3276. }
  3277. }
  3278. catch (Exception ex)
  3279. {
  3280. ProgressState = false;
  3281. string str = ex.StackTrace;
  3282. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3283. }
  3284. #endregion 右边出站
  3285. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3286. stopwatch1.Stop();
  3287. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3288. }
  3289. else
  3290. {
  3291. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3292. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3293. FunsEip[plcNo].Connect(); // 重连
  3294. }
  3295. }
  3296. catch (Exception ex)
  3297. {
  3298. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3299. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3300. }
  3301. Thread.Sleep(IntervalReadPLC);
  3302. }
  3303. }
  3304. /// <summary>
  3305. /// [S7] 锁螺丝设备 - 进站
  3306. /// </summary>
  3307. /// <param name="plcNo">PLC编号</param>
  3308. /// <param name="stationNameStr">工站全称</param>
  3309. /// <param name="stPLC_MesData"></param>
  3310. /// <param name="tagMesCommName"></param>
  3311. private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string tagBarsetName, string direction,out bool ProgressState, AtlasScrew atlasScrew)
  3312. {
  3313. Stopwatch stopwatch1 = new Stopwatch();
  3314. Stopwatch stopwatch2 = new Stopwatch();
  3315. string atlasSn=string.Empty;
  3316. try
  3317. {
  3318. stopwatch1.Start();
  3319. AddMessage(LogType.Info, stationNameStr +"_"+ direction+"_进站开始");
  3320. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3321. string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
  3322. string StationId = string.Empty; // 工位ID(可配置)
  3323. if (direction == "Left")
  3324. {
  3325. StationId = GlobalContext.S7_StationId_1;
  3326. }
  3327. if (direction == "Right")
  3328. {
  3329. StationId = GlobalContext.S7_StationId_2;
  3330. }
  3331. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3332. //载具码验证产品码
  3333. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3334. if (string.IsNullOrEmpty(strProductBarcode))
  3335. {
  3336. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3337. }
  3338. sn = strProductBarcode;
  3339. atlasSn= strProductBarcode;
  3340. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3341. if (direction == "Left")
  3342. {
  3343. isCollectingFlagLeft = false;//采集螺丝数据结束
  3344. }
  3345. if (direction == "Right")
  3346. {
  3347. isCollectingFlagRight = false;//采集螺丝数据结束
  3348. }
  3349. // 产品SN(物料码)校验
  3350. List<TestItem> item = new List<TestItem>();
  3351. stopwatch2.Start();
  3352. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3353. stopwatch2.Stop();
  3354. //指令执行结果 1:OK 110:失败
  3355. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3356. //进站结果写入PLC
  3357. CommandFromPLC resultToPlC = new CommandFromPLC();
  3358. resultToPlC.cmd = 0;
  3359. resultToPlC.cmdParam = 0; //指令参数
  3360. resultToPlC.cmdResult = mesResultFrmWeb;
  3361. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3362. }
  3363. catch (Exception ex)
  3364. {
  3365. string str = ex.StackTrace;
  3366. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3367. CommandFromPLC resultToPlC = new CommandFromPLC();
  3368. resultToPlC.cmd = 0;
  3369. resultToPlC.cmdParam = 0; //指令参数
  3370. resultToPlC.cmdResult = 110;
  3371. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3372. }
  3373. stopwatch1.Stop();
  3374. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
  3375. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3376. ProgressState = false;
  3377. //开始采集螺丝数据
  3378. if (direction == "Left")
  3379. {
  3380. isCollectingFlagLeft = true;
  3381. CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
  3382. }
  3383. if (direction == "Right")
  3384. {
  3385. isCollectingFlagRight = true;
  3386. CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
  3387. }
  3388. }
  3389. /// <summary>
  3390. /// [S7] 锁螺丝设备 - 出站
  3391. /// </summary>
  3392. private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, string direction, out bool ProgressState)
  3393. {
  3394. Stopwatch stopwatch1 = new Stopwatch();
  3395. Stopwatch stopwatch2 = new Stopwatch();
  3396. try
  3397. {
  3398. stopwatch1.Start();
  3399. AddMessage(LogType.Info, stationNameStr +"_"+ direction+ "_出站开始");
  3400. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3401. string processItem = stationName; // 测试项目
  3402. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3403. string supplierCode = ""; // 供应商代码
  3404. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3405. string batch_num = GlobalContext.BatchNumber; // 批次号
  3406. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3407. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3408. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3409. string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
  3410. string StationId = string.Empty; // 工位ID(可配置)
  3411. if (direction == "Left")
  3412. {
  3413. StationId = GlobalContext.S7_StationId_1;
  3414. }
  3415. if (direction == "Right")
  3416. {
  3417. StationId = GlobalContext.S7_StationId_2;
  3418. }
  3419. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3420. a1Result = 1;
  3421. bool pass = a1Result == 1;
  3422. //根据载具码获取产品码
  3423. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3424. if (string.IsNullOrEmpty(strProductBarcode))
  3425. {
  3426. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3427. }
  3428. sn = strProductBarcode;
  3429. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3430. List<TestItem> items = new List<TestItem>();
  3431. items.Add(new TestItem()
  3432. {
  3433. Parameter_name = "载具码",
  3434. Parameter_value = CarrierBarcode,
  3435. Parameter_unit = ""
  3436. });
  3437. items.Add(new TestItem()
  3438. {
  3439. Parameter_name = "产品码",
  3440. Parameter_value = sn,
  3441. Parameter_unit = ""
  3442. });
  3443. int result1 = 1;
  3444. if (direction == "Right")
  3445. {
  3446. SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3447. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3448. }
  3449. //if (direction == "Left")
  3450. //{
  3451. // isCollectingFlagLeft = false;//采集螺丝数据结束
  3452. //}
  3453. //if (direction == "Right")
  3454. //{
  3455. // isCollectingFlagRight = false;//采集螺丝数据结束
  3456. //}
  3457. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3458. stopwatch2.Start();
  3459. //进站结果写入PLC
  3460. CommandFromPLC resultToPlC = new CommandFromPLC();
  3461. resultToPlC.cmd = 0;
  3462. resultToPlC.cmdParam = 0; //指令参数
  3463. resultToPlC.cmdResult = mesResultFrmWeb;
  3464. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3465. stopwatch2.Stop();
  3466. AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
  3467. //保存PLC返回MES数据到本地
  3468. ResponseMessage message = new ResponseMessage();
  3469. if (direction == "Left")
  3470. {
  3471. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3472. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3473. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3474. message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
  3475. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3476. if (message.result == false)
  3477. {
  3478. AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
  3479. }
  3480. }
  3481. if (direction == "Right")
  3482. {
  3483. string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
  3484. string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
  3485. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3486. message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
  3487. strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
  3488. if (message.result == false)
  3489. {
  3490. AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
  3491. }
  3492. }
  3493. //保存螺丝数据到txt
  3494. (int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes, stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
  3495. if (result.Item1 != 0)
  3496. {
  3497. AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
  3498. }
  3499. AddMessage(LogType.Info, stationNameStr + "_"+ direction+"_保存加工数据到本地成功");
  3500. }
  3501. catch (Exception ex)
  3502. {
  3503. stopwatch2.Start();
  3504. CommandFromPLC resultToPlC = new CommandFromPLC();
  3505. resultToPlC.cmd = 0;
  3506. resultToPlC.cmdParam = 0; //指令参数
  3507. resultToPlC.cmdResult = 110;
  3508. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3509. stopwatch2.Stop();
  3510. string str = ex.StackTrace;
  3511. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3512. }
  3513. stopwatch1.Stop();
  3514. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3515. ProgressState = false;
  3516. }
  3517. #endregion
  3518. #region S8
  3519. /// <summary>
  3520. /// [S8] 3D螺丝高度检测设备
  3521. /// </summary>
  3522. /// <param name="plcNo">PLC编号</param>
  3523. private void ReadStation_S8(int plcNo)
  3524. {
  3525. string stationCode = "[OP80]";
  3526. string stationName = "NG下料";
  3527. string stationNameStr = stationCode + stationName;
  3528. string tagBaseName = "g_OP80_MES"; //标签变量名称
  3529. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3530. string tagAgvCommName = "agvCommFrmPC";
  3531. string tagBarsetName = "BarcodeSet";
  3532. OP80_MesData_t stPLC_MesData; //PLC的MES数据
  3533. (int, string) result;
  3534. while (true)
  3535. {
  3536. try
  3537. {
  3538. if (!GlobalContext._IsCon_Funs1)
  3539. {
  3540. UpdatePLCMonitor(1, plcNo, 0);
  3541. continue;
  3542. }
  3543. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3544. {
  3545. Stopwatch stopwatch1 = new Stopwatch();
  3546. Stopwatch stopwatch2 = new Stopwatch();
  3547. stopwatch1.Start();
  3548. stopwatch2.Start();
  3549. #region 一次性读取所有数据
  3550. // 一次性读取所有数据
  3551. result = FunsEip[plcNo].Read_SingleTag<OP80_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3552. if (result.Item1 != 0)
  3553. {
  3554. //richTextBox1.AppendText("\n" + strRet);
  3555. }
  3556. else
  3557. {
  3558. //richTextBox1.AppendText("\n" + "读取成功");
  3559. }
  3560. #endregion 一次性读取所有数据
  3561. stopwatch2.Stop();
  3562. #region 进站
  3563. try
  3564. {
  3565. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3566. {
  3567. lock (lockObj)
  3568. {
  3569. if (!ProgressState)
  3570. {
  3571. ProgressState = true;
  3572. Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3573. }
  3574. }
  3575. }
  3576. }
  3577. catch (Exception ex)
  3578. {
  3579. ProgressState = false;
  3580. string str = ex.StackTrace;
  3581. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3582. }
  3583. #endregion 进站
  3584. #region 出站
  3585. try
  3586. {
  3587. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3588. {
  3589. lock (lockObj)
  3590. {
  3591. if (!ProgressState)
  3592. {
  3593. ProgressState = true;
  3594. Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3595. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3596. }
  3597. }
  3598. }
  3599. }
  3600. catch (Exception ex)
  3601. {
  3602. ProgressState = false;
  3603. string str = ex.StackTrace;
  3604. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3605. }
  3606. #endregion 出站
  3607. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3608. stopwatch1.Stop();
  3609. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3610. }
  3611. else
  3612. {
  3613. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3614. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3615. FunsEip[plcNo].Connect(); // 重连
  3616. }
  3617. }
  3618. catch (Exception ex)
  3619. {
  3620. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3621. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3622. }
  3623. Thread.Sleep(IntervalReadPLC);
  3624. }
  3625. }
  3626. /// <summary>
  3627. /// [S8] 3D螺丝高度检测设备 - 进站
  3628. /// </summary>
  3629. /// <param name="plcNo">PLC编号</param>
  3630. /// <param name="stationNameStr">工站全称</param>
  3631. /// <param name="stPLC_MesData"></param>
  3632. /// <param name="tagMesCommName"></param>
  3633. private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3634. {
  3635. Stopwatch stopwatch1 = new Stopwatch();
  3636. Stopwatch stopwatch2 = new Stopwatch();
  3637. try
  3638. {
  3639. stopwatch1.Start();
  3640. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3641. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3642. string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
  3643. string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
  3644. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3645. //载具码验证产品码
  3646. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3647. if (string.IsNullOrEmpty(strProductBarcode))
  3648. {
  3649. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3650. }
  3651. sn = strProductBarcode;
  3652. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3653. // 产品SN(物料码)校验
  3654. List<TestItem> item = new List<TestItem>();
  3655. stopwatch2.Start();
  3656. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3657. stopwatch2.Stop();
  3658. //指令执行结果 1:OK 110:失败
  3659. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3660. //进站结果写入PLC
  3661. CommandFromPLC resultToPlC = new CommandFromPLC();
  3662. resultToPlC.cmd = 0;
  3663. resultToPlC.cmdParam = 0; //指令参数
  3664. resultToPlC.cmdResult = mesResultFrmWeb;
  3665. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3666. }
  3667. catch (Exception ex)
  3668. {
  3669. string str = ex.StackTrace;
  3670. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3671. CommandFromPLC resultToPlC = new CommandFromPLC();
  3672. resultToPlC.cmd = 0;
  3673. resultToPlC.cmdParam = 0; //指令参数
  3674. resultToPlC.cmdResult = 110;
  3675. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3676. }
  3677. stopwatch1.Stop();
  3678. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3679. ProgressState = false;
  3680. }
  3681. /// <summary>
  3682. /// [S8] 3D螺丝高度检测设备 - 出站接口
  3683. /// </summary>
  3684. private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3685. {
  3686. Stopwatch stopwatch1 = new Stopwatch();
  3687. Stopwatch stopwatch2 = new Stopwatch();
  3688. try
  3689. {
  3690. stopwatch1.Start();
  3691. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3692. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3693. string processItem = stationName; // 测试项目
  3694. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3695. string supplierCode = ""; // 供应商代码
  3696. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3697. string batch_num = GlobalContext.BatchNumber; // 批次号
  3698. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3699. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3700. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3701. string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
  3702. string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
  3703. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3704. bool pass = a1Result == 1;
  3705. //根据载具码获取产品码
  3706. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3707. if (string.IsNullOrEmpty(strProductBarcode))
  3708. {
  3709. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3710. }
  3711. sn = strProductBarcode;
  3712. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3713. List<TestItem> items = new List<TestItem>();
  3714. items.Add(new TestItem()
  3715. {
  3716. Parameter_name = "载具码",
  3717. Parameter_value = CarrierBarcode,
  3718. Parameter_unit = ""
  3719. });
  3720. items.Add(new TestItem()
  3721. {
  3722. Parameter_name = "产品码",
  3723. Parameter_value = sn,
  3724. Parameter_unit = ""
  3725. });
  3726. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3727. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3728. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3729. stopwatch2.Start();
  3730. //进站结果写入PLC
  3731. CommandFromPLC resultToPlC = new CommandFromPLC();
  3732. resultToPlC.cmd = 0;
  3733. resultToPlC.cmdParam = 0; //指令参数
  3734. resultToPlC.cmdResult = mesResultFrmWeb;
  3735. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3736. stopwatch2.Stop();
  3737. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3738. //保存PLC返回MES数据到本地
  3739. ResponseMessage message = new ResponseMessage();
  3740. string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
  3741. string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
  3742. message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
  3743. if (message.result == false)
  3744. {
  3745. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3746. }
  3747. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3748. }
  3749. catch (Exception ex)
  3750. {
  3751. stopwatch2.Start();
  3752. CommandFromPLC resultToPlC = new CommandFromPLC();
  3753. resultToPlC.cmd = 0;
  3754. resultToPlC.cmdParam = 0; //指令参数
  3755. resultToPlC.cmdResult = 110;
  3756. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3757. stopwatch2.Stop();
  3758. string str = ex.StackTrace;
  3759. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3760. }
  3761. stopwatch1.Stop();
  3762. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3763. ProgressState = false;
  3764. }
  3765. #endregion
  3766. #region S9
  3767. /// <summary>
  3768. /// [S9] 下料设备
  3769. /// </summary>
  3770. /// <param name="plcNo">PLC编号</param>
  3771. private void ReadStation_S9(int plcNo)
  3772. {
  3773. string stationCode = "[OP90]";
  3774. string stationName = "半成品下料";
  3775. string stationNameStr = stationCode + stationName;
  3776. string tagBaseName = "g_OP90_MES"; //标签变量名称
  3777. string tagMesCommName = "mesCommToPC"; //标签变量名称
  3778. string tagAgvCommName = "agvCommFrmPC";
  3779. string tagBarsetName = "BarcodeSet";
  3780. OP90_MesData_t stPLC_MesData; //PLC的MES数据
  3781. (int, string) result;
  3782. while (true)
  3783. {
  3784. try
  3785. {
  3786. if (!GlobalContext._IsCon_Funs1)
  3787. {
  3788. UpdatePLCMonitor(1, plcNo, 0);
  3789. continue;
  3790. }
  3791. if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
  3792. {
  3793. Stopwatch stopwatch1 = new Stopwatch();
  3794. Stopwatch stopwatch2 = new Stopwatch();
  3795. stopwatch1.Start();
  3796. stopwatch2.Start();
  3797. #region 一次性读取所有数据
  3798. // 一次性读取所有数据
  3799. result = FunsEip[plcNo].Read_SingleTag<OP90_MesData_t>(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
  3800. if (result.Item1 != 0)
  3801. {
  3802. //richTextBox1.AppendText("\n" + strRet);
  3803. }
  3804. else
  3805. {
  3806. //richTextBox1.AppendText("\n" + "读取成功");
  3807. }
  3808. #endregion 一次性读取所有数据
  3809. stopwatch2.Stop();
  3810. #region 进站
  3811. try
  3812. {
  3813. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
  3814. {
  3815. lock (lockObj)
  3816. {
  3817. if (!ProgressState)
  3818. {
  3819. ProgressState = true;
  3820. Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
  3821. }
  3822. }
  3823. }
  3824. }
  3825. catch (Exception ex)
  3826. {
  3827. ProgressState = false;
  3828. string str = ex.StackTrace;
  3829. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3830. }
  3831. #endregion 进站
  3832. #region 出站
  3833. try
  3834. {
  3835. if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
  3836. {
  3837. lock (lockObj)
  3838. {
  3839. if (!ProgressState)
  3840. {
  3841. ProgressState = true;
  3842. Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, stationCode, stationName, out ProgressState));
  3843. stPLC_MesData.mesCommFrmPLC.cmd = 0;
  3844. }
  3845. }
  3846. }
  3847. }
  3848. catch (Exception ex)
  3849. {
  3850. ProgressState = false;
  3851. string str = ex.StackTrace;
  3852. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3853. }
  3854. #endregion 出站
  3855. UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  3856. stopwatch1.Stop();
  3857. //OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  3858. }
  3859. else
  3860. {
  3861. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3862. AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  3863. FunsEip[plcNo].Connect(); // 重连
  3864. }
  3865. }
  3866. catch (Exception ex)
  3867. {
  3868. UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  3869. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  3870. }
  3871. Thread.Sleep(IntervalReadPLC);
  3872. }
  3873. }
  3874. /// <summary>
  3875. /// [S9] 下料设备 - 进站
  3876. /// </summary>
  3877. /// <param name="plcNo">PLC编号</param>
  3878. /// <param name="stationNameStr">工站全称</param>
  3879. /// <param name="stPLC_MesData"></param>
  3880. /// <param name="tagMesCommName"></param>
  3881. private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string tagBarsetName, out bool ProgressState)
  3882. {
  3883. Stopwatch stopwatch1 = new Stopwatch();
  3884. Stopwatch stopwatch2 = new Stopwatch();
  3885. try
  3886. {
  3887. stopwatch1.Start();
  3888. AddMessage(LogType.Info, stationNameStr + "_进站开始");
  3889. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
  3890. string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
  3891. string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
  3892. string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
  3893. //载具码验证产品码
  3894. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
  3895. if (string.IsNullOrEmpty(strProductBarcode))
  3896. {
  3897. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3898. }
  3899. sn = strProductBarcode;
  3900. AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
  3901. // 产品SN(物料码)校验
  3902. List<TestItem> item = new List<TestItem>();
  3903. stopwatch2.Start();
  3904. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, MachineId, StationId);
  3905. stopwatch2.Stop();
  3906. //指令执行结果 1:OK 110:失败
  3907. byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
  3908. //进站结果写入PLC
  3909. CommandFromPLC resultToPlC = new CommandFromPLC();
  3910. resultToPlC.cmd = 0;
  3911. resultToPlC.cmdParam = 0; //指令参数
  3912. resultToPlC.cmdResult = mesResultFrmWeb;
  3913. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3914. }
  3915. catch (Exception ex)
  3916. {
  3917. string str = ex.StackTrace;
  3918. AddMessage(LogType.Error, $"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  3919. CommandFromPLC resultToPlC = new CommandFromPLC();
  3920. resultToPlC.cmd = 0;
  3921. resultToPlC.cmdParam = 0; //指令参数
  3922. resultToPlC.cmdResult = 110;
  3923. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3924. }
  3925. stopwatch1.Stop();
  3926. AddMessage(LogType.Info, stationNameStr + "_进站结束");
  3927. AddMessage(LogType.Info, stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  3928. ProgressState = false;
  3929. }
  3930. /// <summary>
  3931. /// [S9] 下料设备 - 出站接口
  3932. /// </summary>
  3933. private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName, string stationCode, string stationName, out bool ProgressState)
  3934. {
  3935. Stopwatch stopwatch1 = new Stopwatch();
  3936. Stopwatch stopwatch2 = new Stopwatch();
  3937. try
  3938. {
  3939. stopwatch1.Start();
  3940. AddMessage(LogType.Info, stationNameStr + "_出站开始");
  3941. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  3942. string processItem = stationName; // 测试项目
  3943. string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  3944. string supplierCode = ""; // 供应商代码
  3945. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  3946. string batch_num = GlobalContext.BatchNumber; // 批次号
  3947. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  3948. string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
  3949. string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
  3950. string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
  3951. string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
  3952. int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
  3953. bool pass = a1Result == 1;
  3954. //根据载具码获取产品码
  3955. string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
  3956. if (string.IsNullOrEmpty(strProductBarcode))
  3957. {
  3958. AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
  3959. }
  3960. sn = strProductBarcode;
  3961. AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
  3962. List<TestItem> items = new List<TestItem>();
  3963. items.Add(new TestItem()
  3964. {
  3965. Parameter_name = "载具码",
  3966. Parameter_value = CarrierBarcode,
  3967. Parameter_unit = ""
  3968. });
  3969. items.Add(new TestItem()
  3970. {
  3971. Parameter_name = "产品码",
  3972. Parameter_value = sn,
  3973. Parameter_unit = ""
  3974. });
  3975. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  3976. , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "");
  3977. byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
  3978. stopwatch2.Start();
  3979. //进站结果写入PLC
  3980. CommandFromPLC resultToPlC = new CommandFromPLC();
  3981. resultToPlC.cmd = 0;
  3982. resultToPlC.cmdParam = 0; //指令参数
  3983. resultToPlC.cmdResult = mesResultFrmWeb;
  3984. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  3985. stopwatch2.Stop();
  3986. AddMessage(LogType.Info, stationNameStr + "_出站结束");
  3987. //保存PLC返回MES数据到本地
  3988. ResponseMessage message = new ResponseMessage();
  3989. message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.nRemainCount);
  3990. if (message.result == false)
  3991. {
  3992. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
  3993. }
  3994. AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
  3995. if (result1 == 1)
  3996. {
  3997. //载具码解除绑定
  3998. message = SQLHelper.DelCarrierBind(CarrierBarcode);
  3999. if (message.result == false)
  4000. {
  4001. AddMessage(LogType.Error, message.text);
  4002. }
  4003. }
  4004. }
  4005. catch (Exception ex)
  4006. {
  4007. stopwatch2.Start();
  4008. CommandFromPLC resultToPlC = new CommandFromPLC();
  4009. resultToPlC.cmd = 0;
  4010. resultToPlC.cmdParam = 0; //指令参数
  4011. resultToPlC.cmdResult = 110;
  4012. WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
  4013. stopwatch2.Stop();
  4014. string str = ex.StackTrace;
  4015. AddMessage(LogType.Error, $"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4016. }
  4017. stopwatch1.Stop();
  4018. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4019. ProgressState = false;
  4020. }
  4021. #endregion
  4022. #endregion Xiaomi
  4023. #region PLC1 张超凡
  4024. #region [S1] Tray盘上料装备(板测)
  4025. /// <summary>
  4026. /// S1工位的数据- 触发信号上次的值
  4027. /// </summary>
  4028. private Dictionary<string, object> s1PLCSignal_Old = new Dictionary<string, object>();
  4029. /// <summary>
  4030. /// S1工位的数据(含触发信号)
  4031. /// </summary>
  4032. private Dictionary<string, object> s1PLCData = new Dictionary<string, object>();
  4033. /// <summary>
  4034. /// S1工位的数据- 回写点位
  4035. /// </summary>
  4036. private Dictionary<string, WriteToPLC_Flag> s1PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  4037. ///// <summary>
  4038. ///// 触发信号
  4039. ///// </summary>
  4040. //private ManualResetEvent[] MreTasks;
  4041. /// <summary>
  4042. /// [S1] Tray盘上料装备(板测)
  4043. /// </summary>
  4044. /// <param name="plcNo">PLC编号</param>
  4045. //private void ReadStation_S1(int plcNo)
  4046. //{
  4047. // // [S1] Tray盘上料装备
  4048. // // [S2] FCT
  4049. // // [S3] 值板机
  4050. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  4051. // // [S5] Tray盘下料装备
  4052. // string stationCode = "[S1]";
  4053. // string stationName = "Tray盘上料装备";
  4054. // string stationNameStr = stationCode + stationName;
  4055. // #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4056. // // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4057. // s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4058. // s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4059. // s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4060. // s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4061. // s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4062. // s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4063. // s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  4064. // s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4065. // s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  4066. // // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4067. // s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
  4068. // s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
  4069. // s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
  4070. // s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
  4071. // s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
  4072. // s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
  4073. // s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
  4074. // s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
  4075. // s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
  4076. // s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
  4077. // s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
  4078. // s1PLCData.Add("a1Result", 0); // 产品结果
  4079. // s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
  4080. // s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
  4081. // s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
  4082. // s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
  4083. // s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
  4084. // s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  4085. // s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
  4086. // s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
  4087. // s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
  4088. // s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
  4089. // s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
  4090. // s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  4091. // s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
  4092. // s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
  4093. // s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  4094. // s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
  4095. // s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
  4096. // #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
  4097. // while (IsRun)
  4098. // {
  4099. // try
  4100. // {
  4101. // if (!GlobalContext._IsCon_Funs1)
  4102. // {
  4103. // UpdatePLCMonitor(1, plcNo, 0);
  4104. // continue;
  4105. // }
  4106. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  4107. // {
  4108. // Stopwatch stopwatch1 = new Stopwatch();
  4109. // Stopwatch stopwatch2 = new Stopwatch();
  4110. // stopwatch1.Start();
  4111. // stopwatch2.Start();
  4112. // #region 一次性读取所有数据
  4113. // // 一次性读取所有数据
  4114. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  4115. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  4116. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  4117. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
  4118. // int[] datas = data1.Concat(data2).ToArray();
  4119. // datas = datas.Concat(data3).ToArray();
  4120. // datas = datas.Concat(data4).ToArray();
  4121. // s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
  4122. // s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
  4123. // int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
  4124. // s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
  4125. // s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
  4126. // s1PLCData["a1MES_FLAG_Check"] = datas[77];
  4127. // int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
  4128. // s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
  4129. // s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
  4130. // s1PLCData["a1MES_FLAG"] = datas[109];
  4131. // int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
  4132. // s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
  4133. // int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
  4134. // s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
  4135. // int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
  4136. // s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
  4137. // s1PLCData["a1Result"] = datas[170];
  4138. // s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
  4139. // s1PLCData["a1MES_FLAG_ICT"] = datas[182];
  4140. // int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
  4141. // s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
  4142. // int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
  4143. // s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
  4144. // int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
  4145. // s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
  4146. // s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
  4147. // s1PLCData["a1OEEMES_FLAG"] = datas[254];
  4148. // int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
  4149. // s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
  4150. // int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
  4151. // s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
  4152. // s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
  4153. // s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
  4154. // s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
  4155. // s1PLCData["a1AGVUpStart"] = datas[308];
  4156. // s1PLCData["a1AGVUpEnd"] = datas[309];
  4157. // s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
  4158. // s1PLCData["a1AGVDownStart"] = datas[321];
  4159. // s1PLCData["a1AGVDownEnd"] = datas[322];
  4160. // #endregion 一次性读取所有数据
  4161. // stopwatch2.Stop();
  4162. // #region 回写操作,写后清空flag
  4163. // PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
  4164. // #endregion 回写操作,写后清空flag
  4165. // #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4166. // try
  4167. // {
  4168. // int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
  4169. // int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
  4170. // int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
  4171. // if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
  4172. // {
  4173. // if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
  4174. // Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
  4175. // else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
  4176. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  4177. // s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
  4178. // }
  4179. // }
  4180. // catch (Exception ex)
  4181. // {
  4182. // // 6代表上位机报警
  4183. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6);
  4184. // string str = ex.StackTrace;
  4185. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4186. // }
  4187. // #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
  4188. // #region 上料进站校验
  4189. // try
  4190. // {
  4191. // int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
  4192. // int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
  4193. // int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
  4194. // if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
  4195. // {
  4196. // if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
  4197. // Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  4198. // else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
  4199. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  4200. // s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
  4201. // }
  4202. // }
  4203. // catch (Exception ex)
  4204. // {
  4205. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4206. // string str = ex.StackTrace;
  4207. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4208. // }
  4209. // #endregion 上料进站校验
  4210. // #region Tray盘上料装备-出站接口
  4211. // try
  4212. // {
  4213. // int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
  4214. // int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
  4215. // int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
  4216. // if (a1PLC_FLAG != a1PLC_FLAGOld)
  4217. // {
  4218. // if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
  4219. // Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  4220. // else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
  4221. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)0);
  4222. // s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
  4223. // }
  4224. // }
  4225. // catch (Exception ex)
  4226. // {
  4227. // Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)6); // 6代表上位机报警
  4228. // string str = ex.StackTrace;
  4229. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4230. // }
  4231. // #endregion Tray盘上料装备-出站接口
  4232. // #region Tray盘上料装备-将SN发给ICT标机
  4233. // try
  4234. // {
  4235. // int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
  4236. // int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
  4237. // int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
  4238. // if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
  4239. // {
  4240. // if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
  4241. // Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
  4242. // else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
  4243. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)0);
  4244. // s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
  4245. // }
  4246. // }
  4247. // catch (Exception ex)
  4248. // {
  4249. // Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4250. // string str = ex.StackTrace;
  4251. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4252. // }
  4253. // #endregion Tray盘上料装备-将SN发给ICT标机
  4254. // #region Tray盘上料装备-点检数据
  4255. // //try
  4256. // //{
  4257. // // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
  4258. // // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
  4259. // // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
  4260. // // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
  4261. // // if (pLC_Flag && !mES_Flag) // 1 0
  4262. // // {
  4263. // // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
  4264. // // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
  4265. // // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
  4266. // // }
  4267. // // else if (!pLC_Flag && mES_Flag) // 0 1
  4268. // // {
  4269. // // // 清空写给PLC的数据
  4270. // // // MES_Flag重置为0
  4271. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
  4272. // // }
  4273. // //}
  4274. // //catch (Exception ex)
  4275. // //{
  4276. // // // MES_Flag 为2上位机报错
  4277. // // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4278. // // string str = ex.StackTrace;
  4279. // // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4280. // //}
  4281. // #endregion Tray盘上料装备-点检数据
  4282. // #region 节拍接口
  4283. // try
  4284. // {
  4285. // int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
  4286. // int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
  4287. // int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
  4288. // if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
  4289. // {
  4290. // if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
  4291. // Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  4292. // else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
  4293. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)0); //
  4294. // s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
  4295. // }
  4296. // }
  4297. // catch (Exception ex)
  4298. // {
  4299. // Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4300. // string str = ex.StackTrace;
  4301. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4302. // }
  4303. // #endregion 节拍接口
  4304. // #region AGV上料
  4305. // // AGV上料叫AGV信号
  4306. // try
  4307. // {
  4308. // int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
  4309. // int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
  4310. // if (a1AGVUpCall != a1AGVUpCallOld)
  4311. // {
  4312. // if (a1AGVUpCall == 1) // 0->1
  4313. // Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  4314. // s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
  4315. // }
  4316. // }
  4317. // catch (Exception ex)
  4318. // {
  4319. // Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4320. // string str = ex.StackTrace;
  4321. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4322. // }
  4323. // // AGV上料完成信号
  4324. // try
  4325. // {
  4326. // int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
  4327. // int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
  4328. // if (a1AGVUpEnd != a1AGVUpEndOld)
  4329. // {
  4330. // if (a1AGVUpEnd == 1) // 0->1
  4331. // Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  4332. // s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
  4333. // }
  4334. // }
  4335. // catch (Exception ex)
  4336. // {
  4337. // Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  4338. // string str = ex.StackTrace;
  4339. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4340. // }
  4341. // #endregion AGV上料
  4342. // #region AGV下料
  4343. // // AGV下料叫agv信号
  4344. // try
  4345. // {
  4346. // int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
  4347. // int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
  4348. // if (a1AGVDownCall != a1AGVDownCallOld)
  4349. // {
  4350. // if (a1AGVDownCall == 1) // 0->1
  4351. // Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  4352. // s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
  4353. // }
  4354. // }
  4355. // catch (Exception ex)
  4356. // {
  4357. // Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  4358. // string str = ex.StackTrace;
  4359. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4360. // }
  4361. // // AGV下料完成信号
  4362. // try
  4363. // {
  4364. // int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
  4365. // int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
  4366. // if (a1AGVDownEnd != a1AGVDownEndOld)
  4367. // {
  4368. // if (a1AGVDownEnd == 1) // 0->1
  4369. // Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  4370. // s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
  4371. // }
  4372. // }
  4373. // catch (Exception ex)
  4374. // {
  4375. // Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  4376. // string str = ex.StackTrace;
  4377. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4378. // }
  4379. // #endregion AGV下料
  4380. // #region 心跳
  4381. // try
  4382. // {
  4383. // short states = 0;
  4384. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  4385. // }
  4386. // catch (Exception ex)
  4387. // {
  4388. // string str = ex.StackTrace;
  4389. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4390. // }
  4391. // #endregion 心跳
  4392. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  4393. // stopwatch1.Stop();
  4394. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  4395. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  4396. // }
  4397. // else
  4398. // {
  4399. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4400. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  4401. // Funs[plcNo].Connect(); // 重连
  4402. // }
  4403. // }
  4404. // catch (Exception ex)
  4405. // {
  4406. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  4407. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  4408. // Funs[plcNo].ReConnect();
  4409. // }
  4410. // Thread.Sleep(IntervalReadPLC);
  4411. // }
  4412. //}
  4413. /// <summary>
  4414. /// [S1] Tray盘上料装备(板测)- 载具进站查询状态
  4415. /// </summary>
  4416. /// <param name="plcNo">PLC编号</param>
  4417. /// <param name="stationNameStr">工站全称</param>
  4418. private void S1载具进站查询状态(int plcNo, string stationNameStr)
  4419. {
  4420. Stopwatch stopwatch1 = new Stopwatch();
  4421. Stopwatch stopwatch2 = new Stopwatch();
  4422. try
  4423. {
  4424. stopwatch1.Start();
  4425. string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
  4426. sn = sn.Replace("\0", "");
  4427. #region 查询载具上的产品信息
  4428. string cavityData = string.Empty;
  4429. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  4430. if (string.IsNullOrEmpty(cavityData))
  4431. cavityData = "";
  4432. if (snResult != 0)
  4433. {
  4434. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4435. writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
  4436. writeToPLC_Flag1.Adress = 2003;
  4437. writeToPLC_Flag1.Value = (short)6;
  4438. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
  4439. stopwatch1.Stop();
  4440. AddMessage(LogType.Info, stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  4441. return;
  4442. }
  4443. #endregion 查询载具上的产品信息
  4444. string[] cavitySNs = cavityData.Split('.');
  4445. string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
  4446. string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
  4447. short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
  4448. short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
  4449. if (cavitySNs != null && cavitySNs.Length >= 2)
  4450. {
  4451. a1CavitySN1_VehicleStates = cavitySNs[0];
  4452. a1CavitySN2_VehicleStates = cavitySNs[1];
  4453. a1CavityResult1_VehicleStates = 2;
  4454. a1CavityResult2_VehicleStates = 2;
  4455. }
  4456. if (a1CavitySN1_VehicleStates == "假产品")
  4457. a1CavityResult1_VehicleStates = 3;
  4458. if (a1CavitySN2_VehicleStates == "假产品")
  4459. a1CavityResult2_VehicleStates = 3;
  4460. short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4461. // 回写
  4462. stopwatch2.Start();
  4463. //Funs[plcNo].WriteMultipleRegisters<string>(2024, a1CavitySN1_VehicleStates, 20);
  4464. //Funs[plcNo].WriteMultipleRegisters<string>(2044, a1CavitySN2_VehicleStates, 20);
  4465. //Funs[plcNo].WriteMultipleRegisters<short>(2064, a1CavityResult1_VehicleStates);
  4466. //Funs[plcNo].WriteMultipleRegisters<short>(2065, a1CavityResult2_VehicleStates);
  4467. //// MES_Flag
  4468. //Funs[plcNo].WriteMultipleRegisters<short>(2003, mES_Flag);
  4469. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4470. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4471. writeToPLC_Flag.Adress = 2003;
  4472. writeToPLC_Flag.Value = mES_Flag;
  4473. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  4474. {
  4475. Name = "a1CavitySN1_VehicleStates",
  4476. Adress = 2024,
  4477. ValueType = PLCValueType.String,
  4478. ValueTypeStrLength = 20,
  4479. Value = a1CavitySN1_VehicleStates
  4480. });
  4481. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
  4482. {
  4483. Name = "a1CavitySN2_VehicleStates",
  4484. Adress = 2044,
  4485. ValueType = PLCValueType.String,
  4486. ValueTypeStrLength = 20,
  4487. Value = a1CavitySN2_VehicleStates
  4488. });
  4489. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4490. {
  4491. Name = "a1CavityResult1_VehicleStates",
  4492. Adress = 2064,
  4493. ValueType = PLCValueType.Short,
  4494. Value = a1CavityResult1_VehicleStates
  4495. });
  4496. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  4497. {
  4498. Name = "a1CavityResult2_VehicleStates",
  4499. Adress = 2065,
  4500. ValueType = PLCValueType.Short,
  4501. Value = a1CavityResult2_VehicleStates
  4502. });
  4503. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4504. stopwatch2.Stop();
  4505. }
  4506. catch (Exception ex)
  4507. {
  4508. string str = ex.StackTrace;
  4509. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4510. // MES_Flag
  4511. stopwatch2.Start();
  4512. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  4513. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4514. writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
  4515. writeToPLC_Flag.Adress = 2003;
  4516. writeToPLC_Flag.Value = (short)6;
  4517. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
  4518. stopwatch2.Stop();
  4519. }
  4520. stopwatch1.Stop();
  4521. AddMessage(LogType.Info, stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4522. }
  4523. /// <summary>
  4524. /// [S1] Tray盘上料装备(板测)- 上料进站校验
  4525. /// </summary>
  4526. /// <param name="plcNo">PLC编号</param>
  4527. /// <param name="stationNameStr">工站全称</param>
  4528. private void S1上料进站校验(int plcNo, string stationNameStr)
  4529. {
  4530. Stopwatch stopwatch1 = new Stopwatch();
  4531. Stopwatch stopwatch2 = new Stopwatch();
  4532. try
  4533. {
  4534. stopwatch1.Start();
  4535. string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
  4536. sn = sn.Replace("\0", "");
  4537. // 保存进站数据+调用进站MES接口
  4538. List<TestItem> item = new List<TestItem>();
  4539. stopwatch2.Start();
  4540. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, out string errorMsg);
  4541. stopwatch2.Stop();
  4542. short a1MES_FLAG_Check = (short)result;
  4543. //Funs[plcNo].WriteMultipleRegisters<short>(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  4544. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4545. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4546. writeToPLC_Flag.Adress = 2077;
  4547. writeToPLC_Flag.Value = a1MES_FLAG_Check;
  4548. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4549. }
  4550. catch (Exception ex)
  4551. {
  4552. string str = ex.StackTrace;
  4553. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4554. // MES_Flag
  4555. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  4556. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4557. writeToPLC_Flag.Name = "a1MES_FLAG_Check";
  4558. writeToPLC_Flag.Adress = 2077;
  4559. writeToPLC_Flag.Value = (short)6;
  4560. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
  4561. }
  4562. stopwatch1.Stop();
  4563. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4564. }
  4565. /// <summary>
  4566. /// [S1] Tray盘上料装备(板测)- 出站接口
  4567. /// </summary>
  4568. /// <param name="plcNo"></param>
  4569. /// <param name="stationCode"></param>
  4570. /// <param name="stationName"></param>
  4571. private void S1出站接口(int plcNo, string stationCode, string stationName)
  4572. {
  4573. Stopwatch stopwatch1 = new Stopwatch();
  4574. Stopwatch stopwatch2 = new Stopwatch();
  4575. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4576. string stationNameStr = stationCode + stationName;
  4577. string processItem = stationName; // 测试项目
  4578. try
  4579. {
  4580. stopwatch1.Start();
  4581. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4582. //string batch_num = GlobalContext.BatchNumber; // 批次号
  4583. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  4584. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  4585. string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
  4586. sn = sn.Replace("\0", "");
  4587. string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
  4588. partNo1 = partNo1.Replace("\0", "");
  4589. string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
  4590. partNo2 = partNo2.Replace("\0", "");
  4591. int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
  4592. bool pass = a1Result == 1;
  4593. stopwatch2.Start();
  4594. // 产品1
  4595. List<TestItem> items = new List<TestItem>();
  4596. items.Add(new TestItem()
  4597. {
  4598. Parameter_name = "载具码",
  4599. Parameter_value = sn,
  4600. Parameter_unit = ""
  4601. });
  4602. items.Add(new TestItem()
  4603. {
  4604. Parameter_name = "载具穴号",
  4605. Parameter_value = "1",
  4606. Parameter_unit = ""
  4607. });
  4608. items.Add(new TestItem()
  4609. {
  4610. Parameter_name = "产品结果",
  4611. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4612. Parameter_unit = ""
  4613. });
  4614. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4615. , workorder_code, mtltmrk, partNo1, pass, sn, "1");
  4616. // 产品2
  4617. items = new List<TestItem>();
  4618. items.Add(new TestItem()
  4619. {
  4620. Parameter_name = "载具码",
  4621. Parameter_value = sn,
  4622. Parameter_unit = ""
  4623. });
  4624. items.Add(new TestItem()
  4625. {
  4626. Parameter_name = "载具穴号",
  4627. Parameter_value = "2",
  4628. Parameter_unit = ""
  4629. });
  4630. items.Add(new TestItem()
  4631. {
  4632. Parameter_name = "产品结果",
  4633. Parameter_value = a1Result == 1 ? "OK" : "NG",
  4634. Parameter_unit = ""
  4635. });
  4636. int result2 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  4637. , workorder_code, mtltmrk, partNo2, pass, sn, "2");
  4638. short result = 0;
  4639. List<int> results = new List<int>() { result1, result2 };
  4640. if (result1 == 1 && result2 == 1)
  4641. result = 1;
  4642. else if (results.Contains(3))
  4643. result = 3;
  4644. else if (results.Contains(2))
  4645. result = 2;
  4646. else if (results.Contains(4))
  4647. result = 4;
  4648. else
  4649. result = 4;
  4650. stopwatch2.Stop();
  4651. #region 存储绑定数据到 边线MES系统中
  4652. if (result == 1)
  4653. {
  4654. string data = string.Concat(partNo1, ".", partNo2);
  4655. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  4656. if (resultMesR != 0)
  4657. {
  4658. result = 4;
  4659. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  4660. }
  4661. }
  4662. #endregion 存储绑定数据到 边线MES系统中
  4663. // MES_Flag 为MES报错
  4664. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4665. //Funs[plcNo].WriteMultipleRegisters<short>(2109, result); // 4代表上位机报警
  4666. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4667. writeToPLC_Flag.Name = "a1MES_FLAG";
  4668. writeToPLC_Flag.Adress = 2109;
  4669. writeToPLC_Flag.Value = result;
  4670. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4671. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4672. }
  4673. catch (Exception ex)
  4674. {
  4675. stopwatch2.Restart();
  4676. // MES_Flag 为4上位机报错
  4677. //Funs[plcNo].WriteMultipleRegisters<short>(2109, (short)4); // 4代表上位机报警
  4678. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4679. writeToPLC_Flag.Name = "a1MES_FLAG";
  4680. writeToPLC_Flag.Adress = 2109;
  4681. writeToPLC_Flag.Value = (short)4;
  4682. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
  4683. stopwatch2.Stop();
  4684. string str = ex.StackTrace;
  4685. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4686. }
  4687. stopwatch1.Stop();
  4688. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4689. }
  4690. //// 上传点检数据_ [S1] Tray盘上料装备(板测)
  4691. //private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
  4692. //{
  4693. // string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  4694. // string stationNameStr = stationCode + stationName;
  4695. // string processItem = stationName; // 测试项目
  4696. // try
  4697. // {
  4698. // string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  4699. // string accno = "1"; // 工序编号
  4700. // Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
  4701. // float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
  4702. // List<OneCheckItem> items = new List<OneCheckItem>()
  4703. // {
  4704. // new OneCheckItem()
  4705. // {
  4706. // Onecheck_name="胶圈装配行程设定上限",
  4707. // Onecheck_content="上限值",
  4708. // Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
  4709. // },
  4710. // };
  4711. // OneCheckData oneCheckData = new OneCheckData()
  4712. // {
  4713. // Line_code = GlobalContext.LineCode,
  4714. // Line_name = GlobalContext.LineName,
  4715. // Equipment_code = equipmentCode,
  4716. // Equipment_name = equipmentCode,
  4717. // Workorder_code = workorder_code,
  4718. // Procedure_code = accno,
  4719. // Procedure_name = processItem,
  4720. // Oneckeck_values = items,
  4721. // Onecheck_empcode = "",
  4722. // Onecheck_empname = "",
  4723. // Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  4724. // };
  4725. // int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
  4726. // //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
  4727. // short result = result1 == 1 ? (short)1 : (short)2;
  4728. // // MES_Flag 为4MES报错
  4729. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
  4730. // WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  4731. // }
  4732. // catch (Exception ex)
  4733. // {
  4734. // // MES_Flag 为2上位机报错
  4735. // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
  4736. // string str = ex.StackTrace;
  4737. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4738. // }
  4739. //}
  4740. // ReadStation_S1_2 节拍接口+AGV
  4741. /// <summary>
  4742. /// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
  4743. /// </summary>
  4744. /// <param name="plcNo">PLC编号</param>
  4745. /// <param name="stationNameStr">工站全称</param>
  4746. private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
  4747. {
  4748. Stopwatch stopwatch1 = new Stopwatch();
  4749. Stopwatch stopwatch2 = new Stopwatch();
  4750. try
  4751. {
  4752. stopwatch1.Start();
  4753. string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
  4754. a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
  4755. string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
  4756. a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
  4757. string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
  4758. a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
  4759. // ZS 将SN发给ICT标机(串口)
  4760. short a1MES_FLAG_ICT = 1;
  4761. stopwatch2.Start();
  4762. // MES_Flag
  4763. //Funs[plcNo].WriteMultipleRegisters<short>(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
  4764. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4765. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4766. writeToPLC_Flag.Adress = 2182;
  4767. writeToPLC_Flag.Value = a1MES_FLAG_ICT;
  4768. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4769. stopwatch2.Stop();
  4770. }
  4771. catch (Exception ex)
  4772. {
  4773. string str = ex.StackTrace;
  4774. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4775. stopwatch2.Start();
  4776. // MES_Flag
  4777. //Funs[plcNo].WriteMultipleRegisters<short>(2182, (short)4); // 4代表上位机报警
  4778. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4779. writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
  4780. writeToPLC_Flag.Adress = 2182;
  4781. writeToPLC_Flag.Value = (short)4;
  4782. SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
  4783. stopwatch2.Stop();
  4784. }
  4785. stopwatch1.Stop();
  4786. AddMessage(LogType.Info, stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4787. }
  4788. /// <summary>
  4789. /// [S1] Tray盘上料装备(板测)- 节拍接口
  4790. /// </summary>
  4791. /// <param name="plcNo">PLC编号</param>
  4792. /// <param name="stationNameStr">工站全称</param>
  4793. private void S1节拍接口(int plcNo, string stationNameStr)
  4794. {
  4795. Stopwatch stopwatch1 = new Stopwatch();
  4796. Stopwatch stopwatch2 = new Stopwatch();
  4797. string resultStr = string.Empty;
  4798. try
  4799. {
  4800. stopwatch1.Start();
  4801. string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
  4802. string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
  4803. a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
  4804. string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
  4805. a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
  4806. string a1OEEPartNum = ((int)s1PLCData["a1OEEPartNum"]).ToString(); // 穴位号
  4807. a1OEEPartNum = a1OEEPartNum.Replace("\0", "");
  4808. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  4809. if (!actionBool)
  4810. {
  4811. stopwatch2.Start();
  4812. // MES_Flag
  4813. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4814. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  4815. writeToPLC_Flag1.Name = "a1OEEMES_FLAG";
  4816. writeToPLC_Flag1.Adress = 2254;
  4817. writeToPLC_Flag1.Value = (short)1;
  4818. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag1);
  4819. stopwatch2.Stop();
  4820. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4821. return;
  4822. }
  4823. if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode))
  4824. {
  4825. stopwatch2.Start();
  4826. // MES_Flag
  4827. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4828. WriteToPLC_Flag writeToPLC_Flag2 = new WriteToPLC_Flag(); // MES_Flag
  4829. writeToPLC_Flag2.Name = "a1OEEMES_FLAG";
  4830. writeToPLC_Flag2.Adress = 2254;
  4831. writeToPLC_Flag2.Value = (short)1;
  4832. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag2);
  4833. stopwatch2.Stop();
  4834. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4835. return;
  4836. }
  4837. else if (string.IsNullOrEmpty(a1OEEPartNo) && !string.IsNullOrEmpty(a1OEEVehicleCode))
  4838. { // 查产品SN
  4839. a1OEEPartNo = "Test"; // ZS
  4840. }
  4841. short a1OEEMES_FLAG = 0;
  4842. // 上传OEE
  4843. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
  4844. a1OEEMES_FLAG = result.Item1;
  4845. resultStr = result.Item2;
  4846. stopwatch2.Start();
  4847. // MES_Flag
  4848. //Funs[plcNo].WriteMultipleRegisters<short>(2254, a1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  4849. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4850. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  4851. writeToPLC_Flag.Adress = 2254;
  4852. writeToPLC_Flag.Value = a1OEEMES_FLAG;
  4853. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  4854. stopwatch2.Stop();
  4855. }
  4856. catch (Exception ex)
  4857. {
  4858. string str = ex.StackTrace;
  4859. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4860. // MES_Flag
  4861. stopwatch2.Start();
  4862. //Funs[plcNo].WriteMultipleRegisters<short>(2254, (short)4); // 4代表上位机报警
  4863. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4864. writeToPLC_Flag.Name = "a1OEEMES_FLAG";
  4865. writeToPLC_Flag.Adress = 2254;
  4866. writeToPLC_Flag.Value = (short)4;
  4867. SxPLCWriteData_Add(ref s1PLCWriteData, "a1OEEMES_FLAG", writeToPLC_Flag);
  4868. stopwatch2.Stop();
  4869. }
  4870. stopwatch1.Stop();
  4871. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4872. }
  4873. /// <summary>
  4874. /// [S1] Tray盘上料装备(板测)- AGV上料叫agv
  4875. /// </summary>
  4876. /// <param name="plcNo">PLC编号</param>
  4877. /// <param name="stationNameStr">工站全称</param>
  4878. private void S1AGV上料叫agv(int plcNo, string stationNameStr)
  4879. {
  4880. Stopwatch stopwatch1 = new Stopwatch();
  4881. Stopwatch stopwatch2 = new Stopwatch();
  4882. try
  4883. {
  4884. stopwatch1.Start();
  4885. // ZS 呼叫AGV
  4886. short a1AGVUpCall = 2;
  4887. stopwatch2.Start();
  4888. // a1AGVUpCall
  4889. //Funs[plcNo].WriteMultipleRegisters<short>(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4890. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4891. writeToPLC_Flag.Name = "a1AGVUpCall";
  4892. writeToPLC_Flag.Adress = 2307;
  4893. writeToPLC_Flag.Value = a1AGVUpCall;
  4894. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  4895. stopwatch2.Stop();
  4896. }
  4897. catch (Exception ex)
  4898. {
  4899. string str = ex.StackTrace;
  4900. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4901. // a1AGVUpCall
  4902. stopwatch2.Start();
  4903. //Funs[plcNo].WriteMultipleRegisters<short>(2307, (short)4); // 4代表上位机报警
  4904. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4905. writeToPLC_Flag.Name = "a1AGVUpCall";
  4906. writeToPLC_Flag.Adress = 2307;
  4907. writeToPLC_Flag.Value = (short)4;
  4908. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
  4909. stopwatch2.Stop();
  4910. }
  4911. stopwatch1.Stop();
  4912. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4913. }
  4914. /// <summary>
  4915. /// [S1] Tray盘上料装备(板测)- AGV上料完成
  4916. /// </summary>
  4917. /// <param name="plcNo">PLC编号</param>
  4918. /// <param name="stationNameStr">工站全称</param>
  4919. private void S1AGV上料完成(int plcNo, string stationNameStr)
  4920. {
  4921. Stopwatch stopwatch1 = new Stopwatch();
  4922. Stopwatch stopwatch2 = new Stopwatch();
  4923. try
  4924. {
  4925. stopwatch1.Start();
  4926. // ZS AGV上料完成,让小车离开
  4927. short a1AGVUpEnd = 2;
  4928. stopwatch2.Start();
  4929. // a1AGVUpEnd
  4930. //Funs[plcNo].WriteMultipleRegisters<short>(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4931. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4932. writeToPLC_Flag.Name = "a1AGVUpEnd";
  4933. writeToPLC_Flag.Adress = 2309;
  4934. writeToPLC_Flag.Value = a1AGVUpEnd;
  4935. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  4936. stopwatch2.Stop();
  4937. }
  4938. catch (Exception ex)
  4939. {
  4940. string str = ex.StackTrace;
  4941. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4942. // a1AGVUpEnd
  4943. stopwatch2.Start();
  4944. //Funs[plcNo].WriteMultipleRegisters<short>(2309, (short)4); // 4代表上位机报警
  4945. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4946. writeToPLC_Flag.Name = "a1AGVUpEnd";
  4947. writeToPLC_Flag.Adress = 2309;
  4948. writeToPLC_Flag.Value = (short)4;
  4949. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
  4950. stopwatch2.Stop();
  4951. }
  4952. stopwatch1.Stop();
  4953. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4954. }
  4955. /// <summary>
  4956. /// [S1] Tray盘上料装备(板测)- AGV下料叫agv
  4957. /// </summary>
  4958. /// <param name="plcNo">PLC编号</param>
  4959. /// <param name="stationNameStr">工站全称</param>
  4960. private void S1AGV下料叫agv(int plcNo, string stationNameStr)
  4961. {
  4962. Stopwatch stopwatch1 = new Stopwatch();
  4963. Stopwatch stopwatch2 = new Stopwatch();
  4964. try
  4965. {
  4966. stopwatch1.Start();
  4967. // ZS 呼叫AGV
  4968. short a1AGVDownCall = 2;
  4969. stopwatch2.Start();
  4970. // a1AGVDownCall
  4971. //Funs[plcNo].WriteMultipleRegisters<short>(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  4972. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4973. writeToPLC_Flag.Name = "a1AGVDownCall";
  4974. writeToPLC_Flag.Adress = 2320;
  4975. writeToPLC_Flag.Value = a1AGVDownCall;
  4976. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  4977. stopwatch2.Stop();
  4978. }
  4979. catch (Exception ex)
  4980. {
  4981. string str = ex.StackTrace;
  4982. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  4983. // a1AGVDownCall
  4984. stopwatch2.Start();
  4985. //Funs[plcNo].WriteMultipleRegisters<short>(2320, (short)4); // 4代表上位机报警
  4986. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  4987. writeToPLC_Flag.Name = "a1AGVDownCall";
  4988. writeToPLC_Flag.Adress = 2320;
  4989. writeToPLC_Flag.Value = (short)4;
  4990. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
  4991. stopwatch2.Stop();
  4992. }
  4993. stopwatch1.Stop();
  4994. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  4995. }
  4996. /// <summary>
  4997. /// [S1] Tray盘上料装备(板测)- AGV下料完成
  4998. /// </summary>
  4999. /// <param name="plcNo">PLC编号</param>
  5000. /// <param name="stationNameStr">工站全称</param>
  5001. private void S1AGV下料完成(int plcNo, string stationNameStr)
  5002. {
  5003. Stopwatch stopwatch1 = new Stopwatch();
  5004. Stopwatch stopwatch2 = new Stopwatch();
  5005. try
  5006. {
  5007. stopwatch1.Start();
  5008. // ZS AGV上料完成,让小车离开
  5009. short a1AGVDownEnd = 2;
  5010. stopwatch2.Start();
  5011. // a1AGVDownEnd
  5012. //Funs[plcNo].WriteMultipleRegisters<short>(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  5013. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5014. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5015. writeToPLC_Flag.Adress = 2322;
  5016. writeToPLC_Flag.Value = a1AGVDownEnd;
  5017. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5018. stopwatch2.Stop();
  5019. }
  5020. catch (Exception ex)
  5021. {
  5022. string str = ex.StackTrace;
  5023. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5024. // a1AGVDownEnd
  5025. stopwatch2.Start();
  5026. //Funs[plcNo].WriteMultipleRegisters<short>(2322, (short)4); // 4代表上位机报警
  5027. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5028. writeToPLC_Flag.Name = "a1AGVDownEnd";
  5029. writeToPLC_Flag.Adress = 2322;
  5030. writeToPLC_Flag.Value = (short)4;
  5031. SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
  5032. stopwatch2.Stop();
  5033. }
  5034. stopwatch1.Stop();
  5035. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5036. }
  5037. #endregion [S1] Tray盘上料装备(板测)
  5038. #endregion PLC1 张超凡
  5039. #region PLC2 李晓奇
  5040. #region [S2] FCT(板测)
  5041. /// <summary>
  5042. /// S2工位的数据- 触发信号上次的值
  5043. /// </summary>
  5044. private Dictionary<string, object> s2PLCSignal_Old = new Dictionary<string, object>();
  5045. /// <summary>
  5046. /// S2工位的数据(含触发信号)
  5047. /// </summary>
  5048. private Dictionary<string, object> s2PLCData = new Dictionary<string, object>();
  5049. /// <summary>
  5050. /// S2工位的数据- 回写点位
  5051. /// </summary>
  5052. private Dictionary<string, WriteToPLC_Flag> s2PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5053. /// <summary>
  5054. /// [S2] FCT(板测)
  5055. /// </summary>
  5056. /// <param name="plcNo">PLC编号</param>
  5057. //private void ReadStation_S2(int plcNo)
  5058. //{
  5059. // // [S1] Tray盘上料装备
  5060. // // [S2] FCT
  5061. // // [S3] 值板机
  5062. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5063. // // [S5] Tray盘下料装备
  5064. // /// 上位机心跳
  5065. // /// 获取设备报警数据与状态信息
  5066. // string stationCode = "[S2]";
  5067. // string stationName = "FCT";
  5068. // string stationNameStr = stationCode + stationName;
  5069. // #region 创建字典
  5070. // // 触发信号字典 赋值
  5071. // s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5072. // s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
  5073. // s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5074. // s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5075. // // PLC数据字典 赋值
  5076. // s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
  5077. // s2PLCData.Add("b1MES_FLAG_Check", 0);
  5078. // s2PLCData.Add("b1ProductSN_Check", 0);
  5079. // s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
  5080. // s2PLCData.Add("b1MES_FLAG_Unbind", 0);
  5081. // s2PLCData.Add("b1ProductSN_Unbind", "");
  5082. // s2PLCData.Add("b1ProductSN_Bind", "");
  5083. // s2PLCData.Add("b1Part1SN_Bind", "");
  5084. // s2PLCData.Add("b1Part2SN_Bind", "");
  5085. // s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
  5086. // s2PLCData.Add("b1MES_FLAG", 0);
  5087. // s2PLCData.Add("b1ProductSN", 0);
  5088. // s2PLCData.Add("b1Part1Result", 0);
  5089. // s2PLCData.Add("b1Part2Result", 0);
  5090. // s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
  5091. // s2PLCData.Add("b1OEEMES_FLAG", 0);
  5092. // s2PLCData.Add("b1OEEProductSN", "");
  5093. // s2PLCData.Add("b1OEEType", 0);
  5094. // #endregion 创建字典
  5095. // while (IsRun)
  5096. // {
  5097. // try
  5098. // {
  5099. // if (!GlobalContext._IsCon_Funs2)
  5100. // {
  5101. // UpdatePLCMonitor(1, plcNo, 0);
  5102. // continue;
  5103. // }
  5104. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5105. // {
  5106. // Stopwatch stopwatch1 = new Stopwatch();
  5107. // Stopwatch stopwatch2 = new Stopwatch();
  5108. // stopwatch1.Start();
  5109. // stopwatch2.Start();
  5110. // #region 一次性读取所有数据
  5111. // // 一次性读取所有数据
  5112. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
  5113. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
  5114. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
  5115. // int[] datas = data1.Concat(data2).ToArray();
  5116. // datas = datas.Concat(data3).ToArray();
  5117. // s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
  5118. // s2PLCData["b1MES_FLAG_Check"] = datas[3];
  5119. // int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5120. // s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
  5121. // s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
  5122. // s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
  5123. // int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
  5124. // s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
  5125. // int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
  5126. // s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
  5127. // int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
  5128. // s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
  5129. // int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
  5130. // s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
  5131. // s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
  5132. // s2PLCData["b1MES_FLAG"] = datas[169];
  5133. // int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
  5134. // s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
  5135. // s2PLCData["b1Part1Result"] = datas[190];
  5136. // s2PLCData["b1Part2Result"] = datas[191];
  5137. // s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
  5138. // s2PLCData["b1OEEMES_FLAG"] = datas[203];
  5139. // int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
  5140. // s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
  5141. // s2PLCData["b1OEEType"] = datas[224];
  5142. // #endregion 一次性读取所有数据
  5143. // stopwatch2.Stop();
  5144. // #region 回写操作,写后清空flag
  5145. // PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
  5146. // #endregion 回写操作,写后清空flag
  5147. // #region 进站校验
  5148. // try
  5149. // {
  5150. // int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
  5151. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5152. // int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
  5153. // if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
  5154. // {
  5155. // if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
  5156. // Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5157. // else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
  5158. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5159. // s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
  5160. // }
  5161. // }
  5162. // catch (Exception ex)
  5163. // {
  5164. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5165. // string str = ex.StackTrace;
  5166. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5167. // }
  5168. // #endregion 进站校验
  5169. // #region 二穴载具解绑/绑定(产品换载具)
  5170. // try
  5171. // {
  5172. // int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
  5173. // int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
  5174. // int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
  5175. // if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
  5176. // {
  5177. // if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
  5178. // Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5179. // else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
  5180. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)0);
  5181. // s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
  5182. // }
  5183. // }
  5184. // catch (Exception ex)
  5185. // {
  5186. // Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5187. // string str = ex.StackTrace;
  5188. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5189. // }
  5190. // #endregion 二穴载具解绑/绑定(产品换载具)
  5191. // #region FCT-出站接口
  5192. // try
  5193. // {
  5194. // int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
  5195. // int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
  5196. // int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
  5197. // if (b1PLC_FLAG != b1PLC_FLAGOld)
  5198. // {
  5199. // if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
  5200. // Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5201. // else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
  5202. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)0);
  5203. // }
  5204. // }
  5205. // catch (Exception ex)
  5206. // {
  5207. // // MES_Flag 为6上位机报错
  5208. // Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)6); // 6代表上位机报警
  5209. // string str = ex.StackTrace;
  5210. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5211. // }
  5212. // #endregion FCT-出站接口
  5213. // #region 节拍接口
  5214. // try
  5215. // {
  5216. // int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
  5217. // int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
  5218. // int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
  5219. // if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
  5220. // {
  5221. // if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
  5222. // Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5223. // else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
  5224. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)0);
  5225. // s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
  5226. // }
  5227. // }
  5228. // catch (Exception ex)
  5229. // {
  5230. // Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5231. // string str = ex.StackTrace;
  5232. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5233. // }
  5234. // #endregion 节拍接口
  5235. // #region 心跳
  5236. // try
  5237. // {
  5238. // short states = 0;
  5239. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  5240. // }
  5241. // catch (Exception ex)
  5242. // {
  5243. // string str = ex.StackTrace;
  5244. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5245. // }
  5246. // #endregion 心跳
  5247. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5248. // stopwatch1.Stop();
  5249. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  5250. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5251. // }
  5252. // else
  5253. // {
  5254. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5255. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5256. // Funs[plcNo].Connect();
  5257. // }
  5258. // }
  5259. // catch (Exception ex)
  5260. // {
  5261. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5262. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5263. // Funs[plcNo].ReConnect();
  5264. // }
  5265. // Thread.Sleep(IntervalReadPLC);
  5266. // }
  5267. //}
  5268. /// <summary>
  5269. /// [S2] FCT(板测)- 进站校验
  5270. /// </summary>
  5271. /// <param name="plcNo">PLC编号</param>
  5272. /// <param name="stationNameStr">工站全称</param>
  5273. private void S2进站校验(int plcNo, string stationNameStr)
  5274. {
  5275. Stopwatch stopwatch1 = new Stopwatch();
  5276. Stopwatch stopwatch2 = new Stopwatch();
  5277. try
  5278. {
  5279. stopwatch1.Start();
  5280. string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
  5281. sn = sn.Replace("\0", "");
  5282. #region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5283. // 查询物料码By载具码 并判断是不是假产品
  5284. string cavityData = string.Empty;
  5285. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  5286. if (string.IsNullOrEmpty(cavityData))
  5287. cavityData = "";
  5288. if (snResult != 0)
  5289. {
  5290. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5291. writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
  5292. writeToPLC_Flag1.Adress = 2003;
  5293. writeToPLC_Flag1.Value = (short)6;
  5294. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
  5295. stopwatch1.Stop();
  5296. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5297. return;
  5298. }
  5299. #endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
  5300. string[] cavitySNs = cavityData.Split('.');
  5301. string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
  5302. string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
  5303. short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5304. short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5305. if (cavitySNs != null && cavitySNs.Length >= 2)
  5306. {
  5307. b1Part1SN_Check = cavitySNs[0];
  5308. b1Part2SN_Check = cavitySNs[1];
  5309. b1Part1Result_Check = 2;
  5310. b1Part2Result_Check = 2;
  5311. }
  5312. if (b1Part1SN_Check == "假产品")
  5313. b1Part1Result_Check = 3;
  5314. if (b1Part2SN_Check == "假产品")
  5315. b1Part2Result_Check = 3;
  5316. // 调用MES进站
  5317. stopwatch2.Start();
  5318. // 调用MES进站 - 产品1
  5319. List<TestItem> item;
  5320. int result1 = b1Part1Result_Check;
  5321. if (result1 != 3)
  5322. {
  5323. item = new List<TestItem>();
  5324. item.Add(new TestItem()
  5325. {
  5326. Parameter_name = "载具码",
  5327. Parameter_value = sn,
  5328. });
  5329. item.Add(new TestItem()
  5330. {
  5331. Parameter_name = "载具穴号",
  5332. Parameter_value = "1",
  5333. });
  5334. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part1SN_Check, item, out string errorMsg);
  5335. }
  5336. // 调用MES进站 - 产品2
  5337. int result2 = b1Part2Result_Check;
  5338. if (result2 != 3)
  5339. {
  5340. item = new List<TestItem>();
  5341. item.Add(new TestItem()
  5342. {
  5343. Parameter_name = "载具码",
  5344. Parameter_value = sn,
  5345. });
  5346. item.Add(new TestItem()
  5347. {
  5348. Parameter_name = "载具穴号",
  5349. Parameter_value = "2",
  5350. });
  5351. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, b1Part2SN_Check, item, out string errorMsg);
  5352. }
  5353. stopwatch2.Stop();
  5354. b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  5355. b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  5356. int result = result1;
  5357. if (result == 1)
  5358. result = result2;
  5359. short b1MES_FLAG_Check = (short)result;
  5360. //Funs[plcNo].WriteMultipleRegisters<string>(2024, b1Part1SN_Check, 20);
  5361. //Funs[plcNo].WriteMultipleRegisters<string>(2044, b1Part2SN_Check, 20);
  5362. //Funs[plcNo].WriteMultipleRegisters<short>(2064, b1Part1Result_Check);
  5363. //Funs[plcNo].WriteMultipleRegisters<short>(2065, b1Part2Result_Check);
  5364. //// MES_Flag
  5365. //Funs[plcNo].WriteMultipleRegisters<short>(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5366. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5367. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5368. writeToPLC_Flag.Adress = 2003;
  5369. writeToPLC_Flag.Value = b1MES_FLAG_Check;
  5370. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5371. {
  5372. Name = "b1Part1SN_Check",
  5373. Adress = 2024,
  5374. ValueType = PLCValueType.String,
  5375. ValueTypeStrLength = 20,
  5376. Value = b1Part1SN_Check
  5377. });
  5378. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5379. {
  5380. Name = "b1Part2SN_Check",
  5381. Adress = 2044,
  5382. ValueType = PLCValueType.String,
  5383. ValueTypeStrLength = 20,
  5384. Value = b1Part2SN_Check
  5385. });
  5386. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5387. {
  5388. Name = "b1Part1Result_Check",
  5389. Adress = 2064,
  5390. ValueType = PLCValueType.Short,
  5391. Value = b1Part1Result_Check
  5392. });
  5393. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  5394. {
  5395. Name = "b1Part2Result_Check",
  5396. Adress = 2065,
  5397. ValueType = PLCValueType.Short,
  5398. Value = b1Part2Result_Check
  5399. });
  5400. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5401. }
  5402. catch (Exception ex)
  5403. {
  5404. string str = ex.StackTrace;
  5405. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5406. // MES_Flag
  5407. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5408. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5409. writeToPLC_Flag.Name = "b1MES_FLAG_Check";
  5410. writeToPLC_Flag.Adress = 2003;
  5411. writeToPLC_Flag.Value = (short)6;
  5412. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
  5413. }
  5414. stopwatch1.Stop();
  5415. AddMessage(LogType.Info, stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5416. }
  5417. /// <summary>
  5418. /// [S2] FCT(板测)- 二穴载具解绑绑定
  5419. /// </summary>
  5420. /// <param name="plcNo">PLC编号</param>
  5421. /// <param name="stationNameStr">工站全称</param>
  5422. private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
  5423. {
  5424. Stopwatch stopwatch1 = new Stopwatch();
  5425. Stopwatch stopwatch2 = new Stopwatch();
  5426. try
  5427. {
  5428. stopwatch1.Start();
  5429. // 产品换载具
  5430. string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
  5431. b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
  5432. string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
  5433. b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
  5434. string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
  5435. b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
  5436. string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
  5437. b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
  5438. stopwatch2.Start();
  5439. #region 查询载具上的产品信息
  5440. //string cavityData = string.Empty;
  5441. //int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
  5442. //if (string.IsNullOrEmpty(cavityData))
  5443. // cavityData = "";
  5444. //if (snResult != 0)
  5445. //{
  5446. // WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5447. // writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5448. // writeToPLC_Flag.Adress = 2077;
  5449. // writeToPLC_Flag.Value = (short)6;
  5450. // SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5451. // stopwatch1.Stop();
  5452. // AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5453. // return;
  5454. //}
  5455. #endregion 查询载具上的产品信息
  5456. #region 解绑(边线MES系统)
  5457. int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
  5458. if (snResult != 0)
  5459. {
  5460. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5461. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5462. writeToPLC_Flag1.Adress = 2077;
  5463. writeToPLC_Flag1.Value = (short)6;
  5464. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5465. stopwatch1.Stop();
  5466. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5467. return;
  5468. }
  5469. #endregion 解绑(边线MES系统)
  5470. #region 存储绑定数据到 边线MES系统中
  5471. string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
  5472. snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
  5473. if (snResult != 0)
  5474. {
  5475. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5476. writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
  5477. writeToPLC_Flag1.Adress = 2077;
  5478. writeToPLC_Flag1.Value = (short)6;
  5479. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
  5480. stopwatch1.Stop();
  5481. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5482. return;
  5483. }
  5484. #endregion 存储绑定数据到 边线MES系统中
  5485. stopwatch2.Stop();
  5486. short b1MES_FLAG_Unbind = 1;
  5487. // MES_Flag
  5488. //Funs[plcNo].WriteMultipleRegisters<short>(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  5489. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5490. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5491. writeToPLC_Flag.Adress = 2077;
  5492. writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
  5493. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5494. }
  5495. catch (Exception ex)
  5496. {
  5497. string str = ex.StackTrace;
  5498. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5499. // MES_Flag
  5500. stopwatch2.Start();
  5501. //Funs[plcNo].WriteMultipleRegisters<short>(2077, (short)6); // 6代表上位机报警
  5502. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5503. writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
  5504. writeToPLC_Flag.Adress = 2077;
  5505. writeToPLC_Flag.Value = (short)6;
  5506. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
  5507. stopwatch2.Stop();
  5508. }
  5509. stopwatch1.Stop();
  5510. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5511. }
  5512. //// 上次采集到的SN
  5513. //private string sn_FCT = string.Empty;
  5514. /// <summary>
  5515. /// [S2] FCT(板测)- 出站数据
  5516. /// </summary>
  5517. private void S2出站接口(int plcNo, string stationCode, string stationName)
  5518. {
  5519. Stopwatch stopwatch1 = new Stopwatch();
  5520. Stopwatch stopwatch2 = new Stopwatch();
  5521. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  5522. string stationNameStr = stationCode + stationName;
  5523. string processItem = stationName; // 测试项目
  5524. try
  5525. {
  5526. stopwatch1.Start();
  5527. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  5528. //string batch_num = GlobalContext.BatchNumber; // 批次号
  5529. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  5530. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  5531. string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
  5532. int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
  5533. int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
  5534. bool pass1 = b1Part1Result == 1;
  5535. bool pass2 = b1Part2Result == 1;
  5536. #region 根据 载具SN 查 物料SN
  5537. string cavityData = string.Empty;
  5538. int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
  5539. if (string.IsNullOrEmpty(cavityData))
  5540. cavityData = "";
  5541. if (snResult != 0)
  5542. {
  5543. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5544. writeToPLC_Flag1.Name = "b1MES_FLAG";
  5545. writeToPLC_Flag1.Adress = 2169;
  5546. writeToPLC_Flag1.Value = (short)4;
  5547. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
  5548. stopwatch1.Stop();
  5549. AddMessage(LogType.Info, stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  5550. return;
  5551. }
  5552. #endregion 根据 载具SN 查 物料SN
  5553. string[] cavitySNs = cavityData.Split('.');
  5554. string b1ProductSN1 = string.Empty;
  5555. string b1ProductSN2 = string.Empty;
  5556. if (cavitySNs != null && cavitySNs.Length >= 2)
  5557. {
  5558. b1ProductSN1 = cavitySNs[0];
  5559. b1ProductSN2 = cavitySNs[1];
  5560. }
  5561. stopwatch2.Start();
  5562. // 产品1
  5563. int result1 = 0;
  5564. if (b1ProductSN1 == "假产品")
  5565. result1 = 1;
  5566. else
  5567. {
  5568. List<TestItem> items1 = new List<TestItem>();
  5569. items1.Add(new TestItem()
  5570. {
  5571. Parameter_name = "载具码",
  5572. Parameter_value = b1ProductSN.ToString(),
  5573. Parameter_unit = ""
  5574. });
  5575. items1.Add(new TestItem()
  5576. {
  5577. Parameter_name = "载具穴号",
  5578. Parameter_value = "1",
  5579. Parameter_unit = ""
  5580. });
  5581. items1.Add(new TestItem()
  5582. {
  5583. Parameter_name = "产品结果",
  5584. Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
  5585. Parameter_unit = ""
  5586. });
  5587. result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  5588. , workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
  5589. }
  5590. // 产品2
  5591. int result2 = 0;
  5592. if (b1ProductSN1 == "假产品")
  5593. result2 = 1;
  5594. else
  5595. {
  5596. List<TestItem> items2 = new List<TestItem>();
  5597. items2.Add(new TestItem()
  5598. {
  5599. Parameter_name = "载具码",
  5600. Parameter_value = b1ProductSN.ToString(),
  5601. Parameter_unit = ""
  5602. });
  5603. items2.Add(new TestItem()
  5604. {
  5605. Parameter_name = "载具穴号",
  5606. Parameter_value = "2",
  5607. Parameter_unit = ""
  5608. });
  5609. items2.Add(new TestItem()
  5610. {
  5611. Parameter_name = "产品结果",
  5612. Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
  5613. Parameter_unit = ""
  5614. });
  5615. result2 = SwitctProcessData(stationNameStr, items2, equipmentCode, processItem
  5616. , workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
  5617. }
  5618. short result = 0;
  5619. List<int> results = new List<int>() { result1, result2 };
  5620. if (result1 == 1 && result2 == 1)
  5621. result = 1;
  5622. else if (results.Contains(3))
  5623. result = 3;
  5624. else if (results.Contains(2))
  5625. result = 2;
  5626. else if (results.Contains(4))
  5627. result = 4;
  5628. else
  5629. result = 4;
  5630. stopwatch2.Stop();
  5631. //Funs[plcNo].WriteMultipleRegisters<short>(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5632. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5633. writeToPLC_Flag.Name = "b1MES_FLAG";
  5634. writeToPLC_Flag.Adress = 2169;
  5635. writeToPLC_Flag.Value = result;
  5636. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5637. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  5638. }
  5639. catch (Exception ex)
  5640. {
  5641. stopwatch2.Restart();
  5642. // MES_Flag 为4上位机报错
  5643. //Funs[plcNo].WriteMultipleRegisters<short>(2169, (short)4); // 4代表上位机报警
  5644. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5645. writeToPLC_Flag.Name = "b1MES_FLAG";
  5646. writeToPLC_Flag.Adress = 2169;
  5647. writeToPLC_Flag.Value = (short)4;
  5648. SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
  5649. stopwatch2.Stop();
  5650. string str = ex.StackTrace;
  5651. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5652. }
  5653. stopwatch1.Stop();
  5654. AddMessage(LogType.Info, stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5655. }
  5656. /// <summary>
  5657. /// [S2] FCT(板测)- 节拍接口
  5658. /// </summary>
  5659. /// <param name="plcNo">PLC编号</param>
  5660. /// <param name="stationNameStr">工站全称</param>
  5661. private void S2节拍接口(int plcNo, string stationNameStr)
  5662. {
  5663. Stopwatch stopwatch1 = new Stopwatch();
  5664. Stopwatch stopwatch2 = new Stopwatch();
  5665. string resultStr = string.Empty;
  5666. try
  5667. {
  5668. stopwatch1.Start();
  5669. string oEEType = ((int)s2PLCData["b1OEEType"]).ToString(); // 节拍类型(plc写入)
  5670. string b1OEEProductSN = (string)s2PLCData["b1OEEProductSN"]; // 载具SN
  5671. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  5672. if (!actionBool)
  5673. {
  5674. stopwatch2.Start();
  5675. // MES_Flag
  5676. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5677. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5678. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5679. writeToPLC_Flag1.Adress = 2203;
  5680. writeToPLC_Flag1.Value = (short)4;
  5681. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5682. stopwatch2.Stop();
  5683. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5684. return;
  5685. }
  5686. string b1OEEPartNo = string.Empty; // 物料码
  5687. if (string.IsNullOrEmpty(b1OEEProductSN))
  5688. {
  5689. stopwatch2.Start();
  5690. // MES_Flag
  5691. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5692. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  5693. writeToPLC_Flag1.Name = "b1OEEMES_FLAG";
  5694. writeToPLC_Flag1.Adress = 2203;
  5695. writeToPLC_Flag1.Value = (short)1;
  5696. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag1);
  5697. stopwatch2.Stop();
  5698. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5699. return;
  5700. }
  5701. else
  5702. { // 查产品SN
  5703. b1OEEPartNo = "Test"; // ZS
  5704. }
  5705. short b1OEEMES_FLAG = 0;
  5706. // 上传OEE
  5707. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, b1OEEPartNo, b1OEEProductSN);
  5708. b1OEEMES_FLAG = result.Item1;
  5709. resultStr = result.Item2;
  5710. stopwatch2.Start();
  5711. // MES_Flag
  5712. //Funs[plcNo].WriteMultipleRegisters<short>(2203, b1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  5713. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5714. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5715. writeToPLC_Flag.Adress = 2203;
  5716. writeToPLC_Flag.Value = b1OEEMES_FLAG;
  5717. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5718. stopwatch2.Stop();
  5719. }
  5720. catch (Exception ex)
  5721. {
  5722. string str = ex.StackTrace;
  5723. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5724. // MES_Flag
  5725. stopwatch2.Start();
  5726. //Funs[plcNo].WriteMultipleRegisters<short>(2203, (short)4); // 4代表上位机报警
  5727. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  5728. writeToPLC_Flag.Name = "b1OEEMES_FLAG";
  5729. writeToPLC_Flag.Adress = 2203;
  5730. writeToPLC_Flag.Value = (short)4;
  5731. SxPLCWriteData_Add(ref s2PLCWriteData, "b1OEEMES_FLAG", writeToPLC_Flag);
  5732. stopwatch2.Stop();
  5733. }
  5734. stopwatch1.Stop();
  5735. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  5736. }
  5737. #endregion [S2] FCT(板测)
  5738. #endregion PLC2 李晓奇
  5739. #region PLC3 刘永村
  5740. #region [S3] 值板机
  5741. /// <summary>
  5742. /// S3工位的数据- 触发信号上次的值
  5743. /// </summary>
  5744. private Dictionary<string, object> s3PLCSignal_Old = new Dictionary<string, object>();
  5745. /// <summary>
  5746. /// S3工位的数据(含触发信号)
  5747. /// </summary>
  5748. private Dictionary<string, object> s3PLCData = new Dictionary<string, object>();
  5749. /// <summary>
  5750. /// S3工位的数据- 回写点位
  5751. /// </summary>
  5752. private Dictionary<string, WriteToPLC_Flag> s3PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  5753. /// <summary>
  5754. /// [S3] 值板机
  5755. /// </summary>
  5756. /// <param name="plcNo">PLC编号</param>
  5757. //private void ReadStation_S3(int plcNo)
  5758. //{
  5759. // // [S1] Tray盘上料装备
  5760. // // [S2] FCT
  5761. // // [S3] 值板机
  5762. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  5763. // // [S5] Tray盘下料装备
  5764. // /// 上位机心跳
  5765. // /// 获取设备报警数据与状态信息
  5766. // string stationCode = "[S3]";
  5767. // string stationName = "值板机";
  5768. // string stationNameStr = stationCode + stationName;
  5769. // #region 创建字典
  5770. // // 触发信号字典 赋值
  5771. // s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5772. // s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5773. // s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5774. // s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5775. // s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5776. // // PLC数据字典 赋值
  5777. // s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  5778. // s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
  5779. // s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5780. // s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
  5781. // s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
  5782. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5783. // s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5784. // s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
  5785. // s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
  5786. // //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
  5787. // s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
  5788. // s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
  5789. // s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5790. // s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
  5791. // s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
  5792. // s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
  5793. // //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
  5794. // s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5795. // s3PLCData.Add("c1Result", 0); // 产品结果
  5796. // s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  5797. // s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
  5798. // s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
  5799. // s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
  5800. // #endregion 创建字典
  5801. // while (IsRun)
  5802. // {
  5803. // try
  5804. // {
  5805. // if (!GlobalContext._IsCon_Funs3)
  5806. // {
  5807. // UpdatePLCMonitor(1, plcNo, 0);
  5808. // continue;
  5809. // }
  5810. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  5811. // {
  5812. // Stopwatch stopwatch1 = new Stopwatch();
  5813. // Stopwatch stopwatch2 = new Stopwatch();
  5814. // stopwatch1.Start();
  5815. // stopwatch2.Start();
  5816. // #region 一次性读取所有数据
  5817. // // 一次性读取所有数据
  5818. // ModbusClientHelper modbusClientHelper = Funs[plcNo];
  5819. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  5820. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  5821. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
  5822. // int[] datas = data1.Concat(data2).ToArray();
  5823. // datas = datas.Concat(data3).ToArray();
  5824. // s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
  5825. // s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
  5826. // int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  5827. // s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
  5828. // s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
  5829. // s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
  5830. // s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5831. // s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
  5832. // s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
  5833. // s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
  5834. // s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
  5835. // s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  5836. // s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
  5837. // s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
  5838. // int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
  5839. // s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
  5840. // s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  5841. // s3PLCData["c1Result"] = datas[192]; // 产品结果
  5842. // s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
  5843. // s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
  5844. // int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
  5845. // s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
  5846. // s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
  5847. // #endregion 一次性读取所有数据
  5848. // stopwatch2.Stop();
  5849. // #region 回写操作,写后清空flag
  5850. // PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
  5851. // #endregion 回写操作,写后清空flag
  5852. // #region S3进站校验
  5853. // try
  5854. // {
  5855. // int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
  5856. // int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
  5857. // int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
  5858. // if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
  5859. // {
  5860. // if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
  5861. // Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  5862. // else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
  5863. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  5864. // s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
  5865. // }
  5866. // }
  5867. // catch (Exception ex)
  5868. // {
  5869. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  5870. // string str = ex.StackTrace;
  5871. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5872. // }
  5873. // #endregion S3进站校验
  5874. // #region S3二穴载具解绑
  5875. // try
  5876. // {
  5877. // int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
  5878. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
  5879. // int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
  5880. // if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
  5881. // {
  5882. // if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  5883. // Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
  5884. // else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
  5885. // Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)0);
  5886. // s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
  5887. // }
  5888. // }
  5889. // catch (Exception ex)
  5890. // {
  5891. // Funs[plcNo].WriteMultipleRegisters<short>(2083, (short)6); // 6代表上位机报警
  5892. // string str = ex.StackTrace;
  5893. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5894. // }
  5895. // #endregion S3二穴载具解绑
  5896. // #region S3二穴载具绑定
  5897. // try
  5898. // {
  5899. // int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
  5900. // int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
  5901. // int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
  5902. // if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
  5903. // {
  5904. // if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
  5905. // Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
  5906. // else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
  5907. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)0);
  5908. // s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
  5909. // }
  5910. // }
  5911. // catch (Exception ex)
  5912. // {
  5913. // Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  5914. // string str = ex.StackTrace;
  5915. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5916. // }
  5917. // #endregion S3二穴载具绑定
  5918. // #region S3出站接口(+一穴载具绑定)
  5919. // try
  5920. // {
  5921. // int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
  5922. // int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
  5923. // int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
  5924. // if (c1PLC_FLAG != c1PLC_FLAGOld)
  5925. // {
  5926. // if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
  5927. // Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  5928. // else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
  5929. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)0);
  5930. // s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
  5931. // }
  5932. // }
  5933. // catch (Exception ex)
  5934. // {
  5935. // Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)6); // 6代表上位机报警
  5936. // string str = ex.StackTrace;
  5937. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5938. // }
  5939. // #endregion S3出站接口(+一穴载具绑定)
  5940. // #region S3节拍接口
  5941. // try
  5942. // {
  5943. // int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
  5944. // int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
  5945. // int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
  5946. // if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
  5947. // {
  5948. // if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
  5949. // Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  5950. // else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
  5951. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)0);
  5952. // s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
  5953. // }
  5954. // }
  5955. // catch (Exception ex)
  5956. // {
  5957. // Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  5958. // string str = ex.StackTrace;
  5959. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5960. // }
  5961. // #endregion S3节拍接口
  5962. // #region 心跳
  5963. // try
  5964. // {
  5965. // short states = 0;
  5966. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  5967. // }
  5968. // catch (Exception ex)
  5969. // {
  5970. // string str = ex.StackTrace;
  5971. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  5972. // }
  5973. // #endregion 心跳
  5974. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  5975. // stopwatch1.Stop();
  5976. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  5977. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  5978. // }
  5979. // else
  5980. // {
  5981. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5982. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  5983. // Funs[plcNo].Connect();
  5984. // }
  5985. // }
  5986. // catch (Exception ex)
  5987. // {
  5988. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  5989. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  5990. // Funs[plcNo].ReConnect();
  5991. // }
  5992. // Thread.Sleep(IntervalReadPLC);
  5993. // }
  5994. //}
  5995. /// <summary>
  5996. /// [S3] 值板机- 进站校验
  5997. /// </summary>
  5998. /// <param name="plcNo">PLC编号</param>
  5999. /// <param name="stationNameStr">工站全称</param>
  6000. private void S3进站校验(int plcNo, string stationNameStr)
  6001. {
  6002. Stopwatch stopwatch1 = new Stopwatch();
  6003. Stopwatch stopwatch2 = new Stopwatch();
  6004. try
  6005. {
  6006. stopwatch1.Start();
  6007. string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
  6008. sn = sn.Replace("\0", "");
  6009. #region 查询载具上的产品信息
  6010. string cavityData = string.Empty;
  6011. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  6012. if (string.IsNullOrEmpty(cavityData))
  6013. cavityData = "";
  6014. if (snResult != 0)
  6015. {
  6016. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6017. writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
  6018. writeToPLC_Flag1.Adress = 2003;
  6019. writeToPLC_Flag1.Value = (short)6;
  6020. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
  6021. stopwatch1.Stop();
  6022. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6023. return;
  6024. }
  6025. #endregion 查询载具上的产品信息
  6026. string[] cavitySNs = cavityData.Split('.');
  6027. string part1Str = ""; // 产品1的SN码
  6028. string part2Str = ""; // 产品2的SN码
  6029. short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
  6030. short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
  6031. if (cavitySNs != null && cavitySNs.Length >= 2)
  6032. {
  6033. part1Str = cavitySNs[0];
  6034. part2Str = cavitySNs[1];
  6035. c1Part1Result_Check = 2;
  6036. c1Part2Result_Check = 2;
  6037. }
  6038. if (part1Str == "假产品")
  6039. c1Part1Result_Check = 3;
  6040. if (part2Str == "假产品")
  6041. c1Part2Result_Check = 3;
  6042. // 调用MES进站
  6043. stopwatch2.Start();
  6044. // 调用MES进站 - 产品1
  6045. List<TestItem> item;
  6046. int result1 = c1Part1Result_Check;
  6047. if (result1 != 3)
  6048. {
  6049. item = new List<TestItem>();
  6050. item.Add(new TestItem()
  6051. {
  6052. Parameter_name = "载具码",
  6053. Parameter_value = sn,
  6054. });
  6055. item.Add(new TestItem()
  6056. {
  6057. Parameter_name = "载具穴号",
  6058. Parameter_value = "1",
  6059. });
  6060. result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part1Str, item, out string errorMsg);
  6061. }
  6062. // 调用MES进站 - 产品2
  6063. int result2 = c1Part2Result_Check;
  6064. if (result2 != 3)
  6065. {
  6066. item = new List<TestItem>();
  6067. item.Add(new TestItem()
  6068. {
  6069. Parameter_name = "载具码",
  6070. Parameter_value = sn,
  6071. });
  6072. item.Add(new TestItem()
  6073. {
  6074. Parameter_name = "载具穴号",
  6075. Parameter_value = "2",
  6076. });
  6077. result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, part2Str, item, out string errorMsg);
  6078. }
  6079. stopwatch2.Stop();
  6080. if (result1 == 2)
  6081. c1Part1Result_Check = 2;
  6082. if (result2 == 2)
  6083. c1Part2Result_Check = 2;
  6084. int result = result1;
  6085. if (result == 1)
  6086. result = result2;
  6087. short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
  6088. short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
  6089. short c1MES_FLAG_Check = (short)result;
  6090. //Funs[plcNo].WriteMultipleRegisters<short>(2024, c1Part1Result_Check);
  6091. //Funs[plcNo].WriteMultipleRegisters<short>(2025, c1Part2Result_Check);
  6092. //Funs[plcNo].WriteMultipleRegisters<short>(2026, c1Part1Num_Check);
  6093. //Funs[plcNo].WriteMultipleRegisters<short>(2027, c1Part2Num_Check);
  6094. //// MES_Flag
  6095. //Funs[plcNo].WriteMultipleRegisters<short>(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6096. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6097. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6098. writeToPLC_Flag.Adress = 2003;
  6099. writeToPLC_Flag.Value = c1MES_FLAG_Check;
  6100. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6101. {
  6102. Name = "c1Part1Result_Check",
  6103. Adress = 2024,
  6104. ValueType = PLCValueType.Short,
  6105. Value = c1Part1Result_Check
  6106. });
  6107. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6108. {
  6109. Name = "c1Part2Result_Check",
  6110. Adress = 2025,
  6111. ValueType = PLCValueType.Short,
  6112. Value = c1Part2Result_Check
  6113. });
  6114. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6115. {
  6116. Name = "c1Part1Num_Check",
  6117. Adress = 2026,
  6118. ValueType = PLCValueType.Short,
  6119. Value = c1Part1Num_Check
  6120. });
  6121. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  6122. {
  6123. Name = "c1Part2Num_Check",
  6124. Adress = 2027,
  6125. ValueType = PLCValueType.Short,
  6126. Value = c1Part2Num_Check
  6127. });
  6128. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6129. }
  6130. catch (Exception ex)
  6131. {
  6132. string str = ex.StackTrace;
  6133. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6134. // MES_Flag
  6135. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  6136. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6137. writeToPLC_Flag.Name = "c1MES_FLAG_Check";
  6138. writeToPLC_Flag.Adress = 2003;
  6139. writeToPLC_Flag.Value = (short)6;
  6140. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
  6141. }
  6142. stopwatch1.Stop();
  6143. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6144. }
  6145. /// <summary>
  6146. /// [S3] 值板机 - 二穴载具解绑
  6147. /// </summary>
  6148. /// <param name="plcNo">PLC编号</param>
  6149. /// <param name="stationNameStr">工站全称</param>
  6150. private void S3二穴载具解绑(int plcNo, string stationNameStr)
  6151. {
  6152. Stopwatch stopwatch1 = new Stopwatch();
  6153. Stopwatch stopwatch2 = new Stopwatch();
  6154. try
  6155. {
  6156. stopwatch1.Start();
  6157. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6158. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6159. int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6160. // 解绑
  6161. #region 查询载具上的产品信息
  6162. string cavityData = string.Empty;
  6163. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6164. if (string.IsNullOrEmpty(cavityData))
  6165. cavityData = "";
  6166. if (snResult != 0)
  6167. {
  6168. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6169. writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
  6170. writeToPLC_Flag1.Adress = 2082;
  6171. writeToPLC_Flag1.Value = (short)6;
  6172. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
  6173. stopwatch1.Stop();
  6174. AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6175. return;
  6176. }
  6177. #endregion 查询载具上的产品信息
  6178. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6179. #region 解绑
  6180. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6181. {
  6182. // 删除
  6183. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6184. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
  6185. }
  6186. else
  6187. {
  6188. string data_new = string.Join(".", cavitySNs);
  6189. // 删除再插入
  6190. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6191. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6192. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6193. }
  6194. #endregion 解绑
  6195. short c1MES_FLAG_Unbind = 1;
  6196. stopwatch2.Start();
  6197. // MES_Flag
  6198. //Funs[plcNo].WriteMultipleRegisters<short>(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6199. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6200. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6201. writeToPLC_Flag.Adress = 2082;
  6202. writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
  6203. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6204. stopwatch2.Stop();
  6205. }
  6206. catch (Exception ex)
  6207. {
  6208. string str = ex.StackTrace;
  6209. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6210. // MES_Flag
  6211. stopwatch2.Start();
  6212. //Funs[plcNo].WriteMultipleRegisters<short>(2082, (short)6); // 6代表上位机报警
  6213. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6214. writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
  6215. writeToPLC_Flag.Adress = 2082;
  6216. writeToPLC_Flag.Value = (short)6;
  6217. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
  6218. stopwatch2.Stop();
  6219. }
  6220. stopwatch1.Stop();
  6221. AddMessage(LogType.Info, stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6222. }
  6223. /// <summary>
  6224. /// [S3] 值板机 - 二穴载具绑定
  6225. /// </summary>
  6226. /// <param name="plcNo">PLC编号</param>
  6227. /// <param name="stationNameStr">工站全称</param>
  6228. private void S3二穴载具绑定(int plcNo, string stationNameStr)
  6229. {
  6230. Stopwatch stopwatch1 = new Stopwatch();
  6231. Stopwatch stopwatch2 = new Stopwatch();
  6232. try
  6233. {
  6234. stopwatch1.Start();
  6235. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
  6236. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6237. int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
  6238. int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
  6239. int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
  6240. stopwatch2.Start();
  6241. #region 查询载具上的产品信息
  6242. string cavityData = string.Empty;
  6243. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6244. if (string.IsNullOrEmpty(cavityData))
  6245. cavityData = "";
  6246. if (snResult != 0)
  6247. {
  6248. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6249. writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
  6250. writeToPLC_Flag1.Adress = 2115;
  6251. writeToPLC_Flag1.Value = (short)6;
  6252. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
  6253. stopwatch1.Stop();
  6254. AddMessage(LogType.Info, stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6255. return;
  6256. }
  6257. #endregion 查询载具上的产品信息
  6258. // 产品换载具
  6259. string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
  6260. string partSn1 = "";
  6261. string partSn2 = "";
  6262. if (cavitySNs != null && cavitySNs.Length >= 2)
  6263. {
  6264. partSn1 = cavitySNs[0];
  6265. partSn2 = cavitySNs[1];
  6266. }
  6267. string data_new = string.Empty;
  6268. // 是否是两个穴位交换
  6269. if (c1CavityReverse_Bind == 1)
  6270. {
  6271. // 交换
  6272. data_new = string.Concat(partSn2, ".", partSn1);
  6273. }
  6274. else
  6275. { // 不交换
  6276. string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
  6277. cavitySNs[c1VehicleCavityTo_Bind] = sn;
  6278. cavitySNs[c1VehicleCavityFr_Bind] = "";
  6279. data_new = string.Join(".", cavitySNs);
  6280. }
  6281. // 删除再插入
  6282. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6283. int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6284. OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
  6285. stopwatch2.Stop();
  6286. short c1MES_FLAG_Bind = 1;
  6287. // MES_Flag
  6288. //Funs[plcNo].WriteMultipleRegisters<short>(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  6289. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6290. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6291. writeToPLC_Flag.Adress = 2115;
  6292. writeToPLC_Flag.Value = c1MES_FLAG_Bind;
  6293. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6294. }
  6295. catch (Exception ex)
  6296. {
  6297. string str = ex.StackTrace;
  6298. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6299. // MES_Flag
  6300. stopwatch2.Start();
  6301. //Funs[plcNo].WriteMultipleRegisters<short>(2115, (short)6); // 6代表上位机报警
  6302. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6303. writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
  6304. writeToPLC_Flag.Adress = 2115;
  6305. writeToPLC_Flag.Value = (short)6;
  6306. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
  6307. stopwatch2.Stop();
  6308. }
  6309. stopwatch1.Stop();
  6310. AddMessage(LogType.Info, stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6311. }
  6312. //// 上次采集到的SN
  6313. //private string sn_值板机 = string.Empty;
  6314. /// <summary>
  6315. /// [S3] 值板机 - 出站接口
  6316. /// </summary>
  6317. /// <param name="plcNo">PLC编号</param>
  6318. private void S3出站接口(int plcNo, string stationCode, string stationName)
  6319. {
  6320. Stopwatch stopwatch1 = new Stopwatch();
  6321. Stopwatch stopwatch2 = new Stopwatch();
  6322. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  6323. string stationNameStr = stationCode + stationName;
  6324. string processItem = stationName; // 测试项目
  6325. try
  6326. {
  6327. stopwatch1.Start();
  6328. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  6329. //string batch_num = GlobalContext.BatchNumber; // 批次号
  6330. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  6331. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  6332. string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
  6333. sn = sn.Replace("\0", "");
  6334. string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
  6335. c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
  6336. int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
  6337. int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
  6338. bool pass = c1Result == 1;
  6339. // 查sn
  6340. #region 查询载具上的产品信息
  6341. string cavityData = string.Empty;
  6342. int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
  6343. if (string.IsNullOrEmpty(cavityData))
  6344. cavityData = "";
  6345. if (snResult != 0)
  6346. {
  6347. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6348. writeToPLC_Flag1.Name = "c1MES_FLAG";
  6349. writeToPLC_Flag1.Adress = 2150;
  6350. writeToPLC_Flag1.Value = (short)4;
  6351. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
  6352. stopwatch1.Stop();
  6353. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  6354. return;
  6355. }
  6356. #endregion 查询载具上的产品信息
  6357. string[] cavitySNs = cavityData.Split('.');
  6358. string productSN = "";
  6359. if (cavitySNs != null && cavitySNs.Length >= 2)
  6360. {
  6361. productSN = cavitySNs[c1VehicleCavity];
  6362. cavitySNs[c1VehicleCavity] = "";
  6363. }
  6364. stopwatch2.Start();
  6365. List<TestItem> items = new List<TestItem>();
  6366. items.Add(new TestItem()
  6367. {
  6368. Parameter_name = "二穴载具码",
  6369. Parameter_value = c1ProductSN_Check,
  6370. Parameter_unit = ""
  6371. });
  6372. items.Add(new TestItem()
  6373. {
  6374. Parameter_name = "二穴载具穴号",
  6375. Parameter_value = c1VehicleCavity.ToString(),
  6376. Parameter_unit = ""
  6377. });
  6378. items.Add(new TestItem()
  6379. {
  6380. Parameter_name = "一穴载具码",
  6381. Parameter_value = sn,
  6382. Parameter_unit = ""
  6383. });
  6384. items.Add(new TestItem()
  6385. {
  6386. Parameter_name = "一穴载具穴号",
  6387. Parameter_value = "1",
  6388. Parameter_unit = ""
  6389. });
  6390. items.Add(new TestItem()
  6391. {
  6392. Parameter_name = "产品结果",
  6393. Parameter_value = c1Result == 1 ? "OK" : "NG",
  6394. Parameter_unit = ""
  6395. });
  6396. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  6397. , workorder_code, mtltmrk, productSN, pass, sn, "1");
  6398. short result = (short)result1;
  6399. stopwatch2.Stop();
  6400. #region 存储绑定数据到 边线MES系统中
  6401. if (result == 1)
  6402. {
  6403. string data = string.Concat(productSN);
  6404. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  6405. if (resultMesR != 0)
  6406. {
  6407. result = 4;
  6408. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
  6409. }
  6410. }
  6411. #endregion 存储绑定数据到 边线MES系统中
  6412. #region 产品从 来源载具(二穴载具)中删除
  6413. if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
  6414. {
  6415. // 删除
  6416. int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6417. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
  6418. }
  6419. else
  6420. {
  6421. string data_new = string.Join(".", cavitySNs);
  6422. // 删除再插入
  6423. int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
  6424. int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
  6425. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
  6426. }
  6427. #endregion 产品从 来源载具(二穴载具)中删除
  6428. // MES_Flag 为MES报错
  6429. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6430. //Funs[plcNo].WriteMultipleRegisters<short>(2150, result); // 4代表上位机报警
  6431. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6432. writeToPLC_Flag.Name = "c1MES_FLAG";
  6433. writeToPLC_Flag.Adress = 2150;
  6434. writeToPLC_Flag.Value = result;
  6435. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6436. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  6437. }
  6438. catch (Exception ex)
  6439. {
  6440. stopwatch2.Restart();
  6441. // MES_Flag 为4上位机报错
  6442. //Funs[plcNo].WriteMultipleRegisters<short>(2150, (short)4); // 4代表上位机报警
  6443. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6444. writeToPLC_Flag.Name = "c1MES_FLAG";
  6445. writeToPLC_Flag.Adress = 2150;
  6446. writeToPLC_Flag.Value = (short)4;
  6447. SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
  6448. stopwatch2.Stop();
  6449. string str = ex.StackTrace;
  6450. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6451. }
  6452. stopwatch1.Stop();
  6453. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6454. }
  6455. /// <summary>
  6456. /// [S3] 值板机- 节拍接口
  6457. /// </summary>
  6458. /// <param name="plcNo">PLC编号</param>
  6459. /// <param name="stationNameStr">工站全称</param>
  6460. private void S3节拍接口(int plcNo, string stationNameStr)
  6461. {
  6462. Stopwatch stopwatch1 = new Stopwatch();
  6463. Stopwatch stopwatch2 = new Stopwatch();
  6464. string resultStr = string.Empty;
  6465. try
  6466. {
  6467. stopwatch1.Start();
  6468. string oEEType = ((int)s3PLCData["c1OEEType"]).ToString(); // 节拍类型(plc写入)
  6469. string c1OEEProductSN = (string)s3PLCData["c1OEEProductSN"]; // 载具SN
  6470. c1OEEProductSN = c1OEEProductSN.Replace("\0", "");
  6471. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  6472. if (!actionBool)
  6473. {
  6474. stopwatch2.Start();
  6475. // MES_Flag
  6476. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6477. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6478. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6479. writeToPLC_Flag1.Adress = 2204;
  6480. writeToPLC_Flag1.Value = (short)4;
  6481. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6482. stopwatch2.Stop();
  6483. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6484. return;
  6485. }
  6486. string c1OEEPartNo = string.Empty; // 物料码
  6487. if (string.IsNullOrEmpty(c1OEEProductSN))
  6488. {
  6489. stopwatch2.Start();
  6490. // MES_Flag
  6491. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6492. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  6493. writeToPLC_Flag1.Name = "c1OEEMES_FLAG";
  6494. writeToPLC_Flag1.Adress = 2204;
  6495. writeToPLC_Flag1.Value = (short)1;
  6496. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag1);
  6497. stopwatch2.Stop();
  6498. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6499. return;
  6500. }
  6501. else
  6502. { // 查产品SN
  6503. c1OEEPartNo = "Test"; // ZS
  6504. }
  6505. short c1OEEMES_FLAG = 0;
  6506. // 上传OEE
  6507. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, c1OEEPartNo, c1OEEProductSN);
  6508. c1OEEMES_FLAG = result.Item1;
  6509. resultStr = result.Item2;
  6510. stopwatch2.Start();
  6511. // MES_Flag
  6512. //Funs[plcNo].WriteMultipleRegisters<short>(2204, c1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  6513. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6514. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6515. writeToPLC_Flag.Adress = 2204;
  6516. writeToPLC_Flag.Value = c1OEEMES_FLAG;
  6517. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6518. stopwatch2.Stop();
  6519. }
  6520. catch (Exception ex)
  6521. {
  6522. string str = ex.StackTrace;
  6523. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6524. // MES_Flag
  6525. stopwatch2.Start();
  6526. //Funs[plcNo].WriteMultipleRegisters<short>(2204, (short)4); // 4代表上位机报警
  6527. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  6528. writeToPLC_Flag.Name = "c1OEEMES_FLAG";
  6529. writeToPLC_Flag.Adress = 2204;
  6530. writeToPLC_Flag.Value = (short)4;
  6531. SxPLCWriteData_Add(ref s3PLCWriteData, "c1OEEMES_FLAG", writeToPLC_Flag);
  6532. stopwatch2.Stop();
  6533. }
  6534. stopwatch1.Stop();
  6535. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  6536. }
  6537. #endregion [S3] 值板机
  6538. #endregion PLC3 刘永村
  6539. #region PLC4 刘果段
  6540. #region [S4] 取放桁架
  6541. /// <summary>
  6542. /// S4工位的数据- 触发信号上次的值
  6543. /// </summary>
  6544. private Dictionary<string, object> s4PLCSignal_Old = new Dictionary<string, object>();
  6545. /// <summary>
  6546. /// S4工位的数据(含触发信号)
  6547. /// </summary>
  6548. private Dictionary<string, object> s4PLCData = new Dictionary<string, object>();
  6549. /// <summary>
  6550. /// S4工位的数据- 回写点位
  6551. /// </summary>
  6552. private Dictionary<string, WriteToPLC_Flag> s4PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  6553. /// <summary>
  6554. /// [S4] 取放桁架
  6555. /// </summary>
  6556. /// <param name="plcNo">PLC编号</param>
  6557. //private void ReadStation_S4(int plcNo)
  6558. //{
  6559. // // [S1] Tray盘上料装备
  6560. // // [S2] FCT
  6561. // // [S3] 值板机
  6562. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  6563. // // [S5] Tray盘下料装备
  6564. // /// 上位机心跳
  6565. // /// 获取设备报警数据与状态信息
  6566. // string stationCode = "[S4_1]";
  6567. // string stationName = "载具下线装备";
  6568. // string stationNameStr = stationCode + stationName;
  6569. // string stationCode2 = "[S4_2]";
  6570. // string stationName2 = "桁架";
  6571. // string stationNameStr2 = stationCode2 + stationName2;
  6572. // string stationCode3 = "[S4_3]";
  6573. // string stationName3 = "提升机1";
  6574. // string stationNameStr3 = stationCode3 + stationName3;
  6575. // string stationCode4 = "[S4_4]";
  6576. // string stationName4 = "提升机2";
  6577. // string stationNameStr4 = stationCode4 + stationName4;
  6578. // string stationCode5 = "[S4_5]";
  6579. // string stationName5 = "载具上线装备";
  6580. // string stationNameStr5 = stationCode5 + stationName5;
  6581. // #region 创建字典
  6582. // // 触发信号字典 赋值
  6583. // s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6584. // s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6585. // s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6586. // s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6587. // s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6588. // s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6589. // s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6590. // s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6591. // s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6592. // s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6593. // s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6594. // // PLC数据字典 赋值
  6595. // // 载具下线装备(弹夹上线)
  6596. // s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6597. // s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
  6598. // s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
  6599. // s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
  6600. // s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
  6601. // s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
  6602. // s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
  6603. // s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6604. // s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6605. // s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6606. // s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6607. // s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6608. // s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6609. // s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6610. // s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6611. // s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6612. // s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6613. // s4PLCData.Add("d1Result", 0); // 产品结果
  6614. // s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6615. // s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
  6616. // s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
  6617. // s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
  6618. // s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
  6619. // s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
  6620. // s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
  6621. // // 真空标机(提升机)
  6622. // s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
  6623. // s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
  6624. // s4PLCData.Add("d3Type", 0); // 进站还是出站
  6625. // s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
  6626. // s4PLCData.Add("d3Result", 0); // 产品结果
  6627. // s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
  6628. // s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
  6629. // s4PLCData.Add("d4Type", 0); // 进站还是出站
  6630. // s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
  6631. // s4PLCData.Add("d4Result", 0); // 产品结果
  6632. // // 载具上线装备(弹夹下线)
  6633. // s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
  6634. // s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
  6635. // s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
  6636. // s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
  6637. // s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
  6638. // s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
  6639. // s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
  6640. // s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
  6641. // s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
  6642. // s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
  6643. // s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
  6644. // s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
  6645. // s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
  6646. // s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
  6647. // s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
  6648. // s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
  6649. // s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
  6650. // s4PLCData.Add("d5Result", 0); // 产品结果
  6651. // s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  6652. // s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
  6653. // s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
  6654. // s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
  6655. // #endregion 创建字典
  6656. // while (IsRun)
  6657. // {
  6658. // try
  6659. // {
  6660. // if (!GlobalContext._IsCon_Funs4)
  6661. // {
  6662. // UpdatePLCMonitor(1, plcNo, 0);
  6663. // continue;
  6664. // }
  6665. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  6666. // {
  6667. // Stopwatch stopwatch1 = new Stopwatch();
  6668. // Stopwatch stopwatch2 = new Stopwatch();
  6669. // stopwatch1.Start();
  6670. // stopwatch2.Start();
  6671. // #region 一次性读取所有数据
  6672. // // 载具下线装备(弹夹上线)
  6673. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  6674. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
  6675. // int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
  6676. // int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
  6677. // int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
  6678. // int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
  6679. // int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
  6680. // int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
  6681. // int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
  6682. // int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
  6683. // int[] datas = data1.Concat(data2).ToArray();
  6684. // datas = datas.Concat(data3).ToArray();
  6685. // datas = datas.Concat(data4).ToArray();
  6686. // datas = datas.Concat(data5).ToArray();
  6687. // datas = datas.Concat(data6).ToArray();
  6688. // datas = datas.Concat(data7).ToArray();
  6689. // datas = datas.Concat(data8).ToArray();
  6690. // datas = datas.Concat(data9).ToArray();
  6691. // datas = datas.Concat(data10).ToArray();
  6692. // // 载具下线装备(弹夹上线)
  6693. // s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
  6694. // int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
  6695. // s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
  6696. // s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
  6697. // int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
  6698. // s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
  6699. // s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
  6700. // s4PLCData["d1MES_FLAG"] = datas[65];
  6701. // int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
  6702. // s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
  6703. // int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
  6704. // s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
  6705. // int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
  6706. // s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
  6707. // int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
  6708. // s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
  6709. // int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
  6710. // s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
  6711. // int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
  6712. // s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
  6713. // int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
  6714. // s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
  6715. // int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
  6716. // s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
  6717. // int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
  6718. // s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
  6719. // int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
  6720. // s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
  6721. // int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
  6722. // s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
  6723. // int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
  6724. // s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
  6725. // int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
  6726. // s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
  6727. // int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
  6728. // s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
  6729. // int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
  6730. // s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
  6731. // int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
  6732. // s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
  6733. // s4PLCData["d1Result"] = datas[386];
  6734. // s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
  6735. // s4PLCData["d1OEEMES_FLAG"] = datas[398];
  6736. // int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
  6737. // s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
  6738. // s4PLCData["d1OEEType"] = datas[419];
  6739. // // 桁架(查询标机中弹夹的状态)
  6740. // s4PLCData["d2BulletclipScanCode"] = datas[430];
  6741. // s4PLCData["d2BulletclipStates"] = datas[431];
  6742. // int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
  6743. // s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
  6744. // // 真空标机
  6745. // s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
  6746. // s4PLCData["d3MES_FLAG"] = datas[463];
  6747. // int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
  6748. // s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
  6749. // s4PLCData["d3Result"] = datas[484];
  6750. // s4PLCData["d3Type"] = datas[485];
  6751. // s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
  6752. // s4PLCData["d4MES_FLAG"] = datas[496];
  6753. // int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
  6754. // s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
  6755. // s4PLCData["d4Result"] = datas[517];
  6756. // s4PLCData["d4Type"] = datas[518];
  6757. // // 载具上线装备(弹夹下线)
  6758. // s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
  6759. // int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
  6760. // s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
  6761. // s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
  6762. // int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
  6763. // s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
  6764. // s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
  6765. // s4PLCData["d5MES_FLAG"] = datas[591];
  6766. // int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
  6767. // s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
  6768. // int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
  6769. // s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
  6770. // int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
  6771. // s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
  6772. // int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
  6773. // s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
  6774. // int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
  6775. // s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
  6776. // int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
  6777. // s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
  6778. // int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
  6779. // s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
  6780. // int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
  6781. // s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
  6782. // int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
  6783. // s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
  6784. // int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
  6785. // s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
  6786. // int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
  6787. // s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
  6788. // int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
  6789. // s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
  6790. // int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
  6791. // s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
  6792. // int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
  6793. // s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
  6794. // int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
  6795. // s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
  6796. // int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
  6797. // s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
  6798. // s4PLCData["d5Result"] = datas[912];
  6799. // s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
  6800. // s4PLCData["d5OEEMES_FLAG"] = datas[924];
  6801. // int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
  6802. // s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
  6803. // s4PLCData["d5OEEType"] = datas[945];
  6804. // #endregion 一次性读取所有数据
  6805. // stopwatch2.Stop();
  6806. // #region 回写操作,写后清空flag
  6807. // PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
  6808. // #endregion 回写操作,写后清空flag
  6809. // // N801A-S4_1 弹夹扫码
  6810. // #region N801A-S4_1 弹夹扫码
  6811. // try
  6812. // {
  6813. // int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
  6814. // int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
  6815. // if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
  6816. // {
  6817. // if (d1BulletclipScanCode == 1) // 0->1
  6818. // Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6819. // s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
  6820. // }
  6821. // }
  6822. // catch (Exception ex)
  6823. // {
  6824. // Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  6825. // string str = ex.StackTrace;
  6826. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6827. // }
  6828. // #endregion N801A-S4_1 弹夹扫码
  6829. // // N801A-S4_1 载具扫码
  6830. // #region N801A-S4_1 载具扫码
  6831. // try
  6832. // {
  6833. // int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
  6834. // int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
  6835. // if (d1VehicleScanCode != d1VehicleScanCodeOld)
  6836. // {
  6837. // if (d1VehicleScanCode == 1) // 0->1
  6838. // Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
  6839. // s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
  6840. // }
  6841. // }
  6842. // catch (Exception ex)
  6843. // {
  6844. // Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  6845. // string str = ex.StackTrace;
  6846. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6847. // }
  6848. // #endregion N801A-S4_1 载具扫码
  6849. // // N801A-S4_1 出站接口
  6850. // #region N801A-S4_1 出站接口
  6851. // try
  6852. // {
  6853. // int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
  6854. // int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
  6855. // int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
  6856. // if (d1PLC_FLAG != d1PLC_FLAGOld)
  6857. // {
  6858. // if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
  6859. // Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  6860. // else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
  6861. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)0);
  6862. // s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
  6863. // }
  6864. // }
  6865. // catch (Exception ex)
  6866. // {
  6867. // Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)6); // 6代表上位机报警
  6868. // string str = ex.StackTrace;
  6869. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6870. // }
  6871. // #endregion N801A-S4_1 出站接口
  6872. // // N801A-S4_1 节拍接口
  6873. // #region N801A-S4_1 节拍接口
  6874. // try
  6875. // {
  6876. // int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
  6877. // int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
  6878. // int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
  6879. // if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
  6880. // {
  6881. // if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
  6882. // Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  6883. // else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
  6884. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)0);
  6885. // s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
  6886. // }
  6887. // }
  6888. // catch (Exception ex)
  6889. // {
  6890. // Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  6891. // string str = ex.StackTrace;
  6892. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6893. // }
  6894. // #endregion N801A-S4_1 节拍接口
  6895. // // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
  6896. // #region N801A-S4_2 桁架(查询标机中弹夹的状态)
  6897. // try
  6898. // {
  6899. // int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
  6900. // int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
  6901. // if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
  6902. // {
  6903. // if (d2BulletclipScanCode == 1) // 0->1
  6904. // Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
  6905. // s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
  6906. // }
  6907. // }
  6908. // catch (Exception ex)
  6909. // {
  6910. // Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  6911. // string str = ex.StackTrace;
  6912. // AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6913. // }
  6914. // #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
  6915. // // N801A-S4_3 真空标机1 数据
  6916. // #region N801A-S4_3 真空标机1
  6917. // try
  6918. // {
  6919. // int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
  6920. // int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
  6921. // int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
  6922. // if (d3PLC_FLAG != d3PLC_FLAGOld)
  6923. // {
  6924. // if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
  6925. // {
  6926. // int stationType = (int)s4PLCData["d3Type"];
  6927. // if (stationType == 1)
  6928. // {
  6929. // // S4_3进站接口
  6930. // Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
  6931. // }
  6932. // else if (stationType == 2)
  6933. // {
  6934. // // S4_3出站接口
  6935. // Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
  6936. // }
  6937. // }
  6938. // else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
  6939. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)0);
  6940. // s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
  6941. // }
  6942. // }
  6943. // catch (Exception ex)
  6944. // {
  6945. // Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  6946. // string str = ex.StackTrace;
  6947. // AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6948. // }
  6949. // #endregion N801A-S4_3 真空标机1
  6950. // // N801A-S4_4 真空标机2 数据
  6951. // #region N801A-S4_4 真空标机2
  6952. // try
  6953. // {
  6954. // int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
  6955. // int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
  6956. // int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
  6957. // if (d4PLC_FLAG != d4PLC_FLAGOld)
  6958. // {
  6959. // if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
  6960. // {
  6961. // int stationType = (int)s4PLCData["d4Type"];
  6962. // if (stationType == 1)
  6963. // {
  6964. // // S4_4进站接口
  6965. // Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
  6966. // }
  6967. // else if (stationType == 2)
  6968. // {
  6969. // // S4_4出站接口
  6970. // Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
  6971. // }
  6972. // }
  6973. // else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
  6974. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)0);
  6975. // s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
  6976. // }
  6977. // }
  6978. // catch (Exception ex)
  6979. // {
  6980. // Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  6981. // string str = ex.StackTrace;
  6982. // AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  6983. // }
  6984. // #endregion N801A-S4_4 真空标机2
  6985. // // N801A-S4_5 弹夹扫码 数据
  6986. // #region N801A-S4_5 弹夹扫码
  6987. // try
  6988. // {
  6989. // int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
  6990. // int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
  6991. // if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
  6992. // {
  6993. // if (d5BulletclipScanCode == 1) // 0->1
  6994. // Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  6995. // s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
  6996. // }
  6997. // }
  6998. // catch (Exception ex)
  6999. // {
  7000. // Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  7001. // string str = ex.StackTrace;
  7002. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7003. // }
  7004. // #endregion N801A-S4_5 弹夹扫码
  7005. // // N801A-S4_5 载具扫码 数据
  7006. // #region N801A-S4_5 载具扫码
  7007. // try
  7008. // {
  7009. // int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
  7010. // int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
  7011. // if (d5VehicleScanCode != d5VehicleScanCodeOld)
  7012. // {
  7013. // if (d5VehicleScanCode == 1) // 0->1
  7014. // Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
  7015. // s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
  7016. // }
  7017. // }
  7018. // catch (Exception ex)
  7019. // {
  7020. // Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  7021. // string str = ex.StackTrace;
  7022. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7023. // }
  7024. // #endregion N801A-S4_5 载具扫码
  7025. // // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
  7026. // #region N801A-S4_5 出站接口
  7027. // try
  7028. // {
  7029. // int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
  7030. // int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
  7031. // int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
  7032. // if (d5PLC_FLAG != d5PLC_FLAGOld)
  7033. // {
  7034. // if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
  7035. // Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
  7036. // else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
  7037. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)0);
  7038. // s4PLCSignal_Old["d5PLC_FLAG"] = s4PLCData["d5PLC_FLAG"];
  7039. // }
  7040. // }
  7041. // catch (Exception ex)
  7042. // {
  7043. // Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)6); // 6代表上位机报警
  7044. // string str = ex.StackTrace;
  7045. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7046. // }
  7047. // #endregion N801A-S4_5 出站接口
  7048. // // N801A-S4_5 节拍接口 数据
  7049. // #region N801A-S4_5 节拍接口
  7050. // try
  7051. // {
  7052. // int d5OEEPLC_FLAG = (int)s4PLCData["d5OEEPLC_FLAG"];
  7053. // int d5OEEMES_FLAG = (int)s4PLCData["d5OEEMES_FLAG"];
  7054. // int d5OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d5OEEPLC_FLAG"];
  7055. // if (d5OEEPLC_FLAG != d5OEEPLC_FLAGOld)
  7056. // {
  7057. // if (d5OEEPLC_FLAG == 1 && d5OEEMES_FLAG == 0) // 0->1
  7058. // Task.Run(() => S4_5节拍接口(plcNo, stationNameStr5)); // MreTasks[4].Set();
  7059. // else if (d5OEEPLC_FLAG == 0 && d5OEEMES_FLAG != 0)
  7060. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)0);
  7061. // s4PLCSignal_Old["d5OEEPLC_FLAG"] = s4PLCData["d5OEEPLC_FLAG"];
  7062. // }
  7063. // }
  7064. // catch (Exception ex)
  7065. // {
  7066. // Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  7067. // string str = ex.StackTrace;
  7068. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7069. // }
  7070. // #endregion N801A-S4_5 节拍接口
  7071. // #region 心跳
  7072. // try
  7073. // {
  7074. // short states = 0;
  7075. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  7076. // }
  7077. // catch (Exception ex)
  7078. // {
  7079. // string str = ex.StackTrace;
  7080. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7081. // }
  7082. // #endregion 心跳
  7083. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  7084. // stopwatch1.Stop();
  7085. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  7086. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  7087. // }
  7088. // else
  7089. // {
  7090. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7091. // AddMessage_Station(stationNameStr5, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr5 + "连接失败!");
  7092. // Funs[plcNo].Connect();
  7093. // }
  7094. // }
  7095. // catch (Exception ex)
  7096. // {
  7097. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  7098. // AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5}运行出错!错误信息:" + ex.Message.ToString());
  7099. // Funs[plcNo].ReConnect();
  7100. // }
  7101. // Thread.Sleep(IntervalReadPLC);
  7102. // }
  7103. //}
  7104. /// <summary>
  7105. /// [S4] 取放桁架 - S4_1弹夹扫码
  7106. /// </summary>
  7107. /// <param name="plcNo">PLC编号</param>
  7108. /// <param name="stationNameStr">工站全称</param>
  7109. private void S4_1弹夹扫码(int plcNo, string stationNameStr)
  7110. {
  7111. Stopwatch stopwatch1 = new Stopwatch();
  7112. Stopwatch stopwatch2 = new Stopwatch();
  7113. try
  7114. {
  7115. stopwatch1.Start();
  7116. // ZS 弹夹扫码
  7117. string d1BulletclipCode = " "; // 扫到的码
  7118. short d1BulletclipScanCode = 2;
  7119. stopwatch2.Start();
  7120. //Funs[plcNo].WriteMultipleRegisters<string>(2003, d1BulletclipCode, 20);
  7121. //// MES_Flag
  7122. //Funs[plcNo].WriteMultipleRegisters<short>(2002, d1BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7123. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7124. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7125. writeToPLC_Flag.Adress = 2002;
  7126. writeToPLC_Flag.Value = d1BulletclipScanCode;
  7127. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7128. {
  7129. Name = "d1BulletclipCode",
  7130. Adress = 2003,
  7131. ValueType = PLCValueType.String,
  7132. ValueTypeStrLength = 20,
  7133. Value = d1BulletclipCode
  7134. });
  7135. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7136. stopwatch2.Stop();
  7137. }
  7138. catch (Exception ex)
  7139. {
  7140. string str = ex.StackTrace;
  7141. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7142. stopwatch2.Start();
  7143. //Funs[plcNo].WriteMultipleRegisters<string>(2003, " ", 20);
  7144. //// MES_Flag
  7145. //Funs[plcNo].WriteMultipleRegisters<short>(2002, (short)6); // 6代表上位机报警
  7146. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7147. writeToPLC_Flag.Name = "d1BulletclipScanCode";
  7148. writeToPLC_Flag.Adress = 2002;
  7149. writeToPLC_Flag.Value = (short)6;
  7150. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
  7151. {
  7152. Name = "d1BulletclipCode",
  7153. Adress = 2003,
  7154. ValueType = PLCValueType.String,
  7155. ValueTypeStrLength = 20,
  7156. Value = " "
  7157. });
  7158. SxPLCWriteData_Add(ref s4PLCWriteData, "d1BulletclipScanCode", writeToPLC_Flag);
  7159. stopwatch2.Stop();
  7160. }
  7161. stopwatch1.Stop();
  7162. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7163. }
  7164. /// <summary>
  7165. /// [S4] 取放桁架 - S4_1载具扫码
  7166. /// </summary>
  7167. /// <param name="plcNo">PLC编号</param>
  7168. /// <param name="stationNameStr">工站全称</param>
  7169. private void S4_1载具扫码(int plcNo, string stationNameStr)
  7170. {
  7171. Stopwatch stopwatch1 = new Stopwatch();
  7172. Stopwatch stopwatch2 = new Stopwatch();
  7173. try
  7174. {
  7175. stopwatch1.Start();
  7176. // ZS 载具扫码
  7177. string d1VehicleCode = ""; // 扫到的码
  7178. short d1VehicleScanCode = 2;
  7179. #region 进站
  7180. if (d1VehicleScanCode == 2 && !string.IsNullOrEmpty(d1VehicleCode))
  7181. {
  7182. #region 查询载具上的产品信息
  7183. string cavityData = string.Empty;
  7184. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d1VehicleCode, ref cavityData);
  7185. if (string.IsNullOrEmpty(cavityData))
  7186. cavityData = "";
  7187. if (snResult != 0)
  7188. {
  7189. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7190. writeToPLC_Flag1.Name = "d1VehicleScanCode";
  7191. writeToPLC_Flag1.Adress = 2033;
  7192. writeToPLC_Flag1.Value = (short)6; // 6代表上位机报警
  7193. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7194. {
  7195. Name = "d1VehicleCode",
  7196. Adress = 2034,
  7197. ValueType = PLCValueType.String,
  7198. ValueTypeStrLength = 20,
  7199. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7200. });
  7201. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag1);
  7202. stopwatch1.Stop();
  7203. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7204. return;
  7205. }
  7206. string[] cavitySNs = cavityData.Split('.');
  7207. string partNo = "";
  7208. if (cavitySNs != null && cavitySNs.Length >= 1)
  7209. {
  7210. partNo = cavitySNs[0];
  7211. }
  7212. #endregion 查询载具上的产品信息
  7213. List<TestItem> item = new List<TestItem>();
  7214. item.Add(new TestItem()
  7215. {
  7216. Parameter_name = "载具码",
  7217. Parameter_value = d1VehicleCode,
  7218. });
  7219. item.Add(new TestItem()
  7220. {
  7221. Parameter_name = "载具穴号",
  7222. Parameter_value = "1",
  7223. });
  7224. stopwatch2.Start();
  7225. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  7226. stopwatch2.Stop();
  7227. d1VehicleScanCode = (short)result == 1 ? d1VehicleScanCode : (short)result;
  7228. }
  7229. #endregion 进站
  7230. //Funs[plcNo].WriteMultipleRegisters<string>(2034, d1VehicleCode, 20);
  7231. //// MES_Flag
  7232. //Funs[plcNo].WriteMultipleRegisters<short>(2033, d1VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7233. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7234. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7235. writeToPLC_Flag.Adress = 2033;
  7236. writeToPLC_Flag.Value = d1VehicleScanCode;
  7237. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7238. {
  7239. Name = "d1VehicleCode",
  7240. Adress = 2034,
  7241. ValueType = PLCValueType.String,
  7242. ValueTypeStrLength = 20,
  7243. Value = d1VehicleCode
  7244. });
  7245. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7246. }
  7247. catch (Exception ex)
  7248. {
  7249. string str = ex.StackTrace;
  7250. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7251. stopwatch2.Start();
  7252. //Funs[plcNo].WriteMultipleRegisters<string>(2034, " ", 20);
  7253. //// MES_Flag
  7254. //Funs[plcNo].WriteMultipleRegisters<short>(2033, (short)6); // 6代表上位机报警
  7255. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7256. writeToPLC_Flag.Name = "d1VehicleScanCode";
  7257. writeToPLC_Flag.Adress = 2033;
  7258. writeToPLC_Flag.Value = (short)6; // 6代表上位机报警
  7259. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7260. {
  7261. Name = "d1VehicleCode",
  7262. Adress = 2034,
  7263. ValueType = PLCValueType.String,
  7264. ValueTypeStrLength = 20,
  7265. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  7266. });
  7267. SxPLCWriteData_Add(ref s4PLCWriteData, "d1VehicleScanCode", writeToPLC_Flag);
  7268. stopwatch2.Stop();
  7269. }
  7270. stopwatch1.Stop();
  7271. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7272. }
  7273. // 上次采集到的SN
  7274. //private string sn_S4_1出站接口 = string.Empty;
  7275. /// <summary>
  7276. /// [S4] 取放桁架 - S4_1出站接口
  7277. /// </summary>
  7278. private void S4_1出站接口(int plcNo, string stationCode, string stationName)
  7279. {
  7280. Stopwatch stopwatch1 = new Stopwatch();
  7281. Stopwatch stopwatch2 = new Stopwatch();
  7282. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7283. string stationNameStr = stationCode + stationName;
  7284. string processItem = stationName; // 测试项目
  7285. try
  7286. {
  7287. stopwatch1.Start();
  7288. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7289. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7290. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7291. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7292. string sn = (string)s4PLCData["d1ProductSN"]; // 产品SN(弹夹码)
  7293. sn = sn.Replace("\0", "");
  7294. string d1VehicleCode1 = (string)s4PLCData["d1VehicleCode1"]; // 载具1码(弹夹穴位1)
  7295. d1VehicleCode1 = d1VehicleCode1.Replace("\0", "");
  7296. string d1VehicleCode2 = (string)s4PLCData["d1VehicleCode2"]; // 载具2码(弹夹穴位2)
  7297. d1VehicleCode2 = d1VehicleCode2.Replace("\0", "");
  7298. string d1VehicleCode3 = (string)s4PLCData["d1VehicleCode3"]; // 载具3码(弹夹穴位3)
  7299. d1VehicleCode3 = d1VehicleCode3.Replace("\0", "");
  7300. string d1VehicleCode4 = (string)s4PLCData["d1VehicleCode4"]; // 载具4码(弹夹穴位4)
  7301. d1VehicleCode4 = d1VehicleCode4.Replace("\0", "");
  7302. string d1VehicleCode5 = (string)s4PLCData["d1VehicleCode5"]; // 载具5码(弹夹穴位5)
  7303. d1VehicleCode5 = d1VehicleCode5.Replace("\0", "");
  7304. string d1VehicleCode6 = (string)s4PLCData["d1VehicleCode6"]; // 载具6码(弹夹穴位6)
  7305. d1VehicleCode6 = d1VehicleCode6.Replace("\0", "");
  7306. string d1VehicleCode7 = (string)s4PLCData["d1VehicleCode7"]; // 载具7码(弹夹穴位7)
  7307. d1VehicleCode7 = d1VehicleCode7.Replace("\0", "");
  7308. string d1VehicleCode8 = (string)s4PLCData["d1VehicleCode8"]; // 载具8码(弹夹穴位8)
  7309. d1VehicleCode8 = d1VehicleCode8.Replace("\0", "");
  7310. string d1VehicleCode9 = (string)s4PLCData["d1VehicleCode9"]; // 载具9码(弹夹穴位9)
  7311. d1VehicleCode9 = d1VehicleCode9.Replace("\0", "");
  7312. string d1VehicleCode10 = (string)s4PLCData["d1VehicleCode10"]; // 载具10码(弹夹穴位10)
  7313. d1VehicleCode10 = d1VehicleCode10.Replace("\0", "");
  7314. string d1VehicleCode11 = (string)s4PLCData["d1VehicleCode11"]; // 载具11码(弹夹穴位11)
  7315. d1VehicleCode11 = d1VehicleCode11.Replace("\0", "");
  7316. string d1VehicleCode12 = (string)s4PLCData["d1VehicleCode12"]; // 载具12码(弹夹穴位12)
  7317. d1VehicleCode12 = d1VehicleCode12.Replace("\0", "");
  7318. string d1VehicleCode13 = (string)s4PLCData["d1VehicleCode13"]; // 载具13码(弹夹穴位13)
  7319. d1VehicleCode13 = d1VehicleCode13.Replace("\0", "");
  7320. string d1VehicleCode14 = (string)s4PLCData["d1VehicleCode14"]; // 载具14码(弹夹穴位14)
  7321. d1VehicleCode14 = d1VehicleCode14.Replace("\0", "");
  7322. string d1VehicleCode15 = (string)s4PLCData["d1VehicleCode15"]; // 载具15码(弹夹穴位15)
  7323. d1VehicleCode15 = d1VehicleCode15.Replace("\0", "");
  7324. int d1Result = (int)s4PLCData["d1Result"]; // 产品结果
  7325. bool pass = d1Result == 1;
  7326. // 存 载具SN列表
  7327. List<string> vehicleCodes = new List<string>()
  7328. {
  7329. d1VehicleCode1,d1VehicleCode2,d1VehicleCode3,d1VehicleCode4,d1VehicleCode5,
  7330. d1VehicleCode6,d1VehicleCode7,d1VehicleCode8,d1VehicleCode9,d1VehicleCode10,
  7331. d1VehicleCode11,d1VehicleCode12,d1VehicleCode13,d1VehicleCode14,d1VehicleCode15
  7332. };
  7333. // 统一查 产品SN列表
  7334. List<string> partNos = new List<string>();
  7335. foreach (string vehicleCode in vehicleCodes)
  7336. {
  7337. if (string.IsNullOrEmpty(vehicleCode))
  7338. partNos.Add("");
  7339. else
  7340. {
  7341. string partNo = "";
  7342. #region 查询载具上的产品信息
  7343. string cavityData = string.Empty;
  7344. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7345. if (string.IsNullOrEmpty(cavityData))
  7346. cavityData = "";
  7347. if (snResult != 0)
  7348. {
  7349. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7350. writeToPLC_Flag1.Name = "d1MES_FLAG";
  7351. writeToPLC_Flag1.Adress = 2065;
  7352. writeToPLC_Flag1.Value = (short)4;
  7353. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag1);
  7354. stopwatch1.Stop();
  7355. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7356. return;
  7357. }
  7358. string[] cavitySNs = cavityData.Split('.');
  7359. if (cavitySNs != null && cavitySNs.Length >= 1)
  7360. partNo = cavitySNs[0];
  7361. #endregion 查询载具上的产品信息
  7362. partNos.Add(partNo);
  7363. }
  7364. }
  7365. // 统一上传
  7366. stopwatch2.Start();
  7367. List<int> results = new List<int>();
  7368. for (int i = 0; i < partNos.Count; i++)
  7369. {
  7370. string index = (i + 1).ToString(); // 弹夹穴号
  7371. if (string.IsNullOrEmpty(partNos[i]))
  7372. results.Add(1);
  7373. else
  7374. {
  7375. List<TestItem> items1 = new List<TestItem>();
  7376. items1.Add(new TestItem()
  7377. {
  7378. Parameter_name = "弹夹码",
  7379. Parameter_value = sn,
  7380. Parameter_unit = ""
  7381. });
  7382. items1.Add(new TestItem()
  7383. {
  7384. Parameter_name = "弹夹穴号",
  7385. Parameter_value = index,
  7386. Parameter_unit = ""
  7387. });
  7388. items1.Add(new TestItem()
  7389. {
  7390. Parameter_name = "载具码",
  7391. Parameter_value = vehicleCodes[i],
  7392. Parameter_unit = ""
  7393. });
  7394. items1.Add(new TestItem()
  7395. {
  7396. Parameter_name = "载具穴号",
  7397. Parameter_value = "1",
  7398. Parameter_unit = ""
  7399. });
  7400. items1.Add(new TestItem()
  7401. {
  7402. Parameter_name = "产品结果",
  7403. Parameter_value = d1Result == 1 ? "OK" : "NG",
  7404. Parameter_unit = ""
  7405. });
  7406. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7407. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  7408. results.Add(result1);
  7409. }
  7410. }
  7411. short result = 0;
  7412. if (results.All(a => a == 1))
  7413. result = 1;
  7414. else if (results.Contains(3))
  7415. result = 3;
  7416. else if (results.Contains(2))
  7417. result = 2;
  7418. else if (results.Contains(4))
  7419. result = 4;
  7420. else
  7421. result = 4;
  7422. stopwatch2.Stop();
  7423. #region 存储绑定数据到 边线MES系统中
  7424. if (result == 1)
  7425. {
  7426. string data = string.Join(".", vehicleCodes);
  7427. int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
  7428. if (resultMesR != 0)
  7429. {
  7430. result = 4;
  7431. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  7432. }
  7433. }
  7434. #endregion 存储绑定数据到 边线MES系统中
  7435. // MES_Flag 为4MES报错
  7436. //Funs[plcNo].WriteMultipleRegisters<short>(2065, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7437. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7438. writeToPLC_Flag.Name = "d1MES_FLAG";
  7439. writeToPLC_Flag.Adress = 2065;
  7440. writeToPLC_Flag.Value = result;
  7441. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7442. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  7443. }
  7444. catch (Exception ex)
  7445. {
  7446. stopwatch2.Restart();
  7447. // MES_Flag 为4上位机报错
  7448. //Funs[plcNo].WriteMultipleRegisters<short>(2065, (short)4); // 4代表上位机报警
  7449. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7450. writeToPLC_Flag.Name = "d1MES_FLAG";
  7451. writeToPLC_Flag.Adress = 2065;
  7452. writeToPLC_Flag.Value = (short)4;
  7453. SxPLCWriteData_Add(ref s4PLCWriteData, "d1MES_FLAG", writeToPLC_Flag);
  7454. stopwatch2.Stop();
  7455. string str = ex.StackTrace;
  7456. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7457. }
  7458. stopwatch1.Stop();
  7459. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7460. }
  7461. /// <summary>
  7462. /// [S4] 取放桁架 - S4_1节拍接口
  7463. /// </summary>
  7464. /// <param name="plcNo">PLC编号</param>
  7465. /// <param name="stationNameStr">工站全称</param>
  7466. private void S4_1节拍接口(int plcNo, string stationNameStr)
  7467. {
  7468. Stopwatch stopwatch1 = new Stopwatch();
  7469. Stopwatch stopwatch2 = new Stopwatch();
  7470. string resultStr = string.Empty;
  7471. try
  7472. {
  7473. stopwatch1.Start();
  7474. string oEEType = ((int)s4PLCData["d1OEEType"]).ToString(); // 节拍类型(plc写入)
  7475. string d1OEEProductSN = (string)s4PLCData["d1OEEProductSN"]; // 载具SN
  7476. d1OEEProductSN = d1OEEProductSN.Replace("\0", "");
  7477. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  7478. if (!actionBool)
  7479. {
  7480. stopwatch2.Start();
  7481. // MES_Flag
  7482. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7483. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7484. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7485. writeToPLC_Flag1.Adress = 2398;
  7486. writeToPLC_Flag1.Value = (short)4;
  7487. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7488. stopwatch2.Stop();
  7489. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7490. return;
  7491. }
  7492. string d1OEEPartNo = string.Empty; // 物料码
  7493. if (string.IsNullOrEmpty(d1OEEProductSN))
  7494. {
  7495. stopwatch2.Start();
  7496. // MES_Flag
  7497. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7498. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7499. writeToPLC_Flag1.Name = "d1OEEMES_FLAG";
  7500. writeToPLC_Flag1.Adress = 2398;
  7501. writeToPLC_Flag1.Value = (short)1;
  7502. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag1);
  7503. stopwatch2.Stop();
  7504. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7505. return;
  7506. }
  7507. else
  7508. { // 查产品SN ZS
  7509. d1OEEPartNo = "Test";
  7510. }
  7511. short d1OEEMES_FLAG = 0;
  7512. // 上传OEE
  7513. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d1OEEPartNo, d1OEEProductSN);
  7514. d1OEEMES_FLAG = result.Item1;
  7515. resultStr = result.Item2;
  7516. stopwatch2.Start();
  7517. // MES_Flag
  7518. //Funs[plcNo].WriteMultipleRegisters<short>(2398, d1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7519. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7520. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7521. writeToPLC_Flag.Adress = 2398;
  7522. writeToPLC_Flag.Value = d1OEEMES_FLAG;
  7523. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7524. stopwatch2.Stop();
  7525. }
  7526. catch (Exception ex)
  7527. {
  7528. string str = ex.StackTrace;
  7529. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7530. // MES_Flag
  7531. stopwatch2.Start();
  7532. //Funs[plcNo].WriteMultipleRegisters<short>(2398, (short)4); // 4代表上位机报警
  7533. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7534. writeToPLC_Flag.Name = "d1OEEMES_FLAG";
  7535. writeToPLC_Flag.Adress = 2398;
  7536. writeToPLC_Flag.Value = (short)4;
  7537. SxPLCWriteData_Add(ref s4PLCWriteData, "d1OEEMES_FLAG", writeToPLC_Flag);
  7538. stopwatch2.Stop();
  7539. }
  7540. stopwatch1.Stop();
  7541. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7542. }
  7543. /// <summary>
  7544. /// [S4] 取放桁架 - S4_2桁架
  7545. /// </summary>
  7546. /// <param name="plcNo">PLC编号</param>
  7547. /// <param name="stationNameStr">工站全称</param>
  7548. private void S4_2桁架(int plcNo, string stationNameStr)
  7549. {
  7550. Stopwatch stopwatch1 = new Stopwatch();
  7551. Stopwatch stopwatch2 = new Stopwatch();
  7552. try
  7553. {
  7554. stopwatch1.Start();
  7555. // ZS 弹夹扫码
  7556. string d2BulletclipCode = " "; // 扫到的码
  7557. short d2BulletclipStates = 1; // 弹夹状态(上位机写入)
  7558. short d2BulletclipScanCode = 2;
  7559. stopwatch2.Start();
  7560. //Funs[plcNo].WriteMultipleRegisters<string>(2432, d2BulletclipCode, 20); // 扫到的码
  7561. //Funs[plcNo].WriteMultipleRegisters<short>(2431, d2BulletclipStates); // 弹夹状态(上位机写入)
  7562. //// MES_Flag
  7563. //Funs[plcNo].WriteMultipleRegisters<short>(2430, d2BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  7564. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7565. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7566. writeToPLC_Flag.Adress = 2430;
  7567. writeToPLC_Flag.Value = d2BulletclipScanCode;
  7568. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7569. {
  7570. Name = "d2BulletclipCode",
  7571. Adress = 2432,
  7572. ValueType = PLCValueType.String,
  7573. ValueTypeStrLength = 20,
  7574. Value = d2BulletclipCode
  7575. });
  7576. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7577. {
  7578. Name = "d2BulletclipStates",
  7579. Adress = 2431,
  7580. ValueType = PLCValueType.Short,
  7581. Value = d2BulletclipStates
  7582. });
  7583. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7584. stopwatch2.Stop();
  7585. }
  7586. catch (Exception ex)
  7587. {
  7588. string str = ex.StackTrace;
  7589. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7590. stopwatch2.Start();
  7591. Funs[plcNo].WriteMultipleRegisters<string>(2432, " ", 20);
  7592. Funs[plcNo].WriteMultipleRegisters<short>(2431, (short)0);
  7593. // MES_Flag
  7594. Funs[plcNo].WriteMultipleRegisters<short>(2430, (short)6); // 6代表上位机报警
  7595. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7596. writeToPLC_Flag.Name = "d2BulletclipScanCode";
  7597. writeToPLC_Flag.Adress = 2430;
  7598. writeToPLC_Flag.Value = (short)6;
  7599. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7600. {
  7601. Name = "d2BulletclipCode",
  7602. Adress = 2432,
  7603. ValueType = PLCValueType.String,
  7604. ValueTypeStrLength = 20,
  7605. Value = " "
  7606. });
  7607. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
  7608. {
  7609. Name = "d2BulletclipStates",
  7610. Adress = 2431,
  7611. ValueType = PLCValueType.Short,
  7612. Value = (short)0
  7613. });
  7614. SxPLCWriteData_Add(ref s4PLCWriteData, "d2BulletclipScanCode", writeToPLC_Flag);
  7615. stopwatch2.Stop();
  7616. }
  7617. stopwatch1.Stop();
  7618. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7619. }
  7620. // 上次采集到的SN
  7621. //private string sn_S4_3进站接口 = string.Empty;
  7622. /// <summary>
  7623. /// [S4] 取放桁架 - S4_3进站接口(提升机1)
  7624. /// </summary>
  7625. private void S4_3进站接口(int plcNo, string stationNameStr)
  7626. {
  7627. Stopwatch stopwatch1 = new Stopwatch();
  7628. Stopwatch stopwatch2 = new Stopwatch();
  7629. try
  7630. {
  7631. stopwatch1.Start();
  7632. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7633. sn = sn.Replace("\0", "");
  7634. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7635. #region 查询15个载具码
  7636. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7637. string vehicleData = string.Empty;
  7638. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7639. if (string.IsNullOrEmpty(vehicleData))
  7640. vehicleData = "";
  7641. if (snResult != 0)
  7642. {
  7643. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7644. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7645. writeToPLC_Flag1.Adress = 2463;
  7646. writeToPLC_Flag1.Value = (short)4;
  7647. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7648. stopwatch1.Stop();
  7649. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7650. return;
  7651. }
  7652. string[] cavitySNs = vehicleData.Split('.');
  7653. if (cavitySNs != null && cavitySNs.Length > 0)
  7654. {
  7655. for (int i = 0; i < cavitySNs.Length; i++)
  7656. {
  7657. if (string.IsNullOrEmpty(cavitySNs[i]))
  7658. vehicleCodes.Add("");
  7659. else
  7660. vehicleCodes.Add(cavitySNs[i]);
  7661. }
  7662. }
  7663. #endregion 查询15个载具码
  7664. #region 查询15个产品SN
  7665. List<string> portNos = new List<string>(); // 15个产品SN
  7666. foreach (string vehicleCode in vehicleCodes)
  7667. {
  7668. if (string.IsNullOrEmpty(vehicleCode))
  7669. portNos.Add("");
  7670. else
  7671. {
  7672. // 查询
  7673. string cavityData = string.Empty;
  7674. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7675. if (string.IsNullOrEmpty(cavityData))
  7676. cavityData = "";
  7677. if (snResult1 != 0)
  7678. {
  7679. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7680. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7681. writeToPLC_Flag1.Adress = 2463;
  7682. writeToPLC_Flag1.Value = (short)4;
  7683. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7684. stopwatch1.Stop();
  7685. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7686. return;
  7687. }
  7688. string[] partSNs = cavityData.Split('.');
  7689. if (partSNs != null && partSNs.Length >= 1)
  7690. portNos.Add(partSNs[0]);
  7691. else
  7692. portNos.Add("");
  7693. }
  7694. }
  7695. #endregion 查询15个产品SN
  7696. // 调用MES进站(最多15个)
  7697. stopwatch2.Start();
  7698. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  7699. for (int i = 0; i < vehicleCodes.Count; i++)
  7700. {
  7701. // 循环进站
  7702. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  7703. {
  7704. // 产品SN(物料码)校验
  7705. string portNo = portNos[i];
  7706. List<TestItem> item = new List<TestItem>();
  7707. item.Add(new TestItem()
  7708. {
  7709. Parameter_name = "弹夹码",
  7710. Parameter_value = sn,
  7711. });
  7712. item.Add(new TestItem()
  7713. {
  7714. Parameter_name = "弹夹穴位",
  7715. Parameter_value = (i + 1).ToString(),
  7716. });
  7717. item.Add(new TestItem()
  7718. {
  7719. Parameter_name = "载具码",
  7720. Parameter_value = vehicleCodes[i],
  7721. });
  7722. item.Add(new TestItem()
  7723. {
  7724. Parameter_name = "载具穴号",
  7725. Parameter_value = "1",
  7726. });
  7727. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  7728. }
  7729. }
  7730. stopwatch2.Stop();
  7731. short result = 0;
  7732. bool haveMesWarn = results.Contains(5);
  7733. bool havePCWarn = results.Contains(6);
  7734. if (haveMesWarn)
  7735. result = 2; // 5->2
  7736. else if (havePCWarn)
  7737. result = 6; // 6->4
  7738. else
  7739. result = 1;
  7740. // MES_Flag 为4MES报错
  7741. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7742. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7743. writeToPLC_Flag.Name = "d3MES_FLAG";
  7744. writeToPLC_Flag.Adress = 2463;
  7745. writeToPLC_Flag.Value = result;
  7746. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7747. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7748. }
  7749. catch (Exception ex)
  7750. {
  7751. stopwatch2.Stop();
  7752. // MES_Flag 为4上位机报错
  7753. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7754. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7755. writeToPLC_Flag.Name = "d3MES_FLAG";
  7756. writeToPLC_Flag.Adress = 2463;
  7757. writeToPLC_Flag.Value = (short)4;
  7758. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7759. string str = ex.StackTrace;
  7760. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7761. }
  7762. stopwatch1.Stop();
  7763. AddMessage(LogType.Info, stationNameStr + "_S4_3进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7764. }
  7765. // 上次采集到的SN
  7766. //private string sn_S4_3出站接口 = string.Empty;
  7767. /// <summary>
  7768. /// [S4] 取放桁架 - S4_3出站接口(提升机1)
  7769. /// </summary>
  7770. private void S4_3出站接口(int plcNo, string stationCode, string stationName)
  7771. {
  7772. Stopwatch stopwatch1 = new Stopwatch();
  7773. Stopwatch stopwatch2 = new Stopwatch();
  7774. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  7775. string stationNameStr = stationCode + stationName;
  7776. string processItem = stationName; // 测试项目
  7777. try
  7778. {
  7779. stopwatch1.Start();
  7780. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  7781. //string batch_num = GlobalContext.BatchNumber; // 批次号
  7782. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  7783. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  7784. string sn = (string)s4PLCData["d3ProductSN"]; // 产品SN(弹夹码)
  7785. sn = sn.Replace("\0", "");
  7786. int d3Result = (int)s4PLCData["d3Result"]; // 产品结果
  7787. bool isPass = d3Result == 1; // 产品结果 bool
  7788. #region 查询15个载具码
  7789. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7790. string vehicleData = string.Empty;
  7791. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7792. if (string.IsNullOrEmpty(vehicleData))
  7793. vehicleData = "";
  7794. if (snResult1 != 0)
  7795. {
  7796. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7797. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7798. writeToPLC_Flag1.Adress = 2463;
  7799. writeToPLC_Flag1.Value = (short)4;
  7800. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7801. stopwatch1.Stop();
  7802. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7803. return;
  7804. }
  7805. string[] cavitySNs = vehicleData.Split('.');
  7806. if (cavitySNs != null && cavitySNs.Length > 0)
  7807. {
  7808. for (int i = 0; i < cavitySNs.Length; i++)
  7809. {
  7810. if (string.IsNullOrEmpty(cavitySNs[i]))
  7811. vehicleCodes.Add("");
  7812. else
  7813. vehicleCodes.Add(cavitySNs[i]);
  7814. }
  7815. }
  7816. #endregion 查询15个载具码
  7817. // 统一查 产品SN列表
  7818. List<string> partNos = new List<string>();
  7819. foreach (string vehicleCode in vehicleCodes)
  7820. {
  7821. if (string.IsNullOrEmpty(vehicleCode))
  7822. partNos.Add("");
  7823. else
  7824. {
  7825. string partNo = "";
  7826. #region 查询载具上的产品信息
  7827. string cavityData = string.Empty;
  7828. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7829. if (string.IsNullOrEmpty(cavityData))
  7830. cavityData = "";
  7831. if (snResult != 0)
  7832. {
  7833. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7834. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7835. writeToPLC_Flag1.Adress = 2463;
  7836. writeToPLC_Flag1.Value = (short)4;
  7837. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7838. stopwatch1.Stop();
  7839. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7840. return;
  7841. }
  7842. string[] partSNs = cavityData.Split('.');
  7843. if (partSNs != null && partSNs.Length >= 1)
  7844. partNo = partSNs[0];
  7845. #endregion 查询载具上的产品信息
  7846. partNos.Add(partNo);
  7847. }
  7848. }
  7849. // 统一上传 - 调用MES出站
  7850. stopwatch2.Start();
  7851. List<int> results = new List<int>();
  7852. for (int i = 0; i < partNos.Count; i++)
  7853. {
  7854. string index = (i + 1).ToString(); // 弹夹穴号
  7855. if (string.IsNullOrEmpty(partNos[i]))
  7856. results.Add(1);
  7857. else
  7858. {
  7859. List<TestItem> items1 = new List<TestItem>();
  7860. items1.Add(new TestItem()
  7861. {
  7862. Parameter_name = "弹夹码",
  7863. Parameter_value = sn,
  7864. Parameter_unit = ""
  7865. });
  7866. items1.Add(new TestItem()
  7867. {
  7868. Parameter_name = "弹夹穴号",
  7869. Parameter_value = index,
  7870. Parameter_unit = ""
  7871. });
  7872. items1.Add(new TestItem()
  7873. {
  7874. Parameter_name = "载具码",
  7875. Parameter_value = vehicleCodes[i],
  7876. Parameter_unit = ""
  7877. });
  7878. items1.Add(new TestItem()
  7879. {
  7880. Parameter_name = "载具穴号",
  7881. Parameter_value = "1",
  7882. Parameter_unit = ""
  7883. });
  7884. items1.Add(new TestItem()
  7885. {
  7886. Parameter_name = "产品结果",
  7887. Parameter_value = d3Result == 1 ? "OK" : "NG",
  7888. Parameter_unit = ""
  7889. });
  7890. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  7891. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  7892. results.Add(result1);
  7893. }
  7894. }
  7895. short result = 0;
  7896. if (results.All(a => a == 1))
  7897. result = 1;
  7898. else if (results.Contains(3))
  7899. result = 3;
  7900. else if (results.Contains(2))
  7901. result = 2;
  7902. else if (results.Contains(4))
  7903. result = 4;
  7904. else
  7905. result = 4;
  7906. stopwatch2.Stop();
  7907. // MES_Flag 为4MES报错
  7908. //Funs[plcNo].WriteMultipleRegisters<short>(2463, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  7909. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7910. writeToPLC_Flag.Name = "d3MES_FLAG";
  7911. writeToPLC_Flag.Adress = 2463;
  7912. writeToPLC_Flag.Value = result;
  7913. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7914. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  7915. }
  7916. catch (Exception ex)
  7917. {
  7918. stopwatch2.Restart();
  7919. // MES_Flag 为4上位机报错
  7920. //Funs[plcNo].WriteMultipleRegisters<short>(2463, (short)4); // 4代表上位机报警
  7921. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  7922. writeToPLC_Flag.Name = "d3MES_FLAG";
  7923. writeToPLC_Flag.Adress = 2463;
  7924. writeToPLC_Flag.Value = (short)4;
  7925. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag);
  7926. string str = ex.StackTrace;
  7927. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_3出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  7928. stopwatch2.Stop();
  7929. }
  7930. stopwatch1.Stop();
  7931. AddMessage(LogType.Info, stationNameStr + "_S4_3出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  7932. }
  7933. // 上次采集到的SN
  7934. //private string sn_S4_4进站接口 = string.Empty;
  7935. /// <summary>
  7936. /// [S4] 取放桁架 - S4_4进站接口(提升机2)
  7937. /// </summary>
  7938. private void S4_4进站接口(int plcNo, string stationNameStr)
  7939. {
  7940. Stopwatch stopwatch1 = new Stopwatch();
  7941. Stopwatch stopwatch2 = new Stopwatch();
  7942. try
  7943. {
  7944. stopwatch1.Start();
  7945. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  7946. sn = sn.Replace("\0", "");
  7947. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  7948. #region 查询15个载具码
  7949. List<string> vehicleCodes = new List<string>(); // 15个载具码
  7950. string vehicleData = string.Empty;
  7951. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  7952. if (string.IsNullOrEmpty(vehicleData))
  7953. vehicleData = "";
  7954. if (snResult != 0)
  7955. {
  7956. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7957. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7958. writeToPLC_Flag1.Adress = 2463;
  7959. writeToPLC_Flag1.Value = (short)4;
  7960. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7961. stopwatch1.Stop();
  7962. AddMessage(LogType.Info, stationNameStr + $"_进站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7963. return;
  7964. }
  7965. string[] cavitySNs = vehicleData.Split('.');
  7966. if (cavitySNs != null && cavitySNs.Length > 0)
  7967. {
  7968. for (int i = 0; i < cavitySNs.Length; i++)
  7969. {
  7970. if (string.IsNullOrEmpty(cavitySNs[i]))
  7971. vehicleCodes.Add("");
  7972. else
  7973. vehicleCodes.Add(cavitySNs[i]);
  7974. }
  7975. }
  7976. #endregion 查询15个载具码
  7977. #region 查询15个产品SN
  7978. List<string> portNos = new List<string>(); // 15个产品SN
  7979. foreach (string vehicleCode in vehicleCodes)
  7980. {
  7981. if (string.IsNullOrEmpty(vehicleCode))
  7982. portNos.Add("");
  7983. else
  7984. {
  7985. // 查询
  7986. string cavityData = string.Empty;
  7987. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  7988. if (string.IsNullOrEmpty(cavityData))
  7989. cavityData = "";
  7990. if (snResult1 != 0)
  7991. {
  7992. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  7993. writeToPLC_Flag1.Name = "d3MES_FLAG";
  7994. writeToPLC_Flag1.Adress = 2463;
  7995. writeToPLC_Flag1.Value = (short)4;
  7996. SxPLCWriteData_Add(ref s4PLCWriteData, "d3MES_FLAG", writeToPLC_Flag1);
  7997. stopwatch1.Stop();
  7998. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  7999. return;
  8000. }
  8001. string[] partSNs = cavityData.Split('.');
  8002. if (partSNs != null && partSNs.Length >= 1)
  8003. portNos.Add(partSNs[0]);
  8004. else
  8005. portNos.Add("");
  8006. }
  8007. }
  8008. #endregion 查询15个产品SN
  8009. // 调用MES进站(最多15个)
  8010. stopwatch2.Start();
  8011. List<int> results = new int[15].ToList(); // 结果集;0代表产品为空
  8012. for (int i = 0; i < vehicleCodes.Count; i++)
  8013. {
  8014. // 循环进站
  8015. if (!string.IsNullOrEmpty(vehicleCodes[i]))
  8016. {
  8017. // 产品SN(物料码)校验
  8018. string portNo = portNos[i];
  8019. List<TestItem> item = new List<TestItem>();
  8020. item.Add(new TestItem()
  8021. {
  8022. Parameter_name = "弹夹码",
  8023. Parameter_value = sn,
  8024. });
  8025. item.Add(new TestItem()
  8026. {
  8027. Parameter_name = "弹夹穴位",
  8028. Parameter_value = (i + 1).ToString(),
  8029. });
  8030. item.Add(new TestItem()
  8031. {
  8032. Parameter_name = "载具码",
  8033. Parameter_value = vehicleCodes[i],
  8034. });
  8035. item.Add(new TestItem()
  8036. {
  8037. Parameter_name = "载具穴号",
  8038. Parameter_value = "1",
  8039. });
  8040. results[i] = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, portNo, item, out string errorMsg);
  8041. }
  8042. }
  8043. stopwatch2.Stop();
  8044. short result = 0;
  8045. bool haveMesWarn = results.Contains(5);
  8046. bool havePCWarn = results.Contains(6);
  8047. if (haveMesWarn)
  8048. result = 2; // 5->2
  8049. else if (havePCWarn)
  8050. result = 6; // 6->4
  8051. else
  8052. result = 1;
  8053. // MES_Flag 为4MES报错
  8054. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8055. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8056. writeToPLC_Flag.Name = "d4MES_FLAG";
  8057. writeToPLC_Flag.Adress = 2496;
  8058. writeToPLC_Flag.Value = result;
  8059. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8060. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8061. }
  8062. catch (Exception ex)
  8063. {
  8064. stopwatch2.Stop();
  8065. // MES_Flag 为4上位机报错
  8066. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8067. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8068. writeToPLC_Flag.Name = "d4MES_FLAG";
  8069. writeToPLC_Flag.Adress = 2496;
  8070. writeToPLC_Flag.Value = (short)4;
  8071. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8072. string str = ex.StackTrace;
  8073. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4进站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8074. }
  8075. stopwatch1.Stop();
  8076. AddMessage(LogType.Info, stationNameStr + "_S4_4进站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8077. }
  8078. // 上次采集到的SN
  8079. //private string sn_S4_4出站接口 = string.Empty;
  8080. /// <summary>
  8081. /// [S4] 取放桁架 - S4_4出站接口(提升机2)
  8082. /// </summary>
  8083. private void S4_4出站接口(int plcNo, string stationCode, string stationName)
  8084. {
  8085. Stopwatch stopwatch1 = new Stopwatch();
  8086. Stopwatch stopwatch2 = new Stopwatch();
  8087. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8088. string stationNameStr = stationCode + stationName;
  8089. string processItem = stationName; // 测试项目
  8090. try
  8091. {
  8092. stopwatch1.Start();
  8093. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8094. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8095. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8096. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8097. string sn = (string)s4PLCData["d4ProductSN"]; // 产品SN(弹夹码)
  8098. sn = sn.Replace("\0", "");
  8099. int d4Result = (int)s4PLCData["d4Result"]; // 产品结果
  8100. bool isPass = d4Result == 1; // 产品结果 bool
  8101. #region 查询15个载具码
  8102. List<string> vehicleCodes = new List<string>(); // 15个载具码
  8103. string vehicleData = string.Empty;
  8104. int snResult1 = XiaomiMES_RouteCommunication.SNQueryData(sn, ref vehicleData);
  8105. if (string.IsNullOrEmpty(vehicleData))
  8106. vehicleData = "";
  8107. if (snResult1 != 0)
  8108. {
  8109. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8110. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8111. writeToPLC_Flag1.Adress = 2496;
  8112. writeToPLC_Flag1.Value = (short)4;
  8113. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8114. stopwatch1.Stop();
  8115. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult1};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8116. return;
  8117. }
  8118. string[] cavitySNs = vehicleData.Split('.');
  8119. if (cavitySNs != null && cavitySNs.Length > 0)
  8120. {
  8121. for (int i = 0; i < cavitySNs.Length; i++)
  8122. {
  8123. if (string.IsNullOrEmpty(cavitySNs[i]))
  8124. vehicleCodes.Add("");
  8125. else
  8126. vehicleCodes.Add(cavitySNs[i]);
  8127. }
  8128. }
  8129. #endregion 查询15个载具码
  8130. // 统一查 产品SN列表
  8131. List<string> partNos = new List<string>();
  8132. foreach (string vehicleCode in vehicleCodes)
  8133. {
  8134. if (string.IsNullOrEmpty(vehicleCode))
  8135. partNos.Add("");
  8136. else
  8137. {
  8138. string partNo = "";
  8139. #region 查询载具上的产品信息
  8140. string cavityData = string.Empty;
  8141. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8142. if (string.IsNullOrEmpty(cavityData))
  8143. cavityData = "";
  8144. if (snResult != 0)
  8145. {
  8146. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8147. writeToPLC_Flag1.Name = "d4MES_FLAG";
  8148. writeToPLC_Flag1.Adress = 2496;
  8149. writeToPLC_Flag1.Value = (short)4;
  8150. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag1);
  8151. stopwatch1.Stop();
  8152. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8153. return;
  8154. }
  8155. string[] partSNs = cavityData.Split('.');
  8156. if (partSNs != null && partSNs.Length >= 1)
  8157. partNo = partSNs[0];
  8158. #endregion 查询载具上的产品信息
  8159. partNos.Add(partNo);
  8160. }
  8161. }
  8162. // 调用MES出站
  8163. stopwatch2.Start();
  8164. // 统一上传
  8165. List<int> results = new List<int>();
  8166. for (int i = 0; i < partNos.Count; i++)
  8167. {
  8168. string index = (i + 1).ToString(); // 弹夹穴号
  8169. if (string.IsNullOrEmpty(partNos[i]))
  8170. results.Add(1);
  8171. else
  8172. {
  8173. List<TestItem> items1 = new List<TestItem>();
  8174. items1.Add(new TestItem()
  8175. {
  8176. Parameter_name = "弹夹码",
  8177. Parameter_value = sn,
  8178. Parameter_unit = ""
  8179. });
  8180. items1.Add(new TestItem()
  8181. {
  8182. Parameter_name = "弹夹穴号",
  8183. Parameter_value = index,
  8184. Parameter_unit = ""
  8185. });
  8186. items1.Add(new TestItem()
  8187. {
  8188. Parameter_name = "载具码",
  8189. Parameter_value = vehicleCodes[i],
  8190. Parameter_unit = ""
  8191. });
  8192. items1.Add(new TestItem()
  8193. {
  8194. Parameter_name = "载具穴号",
  8195. Parameter_value = "1",
  8196. Parameter_unit = ""
  8197. });
  8198. items1.Add(new TestItem()
  8199. {
  8200. Parameter_name = "产品结果",
  8201. Parameter_value = d4Result == 1 ? "OK" : "NG",
  8202. Parameter_unit = ""
  8203. });
  8204. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8205. , workorder_code, mtltmrk, partNos[i], isPass, sn, index);
  8206. results.Add(result1);
  8207. }
  8208. }
  8209. short result = 0;
  8210. if (results.All(a => a == 1))
  8211. result = 1;
  8212. else if (results.Contains(3))
  8213. result = 3;
  8214. else if (results.Contains(2))
  8215. result = 2;
  8216. else if (results.Contains(4))
  8217. result = 4;
  8218. else
  8219. result = 4;
  8220. stopwatch2.Stop();
  8221. // MES_Flag 为4MES报错
  8222. //Funs[plcNo].WriteMultipleRegisters<short>(2496, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8223. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8224. writeToPLC_Flag.Name = "d4MES_FLAG";
  8225. writeToPLC_Flag.Adress = 2496;
  8226. writeToPLC_Flag.Value = result;
  8227. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8228. OnMessage(LogType.Debug, $"PLC{plcNo}_{stationNameStr}-Write" + (result == 1 ? "成功!" : "失败!"));
  8229. }
  8230. catch (Exception ex)
  8231. {
  8232. stopwatch2.Restart();
  8233. // MES_Flag 为4上位机报错
  8234. //Funs[plcNo].WriteMultipleRegisters<short>(2496, (short)4); // 4代表上位机报警
  8235. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8236. writeToPLC_Flag.Name = "d4MES_FLAG";
  8237. writeToPLC_Flag.Adress = 2496;
  8238. writeToPLC_Flag.Value = (short)4;
  8239. SxPLCWriteData_Add(ref s4PLCWriteData, "d4MES_FLAG", writeToPLC_Flag);
  8240. string str = ex.StackTrace;
  8241. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}S4_4出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8242. stopwatch2.Stop();
  8243. }
  8244. stopwatch1.Stop();
  8245. AddMessage(LogType.Info, stationNameStr + "_S4_4出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8246. }
  8247. /// <summary>
  8248. /// [S4] 取放桁架 - S4_5弹夹扫码
  8249. /// </summary>
  8250. /// <param name="plcNo">PLC编号</param>
  8251. /// <param name="stationNameStr">工站全称</param>
  8252. private void S4_5弹夹扫码(int plcNo, string stationNameStr)
  8253. {
  8254. Stopwatch stopwatch1 = new Stopwatch();
  8255. Stopwatch stopwatch2 = new Stopwatch();
  8256. try
  8257. {
  8258. stopwatch1.Start();
  8259. // ZS 弹夹扫码
  8260. string d5BulletclipCode = " "; // 扫到的码
  8261. short d5BulletclipScanCode = 2;
  8262. stopwatch2.Start();
  8263. //Funs[plcNo].WriteMultipleRegisters<string>(2529, d5BulletclipCode, 20);
  8264. //// MES_Flag
  8265. //Funs[plcNo].WriteMultipleRegisters<short>(2528, d5BulletclipScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8266. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8267. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8268. writeToPLC_Flag.Adress = 2528;
  8269. writeToPLC_Flag.Value = d5BulletclipScanCode;
  8270. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8271. {
  8272. Name = "d5BulletclipCode",
  8273. Adress = 2529,
  8274. ValueType = PLCValueType.String,
  8275. ValueTypeStrLength = 20,
  8276. Value = d5BulletclipCode
  8277. });
  8278. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8279. stopwatch2.Stop();
  8280. }
  8281. catch (Exception ex)
  8282. {
  8283. string str = ex.StackTrace;
  8284. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8285. stopwatch2.Start();
  8286. //Funs[plcNo].WriteMultipleRegisters<string>(2529, " ", 20);
  8287. //// MES_Flag
  8288. //Funs[plcNo].WriteMultipleRegisters<short>(2528, (short)6); // 6代表上位机报警
  8289. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8290. writeToPLC_Flag.Name = "d5BulletclipScanCode";
  8291. writeToPLC_Flag.Adress = 2528;
  8292. writeToPLC_Flag.Value = (short)6;
  8293. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8294. {
  8295. Name = "d5BulletclipCode",
  8296. Adress = 2529,
  8297. ValueType = PLCValueType.String,
  8298. ValueTypeStrLength = 20,
  8299. Value = " "
  8300. });
  8301. SxPLCWriteData_Add(ref s4PLCWriteData, "d5BulletclipScanCode", writeToPLC_Flag);
  8302. stopwatch2.Stop();
  8303. }
  8304. stopwatch1.Stop();
  8305. AddMessage(LogType.Info, stationNameStr + "_弹夹扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8306. }
  8307. /// <summary>
  8308. /// [S4] 取放桁架 - S4_5载具扫码
  8309. /// </summary>
  8310. /// <param name="plcNo">PLC编号</param>
  8311. /// <param name="stationNameStr">工站全称</param>
  8312. private void S4_5载具扫码(int plcNo, string stationNameStr)
  8313. {
  8314. Stopwatch stopwatch1 = new Stopwatch();
  8315. Stopwatch stopwatch2 = new Stopwatch();
  8316. try
  8317. {
  8318. stopwatch1.Start();
  8319. // ZS 载具扫码
  8320. string d5VehicleCode = " "; // 扫到的码
  8321. short d5VehicleScanCode = 2;
  8322. #region 进站
  8323. if (d5VehicleScanCode == 2 && !string.IsNullOrEmpty(d5VehicleCode))
  8324. {
  8325. // 查产品SN
  8326. #region 查询载具上的产品信息
  8327. string cavityData = string.Empty;
  8328. int snResult = XiaomiMES_RouteCommunication.SNQueryData(d5VehicleCode, ref cavityData);
  8329. if (string.IsNullOrEmpty(cavityData))
  8330. cavityData = "";
  8331. if (snResult != 0)
  8332. {
  8333. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8334. writeToPLC_Flag1.Name = "d5VehicleScanCode";
  8335. writeToPLC_Flag1.Adress = 2559;
  8336. writeToPLC_Flag1.Value = (short)6;
  8337. writeToPLC_Flag1.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8338. {
  8339. Name = "d5VehicleCode",
  8340. Adress = 2560,
  8341. ValueType = PLCValueType.String,
  8342. ValueTypeStrLength = 20,
  8343. Value = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  8344. });
  8345. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag1);
  8346. stopwatch1.Stop();
  8347. AddMessage(LogType.Info, stationNameStr + $"_载具扫码失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8348. return;
  8349. }
  8350. string[] cavitySNs = cavityData.Split('.');
  8351. string partNo = "";
  8352. if (cavitySNs != null && cavitySNs.Length >= 1)
  8353. {
  8354. partNo = cavitySNs[0];
  8355. }
  8356. #endregion 查询载具上的产品信息
  8357. List<TestItem> item = new List<TestItem>();
  8358. item.Add(new TestItem()
  8359. {
  8360. Parameter_name = "载具码",
  8361. Parameter_value = d5VehicleCode,
  8362. });
  8363. item.Add(new TestItem()
  8364. {
  8365. Parameter_name = "载具穴号",
  8366. Parameter_value = "1",
  8367. });
  8368. stopwatch2.Start();
  8369. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  8370. stopwatch2.Stop();
  8371. d5VehicleScanCode = (short)result == 1 ? d5VehicleScanCode : (short)result;
  8372. }
  8373. #endregion 进站
  8374. //Funs[plcNo].WriteMultipleRegisters<string>(2560, d5VehicleCode, 20);
  8375. //// MES_Flag
  8376. //Funs[plcNo].WriteMultipleRegisters<short>(2559, d5VehicleScanCode); // plc发送1代表请求扫码,上位机发送2代表扫码OK,3代表扫码NG,6代表上位机报警;7s未给结果代表扫码超时(扫不到码);请求前200ms确保 扫码信号 为0;
  8377. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8378. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8379. writeToPLC_Flag.Adress = 2559;
  8380. writeToPLC_Flag.Value = d5VehicleScanCode;
  8381. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8382. {
  8383. Name = "d5VehicleCode",
  8384. Adress = 2560,
  8385. ValueType = PLCValueType.String,
  8386. ValueTypeStrLength = 20,
  8387. Value = d5VehicleCode
  8388. });
  8389. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8390. }
  8391. catch (Exception ex)
  8392. {
  8393. string str = ex.StackTrace;
  8394. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8395. stopwatch2.Start();
  8396. //Funs[plcNo].WriteMultipleRegisters<string>(2560, " ", 20);
  8397. //// MES_Flag
  8398. //Funs[plcNo].WriteMultipleRegisters<short>(2559, (short)6); // 6代表上位机报警
  8399. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8400. writeToPLC_Flag.Name = "d5VehicleScanCode";
  8401. writeToPLC_Flag.Adress = 2559;
  8402. writeToPLC_Flag.Value = (short)6;
  8403. writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
  8404. {
  8405. Name = "d5VehicleCode",
  8406. Adress = 2560,
  8407. ValueType = PLCValueType.String,
  8408. ValueTypeStrLength = 20,
  8409. Value = " "
  8410. });
  8411. SxPLCWriteData_Add(ref s4PLCWriteData, "d5VehicleScanCode", writeToPLC_Flag);
  8412. stopwatch2.Stop();
  8413. }
  8414. stopwatch1.Stop();
  8415. AddMessage(LogType.Info, stationNameStr + "_载具扫码;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8416. }
  8417. // 上次采集到的SN
  8418. //private string sn_S4_5出站接口 = string.Empty;
  8419. /// <summary>
  8420. /// [S4] 取放桁架 - S4_5出站接口
  8421. /// </summary>
  8422. private void S4_5出站接口(int plcNo, string stationCode, string stationName)
  8423. {
  8424. Stopwatch stopwatch1 = new Stopwatch();
  8425. Stopwatch stopwatch2 = new Stopwatch();
  8426. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  8427. string stationNameStr = stationCode + stationName;
  8428. string processItem = stationName; // 测试项目
  8429. try
  8430. {
  8431. stopwatch1.Start();
  8432. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  8433. //string batch_num = GlobalContext.BatchNumber; // 批次号
  8434. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  8435. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  8436. string sn = (string)s4PLCData["d5ProductSN"]; // 产品SN(弹夹码)
  8437. sn = sn.Replace("\0", "");
  8438. string d5VehicleCode1 = (string)s4PLCData["d5VehicleCode1"]; // 载具1码(弹夹穴位1)
  8439. d5VehicleCode1 = d5VehicleCode1.Replace("\0", "");
  8440. string d5VehicleCode2 = (string)s4PLCData["d5VehicleCode2"]; // 载具2码(弹夹穴位2)
  8441. d5VehicleCode2 = d5VehicleCode2.Replace("\0", "");
  8442. string d5VehicleCode3 = (string)s4PLCData["d5VehicleCode3"]; // 载具3码(弹夹穴位3)
  8443. d5VehicleCode3 = d5VehicleCode3.Replace("\0", "");
  8444. string d5VehicleCode4 = (string)s4PLCData["d5VehicleCode4"]; // 载具4码(弹夹穴位4)
  8445. d5VehicleCode4 = d5VehicleCode4.Replace("\0", "");
  8446. string d5VehicleCode5 = (string)s4PLCData["d5VehicleCode5"]; // 载具5码(弹夹穴位5)
  8447. d5VehicleCode5 = d5VehicleCode5.Replace("\0", "");
  8448. string d5VehicleCode6 = (string)s4PLCData["d5VehicleCode6"]; // 载具6码(弹夹穴位6)
  8449. d5VehicleCode6 = d5VehicleCode6.Replace("\0", "");
  8450. string d5VehicleCode7 = (string)s4PLCData["d5VehicleCode7"]; // 载具7码(弹夹穴位7)
  8451. d5VehicleCode7 = d5VehicleCode7.Replace("\0", "");
  8452. string d5VehicleCode8 = (string)s4PLCData["d5VehicleCode8"]; // 载具8码(弹夹穴位8)
  8453. d5VehicleCode8 = d5VehicleCode8.Replace("\0", "");
  8454. string d5VehicleCode9 = (string)s4PLCData["d5VehicleCode9"]; // 载具9码(弹夹穴位9)
  8455. d5VehicleCode9 = d5VehicleCode9.Replace("\0", "");
  8456. string d5VehicleCode10 = (string)s4PLCData["d5VehicleCode10"]; // 载具10码(弹夹穴位10)
  8457. d5VehicleCode10 = d5VehicleCode10.Replace("\0", "");
  8458. string d5VehicleCode11 = (string)s4PLCData["d5VehicleCode11"]; // 载具11码(弹夹穴位11)
  8459. d5VehicleCode11 = d5VehicleCode11.Replace("\0", "");
  8460. string d5VehicleCode12 = (string)s4PLCData["d5VehicleCode12"]; // 载具12码(弹夹穴位12)
  8461. d5VehicleCode12 = d5VehicleCode12.Replace("\0", "");
  8462. string d5VehicleCode13 = (string)s4PLCData["d5VehicleCode13"]; // 载具13码(弹夹穴位13)
  8463. d5VehicleCode13 = d5VehicleCode13.Replace("\0", "");
  8464. string d5VehicleCode14 = (string)s4PLCData["d5VehicleCode14"]; // 载具14码(弹夹穴位14)
  8465. d5VehicleCode14 = d5VehicleCode14.Replace("\0", "");
  8466. string d5VehicleCode15 = (string)s4PLCData["d5VehicleCode15"]; // 载具15码(弹夹穴位15)
  8467. d5VehicleCode15 = d5VehicleCode15.Replace("\0", "");
  8468. int d5Result = (int)s4PLCData["d5Result"]; // 产品结果
  8469. bool pass = d5Result == 1;
  8470. // 存 载具SN列表
  8471. List<string> vehicleCodes = new List<string>()
  8472. {
  8473. d5VehicleCode1,d5VehicleCode2,d5VehicleCode3,d5VehicleCode4,d5VehicleCode5,
  8474. d5VehicleCode6,d5VehicleCode7,d5VehicleCode8,d5VehicleCode9,d5VehicleCode10,
  8475. d5VehicleCode11,d5VehicleCode12,d5VehicleCode13,d5VehicleCode14,d5VehicleCode15
  8476. };
  8477. // 统一查 产品SN列表
  8478. List<string> partNos = new List<string>();
  8479. foreach (string vehicleCode in vehicleCodes)
  8480. {
  8481. if (string.IsNullOrEmpty(vehicleCode))
  8482. partNos.Add("");
  8483. else
  8484. {
  8485. string partNo = "";
  8486. #region 查询载具上的产品信息
  8487. string cavityData = string.Empty;
  8488. int snResult = XiaomiMES_RouteCommunication.SNQueryData(vehicleCode, ref cavityData);
  8489. if (string.IsNullOrEmpty(cavityData))
  8490. cavityData = "";
  8491. if (snResult != 0)
  8492. {
  8493. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8494. writeToPLC_Flag1.Name = "d5MES_FLAG";
  8495. writeToPLC_Flag1.Adress = 2591;
  8496. writeToPLC_Flag1.Value = (short)4;
  8497. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag1);
  8498. stopwatch1.Stop();
  8499. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8500. return;
  8501. }
  8502. string[] cavitySNs = cavityData.Split('.');
  8503. if (cavitySNs != null && cavitySNs.Length >= 1)
  8504. partNo = cavitySNs[0];
  8505. #endregion 查询载具上的产品信息
  8506. partNos.Add(partNo);
  8507. }
  8508. }
  8509. // 统一上传
  8510. stopwatch2.Start();
  8511. List<int> results = new List<int>();
  8512. for (int i = 0; i < partNos.Count; i++)
  8513. {
  8514. string index = (i + 1).ToString(); // 弹夹穴号
  8515. if (string.IsNullOrEmpty(partNos[i]))
  8516. results.Add(1);
  8517. else
  8518. {
  8519. List<TestItem> items1 = new List<TestItem>();
  8520. items1.Add(new TestItem()
  8521. {
  8522. Parameter_name = "弹夹码",
  8523. Parameter_value = sn,
  8524. Parameter_unit = ""
  8525. });
  8526. items1.Add(new TestItem()
  8527. {
  8528. Parameter_name = "弹夹穴号",
  8529. Parameter_value = index,
  8530. Parameter_unit = ""
  8531. });
  8532. items1.Add(new TestItem()
  8533. {
  8534. Parameter_name = "载具码",
  8535. Parameter_value = vehicleCodes[i],
  8536. Parameter_unit = ""
  8537. });
  8538. items1.Add(new TestItem()
  8539. {
  8540. Parameter_name = "载具穴号",
  8541. Parameter_value = "1",
  8542. Parameter_unit = ""
  8543. });
  8544. items1.Add(new TestItem()
  8545. {
  8546. Parameter_name = "产品结果",
  8547. Parameter_value = d5Result == 1 ? "OK" : "NG",
  8548. Parameter_unit = ""
  8549. });
  8550. int result1 = SwitctProcessData(stationNameStr, items1, equipmentCode, processItem
  8551. , workorder_code, mtltmrk, partNos[i], pass, sn, index);
  8552. results.Add(result1);
  8553. }
  8554. }
  8555. short result = 0;
  8556. if (results.All(a => a == 1))
  8557. result = 1;
  8558. else if (results.Contains(3))
  8559. result = 3;
  8560. else if (results.Contains(2))
  8561. result = 2;
  8562. else if (results.Contains(4))
  8563. result = 4;
  8564. else
  8565. result = 4;
  8566. stopwatch2.Stop();
  8567. #region 存储绑定数据到 边线MES系统中
  8568. if (result == 1)
  8569. {
  8570. // 删除绑定信息
  8571. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  8572. if (resultMesR != 0)
  8573. {
  8574. result = 4;
  8575. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  8576. }
  8577. }
  8578. #endregion 存储绑定数据到 边线MES系统中
  8579. // MES_Flag 为4MES报错
  8580. //Funs[plcNo].WriteMultipleRegisters<short>(2591, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8581. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8582. writeToPLC_Flag.Name = "d5MES_FLAG";
  8583. writeToPLC_Flag.Adress = 2591;
  8584. writeToPLC_Flag.Value = result;
  8585. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8586. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  8587. }
  8588. catch (Exception ex)
  8589. {
  8590. stopwatch2.Restart();
  8591. // MES_Flag 为4上位机报错
  8592. //Funs[plcNo].WriteMultipleRegisters<short>(2591, (short)4); // 4代表上位机报警
  8593. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8594. writeToPLC_Flag.Name = "d5MES_FLAG";
  8595. writeToPLC_Flag.Adress = 2591;
  8596. writeToPLC_Flag.Value = (short)4;
  8597. SxPLCWriteData_Add(ref s4PLCWriteData, "d5MES_FLAG", writeToPLC_Flag);
  8598. stopwatch2.Stop();
  8599. string str = ex.StackTrace;
  8600. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8601. }
  8602. stopwatch1.Stop();
  8603. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8604. }
  8605. /// <summary>
  8606. /// [S4] 取放桁架 - S4_5节拍接口
  8607. /// </summary>
  8608. /// <param name="plcNo">PLC编号</param>
  8609. /// <param name="stationNameStr">工站全称</param>
  8610. private void S4_5节拍接口(int plcNo, string stationNameStr)
  8611. {
  8612. Stopwatch stopwatch1 = new Stopwatch();
  8613. Stopwatch stopwatch2 = new Stopwatch();
  8614. string resultStr = string.Empty;
  8615. try
  8616. {
  8617. stopwatch1.Start();
  8618. string oEEType = ((int)s4PLCData["d5OEEType"]).ToString(); // 节拍类型(plc写入)
  8619. string d5OEEProductSN = (string)s4PLCData["d5OEEProductSN"]; // 载具SN
  8620. d5OEEProductSN = d5OEEProductSN.Replace("\0", "");
  8621. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  8622. if (!actionBool)
  8623. {
  8624. stopwatch2.Start();
  8625. // MES_Flag
  8626. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 上位机;发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警
  8627. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8628. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8629. writeToPLC_Flag1.Adress = 2924;
  8630. writeToPLC_Flag1.Value = (short)4;
  8631. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8632. stopwatch2.Stop();
  8633. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8634. return;
  8635. }
  8636. string d5OEEPartNo = string.Empty; // 物料码
  8637. if (string.IsNullOrEmpty(d5OEEProductSN))
  8638. {
  8639. stopwatch2.Start();
  8640. // MES_Flag
  8641. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8642. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8643. writeToPLC_Flag1.Name = "d5OEEMES_FLAG";
  8644. writeToPLC_Flag1.Adress = 2924;
  8645. writeToPLC_Flag1.Value = (short)1;
  8646. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag1);
  8647. stopwatch2.Stop();
  8648. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8649. return;
  8650. }
  8651. else
  8652. { // 查产品SN
  8653. d5OEEPartNo = "Test"; // ZS
  8654. }
  8655. short d5OEEMES_FLAG = 0;
  8656. // 上传OEE
  8657. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, d5OEEPartNo, d5OEEProductSN);
  8658. d5OEEMES_FLAG = result.Item1;
  8659. resultStr = result.Item2;
  8660. stopwatch2.Start();
  8661. // MES_Flag
  8662. //Funs[plcNo].WriteMultipleRegisters<short>(2924, d5OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  8663. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8664. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8665. writeToPLC_Flag.Adress = 2924;
  8666. writeToPLC_Flag.Value = d5OEEMES_FLAG;
  8667. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8668. stopwatch2.Stop();
  8669. }
  8670. catch (Exception ex)
  8671. {
  8672. string str = ex.StackTrace;
  8673. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8674. // MES_Flag
  8675. stopwatch2.Start();
  8676. //Funs[plcNo].WriteMultipleRegisters<short>(2924, (short)4); // 4代表上位机报警
  8677. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  8678. writeToPLC_Flag.Name = "d5OEEMES_FLAG";
  8679. writeToPLC_Flag.Adress = 2924;
  8680. writeToPLC_Flag.Value = (short)4;
  8681. SxPLCWriteData_Add(ref s4PLCWriteData, "d5OEEMES_FLAG", writeToPLC_Flag);
  8682. stopwatch2.Stop();
  8683. }
  8684. stopwatch1.Stop();
  8685. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  8686. }
  8687. #endregion [S4] 取放桁架
  8688. #endregion PLC4 刘果段
  8689. #region PLC5 张超凡
  8690. #region [S5] Tray盘下料装备
  8691. /// <summary>
  8692. /// S5工位的数据- 触发信号上次的值
  8693. /// </summary>
  8694. private Dictionary<string, object> s5PLCSignal_Old = new Dictionary<string, object>();
  8695. /// <summary>
  8696. /// S5工位的数据(含触发信号)
  8697. /// </summary>
  8698. private Dictionary<string, object> s5PLCData = new Dictionary<string, object>();
  8699. /// <summary>
  8700. /// S5工位的数据- 回写点位
  8701. /// </summary>
  8702. private Dictionary<string, WriteToPLC_Flag> s5PLCWriteData = new Dictionary<string, WriteToPLC_Flag>();
  8703. /// <summary>
  8704. /// [S5] Tray盘下料装备
  8705. /// </summary>
  8706. /// <param name="plcNo">PLC编号</param>
  8707. //private void ReadStation_S5(int plcNo)
  8708. //{
  8709. // // [S1] Tray盘上料装备
  8710. // // [S2] FCT
  8711. // // [S3] 值板机
  8712. // // [S4_1] 载具下线装备 [S4_5] 载具上线装备
  8713. // // [S5] Tray盘下料装备
  8714. // /// 上位机心跳
  8715. // /// 获取设备报警数据与状态信息
  8716. // string stationCode = "[S5]";
  8717. // string stationName = "Tray盘下料装备";
  8718. // string stationNameStr = stationCode + stationName;
  8719. // #region 创建字典
  8720. // // 触发信号字典 赋值
  8721. // s5PLCSignal_Old.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8722. // s5PLCSignal_Old.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8723. // s5PLCSignal_Old.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8724. // s5PLCSignal_Old.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8725. // s5PLCSignal_Old.Add("e1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
  8726. // s5PLCSignal_Old.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8727. // s5PLCSignal_Old.Add("e1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
  8728. // // PLC数据字典 赋值
  8729. // s5PLCData.Add("e1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
  8730. // s5PLCData.Add("e1MES_FLAG_Check", 0); // MES_FLAG
  8731. // s5PLCData.Add("e1ProductSN_Check", ""); //
  8732. // s5PLCData.Add("e1PLC_FLAG", 0); // PLC_FLAG 出站接口
  8733. // s5PLCData.Add("e1MES_FLAG", 0); // MES_FLAG
  8734. // s5PLCData.Add("e1ProductSN", ""); // 产品SN
  8735. // s5PLCData.Add("e1PartNo", ""); // 物料码
  8736. // s5PLCData.Add("e1Result", 0); // 产品结果
  8737. // s5PLCData.Add("e1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
  8738. // s5PLCData.Add("e1OEEMES_FLAG", 0); // MES_FLAG
  8739. // s5PLCData.Add("e1OEEProductSN", "");// 产品SN(载具SN)
  8740. // s5PLCData.Add("e1OEEType", 0); // 节拍类型(plc写入)
  8741. // s5PLCData.Add("e1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
  8742. // s5PLCData.Add("e1AGVUpStart", 0); // AGV上料开始信号
  8743. // s5PLCData.Add("e1AGVUpEnd", 0); // AGV上料完成信号
  8744. // s5PLCData.Add("e1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
  8745. // s5PLCData.Add("e1AGVDownStart", 0); // AGV下料开始信号
  8746. // s5PLCData.Add("e1AGVDownEnd", 0); // AGV下料完成信号
  8747. // #endregion 创建字典
  8748. // while (IsRun)
  8749. // {
  8750. // try
  8751. // {
  8752. // if (!GlobalContext._IsCon_Funs5)
  8753. // {
  8754. // UpdatePLCMonitor(1, plcNo, 0);
  8755. // continue;
  8756. // }
  8757. // if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
  8758. // {
  8759. // Stopwatch stopwatch1 = new Stopwatch();
  8760. // Stopwatch stopwatch2 = new Stopwatch();
  8761. // stopwatch1.Start();
  8762. // stopwatch2.Start();
  8763. // #region 一次性读取所有数据
  8764. // int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
  8765. // int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 46);
  8766. // int[] datas = data1.Concat(data2).ToArray();
  8767. // s5PLCData["e1PLC_FLAG_Check"] = datas[2]; // 进站校验
  8768. // s5PLCData["e1MES_FLAG_Check"] = datas[3];
  8769. // int[] e1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
  8770. // s5PLCData["e1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(e1ProductSN_CheckData, 0, 40);
  8771. // s5PLCData["e1PLC_FLAG"] = datas[34]; // 出站接口
  8772. // s5PLCData["e1MES_FLAG"] = datas[35];
  8773. // int[] e1ProductSNData = datas.Skip(36).Take(20).ToArray();
  8774. // s5PLCData["e1ProductSN"] = ModbusClient.ConvertRegistersToString(e1ProductSNData, 0, 40);
  8775. // int[] e1PartNoData = datas.Skip(56).Take(20).ToArray();
  8776. // s5PLCData["e1PartNo"] = ModbusClient.ConvertRegistersToString(e1PartNoData, 0, 40);
  8777. // s5PLCData["e1Result"] = datas[76];
  8778. // s5PLCData["e1OEEPLC_FLAG"] = datas[87]; // 节拍接口
  8779. // s5PLCData["e1OEEMES_FLAG"] = datas[88];
  8780. // int[] e1OEEProductSNData = datas.Skip(89).Take(20).ToArray();
  8781. // s5PLCData["e1OEEProductSN"] = ModbusClient.ConvertRegistersToString(e1OEEProductSNData, 0, 40);
  8782. // s5PLCData["e1OEEType"] = datas[109];
  8783. // s5PLCData["e1AGVUpCall"] = datas[120]; // AGV上料
  8784. // s5PLCData["e1AGVUpStart"] = datas[121];
  8785. // s5PLCData["e1AGVUpEnd"] = datas[122];
  8786. // s5PLCData["e1AGVDownCall"] = datas[133]; // AGV下料
  8787. // s5PLCData["e1AGVDownStart"] = datas[134];
  8788. // s5PLCData["e1AGVDownEnd"] = datas[135];
  8789. // #endregion 一次性读取所有数据
  8790. // stopwatch2.Stop();
  8791. // #region 回写操作,写后清空flag
  8792. // PLCWriteData(Funs[plcNo], ref s5PLCData, ref s5PLCWriteData);
  8793. // #endregion 回写操作,写后清空flag
  8794. // #region 进站校验
  8795. // try
  8796. // {
  8797. // int e1PLC_FLAG_Check = (int)s5PLCData["e1PLC_FLAG_Check"];
  8798. // int e1MES_FLAG_Check = (int)s5PLCData["e1MES_FLAG_Check"];
  8799. // int e1PLC_FLAG_CheckOld = (int)s5PLCSignal_Old["e1PLC_FLAG_Check"];
  8800. // if (e1PLC_FLAG_Check != e1PLC_FLAG_CheckOld)
  8801. // {
  8802. // if (e1PLC_FLAG_Check == 1 && e1MES_FLAG_Check == 0) // 0->1
  8803. // Task.Run(() => S5进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
  8804. // else if (e1PLC_FLAG_Check == 0 && e1MES_FLAG_Check != 0)
  8805. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)0);
  8806. // s5PLCSignal_Old["e1PLC_FLAG_Check"] = s5PLCData["e1PLC_FLAG_Check"];
  8807. // }
  8808. // }
  8809. // catch (Exception ex)
  8810. // {
  8811. // Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  8812. // string str = ex.StackTrace;
  8813. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8814. // }
  8815. // #endregion 进站校验
  8816. // #region 出站接口
  8817. // try
  8818. // {
  8819. // int e1PLC_FLAG = (int)s5PLCData["e1PLC_FLAG"];
  8820. // int e1MES_FLAG = (int)s5PLCData["e1MES_FLAG"];
  8821. // int e1PLC_FLAGOld = (int)s5PLCSignal_Old["e1PLC_FLAG"];
  8822. // if (e1PLC_FLAG != e1PLC_FLAGOld)
  8823. // {
  8824. // if (e1PLC_FLAG == 1 && e1MES_FLAG == 0) // 0->1
  8825. // Task.Run(() => S5出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
  8826. // else if (e1PLC_FLAG == 0 && e1MES_FLAG != 0)
  8827. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)0);
  8828. // s5PLCSignal_Old["e1PLC_FLAG"] = s5PLCData["e1PLC_FLAG"];
  8829. // }
  8830. // }
  8831. // catch (Exception ex)
  8832. // {
  8833. // Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)6); // 6代表上位机报警
  8834. // string str = ex.StackTrace;
  8835. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8836. // }
  8837. // #endregion 出站接口
  8838. // #region 节拍接口
  8839. // try
  8840. // {
  8841. // int e1OEEPLC_FLAG = (int)s5PLCData["e1OEEPLC_FLAG"];
  8842. // int e1OEEMES_FLAG = (int)s5PLCData["e1OEEMES_FLAG"];
  8843. // int e1OEEPLC_FLAGOld = (int)s5PLCSignal_Old["e1OEEPLC_FLAG"];
  8844. // if (e1OEEPLC_FLAG != e1OEEPLC_FLAGOld)
  8845. // {
  8846. // if (e1OEEPLC_FLAG == 1 && e1OEEMES_FLAG == 0) // 0->1
  8847. // Task.Run(() => S5节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
  8848. // else if (e1OEEPLC_FLAG == 0 && e1OEEMES_FLAG != 0)
  8849. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)0);
  8850. // s5PLCSignal_Old["e1OEEPLC_FLAG"] = s5PLCData["e1OEEPLC_FLAG"];
  8851. // }
  8852. // }
  8853. // catch (Exception ex)
  8854. // {
  8855. // Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  8856. // string str = ex.StackTrace;
  8857. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8858. // }
  8859. // #endregion 节拍接口
  8860. // #region AGV上料
  8861. // // AGV上料叫AGV信号
  8862. // try
  8863. // {
  8864. // int e1AGVUpCall = (int)s5PLCData["e1AGVUpCall"];
  8865. // int e1AGVUpCallOld = (int)s5PLCSignal_Old["e1AGVUpCall"];
  8866. // if (e1AGVUpCall != e1AGVUpCallOld)
  8867. // {
  8868. // if (e1AGVUpCall == 1) // 0->1
  8869. // Task.Run(() => S5AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
  8870. // s5PLCSignal_Old["e1AGVUpCall"] = s5PLCData["e1AGVUpCall"];
  8871. // }
  8872. // }
  8873. // catch (Exception ex)
  8874. // {
  8875. // Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  8876. // string str = ex.StackTrace;
  8877. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8878. // }
  8879. // // AGV上料完成信号
  8880. // try
  8881. // {
  8882. // int e1AGVUpEnd = (int)s5PLCData["e1AGVUpEnd"];
  8883. // int e1AGVUpEndOld = (int)s5PLCSignal_Old["e1AGVUpEnd"];
  8884. // if (e1AGVUpEnd != e1AGVUpEndOld)
  8885. // {
  8886. // if (e1AGVUpEnd == 1) // 0->1
  8887. // Task.Run(() => S5AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
  8888. // s5PLCSignal_Old["e1AGVUpEnd"] = s5PLCData["e1AGVUpEnd"];
  8889. // }
  8890. // }
  8891. // catch (Exception ex)
  8892. // {
  8893. // Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  8894. // string str = ex.StackTrace;
  8895. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8896. // }
  8897. // #endregion AGV上料
  8898. // #region AGV下料
  8899. // // AGV下料叫agv信号
  8900. // try
  8901. // {
  8902. // int e1AGVDownCall = (int)s5PLCData["e1AGVDownCall"];
  8903. // int e1AGVDownCallOld = (int)s5PLCSignal_Old["e1AGVDownCall"];
  8904. // if (e1AGVDownCall != e1AGVDownCallOld)
  8905. // {
  8906. // if (e1AGVDownCall == 1) // 0->1
  8907. // Task.Run(() => S5AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
  8908. // s5PLCSignal_Old["e1AGVDownCall"] = s5PLCData["e1AGVDownCall"];
  8909. // }
  8910. // }
  8911. // catch (Exception ex)
  8912. // {
  8913. // Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  8914. // string str = ex.StackTrace;
  8915. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8916. // }
  8917. // // AGV下料完成信号
  8918. // try
  8919. // {
  8920. // int e1AGVDownEnd = (int)s5PLCData["e1AGVDownEnd"];
  8921. // int e1AGVDownEndOld = (int)s5PLCSignal_Old["e1AGVDownEnd"];
  8922. // if (e1AGVDownEnd != e1AGVDownEndOld)
  8923. // {
  8924. // if (e1AGVDownEnd == 1) // 0->1
  8925. // Task.Run(() => S5AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
  8926. // s5PLCSignal_Old["e1AGVDownEnd"] = s5PLCData["e1AGVDownEnd"];
  8927. // }
  8928. // }
  8929. // catch (Exception ex)
  8930. // {
  8931. // Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  8932. // string str = ex.StackTrace;
  8933. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8934. // }
  8935. // #endregion AGV下料
  8936. // #region 心跳
  8937. // try
  8938. // {
  8939. // short states = 0;
  8940. // Funs[plcNo].WriteMultipleRegisters<short>(2000, states);
  8941. // }
  8942. // catch (Exception ex)
  8943. // {
  8944. // string str = ex.StackTrace;
  8945. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  8946. // }
  8947. // #endregion 心跳
  8948. // UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
  8949. // stopwatch1.Stop();
  8950. // //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
  8951. // OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
  8952. // }
  8953. // else
  8954. // {
  8955. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8956. // AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
  8957. // Funs[plcNo].Connect();
  8958. // }
  8959. // }
  8960. // catch (Exception ex)
  8961. // {
  8962. // UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
  8963. // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
  8964. // Funs[plcNo].ReConnect();
  8965. // }
  8966. // Thread.Sleep(IntervalReadPLC);
  8967. // }
  8968. //}
  8969. /// <summary>
  8970. /// [S5] Tray盘下料装备 - 进站校验
  8971. /// </summary>
  8972. /// <param name="plcNo">PLC编号</param>
  8973. /// <param name="stationNameStr">工站全称</param>
  8974. private void S5进站校验(int plcNo, string stationNameStr)
  8975. {
  8976. Stopwatch stopwatch1 = new Stopwatch();
  8977. Stopwatch stopwatch2 = new Stopwatch();
  8978. try
  8979. {
  8980. stopwatch1.Start();
  8981. string sn = (string)s5PLCData["e1ProductSN_Check"]; // 产品SN(载具码)
  8982. sn = sn.Replace("\0", "");
  8983. // 获取产品SN By 载具码
  8984. #region 查询载具上的产品信息
  8985. string cavityData = string.Empty;
  8986. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  8987. if (string.IsNullOrEmpty(cavityData))
  8988. cavityData = "";
  8989. if (snResult != 0)
  8990. {
  8991. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  8992. writeToPLC_Flag1.Name = "e1MES_FLAG_Check";
  8993. writeToPLC_Flag1.Adress = 2003;
  8994. writeToPLC_Flag1.Value = (short)6;
  8995. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag1);
  8996. stopwatch1.Stop();
  8997. AddMessage(LogType.Info, stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  8998. return;
  8999. }
  9000. string[] cavitySNs = cavityData.Split('.');
  9001. string partNo = string.Empty;
  9002. if (cavitySNs != null && cavitySNs.Length >= 1)
  9003. partNo = cavitySNs[0];
  9004. #endregion 查询载具上的产品信息
  9005. // 产品SN(物料码)校验
  9006. List<TestItem> item = new List<TestItem>();
  9007. item.Add(new TestItem()
  9008. {
  9009. Parameter_name = "载具码",
  9010. Parameter_value = sn,
  9011. });
  9012. item.Add(new TestItem()
  9013. {
  9014. Parameter_name = "载具穴号",
  9015. Parameter_value = "1",
  9016. });
  9017. stopwatch2.Start();
  9018. int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, partNo, item, out string errorMsg);
  9019. stopwatch2.Stop();
  9020. short e1MES_FLAG_Check = (short)result;
  9021. // MES_Flag
  9022. //Funs[plcNo].WriteMultipleRegisters<short>(2003, e1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
  9023. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9024. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9025. writeToPLC_Flag.Adress = 2003;
  9026. writeToPLC_Flag.Value = e1MES_FLAG_Check;
  9027. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9028. }
  9029. catch (Exception ex)
  9030. {
  9031. string str = ex.StackTrace;
  9032. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9033. // MES_Flag
  9034. //Funs[plcNo].WriteMultipleRegisters<short>(2003, (short)6); // 6代表上位机报警
  9035. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9036. writeToPLC_Flag.Name = "e1MES_FLAG_Check";
  9037. writeToPLC_Flag.Adress = 2003;
  9038. writeToPLC_Flag.Value = (short)6;
  9039. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG_Check", writeToPLC_Flag);
  9040. }
  9041. stopwatch1.Stop();
  9042. AddMessage(LogType.Info, stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9043. }
  9044. /// <summary>
  9045. /// [S5] Tray盘下料装备 - 出站接口
  9046. /// </summary>
  9047. /// <param name="plcNo"></param>
  9048. /// <param name="stationCode"></param>
  9049. /// <param name="stationName"></param>
  9050. private void S5出站接口(int plcNo, string stationCode, string stationName)
  9051. {
  9052. Stopwatch stopwatch1 = new Stopwatch();
  9053. Stopwatch stopwatch2 = new Stopwatch();
  9054. string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
  9055. string stationNameStr = stationCode + stationName;
  9056. string processItem = stationName; // 测试项目
  9057. try
  9058. {
  9059. stopwatch1.Start();
  9060. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  9061. //string batch_num = GlobalContext.BatchNumber; // 批次号
  9062. string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
  9063. //string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
  9064. string sn = (string)s5PLCData["e1ProductSN"]; // 产品SN(载具SN码)
  9065. sn = sn.Replace("\0", "");
  9066. //string partNo = (string)s5PLCData["e1PartNo"]; // 物料码
  9067. //partNo = partNo.Replace("\0", "");
  9068. #region 查询载具上的产品信息
  9069. string cavityData = string.Empty;
  9070. int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
  9071. if (string.IsNullOrEmpty(cavityData))
  9072. cavityData = "";
  9073. if (snResult != 0)
  9074. {
  9075. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9076. writeToPLC_Flag1.Name = "e1MES_FLAG";
  9077. writeToPLC_Flag1.Adress = 2035;
  9078. writeToPLC_Flag1.Value = (short)4;
  9079. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag1);
  9080. stopwatch1.Stop();
  9081. AddMessage(LogType.Info, stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
  9082. return;
  9083. }
  9084. string[] cavitySNs = cavityData.Split('.');
  9085. string partNo = string.Empty;
  9086. if (cavitySNs != null && cavitySNs.Length >= 1)
  9087. partNo = cavitySNs[0];
  9088. #endregion 查询载具上的产品信息
  9089. int e1Result = (int)s5PLCData["e1Result"]; // 产品结果
  9090. bool pass = e1Result == 1;
  9091. stopwatch2.Start();
  9092. // 上传MES
  9093. List<TestItem> items = new List<TestItem>();
  9094. items.Add(new TestItem()
  9095. {
  9096. Parameter_name = "载具码",
  9097. Parameter_value = sn,
  9098. Parameter_unit = ""
  9099. });
  9100. items.Add(new TestItem()
  9101. {
  9102. Parameter_name = "载具穴号",
  9103. Parameter_value = "1",
  9104. Parameter_unit = ""
  9105. });
  9106. items.Add(new TestItem()
  9107. {
  9108. Parameter_name = "产品结果",
  9109. Parameter_value = e1Result == 1 ? "OK" : "NG",
  9110. Parameter_unit = ""
  9111. });
  9112. int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
  9113. , workorder_code, mtltmrk, partNo, pass, sn, "1");
  9114. //int result = result1 == 1 ? 1 : (GlobalContext.IsSendProcessData ? 4 : 1);
  9115. short result = result1 == 1 ? (short)1 : (short)3;
  9116. stopwatch2.Stop();
  9117. #region 存储绑定数据到 边线MES系统中
  9118. if (result == 1)
  9119. {
  9120. // 删除绑定信息
  9121. int resultMesR = XiaomiMES_RouteCommunication.SNDeleteData(sn);
  9122. if (resultMesR != 0)
  9123. {
  9124. result = 4;
  9125. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}_出站接口失败!MES边线程序返回:{resultMesR}");
  9126. }
  9127. }
  9128. #endregion 存储绑定数据到 边线MES系统中
  9129. // MES_Flag 为MES报错
  9130. // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9131. //Funs[plcNo].WriteMultipleRegisters<short>(2035, result); // 4代表上位机报警
  9132. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9133. writeToPLC_Flag.Name = "e1MES_FLAG";
  9134. writeToPLC_Flag.Adress = 2035;
  9135. writeToPLC_Flag.Value = result;
  9136. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9137. OnMessage(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
  9138. }
  9139. catch (Exception ex)
  9140. {
  9141. stopwatch2.Restart();
  9142. // MES_Flag 为4上位机报错
  9143. //Funs[plcNo].WriteMultipleRegisters<short>(2035, (short)4); // 4代表上位机报警
  9144. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9145. writeToPLC_Flag.Name = "e1MES_FLAG";
  9146. writeToPLC_Flag.Adress = 2035;
  9147. writeToPLC_Flag.Value = (short)4;
  9148. SxPLCWriteData_Add(ref s5PLCWriteData, "e1MES_FLAG", writeToPLC_Flag);
  9149. stopwatch2.Stop();
  9150. string str = ex.StackTrace;
  9151. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9152. }
  9153. stopwatch1.Stop();
  9154. AddMessage(LogType.Info, stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9155. }
  9156. /// <summary>
  9157. /// [S5] Tray盘下料装备 - 节拍接口
  9158. /// </summary>
  9159. /// <param name="plcNo">PLC编号</param>
  9160. /// <param name="stationNameStr">工站全称</param>
  9161. private void S5节拍接口(int plcNo, string stationNameStr)
  9162. {
  9163. Stopwatch stopwatch1 = new Stopwatch();
  9164. Stopwatch stopwatch2 = new Stopwatch();
  9165. string resultStr = string.Empty;
  9166. try
  9167. {
  9168. stopwatch1.Start();
  9169. string oEEType = ((int)s5PLCData["e1OEEType"]).ToString(); // 节拍类型(plc写入)
  9170. string e1OEEProductSN = (string)s5PLCData["e1OEEProductSN"]; // 载具SN
  9171. e1OEEProductSN = e1OEEProductSN.Replace("\0", "");
  9172. bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
  9173. if (!actionBool)
  9174. {
  9175. stopwatch2.Start();
  9176. // MES_Flag
  9177. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9178. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9179. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9180. writeToPLC_Flag1.Adress = 2088;
  9181. writeToPLC_Flag1.Value = (short)4;
  9182. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9183. stopwatch2.Stop();
  9184. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9185. return;
  9186. }
  9187. string e1OEEPartNo = string.Empty; // 物料码
  9188. if (string.IsNullOrEmpty(e1OEEProductSN))
  9189. {
  9190. stopwatch2.Start();
  9191. // MES_Flag
  9192. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)1); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9193. WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
  9194. writeToPLC_Flag1.Name = "e1OEEMES_FLAG";
  9195. writeToPLC_Flag1.Adress = 2088;
  9196. writeToPLC_Flag1.Value = (short)1;
  9197. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag1);
  9198. stopwatch2.Stop();
  9199. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- 上传内容无效已自动省略;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9200. return;
  9201. }
  9202. else
  9203. { // 查产品SN
  9204. e1OEEPartNo = "Test"; // ZS
  9205. }
  9206. short e1OEEMES_FLAG = 0;
  9207. // 上传OEE
  9208. (short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, e1OEEPartNo, e1OEEProductSN);
  9209. e1OEEMES_FLAG = result.Item1;
  9210. resultStr = result.Item2;
  9211. stopwatch2.Start();
  9212. // MES_Flag
  9213. //Funs[plcNo].WriteMultipleRegisters<short>(2088, e1OEEMES_FLAG); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
  9214. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9215. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9216. writeToPLC_Flag.Adress = 2088;
  9217. writeToPLC_Flag.Value = e1OEEMES_FLAG;
  9218. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9219. stopwatch2.Stop();
  9220. }
  9221. catch (Exception ex)
  9222. {
  9223. string str = ex.StackTrace;
  9224. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9225. // MES_Flag
  9226. stopwatch2.Start();
  9227. //Funs[plcNo].WriteMultipleRegisters<short>(2088, (short)4); // 4代表上位机报警
  9228. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9229. writeToPLC_Flag.Name = "e1OEEMES_FLAG";
  9230. writeToPLC_Flag.Adress = 2088;
  9231. writeToPLC_Flag.Value = (short)4;
  9232. SxPLCWriteData_Add(ref s5PLCWriteData, "e1OEEMES_FLAG", writeToPLC_Flag);
  9233. stopwatch2.Stop();
  9234. }
  9235. stopwatch1.Stop();
  9236. AddMessage(LogType.Info, stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9237. }
  9238. /// <summary>
  9239. /// [S5] Tray盘下料装备 - AGV上料叫agv
  9240. /// </summary>
  9241. /// <param name="plcNo">PLC编号</param>
  9242. /// <param name="stationNameStr">工站全称</param>
  9243. private void S5AGV上料叫agv(int plcNo, string stationNameStr)
  9244. {
  9245. Stopwatch stopwatch1 = new Stopwatch();
  9246. Stopwatch stopwatch2 = new Stopwatch();
  9247. try
  9248. {
  9249. stopwatch1.Start();
  9250. // ZS 呼叫AGV
  9251. short e1AGVUpCall = 2;
  9252. stopwatch2.Start();
  9253. // e1AGVUpCall
  9254. //Funs[plcNo].WriteMultipleRegisters<short>(2120, e1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9255. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9256. writeToPLC_Flag.Name = "e1AGVUpCall";
  9257. writeToPLC_Flag.Adress = 2120;
  9258. writeToPLC_Flag.Value = e1AGVUpCall;
  9259. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9260. stopwatch2.Stop();
  9261. }
  9262. catch (Exception ex)
  9263. {
  9264. string str = ex.StackTrace;
  9265. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9266. // e1AGVUpCall
  9267. stopwatch2.Start();
  9268. //Funs[plcNo].WriteMultipleRegisters<short>(2120, (short)4); // 4代表上位机报警
  9269. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9270. writeToPLC_Flag.Name = "e1AGVUpCall";
  9271. writeToPLC_Flag.Adress = 2120;
  9272. writeToPLC_Flag.Value = (short)4;
  9273. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpCall", writeToPLC_Flag);
  9274. stopwatch2.Stop();
  9275. }
  9276. stopwatch1.Stop();
  9277. AddMessage(LogType.Info, stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9278. }
  9279. /// <summary>
  9280. /// [S5] Tray盘下料装备 - AGV上料完成
  9281. /// </summary>
  9282. /// <param name="plcNo">PLC编号</param>
  9283. /// <param name="stationNameStr">工站全称</param>
  9284. private void S5AGV上料完成(int plcNo, string stationNameStr)
  9285. {
  9286. Stopwatch stopwatch1 = new Stopwatch();
  9287. Stopwatch stopwatch2 = new Stopwatch();
  9288. try
  9289. {
  9290. stopwatch1.Start();
  9291. // ZS AGV上料完成,让小车离开
  9292. short e1AGVUpEnd = 2;
  9293. stopwatch2.Start();
  9294. // e1AGVUpEnd
  9295. //Funs[plcNo].WriteMultipleRegisters<short>(2122, e1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9296. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9297. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9298. writeToPLC_Flag.Adress = 2122;
  9299. writeToPLC_Flag.Value = e1AGVUpEnd;
  9300. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9301. stopwatch2.Stop();
  9302. }
  9303. catch (Exception ex)
  9304. {
  9305. string str = ex.StackTrace;
  9306. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9307. // e1AGVUpEnd
  9308. stopwatch2.Start();
  9309. //Funs[plcNo].WriteMultipleRegisters<short>(2122, (short)4); // 4代表上位机报警
  9310. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9311. writeToPLC_Flag.Name = "e1AGVUpEnd";
  9312. writeToPLC_Flag.Adress = 2122;
  9313. writeToPLC_Flag.Value = (short)4;
  9314. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVUpEnd", writeToPLC_Flag);
  9315. stopwatch2.Stop();
  9316. }
  9317. stopwatch1.Stop();
  9318. AddMessage(LogType.Info, stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9319. }
  9320. /// <summary>
  9321. /// [S5] Tray盘下料装备 - AGV下料叫agv
  9322. /// </summary>
  9323. /// <param name="plcNo">PLC编号</param>
  9324. /// <param name="stationNameStr">工站全称</param>
  9325. private void S5AGV下料叫agv(int plcNo, string stationNameStr)
  9326. {
  9327. Stopwatch stopwatch1 = new Stopwatch();
  9328. Stopwatch stopwatch2 = new Stopwatch();
  9329. try
  9330. {
  9331. stopwatch1.Start();
  9332. // ZS 呼叫AGV
  9333. short e1AGVDownCall = 2;
  9334. stopwatch2.Start();
  9335. // e1AGVDownCall
  9336. //Funs[plcNo].WriteMultipleRegisters<short>(2133, e1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9337. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9338. writeToPLC_Flag.Name = "e1AGVDownCall";
  9339. writeToPLC_Flag.Adress = 2133;
  9340. writeToPLC_Flag.Value = e1AGVDownCall;
  9341. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9342. stopwatch2.Stop();
  9343. }
  9344. catch (Exception ex)
  9345. {
  9346. string str = ex.StackTrace;
  9347. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9348. // e1AGVDownCall
  9349. stopwatch2.Start();
  9350. //Funs[plcNo].WriteMultipleRegisters<short>(2133, (short)4); // 4代表上位机报警
  9351. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9352. writeToPLC_Flag.Name = "e1AGVDownCall";
  9353. writeToPLC_Flag.Adress = 2133;
  9354. writeToPLC_Flag.Value = (short)4;
  9355. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownCall", writeToPLC_Flag);
  9356. stopwatch2.Stop();
  9357. }
  9358. stopwatch1.Stop();
  9359. AddMessage(LogType.Info, stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9360. }
  9361. /// <summary>
  9362. /// [S5] Tray盘下料装备 - AGV下料完成
  9363. /// </summary>
  9364. /// <param name="plcNo">PLC编号</param>
  9365. /// <param name="stationNameStr">工站全称</param>
  9366. private void S5AGV下料完成(int plcNo, string stationNameStr)
  9367. {
  9368. Stopwatch stopwatch1 = new Stopwatch();
  9369. Stopwatch stopwatch2 = new Stopwatch();
  9370. try
  9371. {
  9372. stopwatch1.Start();
  9373. // ZS AGV上料完成,让小车离开
  9374. short e1AGVDownEnd = 2;
  9375. stopwatch2.Start();
  9376. // e1AGVDownEnd
  9377. //Funs[plcNo].WriteMultipleRegisters<short>(2135, e1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
  9378. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9379. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9380. writeToPLC_Flag.Adress = 2135;
  9381. writeToPLC_Flag.Value = e1AGVDownEnd;
  9382. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9383. stopwatch2.Stop();
  9384. }
  9385. catch (Exception ex)
  9386. {
  9387. string str = ex.StackTrace;
  9388. AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9389. // e1AGVDownEnd
  9390. stopwatch2.Start();
  9391. //Funs[plcNo].WriteMultipleRegisters<short>(2135, (short)4); // 4代表上位机报警
  9392. WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
  9393. writeToPLC_Flag.Name = "e1AGVDownEnd";
  9394. writeToPLC_Flag.Adress = 2135;
  9395. writeToPLC_Flag.Value = (short)4;
  9396. SxPLCWriteData_Add(ref s5PLCWriteData, "e1AGVDownEnd", writeToPLC_Flag);
  9397. stopwatch2.Stop();
  9398. }
  9399. stopwatch1.Stop();
  9400. AddMessage(LogType.Info, stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
  9401. }
  9402. #endregion [S5] Tray盘下料装备
  9403. #endregion PLC5 张超凡
  9404. #region 缓存读取到的PLC数据 与 需要写入的PLC数据
  9405. /// <summary>
  9406. /// PLC读取到的数据 -添加数据
  9407. /// </summary>
  9408. public static void SxPLCData_Add(ref Dictionary<string, object> sxPlcData, string newKey, object newValue)
  9409. {
  9410. if (sxPlcData.ContainsKey(newKey))
  9411. sxPlcData[newKey] = newValue;
  9412. else
  9413. sxPlcData.Add(newKey, newValue);
  9414. }
  9415. /// <summary>
  9416. /// PLC需要写入的数据 -添加数据
  9417. /// </summary>
  9418. public static void SxPLCWriteData_Add(ref Dictionary<string, WriteToPLC_Flag> sxPLCWriteData, string newKey, WriteToPLC_Flag newValue)
  9419. {
  9420. if (sxPLCWriteData.ContainsKey(newKey))
  9421. sxPLCWriteData[newKey] = newValue;
  9422. else
  9423. sxPLCWriteData.Add(newKey, newValue);
  9424. }
  9425. /// <summary>
  9426. /// PLC回写操作,写后清空flag
  9427. /// </summary>
  9428. /// <param name="modbusClient">modbus对象</param>
  9429. /// <param name="pLCReadDatas">读取到的数据字典</param>
  9430. /// <param name="pLCWriteDatas">需要写入的数据</param>
  9431. public static void PLCWriteData(ModbusClientHelper modbusClient, ref Dictionary<string, object> pLCReadDatas, ref Dictionary<string, WriteToPLC_Flag> pLCWriteDataDic)
  9432. {
  9433. if (pLCWriteDataDic != null && pLCWriteDataDic.Count > 0)
  9434. {
  9435. List<WriteToPLC_Flag> pLCWriteDatas = pLCWriteDataDic.Values.ToList();
  9436. for (int i = 0; i < pLCWriteDatas.Count; i++)
  9437. {
  9438. string mesFlagName = pLCWriteDatas[i].Name;
  9439. int mesFlagAdress = pLCWriteDatas[i].Adress;
  9440. short mesFlagValue = (short)pLCWriteDatas[i].Value; // short
  9441. if (mesFlagValue != 0) // 不为0则证明需要写入结果信息
  9442. {
  9443. // 先回写数据
  9444. List<WriteToPLC_Data> writeToPLCDatas = pLCWriteDatas[i].WriteToPLCDatas;
  9445. for (int j = 0; j < writeToPLCDatas.Count; j++)
  9446. {
  9447. int mesDataAdress = writeToPLCDatas[j].Adress;
  9448. PLCValueType mesDataType = writeToPLCDatas[j].ValueType;
  9449. switch (mesDataType)
  9450. {
  9451. case PLCValueType.Short:
  9452. short mesDataValueShort = (short)writeToPLCDatas[j].Value;
  9453. modbusClient.WriteMultipleRegisters<short>(mesDataAdress, mesDataValueShort);
  9454. break;
  9455. case PLCValueType.String:
  9456. string mesDataValueStr = (string)writeToPLCDatas[j].Value;
  9457. int mesDataValueStrLength = writeToPLCDatas[j].ValueTypeStrLength;
  9458. modbusClient.WriteMultipleRegisters<string>(mesDataAdress, mesDataValueStr, mesDataValueStrLength);
  9459. break;
  9460. }
  9461. }
  9462. // 再回写信号
  9463. modbusClient.WriteMultipleRegisters<short>(mesFlagAdress, mesFlagValue);
  9464. // 存储读取数据的字典
  9465. pLCReadDatas[mesFlagName] = (int)mesFlagValue;
  9466. // 存储写入数据的字典 - 清空写入值
  9467. pLCWriteDatas[i].Value = (short)0;
  9468. pLCWriteDataDic[mesFlagName] = pLCWriteDatas[i];
  9469. }
  9470. }
  9471. }
  9472. }
  9473. /// <summary>
  9474. /// 提交点检数据到MES - 取数据库中缓存的 点检数据
  9475. /// </summary>
  9476. /// <param name="no">3</param>
  9477. /// <param name="stationCode">设备编号</param>
  9478. /// <param name="stationNameStr">设备名称</param>
  9479. /// <param name="plcOrder">车间订单号</param>
  9480. private void SubmitOneCheckDataToMESByDB(int plcNo, int stationCode, string stationNameStr, string plcOrder)
  9481. {
  9482. try
  9483. {
  9484. /// [S2]FCT (2-上传点检数据;102-清空该工单该工单的所有点检项缓存)
  9485. /// [S3]值板机 (3-上传点检数据;103-清空该工单该工单的所有点检项缓存)
  9486. /// [S4]取放桁架 (4-上传点检数据;104-清空该工单该工单的所有点检项缓存)
  9487. /// [S6]CCD检测 (6-上传点检数据;106-清空该工单该工单的所有点检项缓存)
  9488. int result1 = 0;
  9489. switch (stationCode)
  9490. {
  9491. case 2:
  9492. case 3:
  9493. case 4:
  9494. case 6:
  9495. result1 = SubmitToMESByDB(stationCode.ToString(), stationNameStr, plcOrder);
  9496. break;
  9497. case 102:
  9498. result1 = ClearOneCheckDataByDB("2", stationNameStr, plcOrder);
  9499. break;
  9500. case 103:
  9501. result1 = ClearOneCheckDataByDB("3", stationNameStr, plcOrder);
  9502. break;
  9503. case 104:
  9504. result1 = ClearOneCheckDataByDB("4", stationNameStr, plcOrder);
  9505. break;
  9506. case 106:
  9507. result1 = ClearOneCheckDataByDB("6", stationNameStr, plcOrder);
  9508. break;
  9509. default:
  9510. // MES_Flag 为“6未找到正确设备编号”
  9511. Funs[plcNo].WriteMultipleRegisters<int>(2406, 6);
  9512. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!未找到需要点检的正确设备编号");
  9513. return;
  9514. }
  9515. short result = result1 == 1 ? (short)1 : (short)2;
  9516. Funs[plcNo].WriteMultipleRegisters<int>(2406, result); // MES_Flag 为4MES报错
  9517. OnMessage(LogType.Debug, $"PLC{plcNo}_PLC通知MES上传点检数据运行完毕!-Write" + (result == 1 ? "成功!" : "失败!"));
  9518. }
  9519. catch (Exception ex)
  9520. {
  9521. // MES_Flag 为2上位机报错
  9522. Funs[plcNo].WriteMultipleRegisters<int>(2406, 2);
  9523. string str = ex.StackTrace;
  9524. AddMessage_Station(stationNameStr, LogType.Error, $"PLC通知上传点检数据到MES运行出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
  9525. }
  9526. }
  9527. #endregion 缓存读取到的PLC数据 与 需要写入的PLC数据
  9528. #region UI刷新
  9529. /// <summary>
  9530. /// 更新商品信息的UI + 下发产品信息(SN)
  9531. /// </summary>
  9532. private void UpdateProductInfo()
  9533. {
  9534. currentWC.Text = GlobalContext.WorkOrderCode; // 订单号
  9535. currentMtltmrk.Text = GlobalContext.Mtltmrk; // 产品型号
  9536. //currentBN.Text = GlobalContext.BatchNumber; // 批次号
  9537. //txt_CurSupplierCode.Text = ""; // 供应商代号
  9538. }
  9539. /// <summary>
  9540. /// 更新PLC连接状态的UI
  9541. /// </summary>
  9542. /// <param name="no">PLC编号</param>
  9543. /// <param name="status">状态</param>
  9544. private void UpdatePLCMonitor(int imgNo, int plcNo, int status)
  9545. {
  9546. if (this != null && !this.IsDisposed)
  9547. {
  9548. switch (imgNo)
  9549. {
  9550. case 1:
  9551. this.BeginInvoke(new Action(() =>
  9552. {
  9553. picPLC.Image = imageListState.Images[status];
  9554. }));
  9555. break;
  9556. case 2:
  9557. this.BeginInvoke(new Action(() =>
  9558. {
  9559. pictureBox2.Image = imageListState.Images[status];
  9560. }));
  9561. break;
  9562. case 3:
  9563. this.BeginInvoke(new Action(() =>
  9564. {
  9565. pictureBox3.Image = imageListState.Images[status];
  9566. }));
  9567. break;
  9568. case 4:
  9569. this.BeginInvoke(new Action(() =>
  9570. {
  9571. pictureBox4.Image = imageListState.Images[status];
  9572. }));
  9573. break;
  9574. case 5:
  9575. this.BeginInvoke(new Action(() =>
  9576. {
  9577. pictureBox5.Image = imageListState.Images[status];
  9578. }));
  9579. break;
  9580. case 6:
  9581. this.BeginInvoke(new Action(() =>
  9582. {
  9583. pictureBox6.Image = imageListState.Images[status];
  9584. }));
  9585. break;
  9586. case 7:
  9587. this.BeginInvoke(new Action(() =>
  9588. {
  9589. pictureBox7.Image = imageListState.Images[status];
  9590. }));
  9591. break;
  9592. case 8:
  9593. this.BeginInvoke(new Action(() =>
  9594. {
  9595. pictureBox8.Image = imageListState.Images[status];
  9596. }));
  9597. break;
  9598. default:
  9599. break;
  9600. }
  9601. }
  9602. Task.Run(() => // 更新PLC交互页的指示灯
  9603. {
  9604. try
  9605. {
  9606. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9607. {
  9608. Form_Main.formPLCDB.UpdatePLCFunMonitor(plcNo, status);
  9609. }
  9610. }
  9611. catch { }
  9612. });
  9613. }
  9614. #endregion UI刷新
  9615. #region 日志
  9616. /// <summary>
  9617. /// 添加各工位运行日志(同步至PLC交互页面)
  9618. /// </summary>
  9619. /// <param name="stationNameStr">工站名称</param>
  9620. /// <param name="logType">日志类型</param>
  9621. /// <param name="message">日志内容</param>
  9622. /// <param name="snNumber">产品数字SN</param>
  9623. public void AddMessage_Station(string stationNameStr, LogType logType, string message, string snNumber = "")
  9624. {
  9625. if (!(stationNameStr.Equals("获取设备报警数据与状态信息")
  9626. && (message.Contains("更新整线运行数据完毕") || message.Contains("更新整线报警数据完毕"))
  9627. ))
  9628. {
  9629. AddMessage(logType, message); // 首页展示+日志记录
  9630. }
  9631. PLCDBFormMessage plcMessage = new PLCDBFormMessage()
  9632. {
  9633. StationName = stationNameStr,
  9634. SnNumber = snNumber,
  9635. Message = message,
  9636. CreateTime = DateTime.Now
  9637. };
  9638. // PLC交互页展示
  9639. Task.Run(() =>
  9640. {
  9641. try
  9642. {
  9643. if (Form_Main.formPLCDB != null && !Form_Main.formPLCDB.IsDisposed)
  9644. {
  9645. Form_Main.formPLCDB.UpdateMessage(plcMessage);
  9646. }
  9647. }
  9648. catch { }
  9649. });
  9650. }
  9651. /// <summary>
  9652. /// 添加运行日志
  9653. /// </summary>
  9654. /// <param name="logType">日志类型</param>
  9655. /// <param name="message">日志内容</param>
  9656. public void AddMessage(LogType logType, string message)
  9657. {
  9658. OnMessage(logType, message);
  9659. string date = DateTime.Now.ToString("yyyy/MM/dd");
  9660. string time = DateTime.Now.ToString("HH:mm:ss:fff");
  9661. string msgShow = time + "--> " + message + "\r\n";
  9662. this.BeginInvoke(new Action(() =>
  9663. {
  9664. systemLog.Rows.Insert(0, date, time, message);
  9665. if (systemLog.Rows.Count >= 100)
  9666. systemLog.Rows.RemoveAt(systemLog.Rows.Count - 1);
  9667. }));
  9668. }
  9669. /// <summary>
  9670. /// 添加运行日志-保存
  9671. /// </summary>
  9672. /// <param name="logType">日志类型</param>
  9673. /// <param name="message">日志内容</param>
  9674. private void OnMessage(LogType logType, string msg)
  9675. {
  9676. MessageEvent?.Invoke(logType, msg);
  9677. }
  9678. /// <summary>
  9679. /// 保存PLC写入日志
  9680. /// </summary>
  9681. /// <param name="logType"></param>
  9682. /// <param name="logValue"></param>
  9683. private void WritePLCLog(LogType logType, string logValue)
  9684. {
  9685. switch ((int)logType)
  9686. {
  9687. case 0:
  9688. _PLCLogNet.WriteDebug(logValue);
  9689. break;
  9690. case 1:
  9691. _PLCLogNet.WriteInfo(logValue);
  9692. break;
  9693. case 2:
  9694. _PLCLogNet.WriteWarn(logValue);
  9695. break;
  9696. case 3:
  9697. _PLCLogNet.WriteError(logValue);
  9698. break;
  9699. default:
  9700. _PLCLogNet.WriteFatal(logValue);
  9701. break;
  9702. }
  9703. }
  9704. /// <summary>
  9705. /// IOT Mqtt回调方法- With DataId
  9706. /// </summary>
  9707. /// <param name="id"></param>
  9708. /// <param name="v"></param>
  9709. /// <param name="dataId"></param>
  9710. public void CallbackWithDataId(string id, string msg, string dataId)
  9711. {
  9712. //_MqttLogNet.WriteInfo("-------CallbackWithDataId-------");
  9713. //byte[] buffer1 = Encoding.Default.GetBytes(v);
  9714. //byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
  9715. //string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
  9716. //Console.WriteLine("{0} -> {1} {2}", id, strBuffer, dataId);
  9717. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9718. _IOTMqttLogNet.WriteInfo($"{datetime}-> [消息ID:{id}][事件ID:{dataId}]{msg}");
  9719. }
  9720. /// <summary>
  9721. /// AGV Mqtt回调方法- 记录Log并处理数据
  9722. /// </summary>
  9723. /// <param name="obj"></param>
  9724. private void AGVMqttShowLog(ResultData_MQTT resultData_MQTT)
  9725. {
  9726. string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
  9727. _AGVMqttLogNet.WriteInfo($"{datetime}->返回结果:{resultData_MQTT.ResultCode},返回信息:{resultData_MQTT.ResultMsg}");
  9728. // 接收到的信息
  9729. string topic = (string)resultData_MQTT.ResultObject1; // 订阅的标识
  9730. string jsonData = (string)resultData_MQTT.ResultObject2; // 订阅的数据
  9731. if (resultData_MQTT.ResultCode == 1 && !string.IsNullOrEmpty(topic)) // 是接收到的数据
  9732. {
  9733. }
  9734. }
  9735. #endregion 日志
  9736. /// <summary>
  9737. /// 实例化报警字典
  9738. /// </summary>
  9739. private void InitalDicAlarm()
  9740. {
  9741. #region 第一个工站(这里未区分工位,所以下面出现的‘工位代码’使用‘线别代码’代替)
  9742. List<Alarm> keyValues1 = new List<Alarm>
  9743. {
  9744. #region 第一组报警(电机)
  9745. new Alarm { 报警类型 = "电机故障", 报警详情 = "料盘搬运_Y轴电机故障" ,关联的PLC地址 = 5100 },
  9746. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_X轴电机故障" ,关联的PLC地址 = 5101 },
  9747. new Alarm { 报警类型 = "电机故障", 报警详情 = "壳体取料_Z轴电机故障" ,关联的PLC地址 = 5102 },
  9748. new Alarm { 报警类型 = "电机故障", 报警详情 = "载具搬运_X轴电机故障" ,关联的PLC地址 = 5103 },
  9749. new Alarm { 报警类型 = "电机故障", 报警详情 = "镭射_X轴电机故障" ,关联的PLC地址 = 5104 },
  9750. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_X轴电机故障" ,关联的PLC地址 = 5105 },
  9751. new Alarm { 报警类型 = "电机故障", 报警详情 = "上相机_Z轴电机故障" ,关联的PLC地址 = 5106 },
  9752. new Alarm { 报警类型 = "电机故障", 报警详情 = "下相机_X轴电机故障" ,关联的PLC地址 = 5107 },
  9753. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_Y轴电机故障" ,关联的PLC地址 = 5108 },
  9754. new Alarm { 报警类型 = "电机故障", 报警详情 = "下料_X轴电机故障" ,关联的PLC地址 = 5109 },
  9755. #endregion 第一组报警(电机)
  9756. #region 第二组报警(气缸)
  9757. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料进退气缸故障" ,关联的PLC地址 = 5200 },
  9758. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓分料升降气缸故障" ,关联的PLC地址 = 5201 },
  9759. new Alarm { 报警类型 = "气缸故障", 报警详情 = "上料仓顶升气缸故障" ,关联的PLC地址 = 5202 },
  9760. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体取料夹爪气缸故障" ,关联的PLC地址 = 5203 },
  9761. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料仓顶升气缸故障" ,关联的PLC地址 = 5204 },
  9762. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料平移气缸故障" ,关联的PLC地址 = 5205 },
  9763. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料升降气缸故障" ,关联的PLC地址 = 5206 },
  9764. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料夹爪气缸故障" ,关联的PLC地址 = 5207 },
  9765. new Alarm { 报警类型 = "气缸故障", 报警详情 = "壳体上料旋转气缸故障" ,关联的PLC地址 = 5208 },
  9766. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装平移气缸故障" ,关联的PLC地址 = 5209 },
  9767. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装升降气缸故障" ,关联的PLC地址 = 5210 },
  9768. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装夹爪气缸故障" ,关联的PLC地址 = 5211 },
  9769. new Alarm { 报警类型 = "气缸故障", 报警详情 = "胶圈组装撑开气缸故障" ,关联的PLC地址 = 5212 },
  9770. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸1故障" ,关联的PLC地址 = 5213 },
  9771. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具定位气缸2故障" ,关联的PLC地址 = 5214 },
  9772. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具下料移载气缸故障" ,关联的PLC地址 = 5215 },
  9773. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具侧推气缸故障" ,关联的PLC地址 = 5216 },
  9774. new Alarm { 报警类型 = "气缸故障", 报警详情 = "载具回流气缸故障" ,关联的PLC地址 = 5217 },
  9775. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2压料气缸故障" ,关联的PLC地址 = 5218 },
  9776. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2电测气缸故障" ,关联的PLC地址 = 5219 },
  9777. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位2气密气缸故障" ,关联的PLC地址 = 5220 },
  9778. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3下压气缸故障" ,关联的PLC地址 = 5221 },
  9779. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位3上顶气缸故障" ,关联的PLC地址 = 5222 },
  9780. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位5相机升降气缸故障" ,关联的PLC地址 = 5223 },
  9781. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组升降气缸故障" ,关联的PLC地址 = 5224 },
  9782. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸1故障" ,关联的PLC地址 = 5225 },
  9783. new Alarm { 报警类型 = "气缸故障", 报警详情 = "下料模组夹爪气缸2故障" ,关联的PLC地址 = 5226 },
  9784. new Alarm { 报警类型 = "气缸故障", 报警详情 = "机械手夹爪气缸故障" ,关联的PLC地址 = 5227 },
  9785. new Alarm { 报警类型 = "气缸故障", 报警详情 = "工位4:镭射压料气缸故障" ,关联的PLC地址 = 5228 },
  9786. #endregion 第二组报警(气缸)
  9787. #region 第三组报警(其他故障)
  9788. new Alarm { 报警类型 = "其他故障", 报警详情 = "上料处缺料报警" ,关联的PLC地址 = 5300 },
  9789. new Alarm { 报警类型 = "其他故障", 报警详情 = "震盘缺料报警" ,关联的PLC地址 = 5301 },
  9790. new Alarm { 报警类型 = "其他故障", 报警详情 = "成品仓料满报警" ,关联的PLC地址 = 5302 },
  9791. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照超时报警" ,关联的PLC地址 = 5303 },
  9792. new Alarm { 报警类型 = "其他故障", 报警详情 = "检测拍照NG报警" ,关联的PLC地址 = 5304 },
  9793. new Alarm { 报警类型 = "其他故障", 报警详情 = "玻璃门打开报警" ,关联的PLC地址 = 5305 },
  9794. #endregion 第三组报警(其他故障)
  9795. };
  9796. DicAlarms_Cur.Add(GlobalContext.LineCode, keyValues1); // 这里使用线体代替工位
  9797. #endregion 第一个工站(这里使用线体代替工位)
  9798. # region 第二个工站-原来的写法(废弃)
  9799. //keyValues = new Dictionary<int, AlarmData[]>();
  9800. ////1
  9801. //dicAlarmName = new Dictionary<int, Alarm>();
  9802. //dicAlarmName.Add(0, new Alarm { Name = "M01衬套组模组X电机报警" });
  9803. //dicAlarmName.Add(1, new Alarm { Name = "M02衬套组模组Y电机报警" });
  9804. //dicAlarmName.Add(2, new Alarm { Name = "M03衬套组模组Z电机报警" });
  9805. //dicAlarmName.Add(3, new Alarm { Name = "M04衬套组模组U电机报警" });
  9806. //dicAlarmName.Add(4, new Alarm { Name = "M05外流线皮带电机报警" });
  9807. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9808. //for (int i = 0; i < dicAlarmName.Count; i++)
  9809. //{
  9810. // alarmDatas[i] = new AlarmData();
  9811. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9812. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9813. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9814. // alarmDatas[i].AlarmType = 1;
  9815. //}
  9816. //keyValues.Add(1, alarmDatas);
  9817. ////2
  9818. //dicAlarmName = new Dictionary<int, Alarm>();
  9819. //dicAlarmName.Add(0, new Alarm { Name = "C01定位气缸故障" });
  9820. //dicAlarmName.Add(1, new Alarm { Name = "C02左推料气缸故障" });
  9821. //dicAlarmName.Add(2, new Alarm { Name = "C03右推料气缸故障" });
  9822. //dicAlarmName.Add(3, new Alarm { Name = "C04左压料气缸故障" });
  9823. //dicAlarmName.Add(4, new Alarm { Name = "C05右压料气缸故障" });
  9824. //dicAlarmName.Add(5, new Alarm { Name = "C06切料气缸故障" });
  9825. //dicAlarmName.Add(6, new Alarm { Name = "C07左入料吹气气缸故障" });
  9826. //dicAlarmName.Add(7, new Alarm { Name = "C08右入料吹气气缸故障" });
  9827. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9828. //for (int i = 0; i < dicAlarmName.Count; i++)
  9829. //{
  9830. // alarmDatas[i] = new AlarmData();
  9831. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-2";
  9832. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9833. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9834. // alarmDatas[i].AlarmType = 2;
  9835. //}
  9836. //keyValues.Add(2, alarmDatas);
  9837. ////3
  9838. //dicAlarmName = new Dictionary<int, Alarm>();
  9839. //dicAlarmName.Add(0, new Alarm { Name = "安全门报警" });
  9840. //dicAlarmName.Add(1, new Alarm { Name = "联机通信故障" });
  9841. //dicAlarmName.Add(2, new Alarm { Name = "连续NG报警" });
  9842. //dicAlarmName.Add(3, new Alarm { Name = "合格率低于设定值报警" });
  9843. //alarmDatas = new AlarmData[dicAlarmName.Count];
  9844. //for (int i = 0; i < dicAlarmName.Count; i++)
  9845. //{
  9846. // alarmDatas[i] = new AlarmData();
  9847. // alarmDatas[i].Equipment_code = GlobalContext.LineCode + "-3";
  9848. // alarmDatas[i].AlarmDesc = dicAlarmName[i].Name;
  9849. // alarmDatas[i].AlarmName = dicAlarmName[i].Name;
  9850. // alarmDatas[i].AlarmType = 3;
  9851. //}
  9852. //keyValues.Add(3, alarmDatas);
  9853. //DicAlarms.Add(2, keyValues);
  9854. #endregion 第二个工站-原来的写法(废弃)
  9855. }
  9856. }
  9857. }